UNPKG

@itwin/core-backend

Version:
203 lines 6.98 kB
/** @packageDocumentation * @module ECDb */ import { Id64String } from "@itwin/core-bentley"; import { 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; } /** * 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 { private _cache; private _readonly; /** * 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 static getRootClassId; /** * Combine partial instance with instance with same key if already exists. * @param rhs partial instance */ private combine; /** * Build key from EC change. * @param change EC change * @returns key created from EC change. */ private static 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; /** * Delete $meta from all the instances. */ stripMetaData(): 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