@itwin/core-backend 4.6.0-dev.6 → 4.6.0-dev.8

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.
Files changed (96) hide show
  1. package/lib/cjs/BackendHubAccess.js.map +1 -1
  2. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  3. package/lib/cjs/BisCoreSchema.js.map +1 -1
  4. package/lib/cjs/BlobContainerService.js.map +1 -1
  5. package/lib/cjs/BriefcaseManager.js.map +1 -1
  6. package/lib/cjs/Category.js.map +1 -1
  7. package/lib/cjs/ChangeSummaryManager.js +2 -2
  8. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  9. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  10. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  11. package/lib/cjs/ChangesetECAdaptor.js +237 -237
  12. package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
  13. package/lib/cjs/ChannelControl.js.map +1 -1
  14. package/lib/cjs/CheckpointManager.js.map +1 -1
  15. package/lib/cjs/ClassRegistry.js +5 -5
  16. package/lib/cjs/ClassRegistry.js.map +1 -1
  17. package/lib/cjs/CloudSqlite.js.map +1 -1
  18. package/lib/cjs/CodeService.js.map +1 -1
  19. package/lib/cjs/CodeSpecs.js.map +1 -1
  20. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  21. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  22. package/lib/cjs/DevTools.js.map +1 -1
  23. package/lib/cjs/DisplayStyle.js.map +1 -1
  24. package/lib/cjs/ECDb.js.map +1 -1
  25. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  26. package/lib/cjs/ECSqlStatement.js.map +1 -1
  27. package/lib/cjs/Element.js.map +1 -1
  28. package/lib/cjs/ElementAspect.js.map +1 -1
  29. package/lib/cjs/ElementGraphics.js.map +1 -1
  30. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  31. package/lib/cjs/Entity.js.map +1 -1
  32. package/lib/cjs/EntityReferences.js.map +1 -1
  33. package/lib/cjs/ExportGraphics.js.map +1 -1
  34. package/lib/cjs/ExternalSource.js.map +1 -1
  35. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  36. package/lib/cjs/GeometrySummary.js +47 -47
  37. package/lib/cjs/GeometrySummary.js.map +1 -1
  38. package/lib/cjs/HubMock.js.map +1 -1
  39. package/lib/cjs/IModelCloneContext.js.map +1 -1
  40. package/lib/cjs/IModelDb.js +8 -8
  41. package/lib/cjs/IModelDb.js.map +1 -1
  42. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  43. package/lib/cjs/IModelHost.js.map +1 -1
  44. package/lib/cjs/IModelJsFs.js.map +1 -1
  45. package/lib/cjs/IpcHost.js.map +1 -1
  46. package/lib/cjs/LineStyle.js.map +1 -1
  47. package/lib/cjs/LocalHub.js +1 -1
  48. package/lib/cjs/LocalHub.js.map +1 -1
  49. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  50. package/lib/cjs/Material.js.map +1 -1
  51. package/lib/cjs/Model.js.map +1 -1
  52. package/lib/cjs/NativeAppStorage.js.map +1 -1
  53. package/lib/cjs/NativeHost.js.map +1 -1
  54. package/lib/cjs/NavigationRelationship.js.map +1 -1
  55. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  56. package/lib/cjs/PropertyStore.js.map +1 -1
  57. package/lib/cjs/Relationship.js.map +1 -1
  58. package/lib/cjs/RpcBackend.js.map +1 -1
  59. package/lib/cjs/SQLiteDb.js.map +1 -1
  60. package/lib/cjs/Schema.js.map +1 -1
  61. package/lib/cjs/SchemaSync.js.map +1 -1
  62. package/lib/cjs/SchemaUtils.js.map +1 -1
  63. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  64. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  65. package/lib/cjs/SqliteStatement.js.map +1 -1
  66. package/lib/cjs/Texture.js.map +1 -1
  67. package/lib/cjs/TileStorage.js.map +1 -1
  68. package/lib/cjs/TxnManager.js.map +1 -1
  69. package/lib/cjs/ViewDefinition.js.map +1 -1
  70. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  71. package/lib/cjs/ViewStore.js.map +1 -1
  72. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  73. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +44 -44
  74. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  75. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  76. package/lib/cjs/assets/Settings/backend.setting.json5 +132 -132
  77. package/lib/cjs/core-backend.js.map +1 -1
  78. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  79. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  80. package/lib/cjs/domains/GenericElements.js.map +1 -1
  81. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  82. package/lib/cjs/rpc/multipart.js.map +1 -1
  83. package/lib/cjs/rpc/tracing.js.map +1 -1
  84. package/lib/cjs/rpc/web/logging.js.map +1 -1
  85. package/lib/cjs/rpc/web/request.js.map +1 -1
  86. package/lib/cjs/rpc/web/response.js.map +1 -1
  87. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  88. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  89. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  90. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  91. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  92. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  93. package/lib/cjs/workspace/Settings.js.map +1 -1
  94. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  95. package/lib/cjs/workspace/Workspace.js.map +1 -1
  96. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AA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9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC;AAED,cAAc;AACd,WAAiB,eAAe;IAC9B,MAAa,OAAQ,SAAQ,2BAAY;QAIvC,gBAAgB;QAChB,YAAY,OAAgB,EAAE,MAAc,EAAE,OAAe;YAC3D,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,CAAC;KACF;IATY,uBAAO,UASnB,CAAA;AAMH,CAAC,EAhBgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAgB/B","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 SQLite\r\n */\r\n\r\nimport { assert, BentleyError, DbResult, GuidString, Id64String, IDisposable, LRUMap } from \"@itwin/core-bentley\";\r\nimport { ECJsNames, IModelError } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n// spell:ignore julianday\r\n\r\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\r\n\r\n/** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so\r\n * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)\r\n * methods of [SqliteStatement]($backend).\r\n * @internal\r\n */\r\nexport interface StringParam {\r\n id?: Id64String;\r\n guid?: GuidString;\r\n}\r\n\r\n/** parameter Index (1-based), or name of the parameter (including the initial ':', '@' or '$')\r\n * @public\r\n */\r\nexport type BindParameter = number | string;\r\n\r\nfunction checkBind(stat: DbResult) {\r\n if (stat !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(stat, \"SQLite Bind error\");\r\n}\r\n\r\n/** Executes SQLite SQL statements.\r\n *\r\n * A statement must be prepared before it can be executed, and it must be released when no longer needed.\r\n * See [IModelDb.withPreparedSqliteStatement]($backend) or\r\n * [ECDb.withPreparedSqliteStatement]($backend) for a convenient and\r\n * reliable way to prepare, execute, and then release a statement.\r\n *\r\n * A statement may contain parameters that must be filled in before use by calling [SqliteStatement.bindValue]($backend)\r\n * or [SqliteStatement.bindValues]($backend).\r\n *\r\n * Once prepared (and parameters are bound, if any), the statement is executed by calling [SqliteStatement.step]($backend).\r\n * In case of an **SQL SELECT** statement, the current row can be retrieved with [SqliteStatement.getRow]($backend) as\r\n * a whole, or with [SqliteStatement.getValue]($backend) when individual values are needed.\r\n * Alternatively, query results of an **SQL SELECT** statement can be stepped through by using\r\n * standard iteration syntax, such as `for of`.\r\n *\r\n * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared\r\n * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.\r\n * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.\r\n * @public\r\n */\r\nexport class SqliteStatement implements IterableIterator<any>, IDisposable {\r\n private _stmt: IModelJsNative.SqliteStatement | undefined;\r\n private _db: IModelJsNative.AnyDb | undefined;\r\n\r\n public constructor(private _sql: string) { }\r\n public get stmt(): IModelJsNative.SqliteStatement { return this._stmt!; }\r\n public get sql() { return this._sql; }\r\n\r\n /** Check if this statement has been prepared successfully or not */\r\n public get isPrepared(): boolean { return undefined !== this._stmt; }\r\n\r\n /** Prepare this statement prior to first use.\r\n * @param db The DgnDb or ECDb to prepare the statement against\r\n * @param sql The SQL statement string to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.\r\n * The error.message property will provide details.\r\n */\r\n public prepare(db: IModelJsNative.AnyDb, logErrors = true): void {\r\n if (this.isPrepared)\r\n throw new Error(\"SqliteStatement is already prepared\");\r\n this._db = db;\r\n this._stmt = new IModelHost.platform.SqliteStatement();\r\n this._stmt.prepare(db, this._sql, logErrors);\r\n }\r\n\r\n /** Indicates whether the prepared statement makes no **direct* changes to the content of the file\r\n * or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.\r\n */\r\n public get isReadonly(): boolean {\r\n return this.stmt.isReadonly();\r\n }\r\n\r\n /** Reset this statement so that the next call to step will return the first row, if any.\r\n */\r\n public reset(): void {\r\n this.stmt.reset();\r\n }\r\n\r\n /** Call this function when finished with this statement. This releases the native resources held by the statement. */\r\n public dispose(): void {\r\n if (this._stmt) {\r\n this._stmt.dispose(); // free native statement\r\n this._stmt = undefined;\r\n this._db = undefined;\r\n }\r\n }\r\n\r\n /**\r\n * Call `step` on this statement and determine whether a new row is available.\r\n * Use this method only when this statement has been prepared with a SELECT statement.\r\n * @return true if a new row is available, false otherwise.\r\n * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.\r\n */\r\n public nextRow(): boolean {\r\n const rc = this.step();\r\n switch (rc) {\r\n case DbResult.BE_SQLITE_ROW:\r\n return true;\r\n case DbResult.BE_SQLITE_DONE:\r\n return false;\r\n }\r\n\r\n this.throwSqlError(rc);\r\n return false; // unreachable\r\n }\r\n\r\n public throwSqlError(rc: DbResult) {\r\n throw new SqliteStatement.DbError(\r\n rc === DbResult.BE_SQLITE_CONSTRAINT_FOREIGNKEY ? \"ValueIsInUse\" :\r\n rc === DbResult.BE_SQLITE_CONSTRAINT_UNIQUE ? \"DuplicateValue\" :\r\n \"SqlLogicError\", rc, `SQL error: ${this._db!.getLastError()}`);\r\n }\r\n\r\n public stepForWrite(): void {\r\n const rc = this.step();\r\n if (rc !== DbResult.BE_SQLITE_DONE)\r\n this.throwSqlError(rc);\r\n }\r\n\r\n /** Binds a value to the specified SQL parameter.\r\n * The value must be of one of these types:\r\n * JavaScript Type | SQLite Type\r\n * --- | ---\r\n * undefined | NULL\r\n * boolean | INTEGER with true being bound as 1 and false as 0\r\n * number | INTEGER if number is integral or REAL if number is not integral\r\n * string | TEXT\r\n * Uint8Array or ArrayBuffer | BLOB\r\n * [StringParam]($backend) where member **id** is set | INTEGER\r\n * [StringParam]($backend) where member **guid** is set | BLOB\r\n *\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param value Value to bind.\r\n * @throws [IModelError]($common) if the value is of an unsupported type or in\r\n * case of other binding errors.\r\n */\r\n public bindValue(parameter: BindParameter, value: any): void {\r\n let stat: DbResult;\r\n if (value === undefined || value === null) {\r\n stat = this.stmt.bindNull(parameter);\r\n } else if (typeof (value) === \"number\") {\r\n if (Number.isInteger(value))\r\n stat = this.stmt.bindInteger(parameter, value);\r\n else\r\n stat = this.stmt.bindDouble(parameter, value);\r\n } else if (typeof (value) === \"boolean\") {\r\n stat = this.stmt.bindInteger(parameter, value ? 1 : 0);\r\n } else if (typeof (value) === \"string\") {\r\n stat = this.stmt.bindString(parameter, value);\r\n } else if (!!value.id) {\r\n stat = this.stmt.bindId(parameter, value.id);\r\n } else if (!!value.guid) {\r\n stat = this.stmt.bindGuid(parameter, value.guid);\r\n } else if (value instanceof Uint8Array) {\r\n stat = this.stmt.bindBlob(parameter, value);\r\n } else\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);\r\n\r\n if (stat !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(stat, \"Error in bindValue\");\r\n }\r\n\r\n /** Bind an integer parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val integer to bind.\r\n */\r\n public bindInteger(parameter: BindParameter, val: number) {\r\n checkBind(this.stmt.bindInteger(parameter, val));\r\n }\r\n /** Bind an integer parameter if it is defined. Otherwise do nothing.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val integer to bind.\r\n */\r\n public maybeBindInteger(parameter: BindParameter, val?: number) {\r\n if (val !== undefined)\r\n this.bindInteger(parameter, val);\r\n }\r\n /** Bind a boolean parameter.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val boolean to bind.\r\n */\r\n public bindBoolean(parameter: BindParameter, val: boolean) {\r\n this.bindInteger(parameter, val ? 1 : 0);\r\n }\r\n /** Bind a boolean parameter if it is defined. Otherwise do nothing.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val boolean to bind.\r\n */\r\n public maybeBindBoolean(parameter: BindParameter, val?: boolean) {\r\n if (val !== undefined)\r\n this.bindBoolean(parameter, val);\r\n }\r\n /** JSON.stringify a property value and bind the JSON string.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val object to bind.\r\n * @internal\r\n */\r\n public bindProps<T>(colIndex: number, val: T) {\r\n this.bindString(colIndex, JSON.stringify(val));\r\n }\r\n /** JSON.stringify a property value if it is defined, and bind the JSON string. Otherwise do nothing.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val object to bind.\r\n * @internal\r\n */\r\n public maybeBindProps<T>(colIndex: number, val?: T) {\r\n if (val !== undefined)\r\n this.bindProps(colIndex, val);\r\n }\r\n /** Bind a double parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val double to bind.\r\n */\r\n public bindDouble(parameter: BindParameter, val: number) {\r\n checkBind(this.stmt.bindDouble(parameter, val));\r\n }\r\n /** Bind a double parameter if it is defined. Otherwise do nothing.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val double to bind.\r\n */\r\n public maybeBindDouble(parameter: BindParameter, val?: number) {\r\n if (val !== undefined)\r\n this.bindDouble(parameter, val);\r\n }\r\n /** Bind a string parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val string to bind.\r\n */\r\n public bindString(parameter: BindParameter, val: string) {\r\n checkBind(this.stmt.bindString(parameter, val));\r\n }\r\n /** Bind a string parameter if it is defined. Otherwise do nothing.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val string to bind.\r\n */\r\n public maybeBindString(parameter: BindParameter, val?: string) {\r\n if (val !== undefined)\r\n this.bindString(parameter, val);\r\n }\r\n /** Bind an Id64String parameter as a 64-bit integer\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val Id to bind.\r\n */\r\n public bindId(parameter: BindParameter, id: Id64String) {\r\n checkBind(this.stmt.bindId(parameter, id));\r\n }\r\n /** Bind a Guid parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val Guid to bind.\r\n */\r\n public bindGuid(parameter: BindParameter, guid: GuidString) {\r\n checkBind(this.stmt.bindGuid(parameter, guid));\r\n }\r\n /** Bind a blob parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val blob to bind.\r\n */\r\n public bindBlob(parameter: BindParameter, blob: Uint8Array) {\r\n checkBind(this.stmt.bindBlob(parameter, blob));\r\n }\r\n /** Bind a blob parameter if it is defined. Otherwise do nothing.\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n * @param val blob to bind.\r\n */\r\n public maybeBindBlob(parameter: BindParameter, val?: Uint8Array) {\r\n if (val !== undefined)\r\n this.bindBlob(parameter, val);\r\n }\r\n /** Bind null to a parameter\r\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\r\n */\r\n public bindNull(parameter: BindParameter) {\r\n checkBind(this.stmt.bindNull(parameter));\r\n }\r\n\r\n /** Bind values to all parameters in the statement.\r\n * @param values The values to bind to the parameters.\r\n * Pass an *array* of values if the parameters are *positional*.\r\n * Pass an *object of the values keyed on the parameter name* for *named parameters*.\r\n * The values in either the array or object must match the respective types of the parameter.\r\n * See [[SqliteStatement.bindValue]] for details on the supported types.\r\n */\r\n public bindValues(values: any[] | object): void {\r\n if (Array.isArray(values)) {\r\n for (let i = 0; i < values.length; i++) {\r\n const paramIndex: number = i + 1;\r\n const paramValue: any = values[i];\r\n if (paramValue === undefined || paramValue === null)\r\n continue;\r\n\r\n this.bindValue(paramIndex, paramValue);\r\n }\r\n return;\r\n }\r\n\r\n for (const entry of Object.entries(values)) {\r\n const paramName: string = entry[0];\r\n const paramValue: any = entry[1];\r\n if (paramValue === undefined || paramValue === null)\r\n continue;\r\n\r\n this.bindValue(paramName, paramValue);\r\n }\r\n }\r\n\r\n /** Clear any bindings that were previously set on this statement.\r\n * @throws [IModelError]($common) in case of errors\r\n */\r\n public clearBindings(): void {\r\n const stat = this.stmt.clearBindings();\r\n if (stat !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(stat, \"Error in clearBindings\");\r\n }\r\n\r\n /** Step this statement to the next row.\r\n *\r\n * For **SQL SELECT** statements the method returns\r\n * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.\r\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.\r\n * - Error status in case of errors.\r\n *\r\n * For **SQL INSERT, UPDATE, DELETE** statements the method returns\r\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.\r\n * - Error status in case of errors.\r\n */\r\n public step(): DbResult {\r\n return this.stmt.step();\r\n }\r\n /** Get the query result's column count (only for SQL SELECT statements). */\r\n public getColumnCount(): number {\r\n return this.stmt.getColumnCount();\r\n }\r\n /** Get the value for the column at the given index in the query result.\r\n * @param columnIx Index of SQL column in query result (0-based)\r\n */\r\n public getValue(columnIx: number): SqliteValue {\r\n return new SqliteValue(this.stmt, columnIx);\r\n }\r\n /** Determine whether the value of the specified column is null\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public isValueNull(colIndex: number): boolean {\r\n return this.stmt.isValueNull(colIndex);\r\n }\r\n /** Get a size in bytes of a blob or text column\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getColumnBytes(colIndex: number): number {\r\n return this.stmt.getColumnBytes(colIndex);\r\n }\r\n /** Get a value as a blob\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueBlob(colIndex: number): Uint8Array {\r\n return this.stmt.getValueBlob(colIndex);\r\n }\r\n /** Get the value as a blob, or undefined if it is null.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueBlobMaybe(colIndex: number): Uint8Array | undefined {\r\n return this.isValueNull(colIndex) ? undefined : this.getValueBlob(colIndex);\r\n }\r\n /** Get a value as a double\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueDouble(colIndex: number): number {\r\n return this.stmt.getValueDouble(colIndex);\r\n }\r\n /** Get the value as an double, or undefined if it is null.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueDoubleMaybe(colIndex: number): number | undefined {\r\n return this.isValueNull(colIndex) ? undefined : this.getValueDouble(colIndex);\r\n }\r\n /** Get a value as a integer\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueInteger(colIndex: number): number {\r\n return this.stmt.getValueInteger(colIndex);\r\n }\r\n /** Get the value as an integer, or undefined if it is null.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueIntegerMaybe(colIndex: number): number | undefined {\r\n return this.isValueNull(colIndex) ? undefined : this.getValueInteger(colIndex);\r\n }\r\n /** Get a value as a string\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueString(colIndex: number): string {\r\n return this.stmt.getValueString(colIndex);\r\n }\r\n /** Get the value as a string, or undefined if it is null.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueStringMaybe(colIndex: number): string | undefined {\r\n return this.isValueNull(colIndex) ? undefined : this.getValueString(colIndex);\r\n }\r\n /** Get a value as an Id\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueId(colIndex: number): Id64String {\r\n return this.stmt.getValueId(colIndex);\r\n }\r\n /** Get a value as a Guid\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueGuid(colIndex: number): GuidString {\r\n return this.stmt.getValueGuid(colIndex);\r\n }\r\n /** Get the value as a boolean. Returns `false` if the column is null.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n */\r\n public getValueBoolean(colIndex: number) {\r\n return this.isValueNull(colIndex) ? false : 0 !== this.getValueInteger(colIndex);\r\n }\r\n /** Get the value of a [julianday](https://www.sqlite.org/lang_datefunc.html) column as a JavaScript `Date`.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n * @beta\r\n */\r\n public getValueDate(colIndex: number) {\r\n return new Date((this.stmt.getValueDouble(colIndex) - 2440587.5) * 86400000); // conversion from julian day ms to unix epoch ms\r\n }\r\n /** Get the value as a \"props\" JSON string, then parse it and return the object\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n * @internal\r\n */\r\n public getProps<T>(colIndex: number): T {\r\n return JSON.parse(this.getValueString(colIndex));\r\n }\r\n /** Get the value as a \"props\" JSON string, then parse it and return the object.\r\n * If the column is null, return undefined.\r\n * @param colIndex Index of SQL column in query result (0-based)\r\n * @internal\r\n */\r\n public getPropsMaybe<T>(colIndex: number): T | undefined {\r\n return this.isValueNull(colIndex) ? undefined : this.getProps(colIndex);\r\n }\r\n\r\n /** Get the current row.\r\n * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.\r\n *\r\n * The SQL select clause item's name becomes the member name of the JavaScript object, **with the first character lowered**.\r\n *\r\n * SQLite Type | JavaScript Type\r\n * --- | ---\r\n * [SqliteValueType.Null]($backend) | undefined\r\n * [SqliteValueType.Integer]($backend) | number\r\n * [SqliteValueType.Double]($backend) | number\r\n * [SqliteValueType.String]($backend) | string\r\n * [SqliteValueType.Blob]($backend) | Uint8Array\r\n */\r\n public getRow(): any {\r\n const colCount = this.getColumnCount();\r\n const row: object = {};\r\n const duplicatePropNames = new Map<string, number>();\r\n for (let i = 0; i < colCount; i++) {\r\n const sqliteValue = this.getValue(i);\r\n if (!sqliteValue.isNull) {\r\n const propName: string = SqliteStatement.determineResultRowPropertyName(duplicatePropNames, sqliteValue);\r\n let val: any;\r\n switch (sqliteValue.type) {\r\n case SqliteValueType.Blob:\r\n val = sqliteValue.getBlob();\r\n break;\r\n case SqliteValueType.Double:\r\n val = sqliteValue.getDouble();\r\n break;\r\n case SqliteValueType.Integer:\r\n val = sqliteValue.getInteger();\r\n break;\r\n case SqliteValueType.String:\r\n val = sqliteValue.getString();\r\n break;\r\n\r\n default:\r\n throw new Error(\"Unsupported SqliteValueType\");\r\n }\r\n\r\n Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });\r\n }\r\n }\r\n return row;\r\n }\r\n\r\n private static determineResultRowPropertyName(duplicatePropNames: Map<string, number>, sqliteValue: SqliteValue): string {\r\n let jsName = ECJsNames.toJsName(sqliteValue.columnName);\r\n\r\n // now check duplicates. If there are, append a numeric suffix to the duplicates\r\n let suffix = duplicatePropNames.get(jsName);\r\n if (suffix === undefined)\r\n duplicatePropNames.set(jsName, 0);\r\n else {\r\n suffix++;\r\n duplicatePropNames.set(jsName, suffix);\r\n jsName += `_${suffix}`;\r\n }\r\n\r\n return jsName;\r\n }\r\n\r\n /** Calls step when called as an iterator.\r\n */\r\n public next(): IteratorResult<any> {\r\n return DbResult.BE_SQLITE_ROW === this.step() ? { done: false, value: this.getRow() } : { done: true, value: undefined };\r\n }\r\n\r\n /** The iterator that will step through the results of this statement. */\r\n public [Symbol.iterator](): IterableIterator<any> { return this; }\r\n}\r\n\r\n/** Data type of a value in in an SQLite SQL query result.\r\n * See also:\r\n * - [SqliteValue]($backend)\r\n * - [SqliteStatement]($backend)\r\n * - [SqliteStatement.getValue]($backend)\r\n * @public\r\n */\r\nexport enum SqliteValueType {\r\n // do not change the values of that enum. It must correspond to the respective\r\n // enum DbValueType in the native BeSQLite API.\r\n Integer = 1,\r\n Double = 2,\r\n String = 3,\r\n Blob = 4,\r\n Null = 5,\r\n}\r\n\r\n/** Value of a column in a row of an SQLite SQL query result.\r\n * See also:\r\n * - [SqliteStatement]($backend)\r\n * - [SqliteStatement.getValue]($backend)\r\n * @public\r\n */\r\nexport class SqliteValue {\r\n private readonly _stmt: IModelJsNative.SqliteStatement;\r\n private readonly _colIndex: number;\r\n\r\n public constructor(stmt: IModelJsNative.SqliteStatement, colIndex: number) {\r\n this._stmt = stmt;\r\n this._colIndex = colIndex;\r\n }\r\n\r\n /** Indicates whether the value is NULL or not. */\r\n public get isNull(): boolean { return this._stmt.isValueNull(this._colIndex); }\r\n\r\n /** Gets the data type of the value. */\r\n public get type(): SqliteValueType { return this._stmt.getColumnType(this._colIndex); }\r\n\r\n /** Gets the name of the column of the value. */\r\n public get columnName(): string { return this._stmt.getColumnName(this._colIndex); }\r\n\r\n /** Gets the SqlValue as JavaScript value.\r\n *\r\n * SQLite Type | JavaScript Type\r\n * --- | ---\r\n * [SqliteValueType.Null]($backend) | undefined\r\n * [SqliteValueType.Integer]($backend) | number\r\n * [SqliteValueType.Double]($backend) | number\r\n * [SqliteValueType.String]($backend) | string\r\n * [SqliteValueType.Blob]($backend) | Uint8Array\r\n */\r\n public get value(): any {\r\n switch (this.type) {\r\n case SqliteValueType.Null:\r\n return undefined;\r\n case SqliteValueType.Blob:\r\n return this.getBlob();\r\n case SqliteValueType.Double:\r\n return this.getDouble();\r\n case SqliteValueType.Integer:\r\n return this.getInteger();\r\n case SqliteValueType.String:\r\n return this.getString();\r\n default:\r\n throw new Error(\"Unhandled SqliteValueType\");\r\n }\r\n }\r\n\r\n /** Get the value as Blob */\r\n public getBlob(): Uint8Array { return this._stmt.getValueBlob(this._colIndex); }\r\n /** Get the value as a double value */\r\n public getDouble(): number { return this._stmt.getValueDouble(this._colIndex); }\r\n /** Get the value as a integer value */\r\n public getInteger(): number { return this._stmt.getValueInteger(this._colIndex); }\r\n /** Get the value as a string value */\r\n public getString(): string { return this._stmt.getValueString(this._colIndex); }\r\n /** Get the value as an Id value */\r\n public getId(): Id64String { return this._stmt.getValueId(this._colIndex); }\r\n /** Get the value as a Guid value */\r\n public getGuid(): GuidString { return this._stmt.getValueGuid(this._colIndex); }\r\n}\r\n\r\ninterface Statement {\r\n isPrepared: boolean;\r\n sql: string;\r\n dispose(): void;\r\n reset(): void;\r\n clearBindings(): void;\r\n}\r\n\r\n/** A cache for previously prepared SqliteStatements.\r\n * It only holds Statements after they are no longer in use, resetting and clearing their bindings before saving them.\r\n * When a request to use a statement from the cache is made, it is first removed from the cache.\r\n * @internal\r\n */\r\nexport class StatementCache<Stmt extends Statement> {\r\n private _cache: LRUMap<string, Stmt>;\r\n\r\n public constructor(maxCount = 40) {\r\n this._cache = new LRUMap<string, Stmt>(maxCount);\r\n }\r\n\r\n public get size() { return this._cache.size; }\r\n public addOrDispose(stmt: Stmt): void {\r\n assert(stmt.isPrepared);\r\n\r\n const existing = this._cache.get(stmt.sql);\r\n if (existing !== undefined) {\r\n stmt.dispose(); // we already have a statement with this sql cached, we can't save another one so just dispose it\r\n return;\r\n }\r\n if (this._cache.size >= this._cache.limit) {\r\n const oldest = this._cache.shift()!;\r\n oldest[1].dispose();\r\n }\r\n stmt.reset();\r\n stmt.clearBindings();\r\n this._cache.set(stmt.sql, stmt);\r\n }\r\n\r\n public findAndRemove(sql: string): Stmt | undefined {\r\n return this._cache.delete(sql);\r\n }\r\n\r\n public clear() {\r\n this._cache.forEach((stmt) => stmt.dispose());\r\n this._cache.clear();\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SqliteStatement {\r\n export class DbError extends BentleyError {\r\n /** A string that indicates the type of problem that caused the exception. */\r\n public readonly errorId: ErrorId;\r\n\r\n /** @internal */\r\n constructor(errorId: ErrorId, errNum: number, message: string) {\r\n super(errNum, message);\r\n this.errorId = errorId;\r\n }\r\n }\r\n\r\n export type ErrorId =\r\n \"DuplicateValue\" |\r\n \"SqlLogicError\" |\r\n \"ValueIsInUse\";\r\n}\r\n"]}
1
+ {"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../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AE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC;AAED,cAAc;AACd,WAAiB,eAAe;IAC9B,MAAa,OAAQ,SAAQ,2BAAY;QAIvC,gBAAgB;QAChB,YAAY,OAAgB,EAAE,MAAc,EAAE,OAAe;YAC3D,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,CAAC;KACF;IATY,uBAAO,UASnB,CAAA;AAMH,CAAC,EAhBgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAgB/B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLite\n */\n\nimport { assert, BentleyError, DbResult, GuidString, Id64String, IDisposable, LRUMap } from \"@itwin/core-bentley\";\nimport { ECJsNames, IModelError } from \"@itwin/core-common\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { IModelHost } from \"./IModelHost\";\n\n// spell:ignore julianday\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\n/** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so\n * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)\n * methods of [SqliteStatement]($backend).\n * @internal\n */\nexport interface StringParam {\n id?: Id64String;\n guid?: GuidString;\n}\n\n/** parameter Index (1-based), or name of the parameter (including the initial ':', '@' or '$')\n * @public\n */\nexport type BindParameter = number | string;\n\nfunction checkBind(stat: DbResult) {\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"SQLite Bind error\");\n}\n\n/** Executes SQLite SQL statements.\n *\n * A statement must be prepared before it can be executed, and it must be released when no longer needed.\n * See [IModelDb.withPreparedSqliteStatement]($backend) or\n * [ECDb.withPreparedSqliteStatement]($backend) for a convenient and\n * reliable way to prepare, execute, and then release a statement.\n *\n * A statement may contain parameters that must be filled in before use by calling [SqliteStatement.bindValue]($backend)\n * or [SqliteStatement.bindValues]($backend).\n *\n * Once prepared (and parameters are bound, if any), the statement is executed by calling [SqliteStatement.step]($backend).\n * In case of an **SQL SELECT** statement, the current row can be retrieved with [SqliteStatement.getRow]($backend) as\n * a whole, or with [SqliteStatement.getValue]($backend) when individual values are needed.\n * Alternatively, query results of an **SQL SELECT** statement can be stepped through by using\n * standard iteration syntax, such as `for of`.\n *\n * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared\n * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.\n * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.\n * @public\n */\nexport class SqliteStatement implements IterableIterator<any>, IDisposable {\n private _stmt: IModelJsNative.SqliteStatement | undefined;\n private _db: IModelJsNative.AnyDb | undefined;\n\n public constructor(private _sql: string) { }\n public get stmt(): IModelJsNative.SqliteStatement { return this._stmt!; }\n public get sql() { return this._sql; }\n\n /** Check if this statement has been prepared successfully or not */\n public get isPrepared(): boolean { return undefined !== this._stmt; }\n\n /** Prepare this statement prior to first use.\n * @param db The DgnDb or ECDb to prepare the statement against\n * @param sql The SQL statement string to prepare\n * @param logErrors Determine if errors are logged or not\n * @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.\n * The error.message property will provide details.\n */\n public prepare(db: IModelJsNative.AnyDb, logErrors = true): void {\n if (this.isPrepared)\n throw new Error(\"SqliteStatement is already prepared\");\n this._db = db;\n this._stmt = new IModelHost.platform.SqliteStatement();\n this._stmt.prepare(db, this._sql, logErrors);\n }\n\n /** Indicates whether the prepared statement makes no **direct* changes to the content of the file\n * or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.\n */\n public get isReadonly(): boolean {\n return this.stmt.isReadonly();\n }\n\n /** Reset this statement so that the next call to step will return the first row, if any.\n */\n public reset(): void {\n this.stmt.reset();\n }\n\n /** Call this function when finished with this statement. This releases the native resources held by the statement. */\n public dispose(): void {\n if (this._stmt) {\n this._stmt.dispose(); // free native statement\n this._stmt = undefined;\n this._db = undefined;\n }\n }\n\n /**\n * Call `step` on this statement and determine whether a new row is available.\n * Use this method only when this statement has been prepared with a SELECT statement.\n * @return true if a new row is available, false otherwise.\n * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.\n */\n public nextRow(): boolean {\n const rc = this.step();\n switch (rc) {\n case DbResult.BE_SQLITE_ROW:\n return true;\n case DbResult.BE_SQLITE_DONE:\n return false;\n }\n\n this.throwSqlError(rc);\n return false; // unreachable\n }\n\n public throwSqlError(rc: DbResult) {\n throw new SqliteStatement.DbError(\n rc === DbResult.BE_SQLITE_CONSTRAINT_FOREIGNKEY ? \"ValueIsInUse\" :\n rc === DbResult.BE_SQLITE_CONSTRAINT_UNIQUE ? \"DuplicateValue\" :\n \"SqlLogicError\", rc, `SQL error: ${this._db!.getLastError()}`);\n }\n\n public stepForWrite(): void {\n const rc = this.step();\n if (rc !== DbResult.BE_SQLITE_DONE)\n this.throwSqlError(rc);\n }\n\n /** Binds a value to the specified SQL parameter.\n * The value must be of one of these types:\n * JavaScript Type | SQLite Type\n * --- | ---\n * undefined | NULL\n * boolean | INTEGER with true being bound as 1 and false as 0\n * number | INTEGER if number is integral or REAL if number is not integral\n * string | TEXT\n * Uint8Array or ArrayBuffer | BLOB\n * [StringParam]($backend) where member **id** is set | INTEGER\n * [StringParam]($backend) where member **guid** is set | BLOB\n *\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param value Value to bind.\n * @throws [IModelError]($common) if the value is of an unsupported type or in\n * case of other binding errors.\n */\n public bindValue(parameter: BindParameter, value: any): void {\n let stat: DbResult;\n if (value === undefined || value === null) {\n stat = this.stmt.bindNull(parameter);\n } else if (typeof (value) === \"number\") {\n if (Number.isInteger(value))\n stat = this.stmt.bindInteger(parameter, value);\n else\n stat = this.stmt.bindDouble(parameter, value);\n } else if (typeof (value) === \"boolean\") {\n stat = this.stmt.bindInteger(parameter, value ? 1 : 0);\n } else if (typeof (value) === \"string\") {\n stat = this.stmt.bindString(parameter, value);\n } else if (!!value.id) {\n stat = this.stmt.bindId(parameter, value.id);\n } else if (!!value.guid) {\n stat = this.stmt.bindGuid(parameter, value.guid);\n } else if (value instanceof Uint8Array) {\n stat = this.stmt.bindBlob(parameter, value);\n } else\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);\n\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in bindValue\");\n }\n\n /** Bind an integer parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val integer to bind.\n */\n public bindInteger(parameter: BindParameter, val: number) {\n checkBind(this.stmt.bindInteger(parameter, val));\n }\n /** Bind an integer parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val integer to bind.\n */\n public maybeBindInteger(parameter: BindParameter, val?: number) {\n if (val !== undefined)\n this.bindInteger(parameter, val);\n }\n /** Bind a boolean parameter.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val boolean to bind.\n */\n public bindBoolean(parameter: BindParameter, val: boolean) {\n this.bindInteger(parameter, val ? 1 : 0);\n }\n /** Bind a boolean parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val boolean to bind.\n */\n public maybeBindBoolean(parameter: BindParameter, val?: boolean) {\n if (val !== undefined)\n this.bindBoolean(parameter, val);\n }\n /** JSON.stringify a property value and bind the JSON string.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val object to bind.\n * @internal\n */\n public bindProps<T>(colIndex: number, val: T) {\n this.bindString(colIndex, JSON.stringify(val));\n }\n /** JSON.stringify a property value if it is defined, and bind the JSON string. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val object to bind.\n * @internal\n */\n public maybeBindProps<T>(colIndex: number, val?: T) {\n if (val !== undefined)\n this.bindProps(colIndex, val);\n }\n /** Bind a double parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val double to bind.\n */\n public bindDouble(parameter: BindParameter, val: number) {\n checkBind(this.stmt.bindDouble(parameter, val));\n }\n /** Bind a double parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val double to bind.\n */\n public maybeBindDouble(parameter: BindParameter, val?: number) {\n if (val !== undefined)\n this.bindDouble(parameter, val);\n }\n /** Bind a string parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val string to bind.\n */\n public bindString(parameter: BindParameter, val: string) {\n checkBind(this.stmt.bindString(parameter, val));\n }\n /** Bind a string parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val string to bind.\n */\n public maybeBindString(parameter: BindParameter, val?: string) {\n if (val !== undefined)\n this.bindString(parameter, val);\n }\n /** Bind an Id64String parameter as a 64-bit integer\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Id to bind.\n */\n public bindId(parameter: BindParameter, id: Id64String) {\n checkBind(this.stmt.bindId(parameter, id));\n }\n /** Bind a Guid parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val Guid to bind.\n */\n public bindGuid(parameter: BindParameter, guid: GuidString) {\n checkBind(this.stmt.bindGuid(parameter, guid));\n }\n /** Bind a blob parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val blob to bind.\n */\n public bindBlob(parameter: BindParameter, blob: Uint8Array) {\n checkBind(this.stmt.bindBlob(parameter, blob));\n }\n /** Bind a blob parameter if it is defined. Otherwise do nothing.\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n * @param val blob to bind.\n */\n public maybeBindBlob(parameter: BindParameter, val?: Uint8Array) {\n if (val !== undefined)\n this.bindBlob(parameter, val);\n }\n /** Bind null to a parameter\n * @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')\n */\n public bindNull(parameter: BindParameter) {\n checkBind(this.stmt.bindNull(parameter));\n }\n\n /** Bind values to all parameters in the statement.\n * @param values The values to bind to the parameters.\n * Pass an *array* of values if the parameters are *positional*.\n * Pass an *object of the values keyed on the parameter name* for *named parameters*.\n * The values in either the array or object must match the respective types of the parameter.\n * See [[SqliteStatement.bindValue]] for details on the supported types.\n */\n public bindValues(values: any[] | object): void {\n if (Array.isArray(values)) {\n for (let i = 0; i < values.length; i++) {\n const paramIndex: number = i + 1;\n const paramValue: any = values[i];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramIndex, paramValue);\n }\n return;\n }\n\n for (const entry of Object.entries(values)) {\n const paramName: string = entry[0];\n const paramValue: any = entry[1];\n if (paramValue === undefined || paramValue === null)\n continue;\n\n this.bindValue(paramName, paramValue);\n }\n }\n\n /** Clear any bindings that were previously set on this statement.\n * @throws [IModelError]($common) in case of errors\n */\n public clearBindings(): void {\n const stat = this.stmt.clearBindings();\n if (stat !== DbResult.BE_SQLITE_OK)\n throw new IModelError(stat, \"Error in clearBindings\");\n }\n\n /** Step this statement to the next row.\n *\n * For **SQL SELECT** statements the method returns\n * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.\n * - Error status in case of errors.\n *\n * For **SQL INSERT, UPDATE, DELETE** statements the method returns\n * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.\n * - Error status in case of errors.\n */\n public step(): DbResult {\n return this.stmt.step();\n }\n /** Get the query result's column count (only for SQL SELECT statements). */\n public getColumnCount(): number {\n return this.stmt.getColumnCount();\n }\n /** Get the value for the column at the given index in the query result.\n * @param columnIx Index of SQL column in query result (0-based)\n */\n public getValue(columnIx: number): SqliteValue {\n return new SqliteValue(this.stmt, columnIx);\n }\n /** Determine whether the value of the specified column is null\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public isValueNull(colIndex: number): boolean {\n return this.stmt.isValueNull(colIndex);\n }\n /** Get a size in bytes of a blob or text column\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getColumnBytes(colIndex: number): number {\n return this.stmt.getColumnBytes(colIndex);\n }\n /** Get a value as a blob\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBlob(colIndex: number): Uint8Array {\n return this.stmt.getValueBlob(colIndex);\n }\n /** Get the value as a blob, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBlobMaybe(colIndex: number): Uint8Array | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueBlob(colIndex);\n }\n /** Get a value as a double\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueDouble(colIndex: number): number {\n return this.stmt.getValueDouble(colIndex);\n }\n /** Get the value as an double, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueDoubleMaybe(colIndex: number): number | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueDouble(colIndex);\n }\n /** Get a value as a integer\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueInteger(colIndex: number): number {\n return this.stmt.getValueInteger(colIndex);\n }\n /** Get the value as an integer, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueIntegerMaybe(colIndex: number): number | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueInteger(colIndex);\n }\n /** Get a value as a string\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueString(colIndex: number): string {\n return this.stmt.getValueString(colIndex);\n }\n /** Get the value as a string, or undefined if it is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueStringMaybe(colIndex: number): string | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getValueString(colIndex);\n }\n /** Get a value as an Id\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueId(colIndex: number): Id64String {\n return this.stmt.getValueId(colIndex);\n }\n /** Get a value as a Guid\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueGuid(colIndex: number): GuidString {\n return this.stmt.getValueGuid(colIndex);\n }\n /** Get the value as a boolean. Returns `false` if the column is null.\n * @param colIndex Index of SQL column in query result (0-based)\n */\n public getValueBoolean(colIndex: number) {\n return this.isValueNull(colIndex) ? false : 0 !== this.getValueInteger(colIndex);\n }\n /** Get the value of a [julianday](https://www.sqlite.org/lang_datefunc.html) column as a JavaScript `Date`.\n * @param colIndex Index of SQL column in query result (0-based)\n * @beta\n */\n public getValueDate(colIndex: number) {\n return new Date((this.stmt.getValueDouble(colIndex) - 2440587.5) * 86400000); // conversion from julian day ms to unix epoch ms\n }\n /** Get the value as a \"props\" JSON string, then parse it and return the object\n * @param colIndex Index of SQL column in query result (0-based)\n * @internal\n */\n public getProps<T>(colIndex: number): T {\n return JSON.parse(this.getValueString(colIndex));\n }\n /** Get the value as a \"props\" JSON string, then parse it and return the object.\n * If the column is null, return undefined.\n * @param colIndex Index of SQL column in query result (0-based)\n * @internal\n */\n public getPropsMaybe<T>(colIndex: number): T | undefined {\n return this.isValueNull(colIndex) ? undefined : this.getProps(colIndex);\n }\n\n /** Get the current row.\n * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.\n *\n * The SQL select clause item's name becomes the member name of the JavaScript object, **with the first character lowered**.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public getRow(): any {\n const colCount = this.getColumnCount();\n const row: object = {};\n const duplicatePropNames = new Map<string, number>();\n for (let i = 0; i < colCount; i++) {\n const sqliteValue = this.getValue(i);\n if (!sqliteValue.isNull) {\n const propName: string = SqliteStatement.determineResultRowPropertyName(duplicatePropNames, sqliteValue);\n let val: any;\n switch (sqliteValue.type) {\n case SqliteValueType.Blob:\n val = sqliteValue.getBlob();\n break;\n case SqliteValueType.Double:\n val = sqliteValue.getDouble();\n break;\n case SqliteValueType.Integer:\n val = sqliteValue.getInteger();\n break;\n case SqliteValueType.String:\n val = sqliteValue.getString();\n break;\n\n default:\n throw new Error(\"Unsupported SqliteValueType\");\n }\n\n Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });\n }\n }\n return row;\n }\n\n private static determineResultRowPropertyName(duplicatePropNames: Map<string, number>, sqliteValue: SqliteValue): string {\n let jsName = ECJsNames.toJsName(sqliteValue.columnName);\n\n // now check duplicates. If there are, append a numeric suffix to the duplicates\n let suffix = duplicatePropNames.get(jsName);\n if (suffix === undefined)\n duplicatePropNames.set(jsName, 0);\n else {\n suffix++;\n duplicatePropNames.set(jsName, suffix);\n jsName += `_${suffix}`;\n }\n\n return jsName;\n }\n\n /** Calls step when called as an iterator.\n */\n public next(): IteratorResult<any> {\n return DbResult.BE_SQLITE_ROW === this.step() ? { done: false, value: this.getRow() } : { done: true, value: undefined };\n }\n\n /** The iterator that will step through the results of this statement. */\n public [Symbol.iterator](): IterableIterator<any> { return this; }\n}\n\n/** Data type of a value in in an SQLite SQL query result.\n * See also:\n * - [SqliteValue]($backend)\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport enum SqliteValueType {\n // do not change the values of that enum. It must correspond to the respective\n // enum DbValueType in the native BeSQLite API.\n Integer = 1,\n Double = 2,\n String = 3,\n Blob = 4,\n Null = 5,\n}\n\n/** Value of a column in a row of an SQLite SQL query result.\n * See also:\n * - [SqliteStatement]($backend)\n * - [SqliteStatement.getValue]($backend)\n * @public\n */\nexport class SqliteValue {\n private readonly _stmt: IModelJsNative.SqliteStatement;\n private readonly _colIndex: number;\n\n public constructor(stmt: IModelJsNative.SqliteStatement, colIndex: number) {\n this._stmt = stmt;\n this._colIndex = colIndex;\n }\n\n /** Indicates whether the value is NULL or not. */\n public get isNull(): boolean { return this._stmt.isValueNull(this._colIndex); }\n\n /** Gets the data type of the value. */\n public get type(): SqliteValueType { return this._stmt.getColumnType(this._colIndex); }\n\n /** Gets the name of the column of the value. */\n public get columnName(): string { return this._stmt.getColumnName(this._colIndex); }\n\n /** Gets the SqlValue as JavaScript value.\n *\n * SQLite Type | JavaScript Type\n * --- | ---\n * [SqliteValueType.Null]($backend) | undefined\n * [SqliteValueType.Integer]($backend) | number\n * [SqliteValueType.Double]($backend) | number\n * [SqliteValueType.String]($backend) | string\n * [SqliteValueType.Blob]($backend) | Uint8Array\n */\n public get value(): any {\n switch (this.type) {\n case SqliteValueType.Null:\n return undefined;\n case SqliteValueType.Blob:\n return this.getBlob();\n case SqliteValueType.Double:\n return this.getDouble();\n case SqliteValueType.Integer:\n return this.getInteger();\n case SqliteValueType.String:\n return this.getString();\n default:\n throw new Error(\"Unhandled SqliteValueType\");\n }\n }\n\n /** Get the value as Blob */\n public getBlob(): Uint8Array { return this._stmt.getValueBlob(this._colIndex); }\n /** Get the value as a double value */\n public getDouble(): number { return this._stmt.getValueDouble(this._colIndex); }\n /** Get the value as a integer value */\n public getInteger(): number { return this._stmt.getValueInteger(this._colIndex); }\n /** Get the value as a string value */\n public getString(): string { return this._stmt.getValueString(this._colIndex); }\n /** Get the value as an Id value */\n public getId(): Id64String { return this._stmt.getValueId(this._colIndex); }\n /** Get the value as a Guid value */\n public getGuid(): GuidString { return this._stmt.getValueGuid(this._colIndex); }\n}\n\ninterface Statement {\n isPrepared: boolean;\n sql: string;\n dispose(): void;\n reset(): void;\n clearBindings(): void;\n}\n\n/** A cache for previously prepared SqliteStatements.\n * It only holds Statements after they are no longer in use, resetting and clearing their bindings before saving them.\n * When a request to use a statement from the cache is made, it is first removed from the cache.\n * @internal\n */\nexport class StatementCache<Stmt extends Statement> {\n private _cache: LRUMap<string, Stmt>;\n\n public constructor(maxCount = 40) {\n this._cache = new LRUMap<string, Stmt>(maxCount);\n }\n\n public get size() { return this._cache.size; }\n public addOrDispose(stmt: Stmt): void {\n assert(stmt.isPrepared);\n\n const existing = this._cache.get(stmt.sql);\n if (existing !== undefined) {\n stmt.dispose(); // we already have a statement with this sql cached, we can't save another one so just dispose it\n return;\n }\n if (this._cache.size >= this._cache.limit) {\n const oldest = this._cache.shift()!;\n oldest[1].dispose();\n }\n stmt.reset();\n stmt.clearBindings();\n this._cache.set(stmt.sql, stmt);\n }\n\n public findAndRemove(sql: string): Stmt | undefined {\n return this._cache.delete(sql);\n }\n\n public clear() {\n this._cache.forEach((stmt) => stmt.dispose());\n this._cache.clear();\n }\n}\n\n/** @public */\nexport namespace SqliteStatement {\n export class DbError extends BentleyError {\n /** A string that indicates the type of problem that caused the exception. */\n public readonly errorId: ErrorId;\n\n /** @internal */\n constructor(errorId: ErrorId, errNum: number, message: string) {\n super(errNum, message);\n this.errorId = errorId;\n }\n }\n\n export type ErrorId =\n \"DuplicateValue\" |\n \"SqlLogicError\" |\n \"ValueIsInUse\";\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../src/Texture.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oDAE4B;AAC5B,uCAA8C;AAW9C;;GAEG;AACH,MAAa,OAAQ,SAAQ,2BAAiB;IAC5C,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,SAAS,CAAC,CAAC,CAAC;IAKpE,YAAY;IACZ,YAAsB,KAAyB,EAAE,MAAgB;QAC/D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAA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,CAAC;YACxD,MAAM;YACN,IAAI;YACJ,WAAW;YACX,KAAK,EAAE,iBAAiB;YACxB,SAAS,EAAE,KAAK;SACjB,CAAC;QAEF,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,aAAa,CAAC,QAAkB,EAAE,iBAA6B,EAAE,IAAY,EAAE,MAAyB,EAAE,IAAsC,EAAE,WAAoB;QAClL,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACjG,OAAO,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF;AAzED,0BAyEC","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 Elements\r\n */\r\n\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n Base64EncodedString, BisCodeSpec, Code, CodeScopeProps, CodeSpec, ImageSourceFormat, TextureProps,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.\r\n * @see [[Texture]] constructor.\r\n * @beta\r\n */\r\nexport interface TextureCreateProps extends Omit<TextureProps, \"data\"> {\r\n data: Base64EncodedString | Uint8Array;\r\n}\r\n\r\n/** Defines a rendering texture that is associated with a Material and applied to surface geometry.\r\n * @public\r\n */\r\nexport class Texture extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"Texture\"; }\r\n public format: ImageSourceFormat;\r\n public data: Uint8Array;\r\n public description?: string;\r\n\r\n /** @beta */\r\n protected constructor(props: TextureCreateProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.format = props.format;\r\n this.data = typeof props.data === \"string\" ? Base64EncodedString.toUint8Array(props.data) : props.data;\r\n this.description = props.description;\r\n }\r\n\r\n public override toJSON(): TextureProps {\r\n const val = super.toJSON() as TextureProps;\r\n val.format = this.format;\r\n val.data = Base64EncodedString.fromUint8Array(this.data);\r\n val.description = this.description;\r\n return val;\r\n }\r\n\r\n /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.\r\n * @param name The Texture name\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.texture);\r\n return 0 === name.length ? Code.createEmpty() : new Code({ spec: codeSpec.id, scope: scopeModelId, value: name });\r\n }\r\n\r\n /** Create a texture with the given parameters.\r\n * @param iModelDb The iModel to contain the texture.\r\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\r\n * @param name The name to serve as the texture's [Code]($common) value.\r\n * @param format The format of the image data.\r\n * @param data The image data in the format specified by `format`.\r\n * @param description An optional description of the texture\r\n * @returns The newly constructed Texture element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n * @see [[insertTexture]] to insert a new texture into the iModel.\r\n */\r\n public static createTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Texture {\r\n const textureProps: TextureCreateProps = {\r\n classFullName: this.classFullName,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n format,\r\n data,\r\n description,\r\n model: definitionModelId,\r\n isPrivate: false,\r\n };\r\n\r\n return new Texture(textureProps, iModelDb);\r\n }\r\n\r\n /** Insert a new texture into a [[DefinitionModel]].\r\n * @param iModelDb The iModel to contain the texture.\r\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\r\n * @param name The name to serve as the texture's [Code]($common) value.\r\n * @param format The format of the image data.\r\n * @param data The image data in the format specified by `format`.\r\n * @param description An optional description of the texture\r\n * @returns The Id of the newly-inserted texture element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n * @see [[insertTexture]] to insert a new texture into the iModel.\r\n */\r\n public static insertTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Id64String {\r\n const texture = this.createTexture(iModelDb, definitionModelId, name, format, data, description);\r\n return iModelDb.elements.insertElement(texture.toJSON());\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../src/Texture.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oDAE4B;AAC5B,uCAA8C;AAW9C;;GAEG;AACH,MAAa,OAAQ,SAAQ,2BAAiB;IAC5C,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,SAAS,CAAC,CAAC,CAAC;IAKpE,YAAY;IACZ,YAAsB,KAAyB,EAAE,MAAgB;QAC/D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,iCAAmB,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QACvG,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IACvC,CAAC;IAEe,MAAM;QACpB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAkB,CAAC;QAC3C,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,GAAG,CAAC,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,EAAE,WAAW,CAAC,CAAC;QACjG,OAAO,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF;AAzED,0BAyEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Elements\n */\n\nimport { Id64String } from \"@itwin/core-bentley\";\nimport {\n Base64EncodedString, BisCodeSpec, Code, CodeScopeProps, CodeSpec, ImageSourceFormat, TextureProps,\n} from \"@itwin/core-common\";\nimport { DefinitionElement } from \"./Element\";\nimport { IModelDb } from \"./IModelDb\";\n\n/** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.\n * @see [[Texture]] constructor.\n * @beta\n */\nexport interface TextureCreateProps extends Omit<TextureProps, \"data\"> {\n data: Base64EncodedString | Uint8Array;\n}\n\n/** Defines a rendering texture that is associated with a Material and applied to surface geometry.\n * @public\n */\nexport class Texture extends DefinitionElement {\n /** @internal */\n public static override get className(): string { return \"Texture\"; }\n public format: ImageSourceFormat;\n public data: Uint8Array;\n public description?: string;\n\n /** @beta */\n protected constructor(props: TextureCreateProps, iModel: IModelDb) {\n super(props, iModel);\n this.format = props.format;\n this.data = typeof props.data === \"string\" ? Base64EncodedString.toUint8Array(props.data) : props.data;\n this.description = props.description;\n }\n\n public override toJSON(): TextureProps {\n const val = super.toJSON() as TextureProps;\n val.format = this.format;\n val.data = Base64EncodedString.fromUint8Array(this.data);\n val.description = this.description;\n return val;\n }\n\n /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.\n * @param iModel The IModelDb\n * @param scopeModelId The Id of the DefinitionModel that contains the Texture and provides the scope for its name.\n * @param name The Texture name\n */\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code {\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.texture);\n return 0 === name.length ? Code.createEmpty() : new Code({ spec: codeSpec.id, scope: scopeModelId, value: name });\n }\n\n /** Create a texture with the given parameters.\n * @param iModelDb The iModel to contain the texture.\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\n * @param name The name to serve as the texture's [Code]($common) value.\n * @param format The format of the image data.\n * @param data The image data in the format specified by `format`.\n * @param description An optional description of the texture\n * @returns The newly constructed Texture element.\n * @throws [[IModelError]] if unable to create the element.\n * @see [[insertTexture]] to insert a new texture into the iModel.\n */\n public static createTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Texture {\n const textureProps: TextureCreateProps = {\n classFullName: this.classFullName,\n code: this.createCode(iModelDb, definitionModelId, name),\n format,\n data,\n description,\n model: definitionModelId,\n isPrivate: false,\n };\n\n return new Texture(textureProps, iModelDb);\n }\n\n /** Insert a new texture into a [[DefinitionModel]].\n * @param iModelDb The iModel to contain the texture.\n * @param definitionModelId The [[DefinitionModel]] to contain the texture.\n * @param name The name to serve as the texture's [Code]($common) value.\n * @param format The format of the image data.\n * @param data The image data in the format specified by `format`.\n * @param description An optional description of the texture\n * @returns The Id of the newly-inserted texture element.\n * @throws [[IModelError]] if unable to insert the element.\n * @see [[insertTexture]] to insert a new texture into the iModel.\n */\n public static insertTexture(iModelDb: IModelDb, definitionModelId: Id64String, name: string, format: ImageSourceFormat, data: Uint8Array | Base64EncodedString, description?: string): Id64String {\n const texture = this.createTexture(iModelDb, definitionModelId, name, format, data, description);\n return iModelDb.elements.insertElement(texture.toJSON());\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TileStorage.js","sourceRoot":"","sources":["../../src/TileStorage.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAAoC;AACpC,+BAAiC;AAEjC,oDAA4D;AAC5D,sDAA6C;AAC7C,mEAAgE;AAChE,6CAA0C;AAY1C;;;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AE,IAAI,CAAC,CAAC,CAAC;IAC3G,CAAC;IAEO,YAAY,CAAC,OAAe,EAAE,GAAY;QAChD,qBAAM,CAAC,YAAY,CACjB,6CAAqB,CAAC,iBAAiB,EACvC,GAAG,EACH,CAAC,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC,qBAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,OAAO,kBAAkB,EAAE,EAAE,GAAG,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CACnI,CAAC;IACJ,CAAC;CACF;AAlKD,kCAkKC","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\nimport { gunzip, gzip } from \"zlib\";\r\nimport { promisify } from \"util\";\r\nimport { Metadata, ObjectReference, ServerStorage, TransferConfig } from \"@itwin/object-storage-core\";\r\nimport { getTileObjectReference } from \"@itwin/core-common\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n/**\r\n * Identifies a tile in cloud tile cache.\r\n * @beta\r\n */\r\nexport interface TileId {\r\n treeId: string;\r\n contentId: string;\r\n guid: string;\r\n}\r\n\r\n/**\r\n * Facilitates interaction with cloud tile cache.\r\n * @beta\r\n */\r\nexport class TileStorage {\r\n /**\r\n * Allows using the underlying `ServerStorage` API directly.\r\n * @see https://github.com/iTwin/object-storage/\r\n */\r\n public readonly storage: ServerStorage;\r\n\r\n public constructor(storage: ServerStorage) {\r\n this.storage = storage;\r\n }\r\n\r\n private _initializedIModels: Set<string> = new Set();\r\n\r\n /**\r\n * Ensures any required cloud storage resources for a specific iModel are ready to use.\r\n */\r\n public async initialize(iModelId: string): Promise<void> {\r\n if (this._initializedIModels.has(iModelId))\r\n return;\r\n if (!(await this.storage.baseDirectoryExists({ baseDirectory: iModelId }))) {\r\n try {\r\n await this.storage.createBaseDirectory({ baseDirectory: iModelId });\r\n } catch (e: any) {\r\n // Ignore 409 errors. This is what Azure blob storage returns when the container already exists.\r\n // Usually this means multiple backends tried to initialize tile storage at the same time.\r\n if(e.statusCode !== 409)\r\n throw e;\r\n }\r\n }\r\n this._initializedIModels.add(iModelId);\r\n }\r\n\r\n /**\r\n * Returns config that can be used by frontends to download tiles\r\n * @param iModelId Id of the iModel\r\n * @param expiresInSeconds Optional number of seconds until the download URL expires. Defaults to expiring exactly at midnight of next Sunday to enable persistent client-side caching.\r\n * It is recommended to set this to a shorter period when using S3-compatible storage - an exact expiry date cannot be ensured due to limitations in their API.\r\n * @see [TileStorage]($frontend)\r\n */\r\n public async getDownloadConfig(iModelId: string, expiresInSeconds?: number): Promise<TransferConfig> {\r\n try {\r\n if (expiresInSeconds !== undefined)\r\n return await this.storage.getDownloadConfig({ baseDirectory: iModelId }, { expiresInSeconds });\r\n const expiresOn = new Date();\r\n expiresOn.setDate(expiresOn.getDate() + (7 - expiresOn.getDay())); // next Sunday\r\n expiresOn.setHours(0, 0, 0, 0); // exactly at midnight\r\n return await this.storage.getDownloadConfig({ baseDirectory: iModelId }, { expiresOn });\r\n } catch (err) {\r\n this.logException(\"Failed to get download config\", err);\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Uploads a tile to the cloud cache.\r\n */\r\n public async uploadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, content: Uint8Array, guid?: string, metadata?: Metadata): Promise<void> {\r\n try {\r\n await this.storage.upload(\r\n getTileObjectReference(iModelId, changesetId, treeId, contentId, guid),\r\n Buffer.from(IModelHost.compressCachedTiles ? await promisify(gzip)(content.buffer) : content.buffer),\r\n metadata,\r\n IModelHost.compressCachedTiles ? { contentEncoding: \"gzip\" } : undefined,\r\n );\r\n } catch (err) {\r\n this.logException(\"Failed to upload tile\", err);\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Downloads a tile from the cloud cache.\r\n */\r\n public async downloadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<Uint8Array> {\r\n try {\r\n const buffer = await this.storage.download(\r\n getTileObjectReference(iModelId, changesetId, treeId, contentId, guid),\r\n \"buffer\",\r\n );\r\n return IModelHost.compressCachedTiles ? await promisify(gunzip)(buffer) : buffer;\r\n } catch (err) {\r\n this.logException(\"Failed to download tile\", err);\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Returns an async iterator of all tiles that are found in the cloud cache.\r\n */\r\n public async *getCachedTilesGenerator(iModelId: string): AsyncGenerator<TileId> {\r\n const iterator = this.getCachedTilePages(iModelId);\r\n for await (const page of iterator) {\r\n for (const tile of page) {\r\n yield tile;\r\n }\r\n }\r\n }\r\n\r\n private async *getCachedTilePages(iModelId: string): AsyncGenerator<TileId[]> {\r\n const iterator = this.storage.getListObjectsPagedIterator({ baseDirectory: iModelId }, 500);\r\n let prevPage: IteratorResult<ObjectReference[], any> | undefined;\r\n do {\r\n // initiate loading the next page\r\n const page = iterator.next();\r\n // process results from the previous page\r\n if (prevPage)\r\n yield this.convertPage(prevPage.value);\r\n // finish loading the next page\r\n prevPage = await page;\r\n } while (!prevPage.done);\r\n }\r\n\r\n private convertPage(page: ObjectReference[]): TileId[] {\r\n return page\r\n .map((objectReference) => ({\r\n parts: objectReference.relativeDirectory?.split(\"/\") ?? [\"\"],\r\n objectName: objectReference.objectName,\r\n }))\r\n .filter(({ parts, objectName }) => {\r\n if (parts[0] !== \"tiles\")\r\n return false;\r\n if (parts.length !== 3) {\r\n Logger.logWarning(BackendLoggerCategory.IModelTileStorage, \"Malformed tile id found in tile cache: {tileId}\", { tileId: [...parts, objectName].join(\"/\") });\r\n return false;\r\n }\r\n return true;\r\n }).map(({ parts, objectName }) => {\r\n // relativeDirectory = tiles/<treeId>/<guid>\r\n // objectName = <contentId>\r\n return {\r\n treeId: parts[1],\r\n contentId: objectName,\r\n guid: parts[2],\r\n };\r\n });\r\n }\r\n\r\n /**\r\n * Returns a list of all tiles that are found in the cloud cache.\r\n */\r\n public async getCachedTiles(iModelId: string): Promise<TileId[]> {\r\n const results: TileId[] = [];\r\n for await (const page of this.getCachedTilePages(iModelId)) {\r\n results.push(...page);\r\n }\r\n return results;\r\n }\r\n\r\n /**\r\n * Returns a boolean indicating whether a tile exists in the cloud cache\r\n */\r\n public async isTileCached(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<boolean> {\r\n return this.storage.objectExists(getTileObjectReference(iModelId, changesetId, treeId, contentId, guid));\r\n }\r\n\r\n private logException(message: string, err: unknown): void {\r\n Logger.logException(\r\n BackendLoggerCategory.IModelTileStorage,\r\n err,\r\n (category, msg, errorMetadata) => Logger.logError(category, `${message}: {errorMessage}`, { ...errorMetadata, errorMessage: msg }),\r\n );\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"TileStorage.js","sourceRoot":"","sources":["../../src/TileStorage.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAAoC;AACpC,+BAAiC;AAEjC,oDAA4D;AAC5D,sDAA6C;AAC7C,mEAAgE;AAChE,6CAA0C;AAY1C;;;GAGG;AACH,MAAa,WAAW;IAOtB,YAAmB,OAAsB;QAIjC,wBAAmB,GAAgB,IAAI,GAAG,EAAE,CAAC;QAHnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAID;;OAEG;IACI,KAAK,CAAC,UAAU,CAAC,QAAgB;QACtC,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC;YACxC,OAAO;QACT,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE;YAC1E,IAAI;gBACF,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC;aACrE;Y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C,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE;YAC/B,4CAA4C;YAC5C,2BAA2B;YAC3B,OAAO;gBACL,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;gBAChB,SAAS,EAAE,UAAU;gBACrB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aACf,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,cAAc,CAAC,QAAgB;QAC1C,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE;YAC1D,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;SACvB;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,WAAmB,EAAE,MAAc,EAAE,SAAiB,EAAE,IAAa;QAC/G,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAA,oCAAsB,EAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3G,CAAC;IAEO,YAAY,CAAC,OAAe,EAAE,GAAY;QAChD,qBAAM,CAAC,YAAY,CACjB,6CAAqB,CAAC,iBAAiB,EACvC,GAAG,EACH,CAAC,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC,qBAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,OAAO,kBAAkB,EAAE,EAAE,GAAG,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CACnI,CAAC;IACJ,CAAC;CACF;AAlKD,kCAkKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { gunzip, gzip } from \"zlib\";\nimport { promisify } from \"util\";\nimport { Metadata, ObjectReference, ServerStorage, TransferConfig } from \"@itwin/object-storage-core\";\nimport { getTileObjectReference } from \"@itwin/core-common\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { IModelHost } from \"./IModelHost\";\n\n/**\n * Identifies a tile in cloud tile cache.\n * @beta\n */\nexport interface TileId {\n treeId: string;\n contentId: string;\n guid: string;\n}\n\n/**\n * Facilitates interaction with cloud tile cache.\n * @beta\n */\nexport class TileStorage {\n /**\n * Allows using the underlying `ServerStorage` API directly.\n * @see https://github.com/iTwin/object-storage/\n */\n public readonly storage: ServerStorage;\n\n public constructor(storage: ServerStorage) {\n this.storage = storage;\n }\n\n private _initializedIModels: Set<string> = new Set();\n\n /**\n * Ensures any required cloud storage resources for a specific iModel are ready to use.\n */\n public async initialize(iModelId: string): Promise<void> {\n if (this._initializedIModels.has(iModelId))\n return;\n if (!(await this.storage.baseDirectoryExists({ baseDirectory: iModelId }))) {\n try {\n await this.storage.createBaseDirectory({ baseDirectory: iModelId });\n } catch (e: any) {\n // Ignore 409 errors. This is what Azure blob storage returns when the container already exists.\n // Usually this means multiple backends tried to initialize tile storage at the same time.\n if(e.statusCode !== 409)\n throw e;\n }\n }\n this._initializedIModels.add(iModelId);\n }\n\n /**\n * Returns config that can be used by frontends to download tiles\n * @param iModelId Id of the iModel\n * @param expiresInSeconds Optional number of seconds until the download URL expires. Defaults to expiring exactly at midnight of next Sunday to enable persistent client-side caching.\n * It is recommended to set this to a shorter period when using S3-compatible storage - an exact expiry date cannot be ensured due to limitations in their API.\n * @see [TileStorage]($frontend)\n */\n public async getDownloadConfig(iModelId: string, expiresInSeconds?: number): Promise<TransferConfig> {\n try {\n if (expiresInSeconds !== undefined)\n return await this.storage.getDownloadConfig({ baseDirectory: iModelId }, { expiresInSeconds });\n const expiresOn = new Date();\n expiresOn.setDate(expiresOn.getDate() + (7 - expiresOn.getDay())); // next Sunday\n expiresOn.setHours(0, 0, 0, 0); // exactly at midnight\n return await this.storage.getDownloadConfig({ baseDirectory: iModelId }, { expiresOn });\n } catch (err) {\n this.logException(\"Failed to get download config\", err);\n throw err;\n }\n }\n\n /**\n * Uploads a tile to the cloud cache.\n */\n public async uploadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, content: Uint8Array, guid?: string, metadata?: Metadata): Promise<void> {\n try {\n await this.storage.upload(\n getTileObjectReference(iModelId, changesetId, treeId, contentId, guid),\n Buffer.from(IModelHost.compressCachedTiles ? await promisify(gzip)(content.buffer) : content.buffer),\n metadata,\n IModelHost.compressCachedTiles ? { contentEncoding: \"gzip\" } : undefined,\n );\n } catch (err) {\n this.logException(\"Failed to upload tile\", err);\n throw err;\n }\n }\n\n /**\n * Downloads a tile from the cloud cache.\n */\n public async downloadTile(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<Uint8Array> {\n try {\n const buffer = await this.storage.download(\n getTileObjectReference(iModelId, changesetId, treeId, contentId, guid),\n \"buffer\",\n );\n return IModelHost.compressCachedTiles ? await promisify(gunzip)(buffer) : buffer;\n } catch (err) {\n this.logException(\"Failed to download tile\", err);\n throw err;\n }\n }\n\n /**\n * Returns an async iterator of all tiles that are found in the cloud cache.\n */\n public async *getCachedTilesGenerator(iModelId: string): AsyncGenerator<TileId> {\n const iterator = this.getCachedTilePages(iModelId);\n for await (const page of iterator) {\n for (const tile of page) {\n yield tile;\n }\n }\n }\n\n private async *getCachedTilePages(iModelId: string): AsyncGenerator<TileId[]> {\n const iterator = this.storage.getListObjectsPagedIterator({ baseDirectory: iModelId }, 500);\n let prevPage: IteratorResult<ObjectReference[], any> | undefined;\n do {\n // initiate loading the next page\n const page = iterator.next();\n // process results from the previous page\n if (prevPage)\n yield this.convertPage(prevPage.value);\n // finish loading the next page\n prevPage = await page;\n } while (!prevPage.done);\n }\n\n private convertPage(page: ObjectReference[]): TileId[] {\n return page\n .map((objectReference) => ({\n parts: objectReference.relativeDirectory?.split(\"/\") ?? [\"\"],\n objectName: objectReference.objectName,\n }))\n .filter(({ parts, objectName }) => {\n if (parts[0] !== \"tiles\")\n return false;\n if (parts.length !== 3) {\n Logger.logWarning(BackendLoggerCategory.IModelTileStorage, \"Malformed tile id found in tile cache: {tileId}\", { tileId: [...parts, objectName].join(\"/\") });\n return false;\n }\n return true;\n }).map(({ parts, objectName }) => {\n // relativeDirectory = tiles/<treeId>/<guid>\n // objectName = <contentId>\n return {\n treeId: parts[1],\n contentId: objectName,\n guid: parts[2],\n };\n });\n }\n\n /**\n * Returns a list of all tiles that are found in the cloud cache.\n */\n public async getCachedTiles(iModelId: string): Promise<TileId[]> {\n const results: TileId[] = [];\n for await (const page of this.getCachedTilePages(iModelId)) {\n results.push(...page);\n }\n return results;\n }\n\n /**\n * Returns a boolean indicating whether a tile exists in the cloud cache\n */\n public async isTileCached(iModelId: string, changesetId: string, treeId: string, contentId: string, guid?: string): Promise<boolean> {\n return this.storage.objectExists(getTileObjectReference(iModelId, changesetId, treeId, contentId, guid));\n }\n\n private logException(message: string, err: unknown): void {\n Logger.logException(\n BackendLoggerCategory.IModelTileStorage,\n err,\n (category, msg, errorMetadata) => Logger.logError(category, `${message}: {errorMessage}`, { ...errorMetadata, errorMessage: msg }),\n );\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TxnManager.js","sourceRoot":"","sources":["../../src/TxnManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,sDAE6B;AAE7B,mEAAgE;AAEhE,uCAAoC;AA4DpC,oCAAoC;AACpC,SAAgB,sBAAsB,CAAC,GAAW;IAChD,MAAM,OAAO,GAAG,mBAAmB,CAAC,WAAW,CAAC;IAChD,mBAAmB,CAAC,WAAW,GAAG,GAAG,CAAC;IACtC,OAAO,OAAO,CAAC;AACjB,CAAC;AAJD,wDAIC;AAED,iIAAiI;AACjI,MAAM,oBAAoB;IAKxB,YA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K,EAAE,CAAC;SAC9D;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,EAAE,IAAI,CAAC,qBAAqB,IAAI,KAAK,CAAC,CAAC;IACzG,CAAC;CACF;AAxSD,gCAwSC","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 iModels\r\n */\r\n\r\nimport * as touch from \"touch\";\r\nimport {\r\n assert, BeEvent, BentleyError, compareStrings, CompressedId64Set, DbResult, Id64Array, Id64String, IModelStatus, IndexMap, Logger, OrderedId64Array,\r\n} from \"@itwin/core-bentley\";\r\nimport { ChangedEntities, EntityIdAndClassIdIterable, ModelGeometryChangesProps, ModelIdAndGeometryGuid } from \"@itwin/core-common\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseDb, StandaloneDb } from \"./IModelDb\";\r\nimport { IpcHost } from \"./IpcHost\";\r\nimport { Relationship, RelationshipProps } from \"./Relationship\";\r\nimport { SqliteStatement } from \"./SqliteStatement\";\r\n\r\n/** A string that identifies a Txn.\r\n * @public\r\n */\r\nexport type TxnIdString = string;\r\n\r\n/** An error generated during dependency validation.\r\n * @see [[TxnManager.validationErrors]].\r\n * @public\r\n */\r\nexport interface ValidationError {\r\n /** If true, txn is aborted. */\r\n fatal: boolean;\r\n /** The type of error. */\r\n errorType: string;\r\n /** Optional description of what went wrong. */\r\n message?: string;\r\n}\r\n\r\n/** Describes a set of [[Element]]s or [[Model]]s that changed as part of a transaction.\r\n * @see [[TxnManager.onElementsChanged]] and [[TxnManager.onModelsChanged]].\r\n * @public\r\n */\r\nexport interface TxnChangedEntities {\r\n /** The entities that were inserted by the transaction. */\r\n readonly inserts: EntityIdAndClassIdIterable;\r\n /** The entities that were deleted by the transaction. */\r\n readonly deletes: EntityIdAndClassIdIterable;\r\n /** The entities that were modified by the transaction, including any [[Element]]s for which one of their [[ElementAspect]]s was changed. */\r\n readonly updates: EntityIdAndClassIdIterable;\r\n}\r\n\r\n/** Arguments supplied to [[TxnManager.queryLocalChanges]].\r\n * @beta\r\n */\r\nexport interface QueryLocalChangesArgs {\r\n /** If supplied and non-empty, restricts the results to include only EC instances belonging to the specified classes or subclasses thereof. */\r\n readonly includedClasses?: string[];\r\n /** If `true`, include changes that have not yet been saved. */\r\n readonly includeUnsavedChanges?: boolean;\r\n}\r\n\r\n/** Represents a change (insertion, deletion, or modification) to a single EC instance made in a local [[BriefcaseDb]].\r\n * @see [[TxnManager.queryLocalChanges]] to iterate all of the changed instances.\r\n* @beta\r\n*/\r\nexport interface ChangeInstanceKey {\r\n /** ECInstanceId of the instance. */\r\n id: Id64String;\r\n /** Fully-qualified class name of the instance. */\r\n classFullName: string;\r\n /** The type of change. */\r\n changeType: \"inserted\" | \"updated\" | \"deleted\";\r\n}\r\n\r\ntype EntitiesChangedEvent = BeEvent<(changes: TxnChangedEntities) => void>;\r\n\r\n/** Strictly for tests. @internal */\r\nexport function setMaxEntitiesPerEvent(max: number): number {\r\n const prevMax = ChangedEntitiesProc.maxPerEvent;\r\n ChangedEntitiesProc.maxPerEvent = max;\r\n return prevMax;\r\n}\r\n\r\n/** Maintains an ordered array of entity Ids and a parallel array containing the index of the corresponding entity's class Id. */\r\nclass ChangedEntitiesArray {\r\n public readonly entityIds = new OrderedId64Array();\r\n private readonly _classIndices: number[] = [];\r\n private readonly _classIds: IndexMap<Id64String>;\r\n\r\n public constructor(classIds: IndexMap<Id64String>) {\r\n this._classIds = classIds;\r\n }\r\n\r\n public insert(entityId: Id64String, classId: Id64String): void {\r\n const entityIndex = this.entityIds.insert(entityId);\r\n const classIndex = this._classIds.insert(classId);\r\n assert(classIndex >= 0);\r\n if (this.entityIds.length !== this._classIndices.length) {\r\n // New entity - insert corresponding class index entry.\r\n this._classIndices.splice(entityIndex, 0, classIndex);\r\n } else {\r\n // Existing entity - update corresponding class index.\r\n // (We do this because apparently connectors can (very rarely) change the class Id of an existing element).\r\n this._classIndices[entityIndex] = classIndex;\r\n }\r\n\r\n assert(this.entityIds.length === this._classIndices.length);\r\n }\r\n\r\n public clear(): void {\r\n this.entityIds.clear();\r\n this._classIndices.length = 0;\r\n }\r\n\r\n public addToChangedEntities(entities: ChangedEntities, type: \"deleted\" | \"inserted\" | \"updated\"): void {\r\n if (this.entityIds.length > 0)\r\n entities[type] = CompressedId64Set.compressIds(this.entityIds);\r\n }\r\n\r\n public iterable(classIds: Id64Array): EntityIdAndClassIdIterable {\r\n function* iterator(entityIds: ReadonlyArray<Id64String>, classIndices: number[]) {\r\n const entity = { id: \"\", classId: \"\" };\r\n for (let i = 0; i < entityIds.length; i++) {\r\n entity.id = entityIds[i];\r\n entity.classId = classIds[classIndices[i]];\r\n yield entity;\r\n }\r\n }\r\n\r\n return {\r\n [Symbol.iterator]: () => iterator(this.entityIds.array, this._classIndices),\r\n };\r\n }\r\n}\r\n\r\nclass ChangedEntitiesProc {\r\n private readonly _classIds = new IndexMap<Id64String>((lhs, rhs) => compareStrings(lhs, rhs));\r\n private readonly _inserted = new ChangedEntitiesArray(this._classIds);\r\n private readonly _deleted = new ChangedEntitiesArray(this._classIds);\r\n private readonly _updated = new ChangedEntitiesArray(this._classIds);\r\n private _currSize = 0;\r\n\r\n public static maxPerEvent = 1000;\r\n\r\n public static process(iModel: BriefcaseDb | StandaloneDb, mgr: TxnManager): void {\r\n if (mgr.isDisposed) {\r\n // The iModel is being closed. Do not prepare new sqlite statements.\r\n return;\r\n }\r\n\r\n this.processChanges(iModel, mgr.onElementsChanged, \"notifyElementsChanged\");\r\n this.processChanges(iModel, mgr.onModelsChanged, \"notifyModelsChanged\");\r\n }\r\n\r\n private sendEvent(iModel: BriefcaseDb | StandaloneDb, evt: EntitiesChangedEvent, evtName: \"notifyElementsChanged\" | \"notifyModelsChanged\") {\r\n if (this._currSize === 0)\r\n return;\r\n\r\n const classIds = this._classIds.toArray();\r\n\r\n // Notify backend listeners.\r\n const txnEntities: TxnChangedEntities = {\r\n inserts: this._inserted.iterable(classIds),\r\n deletes: this._deleted.iterable(classIds),\r\n updates: this._updated.iterable(classIds),\r\n };\r\n evt.raiseEvent(txnEntities);\r\n\r\n // Notify frontend listeners.\r\n const entities: ChangedEntities = {};\r\n this._inserted.addToChangedEntities(entities, \"inserted\");\r\n this._deleted.addToChangedEntities(entities, \"deleted\");\r\n this._updated.addToChangedEntities(entities, \"updated\");\r\n IpcHost.notifyTxns(iModel, evtName, entities);\r\n\r\n // Reset state.\r\n this._inserted.clear();\r\n this._deleted.clear();\r\n this._updated.clear();\r\n this._classIds.clear();\r\n this._currSize = 0;\r\n }\r\n\r\n private static processChanges(iModel: BriefcaseDb | StandaloneDb, changedEvent: EntitiesChangedEvent, evtName: \"notifyElementsChanged\" | \"notifyModelsChanged\") {\r\n try {\r\n const maxSize = this.maxPerEvent;\r\n const changes = new ChangedEntitiesProc();\r\n const select = \"notifyElementsChanged\" === evtName\r\n ? \"SELECT ElementId, ChangeType, ECClassId FROM temp.txn_Elements\"\r\n : \"SELECT ModelId, ChangeType, ECClassId FROM temp.txn_Models\";\r\n iModel.withPreparedSqliteStatement(select, (sql: SqliteStatement) => {\r\n const stmt = sql.stmt;\r\n while (sql.step() === DbResult.BE_SQLITE_ROW) {\r\n const id = stmt.getValueId(0);\r\n const classId = stmt.getValueId(2);\r\n switch (stmt.getValueInteger(1)) {\r\n case 0:\r\n changes._inserted.insert(id, classId);\r\n break;\r\n case 1:\r\n changes._updated.insert(id, classId);\r\n break;\r\n case 2:\r\n changes._deleted.insert(id, classId);\r\n break;\r\n }\r\n\r\n if (++changes._currSize >= maxSize)\r\n changes.sendEvent(iModel, changedEvent, evtName);\r\n }\r\n });\r\n\r\n changes.sendEvent(iModel, changedEvent, evtName);\r\n } catch (err) {\r\n Logger.logError(BackendLoggerCategory.IModelDb, BentleyError.getErrorMessage(err));\r\n }\r\n }\r\n}\r\n\r\n/** Manages local changes to a [[BriefcaseDb]] or [[StandaloneDb]] via [Txns]($docs/learning/InteractiveEditing.md)\r\n * @public\r\n */\r\nexport class TxnManager {\r\n /** @internal */\r\n private _isDisposed = false;\r\n\r\n /** @internal */\r\n public get isDisposed(): boolean {\r\n return this._isDisposed;\r\n }\r\n\r\n /** @internal */\r\n constructor(private _iModel: BriefcaseDb | StandaloneDb) {\r\n _iModel.onBeforeClose.addOnce(() => {\r\n this._isDisposed = true;\r\n });\r\n }\r\n\r\n /** Array of errors from dependency propagation */\r\n public readonly validationErrors: ValidationError[] = [];\r\n\r\n private get _nativeDb() { return this._iModel.nativeDb; }\r\n private _getElementClass(elClassName: string): typeof Element {\r\n return this._iModel.getJsClass(elClassName) as unknown as typeof Element;\r\n }\r\n private _getRelationshipClass(relClassName: string): typeof Relationship {\r\n return this._iModel.getJsClass<typeof Relationship>(relClassName);\r\n }\r\n\r\n /** If a -watch file exists for this iModel, update its timestamp so watching processes can be\r\n * notified that we've modified the briefcase.\r\n */\r\n private touchWatchFile(): void {\r\n // This is an async call. We don't have any reason to await it.\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n touch(this._iModel.watchFilePathName, { nocreate: true });\r\n }\r\n\r\n /** @internal */\r\n protected _onBeforeOutputsHandled(elClassName: string, elId: Id64String): void {\r\n (this._getElementClass(elClassName) as any).onBeforeOutputsHandled(elId, this._iModel);\r\n }\r\n /** @internal */\r\n protected _onAllInputsHandled(elClassName: string, elId: Id64String): void {\r\n (this._getElementClass(elClassName) as any).onAllInputsHandled(elId, this._iModel);\r\n }\r\n /** @internal */\r\n protected _onRootChanged(props: RelationshipProps): void {\r\n this._getRelationshipClass(props.classFullName).onRootChanged(props, this._iModel);\r\n }\r\n /** @internal */\r\n protected _onDeletedDependency(props: RelationshipProps): void {\r\n this._getRelationshipClass(props.classFullName).onDeletedDependency(props, this._iModel);\r\n }\r\n /** @internal */\r\n protected _onBeginValidate() { this.validationErrors.length = 0; }\r\n\r\n /** called from native code after validation of a Txn, either from saveChanges or apply changeset.\r\n * @internal\r\n */\r\n protected _onEndValidate() {\r\n ChangedEntitiesProc.process(this._iModel, this);\r\n this.onEndValidation.raiseEvent();\r\n // TODO: if (this.validationErrors.length !== 0) throw new IModelError(validation ...)\r\n }\r\n\r\n /** @internal */\r\n protected _onGeometryChanged(modelProps: ModelGeometryChangesProps[]) {\r\n this.onGeometryChanged.raiseEvent(modelProps);\r\n IpcHost.notifyEditingScope(this._iModel, \"notifyGeometryChanged\", modelProps); // send to frontend\r\n }\r\n\r\n /** @internal */\r\n protected _onGeometryGuidsChanged(changes: ModelIdAndGeometryGuid[]): void {\r\n this.onModelGeometryChanged.raiseEvent(changes);\r\n IpcHost.notifyTxns(this._iModel, \"notifyGeometryGuidsChanged\", changes);\r\n }\r\n\r\n /** @internal */\r\n protected _onCommit() {\r\n this.onCommit.raiseEvent();\r\n IpcHost.notifyTxns(this._iModel, \"notifyCommit\");\r\n }\r\n\r\n /** @internal */\r\n protected _onCommitted() {\r\n this.touchWatchFile();\r\n this.onCommitted.raiseEvent();\r\n IpcHost.notifyTxns(this._iModel, \"notifyCommitted\", this.hasPendingTxns, Date.now());\r\n }\r\n\r\n /** @internal */\r\n protected _onReplayExternalTxns() {\r\n this.onReplayExternalTxns.raiseEvent();\r\n IpcHost.notifyTxns(this._iModel, \"notifyReplayExternalTxns\");\r\n }\r\n\r\n /** @internal */\r\n protected _onReplayedExternalTxns() {\r\n this.onReplayedExternalTxns.raiseEvent();\r\n IpcHost.notifyTxns(this._iModel, \"notifyReplayedExternalTxns\");\r\n }\r\n\r\n /** @internal */\r\n protected _onChangesApplied() {\r\n ChangedEntitiesProc.process(this._iModel, this);\r\n this.onChangesApplied.raiseEvent();\r\n IpcHost.notifyTxns(this._iModel, \"notifyChangesApplied\");\r\n }\r\n\r\n /** @internal */\r\n protected _onBeforeUndoRedo(isUndo: boolean) {\r\n this.onBeforeUndoRedo.raiseEvent(isUndo);\r\n IpcHost.notifyTxns(this._iModel, \"notifyBeforeUndoRedo\", isUndo);\r\n }\r\n\r\n /** @internal */\r\n protected _onAfterUndoRedo(isUndo: boolean) {\r\n this.touchWatchFile();\r\n this.onAfterUndoRedo.raiseEvent(isUndo);\r\n IpcHost.notifyTxns(this._iModel, \"notifyAfterUndoRedo\", isUndo);\r\n }\r\n\r\n /** Dependency handlers may call method this to report a validation error.\r\n * @param error The error. If error.fatal === true, the transaction will cancel rather than commit.\r\n */\r\n public reportError(error: ValidationError) {\r\n this.validationErrors.push(error);\r\n this._nativeDb.logTxnError(error.fatal);\r\n }\r\n\r\n /** Determine whether any fatal validation errors have occurred during dependency propagation. */\r\n public get hasFatalError(): boolean { return this._nativeDb.hasFatalTxnError(); }\r\n\r\n /** @internal */\r\n public readonly onEndValidation = new BeEvent<() => void>();\r\n\r\n /** Called after validation completes from [[IModelDb.saveChanges]].\r\n * The argument to the event holds the list of elements that were inserted, updated, and deleted.\r\n * @note If there are many changed elements in a single Txn, the notifications are sent in batches so this event *may be called multiple times* per Txn.\r\n */\r\n public readonly onElementsChanged = new BeEvent<(changes: TxnChangedEntities) => void>();\r\n\r\n /** Called after validation completes from [[IModelDb.saveChanges]].\r\n * The argument to the event holds the list of models that were inserted, updated, and deleted.\r\n * @note If there are many changed models in a single Txn, the notifications are sent in batches so this event *may be called multiple times* per Txn.\r\n */\r\n public readonly onModelsChanged = new BeEvent<(changes: TxnChangedEntities) => void>();\r\n\r\n /** Event raised after the geometry within one or more [[GeometricModel]]s is modified by applying a changeset or validation of a transaction.\r\n * A model's geometry can change as a result of:\r\n * - Insertion or deletion of a geometric element within the model; or\r\n * - Modification of an existing element's geometric properties; or\r\n * - An explicit request to flag it as changed via [[IModelDb.Models.updateModel]].\r\n */\r\n public readonly onModelGeometryChanged = new BeEvent<(changes: ReadonlyArray<ModelIdAndGeometryGuid>) => void>();\r\n\r\n public readonly onGeometryChanged = new BeEvent<(models: ModelGeometryChangesProps[]) => void>();\r\n /** Event raised before a commit operation is performed. Initiated by a call to [[IModelDb.saveChanges]], unless there are no changes to save. */\r\n public readonly onCommit = new BeEvent<() => void>();\r\n /** Event raised after a commit operation has been performed. Initiated by a call to [[IModelDb.saveChanges]], even if there were no changes to save. */\r\n public readonly onCommitted = new BeEvent<() => void>();\r\n /** Event raised after a ChangeSet has been applied to this briefcase */\r\n public readonly onChangesApplied = new BeEvent<() => void>();\r\n /** Event raised before an undo/redo operation is performed. */\r\n public readonly onBeforeUndoRedo = new BeEvent<(isUndo: boolean) => void>();\r\n /** Event raised after an undo/redo operation has been performed.\r\n * @param _action The action that was performed.\r\n */\r\n public readonly onAfterUndoRedo = new BeEvent<(isUndo: boolean) => void>();\r\n /** Event raised for a read-only briefcase that was opened with the `watchForChanges` flag enabled when changes made by another connection are applied to the briefcase.\r\n * @see [[onReplayedExternalTxns]] for the event raised after all such changes have been applied.\r\n */\r\n public readonly onReplayExternalTxns = new BeEvent<() => void>();\r\n /** Event raised for a read-only briefcase that was opened with the `watchForChanges` flag enabled when changes made by another connection are applied to the briefcase.\r\n * @see [[onReplayExternalTxns]] for the event raised before the changes are applied.\r\n */\r\n public readonly onReplayedExternalTxns = new BeEvent<() => void>();\r\n\r\n /**\r\n * Restart the current TxnManager session. This causes all Txns in the current session to no longer be undoable (as if the file was closed\r\n * and reopened.)\r\n * @note This can be quite disconcerting to the user expecting to be able to undo previously made changes. It should only be used\r\n * under extreme circumstances where damage to the file or session could happen if the currently committed are reversed. Use sparingly and with care.\r\n * Probably a good idea to alert the user it happened.\r\n */\r\n public restartSession() {\r\n this._nativeDb.restartTxnSession();\r\n }\r\n\r\n /** Determine whether current txn is propagating indirect changes or not. */\r\n public get isIndirectChanges(): boolean { return this._nativeDb.isIndirectChanges(); }\r\n\r\n /** Determine if there are currently any reversible (undoable) changes from this editing session. */\r\n public get isUndoPossible(): boolean { return this._nativeDb.isUndoPossible(); }\r\n\r\n /** Determine if there are currently any reinstatable (redoable) changes */\r\n public get isRedoPossible(): boolean { return this._nativeDb.isRedoPossible(); }\r\n\r\n /** Get the description of the operation that would be reversed by calling reverseTxns(1).\r\n * This is useful for showing the operation that would be undone, for example in a menu.\r\n */\r\n public getUndoString(): string { return this._nativeDb.getUndoString(); }\r\n\r\n /** Get a description of the operation that would be reinstated by calling reinstateTxn.\r\n * This is useful for showing the operation that would be redone, in a pull-down menu for example.\r\n */\r\n public getRedoString(): string { return this._nativeDb.getRedoString(); }\r\n\r\n /** Begin a new multi-Txn operation. This can be used to cause a series of Txns that would normally\r\n * be considered separate actions for undo to be grouped into a single undoable operation. This means that when reverseTxns(1) is called,\r\n * the entire group of changes are undone together. Multi-Txn operations can be nested and until the outermost operation is closed\r\n * all changes constitute a single operation.\r\n * @note This method must always be paired with a call to endMultiTxnAction.\r\n */\r\n public beginMultiTxnOperation(): DbResult { return this._nativeDb.beginMultiTxnOperation(); }\r\n\r\n /** End a multi-Txn operation */\r\n public endMultiTxnOperation(): DbResult { return this._nativeDb.endMultiTxnOperation(); }\r\n\r\n /** Return the depth of the multi-Txn stack. Generally for diagnostic use only. */\r\n public getMultiTxnOperationDepth(): number { return this._nativeDb.getMultiTxnOperationDepth(); }\r\n\r\n /** Reverse (undo) the most recent operation(s) to this IModelDb.\r\n * @param numOperations the number of operations to reverse. If this is greater than 1, the entire set of operations will\r\n * be reinstated together when/if ReinstateTxn is called.\r\n * @note If there are any outstanding uncommitted changes, they are reversed.\r\n * @note The term \"operation\" is used rather than Txn, since multiple Txns can be grouped together via [[beginMultiTxnOperation]]. So,\r\n * even if numOperations is 1, multiple Txns may be reversed if they were grouped together when they were made.\r\n * @note If numOperations is too large only the operations are reversible are reversed.\r\n */\r\n public reverseTxns(numOperations: number): IModelStatus {\r\n return this._iModel.reverseTxns(numOperations);\r\n }\r\n\r\n /** Reverse the most recent operation. */\r\n public reverseSingleTxn(): IModelStatus { return this.reverseTxns(1); }\r\n\r\n /** Reverse all changes back to the beginning of the session. */\r\n public reverseAll(): IModelStatus { return this._nativeDb.reverseAll(); }\r\n\r\n /** Reverse all changes back to a previously saved TxnId.\r\n * @param txnId a TxnId obtained from a previous call to GetCurrentTxnId.\r\n * @returns Success if the transactions were reversed, error status otherwise.\r\n * @see [[getCurrentTxnId]] [[cancelTo]]\r\n */\r\n public reverseTo(txnId: TxnIdString): IModelStatus { return this._nativeDb.reverseTo(txnId); }\r\n\r\n /** Reverse and then cancel (make non-reinstatable) all changes back to a previous TxnId.\r\n * @param txnId a TxnId obtained from a previous call to [[getCurrentTxnId]]\r\n * @returns Success if the transactions were reversed and cleared, error status otherwise.\r\n */\r\n public cancelTo(txnId: TxnIdString): IModelStatus { return this._nativeDb.cancelTo(txnId); }\r\n\r\n /** Reinstate the most recently reversed transaction. Since at any time multiple transactions can be reversed, it\r\n * may take multiple calls to this method to reinstate all reversed operations.\r\n * @returns Success if a reversed transaction was reinstated, error status otherwise.\r\n * @note If there are any outstanding uncommitted changes, they are canceled before the Txn is reinstated.\r\n */\r\n public reinstateTxn(): IModelStatus { return this._iModel.reinstateTxn(); }\r\n\r\n /** Get the Id of the first transaction, if any.\r\n */\r\n public queryFirstTxnId(): TxnIdString { return this._nativeDb.queryFirstTxnId(); }\r\n\r\n /** Get the successor of the specified TxnId */\r\n public queryNextTxnId(txnId: TxnIdString): TxnIdString { return this._nativeDb.queryNextTxnId(txnId); }\r\n\r\n /** Get the predecessor of the specified TxnId */\r\n public queryPreviousTxnId(txnId: TxnIdString): TxnIdString { return this._nativeDb.queryPreviousTxnId(txnId); }\r\n\r\n /** Get the Id of the current (tip) transaction. */\r\n public getCurrentTxnId(): TxnIdString { return this._nativeDb.getCurrentTxnId(); }\r\n\r\n /** Get the description that was supplied when the specified transaction was saved. */\r\n public getTxnDescription(txnId: TxnIdString): string { return this._nativeDb.getTxnDescription(txnId); }\r\n\r\n /** Test if a TxnId is valid */\r\n public isTxnIdValid(txnId: TxnIdString): boolean { return this._nativeDb.isTxnIdValid(txnId); }\r\n\r\n /** Query if there are any pending Txns in this IModelDb that are waiting to be pushed. */\r\n public get hasPendingTxns(): boolean { return this._nativeDb.hasPendingTxns(); }\r\n\r\n /** Query if there are any changes in memory that have yet to be saved to the IModelDb. */\r\n public get hasUnsavedChanges(): boolean { return this._nativeDb.hasUnsavedChanges(); }\r\n\r\n /** Query if there are un-saved or un-pushed local changes. */\r\n public get hasLocalChanges(): boolean { return this.hasUnsavedChanges || this.hasPendingTxns; }\r\n\r\n /** Obtain a list of the EC instances that have been changed locally by the [[BriefcaseDb]] associated with this `TxnManager` and have not yet been pushed to the iModel.\r\n * @beta\r\n */\r\n public queryLocalChanges(args?: QueryLocalChangesArgs): Iterable<ChangeInstanceKey> {\r\n if (!args) {\r\n args = { includedClasses: [], includeUnsavedChanges: false };\r\n }\r\n return this._nativeDb.getLocalChanges(args.includedClasses ?? [], args.includeUnsavedChanges ?? false);\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"TxnManager.js","sourceRoot":"","sources":["../../src/TxnManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,sDAE6B;AAE7B,mEAAgE;AAEhE,uCAAoC;AA4DpC,oCAAoC;AACpC,SAAgB,sBAAsB,CAAC,GAAW;IAChD,MAAM,OAAO,GAAG,mBAAmB,CAAC,WAAW,CAAC;IAChD,mBAAmB,CAAC,WAAW,GAAG,GAAG,CAAC;IACtC,OAAO,OAAO,CAAC;AACjB,CAAC;AAJD,wDAIC;AAED,iIAAiI;AACjI,MAAM,oBAAoB;IAKxB,YAAmB,QAA8B;QAJjC,cAAS,GAAG,IAAI,+BAAgB,EAAE,CAAC;QAClC,kBAAa,GAAa,EAAE,CAAC;QAI5C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,QAAoB,EAAE,OAAmB;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,IA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CAAC,CAAC,CAAC,CAAC;IAEvG,iDAAiD;IAC1C,kBAAkB,CAAC,KAAkB,IAAiB,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/G,oDAAoD;IAC7C,eAAe,KAAkB,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;IAElF,sFAAsF;IAC/E,iBAAiB,CAAC,KAAkB,IAAY,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAExG,+BAA+B;IACxB,YAAY,CAAC,KAAkB,IAAa,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/F,2FAA2F;IAC3F,IAAW,cAAc,KAAc,OAAO,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IAEhF,0FAA0F;IAC1F,IAAW,iBAAiB,KAAc,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAEtF,8DAA8D;IAC9D,IAAW,eAAe,KAAc,OAAO,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IAE/F;;MAEE;IACK,iBAAiB,CAAC,IAA4B;QACnD,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,EAAE,eAAe,EAAE,EAAE,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC;SAC9D;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,EAAE,IAAI,CAAC,qBAAqB,IAAI,KAAK,CAAC,CAAC;IACzG,CAAC;CACF;AAxSD,gCAwSC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\nimport * as touch from \"touch\";\nimport {\n assert, BeEvent, BentleyError, compareStrings, CompressedId64Set, DbResult, Id64Array, Id64String, IModelStatus, IndexMap, Logger, OrderedId64Array,\n} from \"@itwin/core-bentley\";\nimport { ChangedEntities, EntityIdAndClassIdIterable, ModelGeometryChangesProps, ModelIdAndGeometryGuid } from \"@itwin/core-common\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { BriefcaseDb, StandaloneDb } from \"./IModelDb\";\nimport { IpcHost } from \"./IpcHost\";\nimport { Relationship, RelationshipProps } from \"./Relationship\";\nimport { SqliteStatement } from \"./SqliteStatement\";\n\n/** A string that identifies a Txn.\n * @public\n */\nexport type TxnIdString = string;\n\n/** An error generated during dependency validation.\n * @see [[TxnManager.validationErrors]].\n * @public\n */\nexport interface ValidationError {\n /** If true, txn is aborted. */\n fatal: boolean;\n /** The type of error. */\n errorType: string;\n /** Optional description of what went wrong. */\n message?: string;\n}\n\n/** Describes a set of [[Element]]s or [[Model]]s that changed as part of a transaction.\n * @see [[TxnManager.onElementsChanged]] and [[TxnManager.onModelsChanged]].\n * @public\n */\nexport interface TxnChangedEntities {\n /** The entities that were inserted by the transaction. */\n readonly inserts: EntityIdAndClassIdIterable;\n /** The entities that were deleted by the transaction. */\n readonly deletes: EntityIdAndClassIdIterable;\n /** The entities that were modified by the transaction, including any [[Element]]s for which one of their [[ElementAspect]]s was changed. */\n readonly updates: EntityIdAndClassIdIterable;\n}\n\n/** Arguments supplied to [[TxnManager.queryLocalChanges]].\n * @beta\n */\nexport interface QueryLocalChangesArgs {\n /** If supplied and non-empty, restricts the results to include only EC instances belonging to the specified classes or subclasses thereof. */\n readonly includedClasses?: string[];\n /** If `true`, include changes that have not yet been saved. */\n readonly includeUnsavedChanges?: boolean;\n}\n\n/** Represents a change (insertion, deletion, or modification) to a single EC instance made in a local [[BriefcaseDb]].\n * @see [[TxnManager.queryLocalChanges]] to iterate all of the changed instances.\n* @beta\n*/\nexport interface ChangeInstanceKey {\n /** ECInstanceId of the instance. */\n id: Id64String;\n /** Fully-qualified class name of the instance. */\n classFullName: string;\n /** The type of change. */\n changeType: \"inserted\" | \"updated\" | \"deleted\";\n}\n\ntype EntitiesChangedEvent = BeEvent<(changes: TxnChangedEntities) => void>;\n\n/** Strictly for tests. @internal */\nexport function setMaxEntitiesPerEvent(max: number): number {\n const prevMax = ChangedEntitiesProc.maxPerEvent;\n ChangedEntitiesProc.maxPerEvent = max;\n return prevMax;\n}\n\n/** Maintains an ordered array of entity Ids and a parallel array containing the index of the corresponding entity's class Id. */\nclass ChangedEntitiesArray {\n public readonly entityIds = new OrderedId64Array();\n private readonly _classIndices: number[] = [];\n private readonly _classIds: IndexMap<Id64String>;\n\n public constructor(classIds: IndexMap<Id64String>) {\n this._classIds = classIds;\n }\n\n public insert(entityId: Id64String, classId: Id64String): void {\n const entityIndex = this.entityIds.insert(entityId);\n const classIndex = this._classIds.insert(classId);\n assert(classIndex >= 0);\n if (this.entityIds.length !== this._classIndices.length) {\n // New entity - insert corresponding class index entry.\n this._classIndices.splice(entityIndex, 0, classIndex);\n } else {\n // Existing entity - update corresponding class index.\n // (We do this because apparently connectors can (very rarely) change the class Id of an existing element).\n this._classIndices[entityIndex] = classIndex;\n }\n\n assert(this.entityIds.length === this._classIndices.length);\n }\n\n public clear(): void {\n this.entityIds.clear();\n this._classIndices.length = 0;\n }\n\n public addToChangedEntities(entities: ChangedEntities, type: \"deleted\" | \"inserted\" | \"updated\"): void {\n if (this.entityIds.length > 0)\n entities[type] = CompressedId64Set.compressIds(this.entityIds);\n }\n\n public iterable(classIds: Id64Array): EntityIdAndClassIdIterable {\n function* iterator(entityIds: ReadonlyArray<Id64String>, classIndices: number[]) {\n const entity = { id: \"\", classId: \"\" };\n for (let i = 0; i < entityIds.length; i++) {\n entity.id = entityIds[i];\n entity.classId = classIds[classIndices[i]];\n yield entity;\n }\n }\n\n return {\n [Symbol.iterator]: () => iterator(this.entityIds.array, this._classIndices),\n };\n }\n}\n\nclass ChangedEntitiesProc {\n private readonly _classIds = new IndexMap<Id64String>((lhs, rhs) => compareStrings(lhs, rhs));\n private readonly _inserted = new ChangedEntitiesArray(this._classIds);\n private readonly _deleted = new ChangedEntitiesArray(this._classIds);\n private readonly _updated = new ChangedEntitiesArray(this._classIds);\n private _currSize = 0;\n\n public static maxPerEvent = 1000;\n\n public static process(iModel: BriefcaseDb | StandaloneDb, mgr: TxnManager): void {\n if (mgr.isDisposed) {\n // The iModel is being closed. Do not prepare new sqlite statements.\n return;\n }\n\n this.processChanges(iModel, mgr.onElementsChanged, \"notifyElementsChanged\");\n this.processChanges(iModel, mgr.onModelsChanged, \"notifyModelsChanged\");\n }\n\n private sendEvent(iModel: BriefcaseDb | StandaloneDb, evt: EntitiesChangedEvent, evtName: \"notifyElementsChanged\" | \"notifyModelsChanged\") {\n if (this._currSize === 0)\n return;\n\n const classIds = this._classIds.toArray();\n\n // Notify backend listeners.\n const txnEntities: TxnChangedEntities = {\n inserts: this._inserted.iterable(classIds),\n deletes: this._deleted.iterable(classIds),\n updates: this._updated.iterable(classIds),\n };\n evt.raiseEvent(txnEntities);\n\n // Notify frontend listeners.\n const entities: ChangedEntities = {};\n this._inserted.addToChangedEntities(entities, \"inserted\");\n this._deleted.addToChangedEntities(entities, \"deleted\");\n this._updated.addToChangedEntities(entities, \"updated\");\n IpcHost.notifyTxns(iModel, evtName, entities);\n\n // Reset state.\n this._inserted.clear();\n this._deleted.clear();\n this._updated.clear();\n this._classIds.clear();\n this._currSize = 0;\n }\n\n private static processChanges(iModel: BriefcaseDb | StandaloneDb, changedEvent: EntitiesChangedEvent, evtName: \"notifyElementsChanged\" | \"notifyModelsChanged\") {\n try {\n const maxSize = this.maxPerEvent;\n const changes = new ChangedEntitiesProc();\n const select = \"notifyElementsChanged\" === evtName\n ? \"SELECT ElementId, ChangeType, ECClassId FROM temp.txn_Elements\"\n : \"SELECT ModelId, ChangeType, ECClassId FROM temp.txn_Models\";\n iModel.withPreparedSqliteStatement(select, (sql: SqliteStatement) => {\n const stmt = sql.stmt;\n while (sql.step() === DbResult.BE_SQLITE_ROW) {\n const id = stmt.getValueId(0);\n const classId = stmt.getValueId(2);\n switch (stmt.getValueInteger(1)) {\n case 0:\n changes._inserted.insert(id, classId);\n break;\n case 1:\n changes._updated.insert(id, classId);\n break;\n case 2:\n changes._deleted.insert(id, classId);\n break;\n }\n\n if (++changes._currSize >= maxSize)\n changes.sendEvent(iModel, changedEvent, evtName);\n }\n });\n\n changes.sendEvent(iModel, changedEvent, evtName);\n } catch (err) {\n Logger.logError(BackendLoggerCategory.IModelDb, BentleyError.getErrorMessage(err));\n }\n }\n}\n\n/** Manages local changes to a [[BriefcaseDb]] or [[StandaloneDb]] via [Txns]($docs/learning/InteractiveEditing.md)\n * @public\n */\nexport class TxnManager {\n /** @internal */\n private _isDisposed = false;\n\n /** @internal */\n public get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /** @internal */\n constructor(private _iModel: BriefcaseDb | StandaloneDb) {\n _iModel.onBeforeClose.addOnce(() => {\n this._isDisposed = true;\n });\n }\n\n /** Array of errors from dependency propagation */\n public readonly validationErrors: ValidationError[] = [];\n\n private get _nativeDb() { return this._iModel.nativeDb; }\n private _getElementClass(elClassName: string): typeof Element {\n return this._iModel.getJsClass(elClassName) as unknown as typeof Element;\n }\n private _getRelationshipClass(relClassName: string): typeof Relationship {\n return this._iModel.getJsClass<typeof Relationship>(relClassName);\n }\n\n /** If a -watch file exists for this iModel, update its timestamp so watching processes can be\n * notified that we've modified the briefcase.\n */\n private touchWatchFile(): void {\n // This is an async call. We don't have any reason to await it.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n touch(this._iModel.watchFilePathName, { nocreate: true });\n }\n\n /** @internal */\n protected _onBeforeOutputsHandled(elClassName: string, elId: Id64String): void {\n (this._getElementClass(elClassName) as any).onBeforeOutputsHandled(elId, this._iModel);\n }\n /** @internal */\n protected _onAllInputsHandled(elClassName: string, elId: Id64String): void {\n (this._getElementClass(elClassName) as any).onAllInputsHandled(elId, this._iModel);\n }\n /** @internal */\n protected _onRootChanged(props: RelationshipProps): void {\n this._getRelationshipClass(props.classFullName).onRootChanged(props, this._iModel);\n }\n /** @internal */\n protected _onDeletedDependency(props: RelationshipProps): void {\n this._getRelationshipClass(props.classFullName).onDeletedDependency(props, this._iModel);\n }\n /** @internal */\n protected _onBeginValidate() { this.validationErrors.length = 0; }\n\n /** called from native code after validation of a Txn, either from saveChanges or apply changeset.\n * @internal\n */\n protected _onEndValidate() {\n ChangedEntitiesProc.process(this._iModel, this);\n this.onEndValidation.raiseEvent();\n // TODO: if (this.validationErrors.length !== 0) throw new IModelError(validation ...)\n }\n\n /** @internal */\n protected _onGeometryChanged(modelProps: ModelGeometryChangesProps[]) {\n this.onGeometryChanged.raiseEvent(modelProps);\n IpcHost.notifyEditingScope(this._iModel, \"notifyGeometryChanged\", modelProps); // send to frontend\n }\n\n /** @internal */\n protected _onGeometryGuidsChanged(changes: ModelIdAndGeometryGuid[]): void {\n this.onModelGeometryChanged.raiseEvent(changes);\n IpcHost.notifyTxns(this._iModel, \"notifyGeometryGuidsChanged\", changes);\n }\n\n /** @internal */\n protected _onCommit() {\n this.onCommit.raiseEvent();\n IpcHost.notifyTxns(this._iModel, \"notifyCommit\");\n }\n\n /** @internal */\n protected _onCommitted() {\n this.touchWatchFile();\n this.onCommitted.raiseEvent();\n IpcHost.notifyTxns(this._iModel, \"notifyCommitted\", this.hasPendingTxns, Date.now());\n }\n\n /** @internal */\n protected _onReplayExternalTxns() {\n this.onReplayExternalTxns.raiseEvent();\n IpcHost.notifyTxns(this._iModel, \"notifyReplayExternalTxns\");\n }\n\n /** @internal */\n protected _onReplayedExternalTxns() {\n this.onReplayedExternalTxns.raiseEvent();\n IpcHost.notifyTxns(this._iModel, \"notifyReplayedExternalTxns\");\n }\n\n /** @internal */\n protected _onChangesApplied() {\n ChangedEntitiesProc.process(this._iModel, this);\n this.onChangesApplied.raiseEvent();\n IpcHost.notifyTxns(this._iModel, \"notifyChangesApplied\");\n }\n\n /** @internal */\n protected _onBeforeUndoRedo(isUndo: boolean) {\n this.onBeforeUndoRedo.raiseEvent(isUndo);\n IpcHost.notifyTxns(this._iModel, \"notifyBeforeUndoRedo\", isUndo);\n }\n\n /** @internal */\n protected _onAfterUndoRedo(isUndo: boolean) {\n this.touchWatchFile();\n this.onAfterUndoRedo.raiseEvent(isUndo);\n IpcHost.notifyTxns(this._iModel, \"notifyAfterUndoRedo\", isUndo);\n }\n\n /** Dependency handlers may call method this to report a validation error.\n * @param error The error. If error.fatal === true, the transaction will cancel rather than commit.\n */\n public reportError(error: ValidationError) {\n this.validationErrors.push(error);\n this._nativeDb.logTxnError(error.fatal);\n }\n\n /** Determine whether any fatal validation errors have occurred during dependency propagation. */\n public get hasFatalError(): boolean { return this._nativeDb.hasFatalTxnError(); }\n\n /** @internal */\n public readonly onEndValidation = new BeEvent<() => void>();\n\n /** Called after validation completes from [[IModelDb.saveChanges]].\n * The argument to the event holds the list of elements that were inserted, updated, and deleted.\n * @note If there are many changed elements in a single Txn, the notifications are sent in batches so this event *may be called multiple times* per Txn.\n */\n public readonly onElementsChanged = new BeEvent<(changes: TxnChangedEntities) => void>();\n\n /** Called after validation completes from [[IModelDb.saveChanges]].\n * The argument to the event holds the list of models that were inserted, updated, and deleted.\n * @note If there are many changed models in a single Txn, the notifications are sent in batches so this event *may be called multiple times* per Txn.\n */\n public readonly onModelsChanged = new BeEvent<(changes: TxnChangedEntities) => void>();\n\n /** Event raised after the geometry within one or more [[GeometricModel]]s is modified by applying a changeset or validation of a transaction.\n * A model's geometry can change as a result of:\n * - Insertion or deletion of a geometric element within the model; or\n * - Modification of an existing element's geometric properties; or\n * - An explicit request to flag it as changed via [[IModelDb.Models.updateModel]].\n */\n public readonly onModelGeometryChanged = new BeEvent<(changes: ReadonlyArray<ModelIdAndGeometryGuid>) => void>();\n\n public readonly onGeometryChanged = new BeEvent<(models: ModelGeometryChangesProps[]) => void>();\n /** Event raised before a commit operation is performed. Initiated by a call to [[IModelDb.saveChanges]], unless there are no changes to save. */\n public readonly onCommit = new BeEvent<() => void>();\n /** Event raised after a commit operation has been performed. Initiated by a call to [[IModelDb.saveChanges]], even if there were no changes to save. */\n public readonly onCommitted = new BeEvent<() => void>();\n /** Event raised after a ChangeSet has been applied to this briefcase */\n public readonly onChangesApplied = new BeEvent<() => void>();\n /** Event raised before an undo/redo operation is performed. */\n public readonly onBeforeUndoRedo = new BeEvent<(isUndo: boolean) => void>();\n /** Event raised after an undo/redo operation has been performed.\n * @param _action The action that was performed.\n */\n public readonly onAfterUndoRedo = new BeEvent<(isUndo: boolean) => void>();\n /** Event raised for a read-only briefcase that was opened with the `watchForChanges` flag enabled when changes made by another connection are applied to the briefcase.\n * @see [[onReplayedExternalTxns]] for the event raised after all such changes have been applied.\n */\n public readonly onReplayExternalTxns = new BeEvent<() => void>();\n /** Event raised for a read-only briefcase that was opened with the `watchForChanges` flag enabled when changes made by another connection are applied to the briefcase.\n * @see [[onReplayExternalTxns]] for the event raised before the changes are applied.\n */\n public readonly onReplayedExternalTxns = new BeEvent<() => void>();\n\n /**\n * Restart the current TxnManager session. This causes all Txns in the current session to no longer be undoable (as if the file was closed\n * and reopened.)\n * @note This can be quite disconcerting to the user expecting to be able to undo previously made changes. It should only be used\n * under extreme circumstances where damage to the file or session could happen if the currently committed are reversed. Use sparingly and with care.\n * Probably a good idea to alert the user it happened.\n */\n public restartSession() {\n this._nativeDb.restartTxnSession();\n }\n\n /** Determine whether current txn is propagating indirect changes or not. */\n public get isIndirectChanges(): boolean { return this._nativeDb.isIndirectChanges(); }\n\n /** Determine if there are currently any reversible (undoable) changes from this editing session. */\n public get isUndoPossible(): boolean { return this._nativeDb.isUndoPossible(); }\n\n /** Determine if there are currently any reinstatable (redoable) changes */\n public get isRedoPossible(): boolean { return this._nativeDb.isRedoPossible(); }\n\n /** Get the description of the operation that would be reversed by calling reverseTxns(1).\n * This is useful for showing the operation that would be undone, for example in a menu.\n */\n public getUndoString(): string { return this._nativeDb.getUndoString(); }\n\n /** Get a description of the operation that would be reinstated by calling reinstateTxn.\n * This is useful for showing the operation that would be redone, in a pull-down menu for example.\n */\n public getRedoString(): string { return this._nativeDb.getRedoString(); }\n\n /** Begin a new multi-Txn operation. This can be used to cause a series of Txns that would normally\n * be considered separate actions for undo to be grouped into a single undoable operation. This means that when reverseTxns(1) is called,\n * the entire group of changes are undone together. Multi-Txn operations can be nested and until the outermost operation is closed\n * all changes constitute a single operation.\n * @note This method must always be paired with a call to endMultiTxnAction.\n */\n public beginMultiTxnOperation(): DbResult { return this._nativeDb.beginMultiTxnOperation(); }\n\n /** End a multi-Txn operation */\n public endMultiTxnOperation(): DbResult { return this._nativeDb.endMultiTxnOperation(); }\n\n /** Return the depth of the multi-Txn stack. Generally for diagnostic use only. */\n public getMultiTxnOperationDepth(): number { return this._nativeDb.getMultiTxnOperationDepth(); }\n\n /** Reverse (undo) the most recent operation(s) to this IModelDb.\n * @param numOperations the number of operations to reverse. If this is greater than 1, the entire set of operations will\n * be reinstated together when/if ReinstateTxn is called.\n * @note If there are any outstanding uncommitted changes, they are reversed.\n * @note The term \"operation\" is used rather than Txn, since multiple Txns can be grouped together via [[beginMultiTxnOperation]]. So,\n * even if numOperations is 1, multiple Txns may be reversed if they were grouped together when they were made.\n * @note If numOperations is too large only the operations are reversible are reversed.\n */\n public reverseTxns(numOperations: number): IModelStatus {\n return this._iModel.reverseTxns(numOperations);\n }\n\n /** Reverse the most recent operation. */\n public reverseSingleTxn(): IModelStatus { return this.reverseTxns(1); }\n\n /** Reverse all changes back to the beginning of the session. */\n public reverseAll(): IModelStatus { return this._nativeDb.reverseAll(); }\n\n /** Reverse all changes back to a previously saved TxnId.\n * @param txnId a TxnId obtained from a previous call to GetCurrentTxnId.\n * @returns Success if the transactions were reversed, error status otherwise.\n * @see [[getCurrentTxnId]] [[cancelTo]]\n */\n public reverseTo(txnId: TxnIdString): IModelStatus { return this._nativeDb.reverseTo(txnId); }\n\n /** Reverse and then cancel (make non-reinstatable) all changes back to a previous TxnId.\n * @param txnId a TxnId obtained from a previous call to [[getCurrentTxnId]]\n * @returns Success if the transactions were reversed and cleared, error status otherwise.\n */\n public cancelTo(txnId: TxnIdString): IModelStatus { return this._nativeDb.cancelTo(txnId); }\n\n /** Reinstate the most recently reversed transaction. Since at any time multiple transactions can be reversed, it\n * may take multiple calls to this method to reinstate all reversed operations.\n * @returns Success if a reversed transaction was reinstated, error status otherwise.\n * @note If there are any outstanding uncommitted changes, they are canceled before the Txn is reinstated.\n */\n public reinstateTxn(): IModelStatus { return this._iModel.reinstateTxn(); }\n\n /** Get the Id of the first transaction, if any.\n */\n public queryFirstTxnId(): TxnIdString { return this._nativeDb.queryFirstTxnId(); }\n\n /** Get the successor of the specified TxnId */\n public queryNextTxnId(txnId: TxnIdString): TxnIdString { return this._nativeDb.queryNextTxnId(txnId); }\n\n /** Get the predecessor of the specified TxnId */\n public queryPreviousTxnId(txnId: TxnIdString): TxnIdString { return this._nativeDb.queryPreviousTxnId(txnId); }\n\n /** Get the Id of the current (tip) transaction. */\n public getCurrentTxnId(): TxnIdString { return this._nativeDb.getCurrentTxnId(); }\n\n /** Get the description that was supplied when the specified transaction was saved. */\n public getTxnDescription(txnId: TxnIdString): string { return this._nativeDb.getTxnDescription(txnId); }\n\n /** Test if a TxnId is valid */\n public isTxnIdValid(txnId: TxnIdString): boolean { return this._nativeDb.isTxnIdValid(txnId); }\n\n /** Query if there are any pending Txns in this IModelDb that are waiting to be pushed. */\n public get hasPendingTxns(): boolean { return this._nativeDb.hasPendingTxns(); }\n\n /** Query if there are any changes in memory that have yet to be saved to the IModelDb. */\n public get hasUnsavedChanges(): boolean { return this._nativeDb.hasUnsavedChanges(); }\n\n /** Query if there are un-saved or un-pushed local changes. */\n public get hasLocalChanges(): boolean { return this.hasUnsavedChanges || this.hasPendingTxns; }\n\n /** Obtain a list of the EC instances that have been changed locally by the [[BriefcaseDb]] associated with this `TxnManager` and have not yet been pushed to the iModel.\n * @beta\n */\n public queryLocalChanges(args?: QueryLocalChangesArgs): Iterable<ChangeInstanceKey> {\n if (!args) {\n args = { includedClasses: [], includeUnsavedChanges: false };\n }\n return this._nativeDb.getLocalChanges(args.includedClasses ?? [], args.includeUnsavedChanges ?? false);\n }\n}\n\n"]}