@itwin/core-backend
Version:
iTwin.js backend components
262 lines • 9.68 kB
TypeScript
/** @packageDocumentation
* @module ECDb
*/
import { Id64String } from "@itwin/core-bentley";
import { AnyDb, SqliteChangeOp, SqliteChangesetReader, SqliteValueStage } from "./SqliteChangesetReader";
/**
* Record meta data for the change.
* @beta
* */
export interface ChangeMetaData {
/** list of tables making up this EC change */
tables: string[];
/** full name of the class of this EC change */
classFullName?: string;
/** sqlite operation that caused the change */
op: SqliteChangeOp;
/** version of the value read from sqlite change */
stage: SqliteValueStage;
/** if classId for the change was not found in db then fallback class for the table */
fallbackClassId?: Id64String;
/** list of change index making up this change (one per table) */
changeIndexes: number[];
}
/**
* Represent EC change derived from low level sqlite change
* @beta
*/
export interface ChangedECInstance {
ECInstanceId: Id64String;
ECClassId?: Id64String;
$meta?: ChangeMetaData;
[key: string]: any;
}
/**
* Represents a cache for unifying EC changes.
* @beta
*/
export interface ECChangeUnifierCache extends Disposable {
/**
* Retrieves the value associated with the specified key from the cache.
* @param key - The key to retrieve the value for.
* @returns The value associated with the key, or undefined if the key is not found.
*/
get(key: string): ChangedECInstance | undefined;
/**
* Sets the value associated with the specified key in the cache.
* @param key - The key to set the value for.
* @param value - The value to be associated with the key.
*/
set(key: string, value: ChangedECInstance): void;
/**
* Returns an iterator for all the values in the cache.
* @returns An iterator for all the values in the cache.
*/
all(): IterableIterator<ChangedECInstance>;
/**
* Returns the number of entries in the cache.
* @returns The number of entries in the cache.
*/
count(): number;
}
/** @beta */
export declare namespace ECChangeUnifierCache {
/**
* Creates and returns a new in-memory cache for EC change unification.
* @note This cache is fast but recommended for small to medium size changesets. As it store changes in memory using a hash map, it may run out of memory for larger changesets.
* @returns {ECChangeUnifierCache} An instance of cache that store changes in memory using a hash map.
*/
function createInMemoryCache(): ECChangeUnifierCache;
/**
* Creates an ECChangeUnifierCache that is backed by a database.
* @note This cache is suitable for larger changesets and uses SQLite to store changes. It is slower than the in-memory cache but can handle larger datasets without running out of memory.
* @param db - The database instance to use for caching.
* @param bufferedReadInstanceSizeInBytes - The size in bytes for buffered read instances. Defaults to 10 MB.
* @returns An instance of ECChangeUnifierCache backed by SQLite temp db.
*/
function createSqliteBackedCache(db: AnyDb, bufferedReadInstanceSizeInBytes?: number): ECChangeUnifierCache;
}
/**
* Combine partial changed instance into single instance.
* Partial changes is per table and a single instance can
* span multiple tables.
* @beta
*/
export declare class PartialECChangeUnifier implements Disposable {
private _db;
private _cache;
private _readonly;
constructor(_db: AnyDb, _cache?: ECChangeUnifierCache);
/**
* Dispose the instance.
*/
[Symbol.dispose](): void;
/**
* Get root class id for a given class
* @param classId given class id
* @param db use to find root class
* @returns return root class id
*/
private getRootClassId;
/**
* Checks if the given `rhsClassId` is an instance of the `lhsClassId`.
* @param rhsClassId The ID of the right-hand side class.
* @param lhsClassId The ID of the left-hand side class.
* @returns `true` if `rhsClassId` is an instance of `lhsClassId`, `false` otherwise.
*/
private instanceOf;
/**
* Combine partial instance with instance with same key if already exists.
* @param rhs partial instance
*/
private combine;
/**
* Returns the number of instances in the cache.
* @returns The number of instances in the cache.
*/
getInstanceCount(): number;
/**
* Build key from EC change.
* @param change EC change
* @returns key created from EC change.
*/
private buildKey;
/**
* Append partial changes which will be combine using there instance key.
* @note $meta property must be present on partial change as information
* in it is used to combine partial instances.
* @param adaptor changeset adaptor is use to read the partial EC change.
* @beta
*/
appendFrom(adaptor: ChangesetECAdaptor): void;
/**
* Returns complete EC change instances.
* @beta
*/
get instances(): IterableIterator<ChangedECInstance>;
}
/**
* Transform sqlite change to ec change. EC change is partial change as
* it is per table while a single instance can span multiple table.
* @note PrimitiveArray and StructArray are not supported types.
* @beta
*
*/
export declare class ChangesetECAdaptor implements Disposable {
readonly reader: SqliteChangesetReader;
readonly disableMetaData: boolean;
private readonly _mapCache;
private readonly _tableFilter;
private readonly _opFilter;
private readonly _classFilter;
private _allowedClasses;
/**
* set debug flags
*/
readonly debugFlags: {
replaceBlobWithEllipsis: boolean;
replaceGeomWithEllipsis: boolean;
replaceGuidWithEllipsis: boolean;
};
/**
* Return partial inserted instance
* For updates inserted represent new version of instance after update.
*/
inserted?: ChangedECInstance;
/**
* Return partial deleted instance.
* For updates deleted represent old version of instance before update.
*/
deleted?: ChangedECInstance;
/**
* Setup filter that will result in change enumeration restricted to
* list of tables added by acceptTable().
* @param table Name of the table
* @returns Fluent reference to ChangesetAdaptor.
*/
acceptTable(table: string): ChangesetECAdaptor;
/**
* Setup filter that will result in change enumeration restricted to
* list of op added by acceptOp().
* @param op
* @returns Fluent reference to ChangesetAdaptor.
*/
acceptOp(op: SqliteChangeOp): ChangesetECAdaptor;
/**
* Setup filter that will result in change enumeration restricted to
* list of class and its derived classes added by acceptClass().
* @param classFullName
* @returns
*/
acceptClass(classFullName: string): ChangesetECAdaptor;
private buildClassFilter;
/**
* Construct adaptor with a initialized reader.
* @note the changeset reader must have disableSchemaCheck
* set to false and db must also be set.
* @param reader wrap changeset reader.
*/
constructor(reader: SqliteChangesetReader, disableMetaData?: boolean);
/**
* dispose current instance and it will also dispose the changeset reader.
*/
[Symbol.dispose](): void;
/**
* close current instance and it will also close the changeset reader.
*/
close(): void;
/**
* Convert binary GUID into string GUID.
* @param binaryGUID binary version of guid.
* @returns GUID string.
*/
private static convertBinaryToGuid;
/**
* Set value use access string in a JS object.
* @param targetObj object that will be updated.
* @param accessString access string token separated by '.'.
*/
private static setValue;
/**
* Check if sqlite change table is a EC data table
* @param tableName name of the table.
* @returns true if table has EC data.
*/
isECTable(tableName: string): boolean;
/**
* Attempt find ECClassId from ECInstanceId for a change of type 'updated'.
* @param tableName name of the table to find ECClassId from given ECInstanceId
* @param instanceId instance id for which we need ECClassId for.
* @returns if successful returns ECClassId else return undefined.
*/
private getClassIdFromDb;
/** helper method around reader.op */
get op(): SqliteChangeOp;
/** Return true if current change is of type "Inserted" */
get isInserted(): boolean;
/** Return true if current change is of type "Deleted" */
get isDeleted(): boolean;
/** Return true if current change is of type "Updated" */
get isUpdated(): boolean;
/**
* Advance reader to next change or a change that meets the filter set in the current adaptor
* @returns return false if no more changes to read.
*/
step(): boolean;
/**
* Transform nav change column into navigation EC property
* @param prop navigation property definition.
* @param change sqlite change.
* @param out ec instance that will be updated with navigation property.
*/
private transformNavigationProperty;
/**
* Transform sqlite change into EC change.
* @param classMap classMap use to deserialize sqlite change into EC change.
* @param change sqlite change from changeset.
* @param table table definition of sqlite change provided.
* @param out EC changeset that will be updated with properties.
*/
private transform;
}
//# sourceMappingURL=ChangesetECAdaptor.d.ts.map