import { EntityType, MetadataStore } from '../metadata/entity-metadata.js'; import type { Entity } from './entity-aspect.js'; /** An EntityKey is an object that represents the unique identity of an entity. EntityKey's are immutable. */ export declare class EntityKey { /** The 'EntityType' that this is a key for. __Read Only__ */ entityType: EntityType; /** An array of the values for this key. This will usually only have a single element, unless the entity type has a multipart key. __Read Only__ */ values: any[]; /** Constructs a new EntityKey. Each entity within an EntityManager will have a unique EntityKey. ```ts // assume Employee is registered with the MetadataStore const entityKey = new EntityKey(Employee, 1); ``` EntityKey's may also be found by calling EntityAspect.getKey() ```ts // assume employee1 is an existing Employee entity const empKey = employee1.entityAspect.getKey(); ``` A key of more than one property is clearest given by name, in any order: ```ts const detailKey = new EntityKey(OrderDetail, { orderID: 10248, productID: 11 }); ``` or as an array, in the order of the type's {@link EntityType.keyProperties}: the order of the key's definition on the server - `HasKey(od => new { od.OrderID, od.ProductID })` - which a generated entity class states in its doc comment, as `Key: orderID, productID`. ```ts const sameKey = new EntityKey(OrderDetail, [10248, 11]); ``` A wrong order is not an error - it is a valid key for another row - which is why the named form is better for these. @param entityType - The {@link EntityType} of the entity, or a class registered for it with {@link MetadataStore.registerEntityTypeCtor}. @param keyValues - The key's value; for a key of more than one property, an object of values by property name, or an array in key order. A named value that is not part of the key, or a key property with no value, throws. */ constructor(entityType: EntityType | (new () => Entity), keyValues: any); /** Returns the plain form of this key - `{ entityType, values }`, with the entity type's qualified name - which `JSON.stringify` uses and {@link EntityKey.fromJSON} turns back into a key. Breeze uses it to record temporary keys in an {@link EntityManager.exportEntities} bundle. */ toJSON(): { /** The qualified name of the key's entity type, such as `"Customer:#Northwind.Models"`. */ entityType: string; /** The key's values, one per key property. */ values: any[]; }; /** Recreates a key from the output of {@link EntityKey.toJSON}, looking its entity type up in `metadataStore`. Throws if the type is not there. Used by {@link EntityManager.importEntities}. */ static fromJSON(json: any, metadataStore: MetadataStore): EntityKey; /** Used to compare EntityKeys are determine if they refer to the same Entity. There is also an static version of 'equals' with the same functionality. ```ts // assume Employee is registered with the MetadataStore const empKey1 = new EntityKey(Employee, 1); // assume employee1 is an existing Employee entity const empKey2 = employee1.entityAspect.getKey(); if (empKey1.equals(empKey2)) { // do something ... } ``` */ equals(entityKey: EntityKey): boolean; /** Returns this key as a string: the entity type's qualified name, a hyphen, and the key values joined by `:::` - such as `"Order:#Northwind.Models-10248"`. Given `altEntityType`, that type's name is used instead. Breeze uses this form in error messages and as the property names of an {@link ITempKeyMap}. */ toString(altEntityType?: EntityType): string; /** Used to compare EntityKeys are determine if they refer to the same Entity. There is also an instance version of 'equals' with the same functionality. ```ts // assume Employee is registered with the MetadataStore const empKey1 = new EntityKey(Employee, 1); // assume employee1 is an existing Employee entity const empKey2 = employee1.entityAspect.getKey(); if (EntityKey.equals(empKey1, empKey2)) { // do something ... } ``` */ static equals(k1: EntityKey, k2: EntityKey): boolean; /** hidden */ static createKeyString(keyValues: any[]): string; }