import { EntityType } from '../metadata/entity-metadata.js'; import { EntityKey } from './entity-key.js'; /** Generates temporary key values for new entities - one added with an unset key when its type's `autoGeneratedKeyType` is not `None`, or one passed to {@link EntityManager.generateTempKeyValue} - and keeps a record of the temporary values the manager's entities hold, so that an import cannot give a second entity one of them. Each {@link EntityManager} has its own, as {@link EntityManager.keyGenerator}, and replaces it when cleared. To supply your own, pass a subclass's constructor as `keyGeneratorCtor` in the {@link EntityManagerConfig}, and have its `generateTempKeyValue` pass the value it makes to `super.generateTempKeyValue` as `valueIfAvail`, so that the value is recorded; Breeze calls only {@link KeyGenerator.generateTempKeyValue}. */ export declare class KeyGenerator { /** Creates a generator that has handed out no values. An {@link EntityManager} creates its own from {@link EntityManagerConfig.keyGeneratorCtor}. */ constructor(); /** Returns a unique 'temporary' id for the specified {@link EntityType}. Uniqueness is defined for this purpose as being unique within each instance of a KeyGenerator. This is sufficient because each EntityManager will have its own instance of a KeyGenerator and any entities imported into the EntityManager with temporary keys will have them regenerated and remapped on import. The return value of this method must be of the correct type as determined by the keyProperties of the specified EntityType @example // Assume em1 is a preexisting EntityManager, and the server generates Order keys const order1 = em1.createEntity(Order); // next line calls em1.keyGenerator.generateTempKeyValue(order1.entityType), // sets order1's 'orderID' property to the result, and returns it const oid1 = em1.generateTempKeyValue(order1); const saveResult = await em1.saveChanges(); const sameOrder1 = saveResult.entities[0]; // order1 === sameOrder1; // but order1.orderID != oid1 // because the server will have generated a new id // and the client will have been updated with this // new id. @param entityType - The type to generate a key for. Its key must be a single property. @param valueIfAvail - A key value to use if no entity in the manager holds it. When entities with temporary keys are imported, the manager passes each one's key here, so that the key survives the import where it can; a subclass passes the value it made. If the value is taken, or omitted, a new one is generated. Either way, the value returned is recorded as held. @returns The key value, of the key property's data type. */ generateTempKeyValue(entityType: EntityType, valueIfAvail?: any): any; /** Returns an {@link EntityKey} for each temporary key value the manager's entities hold: the values this generator handed out or recorded, less those released when an entity was saved and given the server's key, or detached. @deprecated Ask the entities instead: `em.getEntities().filter(e => e.entityAspect.hasTempKey).map(e => e.entityAspect.getKey())`. Breeze does not call it. It still works; it is not scheduled for removal. */ getTempKeys(): EntityKey[]; /** Whether `entityKey`'s value is a temporary key an entity in the manager holds - one of the values {@link KeyGenerator.getTempKeys} returns. Always false for a multipart key. @deprecated Ask the entity instead: `em.getEntityByKey(key)?.entityAspect.hasTempKey`, or {@link EntityAspect.hasTempKey} when you have the entity. Breeze does not call it. It still works; it is not scheduled for removal. */ isTempKey(entityKey: EntityKey): boolean; }