@itwin/core-backend 3.5.0-dev.4 → 3.5.0-dev.43

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 (278) hide show
  1. package/CHANGELOG.md +77 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -23
  3. package/lib/cjs/AliCloudStorageService.js +71 -71
  4. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  5. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  6. package/lib/cjs/BackendHubAccess.js +41 -41
  7. package/lib/cjs/BackendHubAccess.js.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.d.ts +91 -91
  9. package/lib/cjs/BackendLoggerCategory.js +99 -99
  10. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  11. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  12. package/lib/cjs/BisCoreSchema.js +60 -60
  13. package/lib/cjs/BisCoreSchema.js.map +1 -1
  14. package/lib/cjs/BriefcaseManager.d.ts +170 -165
  15. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  16. package/lib/cjs/BriefcaseManager.js +413 -405
  17. package/lib/cjs/BriefcaseManager.js.map +1 -1
  18. package/lib/cjs/Category.d.ts +153 -153
  19. package/lib/cjs/Category.js +243 -243
  20. package/lib/cjs/Category.js.map +1 -1
  21. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  22. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
  23. package/lib/cjs/ChangeSummaryManager.js +447 -445
  24. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  25. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  26. package/lib/cjs/ChangedElementsDb.js +165 -165
  27. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  28. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  29. package/lib/cjs/ChangedElementsManager.js +88 -88
  30. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  31. package/lib/cjs/CheckpointManager.d.ts +120 -120
  32. package/lib/cjs/CheckpointManager.js +343 -343
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/ClassRegistry.d.ts +79 -71
  35. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  36. package/lib/cjs/ClassRegistry.js +249 -215
  37. package/lib/cjs/ClassRegistry.js.map +1 -1
  38. package/lib/cjs/CloudSqlite.d.ts +350 -349
  39. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  40. package/lib/cjs/CloudSqlite.js +152 -151
  41. package/lib/cjs/CloudSqlite.js.map +1 -1
  42. package/lib/cjs/CloudStorageBackend.d.ts +58 -58
  43. package/lib/cjs/CloudStorageBackend.js +173 -173
  44. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  45. package/lib/cjs/CodeService.d.ts +396 -396
  46. package/lib/cjs/CodeService.js +63 -63
  47. package/lib/cjs/CodeService.js.map +1 -1
  48. package/lib/cjs/CodeSpecs.d.ts +50 -50
  49. package/lib/cjs/CodeSpecs.js +112 -112
  50. package/lib/cjs/CodeSpecs.js.map +1 -1
  51. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  52. package/lib/cjs/ConcurrentQuery.js +30 -30
  53. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  54. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -32
  55. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  56. package/lib/cjs/CustomViewState3dCreator.js +81 -113
  57. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  58. package/lib/cjs/DevTools.d.ts +71 -71
  59. package/lib/cjs/DevTools.js +154 -154
  60. package/lib/cjs/DevTools.js.map +1 -1
  61. package/lib/cjs/DisplayStyle.d.ts +106 -106
  62. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  63. package/lib/cjs/DisplayStyle.js +256 -256
  64. package/lib/cjs/DisplayStyle.js.map +1 -1
  65. package/lib/cjs/ECDb.d.ts +191 -191
  66. package/lib/cjs/ECDb.js +350 -350
  67. package/lib/cjs/ECDb.js.map +1 -1
  68. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  69. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  70. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  71. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  72. package/lib/cjs/ECSqlStatement.js +791 -791
  73. package/lib/cjs/ECSqlStatement.js.map +1 -1
  74. package/lib/cjs/Element.d.ts +1102 -1109
  75. package/lib/cjs/Element.d.ts.map +1 -1
  76. package/lib/cjs/Element.js +1416 -1420
  77. package/lib/cjs/Element.js.map +1 -1
  78. package/lib/cjs/ElementAspect.d.ts +176 -156
  79. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  80. package/lib/cjs/ElementAspect.js +211 -178
  81. package/lib/cjs/ElementAspect.js.map +1 -1
  82. package/lib/cjs/ElementGraphics.d.ts +9 -9
  83. package/lib/cjs/ElementGraphics.js +41 -41
  84. package/lib/cjs/ElementGraphics.js.map +1 -1
  85. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  86. package/lib/cjs/ElementTreeWalker.js +409 -409
  87. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  88. package/lib/cjs/Entity.d.ts +106 -76
  89. package/lib/cjs/Entity.d.ts.map +1 -1
  90. package/lib/cjs/Entity.js +134 -82
  91. package/lib/cjs/Entity.js.map +1 -1
  92. package/lib/cjs/EntityReferences.d.ts +50 -0
  93. package/lib/cjs/EntityReferences.d.ts.map +1 -0
  94. package/lib/cjs/EntityReferences.js +96 -0
  95. package/lib/cjs/EntityReferences.js.map +1 -0
  96. package/lib/cjs/ExportGraphics.d.ts +317 -317
  97. package/lib/cjs/ExportGraphics.js +208 -208
  98. package/lib/cjs/ExportGraphics.js.map +1 -1
  99. package/lib/cjs/ExternalSource.d.ts +96 -94
  100. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  101. package/lib/cjs/ExternalSource.js +131 -125
  102. package/lib/cjs/ExternalSource.js.map +1 -1
  103. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  104. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  105. package/lib/cjs/GeoCoordConfig.js +85 -82
  106. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  107. package/lib/cjs/GeometrySummary.d.ts +4 -4
  108. package/lib/cjs/GeometrySummary.js +380 -380
  109. package/lib/cjs/GeometrySummary.js.map +1 -1
  110. package/lib/cjs/HubMock.d.ts +94 -93
  111. package/lib/cjs/HubMock.d.ts.map +1 -1
  112. package/lib/cjs/HubMock.js +222 -190
  113. package/lib/cjs/HubMock.js.map +1 -1
  114. package/lib/cjs/IModelCloneContext.d.ts +8 -85
  115. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  116. package/lib/cjs/IModelCloneContext.js +15 -150
  117. package/lib/cjs/IModelCloneContext.js.map +1 -1
  118. package/lib/cjs/IModelDb.d.ts +1183 -1164
  119. package/lib/cjs/IModelDb.d.ts.map +1 -1
  120. package/lib/cjs/IModelDb.js +2374 -2324
  121. package/lib/cjs/IModelDb.js.map +1 -1
  122. package/lib/cjs/IModelElementCloneContext.d.ts +90 -0
  123. package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -0
  124. package/lib/cjs/IModelElementCloneContext.js +160 -0
  125. package/lib/cjs/IModelElementCloneContext.js.map +1 -0
  126. package/lib/cjs/IModelHost.d.ts +370 -361
  127. package/lib/cjs/IModelHost.d.ts.map +1 -1
  128. package/lib/cjs/IModelHost.js +496 -489
  129. package/lib/cjs/IModelHost.js.map +1 -1
  130. package/lib/cjs/IModelJsFs.d.ts +62 -62
  131. package/lib/cjs/IModelJsFs.js +140 -140
  132. package/lib/cjs/IModelJsFs.js.map +1 -1
  133. package/lib/cjs/IpcHost.d.ts +104 -98
  134. package/lib/cjs/IpcHost.d.ts.map +1 -1
  135. package/lib/cjs/IpcHost.js +278 -234
  136. package/lib/cjs/IpcHost.js.map +1 -1
  137. package/lib/cjs/LineStyle.d.ts +311 -311
  138. package/lib/cjs/LineStyle.js +295 -295
  139. package/lib/cjs/LineStyle.js.map +1 -1
  140. package/lib/cjs/LocalHub.d.ts +162 -162
  141. package/lib/cjs/LocalHub.js +587 -587
  142. package/lib/cjs/LocalHub.js.map +1 -1
  143. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  144. package/lib/cjs/LocalhostIpcHost.js +81 -81
  145. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  146. package/lib/cjs/Material.d.ts +103 -103
  147. package/lib/cjs/Material.js +147 -147
  148. package/lib/cjs/Material.js.map +1 -1
  149. package/lib/cjs/Model.d.ts +392 -386
  150. package/lib/cjs/Model.d.ts.map +1 -1
  151. package/lib/cjs/Model.js +485 -471
  152. package/lib/cjs/Model.js.map +1 -1
  153. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  154. package/lib/cjs/NativeAppStorage.js +202 -202
  155. package/lib/cjs/NativeAppStorage.js.map +1 -1
  156. package/lib/cjs/NativeHost.d.ts +52 -52
  157. package/lib/cjs/NativeHost.d.ts.map +1 -1
  158. package/lib/cjs/NativeHost.js +163 -168
  159. package/lib/cjs/NativeHost.js.map +1 -1
  160. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  161. package/lib/cjs/NavigationRelationship.js +225 -225
  162. package/lib/cjs/NavigationRelationship.js.map +1 -1
  163. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  164. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  165. package/lib/cjs/PromiseMemoizer.js +101 -101
  166. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  167. package/lib/cjs/PropertyStore.d.ts +132 -132
  168. package/lib/cjs/PropertyStore.js +11 -11
  169. package/lib/cjs/PropertyStore.js.map +1 -1
  170. package/lib/cjs/Relationship.d.ts +416 -400
  171. package/lib/cjs/Relationship.d.ts.map +1 -1
  172. package/lib/cjs/Relationship.js +494 -465
  173. package/lib/cjs/Relationship.js.map +1 -1
  174. package/lib/cjs/RpcBackend.d.ts +5 -28
  175. package/lib/cjs/RpcBackend.d.ts.map +1 -1
  176. package/lib/cjs/RpcBackend.js +31 -126
  177. package/lib/cjs/RpcBackend.js.map +1 -1
  178. package/lib/cjs/SQLiteDb.d.ts +219 -219
  179. package/lib/cjs/SQLiteDb.js +214 -214
  180. package/lib/cjs/SQLiteDb.js.map +1 -1
  181. package/lib/cjs/Schema.d.ts +55 -55
  182. package/lib/cjs/Schema.js +83 -83
  183. package/lib/cjs/Schema.js.map +1 -1
  184. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  185. package/lib/cjs/ServerBasedLocks.js +168 -168
  186. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  187. package/lib/cjs/SqliteStatement.d.ts +360 -283
  188. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  189. package/lib/cjs/SqliteStatement.js +586 -448
  190. package/lib/cjs/SqliteStatement.js.map +1 -1
  191. package/lib/cjs/Texture.d.ts +58 -58
  192. package/lib/cjs/Texture.js +82 -82
  193. package/lib/cjs/Texture.js.map +1 -1
  194. package/lib/cjs/TileStorage.d.ts +18 -18
  195. package/lib/cjs/TileStorage.js +90 -90
  196. package/lib/cjs/TileStorage.js.map +1 -1
  197. package/lib/cjs/TxnManager.d.ts +202 -202
  198. package/lib/cjs/TxnManager.js +356 -356
  199. package/lib/cjs/TxnManager.js.map +1 -1
  200. package/lib/cjs/ViewDefinition.d.ts +439 -435
  201. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  202. package/lib/cjs/ViewDefinition.js +646 -635
  203. package/lib/cjs/ViewDefinition.js.map +1 -1
  204. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  205. package/lib/cjs/ViewStateHydrator.js +103 -103
  206. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  207. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  208. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  209. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  210. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  211. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  212. package/lib/cjs/core-backend.d.ts +184 -182
  213. package/lib/cjs/core-backend.d.ts.map +1 -1
  214. package/lib/cjs/core-backend.js +204 -202
  215. package/lib/cjs/core-backend.js.map +1 -1
  216. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  217. package/lib/cjs/domains/FunctionalElements.js +145 -145
  218. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  219. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  220. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  221. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  222. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  223. package/lib/cjs/domains/GenericElements.js +263 -263
  224. package/lib/cjs/domains/GenericElements.js.map +1 -1
  225. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  226. package/lib/cjs/domains/GenericSchema.js +28 -28
  227. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  228. package/lib/cjs/rpc/multipart.d.ts +12 -0
  229. package/lib/cjs/rpc/multipart.d.ts.map +1 -0
  230. package/lib/cjs/rpc/multipart.js +71 -0
  231. package/lib/cjs/rpc/multipart.js.map +1 -0
  232. package/lib/cjs/rpc/tracing.d.ts +29 -0
  233. package/lib/cjs/rpc/tracing.d.ts.map +1 -0
  234. package/lib/cjs/rpc/tracing.js +74 -0
  235. package/lib/cjs/rpc/tracing.js.map +1 -0
  236. package/lib/cjs/rpc/web/logging.d.ts +10 -0
  237. package/lib/cjs/rpc/web/logging.d.ts.map +1 -0
  238. package/lib/cjs/rpc/web/logging.js +43 -0
  239. package/lib/cjs/rpc/web/logging.js.map +1 -0
  240. package/lib/cjs/rpc/web/request.d.ts +7 -0
  241. package/lib/cjs/rpc/web/request.d.ts.map +1 -0
  242. package/lib/cjs/rpc/web/request.js +74 -0
  243. package/lib/cjs/rpc/web/request.js.map +1 -0
  244. package/lib/cjs/rpc/web/response.d.ts +7 -0
  245. package/lib/cjs/rpc/web/response.d.ts.map +1 -0
  246. package/lib/cjs/rpc/web/response.js +106 -0
  247. package/lib/cjs/rpc/web/response.js.map +1 -0
  248. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  249. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  250. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  251. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +46 -45
  252. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  253. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +287 -262
  254. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  255. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -22
  256. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  257. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +202 -204
  258. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  259. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  260. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -168
  261. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  262. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  263. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  264. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  265. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  266. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  267. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  268. package/lib/cjs/workspace/Settings.d.ts +186 -186
  269. package/lib/cjs/workspace/Settings.js +155 -155
  270. package/lib/cjs/workspace/Settings.js.map +1 -1
  271. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  272. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  273. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  274. package/lib/cjs/workspace/Workspace.d.ts +414 -414
  275. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  276. package/lib/cjs/workspace/Workspace.js +543 -543
  277. package/lib/cjs/workspace/Workspace.js.map +1 -1
  278. package/package.json +14 -13
@@ -1,191 +1,223 @@
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.HubMock = void 0;
8
- const path_1 = require("path");
9
- const core_bentley_1 = require("@itwin/core-bentley");
10
- const IModelHost_1 = require("./IModelHost");
11
- const IModelJsFs_1 = require("./IModelJsFs");
12
- const LocalHub_1 = require("./LocalHub");
13
- function wasStarted(val) {
14
- if (undefined === val)
15
- throw new Error("Call HubMock.startup first");
16
- }
17
- /**
18
- * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.
19
- *
20
- * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:
21
- * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs
22
- * - waste network and data center resources (i.e. $$$s),
23
- * - interfere with other tests running on the same or other systems, and
24
- * - (far worse) are the source of test flakiness outside of the api being tested.
25
- *
26
- * This class can be used to create tests that do not require authentication, are synchronous,
27
- * are guaranteed to be self-contained (i.e. do not interfere with other tests running at the same time or later), and do not fail for reasons outside
28
- * of the control of the test itself. As a bonus, in addition to making tests more reliable, mocking IModelHub generally makes tests run *much* faster.
29
- *
30
- * On the other hand, tests that expect to find an existing iModels, checkpoints, changesets, etc. in IModelHub cannot be mocked. In that case, those tests
31
- * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to
32
- * low level testing of the core apis only.
33
- *
34
- * To initialize HubMock, call [[startup]] at the beginning of your test, usually in `describe.before`. Thereafter, all access to iModelHub for an iModel will be
35
- * directed to a [[LocalHub]] - your test code does not change. After the test(s) complete, call [[shutdown]] (usually in `describe.after`) to stop mocking IModelHub and clean
36
- * up any resources used by the test(s). If you want to mock a single test, call [[startup]] as the first line and [[shutdown]] as the last. If you wish to run the
37
- * test against a "real" IModelHub, you can simply comment off the call [[startup]], though in that case you should make sure the name of your
38
- * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)
39
- *
40
- * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.
41
- * They use mock (aka "bogus") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current
42
- * computer.
43
- *
44
- * @note Only one HubMock at a time, *running in a single process*, may be active. The comments above about multiple simultaneous tests refer to tests
45
- * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.
46
- *
47
- * @internal
48
- */
49
- class HubMock {
50
- /** Determine whether a test us currently being run under HubMock */
51
- static get isValid() { return undefined !== this.mockRoot; }
52
- static get iTwinId() {
53
- wasStarted(this._iTwinId);
54
- return this._iTwinId;
55
- }
56
- /**
57
- * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].
58
- * @param mockName a unique name (e.g. "MyTest") for this HubMock to disambiguate tests when more than one is simultaneously active.
59
- * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.
60
- */
61
- static startup(mockName, outputDir) {
62
- if (this.isValid)
63
- throw new Error("Either a previous test did not call HubMock.shutdown() properly, or more than one test is simultaneously attempting to use HubMock, which is not allowed");
64
- this.hubs.clear();
65
- this.mockRoot = (0, path_1.join)(outputDir, "HubMock", mockName);
66
- IModelJsFs_1.IModelJsFs.recursiveMkDirSync(this.mockRoot);
67
- IModelJsFs_1.IModelJsFs.purgeDirSync(this.mockRoot);
68
- this._saveHubAccess = IModelHost_1.IModelHost.getHubAccess();
69
- IModelHost_1.IModelHost.setHubAccess(this);
70
- HubMock._iTwinId = core_bentley_1.Guid.createValue(); // all iModels for this test get the same "iTwinId"
71
- }
72
- /** Stop a HubMock that was previously started with [[startup]]
73
- * @note this function throws an exception if any of the iModels used during the tests are left open.
74
- */
75
- static shutdown() {
76
- if (this.mockRoot === undefined)
77
- return;
78
- HubMock._iTwinId = undefined;
79
- for (const hub of this.hubs)
80
- hub[1].cleanup();
81
- this.hubs.clear();
82
- IModelJsFs_1.IModelJsFs.purgeDirSync(this.mockRoot);
83
- IModelJsFs_1.IModelJsFs.removeSync(this.mockRoot);
84
- IModelHost_1.IModelHost.setHubAccess(this._saveHubAccess);
85
- this.mockRoot = undefined;
86
- }
87
- static findLocalHub(iModelId) {
88
- const hub = this.hubs.get(iModelId);
89
- if (!hub)
90
- throw new Error(`local hub for iModel ${iModelId} not created`);
91
- return hub;
92
- }
93
- /** create a [[LocalHub]] for an iModel. */
94
- static async createNewIModel(arg) {
95
- wasStarted(this.mockRoot);
96
- const props = { ...arg, iModelId: core_bentley_1.Guid.createValue() };
97
- const mock = new LocalHub_1.LocalHub((0, path_1.join)(this.mockRoot, props.iModelId), props);
98
- this.hubs.set(props.iModelId, mock);
99
- return props.iModelId;
100
- }
101
- /** remove the [[LocalHub]] for an iModel */
102
- static destroy(iModelId) {
103
- this.findLocalHub(iModelId).cleanup();
104
- this.hubs.delete(iModelId);
105
- }
106
- /** All methods below are mocks of the [[BackendHubAccess]] interface */
107
- static async getChangesetFromNamedVersion(arg) {
108
- return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);
109
- }
110
- static changesetIndexFromArg(arg) {
111
- return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);
112
- }
113
- static async getChangesetFromVersion(arg) {
114
- const hub = this.findLocalHub(arg.iModelId);
115
- const version = arg.version;
116
- if (version.isFirst)
117
- return hub.getChangesetByIndex(0);
118
- const asOf = version.getAsOfChangeSet();
119
- if (asOf)
120
- return hub.getChangesetById(asOf);
121
- const versionName = version.getName();
122
- if (versionName)
123
- return hub.findNamedVersion(versionName);
124
- return hub.getLatestChangeset();
125
- }
126
- static async getLatestChangeset(arg) {
127
- return this.findLocalHub(arg.iModelId).getLatestChangeset();
128
- }
129
- static async getAccessToken(arg) {
130
- var _a;
131
- return (_a = arg.accessToken) !== null && _a !== void 0 ? _a : await IModelHost_1.IModelHost.getAccessToken();
132
- }
133
- static async getMyBriefcaseIds(arg) {
134
- const accessToken = await this.getAccessToken(arg);
135
- return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);
136
- }
137
- static async acquireNewBriefcaseId(arg) {
138
- const accessToken = await this.getAccessToken(arg);
139
- return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);
140
- }
141
- /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */
142
- static async releaseBriefcase(arg) {
143
- return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);
144
- }
145
- static async downloadChangeset(arg) {
146
- return this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });
147
- }
148
- static async downloadChangesets(arg) {
149
- return this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });
150
- }
151
- static async queryChangeset(arg) {
152
- return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));
153
- }
154
- static async queryChangesets(arg) {
155
- return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);
156
- }
157
- static async pushChangeset(arg) {
158
- return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);
159
- }
160
- static async queryV2Checkpoint(_arg) {
161
- return undefined;
162
- }
163
- // eslint-disable-next-line deprecation/deprecation
164
- static async downloadV1Checkpoint(arg) {
165
- return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });
166
- }
167
- static async releaseAllLocks(arg) {
168
- const hub = this.findLocalHub(arg.iModelId);
169
- hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });
170
- }
171
- static async queryAllLocks(_arg) {
172
- return [];
173
- }
174
- static async acquireLocks(arg, locks) {
175
- this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);
176
- }
177
- static async queryIModelByName(arg) {
178
- for (const hub of this.hubs) {
179
- const localHub = hub[1];
180
- if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)
181
- return localHub.iModelId;
182
- }
183
- return undefined;
184
- }
185
- static async deleteIModel(arg) {
186
- return this.destroy(arg.iModelId);
187
- }
188
- }
189
- exports.HubMock = HubMock;
190
- HubMock.hubs = new Map();
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.HubMock = void 0;
8
+ const path_1 = require("path");
9
+ const core_bentley_1 = require("@itwin/core-bentley");
10
+ const CheckpointManager_1 = require("./CheckpointManager");
11
+ const IModelHost_1 = require("./IModelHost");
12
+ const IModelJsFs_1 = require("./IModelJsFs");
13
+ const LocalHub_1 = require("./LocalHub");
14
+ function wasStarted(val) {
15
+ if (undefined === val)
16
+ throw new Error("Call HubMock.startup first");
17
+ }
18
+ /**
19
+ * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.
20
+ *
21
+ * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:
22
+ * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs
23
+ * - waste network and data center resources (i.e. $$$s),
24
+ * - interfere with other tests running on the same or other systems, and
25
+ * - (far worse) are the source of test flakiness outside of the api being tested.
26
+ *
27
+ * This class can be used to create tests that do not require authentication, are synchronous,
28
+ * are guaranteed to be self-contained (i.e. do not interfere with other tests running at the same time or later), and do not fail for reasons outside
29
+ * of the control of the test itself. As a bonus, in addition to making tests more reliable, mocking IModelHub generally makes tests run *much* faster.
30
+ *
31
+ * On the other hand, tests that expect to find an existing iModels, checkpoints, changesets, etc. in IModelHub cannot be mocked. In that case, those tests
32
+ * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to
33
+ * low level testing of the core apis only.
34
+ *
35
+ * To initialize HubMock, call [[startup]] at the beginning of your test, usually in `describe.before`. Thereafter, all access to iModelHub for an iModel will be
36
+ * directed to a [[LocalHub]] - your test code does not change. After the test(s) complete, call [[shutdown]] (usually in `describe.after`) to stop mocking IModelHub and clean
37
+ * up any resources used by the test(s). If you want to mock a single test, call [[startup]] as the first line and [[shutdown]] as the last. If you wish to run the
38
+ * test against a "real" IModelHub, you can simply comment off the call [[startup]], though in that case you should make sure the name of your
39
+ * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)
40
+ *
41
+ * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.
42
+ * They use mock (aka "bogus") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current
43
+ * computer.
44
+ *
45
+ * @note Only one HubMock at a time, *running in a single process*, may be active. The comments above about multiple simultaneous tests refer to tests
46
+ * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.
47
+ *
48
+ * @internal
49
+ */
50
+ class HubMock {
51
+ /** Determine whether a test us currently being run under HubMock */
52
+ static get isValid() { return undefined !== this.mockRoot; }
53
+ static get iTwinId() {
54
+ wasStarted(this._iTwinId);
55
+ return this._iTwinId;
56
+ }
57
+ /**
58
+ * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].
59
+ * @param mockName a unique name (e.g. "MyTest") for this HubMock to disambiguate tests when more than one is simultaneously active.
60
+ * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.
61
+ */
62
+ static startup(mockName, outputDir) {
63
+ if (this.isValid)
64
+ throw new Error("Either a previous test did not call HubMock.shutdown() properly, or more than one test is simultaneously attempting to use HubMock, which is not allowed");
65
+ this.hubs.clear();
66
+ this.mockRoot = (0, path_1.join)(outputDir, "HubMock", mockName);
67
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync(this.mockRoot);
68
+ IModelJsFs_1.IModelJsFs.purgeDirSync(this.mockRoot);
69
+ this._saveHubAccess = IModelHost_1.IModelHost.getHubAccess();
70
+ IModelHost_1.IModelHost.setHubAccess(this);
71
+ HubMock._iTwinId = core_bentley_1.Guid.createValue(); // all iModels for this test get the same "iTwinId"
72
+ }
73
+ /** Stop a HubMock that was previously started with [[startup]]
74
+ * @note this function throws an exception if any of the iModels used during the tests are left open.
75
+ */
76
+ static shutdown() {
77
+ if (this.mockRoot === undefined)
78
+ return;
79
+ HubMock._iTwinId = undefined;
80
+ for (const hub of this.hubs)
81
+ hub[1].cleanup();
82
+ this.hubs.clear();
83
+ IModelJsFs_1.IModelJsFs.purgeDirSync(this.mockRoot);
84
+ IModelJsFs_1.IModelJsFs.removeSync(this.mockRoot);
85
+ IModelHost_1.IModelHost.setHubAccess(this._saveHubAccess);
86
+ this.mockRoot = undefined;
87
+ }
88
+ static findLocalHub(iModelId) {
89
+ const hub = this.hubs.get(iModelId);
90
+ if (!hub)
91
+ throw new Error(`local hub for iModel ${iModelId} not created`);
92
+ return hub;
93
+ }
94
+ /** create a [[LocalHub]] for an iModel. */
95
+ static async createNewIModel(arg) {
96
+ wasStarted(this.mockRoot);
97
+ const props = { ...arg, iModelId: core_bentley_1.Guid.createValue() };
98
+ const mock = new LocalHub_1.LocalHub((0, path_1.join)(this.mockRoot, props.iModelId), props);
99
+ this.hubs.set(props.iModelId, mock);
100
+ return props.iModelId;
101
+ }
102
+ /** remove the [[LocalHub]] for an iModel */
103
+ static destroy(iModelId) {
104
+ this.findLocalHub(iModelId).cleanup();
105
+ this.hubs.delete(iModelId);
106
+ }
107
+ /** All methods below are mocks of the [[BackendHubAccess]] interface */
108
+ static async getChangesetFromNamedVersion(arg) {
109
+ return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);
110
+ }
111
+ static changesetIndexFromArg(arg) {
112
+ return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);
113
+ }
114
+ static async getChangesetFromVersion(arg) {
115
+ const hub = this.findLocalHub(arg.iModelId);
116
+ const version = arg.version;
117
+ if (version.isFirst)
118
+ return hub.getChangesetByIndex(0);
119
+ const asOf = version.getAsOfChangeSet();
120
+ if (asOf)
121
+ return hub.getChangesetById(asOf);
122
+ const versionName = version.getName();
123
+ if (versionName)
124
+ return hub.findNamedVersion(versionName);
125
+ return hub.getLatestChangeset();
126
+ }
127
+ static async getLatestChangeset(arg) {
128
+ return this.findLocalHub(arg.iModelId).getLatestChangeset();
129
+ }
130
+ static async getAccessToken(arg) {
131
+ var _a;
132
+ return (_a = arg.accessToken) !== null && _a !== void 0 ? _a : await IModelHost_1.IModelHost.getAccessToken();
133
+ }
134
+ static async getMyBriefcaseIds(arg) {
135
+ const accessToken = await this.getAccessToken(arg);
136
+ return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);
137
+ }
138
+ static async acquireNewBriefcaseId(arg) {
139
+ const accessToken = await this.getAccessToken(arg);
140
+ return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);
141
+ }
142
+ /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */
143
+ static async releaseBriefcase(arg) {
144
+ return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);
145
+ }
146
+ static async downloadChangeset(arg) {
147
+ var _a;
148
+ const changesetProps = this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });
149
+ if (arg.progressCallback) {
150
+ const totalSize = (_a = IModelJsFs_1.IModelJsFs.lstatSync(changesetProps.pathname)) === null || _a === void 0 ? void 0 : _a.size;
151
+ if (totalSize)
152
+ await HubMock.mockProgressReporting(arg.progressCallback, totalSize);
153
+ }
154
+ return changesetProps;
155
+ }
156
+ static async downloadChangesets(arg) {
157
+ const changesetProps = this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });
158
+ if (arg.progressCallback) {
159
+ const totalSize = changesetProps.reduce((sum, props) => { var _a, _b; return sum + ((_b = (_a = IModelJsFs_1.IModelJsFs.lstatSync(props.pathname)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0); }, 0);
160
+ await HubMock.mockProgressReporting(arg.progressCallback, totalSize);
161
+ }
162
+ return changesetProps;
163
+ }
164
+ static async queryChangeset(arg) {
165
+ return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));
166
+ }
167
+ static async queryChangesets(arg) {
168
+ return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);
169
+ }
170
+ static async pushChangeset(arg) {
171
+ return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);
172
+ }
173
+ static async queryV2Checkpoint(_arg) {
174
+ return undefined;
175
+ }
176
+ // eslint-disable-next-line deprecation/deprecation
177
+ static async downloadV1Checkpoint(arg) {
178
+ return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });
179
+ }
180
+ static async releaseAllLocks(arg) {
181
+ const hub = this.findLocalHub(arg.iModelId);
182
+ hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });
183
+ }
184
+ static async queryAllLocks(_arg) {
185
+ return [];
186
+ }
187
+ static async acquireLocks(arg, locks) {
188
+ this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);
189
+ }
190
+ static async queryIModelByName(arg) {
191
+ for (const hub of this.hubs) {
192
+ const localHub = hub[1];
193
+ if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)
194
+ return localHub.iModelId;
195
+ }
196
+ return undefined;
197
+ }
198
+ static async deleteIModel(arg) {
199
+ return this.destroy(arg.iModelId);
200
+ }
201
+ static async mockProgressReporting(progressCallback, totalSize) {
202
+ await new Promise((resolve, reject) => {
203
+ let rejected = false;
204
+ const mockProgress = (index) => {
205
+ const bytesDownloaded = Math.floor(totalSize * (index / 4));
206
+ if (!rejected && progressCallback(bytesDownloaded, totalSize) === CheckpointManager_1.ProgressStatus.Abort) {
207
+ rejected = true;
208
+ reject(new Error("AbortError"));
209
+ }
210
+ };
211
+ mockProgress(1);
212
+ setTimeout(() => mockProgress(2), 50);
213
+ setTimeout(() => mockProgress(3), 100);
214
+ setTimeout(() => {
215
+ mockProgress(4);
216
+ resolve(undefined);
217
+ }, 150);
218
+ });
219
+ }
220
+ }
221
+ exports.HubMock = HubMock;
222
+ HubMock.hubs = new Map();
191
223
  //# sourceMappingURL=HubMock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HubMock.js","sourceRoot":"","sources":["../../src/HubMock.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,+BAA4B;AAC5B,sDAAuD;AAUvD,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAsC;AAGtC,SAAS,UAAU,CAAC,GAAuB;IACzC,IAAI,SAAS,KAAK,GAAG;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,OAAO;IAMlB,oEAAoE;IAC7D,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,MAAM,KAAK,OAAO;QACvB,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,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AC,GAAkB;QACtD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE;YAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,QAAQ,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,CAAC,UAAU;gBAC5E,OAAO,QAAQ,CAAC,QAAQ,CAAC;SAC5B;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,GAA0C;QACzE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;;AA/KH,0BAgLC;AA9KgB,YAAI,GAAG,IAAI,GAAG,EAAoB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { join } from \"path\";\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\nimport {\n ChangesetFileProps, ChangesetIndex, ChangesetIndexAndId, ChangesetProps, ChangesetRange, IModelVersion, LocalDirName,\n} from \"@itwin/core-common\";\nimport {\n AcquireNewBriefcaseIdArg,\n BackendHubAccess, BriefcaseDbArg, BriefcaseIdArg, ChangesetArg, CheckpointArg, CreateNewIModelProps, DownloadChangesetArg, DownloadChangesetRangeArg, IModelIdArg, IModelNameArg,\n LockMap, LockProps, V2CheckpointAccessProps,\n} from \"./BackendHubAccess\";\nimport { CheckpointProps } from \"./CheckpointManager\";\nimport { IModelHost } from \"./IModelHost\";\nimport { IModelJsFs } from \"./IModelJsFs\";\nimport { LocalHub } from \"./LocalHub\";\nimport { TokenArg } from \"./IModelDb\";\n\nfunction wasStarted(val: string | undefined): asserts val is string {\n if (undefined === val)\n throw new Error(\"Call HubMock.startup first\");\n}\n\n/**\n * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.\n *\n * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:\n * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs\n * - waste network and data center resources (i.e. $$$s),\n * - interfere with other tests running on the same or other systems, and\n * - (far worse) are the source of test flakiness outside of the api being tested.\n *\n * This class can be used to create tests that do not require authentication, are synchronous,\n * are guaranteed to be self-contained (i.e. do not interfere with other tests running at the same time or later), and do not fail for reasons outside\n * of the control of the test itself. As a bonus, in addition to making tests more reliable, mocking IModelHub generally makes tests run *much* faster.\n *\n * On the other hand, tests that expect to find an existing iModels, checkpoints, changesets, etc. in IModelHub cannot be mocked. In that case, those tests\n * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to\n * low level testing of the core apis only.\n *\n * To initialize HubMock, call [[startup]] at the beginning of your test, usually in `describe.before`. Thereafter, all access to iModelHub for an iModel will be\n * directed to a [[LocalHub]] - your test code does not change. After the test(s) complete, call [[shutdown]] (usually in `describe.after`) to stop mocking IModelHub and clean\n * up any resources used by the test(s). If you want to mock a single test, call [[startup]] as the first line and [[shutdown]] as the last. If you wish to run the\n * test against a \"real\" IModelHub, you can simply comment off the call [[startup]], though in that case you should make sure the name of your\n * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)\n *\n * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.\n * They use mock (aka \"bogus\") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current\n * computer.\n *\n * @note Only one HubMock at a time, *running in a single process*, may be active. The comments above about multiple simultaneous tests refer to tests\n * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.\n *\n * @internal\n */\nexport class HubMock {\n private static mockRoot: LocalDirName | undefined;\n private static hubs = new Map<string, LocalHub>();\n private static _saveHubAccess: BackendHubAccess | undefined;\n private static _iTwinId: GuidString | undefined;\n\n /** Determine whether a test us currently being run under HubMock */\n public static get isValid() { return undefined !== this.mockRoot; }\n public static get iTwinId() {\n wasStarted(this._iTwinId);\n return this._iTwinId;\n }\n\n /**\n * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].\n * @param mockName a unique name (e.g. \"MyTest\") for this HubMock to disambiguate tests when more than one is simultaneously active.\n * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.\n */\n public static startup(mockName: LocalDirName, outputDir: string) {\n if (this.isValid)\n throw new Error(\"Either a previous test did not call HubMock.shutdown() properly, or more than one test is simultaneously attempting to use HubMock, which is not allowed\");\n\n this.hubs.clear();\n this.mockRoot = join(outputDir, \"HubMock\", mockName);\n IModelJsFs.recursiveMkDirSync(this.mockRoot);\n IModelJsFs.purgeDirSync(this.mockRoot);\n this._saveHubAccess = IModelHost.getHubAccess();\n\n IModelHost.setHubAccess(this);\n HubMock._iTwinId = Guid.createValue(); // all iModels for this test get the same \"iTwinId\"\n }\n\n /** Stop a HubMock that was previously started with [[startup]]\n * @note this function throws an exception if any of the iModels used during the tests are left open.\n */\n public static shutdown() {\n if (this.mockRoot === undefined)\n return;\n\n HubMock._iTwinId = undefined;\n for (const hub of this.hubs)\n hub[1].cleanup();\n\n this.hubs.clear();\n IModelJsFs.purgeDirSync(this.mockRoot);\n IModelJsFs.removeSync(this.mockRoot);\n IModelHost.setHubAccess(this._saveHubAccess);\n this.mockRoot = undefined;\n }\n\n public static findLocalHub(iModelId: GuidString): LocalHub {\n const hub = this.hubs.get(iModelId);\n if (!hub)\n throw new Error(`local hub for iModel ${iModelId} not created`);\n return hub;\n }\n\n /** create a [[LocalHub]] for an iModel. */\n public static async createNewIModel(arg: CreateNewIModelProps): Promise<GuidString> {\n wasStarted(this.mockRoot);\n const props = { ...arg, iModelId: Guid.createValue() };\n const mock = new LocalHub(join(this.mockRoot, props.iModelId), props);\n this.hubs.set(props.iModelId, mock);\n return props.iModelId;\n }\n\n /** remove the [[LocalHub]] for an iModel */\n public static destroy(iModelId: GuidString) {\n this.findLocalHub(iModelId).cleanup();\n this.hubs.delete(iModelId);\n }\n\n /** All methods below are mocks of the [[BackendHubAccess]] interface */\n\n public static async getChangesetFromNamedVersion(arg: IModelIdArg & { versionName: string }): Promise<ChangesetProps> {\n return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);\n }\n\n private static changesetIndexFromArg(arg: ChangesetArg) {\n return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);\n }\n\n public static async getChangesetFromVersion(arg: IModelIdArg & { version: IModelVersion }): Promise<ChangesetProps> {\n const hub = this.findLocalHub(arg.iModelId);\n const version = arg.version;\n if (version.isFirst)\n return hub.getChangesetByIndex(0);\n\n const asOf = version.getAsOfChangeSet();\n if (asOf)\n return hub.getChangesetById(asOf);\n\n const versionName = version.getName();\n if (versionName)\n return hub.findNamedVersion(versionName);\n\n return hub.getLatestChangeset();\n }\n\n public static async getLatestChangeset(arg: IModelIdArg): Promise<ChangesetProps> {\n return this.findLocalHub(arg.iModelId).getLatestChangeset();\n }\n\n private static async getAccessToken(arg: TokenArg) {\n return arg.accessToken ?? await IModelHost.getAccessToken();\n }\n\n public static async getMyBriefcaseIds(arg: IModelIdArg): Promise<number[]> {\n const accessToken = await this.getAccessToken(arg);\n return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);\n }\n\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<number> {\n const accessToken = await this.getAccessToken(arg);\n return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);\n }\n\n /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */\n public static async releaseBriefcase(arg: BriefcaseIdArg): Promise<void> {\n return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);\n }\n\n public static async downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps> {\n return this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });\n }\n\n public static async downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]> {\n return this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });\n }\n\n public static async queryChangeset(arg: ChangesetArg): Promise<ChangesetProps> {\n return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));\n }\n\n public static async queryChangesets(arg: IModelIdArg & { range?: ChangesetRange }): Promise<ChangesetProps[]> {\n return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);\n }\n\n public static async pushChangeset(arg: IModelIdArg & { changesetProps: ChangesetFileProps }): Promise<ChangesetIndex> {\n return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);\n }\n\n public static async queryV2Checkpoint(_arg: CheckpointProps): Promise<V2CheckpointAccessProps | undefined> {\n return undefined;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n public static async downloadV1Checkpoint(arg: CheckpointArg): Promise<ChangesetIndexAndId> {\n return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });\n }\n\n public static async releaseAllLocks(arg: BriefcaseDbArg) {\n const hub = this.findLocalHub(arg.iModelId);\n hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });\n }\n\n public static async queryAllLocks(_arg: BriefcaseDbArg): Promise<LockProps[]> {\n return [];\n }\n\n public static async acquireLocks(arg: BriefcaseDbArg, locks: LockMap): Promise<void> {\n this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);\n }\n\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\n for (const hub of this.hubs) {\n const localHub = hub[1];\n if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)\n return localHub.iModelId;\n }\n return undefined;\n }\n\n public static async deleteIModel(arg: IModelIdArg & { iTwinId: G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AAG,CAAC,CAAC;YACvC,UAAU,CAAC,GAAG,EAAE;gBACd,YAAY,CAAC,CAAC,CAAC,CAAC;gBAChB,OAAO,CAAC,SAAS,CAAC,CAAC;YACrB,CAAC,EAAE,GAAG,CAAC,CAAC;QACV,CAAC,CAAC,CAAC;IACL,CAAC;;AApNH,0BAqNC;AAnNgB,YAAI,GAAG,IAAI,GAAG,EAAoB,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\r\nimport { join } from \"path\";\r\nimport { Guid, GuidString } from \"@itwin/core-bentley\";\r\nimport {\r\n ChangesetFileProps, ChangesetIndex, ChangesetIndexAndId, ChangesetProps, ChangesetRange, IModelVersion, LocalDirName,\r\n} from \"@itwin/core-common\";\r\nimport {\r\n AcquireNewBriefcaseIdArg,\r\n BackendHubAccess, BriefcaseDbArg, BriefcaseIdArg, ChangesetArg, CheckpointArg, CreateNewIModelProps, DownloadChangesetArg, DownloadChangesetRangeArg, IModelIdArg, IModelNameArg,\r\n LockMap, LockProps, V2CheckpointAccessProps,\r\n} from \"./BackendHubAccess\";\r\nimport { CheckpointProps, ProgressFunction, ProgressStatus } from \"./CheckpointManager\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { LocalHub } from \"./LocalHub\";\r\nimport { TokenArg } from \"./IModelDb\";\r\n\r\nfunction wasStarted(val: string | undefined): asserts val is string {\r\n if (undefined === val)\r\n throw new Error(\"Call HubMock.startup first\");\r\n}\r\n\r\n/**\r\n * Mocks iModelHub for testing creating Briefcases, downloading checkpoints, and simulating multiple users pushing and pulling changesets, etc.\r\n *\r\n * Generally, tests for apis that *create or modify* iModels can and should be mocked. Otherwise they:\r\n * - create tremendous load on the test servers when they run on programmer's desktops and in CI jobs\r\n * - waste network and data center resources (i.e. $$$s),\r\n * - interfere with other tests running on the same or other systems, and\r\n * - (far worse) are the source of test flakiness outside of the api being tested.\r\n *\r\n * This class can be used to create tests that do not require authentication, are synchronous,\r\n * are guaranteed to be self-contained (i.e. do not interfere with other tests running at the same time or later), and do not fail for reasons outside\r\n * of the control of the test itself. As a bonus, in addition to making tests more reliable, mocking IModelHub generally makes tests run *much* faster.\r\n *\r\n * On the other hand, tests that expect to find an existing iModels, checkpoints, changesets, etc. in IModelHub cannot be mocked. In that case, those tests\r\n * should be careful to NOT modify the data, since doing so causes interference with other tests running simultaneously. These tests should be limited to\r\n * low level testing of the core apis only.\r\n *\r\n * To initialize HubMock, call [[startup]] at the beginning of your test, usually in `describe.before`. Thereafter, all access to iModelHub for an iModel will be\r\n * directed to a [[LocalHub]] - your test code does not change. After the test(s) complete, call [[shutdown]] (usually in `describe.after`) to stop mocking IModelHub and clean\r\n * up any resources used by the test(s). If you want to mock a single test, call [[startup]] as the first line and [[shutdown]] as the last. If you wish to run the\r\n * test against a \"real\" IModelHub, you can simply comment off the call [[startup]], though in that case you should make sure the name of your\r\n * iModel is unique so your test won't collide with other tests (iModel name uniqueness is not necessary for mocked tests.)\r\n *\r\n * Mocked tests must always start by creating a new iModel via [[IModelHost.hubAccess.createNewIModel]] with a `version0` iModel.\r\n * They use mock (aka \"bogus\") credentials for `AccessTokens`, which is fine since [[HubMock]] never accesses resources outside the current\r\n * computer.\r\n *\r\n * @note Only one HubMock at a time, *running in a single process*, may be active. The comments above about multiple simultaneous tests refer to tests\r\n * running on different computers, or on a single computer in multiple processes. All of those scenarios are problematic without mocking.\r\n *\r\n * @internal\r\n */\r\nexport class HubMock {\r\n private static mockRoot: LocalDirName | undefined;\r\n private static hubs = new Map<string, LocalHub>();\r\n private static _saveHubAccess: BackendHubAccess | undefined;\r\n private static _iTwinId: GuidString | undefined;\r\n\r\n /** Determine whether a test us currently being run under HubMock */\r\n public static get isValid() { return undefined !== this.mockRoot; }\r\n public static get iTwinId() {\r\n wasStarted(this._iTwinId);\r\n return this._iTwinId;\r\n }\r\n\r\n /**\r\n * Begin mocking IModelHub access. After this call, all access to IModelHub will be directed to a [[LocalHub]].\r\n * @param mockName a unique name (e.g. \"MyTest\") for this HubMock to disambiguate tests when more than one is simultaneously active.\r\n * It is used to create a private directory used by the HubMock for a test. That directory is removed when [[shutdown]] is called.\r\n */\r\n public static startup(mockName: LocalDirName, outputDir: string) {\r\n if (this.isValid)\r\n throw new Error(\"Either a previous test did not call HubMock.shutdown() properly, or more than one test is simultaneously attempting to use HubMock, which is not allowed\");\r\n\r\n this.hubs.clear();\r\n this.mockRoot = join(outputDir, \"HubMock\", mockName);\r\n IModelJsFs.recursiveMkDirSync(this.mockRoot);\r\n IModelJsFs.purgeDirSync(this.mockRoot);\r\n this._saveHubAccess = IModelHost.getHubAccess();\r\n\r\n IModelHost.setHubAccess(this);\r\n HubMock._iTwinId = Guid.createValue(); // all iModels for this test get the same \"iTwinId\"\r\n }\r\n\r\n /** Stop a HubMock that was previously started with [[startup]]\r\n * @note this function throws an exception if any of the iModels used during the tests are left open.\r\n */\r\n public static shutdown() {\r\n if (this.mockRoot === undefined)\r\n return;\r\n\r\n HubMock._iTwinId = undefined;\r\n for (const hub of this.hubs)\r\n hub[1].cleanup();\r\n\r\n this.hubs.clear();\r\n IModelJsFs.purgeDirSync(this.mockRoot);\r\n IModelJsFs.removeSync(this.mockRoot);\r\n IModelHost.setHubAccess(this._saveHubAccess);\r\n this.mockRoot = undefined;\r\n }\r\n\r\n public static findLocalHub(iModelId: GuidString): LocalHub {\r\n const hub = this.hubs.get(iModelId);\r\n if (!hub)\r\n throw new Error(`local hub for iModel ${iModelId} not created`);\r\n return hub;\r\n }\r\n\r\n /** create a [[LocalHub]] for an iModel. */\r\n public static async createNewIModel(arg: CreateNewIModelProps): Promise<GuidString> {\r\n wasStarted(this.mockRoot);\r\n const props = { ...arg, iModelId: Guid.createValue() };\r\n const mock = new LocalHub(join(this.mockRoot, props.iModelId), props);\r\n this.hubs.set(props.iModelId, mock);\r\n return props.iModelId;\r\n }\r\n\r\n /** remove the [[LocalHub]] for an iModel */\r\n public static destroy(iModelId: GuidString) {\r\n this.findLocalHub(iModelId).cleanup();\r\n this.hubs.delete(iModelId);\r\n }\r\n\r\n /** All methods below are mocks of the [[BackendHubAccess]] interface */\r\n\r\n public static async getChangesetFromNamedVersion(arg: IModelIdArg & { versionName: string }): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).findNamedVersion(arg.versionName);\r\n }\r\n\r\n private static changesetIndexFromArg(arg: ChangesetArg) {\r\n return (undefined !== arg.changeset.index) ? arg.changeset.index : this.findLocalHub(arg.iModelId).getChangesetIndex(arg.changeset.id);\r\n }\r\n\r\n public static async getChangesetFromVersion(arg: IModelIdArg & { version: IModelVersion }): Promise<ChangesetProps> {\r\n const hub = this.findLocalHub(arg.iModelId);\r\n const version = arg.version;\r\n if (version.isFirst)\r\n return hub.getChangesetByIndex(0);\r\n\r\n const asOf = version.getAsOfChangeSet();\r\n if (asOf)\r\n return hub.getChangesetById(asOf);\r\n\r\n const versionName = version.getName();\r\n if (versionName)\r\n return hub.findNamedVersion(versionName);\r\n\r\n return hub.getLatestChangeset();\r\n }\r\n\r\n public static async getLatestChangeset(arg: IModelIdArg): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).getLatestChangeset();\r\n }\r\n\r\n private static async getAccessToken(arg: TokenArg) {\r\n return arg.accessToken ?? await IModelHost.getAccessToken();\r\n }\r\n\r\n public static async getMyBriefcaseIds(arg: IModelIdArg): Promise<number[]> {\r\n const accessToken = await this.getAccessToken(arg);\r\n return this.findLocalHub(arg.iModelId).getBriefcaseIds(accessToken);\r\n }\r\n\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<number> {\r\n const accessToken = await this.getAccessToken(arg);\r\n return this.findLocalHub(arg.iModelId).acquireNewBriefcaseId(accessToken, arg.briefcaseAlias);\r\n }\r\n\r\n /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */\r\n public static async releaseBriefcase(arg: BriefcaseIdArg): Promise<void> {\r\n return this.findLocalHub(arg.iModelId).releaseBriefcaseId(arg.briefcaseId);\r\n }\r\n\r\n public static async downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps> {\r\n const changesetProps = this.findLocalHub(arg.iModelId).downloadChangeset({ index: this.changesetIndexFromArg(arg), targetDir: arg.targetDir });\r\n\r\n if (arg.progressCallback) {\r\n const totalSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\r\n if (totalSize)\r\n await HubMock.mockProgressReporting(arg.progressCallback, totalSize);\r\n }\r\n\r\n return changesetProps;\r\n }\r\n\r\n public static async downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]> {\r\n const changesetProps = this.findLocalHub(arg.iModelId).downloadChangesets({ range: arg.range, targetDir: arg.targetDir });\r\n\r\n if (arg.progressCallback) {\r\n const totalSize = changesetProps.reduce((sum, props) => sum + (IModelJsFs.lstatSync(props.pathname)?.size ?? 0), 0);\r\n await HubMock.mockProgressReporting(arg.progressCallback, totalSize);\r\n }\r\n\r\n return changesetProps;\r\n }\r\n\r\n public static async queryChangeset(arg: ChangesetArg): Promise<ChangesetProps> {\r\n return this.findLocalHub(arg.iModelId).getChangesetByIndex(this.changesetIndexFromArg(arg));\r\n }\r\n\r\n public static async queryChangesets(arg: IModelIdArg & { range?: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return this.findLocalHub(arg.iModelId).queryChangesets(arg.range);\r\n }\r\n\r\n public static async pushChangeset(arg: IModelIdArg & { changesetProps: ChangesetFileProps }): Promise<ChangesetIndex> {\r\n return this.findLocalHub(arg.iModelId).addChangeset(arg.changesetProps);\r\n }\r\n\r\n public static async queryV2Checkpoint(_arg: CheckpointProps): Promise<V2CheckpointAccessProps | undefined> {\r\n return undefined;\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n public static async downloadV1Checkpoint(arg: CheckpointArg): Promise<ChangesetIndexAndId> {\r\n return this.findLocalHub(arg.checkpoint.iModelId).downloadCheckpoint({ changeset: arg.checkpoint.changeset, targetFile: arg.localFile });\r\n }\r\n\r\n public static async releaseAllLocks(arg: BriefcaseDbArg) {\r\n const hub = this.findLocalHub(arg.iModelId);\r\n hub.releaseAllLocks({ briefcaseId: arg.briefcaseId, changesetIndex: hub.getIndexFromChangeset(arg.changeset) });\r\n }\r\n\r\n public static async queryAllLocks(_arg: BriefcaseDbArg): Promise<LockProps[]> {\r\n return [];\r\n }\r\n\r\n public static async acquireLocks(arg: BriefcaseDbArg, locks: LockMap): Promise<void> {\r\n this.findLocalHub(arg.iModelId).acquireLocks(locks, arg);\r\n }\r\n\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n for (const hub of this.hubs) {\r\n const localHub = hub[1];\r\n if (localHub.iTwinId === arg.iTwinId && localHub.iModelName === arg.iModelName)\r\n return localHub.iModelId;\r\n }\r\n return undefined;\r\n }\r\n\r\n public static async deleteIModel(arg: IModelIdArg & { iTwinId: GuidString }): Promise<void> {\r\n return this.destroy(arg.iModelId);\r\n }\r\n\r\n private static async mockProgressReporting(progressCallback: ProgressFunction, totalSize: number): Promise<void> {\r\n await new Promise((resolve, reject) => {\r\n let rejected = false;\r\n\r\n const mockProgress = (index: number) => {\r\n const bytesDownloaded = Math.floor(totalSize * (index / 4));\r\n if (!rejected && progressCallback(bytesDownloaded, totalSize) === ProgressStatus.Abort){\r\n rejected = true;\r\n reject(new Error(\"AbortError\"));\r\n }\r\n };\r\n\r\n mockProgress(1);\r\n setTimeout(() => mockProgress(2), 50);\r\n setTimeout(() => mockProgress(3), 100);\r\n setTimeout(() => {\r\n mockProgress(4);\r\n resolve(undefined);\r\n }, 150);\r\n });\r\n }\r\n}\r\n"]}
@@ -1,86 +1,9 @@
1
- /** @packageDocumentation
2
- * @module iModels
3
- */
4
- import { Id64String } from "@itwin/core-bentley";
5
- import { ElementProps } from "@itwin/core-common";
6
- import { IModelJsNative } from "@bentley/imodeljs-native";
7
- import { Element } from "./Element";
8
- import { IModelDb } from "./IModelDb";
9
- import { SQLiteDb } from "./SQLiteDb";
10
- /** The context for transforming a *source* Element to a *target* Element and remapping internal identifiers to the target iModel.
11
- * @beta
12
- */
13
- export declare class IModelCloneContext {
14
- /** The source IModelDb. */
15
- readonly sourceDb: IModelDb;
16
- /** The target IModelDb. */
17
- readonly targetDb: IModelDb;
18
- /** The native import context */
19
- private _nativeContext;
20
- /** Construct a new IModelCloneContext.
21
- * @param sourceDb The source IModelDb.
22
- * @param targetDb If provided the target IModelDb. If not provided, the source and target are the same IModelDb.
23
- */
24
- constructor(sourceDb: IModelDb, targetDb?: IModelDb);
25
- /** Returns `true` if this context is for transforming between 2 iModels and `false` if it for transforming within the same iModel. */
26
- get isBetweenIModels(): boolean;
27
- /** Dispose any native resources associated with this IModelCloneContext. */
28
- dispose(): void;
29
- /** Debugging aid that dumps the Id remapping details and other information to the specified output file.
30
- * @internal
31
- */
32
- dump(outputFileName: string): void;
33
- /** Add a rule that remaps the specified source [CodeSpec]($common) to the specified target [CodeSpec]($common).
34
- * @param sourceCodeSpecName The name of the CodeSpec from the source iModel.
35
- * @param targetCodeSpecName The name of the CodeSpec from the target iModel.
36
- * @throws [[IModelError]] if either CodeSpec could not be found.
37
- */
38
- remapCodeSpec(sourceCodeSpecName: string, targetCodeSpecName: string): void;
39
- /** Add a rule that remaps the specified source class to the specified target class. */
40
- remapElementClass(sourceClassFullName: string, targetClassFullName: string): void;
41
- /** Add a rule that remaps the specified source Element to the specified target Element. */
42
- remapElement(sourceId: Id64String, targetId: Id64String): void;
43
- /** Remove a rule that remaps the specified source Element. */
44
- removeElement(sourceId: Id64String): void;
45
- /** Look up a target CodeSpecId from the source CodeSpecId.
46
- * @returns the target CodeSpecId or [Id64.invalid]($bentley) if a mapping not found.
47
- */
48
- findTargetCodeSpecId(sourceId: Id64String): Id64String;
49
- /** Look up a target ElementId from the source ElementId.
50
- * @returns the target ElementId or [Id64.invalid]($bentley) if a mapping not found.
51
- */
52
- findTargetElementId(sourceElementId: Id64String): Id64String;
53
- /** Filter out geometry entries in the specified SubCategory from GeometryStreams in the target iModel.
54
- * @note It is not possible to filter out a *default* SubCategory. A request to do so will be ignored.
55
- * @see [SubCategory.isDefaultSubCategory]($backend)
56
- */
57
- filterSubCategory(sourceSubCategoryId: Id64String): void;
58
- /** Returns `true` if there are any SubCategories being filtered. */
59
- get hasSubCategoryFilter(): boolean;
60
- /** Returns `true` if this SubCategory is being filtered. */
61
- isSubCategoryFiltered(subCategoryId: Id64String): boolean;
62
- /** Import the specified font from the source iModel into the target iModel.
63
- * @internal
64
- */
65
- importFont(sourceFontNumber: number): void;
66
- /** Import a single CodeSpec from the source iModel into the target iModel.
67
- * @internal
68
- */
69
- importCodeSpec(sourceCodeSpecId: Id64String): void;
70
- /** Clone the specified source Element into ElementProps for the target iModel.
71
- * @internal
72
- */
73
- cloneElement(sourceElement: Element, cloneOptions?: IModelJsNative.CloneElementOptions): ElementProps;
74
- /**
75
- * serialize state to a sqlite database at a given path
76
- * assumes the database has not already had any context state serialized to it
77
- * @internal
78
- */
79
- saveStateToDb(db: SQLiteDb): void;
80
- /**
81
- * load state from a sqlite database at a given path
82
- * @internal
83
- */
84
- loadStateFromDb(db: SQLiteDb): void;
85
- }
1
+ /** @packageDocumentation
2
+ * @module iModels
3
+ */
4
+ import { IModelElementCloneContext } from "./IModelElementCloneContext";
5
+ /** @deprecated use [[IModelElementCloneContext]] instead, @beta */
6
+ export declare const IModelCloneContext: typeof IModelElementCloneContext;
7
+ /** @deprecated use [[IModelElementCloneContext]] instead, @beta */
8
+ export declare type IModelCloneContext = IModelElementCloneContext;
86
9
  //# sourceMappingURL=IModelCloneContext.d.ts.map