@itwin/presentation-common
Version:
Common pieces for iModel.js presentation packages
162 lines • 5.51 kB
TypeScript
/** @packageDocumentation
* @module Core
*/
import { GuidString } from "@itwin/core-bentley";
import { EntityProps } from "@itwin/core-common";
import { InstanceId, InstanceKey } from "./EC.js";
import { NodeKey } from "./hierarchy/Key.js";
/**
* A single key that identifies something in an iTwin.js application
* @public
*/
export type Key = Readonly<NodeKey> | Readonly<InstanceKey> | Readonly<EntityProps>;
/** @public */
export declare namespace Key {
/**
* Check if the supplied key is a `NodeKey`
*
* @deprecated in 5.2 - will not be removed until after 2026-10-01. Use the new [@itwin/presentation-hierarchies](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/README.md)
* package for creating hierarchies.
*/
function isNodeKey(key: Key): key is Extract<Key, Readonly<NodeKey>>;
/** Check if the supplied key is an `InstanceKey` */
function isInstanceKey(key: Key): key is Extract<Key, Readonly<InstanceKey>>;
/** Check if the supplied key is an `EntityProps` */
function isEntityProps(key: Key): key is Extract<Key, Readonly<EntityProps>>;
}
/**
* A type for multiple keys that identify something in iModel.js application
* @public
*/
export type Keys = ReadonlyArray<Key> | Readonly<KeySet>;
/**
* A data structure of serialized [[KeySet]]
* @public
*/
export interface KeySetJSON {
/** JSON representation of a list of instance keys */
instanceKeys: Array<[string, string]>;
/**
* An array of serialized node keys
*
* @deprecated in 5.2 - will not be removed until after 2026-10-01. Use the new [@itwin/presentation-hierarchies](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/README.md)
* package for creating hierarchies.
*/
nodeKeys: NodeKey[];
}
/**
* A class that holds multiple [[Key]] objects. It's basically
* used as a container that holds multiple keys of different types.
*
* @public
*/
export declare class KeySet {
private _instanceKeys;
private _lowerCaseMap;
private _nodeKeys;
private _guid;
/**
* Creates an instance of KeySet.
* @param source Optional source to initialize from.
*/
constructor(source?: Keys);
private recalculateGuid;
/**
* Get a GUID that identifies changes in this keyset. The value
* does not uniquely identify contents of the keyset, but it can be
* used to check whether keyset has changed.
*/
get guid(): GuidString;
/**
* Get a map of instance keys stored in this KeySet
*
* **Warning**: getting instance keys might be expensive for
* large KeySets.
*/
get instanceKeys(): Map<string, Set<InstanceId>>;
/**
* Get instance keys count
*/
get instanceKeysCount(): number;
/**
* Get a set of node keys stored in this KeySet
*
* **Warning**: getting node keys might be expensive for large KeySets.
*
* @deprecated in 5.2 - will not be removed until after 2026-10-01. Use the new [@itwin/presentation-hierarchies](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/README.md)
* package for creating hierarchies.
*/
get nodeKeys(): Set<NodeKey>;
/**
* Get node keys count
*
* @deprecated in 5.2 - will not be removed until after 2026-10-01. Use the new [@itwin/presentation-hierarchies](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/README.md)
* package for creating hierarchies.
*/
get nodeKeysCount(): number;
private isKeySet;
private isKeysArray;
/**
* Clear this KeySet.
* @returns itself
*/
clear(): KeySet;
private addKeySet;
private addKeySetJSON;
/**
* Add a key or keys to this KeySet.
* @param value A key or keys to add.
* @param pred An optional predicate function that indicates whether a key should be added
* @returns itself
*/
add(value: Keys | Key, pred?: (key: Key) => boolean): KeySet;
private deleteKeySet;
/**
* Deletes a key or keys from this KeySet.
* @param value A key or keys to delete.
* @returns itself
*/
delete(value: Keys | Key): KeySet;
/**
* Check if this KeySet contains the specified key.
* @param value The key to check.
*/
has(value: Key): boolean;
private hasKeySet;
private hasKeysArray;
/**
* Check if this KeySet contains all the specified keys.
* @param keys The keys to check.
*/
hasAll(keys: Keys): boolean;
/**
* Check if this KeySet contains any of the specified keys.
* @param keys The keys to check.
*/
hasAny(keys: Keys): boolean;
/**
* Get the number of keys stored in this KeySet.
*/
get size(): number;
/**
* Is this KeySet currently empty.
*/
get isEmpty(): boolean;
/** Iterate over all keys in this keyset. */
some(callback: (key: Key) => boolean): boolean;
/** Iterate over all keys in this keyset. */
forEach(callback: (key: InstanceKey | NodeKey, index: number) => void): void;
/** Iterate over all keys in this keyset in batches */
forEachBatch(batchSize: number, callback: (batch: KeySet, index: number) => void): void;
/**
* Serializes this KeySet to JSON
* @public
*/
toJSON(): KeySetJSON;
/**
* Creates a KeySet from JSON
* @public
*/
static fromJSON(json: KeySetJSON): KeySet;
}
//# sourceMappingURL=KeySet.d.ts.map