@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,61 @@
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.BisCoreSchema = void 0;
11
+ const path = require("path");
12
+ const categoryMod = require("./Category");
13
+ const ClassRegistry_1 = require("./ClassRegistry");
14
+ const elementMod = require("./Element");
15
+ const aspectMod = require("./ElementAspect");
16
+ const externalSourceMod = require("./ExternalSource");
17
+ const IModelHost_1 = require("./IModelHost");
18
+ const materialMod = require("./Material");
19
+ const modelMod = require("./Model");
20
+ const linkMod = require("./Relationship");
21
+ const Schema_1 = require("./Schema");
22
+ const textureMod = require("./Texture");
23
+ const viewMod = require("./ViewDefinition");
24
+ const displayStyleMod = require("./DisplayStyle");
25
+ /**
26
+ * The [BisCore]($docs/bis/intro/schemas-domains.md) schema is the lowest level Schema in an iModel.
27
+ *
28
+ * It is automatically registered when [[IModelHost.startup]] is called.
29
+ *
30
+ * ** Example:**
31
+ * ``` ts
32
+ * [[include:BisCore.registerSchemaAndGetClass]]
33
+ * ```
34
+ * @public
35
+ */
36
+ class BisCoreSchema extends Schema_1.Schema {
37
+ static get schemaName() { return "BisCore"; }
38
+ static get schemaFilePath() { return path.join(IModelHost_1.KnownLocations.nativeAssetsDir, "ECSchemas", "Dgn", `${BisCoreSchema.schemaName}.ecschema.xml`); }
39
+ /** @internal */
40
+ static registerSchema() {
41
+ if (this === Schema_1.Schemas.getRegisteredSchema(this.schemaName))
42
+ return;
43
+ Schema_1.Schemas.unregisterSchema(this.schemaName);
44
+ Schema_1.Schemas.registerSchema(this);
45
+ // this list should include all backend .ts files with implementations of Entity-based classes. Order does not matter.
46
+ [
47
+ elementMod,
48
+ aspectMod,
49
+ modelMod,
50
+ categoryMod,
51
+ viewMod,
52
+ linkMod,
53
+ textureMod,
54
+ materialMod,
55
+ externalSourceMod,
56
+ displayStyleMod,
57
+ ].forEach((module) => ClassRegistry_1.ClassRegistry.registerModule(module, this));
58
+ }
59
+ }
60
+ exports.BisCoreSchema = BisCoreSchema;
61
+ //# sourceMappingURL=BisCoreSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BisCoreSchema.js","sourceRoot":"","sources":["../../src/BisCoreSchema.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,6BAA6B;AAC7B,0CAA0C;AAC1C,mDAAgD;AAChD,wCAAwC;AACxC,6CAA6C;AAC7C,sDAAsD;AACtD,6CAA8C;AAC9C,0CAA0C;AAC1C,oCAAoC;AACpC,0CAA0C;AAC1C,qCAA2C;AAC3C,wCAAwC;AACxC,4CAA4C;AAC5C,kDAAkD;AAElD;;;;;;;;;;GAUG;AACH,MAAa,aAAc,SAAQ,eAAM;IAChC,MAAM,KAAc,UAAU,KAAa,OAAO,SAAS,CAAC,CAAC,CAAC;IAC9D,MAAM,KAAK,cAAc,KAAa,OAAO,IAAI,CAAC,IAAI,CAAC,2BAAc,CAAC,eAAe,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,UAAU,eAAe,CAAC,CAAC,CAAC,CAAC;IAEhK,gBAAgB;IACT,MAAM,CAAC,cAAc;QAC1B,IAAI,IAAI,KAAK,gBAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC;YACvD,OAAO;QAET,gBAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1C,gBAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE7B,sHAAsH;QACtH;YACE,UAAU;YACV,SAAS;YACT,QAAQ;YACR,WAAW;YACX,OAAO;YACP,OAAO;YACP,UAAU;YACV,WAAW;YACX,iBAAiB;YACjB,eAAe;SAChB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,6BAAa,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;CACF;AA1BD,sCA0BC","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 * as path from \"path\";\r\nimport * as categoryMod from \"./Category\";\r\nimport { ClassRegistry } from \"./ClassRegistry\";\r\nimport * as elementMod from \"./Element\";\r\nimport * as aspectMod from \"./ElementAspect\";\r\nimport * as externalSourceMod from \"./ExternalSource\";\r\nimport { KnownLocations } from \"./IModelHost\";\r\nimport * as materialMod from \"./Material\";\r\nimport * as modelMod from \"./Model\";\r\nimport * as linkMod from \"./Relationship\";\r\nimport { Schema, Schemas } from \"./Schema\";\r\nimport * as textureMod from \"./Texture\";\r\nimport * as viewMod from \"./ViewDefinition\";\r\nimport * as displayStyleMod from \"./DisplayStyle\";\r\n\r\n/**\r\n * The [BisCore]($docs/bis/intro/schemas-domains.md) schema is the lowest level Schema in an iModel.\r\n *\r\n * It is automatically registered when [[IModelHost.startup]] is called.\r\n *\r\n * ** Example:**\r\n * ``` ts\r\n * [[include:BisCore.registerSchemaAndGetClass]]\r\n * ```\r\n * @public\r\n */\r\nexport class BisCoreSchema extends Schema {\r\n public static override get schemaName(): string { return \"BisCore\"; }\r\n public static get schemaFilePath(): string { return path.join(KnownLocations.nativeAssetsDir, \"ECSchemas\", \"Dgn\", `${BisCoreSchema.schemaName}.ecschema.xml`); }\r\n\r\n /** @internal */\r\n public static registerSchema() {\r\n if (this === Schemas.getRegisteredSchema(this.schemaName))\r\n return;\r\n\r\n Schemas.unregisterSchema(this.schemaName);\r\n Schemas.registerSchema(this);\r\n\r\n // this list should include all backend .ts files with implementations of Entity-based classes. Order does not matter.\r\n [\r\n elementMod,\r\n aspectMod,\r\n modelMod,\r\n categoryMod,\r\n viewMod,\r\n linkMod,\r\n textureMod,\r\n materialMod,\r\n externalSourceMod,\r\n displayStyleMod,\r\n ].forEach((module) => ClassRegistry.registerModule(module, this));\r\n }\r\n}\r\n"]}
@@ -0,0 +1,167 @@
1
+ /** @packageDocumentation
2
+ * @module iModels
3
+ */
4
+ import { AccessToken, BeDuration, GuidString } from "@itwin/core-bentley";
5
+ import { BriefcaseId, BriefcaseProps, ChangesetIndex, LocalBriefcaseProps, LocalDirName, LocalFileName, RequestNewBriefcaseProps, RpcActivity } from "@itwin/core-common";
6
+ import { AcquireNewBriefcaseIdArg } from "./BackendHubAccess";
7
+ import { ProgressFunction } from "./CheckpointManager";
8
+ import { BriefcaseDb, IModelDb, TokenArg } from "./IModelDb";
9
+ /** The argument for [[BriefcaseManager.downloadBriefcase]]
10
+ * @public
11
+ */
12
+ export interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {
13
+ /** If present, a function called periodically during the download to indicate progress.
14
+ * @note return non-zero from this function to abort the download.
15
+ */
16
+ onProgress?: ProgressFunction;
17
+ }
18
+ /**
19
+ * Parameters for pushing changesets to iModelHub
20
+ * @public
21
+ */
22
+ export interface PushChangesArgs extends TokenArg {
23
+ /** A description of the changes. This is visible on the iModel's timeline. */
24
+ description: string;
25
+ /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */
26
+ retainLocks?: true;
27
+ /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */
28
+ mergeRetryCount?: number;
29
+ /** delay to wait between pull/merge retry attempts. Default is 3 seconds */
30
+ mergeRetryDelay?: BeDuration;
31
+ /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */
32
+ pushRetryCount?: number;
33
+ /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */
34
+ pushRetryDelay?: BeDuration;
35
+ }
36
+ /**
37
+ * Specifies a specific index for pulling changes.
38
+ * @public
39
+ */
40
+ export interface ToChangesetArgs extends TokenArg {
41
+ /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */
42
+ toIndex?: ChangesetIndex;
43
+ }
44
+ /** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]
45
+ * @public
46
+ */
47
+ export declare type PullChangesArgs = ToChangesetArgs;
48
+ /** Manages downloading Briefcases and downloading and uploading changesets.
49
+ * @public
50
+ */
51
+ export declare class BriefcaseManager {
52
+ /** Get the local path of the folder storing files that are associated with an imodel */
53
+ static getIModelPath(iModelId: GuidString): LocalDirName;
54
+ /** @internal */
55
+ static getChangeSetsPath(iModelId: GuidString): LocalDirName;
56
+ /** @internal */
57
+ static getChangeCachePathName(iModelId: GuidString): LocalFileName;
58
+ /** @internal */
59
+ static getChangedElementsPathName(iModelId: GuidString): LocalFileName;
60
+ private static _briefcaseSubDir;
61
+ /** @internal */
62
+ static getBriefcaseBasePath(iModelId: GuidString): LocalDirName;
63
+ /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.
64
+ * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].
65
+ * @param briefcase the iModelId and BriefcaseId for the filename
66
+ * @see getIModelPath
67
+ */
68
+ static getFileName(briefcase: BriefcaseProps): LocalFileName;
69
+ private static setupCacheDir;
70
+ private static _initialized?;
71
+ /** Initialize BriefcaseManager
72
+ * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.
73
+ * Briefcases are stored relative to this path in sub-folders organized by IModelId.
74
+ * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.
75
+ */
76
+ static initialize(cacheRootDir: LocalDirName): void;
77
+ private static finalize;
78
+ /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId
79
+ * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all
80
+ * iModels in the briefcase cache are returned.
81
+ * @note usually there should only be one briefcase per iModel.
82
+ */
83
+ static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[];
84
+ private static _cacheDir;
85
+ /** Get the root directory for the briefcase cache */
86
+ static get cacheDir(): LocalDirName;
87
+ /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub
88
+ * @note this does check whether the id was actually acquired by the caller.
89
+ */
90
+ static isValidBriefcaseId(id: BriefcaseId): boolean;
91
+ /** Acquire a new briefcaseId from iModelHub for the supplied iModelId
92
+ * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,
93
+ * it's a good idea to supply different aliases for each of them.
94
+ */
95
+ static acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId>;
96
+ /** Download a new briefcase from iModelHub for the supplied iModelId.
97
+ *
98
+ * The process of downloading a briefcase file involves first obtaining a valid BriefcaseId from IModelHub. For each IModel, IModelHub maintains
99
+ * a list of BriefcaseIds assigned to users, to ensure that no two users have the same BriefcaseId. Typically a given user will have only
100
+ * one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one briefcase to make isolated independent sets of changes,
101
+ * but that is exceedingly complicated and rare. If no BriefcaseId is supplied, a new one is acquired from iModelHub.
102
+ *
103
+ * Then, a Checkpoint file (as of a ChangeSetId, typically "Latest") is downloaded from IModelHub. After the download completes,
104
+ * the briefcaseId in the local file is changed to acquired briefcaseId, changing the checkpoint file into a briefcase file.
105
+ *
106
+ * Each of these steps requires a valid `AuthorizedClientRequestContext` to provide the user's credentials for the requests.
107
+ *
108
+ * @param request The properties that specify the briefcase file to be downloaded.
109
+ * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).
110
+ * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply
111
+ * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named
112
+ * for the IModelId.
113
+ * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)
114
+ * @note The special briefcaseId [[BriefcaseIdValue.Unassigned]] (0) can be used for a local briefcase that can accept changesets but may not be generate changesets.
115
+ * @see CheckpointManager.downloadCheckpoint
116
+ */
117
+ static downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps>;
118
+ /** Deletes change sets of an iModel from local disk
119
+ * @internal
120
+ */
121
+ static deleteChangeSetsFromLocalDisk(iModelId: string): void;
122
+ /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.
123
+ * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].
124
+ * @see deleteBriefcaseFiles
125
+ */
126
+ static releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void>;
127
+ /**
128
+ * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.
129
+ * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and
130
+ * associated files (that is, all files in the same directory that start with the briefcase name).
131
+ * @param filePath the full file name of the Briefcase to delete
132
+ * @param accessToken for releasing the briefcaseId
133
+ */
134
+ static deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void>;
135
+ /** Deletes a file
136
+ * - Does not throw any error, but logs it instead
137
+ * - Returns true if the delete was successful
138
+ */
139
+ private static deleteFile;
140
+ /** Deletes a folder, checking if it's empty
141
+ * - Does not throw any error, but logs it instead
142
+ * - Returns true if the delete was successful
143
+ */
144
+ private static deleteFolderIfEmpty;
145
+ /** Deletes the contents of a folder, but not the folder itself
146
+ * - Does not throw any errors, but logs them.
147
+ * - returns true if the delete was successful.
148
+ */
149
+ private static deleteFolderContents;
150
+ /** Deletes a folder and all it's contents.
151
+ * - Does not throw any errors, but logs them.
152
+ * - returns true if the delete was successful.
153
+ */
154
+ private static deleteFolderAndContents;
155
+ private static applySingleChangeset;
156
+ /** @internal */
157
+ static pullAndApplyChangesets(db: IModelDb, arg: ToChangesetArgs): Promise<void>;
158
+ /** create a changeset from the current changes, and push it to iModelHub */
159
+ private static pushChanges;
160
+ /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]
161
+ * @internal
162
+ */
163
+ static pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void>;
164
+ /** @internal */
165
+ static logUsage(imodel: IModelDb, activity?: RpcActivity): void;
166
+ }
167
+ //# sourceMappingURL=BriefcaseManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BriefcaseManager.d.ts","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,406 @@
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 iModels
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BriefcaseManager = void 0;
11
+ // cspell:ignore cset csets ecchanges
12
+ const path = require("path");
13
+ const core_bentley_1 = require("@itwin/core-bentley");
14
+ const core_common_1 = require("@itwin/core-common");
15
+ const telemetry_client_1 = require("@bentley/telemetry-client");
16
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
17
+ const CheckpointManager_1 = require("./CheckpointManager");
18
+ const IModelDb_1 = require("./IModelDb");
19
+ const IModelHost_1 = require("./IModelHost");
20
+ const IModelJsFs_1 = require("./IModelJsFs");
21
+ const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.IModelDb;
22
+ /** Manages downloading Briefcases and downloading and uploading changesets.
23
+ * @public
24
+ */
25
+ class BriefcaseManager {
26
+ /** Get the local path of the folder storing files that are associated with an imodel */
27
+ static getIModelPath(iModelId) { return path.join(this._cacheDir, iModelId); }
28
+ /** @internal */
29
+ static getChangeSetsPath(iModelId) { return path.join(this.getIModelPath(iModelId), "changesets"); }
30
+ /** @internal */
31
+ static getChangeCachePathName(iModelId) { return path.join(this.getIModelPath(iModelId), iModelId.concat(".bim.ecchanges")); }
32
+ /** @internal */
33
+ static getChangedElementsPathName(iModelId) { return path.join(this.getIModelPath(iModelId), iModelId.concat(".bim.elems")); }
34
+ /** @internal */
35
+ static getBriefcaseBasePath(iModelId) {
36
+ return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);
37
+ }
38
+ /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.
39
+ * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].
40
+ * @param briefcase the iModelId and BriefcaseId for the filename
41
+ * @see getIModelPath
42
+ */
43
+ static getFileName(briefcase) {
44
+ return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);
45
+ }
46
+ static setupCacheDir(cacheRootDir) {
47
+ this._cacheDir = cacheRootDir;
48
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync(this._cacheDir);
49
+ }
50
+ /** Initialize BriefcaseManager
51
+ * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.
52
+ * Briefcases are stored relative to this path in sub-folders organized by IModelId.
53
+ * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.
54
+ */
55
+ static initialize(cacheRootDir) {
56
+ if (this._initialized)
57
+ return;
58
+ this.setupCacheDir(cacheRootDir);
59
+ IModelHost_1.IModelHost.onBeforeShutdown.addOnce(this.finalize, this);
60
+ this._initialized = true;
61
+ }
62
+ static finalize() {
63
+ this._initialized = false;
64
+ }
65
+ /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId
66
+ * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all
67
+ * iModels in the briefcase cache are returned.
68
+ * @note usually there should only be one briefcase per iModel.
69
+ */
70
+ static getCachedBriefcases(iModelId) {
71
+ var _a, _b, _c;
72
+ const briefcaseList = [];
73
+ const iModelDirs = IModelJsFs_1.IModelJsFs.readdirSync(this._cacheDir);
74
+ for (const iModelDir of iModelDirs) {
75
+ if (iModelId && iModelId !== iModelDir)
76
+ continue;
77
+ const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);
78
+ try {
79
+ if (!((_a = IModelJsFs_1.IModelJsFs.lstatSync(bcPath)) === null || _a === void 0 ? void 0 : _a.isDirectory))
80
+ continue;
81
+ }
82
+ catch (err) {
83
+ continue;
84
+ }
85
+ const briefcases = IModelJsFs_1.IModelJsFs.readdirSync(bcPath);
86
+ for (const briefcaseName of briefcases) {
87
+ if (briefcaseName.endsWith(".bim")) {
88
+ try {
89
+ const fileName = path.join(bcPath, briefcaseName);
90
+ const fileSize = (_c = (_b = IModelJsFs_1.IModelJsFs.lstatSync(fileName)) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0;
91
+ const db = IModelDb_1.IModelDb.openDgnDb({ path: fileName }, core_bentley_1.OpenMode.Readonly);
92
+ briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });
93
+ db.closeIModel();
94
+ }
95
+ catch (_err) {
96
+ }
97
+ }
98
+ }
99
+ }
100
+ return briefcaseList;
101
+ }
102
+ /** Get the root directory for the briefcase cache */
103
+ static get cacheDir() { return this._cacheDir; }
104
+ /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub
105
+ * @note this does check whether the id was actually acquired by the caller.
106
+ */
107
+ static isValidBriefcaseId(id) {
108
+ return id >= core_common_1.BriefcaseIdValue.FirstValid && id <= core_common_1.BriefcaseIdValue.LastValid;
109
+ }
110
+ /** Acquire a new briefcaseId from iModelHub for the supplied iModelId
111
+ * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,
112
+ * it's a good idea to supply different aliases for each of them.
113
+ */
114
+ static async acquireNewBriefcaseId(arg) {
115
+ return IModelHost_1.IModelHost.hubAccess.acquireNewBriefcaseId(arg);
116
+ }
117
+ /** Download a new briefcase from iModelHub for the supplied iModelId.
118
+ *
119
+ * The process of downloading a briefcase file involves first obtaining a valid BriefcaseId from IModelHub. For each IModel, IModelHub maintains
120
+ * a list of BriefcaseIds assigned to users, to ensure that no two users have the same BriefcaseId. Typically a given user will have only
121
+ * one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one briefcase to make isolated independent sets of changes,
122
+ * but that is exceedingly complicated and rare. If no BriefcaseId is supplied, a new one is acquired from iModelHub.
123
+ *
124
+ * Then, a Checkpoint file (as of a ChangeSetId, typically "Latest") is downloaded from IModelHub. After the download completes,
125
+ * the briefcaseId in the local file is changed to acquired briefcaseId, changing the checkpoint file into a briefcase file.
126
+ *
127
+ * Each of these steps requires a valid `AuthorizedClientRequestContext` to provide the user's credentials for the requests.
128
+ *
129
+ * @param request The properties that specify the briefcase file to be downloaded.
130
+ * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).
131
+ * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply
132
+ * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named
133
+ * for the IModelId.
134
+ * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)
135
+ * @note The special briefcaseId [[BriefcaseIdValue.Unassigned]] (0) can be used for a local briefcase that can accept changesets but may not be generate changesets.
136
+ * @see CheckpointManager.downloadCheckpoint
137
+ */
138
+ static async downloadBriefcase(arg) {
139
+ var _a, _b, _c, _d, _e;
140
+ const briefcaseId = arg.briefcaseId = (_a = arg.briefcaseId) !== null && _a !== void 0 ? _a : await this.acquireNewBriefcaseId(arg);
141
+ const fileName = (_b = arg.fileName) !== null && _b !== void 0 ? _b : this.getFileName(arg);
142
+ if (IModelJsFs_1.IModelJsFs.existsSync(fileName))
143
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.FileAlreadyExists, `Briefcase "${fileName}" already exists`);
144
+ const asOf = (_c = arg.asOf) !== null && _c !== void 0 ? _c : core_common_1.IModelVersion.latest().toJSON();
145
+ const changeset = await IModelHost_1.IModelHost.hubAccess.getChangesetFromVersion({ ...arg, version: core_common_1.IModelVersion.fromJSON(asOf) });
146
+ const checkpoint = { ...arg, changeset };
147
+ await CheckpointManager_1.CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });
148
+ const fileSize = (_e = (_d = IModelJsFs_1.IModelJsFs.lstatSync(fileName)) === null || _d === void 0 ? void 0 : _d.size) !== null && _e !== void 0 ? _e : 0;
149
+ const response = {
150
+ fileName,
151
+ briefcaseId,
152
+ iModelId: arg.iModelId,
153
+ iTwinId: arg.iTwinId,
154
+ changeset: checkpoint.changeset,
155
+ fileSize,
156
+ };
157
+ // now open the downloaded checkpoint and reset its BriefcaseId
158
+ const nativeDb = new IModelHost_1.IModelHost.platform.DgnDb();
159
+ try {
160
+ nativeDb.openIModel(fileName, core_bentley_1.OpenMode.ReadWrite);
161
+ }
162
+ catch (err) {
163
+ throw new core_common_1.IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);
164
+ }
165
+ try {
166
+ nativeDb.resetBriefcaseId(briefcaseId);
167
+ if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)
168
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);
169
+ }
170
+ finally {
171
+ nativeDb.saveChanges();
172
+ nativeDb.closeIModel();
173
+ }
174
+ return response;
175
+ }
176
+ /** Deletes change sets of an iModel from local disk
177
+ * @internal
178
+ */
179
+ static deleteChangeSetsFromLocalDisk(iModelId) {
180
+ const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);
181
+ BriefcaseManager.deleteFolderAndContents(changesetsPath);
182
+ }
183
+ /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.
184
+ * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].
185
+ * @see deleteBriefcaseFiles
186
+ */
187
+ static async releaseBriefcase(accessToken, briefcase) {
188
+ if (this.isValidBriefcaseId(briefcase.briefcaseId))
189
+ return IModelHost_1.IModelHost.hubAccess.releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });
190
+ }
191
+ /**
192
+ * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.
193
+ * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and
194
+ * associated files (that is, all files in the same directory that start with the briefcase name).
195
+ * @param filePath the full file name of the Briefcase to delete
196
+ * @param accessToken for releasing the briefcaseId
197
+ */
198
+ static async deleteBriefcaseFiles(filePath, accessToken) {
199
+ try {
200
+ const db = IModelDb_1.IModelDb.openDgnDb({ path: filePath }, core_bentley_1.OpenMode.Readonly);
201
+ const briefcase = {
202
+ iModelId: db.getIModelId(),
203
+ briefcaseId: db.getBriefcaseId(),
204
+ };
205
+ db.closeIModel();
206
+ if (accessToken) {
207
+ if (this.isValidBriefcaseId(briefcase.briefcaseId)) {
208
+ await BriefcaseManager.releaseBriefcase(accessToken, briefcase);
209
+ }
210
+ }
211
+ }
212
+ catch (error) {
213
+ }
214
+ // first try to delete the briefcase file
215
+ try {
216
+ if (IModelJsFs_1.IModelJsFs.existsSync(filePath))
217
+ IModelJsFs_1.IModelJsFs.unlinkSync(filePath);
218
+ }
219
+ catch (err) {
220
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);
221
+ }
222
+ // next, delete all files that start with the briefcase's filePath (e.g. "a.bim-locks", "a.bim-journal", etc.)
223
+ try {
224
+ const dirName = path.dirname(filePath);
225
+ const fileName = path.basename(filePath);
226
+ const files = IModelJsFs_1.IModelJsFs.readdirSync(dirName);
227
+ for (const file of files) {
228
+ if (file.startsWith(fileName))
229
+ this.deleteFile(path.join(dirName, file)); // don't throw on error
230
+ }
231
+ }
232
+ catch (err) {
233
+ }
234
+ }
235
+ /** Deletes a file
236
+ * - Does not throw any error, but logs it instead
237
+ * - Returns true if the delete was successful
238
+ */
239
+ static deleteFile(pathname) {
240
+ try {
241
+ IModelJsFs_1.IModelJsFs.unlinkSync(pathname);
242
+ }
243
+ catch (error) {
244
+ core_bentley_1.Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);
245
+ return false;
246
+ }
247
+ return true;
248
+ }
249
+ /** Deletes a folder, checking if it's empty
250
+ * - Does not throw any error, but logs it instead
251
+ * - Returns true if the delete was successful
252
+ */
253
+ static deleteFolderIfEmpty(folderPathname) {
254
+ try {
255
+ const files = IModelJsFs_1.IModelJsFs.readdirSync(folderPathname);
256
+ if (files.length > 0)
257
+ return false;
258
+ IModelJsFs_1.IModelJsFs.rmdirSync(folderPathname);
259
+ }
260
+ catch (error) {
261
+ core_bentley_1.Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);
262
+ return false;
263
+ }
264
+ return true;
265
+ }
266
+ /** Deletes the contents of a folder, but not the folder itself
267
+ * - Does not throw any errors, but logs them.
268
+ * - returns true if the delete was successful.
269
+ */
270
+ static deleteFolderContents(folderPathname) {
271
+ if (!IModelJsFs_1.IModelJsFs.existsSync(folderPathname))
272
+ return false;
273
+ let status = true;
274
+ const files = IModelJsFs_1.IModelJsFs.readdirSync(folderPathname);
275
+ for (const file of files) {
276
+ const curPath = path.join(folderPathname, file);
277
+ const locStatus = (IModelJsFs_1.IModelJsFs.lstatSync(curPath).isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);
278
+ if (!locStatus)
279
+ status = false;
280
+ }
281
+ return status;
282
+ }
283
+ /** Deletes a folder and all it's contents.
284
+ * - Does not throw any errors, but logs them.
285
+ * - returns true if the delete was successful.
286
+ */
287
+ static deleteFolderAndContents(folderPathname) {
288
+ if (!IModelJsFs_1.IModelJsFs.existsSync(folderPathname))
289
+ return true;
290
+ let status = false;
291
+ status = BriefcaseManager.deleteFolderContents(folderPathname);
292
+ if (!status)
293
+ return false;
294
+ status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);
295
+ return status;
296
+ }
297
+ static async applySingleChangeset(db, changesetFile) {
298
+ if (changesetFile.changesType === core_common_1.ChangesetType.Schema)
299
+ db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)
300
+ db.nativeDb.applyChangeset(changesetFile);
301
+ db.changeset = db.nativeDb.getCurrentChangeset();
302
+ // we're done with this changeset, delete it
303
+ IModelJsFs_1.IModelJsFs.removeSync(changesetFile.pathname);
304
+ }
305
+ /** @internal */
306
+ static async pullAndApplyChangesets(db, arg) {
307
+ if (!db.isOpen || db.nativeDb.isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true
308
+ throw new core_common_1.IModelError(core_bentley_1.ChangeSetStatus.ApplyError, "Briefcase must be open ReadWrite to process change sets");
309
+ let currentIndex = db.changeset.index;
310
+ if (currentIndex === undefined)
311
+ currentIndex = (await IModelHost_1.IModelHost.hubAccess.queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;
312
+ const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;
313
+ // Download change sets
314
+ const changesets = await IModelHost_1.IModelHost.hubAccess.downloadChangesets({
315
+ accessToken: arg.accessToken,
316
+ iModelId: db.iModelId,
317
+ range: { first: reverse ? arg.toIndex + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex },
318
+ targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),
319
+ });
320
+ if (changesets.length === 0)
321
+ return; // nothing to apply
322
+ if (reverse)
323
+ changesets.reverse();
324
+ for (const changeset of changesets)
325
+ await this.applySingleChangeset(db, changeset);
326
+ // notify listeners
327
+ db.notifyChangesetApplied();
328
+ }
329
+ /** create a changeset from the current changes, and push it to iModelHub */
330
+ static async pushChanges(db, arg) {
331
+ var _a, _b;
332
+ const changesetProps = db.nativeDb.startCreateChangeset();
333
+ changesetProps.briefcaseId = db.briefcaseId;
334
+ changesetProps.description = arg.description;
335
+ changesetProps.size = (_a = IModelJsFs_1.IModelJsFs.lstatSync(changesetProps.pathname)) === null || _a === void 0 ? void 0 : _a.size;
336
+ if (!changesetProps.size) // either undefined or 0 means error
337
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoContent, "error creating changeset");
338
+ let retryCount = (_b = arg.pushRetryCount) !== null && _b !== void 0 ? _b : 3;
339
+ while (true) {
340
+ try {
341
+ const accessToken = await IModelHost_1.IModelHost.getAccessToken();
342
+ const index = await IModelHost_1.IModelHost.hubAccess.pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });
343
+ db.nativeDb.completeCreateChangeset({ index });
344
+ db.changeset = db.nativeDb.getCurrentChangeset();
345
+ if (!arg.retainLocks)
346
+ await db.locks.releaseAllLocks();
347
+ return;
348
+ }
349
+ catch (err) {
350
+ const shouldRetry = () => {
351
+ if (retryCount-- <= 0)
352
+ return false;
353
+ switch (err.errorNumber) {
354
+ case core_bentley_1.IModelHubStatus.AnotherUserPushing:
355
+ case core_bentley_1.IModelHubStatus.DatabaseTemporarilyLocked:
356
+ case core_bentley_1.IModelHubStatus.OperationFailed:
357
+ return true;
358
+ }
359
+ return false;
360
+ };
361
+ if (!shouldRetry()) {
362
+ db.nativeDb.abandonCreateChangeset();
363
+ throw err;
364
+ }
365
+ }
366
+ finally {
367
+ IModelJsFs_1.IModelJsFs.removeSync(changesetProps.pathname);
368
+ }
369
+ }
370
+ }
371
+ /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]
372
+ * @internal
373
+ */
374
+ static async pullMergePush(db, arg) {
375
+ var _a, _b;
376
+ let retryCount = (_a = arg.mergeRetryCount) !== null && _a !== void 0 ? _a : 5;
377
+ while (true) {
378
+ try {
379
+ await BriefcaseManager.pullAndApplyChangesets(db, arg);
380
+ return await BriefcaseManager.pushChanges(db, arg);
381
+ }
382
+ catch (err) {
383
+ if (retryCount-- <= 0 || err.errorNumber !== core_bentley_1.IModelHubStatus.PullIsRequired)
384
+ throw (err);
385
+ await ((_b = arg.mergeRetryDelay) !== null && _b !== void 0 ? _b : core_bentley_1.BeDuration.fromSeconds(3)).wait();
386
+ }
387
+ }
388
+ }
389
+ /** @internal */
390
+ static logUsage(imodel, activity) {
391
+ var _a;
392
+ const telemetryEvent = new telemetry_client_1.TelemetryEvent("core-backend - Open iModel", "7a6424d1-2114-4e89-b13b-43670a38ccd4", // Feature: "iModel Use"
393
+ imodel.iTwinId, imodel.iModelId, (_a = imodel.changeset) === null || _a === void 0 ? void 0 : _a.id);
394
+ activity = activity !== null && activity !== void 0 ? activity : {
395
+ activityId: "",
396
+ applicationId: IModelHost_1.IModelHost.applicationId,
397
+ applicationVersion: IModelHost_1.IModelHost.applicationVersion,
398
+ sessionId: IModelHost_1.IModelHost.sessionId,
399
+ accessToken: "", // IModelHost.getAccessToken(); ACCESS_TOKEN_NEEDS_WORK
400
+ };
401
+ IModelHost_1.IModelHost.telemetry.postTelemetry(activity, telemetryEvent); // eslint-disable-line @typescript-eslint/no-floating-promises
402
+ }
403
+ }
404
+ exports.BriefcaseManager = BriefcaseManager;
405
+ BriefcaseManager._briefcaseSubDir = "briefcases";
406
+ //# sourceMappingURL=BriefcaseManager.js.map