@itwin/core-backend 5.13.0 → 5.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -119,7 +119,7 @@ export declare class Entity {
119
119
  * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.
120
120
  * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.
121
121
  * @throws Error if metadata for the class cannot be retrieved.
122
- * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` yourself. SchemaView does not expose the `BisCore.CustomHandledProperty` custom attribute, so the `includeCustom: false` filter must be replicated by the caller (query the custom-handled property set via ECSql) if needed.
122
+ * @deprecated in 5.10.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` yourself. SchemaView does not expose the `BisCore.CustomHandledProperty` custom attribute, so the `includeCustom: false` filter must be replicated by the caller (query the custom-handled property set via ECSql) if needed.
123
123
  *
124
124
  * @example
125
125
  * ```typescript
@@ -146,11 +146,11 @@ export declare class Entity {
146
146
  * @throws [[IModelError]] if there is a problem querying the schema
147
147
  * @returns The metadata for the current entity
148
148
  * @public @preview
149
- * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Obtain a `SchemaView` via `iModel.getSchemaView()` and call `view.findClass(entity.classFullName)` to retrieve a `SchemaView.Class`. The returned type differs from `EntityClass | RelationshipClass` and offers a synchronous, snapshot-style API.
149
+ * @deprecated in 5.10.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and call `view.findClass(entity.classFullName)` to retrieve a `SchemaView.Class`. The returned type differs from `EntityClass | RelationshipClass` and offers a synchronous, snapshot-style API.
150
150
  */
151
151
  getMetaData(): Promise<EntityClass | RelationshipClass>;
152
152
  /** @internal
153
- * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Internal callers should obtain a `SchemaView` via `iModel.getSchemaView()` (or retain a pre-loaded one) and call `view.findClass(...)` instead. Note that `getSchemaView()` is async.
153
+ * @deprecated in 5.10.0 - might be removed in next major version. Internal callers should obtain a `SchemaView` via `iModel.getSchemaView()` (or retain a pre-loaded one) and call `view.findClass(...)` instead. Note that `getSchemaView()` is async.
154
154
  */
155
155
  getMetaDataSync(): EntityClass | RelationshipClass;
156
156
  /** @internal */
package/lib/esm/Entity.js CHANGED
@@ -162,7 +162,7 @@ export class Entity {
162
162
  * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.
163
163
  * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.
164
164
  * @throws Error if metadata for the class cannot be retrieved.
165
- * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` yourself. SchemaView does not expose the `BisCore.CustomHandledProperty` custom attribute, so the `includeCustom: false` filter must be replicated by the caller (query the custom-handled property set via ECSql) if needed.
165
+ * @deprecated in 5.10.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` yourself. SchemaView does not expose the `BisCore.CustomHandledProperty` custom attribute, so the `includeCustom: false` filter must be replicated by the caller (query the custom-handled property set via ECSql) if needed.
166
166
  *
167
167
  * @example
168
168
  * ```typescript
@@ -200,7 +200,7 @@ export class Entity {
200
200
  * @throws [[IModelError]] if there is a problem querying the schema
201
201
  * @returns The metadata for the current entity
202
202
  * @public @preview
203
- * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Obtain a `SchemaView` via `iModel.getSchemaView()` and call `view.findClass(entity.classFullName)` to retrieve a `SchemaView.Class`. The returned type differs from `EntityClass | RelationshipClass` and offers a synchronous, snapshot-style API.
203
+ * @deprecated in 5.10.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and call `view.findClass(entity.classFullName)` to retrieve a `SchemaView.Class`. The returned type differs from `EntityClass | RelationshipClass` and offers a synchronous, snapshot-style API.
204
204
  */
205
205
  async getMetaData() {
206
206
  if (this._metadata) {
@@ -216,7 +216,7 @@ export class Entity {
216
216
  }
217
217
  }
218
218
  /** @internal
219
- * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Internal callers should obtain a `SchemaView` via `iModel.getSchemaView()` (or retain a pre-loaded one) and call `view.findClass(...)` instead. Note that `getSchemaView()` is async.
219
+ * @deprecated in 5.10.0 - might be removed in next major version. Internal callers should obtain a `SchemaView` via `iModel.getSchemaView()` (or retain a pre-loaded one) and call `view.findClass(...)` instead. Note that `getSchemaView()` is async.
220
220
  */
221
221
  getMetaDataSync() {
222
222
  if (this._metadata) {
@@ -1 +1 @@
1
- {"version":3,"file":"Entity.js","sourceRoot":"","sources":["../../src/Entity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAmC,kBAAkB,EAAsC,MAAM,oBAAoB,CAAC;AAG7H,OAAO,EAAE,OAAO,EAAE,WAAW,EAAY,iBAAiB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC5G,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAgC/C;;;;GAIG;AACH,MAAM,OAAO,MAAM;IACjB;;OAEG;IACa,kBAAkB,GAAG,IAAa,CAAC;IACnD,0CAA0C;IACnC,MAAM,CAAC,MAAM,CAAgB,CAAC,mGAAmG;IAExI,IAAY,KAAK,KAAoB,OAAO,IAAI,CAAC,WAA4B,CAAC,CAAC,CAAC;IAEhF;;;;OAIG;IACI,MAAM,KAAK,SAAS,KAAa,OAAO,QAAQ,CAAC,CAAC,CAAC;IAE1D;;OAEG;IACI,MAAM,KAAK,aAAa;QAC7B,gFAAgF;QAChF,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,M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E;;;;;OAKG;IACI,MAAM,CAAC,EAAE,CAAC,UAAyB;QACxC,6EAA6E;QAC7E,OAAO,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,SAAS,YAAY,UAAU,CAAC;IACrE,CAAC;IAED;;;OAGG;IACI,MAAM,KAAK,gBAAgB,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC;IAEtD;;;;;OAKG;IACI,eAAe;QACpB,MAAM,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC9C,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;QACvC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;;;;;OAOG;IACO,mBAAmB,CAAC,aAAiC;QAC7D,OAAO,CAAC,2BAA2B;IACrC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { ElementLoadOptions, EntityProps, EntityReferenceSet, PropertyCallback, PropertyMetaData } from \"@itwin/core-common\";\r\nimport type { IModelDb } from \"./IModelDb\";\r\nimport { Schema } from \"./Schema\";\r\nimport { ECClass, EntityClass, Property, RelationshipClass, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\n/** Represents a row returned by an ECSql query. The row is returned as a map of property names to values.\r\n * ECSqlRow has same schema as declared in ECSchema for the class and similar to if ECSQL SELECT * FROM <schema>:<class> were executed.\r\n * @beta */\r\nexport interface ECSqlRow {\r\n [key: string]: any\r\n}\r\n\r\n/** Set of properties that are used to deserialize an [[EntityProps]] from an ECSqlRow.\r\n * @beta */\r\nexport interface DeserializeEntityArgs {\r\n /** Row to deserialize */\r\n row: ECSqlRow;\r\n /** The IModel that contains this Entity */\r\n iModel: IModelDb;\r\n /** The options used when loading */\r\n options?: {\r\n /** Options used when loading an element */\r\n element?: ElementLoadOptions;\r\n }\r\n}\r\n\r\n/** A property of an [[Entity]] that needs to be custom handled during deserialization and serialization.\r\n * @beta */\r\nexport interface CustomHandledProperty {\r\n /** The name of the property as it appears in the ECSqlRow */\r\n readonly propertyName: string;\r\n /** Where the property is defined */\r\n readonly source: \"Class\" | \"Computed\";\r\n}\r\n\r\n/** Represents one of the fundamental building block in an [[IModelDb]]: as an [[Element]], [[Model]], or [[Relationship]].\r\n * Every subclass of Entity represents one BIS [ECClass]($ecschema-metadata).\r\n * An Entity is typically instantiated from an [EntityProps]($common) and can be converted back to this representation via [[Entity.toJSON]].\r\n * @public @preview\r\n */\r\nexport class Entity {\r\n /** An immutable property used to discriminate between [[Entity]] and [EntityProps]($common), used to inform the TypeScript compiler that these two types\r\n * are never substitutable for one another. To obtain an EntityProps from an Entity, use [[Entity.toJSON]].\r\n */\r\n public readonly isInstanceOfEntity = true as const;\r\n /** The Schema that defines this class. */\r\n public static schema: typeof Schema; // TODO: Schema key on the static level, but it requires a version which may differ between imodels\r\n\r\n private get _ctor(): typeof Entity { return this.constructor as typeof Entity; }\r\n\r\n /** The name of the BIS class associated with this class.\r\n * @note Every subclass of Entity **MUST** override this method to identify its BIS class.\r\n * Failure to do so will ordinarily result in an error when the class is registered, since there may only\r\n * be one JavaScript class for a given BIS class (usually the errant class will collide with its superclass.)\r\n */\r\n public static get className(): string { return \"Entity\"; }\r\n\r\n /** Serves as a unique identifier for this class. Typed variant of [[classFullName]].\r\n * @public @preview\r\n */\r\n public static get schemaItemKey(): SchemaItemKey {\r\n // We cannot cache this here because the className gets overridden in subclasses\r\n return new SchemaItemKey(this.className, this.schema.schemaKey);\r\n }\r\n\r\n /** Cached Metadata for the ECClass */\r\n protected _metadata?: EntityClass | RelationshipClass;\r\n\r\n /** When working with an Entity it can be useful to set property values directly, bypassing the compiler's type checking.\r\n * This property makes such code slightly less tedious to read and write.\r\n * @internal\r\n */\r\n public get asAny(): any { return this; }\r\n\r\n /** The name of the BIS Schema that defines this class */\r\n public get schemaName(): string { return this._ctor.schema.schemaName; }\r\n\r\n /** The name of the BIS class associated with this class. */\r\n public get className(): string { return this._ctor.className; }\r\n\r\n /** The [[IModelDb]] that contains this Entity */\r\n public iModel: IModelDb;\r\n\r\n /** The Id of this Entity. May be invalid if the Entity has not yet been saved in the database. */\r\n public id: Id64String;\r\n\r\n\r\n protected constructor(props: EntityProps, iModel: IModelDb) {\r\n this.iModel = iModel;\r\n this.id = Id64.fromJSON(props.id);\r\n // copy all auto-handled properties from input to the object being constructed\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n this.forEachProperty((propName: string, meta: PropertyMetaData) => (this as any)[propName] = meta.createProperty((props as any)[propName]), false);\r\n }\r\n\r\n /** Invoke the constructor of the specified `Entity` subclass.\r\n * @internal\r\n */\r\n public static instantiate(subclass: typeof Entity, props: EntityProps, iModel: IModelDb): Entity {\r\n return new subclass(props, iModel);\r\n }\r\n\r\n /** List of properties that are need to be custom handled during deserialization and serialization.\r\n * These properties differ between the ECSql instance of an Entity and the Entity itself.\r\n * @beta */\r\n protected static readonly _customHandledProps: CustomHandledProperty[] = [\r\n { propertyName: \"id\", source: \"Class\" },\r\n { propertyName: \"className\", source: \"Class\" },\r\n { propertyName: \"jsonProperties\", source: \"Class\" }\r\n ];\r\n\r\n /** Get the list of properties that are custom handled by this class and its superclasses.\r\n * @internal */\r\n private static getCustomHandledProperties(): readonly CustomHandledProperty[] {\r\n if (this.name === \"Entity\") {\r\n return this._customHandledProps;\r\n }\r\n\r\n const superClass = Object.getPrototypeOf(this) as typeof Entity;\r\n return [\r\n ...superClass.getCustomHandledProperties(),\r\n ...this._customHandledProps,\r\n ];\r\n }\r\n\r\n /** Converts an ECSqlRow of an Entity to an EntityProps. This is used to deserialize an Entity from the database.\r\n * @beta */\r\n public static deserialize(props: DeserializeEntityArgs): EntityProps {\r\n const enProps: EntityProps = {\r\n classFullName: props.row.classFullName,\r\n id: props.row.id,\r\n }\r\n\r\n // Handles cases where id64 ints are stored in the jsonProperties and converts them to hex before parsing as a json object in js\r\n if (props.row.jsonProperties) {\r\n enProps.jsonProperties = JSON.parse(props.iModel[_nativeDb].patchJsonProperties(props.row.jsonProperties));\r\n }\r\n // Auto handles all properties that are not in the 'customHandledProperties' list\r\n const customHandledProperties = this.getCustomHandledProperties();\r\n Object.keys(props.row)\r\n .filter((propertyName) => customHandledProperties.find((val) => val.propertyName === propertyName) === undefined)\r\n .forEach((propertyName) => (enProps as ECSqlRow)[propertyName] = props.row[propertyName]\r\n );\r\n // Handles custom relClassNames to use '.' instead of ':'\r\n Object.keys(enProps).forEach((propertyName) => {\r\n if ((enProps as ECSqlRow)[propertyName].relClassName !== undefined && propertyName !== \"modeledElement\" && propertyName !== \"parentModel\") {\r\n (enProps as ECSqlRow)[propertyName].relClassName = (enProps as ECSqlRow)[propertyName].relClassName.replace(':', '.');\r\n }\r\n });\r\n return enProps;\r\n }\r\n\r\n /** Converts an EntityProps to an ECSqlRow. This is used to serialize an Entity to prepare to write it to the database.\r\n * @beta */\r\n public static serialize(props: EntityProps, _iModel: IModelDb): ECSqlRow {\r\n const inst: ECSqlRow = {\r\n classFullName: props.classFullName,\r\n id: props.id,\r\n }\r\n\r\n const customHandledProperties = this.getCustomHandledProperties();\r\n Object.keys(props)\r\n .filter((propertyName) => customHandledProperties.find((val) => val.propertyName === propertyName) === undefined)\r\n .forEach((propertyName) => inst[propertyName] = (props as ECSqlRow)[propertyName]\r\n );\r\n return inst;\r\n }\r\n\r\n /** Obtain the JSON representation of this Entity. Subclasses of [[Entity]] typically override this method to return their corresponding sub-type of [EntityProps]($common) -\r\n * for example, [[GeometricElement.toJSON]] returns a [GeometricElementProps]($common).\r\n */\r\n public toJSON(): EntityProps {\r\n const val: any = {};\r\n val.classFullName = this.classFullName;\r\n if (Id64.isValid(this.id))\r\n val.id = this.id;\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n this.forEachProperty((propName: string) => val[propName] = (this as any)[propName], false);\r\n return val;\r\n }\r\n\r\n /** Call a function for each property of this Entity.\r\n * @param func The callback to be invoked on each property\r\n * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.\r\n * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.\r\n * @deprecated in 5.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` instead. (`forEach` is also deprecated.)\r\n *\r\n * @example\r\n * ```typescript\r\n * // Deprecated method\r\n * entity.forEachProperty((name, propMetaData) => {\r\n * console.log(`Property name: ${name}, Property type: ${propMetaData.primitiveType}`);\r\n * });\r\n *\r\n * // New method\r\n * entity.forEach((name, property) => {\r\n * console.log(`Property name: ${name}, Property type: ${property.propertyType}`);\r\n * });\r\n * ```\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public forEachProperty(func: PropertyCallback, includeCustom: boolean = true) {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n this.iModel.forEachMetaData(this.classFullName, true, func, includeCustom);\r\n }\r\n\r\n /**\r\n * Call a function for each property of this Entity.\r\n * @param func The callback to be invoked on each property.\r\n * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.\r\n * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.\r\n * @throws Error if metadata for the class cannot be retrieved.\r\n * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` yourself. SchemaView does not expose the `BisCore.CustomHandledProperty` custom attribute, so the `includeCustom: false` filter must be replicated by the caller (query the custom-handled property set via ECSql) if needed.\r\n *\r\n * @example\r\n * ```typescript\r\n * const view = await entity.iModel.getSchemaView();\r\n * const cls = view.findClass(entity.classFullName);\r\n * if (cls) {\r\n * for (const property of cls.getProperties()) {\r\n * console.log(`Property name: ${property.name}, Kind: ${property.kind}`);\r\n * }\r\n * }\r\n * ```\r\n */\r\n public forEach(func: PropertyHandler, includeCustom: boolean = true) {\r\n const item = this._metadata ?? this.iModel.schemaContext.getSchemaItemSync(this.schemaItemKey);\r\n\r\n if (EntityClass.isEntityClass(item) || RelationshipClass.isRelationshipClass(item)) {\r\n for (const property of item.getPropertiesSync()) {\r\n if (includeCustom || !property.customAttributes?.has(`BisCore.CustomHandledProperty`))\r\n func(property.name, property);\r\n }\r\n } else {\r\n throw new Error(`Cannot get metadata for ${this.classFullName}. Class is not an EntityClass or RelationshipClass.`);\r\n }\r\n }\r\n\r\n /** Get the full BIS class name of this Entity in the form \"schema:class\" */\r\n public static get classFullName(): string { return `${this.schema.schemaName}:${this.className}`; }\r\n\r\n /** Get the full BIS class name of this Entity in the form \"schema:class\". */\r\n public get classFullName(): string { return this._ctor.classFullName; }\r\n /**\r\n * Get the item key used by the ecschema-metadata package to identify this entity class\r\n * @public @preview\r\n */\r\n public get schemaItemKey(): SchemaItemKey { return this._ctor.schemaItemKey; }\r\n\r\n /** Query metadata for this entity class from the iModel's schema. Returns cached metadata if available.\r\n * @throws [[IModelError]] if there is a problem querying the schema\r\n * @returns The metadata for the current entity\r\n * @public @preview\r\n * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Obtain a `SchemaView` via `iModel.getSchemaView()` and call `view.findClass(entity.classFullName)` to retrieve a `SchemaView.Class`. The returned type differs from `EntityClass | RelationshipClass` and offers a synchronous, snapshot-style API.\r\n */\r\n public async getMetaData(): Promise<EntityClass | RelationshipClass> {\r\n if (this._metadata) {\r\n return this._metadata;\r\n }\r\n\r\n const ecClass = await this.iModel.schemaContext.getSchemaItem(this.schemaItemKey, ECClass);\r\n if (EntityClass.isEntityClass(ecClass) || RelationshipClass.isRelationshipClass(ecClass)) {\r\n this._metadata = ecClass;\r\n return this._metadata;\r\n } else {\r\n throw new Error(`Cannot get metadata for ${this.classFullName}`);\r\n }\r\n }\r\n\r\n /** @internal\r\n * @deprecated in 5.10.0 - will not be removed until after 2026-09-03. Internal callers should obtain a `SchemaView` via `iModel.getSchemaView()` (or retain a pre-loaded one) and call `view.findClass(...)` instead. Note that `getSchemaView()` is async.\r\n */\r\n public getMetaDataSync(): EntityClass | RelationshipClass {\r\n if (this._metadata) {\r\n return this._metadata;\r\n }\r\n\r\n const ecClass = this.iModel.schemaContext.getSchemaItemSync(this.schemaItemKey, ECClass);\r\n if (EntityClass.isEntityClass(ecClass) || RelationshipClass.isRelationshipClass(ecClass)) {\r\n this._metadata = ecClass;\r\n return this._metadata;\r\n } else {\r\n throw new Error(`Cannot get metadata for ${this.classFullName}`);\r\n }\r\n }\r\n \r\n /** @internal */\r\n public static get protectedOperations(): string[] { return []; }\r\n\r\n /** return whether this Entity class is a subclass of another Entity class\r\n * @note the subclass-ness is checked according to JavaScript inheritance, to check the underlying raw EC class's\r\n * inheritance, you can use [ECClass.is]($ecschema-metadata)\r\n * @note this should have a type of `is<T extends typeof Entity>(otherClass: T): this is T` but can't because of\r\n * typescript's restriction on the `this` type in static methods\r\n */\r\n public static is(otherClass: typeof Entity): boolean {\r\n // inline of @itwin/core-bentley's isSubclassOf due to protected constructor.\r\n return this === otherClass || this.prototype instanceof otherClass;\r\n }\r\n\r\n /** whether this JavaScript class was generated for this ECClass because there was no registered custom implementation\r\n * ClassRegistry overrides this when generating a class\r\n * @internal\r\n */\r\n public static get isGeneratedClass() { return false; }\r\n\r\n /** Get the set of this entity's *entity references*, [EntityReferenceSet]($backend). An *entity reference* is any id\r\n * stored on the entity, in its EC properties or json fields.\r\n * This is important for cloning operations but can be useful in other situations as well.\r\n * @see this.collectReferenceIds\r\n * @beta\r\n */\r\n public getReferenceIds(): EntityReferenceSet {\r\n const referenceIds = new EntityReferenceSet();\r\n this.collectReferenceIds(referenceIds);\r\n return referenceIds;\r\n }\r\n\r\n /** Collect the Ids of this entity's *references* at this level of the class hierarchy.\r\n * A *reference* is any entity referenced by this entity's EC Data, including json fields.\r\n * This is important for cloning operations but can be useful in other situations as well.\r\n * @param _referenceIds The Id64Set to populate with reference Ids.\r\n * @note This should be overridden (with `super` called) at each level the class hierarchy that introduces references.\r\n * @see getReferenceIds\r\n * @beta\r\n */\r\n protected collectReferenceIds(_referenceIds: EntityReferenceSet): void {\r\n return; // no references by default\r\n }\r\n}\r\n\r\n/** A callback function to process properties of an Entity\r\n * @public @preview\r\n */\r\nexport type PropertyHandler = (name: string, property: Property) => void;\r\n\r\n/** Parameter type that can accept both abstract constructor types and non-abstract constructor types for `instanceof` to test.\r\n * @public @preview\r\n */\r\nexport type EntityClassType<T> = Function & { prototype: T }; // eslint-disable-line @typescript-eslint/no-unsafe-function-type\r\n"]}
1
+ {"version":3,"file":"Entity.js","sourceRoot":"","sources":["../../src/Entity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAmC,kBAAkB,EAAsC,MAAM,oBAAoB,CAAC;AAG7H,OAAO,EAAE,OAAO,EAAE,WAAW,EAAY,iBAAiB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC5G,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAgC/C;;;;GAIG;AACH,MAAM,OAAO,MAAM;IACjB;;OAEG;IACa,kBAAkB,GAAG,IAAa,CAAC;IACnD,0CAA0C;IACnC,MAAM,CAAC,MAAM,CAAgB,CAAC,mGAAmG;IAExI,IAAY,KAAK,KAAoB,OAAO,IAAI,CAAC,WAA4B,CAAC,CAAC,CAAC;IAEhF;;;;OAIG;IACI,MAAM,KAAK,SAAS,KAAa,OAAO,QAAQ,CAAC,CAAC,CAAC;IAE1D;;OAEG;IACI,MAAM,KAAK,aAAa;QAC7B,gFAAgF;QAChF,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC;I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UAAyB;QACxC,6EAA6E;QAC7E,OAAO,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,SAAS,YAAY,UAAU,CAAC;IACrE,CAAC;IAED;;;OAGG;IACI,MAAM,KAAK,gBAAgB,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC;IAEtD;;;;;OAKG;IACI,eAAe;QACpB,MAAM,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC9C,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;QACvC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;;;;;OAOG;IACO,mBAAmB,CAAC,aAAiC;QAC7D,OAAO,CAAC,2BAA2B;IACrC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { ElementLoadOptions, EntityProps, EntityReferenceSet, PropertyCallback, PropertyMetaData } from \"@itwin/core-common\";\r\nimport type { IModelDb } from \"./IModelDb\";\r\nimport { Schema } from \"./Schema\";\r\nimport { ECClass, EntityClass, Property, RelationshipClass, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\n/** Represents a row returned by an ECSql query. The row is returned as a map of property names to values.\r\n * ECSqlRow has same schema as declared in ECSchema for the class and similar to if ECSQL SELECT * FROM <schema>:<class> were executed.\r\n * @beta */\r\nexport interface ECSqlRow {\r\n [key: string]: any\r\n}\r\n\r\n/** Set of properties that are used to deserialize an [[EntityProps]] from an ECSqlRow.\r\n * @beta */\r\nexport interface DeserializeEntityArgs {\r\n /** Row to deserialize */\r\n row: ECSqlRow;\r\n /** The IModel that contains this Entity */\r\n iModel: IModelDb;\r\n /** The options used when loading */\r\n options?: {\r\n /** Options used when loading an element */\r\n element?: ElementLoadOptions;\r\n }\r\n}\r\n\r\n/** A property of an [[Entity]] that needs to be custom handled during deserialization and serialization.\r\n * @beta */\r\nexport interface CustomHandledProperty {\r\n /** The name of the property as it appears in the ECSqlRow */\r\n readonly propertyName: string;\r\n /** Where the property is defined */\r\n readonly source: \"Class\" | \"Computed\";\r\n}\r\n\r\n/** Represents one of the fundamental building block in an [[IModelDb]]: as an [[Element]], [[Model]], or [[Relationship]].\r\n * Every subclass of Entity represents one BIS [ECClass]($ecschema-metadata).\r\n * An Entity is typically instantiated from an [EntityProps]($common) and can be converted back to this representation via [[Entity.toJSON]].\r\n * @public @preview\r\n */\r\nexport class Entity {\r\n /** An immutable property used to discriminate between [[Entity]] and [EntityProps]($common), used to inform the TypeScript compiler that these two types\r\n * are never substitutable for one another. To obtain an EntityProps from an Entity, use [[Entity.toJSON]].\r\n */\r\n public readonly isInstanceOfEntity = true as const;\r\n /** The Schema that defines this class. */\r\n public static schema: typeof Schema; // TODO: Schema key on the static level, but it requires a version which may differ between imodels\r\n\r\n private get _ctor(): typeof Entity { return this.constructor as typeof Entity; }\r\n\r\n /** The name of the BIS class associated with this class.\r\n * @note Every subclass of Entity **MUST** override this method to identify its BIS class.\r\n * Failure to do so will ordinarily result in an error when the class is registered, since there may only\r\n * be one JavaScript class for a given BIS class (usually the errant class will collide with its superclass.)\r\n */\r\n public static get className(): string { return \"Entity\"; }\r\n\r\n /** Serves as a unique identifier for this class. Typed variant of [[classFullName]].\r\n * @public @preview\r\n */\r\n public static get schemaItemKey(): SchemaItemKey {\r\n // We cannot cache this here because the className gets overridden in subclasses\r\n return new SchemaItemKey(this.className, this.schema.schemaKey);\r\n }\r\n\r\n /** Cached Metadata for the ECClass */\r\n protected _metadata?: EntityClass | RelationshipClass;\r\n\r\n /** When working with an Entity it can be useful to set property values directly, bypassing the compiler's type checking.\r\n * This property makes such code slightly less tedious to read and write.\r\n * @internal\r\n */\r\n public get asAny(): any { return this; }\r\n\r\n /** The name of the BIS Schema that defines this class */\r\n public get schemaName(): string { return this._ctor.schema.schemaName; }\r\n\r\n /** The name of the BIS class associated with this class. */\r\n public get className(): string { return this._ctor.className; }\r\n\r\n /** The [[IModelDb]] that contains this Entity */\r\n public iModel: IModelDb;\r\n\r\n /** The Id of this Entity. May be invalid if the Entity has not yet been saved in the database. */\r\n public id: Id64String;\r\n\r\n\r\n protected constructor(props: EntityProps, iModel: IModelDb) {\r\n this.iModel = iModel;\r\n this.id = Id64.fromJSON(props.id);\r\n // copy all auto-handled properties from input to the object being constructed\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n this.forEachProperty((propName: string, meta: PropertyMetaData) => (this as any)[propName] = meta.createProperty((props as any)[propName]), false);\r\n }\r\n\r\n /** Invoke the constructor of the specified `Entity` subclass.\r\n * @internal\r\n */\r\n public static instantiate(subclass: typeof Entity, props: EntityProps, iModel: IModelDb): Entity {\r\n return new subclass(props, iModel);\r\n }\r\n\r\n /** List of properties that are need to be custom handled during deserialization and serialization.\r\n * These properties differ between the ECSql instance of an Entity and the Entity itself.\r\n * @beta */\r\n protected static readonly _customHandledProps: CustomHandledProperty[] = [\r\n { propertyName: \"id\", source: \"Class\" },\r\n { propertyName: \"className\", source: \"Class\" },\r\n { propertyName: \"jsonProperties\", source: \"Class\" }\r\n ];\r\n\r\n /** Get the list of properties that are custom handled by this class and its superclasses.\r\n * @internal */\r\n private static getCustomHandledProperties(): readonly CustomHandledProperty[] {\r\n if (this.name === \"Entity\") {\r\n return this._customHandledProps;\r\n }\r\n\r\n const superClass = Object.getPrototypeOf(this) as typeof Entity;\r\n return [\r\n ...superClass.getCustomHandledProperties(),\r\n ...this._customHandledProps,\r\n ];\r\n }\r\n\r\n /** Converts an ECSqlRow of an Entity to an EntityProps. This is used to deserialize an Entity from the database.\r\n * @beta */\r\n public static deserialize(props: DeserializeEntityArgs): EntityProps {\r\n const enProps: EntityProps = {\r\n classFullName: props.row.classFullName,\r\n id: props.row.id,\r\n }\r\n\r\n // Handles cases where id64 ints are stored in the jsonProperties and converts them to hex before parsing as a json object in js\r\n if (props.row.jsonProperties) {\r\n enProps.jsonProperties = JSON.parse(props.iModel[_nativeDb].patchJsonProperties(props.row.jsonProperties));\r\n }\r\n // Auto handles all properties that are not in the 'customHandledProperties' list\r\n const customHandledProperties = this.getCustomHandledProperties();\r\n Object.keys(props.row)\r\n .filter((propertyName) => customHandledProperties.find((val) => val.propertyName === propertyName) === undefined)\r\n .forEach((propertyName) => (enProps as ECSqlRow)[propertyName] = props.row[propertyName]\r\n );\r\n // Handles custom relClassNames to use '.' instead of ':'\r\n Object.keys(enProps).forEach((propertyName) => {\r\n if ((enProps as ECSqlRow)[propertyName].relClassName !== undefined && propertyName !== \"modeledElement\" && propertyName !== \"parentModel\") {\r\n (enProps as ECSqlRow)[propertyName].relClassName = (enProps as ECSqlRow)[propertyName].relClassName.replace(':', '.');\r\n }\r\n });\r\n return enProps;\r\n }\r\n\r\n /** Converts an EntityProps to an ECSqlRow. This is used to serialize an Entity to prepare to write it to the database.\r\n * @beta */\r\n public static serialize(props: EntityProps, _iModel: IModelDb): ECSqlRow {\r\n const inst: ECSqlRow = {\r\n classFullName: props.classFullName,\r\n id: props.id,\r\n }\r\n\r\n const customHandledProperties = this.getCustomHandledProperties();\r\n Object.keys(props)\r\n .filter((propertyName) => customHandledProperties.find((val) => val.propertyName === propertyName) === undefined)\r\n .forEach((propertyName) => inst[propertyName] = (props as ECSqlRow)[propertyName]\r\n );\r\n return inst;\r\n }\r\n\r\n /** Obtain the JSON representation of this Entity. Subclasses of [[Entity]] typically override this method to return their corresponding sub-type of [EntityProps]($common) -\r\n * for example, [[GeometricElement.toJSON]] returns a [GeometricElementProps]($common).\r\n */\r\n public toJSON(): EntityProps {\r\n const val: any = {};\r\n val.classFullName = this.classFullName;\r\n if (Id64.isValid(this.id))\r\n val.id = this.id;\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n this.forEachProperty((propName: string) => val[propName] = (this as any)[propName], false);\r\n return val;\r\n }\r\n\r\n /** Call a function for each property of this Entity.\r\n * @param func The callback to be invoked on each property\r\n * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.\r\n * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.\r\n * @deprecated in 5.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` instead. (`forEach` is also deprecated.)\r\n *\r\n * @example\r\n * ```typescript\r\n * // Deprecated method\r\n * entity.forEachProperty((name, propMetaData) => {\r\n * console.log(`Property name: ${name}, Property type: ${propMetaData.primitiveType}`);\r\n * });\r\n *\r\n * // New method\r\n * entity.forEach((name, property) => {\r\n * console.log(`Property name: ${name}, Property type: ${property.propertyType}`);\r\n * });\r\n * ```\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public forEachProperty(func: PropertyCallback, includeCustom: boolean = true) {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n this.iModel.forEachMetaData(this.classFullName, true, func, includeCustom);\r\n }\r\n\r\n /**\r\n * Call a function for each property of this Entity.\r\n * @param func The callback to be invoked on each property.\r\n * @param includeCustom If true (default), include custom-handled properties in the iteration. Otherwise, skip custom-handled properties.\r\n * @note Custom-handled properties are core properties that have behavior enforced by C++ handlers.\r\n * @throws Error if metadata for the class cannot be retrieved.\r\n * @deprecated in 5.10.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and iterate `view.findClass(entity.classFullName)?.getProperties()` yourself. SchemaView does not expose the `BisCore.CustomHandledProperty` custom attribute, so the `includeCustom: false` filter must be replicated by the caller (query the custom-handled property set via ECSql) if needed.\r\n *\r\n * @example\r\n * ```typescript\r\n * const view = await entity.iModel.getSchemaView();\r\n * const cls = view.findClass(entity.classFullName);\r\n * if (cls) {\r\n * for (const property of cls.getProperties()) {\r\n * console.log(`Property name: ${property.name}, Kind: ${property.kind}`);\r\n * }\r\n * }\r\n * ```\r\n */\r\n public forEach(func: PropertyHandler, includeCustom: boolean = true) {\r\n const item = this._metadata ?? this.iModel.schemaContext.getSchemaItemSync(this.schemaItemKey);\r\n\r\n if (EntityClass.isEntityClass(item) || RelationshipClass.isRelationshipClass(item)) {\r\n for (const property of item.getPropertiesSync()) {\r\n if (includeCustom || !property.customAttributes?.has(`BisCore.CustomHandledProperty`))\r\n func(property.name, property);\r\n }\r\n } else {\r\n throw new Error(`Cannot get metadata for ${this.classFullName}. Class is not an EntityClass or RelationshipClass.`);\r\n }\r\n }\r\n\r\n /** Get the full BIS class name of this Entity in the form \"schema:class\" */\r\n public static get classFullName(): string { return `${this.schema.schemaName}:${this.className}`; }\r\n\r\n /** Get the full BIS class name of this Entity in the form \"schema:class\". */\r\n public get classFullName(): string { return this._ctor.classFullName; }\r\n /**\r\n * Get the item key used by the ecschema-metadata package to identify this entity class\r\n * @public @preview\r\n */\r\n public get schemaItemKey(): SchemaItemKey { return this._ctor.schemaItemKey; }\r\n\r\n /** Query metadata for this entity class from the iModel's schema. Returns cached metadata if available.\r\n * @throws [[IModelError]] if there is a problem querying the schema\r\n * @returns The metadata for the current entity\r\n * @public @preview\r\n * @deprecated in 5.10.0 - might be removed in next major version. Obtain a `SchemaView` via `iModel.getSchemaView()` and call `view.findClass(entity.classFullName)` to retrieve a `SchemaView.Class`. The returned type differs from `EntityClass | RelationshipClass` and offers a synchronous, snapshot-style API.\r\n */\r\n public async getMetaData(): Promise<EntityClass | RelationshipClass> {\r\n if (this._metadata) {\r\n return this._metadata;\r\n }\r\n\r\n const ecClass = await this.iModel.schemaContext.getSchemaItem(this.schemaItemKey, ECClass);\r\n if (EntityClass.isEntityClass(ecClass) || RelationshipClass.isRelationshipClass(ecClass)) {\r\n this._metadata = ecClass;\r\n return this._metadata;\r\n } else {\r\n throw new Error(`Cannot get metadata for ${this.classFullName}`);\r\n }\r\n }\r\n\r\n /** @internal\r\n * @deprecated in 5.10.0 - might be removed in next major version. Internal callers should obtain a `SchemaView` via `iModel.getSchemaView()` (or retain a pre-loaded one) and call `view.findClass(...)` instead. Note that `getSchemaView()` is async.\r\n */\r\n public getMetaDataSync(): EntityClass | RelationshipClass {\r\n if (this._metadata) {\r\n return this._metadata;\r\n }\r\n\r\n const ecClass = this.iModel.schemaContext.getSchemaItemSync(this.schemaItemKey, ECClass);\r\n if (EntityClass.isEntityClass(ecClass) || RelationshipClass.isRelationshipClass(ecClass)) {\r\n this._metadata = ecClass;\r\n return this._metadata;\r\n } else {\r\n throw new Error(`Cannot get metadata for ${this.classFullName}`);\r\n }\r\n }\r\n \r\n /** @internal */\r\n public static get protectedOperations(): string[] { return []; }\r\n\r\n /** return whether this Entity class is a subclass of another Entity class\r\n * @note the subclass-ness is checked according to JavaScript inheritance, to check the underlying raw EC class's\r\n * inheritance, you can use [ECClass.is]($ecschema-metadata)\r\n * @note this should have a type of `is<T extends typeof Entity>(otherClass: T): this is T` but can't because of\r\n * typescript's restriction on the `this` type in static methods\r\n */\r\n public static is(otherClass: typeof Entity): boolean {\r\n // inline of @itwin/core-bentley's isSubclassOf due to protected constructor.\r\n return this === otherClass || this.prototype instanceof otherClass;\r\n }\r\n\r\n /** whether this JavaScript class was generated for this ECClass because there was no registered custom implementation\r\n * ClassRegistry overrides this when generating a class\r\n * @internal\r\n */\r\n public static get isGeneratedClass() { return false; }\r\n\r\n /** Get the set of this entity's *entity references*, [EntityReferenceSet]($backend). An *entity reference* is any id\r\n * stored on the entity, in its EC properties or json fields.\r\n * This is important for cloning operations but can be useful in other situations as well.\r\n * @see this.collectReferenceIds\r\n * @beta\r\n */\r\n public getReferenceIds(): EntityReferenceSet {\r\n const referenceIds = new EntityReferenceSet();\r\n this.collectReferenceIds(referenceIds);\r\n return referenceIds;\r\n }\r\n\r\n /** Collect the Ids of this entity's *references* at this level of the class hierarchy.\r\n * A *reference* is any entity referenced by this entity's EC Data, including json fields.\r\n * This is important for cloning operations but can be useful in other situations as well.\r\n * @param _referenceIds The Id64Set to populate with reference Ids.\r\n * @note This should be overridden (with `super` called) at each level the class hierarchy that introduces references.\r\n * @see getReferenceIds\r\n * @beta\r\n */\r\n protected collectReferenceIds(_referenceIds: EntityReferenceSet): void {\r\n return; // no references by default\r\n }\r\n}\r\n\r\n/** A callback function to process properties of an Entity\r\n * @public @preview\r\n */\r\nexport type PropertyHandler = (name: string, property: Property) => void;\r\n\r\n/** Parameter type that can accept both abstract constructor types and non-abstract constructor types for `instanceof` to test.\r\n * @public @preview\r\n */\r\nexport type EntityClassType<T> = Function & { prototype: T }; // eslint-disable-line @typescript-eslint/no-unsafe-function-type\r\n"]}
@@ -40,7 +40,7 @@ export declare namespace SchemaSync {
40
40
  private setNextReservedElementLocalId;
41
41
  }
42
42
  /** The `containerType` recorded on a BlobContainer that holds an iModel's `SchemaSyncDb`. */
43
- const containerType = "schema-sync";
43
+ const containerType = "schemasync";
44
44
  function setTestCache(iModel: IModelDb, cacheName?: string): void;
45
45
  /** Either an open iModel or the name of a closed briefcase file. Every local read below accepts both, so
46
46
  * a caller that has only a file name does not have to open a `BriefcaseDb` to ask a question about it.
@@ -176,7 +176,7 @@ export declare namespace SchemaSync {
176
176
  * @note this deletes any existing content in the container.
177
177
  */
178
178
  static initializeDb(props: CloudSqlite.ContainerProps): Promise<void>;
179
- /** Create and initialize a new `schema-sync` BlobContainer to hold a `SchemaSyncDb`. */
179
+ /** Create and initialize a new `schemasync` BlobContainer to hold a `SchemaSyncDb`. */
180
180
  static createNewContainer(args: CreateNewContainerProps): Promise<CloudSqlite.ContainerProps>;
181
181
  }
182
182
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaSync.d.ts","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,O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: "itwinjs", name: "SchemaSync" };
150
150
  const defaultDbName = "SchemaSyncDb";
151
151
  /** The `containerType` recorded on a BlobContainer that holds an iModel's `SchemaSyncDb`. */
152
- SchemaSync.containerType = "schema-sync";
152
+ SchemaSync.containerType = "schemasync";
153
153
  const testSyncCachePropKey = "test.schema_sync.cache_name";
154
154
  // for tests only
155
155
  function setTestCache(iModel, cacheName) {
@@ -477,7 +477,7 @@ export var SchemaSync;
477
477
  static async initializeDb(props) {
478
478
  return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });
479
479
  }
480
- /** Create and initialize a new `schema-sync` BlobContainer to hold a `SchemaSyncDb`. */
480
+ /** Create and initialize a new `schemasync` BlobContainer to hold a `SchemaSyncDb`. */
481
481
  static async createNewContainer(args) {
482
482
  const props = await this.createBlobContainer({ scope: args.scope, metadata: { ...args.metadata, containerType: SchemaSync.containerType } });
483
483
  await this.initializeDb(props);
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaSync.js","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAY,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAc,IAAI,EAAc,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClJ,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,uBAAuB,EAAqB,WAAW,EAAiB,MAAM,oBAAoB,CAAC;AAGpI,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAA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AQ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,aAAa,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1I,CAAC;QACD;;;;SAIC;QACM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAAiC;YAChE,OAAO,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACrF,CAAC;QAED,wFAAwF;QACjF,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAA6B;YAClE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAb,WAAA,aAAa,EAAE,EAAE,CAAC,CAAC;YACnH,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAC/B,OAAO,KAAK,CAAC;QACf,CAAC;KACF;IAvBY,sBAAW,cAuBvB,CAAA;AACH,CAAC,EAnlBgB,UAAU,KAAV,UAAU,QAmlB1B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport * as semver from \"semver\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { SQLiteDb, VersionedSqliteDb } from \"./SQLiteDb\";\r\nimport { BriefcaseDb, IModelDb } from \"./IModelDb\";\r\nimport { BentleyError, ChangeSetStatus, DbResult, Guid, GuidString, Id64, Id64String, IModelStatus, Logger, OpenMode } from \"@itwin/core-bentley\";\r\nimport { BriefcaseIdValue, Code, ElementReservationError, FilePropertyProps, IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport type { BlobContainer } from \"./BlobContainerService\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { _implicitTxn, _nativeDb } from \"./internal/Symbols\";\r\n\r\n/** @internal */\r\nexport namespace SchemaSync {\r\n /** How long a briefcase waits for another briefcase's schema import to finish before giving up.\r\n *\r\n * `nRetries` alone does not bound the wait: when the count runs out `CloudSqlite.withLockedDb` asks\r\n * `onFailure` what to do, and anything other than \"stop\" restarts the whole cycle. Without an\r\n * `onFailure` the caller waits forever with no way to give up, so this supplies one.\r\n */\r\n const lockParams: CloudSqlite.ObtainLockParams = {\r\n retryDelayMs: 6000,\r\n nRetries: 10,\r\n onFailure: async (lockedBy: string, expires: string) => {\r\n Logger.logInfo(\"SchemaSync\", `schema sync container is held by ${lockedBy} until ${expires}; giving up`);\r\n return \"stop\";\r\n },\r\n };\r\n const reservedElementsTableName = \"reserved_elements\";\r\n const maxLocalIdExclusive = 0x10000000000; // 2^40\r\n const idSequenceProp: FilePropertyProps = { namespace: \"schemasync\", name: \"nextReservedElementLocalId\" };\r\n\r\n /** Identifies an element to be reserved in a `SchemaSyncDb`. @internal */\r\n export interface ProposedElementReservation {\r\n readonly federationGuid: GuidString;\r\n readonly ecClassId: Id64String;\r\n readonly code: Code;\r\n readonly isCategory?: boolean;\r\n }\r\n\r\n /** An element reservation that has been persisted in a `SchemaSyncDb`. @internal */\r\n export interface ReservedElement extends ProposedElementReservation {\r\n readonly elementId: Id64String;\r\n }\r\n\r\n export interface ReadMethods {\r\n /** Look up an existing element reservation by federationGuid. */\r\n findReservedElement(federationGuid: GuidString): ReservedElement | undefined;\r\n }\r\n\r\n export interface WriteMethods {\r\n /** Reserve the specified elements in the `SchemaSyncDb`. Throws if any requested reservation conflicts with an existing reservation. */\r\n reserveElements(identities: ProposedElementReservation[]): Promise<void>;\r\n }\r\n\r\n /** A CloudSqlite database for synchronizing schema changes across briefcases. */\r\n export class SchemaSyncDb extends VersionedSqliteDb implements ReadMethods, WriteMethods {\r\n private _supportsReservations?: boolean;\r\n public override readonly myVersion = \"5.0.0\";\r\n protected override createDDL() {\r\n this.ensureReservedElementsTable();\r\n }\r\n\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this._supportsReservations = semver.lte(this.myVersion, semver.minVersion(this.getRequiredVersions().readVersion) ?? \"0.0.0\");\r\n }\r\n\r\n private ensureReservedElementsTable(): void {\r\n if (this._supportsReservations)\r\n return;\r\n\r\n this.executeSQL(`\r\n CREATE TABLE IF NOT EXISTS ${reservedElementsTableName} (\r\n federationGuid BLOB PRIMARY KEY,\r\n elementId INTEGER NOT NULL UNIQUE,\r\n ecClassId INTEGER NOT NULL,\r\n codeSpecId INTEGER NOT NULL,\r\n codeScope TEXT NOT NULL,\r\n codeValue TEXT COLLATE NOCASE\r\n )`);\r\n this.executeSQL(`CREATE UNIQUE INDEX IF NOT EXISTS idx_reserved_elem_code ON ${reservedElementsTableName}(codeSpecId, codeScope, codeValue)`);\r\n const minVersion = `^${this.myVersion}`;\r\n this.setRequiredVersions({ readVersion: minVersion, writeVersion: minVersion });\r\n this._supportsReservations = true;\r\n }\r\n\r\n public findReservedElement(federationGuid: GuidString): ReservedElement | undefined {\r\n if (!this._supportsReservations)\r\n return undefined;\r\n\r\n return this.withPreparedSqliteStatement(\r\n `SELECT elementId, ecClassId, codeSpecId, codeScope, codeValue FROM ${reservedElementsTableName} WHERE federationGuid=?`,\r\n (stmt) => {\r\n stmt.bindGuid(1, federationGuid);\r\n if (!stmt.nextRow())\r\n return undefined;\r\n\r\n return {\r\n federationGuid,\r\n elementId: stmt.getValueId(0),\r\n ecClassId: stmt.getValueId(1),\r\n code: new Code({\r\n spec: stmt.getValueId(2),\r\n scope: stmt.getValueString(3),\r\n value: stmt.getValueStringMaybe(4),\r\n }),\r\n };\r\n },\r\n );\r\n }\r\n\r\n private insertReservedElement(id: ProposedElementReservation, elementId: Id64String): void {\r\n this.withPreparedSqliteStatement(\r\n `INSERT INTO ${reservedElementsTableName} (federationGuid, elementId, ecClassId, codeSpecId, codeScope, codeValue) VALUES (?, ?, ?, ?, ?, ?)`,\r\n (stmt) => {\r\n stmt.bindGuid(1, id.federationGuid);\r\n stmt.bindId(2, elementId);\r\n stmt.bindId(3, id.ecClassId);\r\n stmt.bindId(4, id.code.spec);\r\n stmt.bindString(5, id.code.scope);\r\n if (id.code.value === \"\")\r\n stmt.bindNull(6);\r\n else\r\n stmt.bindString(6, id.code.value);\r\n stmt.stepForWrite();\r\n },\r\n );\r\n }\r\n\r\n public async reserveElements(elements: ProposedElementReservation[]): Promise<void> {\r\n this.ensureReservedElementsTable();\r\n\r\n // Insert new reservations as we go, so later entries in `elements` can dedupe against earlier ones\r\n // through the shared (still-uncommitted) transaction. The caller commits on success and abandons on error.\r\n let nextLocalId = this.getNextReservedElementLocalId();\r\n const firstLocalId = nextLocalId;\r\n\r\n for (const def of elements) {\r\n if (!def.federationGuid || !Guid.isGuid(def.federationGuid)) {\r\n ElementReservationError.throwError(\"invalid-reservation\", {\r\n message: \"Element reservation requires an explicit, valid federationGuid\",\r\n });\r\n }\r\n\r\n // Identity is always the federationGuid. If a reservation already exists for it, it must match exactly.\r\n const existing = this.findReservedElement(def.federationGuid);\r\n if (existing) {\r\n if (!this.existingMatches(existing, def)) {\r\n ElementReservationError.throwError(\"reservation-conflict\", {\r\n message: `Element reservation conflict for federationGuid ${existing.federationGuid}: existing row does not match requested class/code`,\r\n federationGuid: existing.federationGuid,\r\n });\r\n }\r\n continue;\r\n }\r\n\r\n const elementId = Id64.fromLocalAndBriefcaseIds(nextLocalId, BriefcaseIdValue.SchemaSyncElementReserved);\r\n this.insertReservedElement(def, elementId);\r\n // skip a local id for each reserved category because category inserts always trigger a second insert for default subcategory\r\n nextLocalId += def.isCategory ? 2 : 1;\r\n if (nextLocalId >= maxLocalIdExclusive) {\r\n this.abandonChanges();\r\n ElementReservationError.throwError(\"id-sequence-exhausted\", { message: `SchemaSync reserved-element local-id sequence exhausted` });\r\n }\r\n }\r\n\r\n if (nextLocalId !== firstLocalId)\r\n this.setNextReservedElementLocalId(nextLocalId);\r\n }\r\n\r\n private existingMatches(existing: ProposedElementReservation, id: ProposedElementReservation): boolean {\r\n return existing.federationGuid === id.federationGuid\r\n && existing.ecClassId === id.ecClassId\r\n && existing.code.equals(id.code);\r\n }\r\n\r\n private getNextReservedElementLocalId(): number {\r\n const stored = this[_nativeDb].queryFileProperty(idSequenceProp, true) as string | undefined;\r\n const current = stored ? Number(stored) : 1;\r\n if (!Number.isInteger(current) || current < 1)\r\n ElementReservationError.throwError(\"corrupt-reservation-data\", { message: `Corrupt SchemaSync reserved-element local-id counter: '${stored}'` });\r\n\r\n return current;\r\n }\r\n\r\n private setNextReservedElementLocalId(next: number): void {\r\n this[_nativeDb].saveFileProperty(idSequenceProp, String(next));\r\n }\r\n }\r\n\r\n const syncProperty = { namespace: \"itwinjs\", name: \"SchemaSync\" };\r\n const defaultDbName = \"SchemaSyncDb\";\r\n /** The `containerType` recorded on a BlobContainer that holds an iModel's `SchemaSyncDb`. */\r\n export const containerType = \"schema-sync\";\r\n const testSyncCachePropKey = \"test.schema_sync.cache_name\";\r\n // for tests only\r\n export function setTestCache(iModel: IModelDb, cacheName?: string): void {\r\n if (cacheName)\r\n iModel[_nativeDb].saveLocalValue(testSyncCachePropKey, cacheName);\r\n else\r\n iModel[_nativeDb].deleteLocalValue(testSyncCachePropKey);\r\n }\r\n\r\n /** Either an open iModel or the name of a closed briefcase file. Every local read below accepts both, so\r\n * a caller that has only a file name does not have to open a `BriefcaseDb` to ask a question about it.\r\n */\r\n export type IModelOrFileName = IModelDb | { readonly fileName: LocalFileName };\r\n\r\n /** Read from an open iModel, or from a closed file opened readonly for the duration of `operation`. */\r\n function readFromIModel<T>(arg: IModelOrFileName, operation: (nativeDb: IModelJsNative.DgnDb) => T): T {\r\n if (arg instanceof IModelDb)\r\n return operation(arg[_nativeDb]);\r\n\r\n const nativeDb = new IModelNative.platform.DgnDb();\r\n nativeDb.openIModel(arg.fileName, OpenMode.Readonly);\r\n try {\r\n return operation(nativeDb);\r\n } finally {\r\n nativeDb.closeFile();\r\n }\r\n }\r\n\r\n /** Whether this iModel's ECSchemas are governed by a `SchemaSyncDb`.\r\n *\r\n * This is the single question every schema operation branches on. It reads one `be_Prop` row written when\r\n * schema sync was enabled and carried to every other briefcase by that changeset - no cloud access, and it\r\n * works on a readonly briefcase, a checkpoint, or a closed file.\r\n * @note This says nothing about whether the container is reachable, or even named. Use\r\n * [[queryContainerProps]] for that. The two are separate on purpose: a file that says it is governed by a\r\n * sync db must never fall back to importing schemas on its own, whatever state the container is in.\r\n */\r\n export function isEnabled(arg: IModelOrFileName): boolean {\r\n return readFromIModel(arg, (nativeDb) => nativeDb.schemaSyncEnabled());\r\n }\r\n\r\n /** One pass over the values schema sync keeps in the file: which container holds the sync db, plus the\r\n * test-only cache override. Read together so a closed file is opened once.\r\n */\r\n function readLocalSyncProps(arg: IModelOrFileName) {\r\n return readFromIModel(arg, (nativeDb) => {\r\n const propsString = nativeDb.queryFileProperty(syncProperty, true) as string | undefined;\r\n let containerProps: CloudSqlite.ContainerProps | undefined;\r\n if (propsString !== undefined) {\r\n try {\r\n containerProps = JSON.parse(propsString) as CloudSqlite.ContainerProps;\r\n } catch (e) {\r\n // Deliberately not swallowed into `undefined`: that would read as \"schema sync was never\r\n // enabled\" and let this briefcase import schemas on its own.\r\n throw new IModelError(DbResult.BE_SQLITE_CORRUPT, `iModel names a SchemaSyncDb container but the property cannot be read: ${BentleyError.getErrorMessage(e)}`);\r\n }\r\n }\r\n return {\r\n containerProps,\r\n testCacheName: nativeDb.queryLocalValue(testSyncCachePropKey),\r\n };\r\n });\r\n }\r\n\r\n /** The container holding this iModel's `SchemaSyncDb`, or `undefined` if schema sync was never enabled.\r\n *\r\n * Local read of the same `be_Prop` file property that [[initializeForIModel]] wrote. Requesting an access\r\n * token for the container is a separate, asynchronous step.\r\n */\r\n export function queryContainerProps(arg: IModelOrFileName): CloudSqlite.ContainerProps | undefined {\r\n return readLocalSyncProps(arg).containerProps;\r\n }\r\n\r\n interface SharedCloudAccess {\r\n access: CloudAccess;\r\n key: string;\r\n referenceCount: number;\r\n }\r\n\r\n const sharedAccessByContainer = new Map<string, SharedCloudAccess | Promise<SharedCloudAccess>>();\r\n const sharedAccessByInstance = new WeakMap<CloudAccess, SharedCloudAccess>();\r\n\r\n export async function getCloudAccess(arg: IModelOrFileName): Promise<CloudAccess> {\r\n const { containerProps, testCacheName } = readLocalSyncProps(arg);\r\n if (undefined === containerProps)\r\n throw new IModelError(DbResult.BE_SQLITE_NOTFOUND, \"iModel does not have a SchemaSyncDb\");\r\n\r\n const sharedAccessKey = JSON.stringify(containerProps) + (testCacheName ?? \"\");\r\n let shared = sharedAccessByContainer.get(sharedAccessKey);\r\n if (undefined === shared) {\r\n const pending = (async () => {\r\n const accessToken = await CloudSqlite.requestToken(containerProps);\r\n const access = new CloudAccess({ ...containerProps, accessToken });\r\n Object.assign(access.lockParams, lockParams);\r\n if (testCacheName)\r\n access.setCache(CloudSqlite.CloudCaches.getCache({ cacheName: testCacheName }));\r\n\r\n const created = { access, key: sharedAccessKey, referenceCount: 0 };\r\n sharedAccessByInstance.set(access, created);\r\n return created;\r\n })();\r\n sharedAccessByContainer.set(sharedAccessKey, pending);\r\n try {\r\n shared = await pending;\r\n if (sharedAccessByContainer.get(sharedAccessKey) === pending)\r\n sharedAccessByContainer.set(sharedAccessKey, shared);\r\n } catch (error) {\r\n if (sharedAccessByContainer.get(sharedAccessKey) === pending)\r\n sharedAccessByContainer.delete(sharedAccessKey);\r\n throw error;\r\n }\r\n } else if (shared instanceof Promise) {\r\n shared = await shared;\r\n }\r\n\r\n ++shared.referenceCount;\r\n return shared.access;\r\n }\r\n\r\n /** Release an access obtained through [[getCloudAccess]]. */\r\n export function releaseCloudAccess(access: CloudAccess): void {\r\n const shared = sharedAccessByInstance.get(access);\r\n if (undefined === shared) {\r\n access.close();\r\n return;\r\n }\r\n\r\n if (--shared.referenceCount > 0)\r\n return;\r\n\r\n sharedAccessByInstance.delete(access);\r\n if (sharedAccessByContainer.get(shared.key) === shared)\r\n sharedAccessByContainer.delete(shared.key);\r\n access.close();\r\n }\r\n\r\n /** Arguments for [[withLockedAccess]]. */\r\n export interface WithLockedAccessArgs {\r\n operationName: string;\r\n openMode?: OpenMode;\r\n user?: string;\r\n }\r\n\r\n export async function withLockedAccess(iModel: IModelOrFileName, args: WithLockedAccessArgs, operation: (access: CloudAccess) => Promise<void>): Promise<void> {\r\n const access = await SchemaSync.getCloudAccess(iModel);\r\n try {\r\n await access.withLockedDb(args, async () => operation(access));\r\n } finally {\r\n releaseCloudAccess(access);\r\n }\r\n }\r\n\r\n /** Build the tables and indexes the briefcase's `ec_` rows describe. A merged schema changeset carries\r\n * those rows but no DDL, so the physical columns are missing until this runs. Needs no cloud access.\r\n */\r\n export function updateDbSchema(iModel: IModelDb): void {\r\n if (isEnabled(iModel) && !iModel.isReadonly) {\r\n iModel.clearCaches();\r\n iModel[_nativeDb].schemaSyncUpdateDbSchema();\r\n iModel[_implicitTxn].saveChanges(\"materialized db schema from ec_ tables\");\r\n }\r\n }\r\n\r\n /** Whether a failed [[IModelDb.importSchemas]] can be retried through the upgrade path.\r\n *\r\n * The update tier refuses two kinds of change: one that has to move data between columns, and one\r\n * that destroys instances or property values. They arrive as different statuses because they are\r\n * different changes, but they mean one thing to a caller - this needs\r\n * [[BriefcaseDb.upgradeSchemas]], which takes the exclusive schema lock.\r\n *\r\n * The retry is the app's decision, not the platform's: taking that lock disturbs everyone else, so\r\n * only the app knows whether to do it now, schedule it, or tell the user.\r\n * ```ts\r\n * try {\r\n * await db.importSchemas(files);\r\n * } catch (e) {\r\n * if (!SchemaSync.requiresUpgrade(e)) throw e;\r\n * await db.upgradeSchemas(files, { description: \"...\" });\r\n * }\r\n * ```\r\n * @internal\r\n */\r\n export function requiresUpgrade(error: unknown): boolean {\r\n const errorNumber = (error as { errorNumber?: number } | undefined)?.errorNumber;\r\n return errorNumber === DbResult.BE_SQLITE_ERROR_DataTransformRequired\r\n || errorNumber === DbResult.BE_SQLITE_ERROR_DataDeletionRequired;\r\n }\r\n\r\n /** Arguments for [[createContainerForIModel]]. */\r\n export interface CreateContainerForIModelArgs {\r\n iModel: IModelDb;\r\n label?: string;\r\n description?: string;\r\n }\r\n\r\n /** Create a cloud container to hold this iModel's `SchemaSyncDb`, and initialize it as empty.\r\n *\r\n * The container is scoped to the iModel, so the service deletes it when the iModel is deleted. Pass the\r\n * returned props to [[initializeForIModel]] - the two calls together are what enables schema sync on an\r\n * iModel that was created without it.\r\n * @note The current user must be authorized to create containers for the iTwin.\r\n */\r\n export async function createContainerForIModel(arg: CreateContainerForIModelArgs): Promise<CloudSqlite.ContainerProps> {\r\n const iModel = arg.iModel;\r\n const iTwinId = iModel.iTwinId;\r\n if (undefined === iTwinId)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot create a SchemaSync container for an iModel that has no iTwin\");\r\n\r\n return CloudAccess.createNewContainer({\r\n scope: { iTwinId, iModelId: iModel.iModelId },\r\n metadata: { label: arg.label ?? `SchemaSync for ${iModel.name}`, description: arg.description },\r\n });\r\n }\r\n\r\n /** Arguments for [[initializeForIModel]]. */\r\n export interface InitializeForIModelArgs {\r\n iModel: IModelDb;\r\n containerProps: CloudSqlite.ContainerProps;\r\n /** Replace the container already recorded on this iModel instead of failing. */\r\n overrideContainer?: boolean;\r\n }\r\n\r\n /** Refuse initialization before a caller provisions a container, then hold the exclusive schema lock and pull to the tip. */\r\n async function prepareToInitializeForIModel(iModel: IModelDb, overrideContainer: boolean): Promise<BriefcaseDb | undefined> {\r\n const briefcase = iModel instanceof BriefcaseDb ? iModel : undefined;\r\n if (briefcase && !briefcase.locks.isServerBased)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot enable SchemaSync without server-based locking\");\r\n\r\n if (briefcase && (iModel[_nativeDb].hasUnsavedChanges() || briefcase.txns.hasLocalChanges))\r\n throw new IModelError(ChangeSetStatus.HasLocalChanges, \"Cannot enable SchemaSync while there are local changes\");\r\n\r\n const assertContainerCanBeInitialized = () => {\r\n const localInfo = iModel[_nativeDb].schemaSyncGetLocalDbInfo();\r\n if (localInfo && !overrideContainer)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Local db already initialized to schema sync (container-id: ${localInfo.id})`);\r\n };\r\n\r\n assertContainerCanBeInitialized();\r\n await iModel.acquireSchemaLock();\r\n await briefcase?.pullChanges();\r\n assertContainerCanBeInitialized();\r\n return briefcase;\r\n }\r\n\r\n async function initializeAfterPreflight(arg: InitializeForIModelArgs, briefcase: BriefcaseDb | undefined): Promise<void> {\r\n const props = { baseUri: arg.containerProps.baseUri, containerId: arg.containerProps.containerId, storageType: arg.containerProps.storageType }; // sanitize to only known properties\r\n const iModel = arg.iModel;\r\n const description = arg.overrideContainer\r\n ? `Overriding SchemaSync for iModel with container-id: ${props.containerId}`\r\n : `Enable SchemaSync for iModel with container-id: ${props.containerId}`;\r\n const txnBeforeInit = briefcase?.txns.getCurrentTxnId();\r\n try {\r\n iModel[_implicitTxn].saveFileProperty(syncProperty, JSON.stringify(props));\r\n try {\r\n await withLockedAccess(iModel, { operationName: \"initialize schemaSync\", openMode: OpenMode.Readonly }, async (syncAccess) => {\r\n iModel[_nativeDb].schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);\r\n iModel[_implicitTxn].saveChanges(description);\r\n });\r\n } catch (error) {\r\n iModel[_implicitTxn].abandonChanges();\r\n if (briefcase && txnBeforeInit !== undefined && briefcase.txns.getCurrentTxnId() !== txnBeforeInit) {\r\n const status = briefcase[_nativeDb].cancelTo(txnBeforeInit, true);\r\n if (status !== IModelStatus.Success)\r\n Logger.logError(\"SchemaSync\", `Failed to roll back schema sync initialization after the container upload failed: ${IModelStatus[status] ?? status}`);\r\n }\r\n throw error;\r\n }\r\n\r\n // Upload the initialized container before publishing the property that tells every briefcase to use it.\r\n // If the push fails, this briefcase keeps the local txn and exclusive schema lock so the push can be retried.\r\n await briefcase?.pushChanges({ description });\r\n } finally {\r\n iModel[_implicitTxn].abandonChanges();\r\n }\r\n\r\n await iModel.initializeSharedElementReservations();\r\n }\r\n\r\n /** Enable schema sync for an iModel, seeding the container from this briefcase.\r\n * @note Takes the exclusive schema lock, refuses local changes, and pulls the briefcase to the tip before writing the container.\r\n * If this operation fails after acquiring the schema lock, it leaves the lock held.\r\n */\r\n export async function initializeForIModel(arg: InitializeForIModelArgs): Promise<void> {\r\n const briefcase = await prepareToInitializeForIModel(arg.iModel, arg.overrideContainer ?? false);\r\n await initializeAfterPreflight(arg, briefcase);\r\n }\r\n\r\n /** The part of a SchemaSyncDb to restore from an authoritative briefcase. @alpha */\r\n export type RepairScope = \"schemaMetadata\" | \"schemaMetadataAndProfile\";\r\n\r\n const nativeRepairScope: Record<RepairScope, number> = {\r\n schemaMetadata: 0,\r\n schemaMetadataAndProfile: 1,\r\n };\r\n\r\n /** Arguments for [[repairForIModel]]. @alpha */\r\n export interface RepairForIModelArgs {\r\n /** A clean SchemaSync-enabled briefcase at the tip of the iModel timeline. */\r\n iModel: BriefcaseDb;\r\n /** Include the schema-owned EC and BeSQLite profile table definitions. */\r\n scope?: RepairScope;\r\n }\r\n\r\n /** Restore the schema-owned portion of the SchemaSyncDb from a briefcase at the tip of the timeline.\r\n *\r\n * This operation takes the exclusive schema lock and refuses to pull or modify the briefcase. Element\r\n * reservations and all other target-only state in the SchemaSyncDb are preserved.\r\n * @alpha\r\n */\r\n export async function repairForIModel(arg: RepairForIModelArgs): Promise<void> {\r\n const iModel = arg.iModel;\r\n if (!isEnabled(iModel))\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot repair SchemaSync because it is not enabled for this iModel\");\r\n\r\n if (iModel[_nativeDb].hasUnsavedChanges() || iModel.txns.hasLocalChanges)\r\n throw new IModelError(ChangeSetStatus.HasLocalChanges, \"Cannot repair SchemaSync while there are local changes\");\r\n\r\n if (!iModel.locks.isServerBased)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot repair SchemaSync without server-based locking\");\r\n\r\n if (arg.scope !== undefined && arg.scope !== \"schemaMetadata\" && arg.scope !== \"schemaMetadataAndProfile\")\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Unknown SchemaSync repair scope\");\r\n\r\n const briefcaseManagerModule = await import(\"./BriefcaseManager\");\r\n const assertBriefcaseIsAtTip = async () => {\r\n const latestChangeset = await briefcaseManagerModule.BriefcaseManager.getLatestChangeset({ iModelId: iModel.iModelId });\r\n if (latestChangeset.id !== iModel.changeset.id)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot repair SchemaSync from a briefcase that is not at the tip of the iModel timeline\");\r\n };\r\n\r\n // Avoid asking Hub for an exclusive lock it cannot grant to a briefcase that first needs to pull.\r\n await assertBriefcaseIsAtTip();\r\n const schemaLockWasHeld = iModel.holdsSchemaLock;\r\n if (!schemaLockWasHeld)\r\n await iModel.acquireSchemaLock();\r\n try {\r\n // Close the race between the preflight query and acquiring the exclusive lock.\r\n await assertBriefcaseIsAtTip();\r\n const repairScope = nativeRepairScope[arg.scope ?? \"schemaMetadata\"];\r\n await withLockedAccess(iModel, { openMode: OpenMode.Readonly, operationName: \"repair schema sync\" }, async (syncAccess) => {\r\n const nativeDb = iModel[_nativeDb] as IModelJsNative.DgnDb & { schemaSyncRepair(syncDbUri: string, scope: number): void };\r\n nativeDb.schemaSyncRepair(syncAccess.getUri(), repairScope);\r\n });\r\n Logger.logInfo(\"SchemaSync\", `Repaired SchemaSyncDb from changeset ${iModel.changeset.id || \"0\"}`);\r\n } finally {\r\n if (!schemaLockWasHeld)\r\n await iModel.locks.abandonAllLocks();\r\n }\r\n }\r\n\r\n /** Arguments for [[enableForIModel]]. */\r\n export interface EnableForIModelArgs {\r\n iModel: IModelDb;\r\n /** An existing container to use. When omitted one is created for this iModel. */\r\n containerProps?: CloudSqlite.ContainerProps;\r\n /** Replace the container already recorded on this iModel instead of failing. */\r\n overrideContainer?: boolean;\r\n label?: string;\r\n description?: string;\r\n }\r\n\r\n /** Turn schema sync on for an iModel: create the container if needed, record it, and seed it.\r\n *\r\n * The single call callers should use. [[createContainerForIModel]] and [[initializeForIModel]] have\r\n * to happen in this order, and an iModel left between the two is one that names a container nothing\r\n * has seeded.\r\n * @returns the container props recorded on the iModel.\r\n * @note Takes the exclusive schema lock and pushes, same protocol as [[BriefcaseDb.upgradeSchemas]] -\r\n * every operation that changes how a file is governed uses it. If this operation fails after acquiring the schema lock,\r\n * it leaves the lock held.\r\n */\r\n export async function enableForIModel(arg: EnableForIModelArgs): Promise<CloudSqlite.ContainerProps> {\r\n if (undefined === arg.containerProps && undefined === arg.iModel.iTwinId)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot create a SchemaSync container for an iModel that has no iTwin\");\r\n\r\n const briefcase = await prepareToInitializeForIModel(arg.iModel, arg.overrideContainer ?? false);\r\n const containerProps = arg.containerProps\r\n ?? await createContainerForIModel({ iModel: arg.iModel, label: arg.label, description: arg.description });\r\n await initializeAfterPreflight({ iModel: arg.iModel, containerProps, overrideContainer: arg.overrideContainer }, briefcase);\r\n return containerProps;\r\n }\r\n\r\n /** Arguments for [[CloudAccess.createNewContainer]]. */\r\n export interface CreateNewContainerProps {\r\n scope: BlobContainer.Scope;\r\n metadata: Omit<BlobContainer.Metadata, \"containerType\">;\r\n }\r\n\r\n /** Provides access to a cloud-based `SchemaSyncDb` to hold ECSchemas. */\r\n export class CloudAccess extends CloudSqlite.DbAccess<SchemaSyncDb, ReadMethods, WriteMethods> {\r\n public constructor(props: CloudSqlite.ContainerAccessProps) {\r\n super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });\r\n }\r\n\r\n public getUri() {\r\n return `${this.getCloudDb()[_nativeDb].getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;\r\n }\r\n /**\r\n * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty ChannelDb into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n public static async initializeDb(props: CloudSqlite.ContainerProps) {\r\n return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });\r\n }\r\n\r\n /** Create and initialize a new `schema-sync` BlobContainer to hold a `SchemaSyncDb`. */\r\n public static async createNewContainer(args: CreateNewContainerProps): Promise<CloudSqlite.ContainerProps> {\r\n const props = await this.createBlobContainer({ scope: args.scope, metadata: { ...args.metadata, containerType } });\r\n await this.initializeDb(props);\r\n return props;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaSync.js","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAY,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAc,IAAI,EAAc,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClJ,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,uBAAuB,EAAqB,WAAW,EAAiB,MAAM,oBAAoB,CAAC;AAGpI,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE7D,gBAAgB;AAChB,MAAM,KAAW,UAAU,CAm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IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1I,CAAC;QACD;;;;SAIC;QACM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAAiC;YAChE,OAAO,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACrF,CAAC;QAED,uFAAuF;QAChF,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAA6B;YAClE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAb,WAAA,aAAa,EAAE,EAAE,CAAC,CAAC;YACnH,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAC/B,OAAO,KAAK,CAAC;QACf,CAAC;KACF;IAvBY,sBAAW,cAuBvB,CAAA;AACH,CAAC,EAnlBgB,UAAU,KAAV,UAAU,QAmlB1B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport * as semver from \"semver\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { SQLiteDb, VersionedSqliteDb } from \"./SQLiteDb\";\r\nimport { BriefcaseDb, IModelDb } from \"./IModelDb\";\r\nimport { BentleyError, ChangeSetStatus, DbResult, Guid, GuidString, Id64, Id64String, IModelStatus, Logger, OpenMode } from \"@itwin/core-bentley\";\r\nimport { BriefcaseIdValue, Code, ElementReservationError, FilePropertyProps, IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport type { BlobContainer } from \"./BlobContainerService\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { _implicitTxn, _nativeDb } from \"./internal/Symbols\";\r\n\r\n/** @internal */\r\nexport namespace SchemaSync {\r\n /** How long a briefcase waits for another briefcase's schema import to finish before giving up.\r\n *\r\n * `nRetries` alone does not bound the wait: when the count runs out `CloudSqlite.withLockedDb` asks\r\n * `onFailure` what to do, and anything other than \"stop\" restarts the whole cycle. Without an\r\n * `onFailure` the caller waits forever with no way to give up, so this supplies one.\r\n */\r\n const lockParams: CloudSqlite.ObtainLockParams = {\r\n retryDelayMs: 6000,\r\n nRetries: 10,\r\n onFailure: async (lockedBy: string, expires: string) => {\r\n Logger.logInfo(\"SchemaSync\", `schema sync container is held by ${lockedBy} until ${expires}; giving up`);\r\n return \"stop\";\r\n },\r\n };\r\n const reservedElementsTableName = \"reserved_elements\";\r\n const maxLocalIdExclusive = 0x10000000000; // 2^40\r\n const idSequenceProp: FilePropertyProps = { namespace: \"schemasync\", name: \"nextReservedElementLocalId\" };\r\n\r\n /** Identifies an element to be reserved in a `SchemaSyncDb`. @internal */\r\n export interface ProposedElementReservation {\r\n readonly federationGuid: GuidString;\r\n readonly ecClassId: Id64String;\r\n readonly code: Code;\r\n readonly isCategory?: boolean;\r\n }\r\n\r\n /** An element reservation that has been persisted in a `SchemaSyncDb`. @internal */\r\n export interface ReservedElement extends ProposedElementReservation {\r\n readonly elementId: Id64String;\r\n }\r\n\r\n export interface ReadMethods {\r\n /** Look up an existing element reservation by federationGuid. */\r\n findReservedElement(federationGuid: GuidString): ReservedElement | undefined;\r\n }\r\n\r\n export interface WriteMethods {\r\n /** Reserve the specified elements in the `SchemaSyncDb`. Throws if any requested reservation conflicts with an existing reservation. */\r\n reserveElements(identities: ProposedElementReservation[]): Promise<void>;\r\n }\r\n\r\n /** A CloudSqlite database for synchronizing schema changes across briefcases. */\r\n export class SchemaSyncDb extends VersionedSqliteDb implements ReadMethods, WriteMethods {\r\n private _supportsReservations?: boolean;\r\n public override readonly myVersion = \"5.0.0\";\r\n protected override createDDL() {\r\n this.ensureReservedElementsTable();\r\n }\r\n\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this._supportsReservations = semver.lte(this.myVersion, semver.minVersion(this.getRequiredVersions().readVersion) ?? \"0.0.0\");\r\n }\r\n\r\n private ensureReservedElementsTable(): void {\r\n if (this._supportsReservations)\r\n return;\r\n\r\n this.executeSQL(`\r\n CREATE TABLE IF NOT EXISTS ${reservedElementsTableName} (\r\n federationGuid BLOB PRIMARY KEY,\r\n elementId INTEGER NOT NULL UNIQUE,\r\n ecClassId INTEGER NOT NULL,\r\n codeSpecId INTEGER NOT NULL,\r\n codeScope TEXT NOT NULL,\r\n codeValue TEXT COLLATE NOCASE\r\n )`);\r\n this.executeSQL(`CREATE UNIQUE INDEX IF NOT EXISTS idx_reserved_elem_code ON ${reservedElementsTableName}(codeSpecId, codeScope, codeValue)`);\r\n const minVersion = `^${this.myVersion}`;\r\n this.setRequiredVersions({ readVersion: minVersion, writeVersion: minVersion });\r\n this._supportsReservations = true;\r\n }\r\n\r\n public findReservedElement(federationGuid: GuidString): ReservedElement | undefined {\r\n if (!this._supportsReservations)\r\n return undefined;\r\n\r\n return this.withPreparedSqliteStatement(\r\n `SELECT elementId, ecClassId, codeSpecId, codeScope, codeValue FROM ${reservedElementsTableName} WHERE federationGuid=?`,\r\n (stmt) => {\r\n stmt.bindGuid(1, federationGuid);\r\n if (!stmt.nextRow())\r\n return undefined;\r\n\r\n return {\r\n federationGuid,\r\n elementId: stmt.getValueId(0),\r\n ecClassId: stmt.getValueId(1),\r\n code: new Code({\r\n spec: stmt.getValueId(2),\r\n scope: stmt.getValueString(3),\r\n value: stmt.getValueStringMaybe(4),\r\n }),\r\n };\r\n },\r\n );\r\n }\r\n\r\n private insertReservedElement(id: ProposedElementReservation, elementId: Id64String): void {\r\n this.withPreparedSqliteStatement(\r\n `INSERT INTO ${reservedElementsTableName} (federationGuid, elementId, ecClassId, codeSpecId, codeScope, codeValue) VALUES (?, ?, ?, ?, ?, ?)`,\r\n (stmt) => {\r\n stmt.bindGuid(1, id.federationGuid);\r\n stmt.bindId(2, elementId);\r\n stmt.bindId(3, id.ecClassId);\r\n stmt.bindId(4, id.code.spec);\r\n stmt.bindString(5, id.code.scope);\r\n if (id.code.value === \"\")\r\n stmt.bindNull(6);\r\n else\r\n stmt.bindString(6, id.code.value);\r\n stmt.stepForWrite();\r\n },\r\n );\r\n }\r\n\r\n public async reserveElements(elements: ProposedElementReservation[]): Promise<void> {\r\n this.ensureReservedElementsTable();\r\n\r\n // Insert new reservations as we go, so later entries in `elements` can dedupe against earlier ones\r\n // through the shared (still-uncommitted) transaction. The caller commits on success and abandons on error.\r\n let nextLocalId = this.getNextReservedElementLocalId();\r\n const firstLocalId = nextLocalId;\r\n\r\n for (const def of elements) {\r\n if (!def.federationGuid || !Guid.isGuid(def.federationGuid)) {\r\n ElementReservationError.throwError(\"invalid-reservation\", {\r\n message: \"Element reservation requires an explicit, valid federationGuid\",\r\n });\r\n }\r\n\r\n // Identity is always the federationGuid. If a reservation already exists for it, it must match exactly.\r\n const existing = this.findReservedElement(def.federationGuid);\r\n if (existing) {\r\n if (!this.existingMatches(existing, def)) {\r\n ElementReservationError.throwError(\"reservation-conflict\", {\r\n message: `Element reservation conflict for federationGuid ${existing.federationGuid}: existing row does not match requested class/code`,\r\n federationGuid: existing.federationGuid,\r\n });\r\n }\r\n continue;\r\n }\r\n\r\n const elementId = Id64.fromLocalAndBriefcaseIds(nextLocalId, BriefcaseIdValue.SchemaSyncElementReserved);\r\n this.insertReservedElement(def, elementId);\r\n // skip a local id for each reserved category because category inserts always trigger a second insert for default subcategory\r\n nextLocalId += def.isCategory ? 2 : 1;\r\n if (nextLocalId >= maxLocalIdExclusive) {\r\n this.abandonChanges();\r\n ElementReservationError.throwError(\"id-sequence-exhausted\", { message: `SchemaSync reserved-element local-id sequence exhausted` });\r\n }\r\n }\r\n\r\n if (nextLocalId !== firstLocalId)\r\n this.setNextReservedElementLocalId(nextLocalId);\r\n }\r\n\r\n private existingMatches(existing: ProposedElementReservation, id: ProposedElementReservation): boolean {\r\n return existing.federationGuid === id.federationGuid\r\n && existing.ecClassId === id.ecClassId\r\n && existing.code.equals(id.code);\r\n }\r\n\r\n private getNextReservedElementLocalId(): number {\r\n const stored = this[_nativeDb].queryFileProperty(idSequenceProp, true) as string | undefined;\r\n const current = stored ? Number(stored) : 1;\r\n if (!Number.isInteger(current) || current < 1)\r\n ElementReservationError.throwError(\"corrupt-reservation-data\", { message: `Corrupt SchemaSync reserved-element local-id counter: '${stored}'` });\r\n\r\n return current;\r\n }\r\n\r\n private setNextReservedElementLocalId(next: number): void {\r\n this[_nativeDb].saveFileProperty(idSequenceProp, String(next));\r\n }\r\n }\r\n\r\n const syncProperty = { namespace: \"itwinjs\", name: \"SchemaSync\" };\r\n const defaultDbName = \"SchemaSyncDb\";\r\n /** The `containerType` recorded on a BlobContainer that holds an iModel's `SchemaSyncDb`. */\r\n export const containerType = \"schemasync\";\r\n const testSyncCachePropKey = \"test.schema_sync.cache_name\";\r\n // for tests only\r\n export function setTestCache(iModel: IModelDb, cacheName?: string): void {\r\n if (cacheName)\r\n iModel[_nativeDb].saveLocalValue(testSyncCachePropKey, cacheName);\r\n else\r\n iModel[_nativeDb].deleteLocalValue(testSyncCachePropKey);\r\n }\r\n\r\n /** Either an open iModel or the name of a closed briefcase file. Every local read below accepts both, so\r\n * a caller that has only a file name does not have to open a `BriefcaseDb` to ask a question about it.\r\n */\r\n export type IModelOrFileName = IModelDb | { readonly fileName: LocalFileName };\r\n\r\n /** Read from an open iModel, or from a closed file opened readonly for the duration of `operation`. */\r\n function readFromIModel<T>(arg: IModelOrFileName, operation: (nativeDb: IModelJsNative.DgnDb) => T): T {\r\n if (arg instanceof IModelDb)\r\n return operation(arg[_nativeDb]);\r\n\r\n const nativeDb = new IModelNative.platform.DgnDb();\r\n nativeDb.openIModel(arg.fileName, OpenMode.Readonly);\r\n try {\r\n return operation(nativeDb);\r\n } finally {\r\n nativeDb.closeFile();\r\n }\r\n }\r\n\r\n /** Whether this iModel's ECSchemas are governed by a `SchemaSyncDb`.\r\n *\r\n * This is the single question every schema operation branches on. It reads one `be_Prop` row written when\r\n * schema sync was enabled and carried to every other briefcase by that changeset - no cloud access, and it\r\n * works on a readonly briefcase, a checkpoint, or a closed file.\r\n * @note This says nothing about whether the container is reachable, or even named. Use\r\n * [[queryContainerProps]] for that. The two are separate on purpose: a file that says it is governed by a\r\n * sync db must never fall back to importing schemas on its own, whatever state the container is in.\r\n */\r\n export function isEnabled(arg: IModelOrFileName): boolean {\r\n return readFromIModel(arg, (nativeDb) => nativeDb.schemaSyncEnabled());\r\n }\r\n\r\n /** One pass over the values schema sync keeps in the file: which container holds the sync db, plus the\r\n * test-only cache override. Read together so a closed file is opened once.\r\n */\r\n function readLocalSyncProps(arg: IModelOrFileName) {\r\n return readFromIModel(arg, (nativeDb) => {\r\n const propsString = nativeDb.queryFileProperty(syncProperty, true) as string | undefined;\r\n let containerProps: CloudSqlite.ContainerProps | undefined;\r\n if (propsString !== undefined) {\r\n try {\r\n containerProps = JSON.parse(propsString) as CloudSqlite.ContainerProps;\r\n } catch (e) {\r\n // Deliberately not swallowed into `undefined`: that would read as \"schema sync was never\r\n // enabled\" and let this briefcase import schemas on its own.\r\n throw new IModelError(DbResult.BE_SQLITE_CORRUPT, `iModel names a SchemaSyncDb container but the property cannot be read: ${BentleyError.getErrorMessage(e)}`);\r\n }\r\n }\r\n return {\r\n containerProps,\r\n testCacheName: nativeDb.queryLocalValue(testSyncCachePropKey),\r\n };\r\n });\r\n }\r\n\r\n /** The container holding this iModel's `SchemaSyncDb`, or `undefined` if schema sync was never enabled.\r\n *\r\n * Local read of the same `be_Prop` file property that [[initializeForIModel]] wrote. Requesting an access\r\n * token for the container is a separate, asynchronous step.\r\n */\r\n export function queryContainerProps(arg: IModelOrFileName): CloudSqlite.ContainerProps | undefined {\r\n return readLocalSyncProps(arg).containerProps;\r\n }\r\n\r\n interface SharedCloudAccess {\r\n access: CloudAccess;\r\n key: string;\r\n referenceCount: number;\r\n }\r\n\r\n const sharedAccessByContainer = new Map<string, SharedCloudAccess | Promise<SharedCloudAccess>>();\r\n const sharedAccessByInstance = new WeakMap<CloudAccess, SharedCloudAccess>();\r\n\r\n export async function getCloudAccess(arg: IModelOrFileName): Promise<CloudAccess> {\r\n const { containerProps, testCacheName } = readLocalSyncProps(arg);\r\n if (undefined === containerProps)\r\n throw new IModelError(DbResult.BE_SQLITE_NOTFOUND, \"iModel does not have a SchemaSyncDb\");\r\n\r\n const sharedAccessKey = JSON.stringify(containerProps) + (testCacheName ?? \"\");\r\n let shared = sharedAccessByContainer.get(sharedAccessKey);\r\n if (undefined === shared) {\r\n const pending = (async () => {\r\n const accessToken = await CloudSqlite.requestToken(containerProps);\r\n const access = new CloudAccess({ ...containerProps, accessToken });\r\n Object.assign(access.lockParams, lockParams);\r\n if (testCacheName)\r\n access.setCache(CloudSqlite.CloudCaches.getCache({ cacheName: testCacheName }));\r\n\r\n const created = { access, key: sharedAccessKey, referenceCount: 0 };\r\n sharedAccessByInstance.set(access, created);\r\n return created;\r\n })();\r\n sharedAccessByContainer.set(sharedAccessKey, pending);\r\n try {\r\n shared = await pending;\r\n if (sharedAccessByContainer.get(sharedAccessKey) === pending)\r\n sharedAccessByContainer.set(sharedAccessKey, shared);\r\n } catch (error) {\r\n if (sharedAccessByContainer.get(sharedAccessKey) === pending)\r\n sharedAccessByContainer.delete(sharedAccessKey);\r\n throw error;\r\n }\r\n } else if (shared instanceof Promise) {\r\n shared = await shared;\r\n }\r\n\r\n ++shared.referenceCount;\r\n return shared.access;\r\n }\r\n\r\n /** Release an access obtained through [[getCloudAccess]]. */\r\n export function releaseCloudAccess(access: CloudAccess): void {\r\n const shared = sharedAccessByInstance.get(access);\r\n if (undefined === shared) {\r\n access.close();\r\n return;\r\n }\r\n\r\n if (--shared.referenceCount > 0)\r\n return;\r\n\r\n sharedAccessByInstance.delete(access);\r\n if (sharedAccessByContainer.get(shared.key) === shared)\r\n sharedAccessByContainer.delete(shared.key);\r\n access.close();\r\n }\r\n\r\n /** Arguments for [[withLockedAccess]]. */\r\n export interface WithLockedAccessArgs {\r\n operationName: string;\r\n openMode?: OpenMode;\r\n user?: string;\r\n }\r\n\r\n export async function withLockedAccess(iModel: IModelOrFileName, args: WithLockedAccessArgs, operation: (access: CloudAccess) => Promise<void>): Promise<void> {\r\n const access = await SchemaSync.getCloudAccess(iModel);\r\n try {\r\n await access.withLockedDb(args, async () => operation(access));\r\n } finally {\r\n releaseCloudAccess(access);\r\n }\r\n }\r\n\r\n /** Build the tables and indexes the briefcase's `ec_` rows describe. A merged schema changeset carries\r\n * those rows but no DDL, so the physical columns are missing until this runs. Needs no cloud access.\r\n */\r\n export function updateDbSchema(iModel: IModelDb): void {\r\n if (isEnabled(iModel) && !iModel.isReadonly) {\r\n iModel.clearCaches();\r\n iModel[_nativeDb].schemaSyncUpdateDbSchema();\r\n iModel[_implicitTxn].saveChanges(\"materialized db schema from ec_ tables\");\r\n }\r\n }\r\n\r\n /** Whether a failed [[IModelDb.importSchemas]] can be retried through the upgrade path.\r\n *\r\n * The update tier refuses two kinds of change: one that has to move data between columns, and one\r\n * that destroys instances or property values. They arrive as different statuses because they are\r\n * different changes, but they mean one thing to a caller - this needs\r\n * [[BriefcaseDb.upgradeSchemas]], which takes the exclusive schema lock.\r\n *\r\n * The retry is the app's decision, not the platform's: taking that lock disturbs everyone else, so\r\n * only the app knows whether to do it now, schedule it, or tell the user.\r\n * ```ts\r\n * try {\r\n * await db.importSchemas(files);\r\n * } catch (e) {\r\n * if (!SchemaSync.requiresUpgrade(e)) throw e;\r\n * await db.upgradeSchemas(files, { description: \"...\" });\r\n * }\r\n * ```\r\n * @internal\r\n */\r\n export function requiresUpgrade(error: unknown): boolean {\r\n const errorNumber = (error as { errorNumber?: number } | undefined)?.errorNumber;\r\n return errorNumber === DbResult.BE_SQLITE_ERROR_DataTransformRequired\r\n || errorNumber === DbResult.BE_SQLITE_ERROR_DataDeletionRequired;\r\n }\r\n\r\n /** Arguments for [[createContainerForIModel]]. */\r\n export interface CreateContainerForIModelArgs {\r\n iModel: IModelDb;\r\n label?: string;\r\n description?: string;\r\n }\r\n\r\n /** Create a cloud container to hold this iModel's `SchemaSyncDb`, and initialize it as empty.\r\n *\r\n * The container is scoped to the iModel, so the service deletes it when the iModel is deleted. Pass the\r\n * returned props to [[initializeForIModel]] - the two calls together are what enables schema sync on an\r\n * iModel that was created without it.\r\n * @note The current user must be authorized to create containers for the iTwin.\r\n */\r\n export async function createContainerForIModel(arg: CreateContainerForIModelArgs): Promise<CloudSqlite.ContainerProps> {\r\n const iModel = arg.iModel;\r\n const iTwinId = iModel.iTwinId;\r\n if (undefined === iTwinId)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot create a SchemaSync container for an iModel that has no iTwin\");\r\n\r\n return CloudAccess.createNewContainer({\r\n scope: { iTwinId, iModelId: iModel.iModelId },\r\n metadata: { label: arg.label ?? `SchemaSync for ${iModel.name}`, description: arg.description },\r\n });\r\n }\r\n\r\n /** Arguments for [[initializeForIModel]]. */\r\n export interface InitializeForIModelArgs {\r\n iModel: IModelDb;\r\n containerProps: CloudSqlite.ContainerProps;\r\n /** Replace the container already recorded on this iModel instead of failing. */\r\n overrideContainer?: boolean;\r\n }\r\n\r\n /** Refuse initialization before a caller provisions a container, then hold the exclusive schema lock and pull to the tip. */\r\n async function prepareToInitializeForIModel(iModel: IModelDb, overrideContainer: boolean): Promise<BriefcaseDb | undefined> {\r\n const briefcase = iModel instanceof BriefcaseDb ? iModel : undefined;\r\n if (briefcase && !briefcase.locks.isServerBased)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot enable SchemaSync without server-based locking\");\r\n\r\n if (briefcase && (iModel[_nativeDb].hasUnsavedChanges() || briefcase.txns.hasLocalChanges))\r\n throw new IModelError(ChangeSetStatus.HasLocalChanges, \"Cannot enable SchemaSync while there are local changes\");\r\n\r\n const assertContainerCanBeInitialized = () => {\r\n const localInfo = iModel[_nativeDb].schemaSyncGetLocalDbInfo();\r\n if (localInfo && !overrideContainer)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Local db already initialized to schema sync (container-id: ${localInfo.id})`);\r\n };\r\n\r\n assertContainerCanBeInitialized();\r\n await iModel.acquireSchemaLock();\r\n await briefcase?.pullChanges();\r\n assertContainerCanBeInitialized();\r\n return briefcase;\r\n }\r\n\r\n async function initializeAfterPreflight(arg: InitializeForIModelArgs, briefcase: BriefcaseDb | undefined): Promise<void> {\r\n const props = { baseUri: arg.containerProps.baseUri, containerId: arg.containerProps.containerId, storageType: arg.containerProps.storageType }; // sanitize to only known properties\r\n const iModel = arg.iModel;\r\n const description = arg.overrideContainer\r\n ? `Overriding SchemaSync for iModel with container-id: ${props.containerId}`\r\n : `Enable SchemaSync for iModel with container-id: ${props.containerId}`;\r\n const txnBeforeInit = briefcase?.txns.getCurrentTxnId();\r\n try {\r\n iModel[_implicitTxn].saveFileProperty(syncProperty, JSON.stringify(props));\r\n try {\r\n await withLockedAccess(iModel, { operationName: \"initialize schemaSync\", openMode: OpenMode.Readonly }, async (syncAccess) => {\r\n iModel[_nativeDb].schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);\r\n iModel[_implicitTxn].saveChanges(description);\r\n });\r\n } catch (error) {\r\n iModel[_implicitTxn].abandonChanges();\r\n if (briefcase && txnBeforeInit !== undefined && briefcase.txns.getCurrentTxnId() !== txnBeforeInit) {\r\n const status = briefcase[_nativeDb].cancelTo(txnBeforeInit, true);\r\n if (status !== IModelStatus.Success)\r\n Logger.logError(\"SchemaSync\", `Failed to roll back schema sync initialization after the container upload failed: ${IModelStatus[status] ?? status}`);\r\n }\r\n throw error;\r\n }\r\n\r\n // Upload the initialized container before publishing the property that tells every briefcase to use it.\r\n // If the push fails, this briefcase keeps the local txn and exclusive schema lock so the push can be retried.\r\n await briefcase?.pushChanges({ description });\r\n } finally {\r\n iModel[_implicitTxn].abandonChanges();\r\n }\r\n\r\n await iModel.initializeSharedElementReservations();\r\n }\r\n\r\n /** Enable schema sync for an iModel, seeding the container from this briefcase.\r\n * @note Takes the exclusive schema lock, refuses local changes, and pulls the briefcase to the tip before writing the container.\r\n * If this operation fails after acquiring the schema lock, it leaves the lock held.\r\n */\r\n export async function initializeForIModel(arg: InitializeForIModelArgs): Promise<void> {\r\n const briefcase = await prepareToInitializeForIModel(arg.iModel, arg.overrideContainer ?? false);\r\n await initializeAfterPreflight(arg, briefcase);\r\n }\r\n\r\n /** The part of a SchemaSyncDb to restore from an authoritative briefcase. @alpha */\r\n export type RepairScope = \"schemaMetadata\" | \"schemaMetadataAndProfile\";\r\n\r\n const nativeRepairScope: Record<RepairScope, number> = {\r\n schemaMetadata: 0,\r\n schemaMetadataAndProfile: 1,\r\n };\r\n\r\n /** Arguments for [[repairForIModel]]. @alpha */\r\n export interface RepairForIModelArgs {\r\n /** A clean SchemaSync-enabled briefcase at the tip of the iModel timeline. */\r\n iModel: BriefcaseDb;\r\n /** Include the schema-owned EC and BeSQLite profile table definitions. */\r\n scope?: RepairScope;\r\n }\r\n\r\n /** Restore the schema-owned portion of the SchemaSyncDb from a briefcase at the tip of the timeline.\r\n *\r\n * This operation takes the exclusive schema lock and refuses to pull or modify the briefcase. Element\r\n * reservations and all other target-only state in the SchemaSyncDb are preserved.\r\n * @alpha\r\n */\r\n export async function repairForIModel(arg: RepairForIModelArgs): Promise<void> {\r\n const iModel = arg.iModel;\r\n if (!isEnabled(iModel))\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot repair SchemaSync because it is not enabled for this iModel\");\r\n\r\n if (iModel[_nativeDb].hasUnsavedChanges() || iModel.txns.hasLocalChanges)\r\n throw new IModelError(ChangeSetStatus.HasLocalChanges, \"Cannot repair SchemaSync while there are local changes\");\r\n\r\n if (!iModel.locks.isServerBased)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot repair SchemaSync without server-based locking\");\r\n\r\n if (arg.scope !== undefined && arg.scope !== \"schemaMetadata\" && arg.scope !== \"schemaMetadataAndProfile\")\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Unknown SchemaSync repair scope\");\r\n\r\n const briefcaseManagerModule = await import(\"./BriefcaseManager\");\r\n const assertBriefcaseIsAtTip = async () => {\r\n const latestChangeset = await briefcaseManagerModule.BriefcaseManager.getLatestChangeset({ iModelId: iModel.iModelId });\r\n if (latestChangeset.id !== iModel.changeset.id)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot repair SchemaSync from a briefcase that is not at the tip of the iModel timeline\");\r\n };\r\n\r\n // Avoid asking Hub for an exclusive lock it cannot grant to a briefcase that first needs to pull.\r\n await assertBriefcaseIsAtTip();\r\n const schemaLockWasHeld = iModel.holdsSchemaLock;\r\n if (!schemaLockWasHeld)\r\n await iModel.acquireSchemaLock();\r\n try {\r\n // Close the race between the preflight query and acquiring the exclusive lock.\r\n await assertBriefcaseIsAtTip();\r\n const repairScope = nativeRepairScope[arg.scope ?? \"schemaMetadata\"];\r\n await withLockedAccess(iModel, { openMode: OpenMode.Readonly, operationName: \"repair schema sync\" }, async (syncAccess) => {\r\n const nativeDb = iModel[_nativeDb] as IModelJsNative.DgnDb & { schemaSyncRepair(syncDbUri: string, scope: number): void };\r\n nativeDb.schemaSyncRepair(syncAccess.getUri(), repairScope);\r\n });\r\n Logger.logInfo(\"SchemaSync\", `Repaired SchemaSyncDb from changeset ${iModel.changeset.id || \"0\"}`);\r\n } finally {\r\n if (!schemaLockWasHeld)\r\n await iModel.locks.abandonAllLocks();\r\n }\r\n }\r\n\r\n /** Arguments for [[enableForIModel]]. */\r\n export interface EnableForIModelArgs {\r\n iModel: IModelDb;\r\n /** An existing container to use. When omitted one is created for this iModel. */\r\n containerProps?: CloudSqlite.ContainerProps;\r\n /** Replace the container already recorded on this iModel instead of failing. */\r\n overrideContainer?: boolean;\r\n label?: string;\r\n description?: string;\r\n }\r\n\r\n /** Turn schema sync on for an iModel: create the container if needed, record it, and seed it.\r\n *\r\n * The single call callers should use. [[createContainerForIModel]] and [[initializeForIModel]] have\r\n * to happen in this order, and an iModel left between the two is one that names a container nothing\r\n * has seeded.\r\n * @returns the container props recorded on the iModel.\r\n * @note Takes the exclusive schema lock and pushes, same protocol as [[BriefcaseDb.upgradeSchemas]] -\r\n * every operation that changes how a file is governed uses it. If this operation fails after acquiring the schema lock,\r\n * it leaves the lock held.\r\n */\r\n export async function enableForIModel(arg: EnableForIModelArgs): Promise<CloudSqlite.ContainerProps> {\r\n if (undefined === arg.containerProps && undefined === arg.iModel.iTwinId)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot create a SchemaSync container for an iModel that has no iTwin\");\r\n\r\n const briefcase = await prepareToInitializeForIModel(arg.iModel, arg.overrideContainer ?? false);\r\n const containerProps = arg.containerProps\r\n ?? await createContainerForIModel({ iModel: arg.iModel, label: arg.label, description: arg.description });\r\n await initializeAfterPreflight({ iModel: arg.iModel, containerProps, overrideContainer: arg.overrideContainer }, briefcase);\r\n return containerProps;\r\n }\r\n\r\n /** Arguments for [[CloudAccess.createNewContainer]]. */\r\n export interface CreateNewContainerProps {\r\n scope: BlobContainer.Scope;\r\n metadata: Omit<BlobContainer.Metadata, \"containerType\">;\r\n }\r\n\r\n /** Provides access to a cloud-based `SchemaSyncDb` to hold ECSchemas. */\r\n export class CloudAccess extends CloudSqlite.DbAccess<SchemaSyncDb, ReadMethods, WriteMethods> {\r\n public constructor(props: CloudSqlite.ContainerAccessProps) {\r\n super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });\r\n }\r\n\r\n public getUri() {\r\n return `${this.getCloudDb()[_nativeDb].getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;\r\n }\r\n /**\r\n * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty ChannelDb into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n public static async initializeDb(props: CloudSqlite.ContainerProps) {\r\n return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });\r\n }\r\n\r\n /** Create and initialize a new `schemasync` BlobContainer to hold a `SchemaSyncDb`. */\r\n public static async createNewContainer(args: CreateNewContainerProps): Promise<CloudSqlite.ContainerProps> {\r\n const props = await this.createBlobContainer({ scope: args.scope, metadata: { ...args.metadata, containerType } });\r\n await this.initializeDb(props);\r\n return props;\r\n }\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-backend",
3
- "version": "5.13.0",
3
+ "version": "5.13.2",
4
4
  "description": "iTwin.js backend components",
5
5
  "main": "lib/cjs/core-backend.js",
6
6
  "module": "lib/esm/core-backend.js",
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@opentelemetry/api": "^1.0.4",
30
- "@itwin/core-bentley": "5.13.0",
31
- "@itwin/core-common": "5.13.0",
32
- "@itwin/core-geometry": "5.13.0",
33
- "@itwin/ecschema-metadata": "5.13.0"
30
+ "@itwin/core-bentley": "5.13.2",
31
+ "@itwin/core-geometry": "5.13.2",
32
+ "@itwin/core-common": "5.13.2",
33
+ "@itwin/ecschema-metadata": "5.13.2"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@opentelemetry/api": {
@@ -71,17 +71,17 @@
71
71
  "marked": "^14.1.3",
72
72
  "sql-formatter": "^15.4.6",
73
73
  "vite": "^6.4.3",
74
- "@itwin/core-common": "5.13.0",
75
- "@itwin/core-bentley": "5.13.0",
76
- "@itwin/build-tools": "5.13.0",
77
- "@itwin/ecschema-metadata": "5.13.0",
78
- "@itwin/ecschema-locaters": "5.13.0",
79
- "@itwin/core-geometry": "5.13.0",
80
- "internal-tools": "3.0.0-dev.69",
81
- "@itwin/ecsql-common": "5.13.0"
74
+ "@itwin/build-tools": "5.13.2",
75
+ "@itwin/ecschema-locaters": "5.13.2",
76
+ "@itwin/core-geometry": "5.13.2",
77
+ "@itwin/core-bentley": "5.13.2",
78
+ "@itwin/core-common": "5.13.2",
79
+ "@itwin/ecsql-common": "5.13.2",
80
+ "@itwin/ecschema-metadata": "5.13.2",
81
+ "internal-tools": "3.0.0-dev.69"
82
82
  },
83
83
  "dependencies": {
84
- "@bentley/imodeljs-native": "5.13.28",
84
+ "@bentley/imodeljs-native": "5.13.34",
85
85
  "@itwin/object-storage-azure": "^3.0.4",
86
86
  "@azure/storage-blob": "^12.28.0",
87
87
  "form-data": "^4.0.6",