@itwin/core-backend 3.0.0-dev.100

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 (245) hide show
  1. package/CHANGELOG.md +1525 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +11 -0
  4. package/lib/cjs/AliCloudStorageService.d.ts +12 -0
  5. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -0
  6. package/lib/cjs/AliCloudStorageService.js +70 -0
  7. package/lib/cjs/AliCloudStorageService.js.map +1 -0
  8. package/lib/cjs/BackendHubAccess.d.ts +208 -0
  9. package/lib/cjs/BackendHubAccess.d.ts.map +1 -0
  10. package/lib/cjs/BackendHubAccess.js +42 -0
  11. package/lib/cjs/BackendHubAccess.js.map +1 -0
  12. package/lib/cjs/BackendLoggerCategory.d.ts +83 -0
  13. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -0
  14. package/lib/cjs/BackendLoggerCategory.js +91 -0
  15. package/lib/cjs/BackendLoggerCategory.js.map +1 -0
  16. package/lib/cjs/BisCoreSchema.d.ts +22 -0
  17. package/lib/cjs/BisCoreSchema.d.ts.map +1 -0
  18. package/lib/cjs/BisCoreSchema.js +61 -0
  19. package/lib/cjs/BisCoreSchema.js.map +1 -0
  20. package/lib/cjs/BriefcaseManager.d.ts +167 -0
  21. package/lib/cjs/BriefcaseManager.d.ts.map +1 -0
  22. package/lib/cjs/BriefcaseManager.js +406 -0
  23. package/lib/cjs/BriefcaseManager.js.map +1 -0
  24. package/lib/cjs/Category.d.ts +154 -0
  25. package/lib/cjs/Category.d.ts.map +1 -0
  26. package/lib/cjs/Category.js +244 -0
  27. package/lib/cjs/Category.js.map +1 -0
  28. package/lib/cjs/ChangeSummaryManager.d.ts +188 -0
  29. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -0
  30. package/lib/cjs/ChangeSummaryManager.js +444 -0
  31. package/lib/cjs/ChangeSummaryManager.js.map +1 -0
  32. package/lib/cjs/ChangedElementsDb.d.ts +97 -0
  33. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -0
  34. package/lib/cjs/ChangedElementsDb.js +166 -0
  35. package/lib/cjs/ChangedElementsDb.js.map +1 -0
  36. package/lib/cjs/ChangedElementsManager.d.ts +40 -0
  37. package/lib/cjs/ChangedElementsManager.d.ts.map +1 -0
  38. package/lib/cjs/ChangedElementsManager.js +89 -0
  39. package/lib/cjs/ChangedElementsManager.js.map +1 -0
  40. package/lib/cjs/CheckpointManager.d.ts +101 -0
  41. package/lib/cjs/CheckpointManager.d.ts.map +1 -0
  42. package/lib/cjs/CheckpointManager.js +257 -0
  43. package/lib/cjs/CheckpointManager.js.map +1 -0
  44. package/lib/cjs/ClassRegistry.d.ts +72 -0
  45. package/lib/cjs/ClassRegistry.d.ts.map +1 -0
  46. package/lib/cjs/ClassRegistry.js +154 -0
  47. package/lib/cjs/ClassRegistry.js.map +1 -0
  48. package/lib/cjs/CloudStorageBackend.d.ts +46 -0
  49. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -0
  50. package/lib/cjs/CloudStorageBackend.js +157 -0
  51. package/lib/cjs/CloudStorageBackend.js.map +1 -0
  52. package/lib/cjs/CodeSpecs.d.ts +51 -0
  53. package/lib/cjs/CodeSpecs.d.ts.map +1 -0
  54. package/lib/cjs/CodeSpecs.js +113 -0
  55. package/lib/cjs/CodeSpecs.js.map +1 -0
  56. package/lib/cjs/ConcurrentQuery.d.ts +12 -0
  57. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -0
  58. package/lib/cjs/ConcurrentQuery.js +24 -0
  59. package/lib/cjs/ConcurrentQuery.js.map +1 -0
  60. package/lib/cjs/DevTools.d.ts +72 -0
  61. package/lib/cjs/DevTools.d.ts.map +1 -0
  62. package/lib/cjs/DevTools.js +155 -0
  63. package/lib/cjs/DevTools.js.map +1 -0
  64. package/lib/cjs/DisplayStyle.d.ts +107 -0
  65. package/lib/cjs/DisplayStyle.d.ts.map +1 -0
  66. package/lib/cjs/DisplayStyle.js +292 -0
  67. package/lib/cjs/DisplayStyle.js.map +1 -0
  68. package/lib/cjs/ECDb.d.ts +196 -0
  69. package/lib/cjs/ECDb.d.ts.map +1 -0
  70. package/lib/cjs/ECDb.js +354 -0
  71. package/lib/cjs/ECDb.js.map +1 -0
  72. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -0
  73. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -0
  74. package/lib/cjs/ECSchemaXmlContext.js +36 -0
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -0
  76. package/lib/cjs/ECSqlStatement.d.ts +467 -0
  77. package/lib/cjs/ECSqlStatement.d.ts.map +1 -0
  78. package/lib/cjs/ECSqlStatement.js +783 -0
  79. package/lib/cjs/ECSqlStatement.js.map +1 -0
  80. package/lib/cjs/Element.d.ts +1082 -0
  81. package/lib/cjs/Element.d.ts.map +1 -0
  82. package/lib/cjs/Element.js +1392 -0
  83. package/lib/cjs/Element.js.map +1 -0
  84. package/lib/cjs/ElementAspect.d.ts +157 -0
  85. package/lib/cjs/ElementAspect.d.ts.map +1 -0
  86. package/lib/cjs/ElementAspect.js +179 -0
  87. package/lib/cjs/ElementAspect.js.map +1 -0
  88. package/lib/cjs/ElementGraphics.d.ts +10 -0
  89. package/lib/cjs/ElementGraphics.d.ts.map +1 -0
  90. package/lib/cjs/ElementGraphics.js +42 -0
  91. package/lib/cjs/ElementGraphics.js.map +1 -0
  92. package/lib/cjs/Entity.d.ts +57 -0
  93. package/lib/cjs/Entity.d.ts.map +1 -0
  94. package/lib/cjs/Entity.js +63 -0
  95. package/lib/cjs/Entity.js.map +1 -0
  96. package/lib/cjs/ExportGraphics.d.ts +302 -0
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -0
  98. package/lib/cjs/ExportGraphics.js +206 -0
  99. package/lib/cjs/ExportGraphics.js.map +1 -0
  100. package/lib/cjs/ExternalSource.d.ts +95 -0
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -0
  102. package/lib/cjs/ExternalSource.js +126 -0
  103. package/lib/cjs/ExternalSource.js.map +1 -0
  104. package/lib/cjs/GeometrySummary.d.ts +5 -0
  105. package/lib/cjs/GeometrySummary.d.ts.map +1 -0
  106. package/lib/cjs/GeometrySummary.js +378 -0
  107. package/lib/cjs/GeometrySummary.js.map +1 -0
  108. package/lib/cjs/IModelCloneContext.d.ts +74 -0
  109. package/lib/cjs/IModelCloneContext.d.ts.map +1 -0
  110. package/lib/cjs/IModelCloneContext.js +130 -0
  111. package/lib/cjs/IModelCloneContext.js.map +1 -0
  112. package/lib/cjs/IModelDb.d.ts +1107 -0
  113. package/lib/cjs/IModelDb.d.ts.map +1 -0
  114. package/lib/cjs/IModelDb.js +2161 -0
  115. package/lib/cjs/IModelDb.js.map +1 -0
  116. package/lib/cjs/IModelHost.d.ts +284 -0
  117. package/lib/cjs/IModelHost.d.ts.map +1 -0
  118. package/lib/cjs/IModelHost.js +411 -0
  119. package/lib/cjs/IModelHost.js.map +1 -0
  120. package/lib/cjs/IModelJsFs.d.ts +63 -0
  121. package/lib/cjs/IModelJsFs.d.ts.map +1 -0
  122. package/lib/cjs/IModelJsFs.js +141 -0
  123. package/lib/cjs/IModelJsFs.js.map +1 -0
  124. package/lib/cjs/IModelSchemaLoader.d.ts +26 -0
  125. package/lib/cjs/IModelSchemaLoader.d.ts.map +1 -0
  126. package/lib/cjs/IModelSchemaLoader.js +95 -0
  127. package/lib/cjs/IModelSchemaLoader.js.map +1 -0
  128. package/lib/cjs/IpcHost.d.ts +99 -0
  129. package/lib/cjs/IpcHost.d.ts.map +1 -0
  130. package/lib/cjs/IpcHost.js +234 -0
  131. package/lib/cjs/IpcHost.js.map +1 -0
  132. package/lib/cjs/LineStyle.d.ts +312 -0
  133. package/lib/cjs/LineStyle.d.ts.map +1 -0
  134. package/lib/cjs/LineStyle.js +296 -0
  135. package/lib/cjs/LineStyle.js.map +1 -0
  136. package/lib/cjs/LocalhostIpcHost.d.ts +19 -0
  137. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -0
  138. package/lib/cjs/LocalhostIpcHost.js +52 -0
  139. package/lib/cjs/LocalhostIpcHost.js.map +1 -0
  140. package/lib/cjs/Material.d.ts +102 -0
  141. package/lib/cjs/Material.d.ts.map +1 -0
  142. package/lib/cjs/Material.js +146 -0
  143. package/lib/cjs/Material.js.map +1 -0
  144. package/lib/cjs/Model.d.ts +387 -0
  145. package/lib/cjs/Model.d.ts.map +1 -0
  146. package/lib/cjs/Model.js +469 -0
  147. package/lib/cjs/Model.js.map +1 -0
  148. package/lib/cjs/NativeAppStorage.d.ts +52 -0
  149. package/lib/cjs/NativeAppStorage.d.ts.map +1 -0
  150. package/lib/cjs/NativeAppStorage.js +203 -0
  151. package/lib/cjs/NativeAppStorage.js.map +1 -0
  152. package/lib/cjs/NativeHost.d.ts +71 -0
  153. package/lib/cjs/NativeHost.d.ts.map +1 -0
  154. package/lib/cjs/NativeHost.js +221 -0
  155. package/lib/cjs/NativeHost.js.map +1 -0
  156. package/lib/cjs/NavigationRelationship.d.ts +157 -0
  157. package/lib/cjs/NavigationRelationship.d.ts.map +1 -0
  158. package/lib/cjs/NavigationRelationship.js +226 -0
  159. package/lib/cjs/NavigationRelationship.js.map +1 -0
  160. package/lib/cjs/PromiseMemoizer.d.ts +52 -0
  161. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -0
  162. package/lib/cjs/PromiseMemoizer.js +93 -0
  163. package/lib/cjs/PromiseMemoizer.js.map +1 -0
  164. package/lib/cjs/Relationship.d.ts +400 -0
  165. package/lib/cjs/Relationship.d.ts.map +1 -0
  166. package/lib/cjs/Relationship.js +460 -0
  167. package/lib/cjs/Relationship.js.map +1 -0
  168. package/lib/cjs/RpcBackend.d.ts +23 -0
  169. package/lib/cjs/RpcBackend.d.ts.map +1 -0
  170. package/lib/cjs/RpcBackend.js +94 -0
  171. package/lib/cjs/RpcBackend.js.map +1 -0
  172. package/lib/cjs/SQLiteDb.d.ts +66 -0
  173. package/lib/cjs/SQLiteDb.d.ts.map +1 -0
  174. package/lib/cjs/SQLiteDb.js +140 -0
  175. package/lib/cjs/SQLiteDb.js.map +1 -0
  176. package/lib/cjs/Schema.d.ts +56 -0
  177. package/lib/cjs/Schema.d.ts.map +1 -0
  178. package/lib/cjs/Schema.js +84 -0
  179. package/lib/cjs/Schema.js.map +1 -0
  180. package/lib/cjs/ServerBasedLocks.d.ts +64 -0
  181. package/lib/cjs/ServerBasedLocks.d.ts.map +1 -0
  182. package/lib/cjs/ServerBasedLocks.js +177 -0
  183. package/lib/cjs/ServerBasedLocks.js.map +1 -0
  184. package/lib/cjs/SqliteStatement.d.ts +264 -0
  185. package/lib/cjs/SqliteStatement.d.ts.map +1 -0
  186. package/lib/cjs/SqliteStatement.js +417 -0
  187. package/lib/cjs/SqliteStatement.js.map +1 -0
  188. package/lib/cjs/Texture.d.ts +59 -0
  189. package/lib/cjs/Texture.d.ts.map +1 -0
  190. package/lib/cjs/Texture.js +83 -0
  191. package/lib/cjs/Texture.js.map +1 -0
  192. package/lib/cjs/TxnManager.d.ts +203 -0
  193. package/lib/cjs/TxnManager.d.ts.map +1 -0
  194. package/lib/cjs/TxnManager.js +354 -0
  195. package/lib/cjs/TxnManager.js.map +1 -0
  196. package/lib/cjs/ViewDefinition.d.ts +432 -0
  197. package/lib/cjs/ViewDefinition.d.ts.map +1 -0
  198. package/lib/cjs/ViewDefinition.js +623 -0
  199. package/lib/cjs/ViewDefinition.js.map +1 -0
  200. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -0
  201. package/lib/cjs/core-backend.d.ts +162 -0
  202. package/lib/cjs/core-backend.d.ts.map +1 -0
  203. package/lib/cjs/core-backend.js +181 -0
  204. package/lib/cjs/core-backend.js.map +1 -0
  205. package/lib/cjs/domains/FunctionalElements.d.ts +102 -0
  206. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -0
  207. package/lib/cjs/domains/FunctionalElements.js +146 -0
  208. package/lib/cjs/domains/FunctionalElements.js.map +1 -0
  209. package/lib/cjs/domains/FunctionalSchema.d.ts +14 -0
  210. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -0
  211. package/lib/cjs/domains/FunctionalSchema.js +41 -0
  212. package/lib/cjs/domains/FunctionalSchema.js.map +1 -0
  213. package/lib/cjs/domains/GenericElements.d.ts +178 -0
  214. package/lib/cjs/domains/GenericElements.d.ts.map +1 -0
  215. package/lib/cjs/domains/GenericElements.js +264 -0
  216. package/lib/cjs/domains/GenericElements.js.map +1 -0
  217. package/lib/cjs/domains/GenericSchema.d.ts +11 -0
  218. package/lib/cjs/domains/GenericSchema.d.ts.map +1 -0
  219. package/lib/cjs/domains/GenericSchema.js +29 -0
  220. package/lib/cjs/domains/GenericSchema.js.map +1 -0
  221. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +16 -0
  222. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts.map +1 -0
  223. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +33 -0
  224. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -0
  225. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +40 -0
  226. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -0
  227. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +207 -0
  228. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -0
  229. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +21 -0
  230. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -0
  231. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -0
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -0
  233. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +37 -0
  234. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -0
  235. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +162 -0
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -0
  237. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +17 -0
  238. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts.map +1 -0
  239. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +44 -0
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -0
  241. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +16 -0
  242. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts.map +1 -0
  243. package/lib/cjs/rpc-impl/WipRpcImpl.js +35 -0
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -0
  245. package/package.json +101 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RpcBackend.js","sourceRoot":"","sources":["../../src/RpcBackend.ts"],"names":[],"mappings":"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","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 RpcInterface\r\n */\r\n\r\n// cspell:ignore calltrace\r\n\r\nimport * as multiparty from \"multiparty\";\r\nimport * as FormData from \"form-data\";\r\nimport { BentleyStatus, HttpServerRequest, IModelError, RpcActivity, RpcInvocation, RpcMultipart, RpcSerializedValue } from \"@itwin/core-common\";\r\nimport { AsyncLocalStorage } from \"async_hooks\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\n\r\n/**\r\n * Utility for tracing Rpc activity processing. When multiple Rpc requests are being processed asynchronously, this\r\n * class can be used to correlate the current calltrace with the originating RpcActivity. This is used for automatic appending\r\n * of RpcActivity to log messages emitted during Rpc processing. It may also be used to retrieve the user accessToken\r\n * from the RpcActivity.\r\n * @public\r\n */\r\nexport class RpcTrace {\r\n private static _storage = new AsyncLocalStorage();\r\n\r\n /** Get the [RpcActivity]($common) for the currently executing async, or `undefined` if there is no\r\n * RpcActivity in the current call stack.\r\n * */\r\n public static get currentActivity(): RpcActivity | undefined {\r\n return RpcTrace._storage.getStore() as RpcActivity | undefined;\r\n }\r\n\r\n /** Start the processing of an RpcActivity. */\r\n public static async run<T>(activity: RpcActivity, fn: () => Promise<T>): Promise<T> {\r\n return RpcTrace._storage.run(activity, fn);\r\n }\r\n}\r\n\r\nlet initialized = false;\r\n/** @internal */\r\nexport function initializeRpcBackend() {\r\n if (initialized)\r\n return;\r\n\r\n initialized = true;\r\n\r\n RpcInvocation.runActivity = RpcTrace.run; // redirect the invocation processing to the tracer\r\n\r\n // set up static logger metadata to include current RpcActivity information for logs during rpc processing\r\n Logger.staticMetaData.set(\"rpc\", () => RpcInvocation.sanitizeForLog(RpcTrace.currentActivity));\r\n\r\n RpcMultipart.createStream = (value: RpcSerializedValue) => {\r\n const form = new FormData();\r\n RpcMultipart.writeValueToForm(form, value);\r\n return form;\r\n };\r\n\r\n RpcMultipart.parseRequest = async (req: HttpServerRequest) => {\r\n return new Promise<RpcSerializedValue>((resolve, reject) => {\r\n const form = new multiparty.Form({ maxFieldsSize: Infinity });\r\n form.on(\"error\", (err) => {\r\n reject(err);\r\n });\r\n\r\n const value = RpcSerializedValue.create();\r\n const data: { [index: string]: { size: number, chunks: Buffer[] } } = {};\r\n\r\n form.on(\"part\", (part: multiparty.Part) => {\r\n part.on(\"data\", (chunk: string | Buffer) => {\r\n if (part.name === \"objects\") {\r\n value.objects += chunk.toString();\r\n } else if (Buffer.isBuffer(chunk)) {\r\n if (!data[part.name]) {\r\n data[part.name] = { size: 0, chunks: [] };\r\n }\r\n\r\n data[part.name].size += chunk.byteLength;\r\n data[part.name].chunks.push(chunk);\r\n } else {\r\n throw new IModelError(BentleyStatus.ERROR, \"Unknown input.\");\r\n }\r\n });\r\n });\r\n\r\n form.on(\"close\", () => {\r\n let i = 0;\r\n for (; ;) {\r\n const part = data[`data-${i}`];\r\n if (!part) {\r\n break;\r\n }\r\n\r\n value.data.push(Buffer.concat(part.chunks, part.size));\r\n ++i;\r\n }\r\n\r\n resolve(value);\r\n });\r\n\r\n form.parse(req);\r\n });\r\n };\r\n}\r\n\r\n"]}
@@ -0,0 +1,66 @@
1
+ /** @packageDocumentation
2
+ * @module SQLiteDb
3
+ */
4
+ import { DbResult, IDisposable, OpenMode } from "@itwin/core-bentley";
5
+ import { IModelJsNative } from "@bentley/imodeljs-native";
6
+ import { SqliteStatement } from "./SqliteStatement";
7
+ /** A SQLiteDb file
8
+ * @public
9
+ */
10
+ export declare class SQLiteDb implements IDisposable {
11
+ private _nativeDb?;
12
+ private _sqliteStatementCache;
13
+ /** @internal */
14
+ get nativeDb(): IModelJsNative.SQLiteDb;
15
+ constructor();
16
+ /** Call this function when finished with this SQLiteDb. This releases the native resources */
17
+ dispose(): void;
18
+ /** Create a SQLiteDb
19
+ * @param pathName The path to the SQLiteDb file to create.
20
+ */
21
+ createDb(pathName: string): void;
22
+ /** Open a SQLiteDb.
23
+ * @param pathName The path to the SQLiteDb file to open
24
+ */
25
+ openDb(pathName: string, openMode: OpenMode): void;
26
+ /** Returns true if the SQLiteDb is open */
27
+ get isOpen(): boolean;
28
+ /** Close SQLiteDb. */
29
+ closeDb(): void;
30
+ /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */
31
+ saveChanges(): void;
32
+ /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */
33
+ abandonChanges(): void;
34
+ /**
35
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
36
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
37
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
38
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
39
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
40
+ * @param sql The SQLite SQL statement to execute
41
+ * @param callback the callback to invoke on the prepared statement
42
+ * @returns the value returned by `callback`.
43
+ * @see [[withPreparedStatement]]
44
+ * @public
45
+ */
46
+ withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T;
47
+ /**
48
+ * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
49
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
50
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
51
+ * @param sql The SQLite SQL statement to execute
52
+ * @param callback the callback to invoke on the prepared statement
53
+ * @returns the value returned by `callback`.
54
+ * @public
55
+ */
56
+ withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T;
57
+ /** Prepare an SQL statement.
58
+ * @param sql The SQLite SQL statement to prepare
59
+ * @param logErrors Determine if errors are logged or not
60
+ * @internal
61
+ */
62
+ prepareSqliteStatement(sql: string, logErrors?: boolean): SqliteStatement;
63
+ /** execute an SQL statement */
64
+ executeSQL(sql: string): DbResult;
65
+ }
66
+ //# sourceMappingURL=SQLiteDb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLiteDb.d.ts","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAkB,MAAM,mBAAmB,CAAC;AAEpE;;GAEG;AACH,qBAAa,QAAS,YAAW,WAAW;IAC1C,OAAO,CAAC,SAAS,CAAC,CAA0B;IAC5C,OAAO,CAAC,qBAAqB,CAAyC;IAEtE,gBAAgB;IAChB,IAAW,QAAQ,IAAI,cAAc,CAAC,QAAQ,CAE7C;;IAKD,8FAA8F;IACvF,OAAO,IAAI,IAAI;IAStB;;OAEG;IACI,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIvC;;OAEG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAIzD,2CAA2C;IAC3C,IAAW,MAAM,IAAI,OAAO,CAAmC;IAE/D,sBAAsB;IACf,OAAO,IAAI,IAAI;IAKtB,oGAAoG;IAC7F,WAAW,IAAI,IAAI;IAI1B,yHAAyH;IAClH,cAAc,IAAI,IAAI;IAI7B;;;;;;;;;;;SAWK;IACE,2BAA2B,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,GAAG,CAAC;IAiB7F;;;;;;;;SAQK;IACE,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,GAAG,CAAC;IAiBrF;;;;SAIK;IACE,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,UAAO,GAAG,eAAe;IAM7E,+BAA+B;IACxB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ;CAQzC"}
@@ -0,0 +1,140 @@
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 SQLiteDb
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SQLiteDb = void 0;
11
+ const IModelHost_1 = require("./IModelHost");
12
+ const SqliteStatement_1 = require("./SqliteStatement");
13
+ /** A SQLiteDb file
14
+ * @public
15
+ */
16
+ class SQLiteDb {
17
+ constructor() {
18
+ this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
19
+ this._nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
20
+ }
21
+ /** @internal */
22
+ get nativeDb() {
23
+ return this._nativeDb;
24
+ }
25
+ /** Call this function when finished with this SQLiteDb. This releases the native resources */
26
+ dispose() {
27
+ if (!this._nativeDb)
28
+ return;
29
+ this.closeDb();
30
+ this._nativeDb.dispose();
31
+ this._nativeDb = undefined;
32
+ }
33
+ /** Create a SQLiteDb
34
+ * @param pathName The path to the SQLiteDb file to create.
35
+ */
36
+ createDb(pathName) {
37
+ this.nativeDb.createDb(pathName);
38
+ }
39
+ /** Open a SQLiteDb.
40
+ * @param pathName The path to the SQLiteDb file to open
41
+ */
42
+ openDb(pathName, openMode) {
43
+ this.nativeDb.openDb(pathName, openMode);
44
+ }
45
+ /** Returns true if the SQLiteDb is open */
46
+ get isOpen() { return this.nativeDb.isOpen(); }
47
+ /** Close SQLiteDb. */
48
+ closeDb() {
49
+ this._sqliteStatementCache.clear();
50
+ this.nativeDb.closeDb();
51
+ }
52
+ /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */
53
+ saveChanges() {
54
+ this.nativeDb.saveChanges();
55
+ }
56
+ /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */
57
+ abandonChanges() {
58
+ this.nativeDb.abandonChanges();
59
+ }
60
+ /**
61
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
62
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
63
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
64
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
65
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
66
+ * @param sql The SQLite SQL statement to execute
67
+ * @param callback the callback to invoke on the prepared statement
68
+ * @returns the value returned by `callback`.
69
+ * @see [[withPreparedStatement]]
70
+ * @public
71
+ */
72
+ withPreparedSqliteStatement(sql, callback) {
73
+ var _a;
74
+ const stmt = (_a = this._sqliteStatementCache.findAndRemove(sql)) !== null && _a !== void 0 ? _a : this.prepareSqliteStatement(sql);
75
+ const release = () => this._sqliteStatementCache.addOrDispose(stmt);
76
+ try {
77
+ const val = callback(stmt);
78
+ if (val instanceof Promise) {
79
+ val.then(release, release);
80
+ }
81
+ else {
82
+ release();
83
+ }
84
+ return val;
85
+ }
86
+ catch (err) {
87
+ release();
88
+ throw err;
89
+ }
90
+ }
91
+ /**
92
+ * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
93
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
94
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
95
+ * @param sql The SQLite SQL statement to execute
96
+ * @param callback the callback to invoke on the prepared statement
97
+ * @returns the value returned by `callback`.
98
+ * @public
99
+ */
100
+ withSqliteStatement(sql, callback) {
101
+ const stmt = this.prepareSqliteStatement(sql);
102
+ const release = () => stmt.dispose();
103
+ try {
104
+ const val = callback(stmt);
105
+ if (val instanceof Promise) {
106
+ val.then(release, release);
107
+ }
108
+ else {
109
+ release();
110
+ }
111
+ return val;
112
+ }
113
+ catch (err) {
114
+ release();
115
+ throw err;
116
+ }
117
+ }
118
+ /** Prepare an SQL statement.
119
+ * @param sql The SQLite SQL statement to prepare
120
+ * @param logErrors Determine if errors are logged or not
121
+ * @internal
122
+ */
123
+ prepareSqliteStatement(sql, logErrors = true) {
124
+ const stmt = new SqliteStatement_1.SqliteStatement(sql);
125
+ stmt.prepare(this.nativeDb, logErrors);
126
+ return stmt;
127
+ }
128
+ /** execute an SQL statement */
129
+ executeSQL(sql) {
130
+ const stmt = this.prepareSqliteStatement(sql);
131
+ try {
132
+ return stmt.step();
133
+ }
134
+ finally {
135
+ stmt.dispose();
136
+ }
137
+ }
138
+ }
139
+ exports.SQLiteDb = SQLiteDb;
140
+ //# sourceMappingURL=SQLiteDb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":"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","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 { DbResult, IDisposable, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n/** A SQLiteDb file\r\n * @public\r\n */\r\nexport class SQLiteDb implements IDisposable {\r\n private _nativeDb?: IModelJsNative.SQLiteDb;\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public get nativeDb(): IModelJsNative.SQLiteDb {\r\n return this._nativeDb!;\r\n }\r\n\r\n constructor() {\r\n this._nativeDb = new IModelHost.platform.SQLiteDb();\r\n }\r\n /** Call this function when finished with this SQLiteDb. This releases the native resources */\r\n public dispose(): void {\r\n if (!this._nativeDb)\r\n return;\r\n\r\n this.closeDb();\r\n this._nativeDb.dispose();\r\n this._nativeDb = undefined;\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param pathName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(pathName: string): void {\r\n this.nativeDb.createDb(pathName);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param pathName The path to the SQLiteDb file to open\r\n */\r\n public openDb(pathName: string, openMode: OpenMode): void {\r\n this.nativeDb.openDb(pathName, openMode);\r\n }\r\n\r\n /** Returns true if the SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /** Close SQLiteDb. */\r\n public closeDb(): void {\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the 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 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 * @see [[withPreparedStatement]]\r\n * @public\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: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\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 * Prepared 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 * @public\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: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\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"]}
@@ -0,0 +1,56 @@
1
+ /** @packageDocumentation
2
+ * @module Schema
3
+ */
4
+ /** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).
5
+ * @public
6
+ */
7
+ export declare class Schema {
8
+ /** The name of the BIS schema handled by this Schema.
9
+ * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.
10
+ * Failure to do so will ordinarily result in an error when the schema is registered, since there may only
11
+ * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)
12
+ */
13
+ static get schemaName(): string;
14
+ /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.
15
+ * Classes generated for this Schema will disallow protected operations.
16
+ * @internal
17
+ */
18
+ static get missingRequiredBehavior(): boolean;
19
+ /** Get a semver-compatible string from a padded version string.
20
+ * works on unpadded version strings as well
21
+ * if there is no write version, it will be added
22
+ * @example Schema.toSemverString("1.02.03") === "1.2.3"
23
+ * @example Schema.toSemverString("1.01") === "1.0.1" // write version was added
24
+ * @beta
25
+ */
26
+ static toSemverString(paddedVersion: string): string;
27
+ /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an
28
+ * error if it is ever called.
29
+ * @internal
30
+ */
31
+ protected constructor();
32
+ }
33
+ /** Manages registered schemas
34
+ * @public
35
+ */
36
+ export declare class Schemas {
37
+ private static readonly _registeredSchemas;
38
+ private constructor();
39
+ /** Register a schema prior to using it.
40
+ * @throws [[IModelError]] if a schema of the same name is already registered.
41
+ */
42
+ static registerSchema(schema: typeof Schema): void;
43
+ /** Unregister a schema, by name, if one is already registered.
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
+ * @param schemaName Name of the schema to unregister
46
+ * @return true if the schema was unregistered
47
+ * @internal
48
+ */
49
+ static unregisterSchema(schemaName: string): boolean;
50
+ /** Look up a previously registered schema
51
+ * @param schemaName The name of the schema
52
+ * @returns the previously registered schema or undefined if not registered.
53
+ */
54
+ static getRegisteredSchema(schemaName: string): typeof Schema | undefined;
55
+ }
56
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,84 @@
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.Schemas = exports.Schema = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const ClassRegistry_1 = require("./ClassRegistry");
14
+ /** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).
15
+ * @public
16
+ */
17
+ class Schema {
18
+ /** The name of the BIS schema handled by this Schema.
19
+ * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.
20
+ * Failure to do so will ordinarily result in an error when the schema is registered, since there may only
21
+ * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)
22
+ */
23
+ static get schemaName() { throw new Error(`you must override static schemaName in ${this.name}`); }
24
+ /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.
25
+ * Classes generated for this Schema will disallow protected operations.
26
+ * @internal
27
+ */
28
+ static get missingRequiredBehavior() { return false; }
29
+ /** Get a semver-compatible string from a padded version string.
30
+ * works on unpadded version strings as well
31
+ * if there is no write version, it will be added
32
+ * @example Schema.toSemverString("1.02.03") === "1.2.3"
33
+ * @example Schema.toSemverString("1.01") === "1.0.1" // write version was added
34
+ * @beta
35
+ */
36
+ static toSemverString(paddedVersion) {
37
+ const tuple = paddedVersion.split(".").map(Number);
38
+ const noWriteVersion = tuple.length === 2;
39
+ if (noWriteVersion)
40
+ tuple.splice(1, 0, 0); // insert 0 before the second element
41
+ return tuple.join(".");
42
+ }
43
+ /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an
44
+ * error if it is ever called.
45
+ * @internal
46
+ */
47
+ constructor() { throw new Error(`cannot create an instance of a Schema ${this.constructor.name}`); }
48
+ }
49
+ exports.Schema = Schema;
50
+ /** Manages registered schemas
51
+ * @public
52
+ */
53
+ class Schemas {
54
+ constructor() { } // this is a singleton
55
+ /** Register a schema prior to using it.
56
+ * @throws [[IModelError]] if a schema of the same name is already registered.
57
+ */
58
+ static registerSchema(schema) {
59
+ const key = schema.schemaName.toLowerCase();
60
+ if (this.getRegisteredSchema(key))
61
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.DuplicateName, `Schema "${schema.schemaName}" is already registered`);
62
+ this._registeredSchemas.set(key, schema);
63
+ }
64
+ /** Unregister a schema, by name, if one is already registered.
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
+ * @param schemaName Name of the schema to unregister
67
+ * @return true if the schema was unregistered
68
+ * @internal
69
+ */
70
+ static unregisterSchema(schemaName) {
71
+ const schema = this.getRegisteredSchema(schemaName);
72
+ if (undefined !== schema)
73
+ ClassRegistry_1.ClassRegistry.unregisterClassesFrom(schema);
74
+ return this._registeredSchemas.delete(schemaName.toLowerCase());
75
+ }
76
+ /** Look up a previously registered schema
77
+ * @param schemaName The name of the schema
78
+ * @returns the previously registered schema or undefined if not registered.
79
+ */
80
+ static getRegisteredSchema(schemaName) { return this._registeredSchemas.get(schemaName.toLowerCase()); }
81
+ }
82
+ exports.Schemas = Schemas;
83
+ Schemas._registeredSchemas = new Map();
84
+ //# sourceMappingURL=Schema.js.map
@@ -0,0 +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;;AAhCpJ,0BAiCC;AAhCyB,0BAAkB,GAAG,IAAI,GAAG,EAAyB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Schema\r\n */\r\n\r\nimport { 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"]}
@@ -0,0 +1,64 @@
1
+ /** @packageDocumentation
2
+ * @module iModels
3
+ */
4
+ import { Id64Arg, Id64String } from "@itwin/core-bentley";
5
+ import { LockState } from "./BackendHubAccess";
6
+ import { BriefcaseDb, LockControl } from "./IModelDb";
7
+ import { SQLiteDb } from "./SQLiteDb";
8
+ /**
9
+ * Both the Model and Parent of an element are considered "owners" of their member elements. That means:
10
+ * 1) they must hold at least a shared lock before an exclusive lock can be acquired for their members
11
+ * 2) if they hold an exclusive lock, then all of their members are exclusively locked implicitly.
12
+ * @internal
13
+ */
14
+ export interface ElementOwners {
15
+ readonly modelId: Id64String;
16
+ readonly parentId: Id64String | undefined;
17
+ }
18
+ /** @internal */
19
+ export declare class ServerBasedLocks implements LockControl {
20
+ get isServerBased(): boolean;
21
+ protected readonly lockDb: SQLiteDb;
22
+ protected readonly briefcase: BriefcaseDb;
23
+ constructor(iModel: BriefcaseDb);
24
+ close(): void;
25
+ private getOwners;
26
+ private getLockState;
27
+ /** Clear the cache of locally held locks.
28
+ * Note: does *not* release locks from server.
29
+ */
30
+ private clearAllLocks;
31
+ /** only for tests */
32
+ getLockCount(state: LockState): number;
33
+ releaseAllLocks(): Promise<void>;
34
+ private insertLock;
35
+ private ownerHoldsExclusiveLock;
36
+ /** Determine whether an the exclusive lock is already held by an element (or one of its owners) */
37
+ holdsExclusiveLock(id: Id64String): boolean;
38
+ holdsSharedLock(id: Id64String): boolean;
39
+ /** if the shared lock on the element supplied is not already held, add it to the set of shared locks required. Then, check owners. */
40
+ private addSharedLock;
41
+ /** add owners (recursively) of an element to a list of required shared locks, if not already held. */
42
+ private addOwnerSharedLocks;
43
+ /** attempt to acquire all necessary locks for a set of elements */
44
+ private acquireAllLocks;
45
+ /**
46
+ * Acquire the exclusive lock on one or more elements. This also attempts to acquire a shared lock on all of the element's owners, recursively.
47
+ * If *any* lock cannot be obtained, no locks are acquired.
48
+ */
49
+ acquireExclusiveLock(ids: Id64Arg): Promise<void>;
50
+ /**
51
+ * Acquire a shared lock on one or more elements. This also attempts to acquire a shared lock on all of the element's owners, recursively.
52
+ * If *any* lock cannot be obtained, no locks are acquired.
53
+ */
54
+ acquireSharedLock(ids: Id64Arg): Promise<void>;
55
+ /** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */
56
+ elementWasCreated(id: Id64String): void;
57
+ /** locks are not necessary during change propagation. */
58
+ private get _locksAreRequired();
59
+ /** throw if locks are currently required and the exclusive lock is not held on the supplied element */
60
+ checkExclusiveLock(id: Id64String, type: string, operation: string): void;
61
+ /** throw if locks are currently required and a shared lock is not held on the supplied element */
62
+ checkSharedLock(id: Id64String, type: string, operation: string): void;
63
+ }
64
+ //# sourceMappingURL=ServerBasedLocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerBasedLocks.d.ts","sourceRoot":"","sources":["../../src/ServerBasedLocks.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAkB,OAAO,EAAE,UAAU,EAA0B,MAAM,qBAAqB,CAAC;AAElG,OAAO,EAAW,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,SAAS,CAAC;CAC3C;AASD,gBAAgB;AAChB,qBAAa,gBAAiB,YAAW,WAAW;IAClD,IAAW,aAAa,YAAmB;IAC3C,SAAS,CAAC,QAAQ,CAAC,MAAM,WAAkB;IAC3C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;gBAEvB,MAAM,EAAE,WAAW;IAY/B,KAAK;IAKZ,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAKrB,qBAAqB;IACd,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAQhC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7C,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,uBAAuB;IAgB/B,mGAAmG;IAC5F,kBAAkB,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO;IAK3C,eAAe,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO;IAM/C,sIAAsI;IACtI,OAAO,CAAC,aAAa;IAUrB,sGAAsG;IACtG,OAAO,CAAC,mBAAmB;IAM3B,mEAAmE;YACrD,eAAe;IAmB7B;;;OAGG;IACU,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9D;;;OAGG;IACU,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAS3D,wGAAwG;IACjG,iBAAiB,CAAC,EAAE,EAAE,UAAU;IAKvC,yDAAyD;IACzD,OAAO,KAAK,iBAAiB,GAAqD;IAElF,uGAAuG;IAChG,kBAAkB,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKzE,kGAAkG;IAC3F,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAKvE"}
@@ -0,0 +1,177 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ServerBasedLocks = void 0;
8
+ /** @packageDocumentation
9
+ * @module iModels
10
+ */
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const BackendHubAccess_1 = require("./BackendHubAccess");
14
+ const IModelHost_1 = require("./IModelHost");
15
+ const SQLiteDb_1 = require("./SQLiteDb");
16
+ /** @internal */
17
+ class ServerBasedLocks {
18
+ constructor(iModel) {
19
+ this.lockDb = new SQLiteDb_1.SQLiteDb();
20
+ this.briefcase = iModel;
21
+ const dbName = `${iModel.nativeDb.getTempFileBaseName()}-locks`;
22
+ try {
23
+ this.lockDb.openDb(dbName, core_bentley_1.OpenMode.ReadWrite);
24
+ }
25
+ catch (_e) {
26
+ this.lockDb.createDb(dbName);
27
+ this.lockDb.executeSQL("CREATE TABLE locks(id INTEGER PRIMARY KEY NOT NULL,state INTEGER NOT NULL,origin INTEGER)");
28
+ this.lockDb.saveChanges();
29
+ }
30
+ }
31
+ get isServerBased() { return true; }
32
+ close() {
33
+ if (this.lockDb.isOpen)
34
+ this.lockDb.closeDb();
35
+ }
36
+ getOwners(id) {
37
+ return this.briefcase.withPreparedSqliteStatement("SELECT ModelId,ParentId FROM bis_Element WHERE id=?", (stmt) => {
38
+ stmt.bindId(1, id);
39
+ const rc = stmt.step();
40
+ if (core_bentley_1.DbResult.BE_SQLITE_ROW !== rc)
41
+ throw new core_common_1.IModelError(rc, `element ${id} not found`);
42
+ return { modelId: stmt.getValueId(0), parentId: stmt.getValueId(1) };
43
+ });
44
+ }
45
+ getLockState(id) {
46
+ return (id === undefined || !core_bentley_1.Id64.isValid(id)) ? undefined : this.lockDb.withPreparedSqliteStatement("SELECT state FROM locks WHERE id=?", (stmt) => {
47
+ stmt.bindId(1, id);
48
+ return (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step()) ? stmt.getValueInteger(0) : undefined;
49
+ });
50
+ }
51
+ /** Clear the cache of locally held locks.
52
+ * Note: does *not* release locks from server.
53
+ */
54
+ clearAllLocks() {
55
+ this.lockDb.executeSQL("DELETE FROM locks");
56
+ this.lockDb.saveChanges();
57
+ }
58
+ /** only for tests */
59
+ getLockCount(state) {
60
+ return this.lockDb.withSqliteStatement("SELECT count(*) FROM locks WHERE state=?", (stmt) => {
61
+ stmt.bindInteger(1, state);
62
+ stmt.step();
63
+ return stmt.getValueInteger(0);
64
+ });
65
+ }
66
+ async releaseAllLocks() {
67
+ await IModelHost_1.IModelHost.hubAccess.releaseAllLocks(this.briefcase); // throws if unsuccessful
68
+ this.clearAllLocks();
69
+ }
70
+ insertLock(id, state, origin) {
71
+ this.lockDb.withPreparedSqliteStatement("INSERT INTO locks(id,state,origin) VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET state=excluded.state,origin=excluded.origin", (stmt) => {
72
+ stmt.bindId(1, id);
73
+ stmt.bindInteger(2, state);
74
+ stmt.bindInteger(3, origin);
75
+ const rc = stmt.step();
76
+ if (core_bentley_1.DbResult.BE_SQLITE_DONE !== rc)
77
+ throw new core_common_1.IModelError(rc, "can't insert lock into database");
78
+ });
79
+ return true;
80
+ }
81
+ ownerHoldsExclusiveLock(id) {
82
+ if (id === undefined || id === core_common_1.IModel.rootSubjectId)
83
+ return false; // has no owners
84
+ const { modelId, parentId } = this.getOwners(id);
85
+ if (this.getLockState(modelId) === BackendHubAccess_1.LockState.Exclusive || this.getLockState(parentId) === BackendHubAccess_1.LockState.Exclusive)
86
+ return true;
87
+ // see if this model is exclusively locked by one of its owners. If so, save that fact on modelId so future tests won't have to descend.
88
+ if (this.ownerHoldsExclusiveLock(modelId))
89
+ return this.insertLock(modelId, BackendHubAccess_1.LockState.Exclusive, 2 /* Discovered */);
90
+ // see if the parent is exclusively locked by one of its owners. If so, save that fact on parentId so future tests won't have to descend.
91
+ return this.ownerHoldsExclusiveLock(parentId) ? this.insertLock(parentId, BackendHubAccess_1.LockState.Exclusive, 2 /* Discovered */) : false;
92
+ }
93
+ /** Determine whether an the exclusive lock is already held by an element (or one of its owners) */
94
+ holdsExclusiveLock(id) {
95
+ // see if we hold the exclusive lock. or if one of the element's owners is exclusively locked (recursively)
96
+ return this.getLockState(id) === BackendHubAccess_1.LockState.Exclusive || this.ownerHoldsExclusiveLock(id);
97
+ }
98
+ holdsSharedLock(id) {
99
+ const state = this.getLockState(id);
100
+ // see if we hold shared or exclusive lock, or if an owner has exclusive lock. If so we implicitly have shared lock, but owner holding shared lock doesn't help.
101
+ return (state === BackendHubAccess_1.LockState.Shared || state === BackendHubAccess_1.LockState.Exclusive) || this.ownerHoldsExclusiveLock(id);
102
+ }
103
+ /** if the shared lock on the element supplied is not already held, add it to the set of shared locks required. Then, check owners. */
104
+ addSharedLock(id, locks) {
105
+ // if the id is not valid, or of the lock is already in the set, or if we already hold a shared lock, we're done
106
+ // Note: if we hold a shared lock, it is guaranteed that we also hold all required shared locks on owners.
107
+ if (id === undefined || !core_bentley_1.Id64.isValid(id) || locks.has(id) || this.holdsSharedLock(id))
108
+ return;
109
+ locks.add(id); // add to set of needed shared locks
110
+ this.addOwnerSharedLocks(id, locks); // check parent models and groups
111
+ }
112
+ /** add owners (recursively) of an element to a list of required shared locks, if not already held. */
113
+ addOwnerSharedLocks(id, locks) {
114
+ const el = this.getOwners(id);
115
+ this.addSharedLock(el.parentId, locks); // if this element is in a group
116
+ this.addSharedLock(el.modelId, locks); // check its model
117
+ }
118
+ /** attempt to acquire all necessary locks for a set of elements */
119
+ async acquireAllLocks(locks) {
120
+ if (locks.size === 0) // no locks are required.
121
+ return;
122
+ const sharedLocks = new Set();
123
+ for (const lock of locks)
124
+ this.addOwnerSharedLocks(lock[0], sharedLocks);
125
+ for (const shared of sharedLocks) {
126
+ if (!locks.has(shared)) // we may already be asking for exclusive lock
127
+ locks.set(shared, BackendHubAccess_1.LockState.Shared);
128
+ }
129
+ await IModelHost_1.IModelHost.hubAccess.acquireLocks(this.briefcase, locks); // throws if unsuccessful
130
+ for (const lock of locks)
131
+ this.insertLock(lock[0], lock[1], 0 /* Acquired */);
132
+ this.lockDb.saveChanges();
133
+ }
134
+ /**
135
+ * Acquire the exclusive lock on one or more elements. This also attempts to acquire a shared lock on all of the element's owners, recursively.
136
+ * If *any* lock cannot be obtained, no locks are acquired.
137
+ */
138
+ async acquireExclusiveLock(ids) {
139
+ const locks = new Map();
140
+ for (const id of core_bentley_1.Id64.iterable(ids)) {
141
+ if (!this.holdsExclusiveLock(id))
142
+ locks.set(id, BackendHubAccess_1.LockState.Exclusive);
143
+ }
144
+ return this.acquireAllLocks(locks);
145
+ }
146
+ /**
147
+ * Acquire a shared lock on one or more elements. This also attempts to acquire a shared lock on all of the element's owners, recursively.
148
+ * If *any* lock cannot be obtained, no locks are acquired.
149
+ */
150
+ async acquireSharedLock(ids) {
151
+ const locks = new Map();
152
+ for (const id of core_bentley_1.Id64.iterable(ids)) {
153
+ if (!this.holdsSharedLock(id))
154
+ locks.set(id, BackendHubAccess_1.LockState.Shared);
155
+ }
156
+ return this.acquireAllLocks(locks);
157
+ }
158
+ /** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */
159
+ elementWasCreated(id) {
160
+ this.insertLock(id, BackendHubAccess_1.LockState.Exclusive, 1 /* NewElement */);
161
+ this.lockDb.saveChanges();
162
+ }
163
+ /** locks are not necessary during change propagation. */
164
+ get _locksAreRequired() { return !this.briefcase.txns.isIndirectChanges; }
165
+ /** throw if locks are currently required and the exclusive lock is not held on the supplied element */
166
+ checkExclusiveLock(id, type, operation) {
167
+ if (this._locksAreRequired && !this.holdsExclusiveLock(id))
168
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.LockNotHeld, `exclusive lock not held on ${type} for ${operation} (id=${id})`);
169
+ }
170
+ /** throw if locks are currently required and a shared lock is not held on the supplied element */
171
+ checkSharedLock(id, type, operation) {
172
+ if (this._locksAreRequired && !this.holdsSharedLock(id))
173
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.LockNotHeld, `shared lock not held on ${type} for ${operation} (id=${id})`);
174
+ }
175
+ }
176
+ exports.ServerBasedLocks = ServerBasedLocks;
177
+ //# sourceMappingURL=ServerBasedLocks.js.map