@itwin/core-backend 4.1.0-dev.8 → 4.1.0-dev.81

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 (134) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/lib/cjs/BackendHubAccess.js.map +1 -1
  3. package/lib/cjs/BlobContainerService.d.ts +38 -28
  4. package/lib/cjs/BlobContainerService.d.ts.map +1 -1
  5. package/lib/cjs/BlobContainerService.js.map +1 -1
  6. package/lib/cjs/BriefcaseManager.d.ts +8 -5
  7. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  8. package/lib/cjs/BriefcaseManager.js +9 -16
  9. package/lib/cjs/BriefcaseManager.js.map +1 -1
  10. package/lib/cjs/Category.d.ts +4 -16
  11. package/lib/cjs/Category.d.ts.map +1 -1
  12. package/lib/cjs/Category.js +0 -12
  13. package/lib/cjs/Category.js.map +1 -1
  14. package/lib/cjs/ChannelControl.d.ts +5 -1
  15. package/lib/cjs/ChannelControl.d.ts.map +1 -1
  16. package/lib/cjs/ChannelControl.js +10 -5
  17. package/lib/cjs/ChannelControl.js.map +1 -1
  18. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  19. package/lib/cjs/CheckpointManager.js +20 -9
  20. package/lib/cjs/CheckpointManager.js.map +1 -1
  21. package/lib/cjs/ClassRegistry.d.ts +2 -1
  22. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  23. package/lib/cjs/ClassRegistry.js +2 -1
  24. package/lib/cjs/ClassRegistry.js.map +1 -1
  25. package/lib/cjs/CloudSqlite.d.ts +57 -40
  26. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  27. package/lib/cjs/CloudSqlite.js +54 -39
  28. package/lib/cjs/CloudSqlite.js.map +1 -1
  29. package/lib/cjs/DisplayStyle.d.ts +2 -5
  30. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  31. package/lib/cjs/DisplayStyle.js +0 -3
  32. package/lib/cjs/DisplayStyle.js.map +1 -1
  33. package/lib/cjs/ECDb.d.ts +6 -0
  34. package/lib/cjs/ECDb.d.ts.map +1 -1
  35. package/lib/cjs/ECDb.js +6 -0
  36. package/lib/cjs/ECDb.js.map +1 -1
  37. package/lib/cjs/ECSchemaXmlContext.d.ts +28 -1
  38. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  39. package/lib/cjs/ECSchemaXmlContext.js +28 -1
  40. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  41. package/lib/cjs/Element.d.ts +40 -97
  42. package/lib/cjs/Element.d.ts.map +1 -1
  43. package/lib/cjs/Element.js +0 -57
  44. package/lib/cjs/Element.js.map +1 -1
  45. package/lib/cjs/ElementAspect.d.ts +2 -4
  46. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  47. package/lib/cjs/ElementAspect.js +2 -4
  48. package/lib/cjs/ElementAspect.js.map +1 -1
  49. package/lib/cjs/Entity.d.ts +5 -2
  50. package/lib/cjs/Entity.d.ts.map +1 -1
  51. package/lib/cjs/Entity.js +10 -2
  52. package/lib/cjs/Entity.js.map +1 -1
  53. package/lib/cjs/ExternalSource.d.ts +4 -11
  54. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  55. package/lib/cjs/ExternalSource.js +0 -7
  56. package/lib/cjs/ExternalSource.js.map +1 -1
  57. package/lib/cjs/IModelDb.d.ts +61 -26
  58. package/lib/cjs/IModelDb.d.ts.map +1 -1
  59. package/lib/cjs/IModelDb.js +164 -83
  60. package/lib/cjs/IModelDb.js.map +1 -1
  61. package/lib/cjs/IModelHost.d.ts +1 -3
  62. package/lib/cjs/IModelHost.d.ts.map +1 -1
  63. package/lib/cjs/IModelHost.js +3 -5
  64. package/lib/cjs/IModelHost.js.map +1 -1
  65. package/lib/cjs/Material.d.ts +0 -1
  66. package/lib/cjs/Material.d.ts.map +1 -1
  67. package/lib/cjs/Material.js +1 -2
  68. package/lib/cjs/Material.js.map +1 -1
  69. package/lib/cjs/Model.d.ts +4 -13
  70. package/lib/cjs/Model.d.ts.map +1 -1
  71. package/lib/cjs/Model.js +0 -9
  72. package/lib/cjs/Model.js.map +1 -1
  73. package/lib/cjs/PropertyStore.d.ts +3 -3
  74. package/lib/cjs/PropertyStore.d.ts.map +1 -1
  75. package/lib/cjs/PropertyStore.js +2 -5
  76. package/lib/cjs/PropertyStore.js.map +1 -1
  77. package/lib/cjs/Relationship.d.ts +2 -5
  78. package/lib/cjs/Relationship.d.ts.map +1 -1
  79. package/lib/cjs/Relationship.js +0 -3
  80. package/lib/cjs/Relationship.js.map +1 -1
  81. package/lib/cjs/SQLiteDb.d.ts +1 -1
  82. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  83. package/lib/cjs/SQLiteDb.js +1 -1
  84. package/lib/cjs/SQLiteDb.js.map +1 -1
  85. package/lib/cjs/Schema.d.ts +0 -1
  86. package/lib/cjs/Schema.d.ts.map +1 -1
  87. package/lib/cjs/Schema.js +0 -1
  88. package/lib/cjs/Schema.js.map +1 -1
  89. package/lib/cjs/SchemaUtils.d.ts +19 -0
  90. package/lib/cjs/SchemaUtils.d.ts.map +1 -0
  91. package/lib/cjs/SchemaUtils.js +42 -0
  92. package/lib/cjs/SchemaUtils.js.map +1 -0
  93. package/lib/cjs/SqliteStatement.d.ts +13 -1
  94. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  95. package/lib/cjs/SqliteStatement.js +23 -1
  96. package/lib/cjs/SqliteStatement.js.map +1 -1
  97. package/lib/cjs/Texture.d.ts +3 -4
  98. package/lib/cjs/Texture.d.ts.map +1 -1
  99. package/lib/cjs/Texture.js +1 -2
  100. package/lib/cjs/Texture.js.map +1 -1
  101. package/lib/cjs/TileStorage.d.ts +3 -0
  102. package/lib/cjs/TileStorage.d.ts.map +1 -1
  103. package/lib/cjs/TileStorage.js +9 -1
  104. package/lib/cjs/TileStorage.js.map +1 -1
  105. package/lib/cjs/ViewDefinition.d.ts +7 -28
  106. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  107. package/lib/cjs/ViewDefinition.js +0 -21
  108. package/lib/cjs/ViewDefinition.js.map +1 -1
  109. package/lib/cjs/ViewStore.d.ts +488 -0
  110. package/lib/cjs/ViewStore.d.ts.map +1 -0
  111. package/lib/cjs/ViewStore.js +1246 -0
  112. package/lib/cjs/ViewStore.js.map +1 -0
  113. package/lib/cjs/core-backend.d.ts +2 -0
  114. package/lib/cjs/core-backend.d.ts.map +1 -1
  115. package/lib/cjs/core-backend.js +2 -0
  116. package/lib/cjs/core-backend.js.map +1 -1
  117. package/lib/cjs/domains/FunctionalElements.d.ts +6 -12
  118. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
  119. package/lib/cjs/domains/FunctionalElements.js +0 -6
  120. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  121. package/lib/cjs/rpc/tracing.js +2 -2
  122. package/lib/cjs/rpc/tracing.js.map +1 -1
  123. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +5 -3
  124. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  125. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +53 -36
  126. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  127. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  128. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +0 -2
  129. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  130. package/lib/cjs/workspace/Workspace.d.ts +1 -1
  131. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  132. package/lib/cjs/workspace/Workspace.js +4 -4
  133. package/lib/cjs/workspace/Workspace.js.map +1 -1
  134. package/package.json +21 -40
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AACzB,+BAA+B;AAC/B,iCAAiC;AAEjC,sDAA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EAjIgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAiIxB","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 SQLiteDb\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport { dirname } from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n// cspell:ignore savepoint julianday rowid\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/**\r\n * A \"generic\" SQLiteDb. This class may be used to access local files or databases in a cloud container.\r\n * @public\r\n */\r\nexport class SQLiteDb {\r\n /** @internal */\r\n public readonly nativeDb = new IModelHost.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelHost.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb.\r\n * @deprecated in 4.0, use [[closeDb]]\r\n */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string): void;\r\n /** @beta */\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this.nativeDb.createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @beta\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\r\n this.nativeDb.openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n }\r\n\r\n /** Returns true if this SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /** Returns true if this SQLiteDb is open readonly */\r\n public get isReadonly(): boolean { return this.nativeDb.isReadonly(); }\r\n\r\n /** Create a new table in this database. */\r\n protected createTable(args: {\r\n /** The name of the table to create. */\r\n tableName: string;\r\n /** all of the columns in the table. */\r\n columns: string;\r\n /** any unique or foreign key constraints */\r\n constraints?: string;\r\n /** if true, add a \"lastMod\" timestamp column and triggers to automatically update it. */\r\n addTimestamp?: boolean;\r\n }) {\r\n const timestampCol = args.addTimestamp ? \",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))\" : \"\";\r\n const constraints = args.constraints ? `,${args.constraints}` : \"\";\r\n this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);\r\n if (args.addTimestamp)\r\n this.executeSQL(`CREATE TRIGGER ${args.tableName}_timestamp AFTER UPDATE ON ${args.tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${args.tableName} SET lastMod=julianday('now') WHERE rowid=new.rowid; END`);\r\n }\r\n\r\n /**\r\n * Get the last modified date for a row in a table of this database.\r\n * @note the table must have been created with `addTimestamp: true`\r\n */\r\n public readLastModTime(tableName: string, rowId: number): Date {\r\n return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {\r\n stmt.bindInteger(1, rowId);\r\n return stmt.getValueDate(0);\r\n });\r\n }\r\n\r\n /**\r\n * Open a database, perform an operation, then close the database.\r\n *\r\n * Details:\r\n * - if database is open, throw an error\r\n * - open a database\r\n * - call a function with the database opened. If it is async, await its return.\r\n * - if function throws, abandon all changes, close database, and rethrow\r\n * - save all changes\r\n * - close the database\r\n * @return value from operation\r\n */\r\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\r\n if (this.isOpen)\r\n throw new Error(\"database is already open\");\r\n\r\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\r\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n try {\r\n const result = operation();\r\n result instanceof Promise ? result.then(save, abandon) : save();\r\n return result;\r\n } catch (e) {\r\n abandon();\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on a database in a CloudContainer with the write lock held.\r\n *\r\n * Details:\r\n * - acquire the write lock on a CloudContainer\r\n * - call `withOpenDb` with openMode `ReadWrite`\r\n * - upload changes\r\n * - release the write lock\r\n * @param args arguments to lock the container and open the database\r\n * @param operation an operation performed on the database with the write lock held.\r\n * @return value from operation\r\n * @internal\r\n */\r\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => Promise<T>) {\r\n return CloudSqlite.withWriteLock(args.moniker, args.container, async () => this.withOpenDb({ ...args, openMode: OpenMode.ReadWrite }, operation), args.busyHandler);\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\r\n this.nativeDb.vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */\r\n public saveChanges(): void {\r\n this.nativeDb.saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */\r\n public abandonChanges(): void {\r\n this.nativeDb.abandonChanges();\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n const release = () => stmt.dispose();\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\r\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\r\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\r\n */\r\n public withSavePoint(savePointName: string, operation: () => void) {\r\n if (this.isReadonly)\r\n throw new Error(\"database is readonly\");\r\n\r\n this.executeSQL(`SAVEPOINT ${savePointName}`);\r\n try {\r\n operation();\r\n this.executeSQL(`RELEASE ${savePointName}`);\r\n } catch (e) {\r\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\r\n throw e;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this.nativeDb, logErrors);\r\n return stmt;\r\n }\r\n\r\n /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.\r\n * This class provides version checking when the database is opened, to guarantee that a valid version of software is\r\n * always used for access.\r\n *\r\n * Notes:\r\n * - This class may be used either to access a local file, or one stored in a cloud container.\r\n * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its\r\n * tables.\r\n * @beta\r\n */\r\nexport abstract class VersionedSqliteDb extends SQLiteDb {\r\n protected static _versionProps = { namespace: \"SQLiteDb\", name: \"versions\" } as const;\r\n\r\n /** The current semver \"persistence version\" of this class.\r\n * @note This value should only be changed when logic in its code is modified in a way that affects the operation of extant copies.\r\n * If this value is outside of the range of accepted versions of a to-be-opened VersionedSqliteDb, the operation will fail. In this manner, if\r\n * changes are made to the format of a VersionedSqliteDb, or if bug fixes are necessary, the `requiredVersions` property in a VersionedSqliteDb may be updated\r\n * and immediately old versions of the package will refuse to open the VersionedSqliteDb, with a message to the user that they need to upgrade their\r\n * software. Likewise, if a new version of the package is asked to open an older VersionedSqliteDb that has not been upgraded to the lowest version\r\n * supported by it, the user will be informed that they need to upgrade their software.\r\n * @note this identifier is independent of versions in `package.json` files.\r\n */\r\n public abstract myVersion: string;\r\n\r\n /**\r\n * Change the \"versions required to open this database\" property stored in this database. After this call,\r\n * versions of software that don't meet the supplied ranges will fail.\r\n * @param versions the new versions required for reading and writing this database.\r\n * @note the database must be opened for write access.\r\n */\r\n public setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges) {\r\n // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.\r\n this.nativeDb.saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));\r\n }\r\n\r\n /** Get the required version ranges necessary to open this VersionedSqliteDb. */\r\n public getRequiredVersions() {\r\n const checkIsString = (value: any) => {\r\n if (typeof value !== \"string\")\r\n throw new Error(`CloudDb ${this.nativeDb.getFilePath()} has invalid \"versions\" property`);\r\n return value;\r\n };\r\n const versionJson = checkIsString(this.nativeDb.queryFileProperty(VersionedSqliteDb._versionProps, true));\r\n const versionRanges = JSON.parse(versionJson) as SQLiteDb.RequiredVersionRanges;\r\n checkIsString(versionRanges.readVersion);\r\n checkIsString(versionRanges.writeVersion);\r\n return versionRanges;\r\n }\r\n\r\n /**\r\n * Implement this method to create all tables for this subclass of `VersionedSqliteDb` when a new database file is created. Called from [[createNewDb]].\r\n */\r\n protected abstract createDDL(): void;\r\n\r\n /**\r\n * Create a new database file for the subclass of VersionedSqliteDb.\r\n * @param fileName the name of a local\r\n * @note The required versions are saved as [[myVersion]] or newer for both read and write.\r\n */\r\n public static createNewDb(fileName: LocalFileName) {\r\n const db = new (this as any)() as VersionedSqliteDb; // \"as any\" necessary because VersionedSqliteDb is abstract\r\n IModelJsFs.recursiveMkDirSync(dirname(fileName));\r\n if (fs.existsSync(fileName))\r\n fs.unlinkSync(fileName);\r\n\r\n db.createDb(fileName);\r\n db.createDDL();\r\n const minVer = `^${db.myVersion}`;\r\n db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });\r\n db.closeDb(true);\r\n }\r\n\r\n /**\r\n * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n */\r\n protected verifyVersions() {\r\n const versions = this.getRequiredVersions();\r\n const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.\r\n const range = isReadonly ? versions.readVersion : versions.writeVersion;\r\n if (semver.satisfies(this.myVersion, range))\r\n return;\r\n\r\n this.closeDb();\r\n const tooNew = semver.gtr(this.myVersion, range);\r\n throw new Error(`${this.nativeDb.getFilePath()} requires ${tooNew ? \"older\" : \"newer\"} version of ${this.constructor.name} for ${isReadonly ? \"read\" : \"write\"}`);\r\n\r\n }\r\n\r\n /**\r\n * Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n * @see [[SqliteDb.openDb]] for argument types\r\n */\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this.verifyVersions();\r\n }\r\n\r\n public async upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, moniker: string }, upgradeFn: () => void }) {\r\n // can't use \"this\" because it checks for version, which we don't want here\r\n return (arg.lockContainer) ?\r\n super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :\r\n super.withOpenDb({ ...arg, openMode: OpenMode.ReadWrite }, arg.upgradeFn);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A semver version range.\r\n * @see https://docs.npmjs.com/cli/v6/using-npm/semver\r\n */\r\n export type VersionRange = string;\r\n\r\n /**\r\n * A pair of semver [[SQLiteDb.VersionRange]]s, one for read and one for write, required to access a [[VersionedSqliteDb]].\r\n * If the version of the software attempting to read or write the database does not satisfy the range, access is denied.\r\n */\r\n export interface RequiredVersionRanges {\r\n /** a range of acceptable persistence versions for reading from a VersionedSqliteDb. */\r\n readonly readVersion: VersionRange;\r\n /** a range of acceptable persistence versions for writing to a VersionedSqliteDb. */\r\n readonly writeVersion: VersionRange;\r\n }\r\n\r\n /** interface for reading and writing to a blob in a SQLiteDb\r\n * @internal\r\n */\r\n export interface BlobIO {\r\n /** Close this BlobIO if it is opened.\r\n * @note this BlobIO *may* be reused after this call by calling `open` again.\r\n */\r\n close(): void;\r\n /** get the total number of bytes in the blob */\r\n getNumBytes(): number;\r\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\r\n isValid(): boolean;\r\n /** Open this BlobIO against a table/row/column in a Db */\r\n open(\r\n /** The database for the blob */\r\n db: IModelJsNative.AnyDb,\r\n args: {\r\n /** the name of the table for the blob*/\r\n tableName: string;\r\n /** the name of the column for the blob */\r\n columnName: string;\r\n /** The rowId of the blob */\r\n row: number;\r\n /** If true, open this BlobIO for write access */\r\n writeable?: boolean;\r\n }): void;\r\n /** Read from a blob\r\n * @returns the contents of the requested byte range\r\n */\r\n read(args: {\r\n /** The number of bytes to read */\r\n numBytes: number;\r\n /** starting offset within the blob to read */\r\n offset: number;\r\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\r\n blob?: ArrayBuffer;\r\n }): Uint8Array;\r\n /** Reposition this BlobIO to a new rowId\r\n * @note this BlobIO must be valid when this methods is called.\r\n */\r\n changeRow(row: number): void;\r\n /** Write to a blob */\r\n write(args: {\r\n /** The number of bytes to write */\r\n numBytes: number;\r\n /** starting offset within the blob to write */\r\n offset: number;\r\n /** the value to write */\r\n blob: ArrayBuffer;\r\n }): void;\r\n }\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Size of a SQLiteDb page in bytes */\r\n export interface PageSize {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export type CreateParams = OpenOrCreateParams & PageSize;\r\n\r\n /** Arguments for `SqliteDb.withOpenDb` */\r\n export interface WithOpenDbArgs {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: CloudSqlite.CloudContainer;\r\n }\r\n\r\n /** Arguments for `SQLiteDb.vacuum` */\r\n export interface VacuumDbArgs extends PageSize {\r\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\r\n into?: LocalFileName;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SQLiteDb.js","source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a,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AAgDH,CAAC,EAjIgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAiIxB","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 SQLiteDb\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport { dirname } from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n// cspell:ignore savepoint julianday rowid\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/**\r\n * A \"generic\" SQLiteDb. This class may be used to access local files or databases in a cloud container.\r\n * @public\r\n */\r\nexport class SQLiteDb {\r\n /** @internal */\r\n public readonly nativeDb = new IModelHost.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelHost.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb.\r\n * @deprecated in 4.0, use [[closeDb]]\r\n */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string): void;\r\n /** @beta */\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this.nativeDb.createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @beta\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\r\n this.nativeDb.openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n }\r\n\r\n /** Returns true if this SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /** Returns true if this SQLiteDb is open readonly */\r\n public get isReadonly(): boolean { return this.nativeDb.isReadonly(); }\r\n\r\n /** Create a new table in this database. */\r\n protected createTable(args: {\r\n /** The name of the table to create. */\r\n tableName: string;\r\n /** all of the columns in the table. */\r\n columns: string;\r\n /** any unique or foreign key constraints */\r\n constraints?: string;\r\n /** if true, add a \"lastMod\" timestamp column and triggers to automatically update it. */\r\n addTimestamp?: boolean;\r\n }) {\r\n const timestampCol = args.addTimestamp ? \",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))\" : \"\";\r\n const constraints = args.constraints ? `,${args.constraints}` : \"\";\r\n this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);\r\n if (args.addTimestamp)\r\n this.executeSQL(`CREATE TRIGGER ${args.tableName}_timestamp AFTER UPDATE ON ${args.tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${args.tableName} SET lastMod=julianday('now') WHERE rowid=new.rowid; END`);\r\n }\r\n\r\n /**\r\n * Get the last modified date for a row in a table of this database.\r\n * @note the table must have been created with `addTimestamp: true`\r\n */\r\n public readLastModTime(tableName: string, rowId: number): Date {\r\n return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {\r\n stmt.bindInteger(1, rowId);\r\n return stmt.getValueDate(0);\r\n });\r\n }\r\n\r\n /**\r\n * Open a database, perform an operation, then close the database.\r\n *\r\n * Details:\r\n * - if database is open, throw an error\r\n * - open a database\r\n * - call a function with the database opened. If it is async, await its return.\r\n * - if function throws, abandon all changes, close database, and rethrow\r\n * - save all changes\r\n * - close the database\r\n * @return value from operation\r\n */\r\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\r\n if (this.isOpen)\r\n throw new Error(\"database is already open\");\r\n\r\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\r\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n try {\r\n const result = operation();\r\n result instanceof Promise ? result.then(save, abandon) : save();\r\n return result;\r\n } catch (e) {\r\n abandon();\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on a database in a CloudContainer with the write lock held.\r\n *\r\n * Details:\r\n * - acquire the write lock on a CloudContainer\r\n * - call `withOpenDb` with openMode `ReadWrite`\r\n * - upload changes\r\n * - release the write lock\r\n * @param args arguments to lock the container and open the database\r\n * @param operation an operation performed on the database with the write lock held.\r\n * @return value from operation\r\n * @internal\r\n */\r\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => Promise<T>) {\r\n return CloudSqlite.withWriteLock(args, async () => this.withOpenDb({ openMode: OpenMode.ReadWrite, ...args }, operation));\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\r\n this.nativeDb.vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */\r\n public saveChanges(): void {\r\n this.nativeDb.saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */\r\n public abandonChanges(): void {\r\n this.nativeDb.abandonChanges();\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n const release = () => stmt.dispose();\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\r\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\r\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\r\n */\r\n public withSavePoint(savePointName: string, operation: () => void) {\r\n if (this.isReadonly)\r\n throw new Error(\"database is readonly\");\r\n\r\n this.executeSQL(`SAVEPOINT ${savePointName}`);\r\n try {\r\n operation();\r\n this.executeSQL(`RELEASE ${savePointName}`);\r\n } catch (e) {\r\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\r\n throw e;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this.nativeDb, logErrors);\r\n return stmt;\r\n }\r\n\r\n /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.\r\n * This class provides version checking when the database is opened, to guarantee that a valid version of software is\r\n * always used for access.\r\n *\r\n * Notes:\r\n * - This class may be used either to access a local file, or one stored in a cloud container.\r\n * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its\r\n * tables.\r\n * @beta\r\n */\r\nexport abstract class VersionedSqliteDb extends SQLiteDb {\r\n protected static _versionProps = { namespace: \"SQLiteDb\", name: \"versions\" } as const;\r\n\r\n /** The current semver \"persistence version\" of this class.\r\n * @note This value should only be changed when logic in its code is modified in a way that affects the operation of extant copies.\r\n * If this value is outside of the range of accepted versions of a to-be-opened VersionedSqliteDb, the operation will fail. In this manner, if\r\n * changes are made to the format of a VersionedSqliteDb, or if bug fixes are necessary, the `requiredVersions` property in a VersionedSqliteDb may be updated\r\n * and immediately old versions of the package will refuse to open the VersionedSqliteDb, with a message to the user that they need to upgrade their\r\n * software. Likewise, if a new version of the package is asked to open an older VersionedSqliteDb that has not been upgraded to the lowest version\r\n * supported by it, the user will be informed that they need to upgrade their software.\r\n * @note this identifier is independent of versions in `package.json` files.\r\n */\r\n public abstract myVersion: string;\r\n\r\n /**\r\n * Change the \"versions required to open this database\" property stored in this database. After this call,\r\n * versions of software that don't meet the supplied ranges will fail.\r\n * @param versions the new versions required for reading and writing this database.\r\n * @note the database must be opened for write access.\r\n */\r\n public setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges) {\r\n // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.\r\n this.nativeDb.saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));\r\n }\r\n\r\n /** Get the required version ranges necessary to open this VersionedSqliteDb. */\r\n public getRequiredVersions() {\r\n const checkIsString = (value: any) => {\r\n if (typeof value !== \"string\")\r\n throw new Error(`CloudDb ${this.nativeDb.getFilePath()} has invalid \"versions\" property`);\r\n return value;\r\n };\r\n const versionJson = checkIsString(this.nativeDb.queryFileProperty(VersionedSqliteDb._versionProps, true));\r\n const versionRanges = JSON.parse(versionJson) as SQLiteDb.RequiredVersionRanges;\r\n checkIsString(versionRanges.readVersion);\r\n checkIsString(versionRanges.writeVersion);\r\n return versionRanges;\r\n }\r\n\r\n /**\r\n * Implement this method to create all tables for this subclass of `VersionedSqliteDb` when a new database file is created. Called from [[createNewDb]].\r\n */\r\n protected abstract createDDL(): void;\r\n\r\n /**\r\n * Create a new database file for the subclass of VersionedSqliteDb.\r\n * @param fileName the name of a local\r\n * @note The required versions are saved as [[myVersion]] or newer for both read and write.\r\n */\r\n public static createNewDb(fileName: LocalFileName) {\r\n const db = new (this as any)() as VersionedSqliteDb; // \"as any\" necessary because VersionedSqliteDb is abstract\r\n IModelJsFs.recursiveMkDirSync(dirname(fileName));\r\n if (fs.existsSync(fileName))\r\n fs.unlinkSync(fileName);\r\n\r\n db.createDb(fileName);\r\n db.createDDL();\r\n const minVer = `^${db.myVersion}`;\r\n db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });\r\n db.closeDb(true);\r\n }\r\n\r\n /**\r\n * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n */\r\n protected verifyVersions() {\r\n const versions = this.getRequiredVersions();\r\n const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.\r\n const range = isReadonly ? versions.readVersion : versions.writeVersion;\r\n if (semver.satisfies(this.myVersion, range))\r\n return;\r\n\r\n this.closeDb();\r\n const tooNew = semver.gtr(this.myVersion, range);\r\n throw new Error(`${this.nativeDb.getFilePath()} requires ${tooNew ? \"older\" : \"newer\"} version of ${this.constructor.name} for ${isReadonly ? \"read\" : \"write\"}`);\r\n\r\n }\r\n\r\n /**\r\n * Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n * @see [[SqliteDb.openDb]] for argument types\r\n */\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this.verifyVersions();\r\n }\r\n\r\n public async upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, user: string }, upgradeFn: () => void }) {\r\n // can't use \"this\" because it checks for version, which we don't want here\r\n return (arg.lockContainer) ?\r\n super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :\r\n super.withOpenDb({ ...arg, openMode: OpenMode.ReadWrite }, arg.upgradeFn);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A semver version range.\r\n * @see https://docs.npmjs.com/cli/v6/using-npm/semver\r\n */\r\n export type VersionRange = string;\r\n\r\n /**\r\n * A pair of semver [[SQLiteDb.VersionRange]]s, one for read and one for write, required to access a [[VersionedSqliteDb]].\r\n * If the version of the software attempting to read or write the database does not satisfy the range, access is denied.\r\n */\r\n export interface RequiredVersionRanges {\r\n /** a range of acceptable persistence versions for reading from a VersionedSqliteDb. */\r\n readonly readVersion: VersionRange;\r\n /** a range of acceptable persistence versions for writing to a VersionedSqliteDb. */\r\n readonly writeVersion: VersionRange;\r\n }\r\n\r\n /** interface for reading and writing to a blob in a SQLiteDb\r\n * @internal\r\n */\r\n export interface BlobIO {\r\n /** Close this BlobIO if it is opened.\r\n * @note this BlobIO *may* be reused after this call by calling `open` again.\r\n */\r\n close(): void;\r\n /** get the total number of bytes in the blob */\r\n getNumBytes(): number;\r\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\r\n isValid(): boolean;\r\n /** Open this BlobIO against a table/row/column in a Db */\r\n open(\r\n /** The database for the blob */\r\n db: IModelJsNative.AnyDb,\r\n args: {\r\n /** the name of the table for the blob*/\r\n tableName: string;\r\n /** the name of the column for the blob */\r\n columnName: string;\r\n /** The rowId of the blob */\r\n row: number;\r\n /** If true, open this BlobIO for write access */\r\n writeable?: boolean;\r\n }): void;\r\n /** Read from a blob\r\n * @returns the contents of the requested byte range\r\n */\r\n read(args: {\r\n /** The number of bytes to read */\r\n numBytes: number;\r\n /** starting offset within the blob to read */\r\n offset: number;\r\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\r\n blob?: ArrayBuffer;\r\n }): Uint8Array;\r\n /** Reposition this BlobIO to a new rowId\r\n * @note this BlobIO must be valid when this methods is called.\r\n */\r\n changeRow(row: number): void;\r\n /** Write to a blob */\r\n write(args: {\r\n /** The number of bytes to write */\r\n numBytes: number;\r\n /** starting offset within the blob to write */\r\n offset: number;\r\n /** the value to write */\r\n blob: ArrayBuffer;\r\n }): void;\r\n }\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Size of a SQLiteDb page in bytes */\r\n export interface PageSize {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export type CreateParams = OpenOrCreateParams & PageSize;\r\n\r\n /** Arguments for `SqliteDb.withOpenDb` */\r\n export interface WithOpenDbArgs {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: CloudSqlite.CloudContainer;\r\n }\r\n\r\n /** Arguments for `SQLiteDb.vacuum` */\r\n export interface VacuumDbArgs extends PageSize {\r\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\r\n into?: LocalFileName;\r\n }\r\n}\r\n"]}
@@ -44,7 +44,6 @@ export declare class Schemas {
44
44
  * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.
45
45
  * @param schemaName Name of the schema to unregister
46
46
  * @return true if the schema was unregistered
47
- * @internal
48
47
  */
49
48
  static unregisterSchema(schemaName: string): boolean;
50
49
  /** Look up a previously registered schema
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAIA;;GAEG;AAMH;;GAEG;AACH,qBAAa,MAAM;IACjB;;;;OAIG;IACH,WAAkB,UAAU,IAAI,MAAM,CAA4E;IAElH;;;OAGG;IACH,WAAkB,uBAAuB,IAAI,OAAO,CAAkB;IAEtE;;;;;;OAMG;WACW,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAQ3D;;;OAGG;IACH,SAAS;CACV;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAoC;IAC9E,OAAO;IAEP;;OAEG;WACW,cAAc,CAAC,MAAM,EAAE,OAAO,MAAM;IAOlD;;;;;OAKG;WACW,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAQ3D;;;OAGG;WACW,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,MAAM,GAAG,SAAS;CACjF"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAIA;;GAEG;AAMH;;GAEG;AACH,qBAAa,MAAM;IACjB;;;;OAIG;IACH,WAAkB,UAAU,IAAI,MAAM,CAA4E;IAElH;;;OAGG;IACH,WAAkB,uBAAuB,IAAI,OAAO,CAAkB;IAEtE;;;;;;OAMG;WACW,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAQ3D;;;OAGG;IACH,SAAS;CACV;AAED;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAoC;IAC9E,OAAO;IAEP;;OAEG;WACW,cAAc,CAAC,MAAM,EAAE,OAAO,MAAM;IAOlD;;;;OAIG;WACW,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAQ3D;;;OAGG;WACW,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,MAAM,GAAG,SAAS;CACjF"}
package/lib/cjs/Schema.js CHANGED
@@ -65,7 +65,6 @@ class Schemas {
65
65
  * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.
66
66
  * @param schemaName Name of the schema to unregister
67
67
  * @return true if the schema was unregistered
68
- * @internal
69
68
  */
70
69
  static unregisterSchema(schemaName) {
71
70
  const schema = this.getRegisteredSchema(schemaName);
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,oDAAiD;AACjD,mDAAgD;AAEhD;;GAEG;AACH,MAAa,MAAM;IACjB;;;;OAIG;IACI,MAAM,KAAK,UAAU,KAAa,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAElH;;;OAGG;IACI,MAAM,KAAK,uBAAuB,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAEtE;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,aAAqB;QAChD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QAC1C,IAAI,cAAc;YAChB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,qCAAqC;QAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,gBAA0B,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;CAC/G;AAlCD,wBAkCC;AAED;;GAEG;AACH,MAAa,OAAO;IAElB,gBAAwB,CAAC,CAAC,sBAAsB;IAEhD;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,MAAqB;QAChD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;QAC5C,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC;YAC/B,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,aAAa,EAAE,WAAW,MAAM,CAAC,UAAU,yBAAyB,CAAC,CAAC;QAC3G,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,gBAAgB,CAAC,UAAkB;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACpD,IAAI,SAAS,KAAK,MAAM;YACtB,6BAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,mBAAmB,CAAC,UAAkB,IAA+B,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;;AA/B1H,0BAAkB,GAAG,IAAI,GAAG,EAAyB,CAAC;AADnE,0BAAO","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ClassRegistry } from \"./ClassRegistry\";\r\n\r\n/** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).\r\n * @public\r\n */\r\nexport class Schema {\r\n /** The name of the BIS schema handled by this Schema.\r\n * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.\r\n * Failure to do so will ordinarily result in an error when the schema is registered, since there may only\r\n * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)\r\n */\r\n public static get schemaName(): string { throw new Error(`you must override static schemaName in ${this.name}`); }\r\n\r\n /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.\r\n * Classes generated for this Schema will disallow protected operations.\r\n * @internal\r\n */\r\n public static get missingRequiredBehavior(): boolean { return false; }\r\n\r\n /** Get a semver-compatible string from a padded version string.\r\n * works on unpadded version strings as well\r\n * if there is no write version, it will be added\r\n * @example Schema.toSemverString(\"1.02.03\") === \"1.2.3\"\r\n * @example Schema.toSemverString(\"1.01\") === \"1.0.1\" // write version was added\r\n * @beta\r\n */\r\n public static toSemverString(paddedVersion: string): string {\r\n const tuple = paddedVersion.split(\".\").map(Number);\r\n const noWriteVersion = tuple.length === 2;\r\n if (noWriteVersion)\r\n tuple.splice(1, 0, 0); // insert 0 before the second element\r\n return tuple.join(\".\");\r\n }\r\n\r\n /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an\r\n * error if it is ever called.\r\n * @internal\r\n */\r\n protected constructor() { throw new Error(`cannot create an instance of a Schema ${this.constructor.name}`); }\r\n}\r\n\r\n/** Manages registered schemas\r\n * @public\r\n */\r\nexport class Schemas {\r\n private static readonly _registeredSchemas = new Map<string, typeof Schema>();\r\n private constructor() { } // this is a singleton\r\n\r\n /** Register a schema prior to using it.\r\n * @throws [[IModelError]] if a schema of the same name is already registered.\r\n */\r\n public static registerSchema(schema: typeof Schema) {\r\n const key = schema.schemaName.toLowerCase();\r\n if (this.getRegisteredSchema(key))\r\n throw new IModelError(IModelStatus.DuplicateName, `Schema \"${schema.schemaName}\" is already registered`);\r\n this._registeredSchemas.set(key, schema);\r\n }\r\n\r\n /** Unregister a schema, by name, if one is already registered.\r\n * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.\r\n * @param schemaName Name of the schema to unregister\r\n * @return true if the schema was unregistered\r\n * @internal\r\n */\r\n public static unregisterSchema(schemaName: string): boolean {\r\n const schema = this.getRegisteredSchema(schemaName);\r\n if (undefined !== schema)\r\n ClassRegistry.unregisterClassesFrom(schema);\r\n\r\n return this._registeredSchemas.delete(schemaName.toLowerCase());\r\n }\r\n\r\n /** Look up a previously registered schema\r\n * @param schemaName The name of the schema\r\n * @returns the previously registered schema or undefined if not registered.\r\n */\r\n public static getRegisteredSchema(schemaName: string): typeof Schema | undefined { return this._registeredSchemas.get(schemaName.toLowerCase()); }\r\n}\r\n"]}
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,oDAAiD;AACjD,mDAAgD;AAEhD;;GAEG;AACH,MAAa,MAAM;IACjB;;;;OAIG;IACI,MAAM,KAAK,UAAU,KAAa,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAElH;;;OAGG;IACI,MAAM,KAAK,uBAAuB,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAEtE;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,aAAqB;QAChD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC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CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;;AA9B1H,0BAAkB,GAAG,IAAI,GAAG,EAAyB,CAAC;AADnE,0BAAO","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ClassRegistry } from \"./ClassRegistry\";\r\n\r\n/** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).\r\n * @public\r\n */\r\nexport class Schema {\r\n /** The name of the BIS schema handled by this Schema.\r\n * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.\r\n * Failure to do so will ordinarily result in an error when the schema is registered, since there may only\r\n * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)\r\n */\r\n public static get schemaName(): string { throw new Error(`you must override static schemaName in ${this.name}`); }\r\n\r\n /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.\r\n * Classes generated for this Schema will disallow protected operations.\r\n * @internal\r\n */\r\n public static get missingRequiredBehavior(): boolean { return false; }\r\n\r\n /** Get a semver-compatible string from a padded version string.\r\n * works on unpadded version strings as well\r\n * if there is no write version, it will be added\r\n * @example Schema.toSemverString(\"1.02.03\") === \"1.2.3\"\r\n * @example Schema.toSemverString(\"1.01\") === \"1.0.1\" // write version was added\r\n * @beta\r\n */\r\n public static toSemverString(paddedVersion: string): string {\r\n const tuple = paddedVersion.split(\".\").map(Number);\r\n const noWriteVersion = tuple.length === 2;\r\n if (noWriteVersion)\r\n tuple.splice(1, 0, 0); // insert 0 before the second element\r\n return tuple.join(\".\");\r\n }\r\n\r\n /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an\r\n * error if it is ever called.\r\n * @internal\r\n */\r\n protected constructor() { throw new Error(`cannot create an instance of a Schema ${this.constructor.name}`); }\r\n}\r\n\r\n/** Manages registered schemas\r\n * @public\r\n */\r\nexport class Schemas {\r\n private static readonly _registeredSchemas = new Map<string, typeof Schema>();\r\n private constructor() { } // this is a singleton\r\n\r\n /** Register a schema prior to using it.\r\n * @throws [[IModelError]] if a schema of the same name is already registered.\r\n */\r\n public static registerSchema(schema: typeof Schema) {\r\n const key = schema.schemaName.toLowerCase();\r\n if (this.getRegisteredSchema(key))\r\n throw new IModelError(IModelStatus.DuplicateName, `Schema \"${schema.schemaName}\" is already registered`);\r\n this._registeredSchemas.set(key, schema);\r\n }\r\n\r\n /** Unregister a schema, by name, if one is already registered.\r\n * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.\r\n * @param schemaName Name of the schema to unregister\r\n * @return true if the schema was unregistered\r\n */\r\n public static unregisterSchema(schemaName: string): boolean {\r\n const schema = this.getRegisteredSchema(schemaName);\r\n if (undefined !== schema)\r\n ClassRegistry.unregisterClassesFrom(schema);\r\n\r\n return this._registeredSchemas.delete(schemaName.toLowerCase());\r\n }\r\n\r\n /** Look up a previously registered schema\r\n * @param schemaName The name of the schema\r\n * @returns the previously registered schema or undefined if not registered.\r\n */\r\n public static getRegisteredSchema(schemaName: string): typeof Schema | undefined { return this._registeredSchemas.get(schemaName.toLowerCase()); }\r\n}\r\n"]}
@@ -0,0 +1,19 @@
1
+ /** @packageDocumentation
2
+ * @module Schema
3
+ */
4
+ import { ECSchemaXmlContext } from "./ECSchemaXmlContext";
5
+ /** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.
6
+ * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.
7
+ * @returns EC3.2 Xml ECSchema(s).
8
+ * @throws [[IModelError]] if there is a problem converting the EC2 schemas.
9
+ * @beta
10
+ */
11
+ export declare function convertEC2SchemasToEC3Schemas(ec2XmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[];
12
+ /** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName
13
+ * @param xmlSchemas The ECSchema Xml string(s).
14
+ * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.
15
+ * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.
16
+ * @beta
17
+ */
18
+ export declare function upgradeCustomAttributesToEC3(xmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[];
19
+ //# sourceMappingURL=SchemaUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaUtils.d.ts","sourceRoot":"","sources":["../../src/SchemaUtils.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,aAAa,CAAC,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAOnH;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,aAAa,CAAC,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAO/G"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Schema
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.upgradeCustomAttributesToEC3 = exports.convertEC2SchemasToEC3Schemas = void 0;
11
+ const imodeljs_native_1 = require("@bentley/imodeljs-native");
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ /** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.
15
+ * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.
16
+ * @returns EC3.2 Xml ECSchema(s).
17
+ * @throws [[IModelError]] if there is a problem converting the EC2 schemas.
18
+ * @beta
19
+ */
20
+ function convertEC2SchemasToEC3Schemas(ec2XmlSchemas, schemaContext) {
21
+ const maybeNativeContext = schemaContext?.nativeContext;
22
+ const ec3XmlSchemas = imodeljs_native_1.IModelJsNative.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);
23
+ if (ec2XmlSchemas.length === 0)
24
+ throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Error converting EC2 Xml schemas");
25
+ return ec3XmlSchemas;
26
+ }
27
+ exports.convertEC2SchemasToEC3Schemas = convertEC2SchemasToEC3Schemas;
28
+ /** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName
29
+ * @param xmlSchemas The ECSchema Xml string(s).
30
+ * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.
31
+ * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.
32
+ * @beta
33
+ */
34
+ function upgradeCustomAttributesToEC3(xmlSchemas, schemaContext) {
35
+ const maybeNativeContext = schemaContext?.nativeContext;
36
+ const schemasWithConvertedCA = imodeljs_native_1.IModelJsNative.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);
37
+ if (schemasWithConvertedCA.length === 0)
38
+ throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Error converting custom attributes of Xml schemas");
39
+ return schemasWithConvertedCA;
40
+ }
41
+ exports.upgradeCustomAttributesToEC3 = upgradeCustomAttributesToEC3;
42
+ //# sourceMappingURL=SchemaUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../../src/SchemaUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,8DAA0D;AAC1D,sDAAoD;AACpD,oDAAiD;AAGjD;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,aAAuB,EAAE,aAAkC;IACvG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,aAAa,GAAa,gCAAc,CAAC,aAAa,CAAC,oBAAoB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IACrH,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kCAAkC,CAAC,CAAC;IAEjF,OAAO,aAAa,CAAC;AACvB,CAAC;AAPD,sEAOC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAAC,UAAoB,EAAE,aAAkC;IACnG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,sBAAsB,GAAa,gCAAc,CAAC,aAAa,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IAC9H,IAAI,sBAAsB,CAAC,MAAM,KAAK,CAAC;QACrC,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,mDAAmD,CAAC,CAAC;IAElG,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAPD,oEAOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ECSchemaXmlContext } from \"./ECSchemaXmlContext\";\r\n\r\n/** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.\r\n * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.\r\n * @returns EC3.2 Xml ECSchema(s).\r\n * @throws [[IModelError]] if there is a problem converting the EC2 schemas.\r\n * @beta\r\n */\r\nexport function convertEC2SchemasToEC3Schemas(ec2XmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const ec3XmlSchemas: string[] = IModelJsNative.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);\r\n if (ec2XmlSchemas.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting EC2 Xml schemas\");\r\n\r\n return ec3XmlSchemas;\r\n}\r\n\r\n/** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName\r\n * @param xmlSchemas The ECSchema Xml string(s).\r\n * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.\r\n * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.\r\n * @beta\r\n */\r\nexport function upgradeCustomAttributesToEC3(xmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const schemasWithConvertedCA: string[] = IModelJsNative.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);\r\n if (schemasWithConvertedCA.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting custom attributes of Xml schemas\");\r\n\r\n return schemasWithConvertedCA;\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
1
  /** @packageDocumentation
2
2
  * @module SQLite
3
3
  */
4
- import { DbResult, GuidString, Id64String, IDisposable } from "@itwin/core-bentley";
4
+ import { BentleyError, DbResult, GuidString, Id64String, IDisposable } from "@itwin/core-bentley";
5
5
  import { IModelJsNative } from "@bentley/imodeljs-native";
6
6
  /** Marks a string as either an [Id64String]($core-bentley) or [GuidString]($core-bentley), so
7
7
  * that it can be passed to the [bindValue]($backend.SqliteStatement) or [bindValues]($backend.SqliteStatement)
@@ -70,6 +70,8 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
70
70
  * @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.
71
71
  */
72
72
  nextRow(): boolean;
73
+ throwSqlError(rc: DbResult): void;
74
+ stepForWrite(): void;
73
75
  /** Binds a value to the specified SQL parameter.
74
76
  * The value must be of one of these types:
75
77
  * JavaScript Type | SQLite Type
@@ -357,5 +359,15 @@ export declare class StatementCache<Stmt extends Statement> {
357
359
  findAndRemove(sql: string): Stmt | undefined;
358
360
  clear(): void;
359
361
  }
362
+ /** @public */
363
+ export declare namespace SqliteStatement {
364
+ class DbError extends BentleyError {
365
+ /** A string that indicates the type of problem that caused the exception. */
366
+ readonly errorId: ErrorId;
367
+ /** @internal */
368
+ constructor(errorId: ErrorId, errNum: number, message: string);
369
+ }
370
+ type ErrorId = "DuplicateValue" | "SqlLogicError" | "ValueIsInUse";
371
+ }
360
372
  export {};
361
373
  //# sourceMappingURL=SqliteStatement.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteStatement.d.ts","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAwB,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAU,MAAM,qBAAqB,CAAC;AAElH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAO1D;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAO5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,eAAgB,YAAW,gBAAgB,CAAC,GAAG,CAAC,EAAE,WAAW;IAIrD,OAAO,CAAC,IAAI;IAH/B,OAAO,CAAC,KAAK,CAA6C;IAC1D,OAAO,CAAC,GAAG,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AO,EAAE,MAAM;KAI9D;IAED,KAAY,OAAO,GACjB,gBAAgB,GAChB,eAAe,GACf,cAAc,CAAC;CAClB"}
@@ -91,7 +91,18 @@ class SqliteStatement {
91
91
  case core_bentley_1.DbResult.BE_SQLITE_DONE:
92
92
  return false;
93
93
  }
94
- throw new core_bentley_1.BentleyError(rc, this._db.getLastError());
94
+ this.throwSqlError(rc);
95
+ return false; // unreachable
96
+ }
97
+ throwSqlError(rc) {
98
+ throw new SqliteStatement.DbError(rc === core_bentley_1.DbResult.BE_SQLITE_CONSTRAINT_FOREIGNKEY ? "ValueIsInUse" :
99
+ rc === core_bentley_1.DbResult.BE_SQLITE_CONSTRAINT_UNIQUE ? "DuplicateValue" :
100
+ "SqlLogicError", rc, `SQL error: ${this._db.getLastError()}`);
101
+ }
102
+ stepForWrite() {
103
+ const rc = this.step();
104
+ if (rc !== core_bentley_1.DbResult.BE_SQLITE_DONE)
105
+ this.throwSqlError(rc);
95
106
  }
96
107
  /** Binds a value to the specified SQL parameter.
97
108
  * The value must be of one of these types:
@@ -584,4 +595,15 @@ class StatementCache {
584
595
  }
585
596
  }
586
597
  exports.StatementCache = StatementCache;
598
+ /** @public */
599
+ (function (SqliteStatement) {
600
+ class DbError extends core_bentley_1.BentleyError {
601
+ /** @internal */
602
+ constructor(errorId, errNum, message) {
603
+ super(errNum, message);
604
+ this.errorId = errorId;
605
+ }
606
+ }
607
+ SqliteStatement.DbError = DbError;
608
+ })(SqliteStatement = exports.SqliteStatement || (exports.SqliteStatement = {}));
587
609
  //# sourceMappingURL=SqliteStatement.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkH;AAClH,oDAA4D;AAE5D,6CAA0C;AAqB1C,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,IAAI,KAAK,uBAAQ,CAAC,YAAY;QAChC,MA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IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACzC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAG,CAAC;YACpC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;SACrB;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAEM,aAAa,CAAC,GAAW;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAjCD,wCAiCC","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 throw new BentleyError(rc, this._db!.getLastError());\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"]}
1
+ {"version":3,"file":"SqliteStatement.js","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAkH;AAClH,oDAA4D;AAE5D,6CAA0C;AAqB1C,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,IAAI,KAAK,uBAAQ,CAAC,YAAY;QAChC,MAAM,IAAI,yBAAW,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,eAAe;IAI1B,YAA2B,IAAY;Q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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"]}
@@ -7,7 +7,7 @@ import { DefinitionElement } from "./Element";
7
7
  import { IModelDb } from "./IModelDb";
8
8
  /** A [TextureProps]($common) in which the image data can be specified either as a base-64-encoded string or a Uint8Array.
9
9
  * @see [[Texture]] constructor.
10
- * @internal
10
+ * @beta
11
11
  */
12
12
  export interface TextureCreateProps extends Omit<TextureProps, "data"> {
13
13
  data: Base64EncodedString | Uint8Array;
@@ -21,9 +21,8 @@ export declare class Texture extends DefinitionElement {
21
21
  format: ImageSourceFormat;
22
22
  data: Uint8Array;
23
23
  description?: string;
24
- /** @internal */
25
- constructor(props: TextureCreateProps, iModel: IModelDb);
26
- /** @internal */
24
+ /** @beta */
25
+ protected constructor(props: TextureCreateProps, iModel: IModelDb);
27
26
  toJSON(): TextureProps;
28
27
  /** Create a Code for a Texture given a name that is meant to be unique within the scope of the specified DefinitionModel.
29
28
  * @param iModel The IModelDb
@@ -1 +1 @@
1
- {"version":3,"file":"Texture.d.ts","sourceRoot":"","sources":["../../src/Texture.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACL,mBAAmB,EAAe,IAAI,EAAE,cAAc,EAAY,iBAAiB,EAAE,YAAY,EAClG,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC;IACpE,IAAI,EAAE,mBAAmB,GAAG,UAAU,CAAC;CACxC;AAED;;GAEG;AACH,qBAAa,OAAQ,SAAQ,iBAAiB;IAC5C,gBAAgB;IAChB,WAA2B,SAAS,IAAI,MAAM,CAAsB;IAC7D,MAAM,EAAE,iBAAiB,CAAC;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IAE5B,gBAAgB;gBACJ,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ;IAOvD,gBAAgB;IACA,MAAM,IAAI,YAAY;IAQtC;;;;OAIG;WACW,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAK5F;;;;;;;;;;OAUG;WACW,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,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