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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/CHANGELOG.md +55 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +41 -41
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
  7. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.js +98 -99
  9. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  11. package/lib/cjs/BisCoreSchema.js +60 -60
  12. package/lib/cjs/BriefcaseManager.d.ts +170 -170
  13. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  14. package/lib/cjs/BriefcaseManager.js +408 -414
  15. package/lib/cjs/BriefcaseManager.js.map +1 -1
  16. package/lib/cjs/Category.d.ts +153 -153
  17. package/lib/cjs/Category.js +243 -243
  18. package/lib/cjs/Category.js.map +1 -1
  19. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  20. package/lib/cjs/ChangeSummaryManager.js +444 -445
  21. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  22. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  23. package/lib/cjs/ChangedElementsDb.js +165 -165
  24. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  25. package/lib/cjs/ChangedElementsManager.js +88 -88
  26. package/lib/cjs/ChannelControl.d.ts +70 -0
  27. package/lib/cjs/ChannelControl.d.ts.map +1 -0
  28. package/lib/cjs/ChannelControl.js +89 -0
  29. package/lib/cjs/ChannelControl.js.map +1 -0
  30. package/lib/cjs/CheckpointManager.d.ts +121 -121
  31. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  32. package/lib/cjs/CheckpointManager.js +351 -349
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/ClassRegistry.d.ts +79 -79
  35. package/lib/cjs/ClassRegistry.js +249 -245
  36. package/lib/cjs/ClassRegistry.js.map +1 -1
  37. package/lib/cjs/CloudSqlite.d.ts +423 -350
  38. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  39. package/lib/cjs/CloudSqlite.js +189 -153
  40. package/lib/cjs/CloudSqlite.js.map +1 -1
  41. package/lib/cjs/CodeService.d.ts +437 -396
  42. package/lib/cjs/CodeService.d.ts.map +1 -1
  43. package/lib/cjs/CodeService.js +63 -63
  44. package/lib/cjs/CodeService.js.map +1 -1
  45. package/lib/cjs/CodeSpecs.d.ts +58 -55
  46. package/lib/cjs/CodeSpecs.d.ts.map +1 -1
  47. package/lib/cjs/CodeSpecs.js +154 -124
  48. package/lib/cjs/CodeSpecs.js.map +1 -1
  49. package/lib/cjs/ConcurrentQuery.d.ts +13 -13
  50. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  51. package/lib/cjs/ConcurrentQuery.js +36 -36
  52. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  53. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  54. package/lib/cjs/CustomViewState3dCreator.js +80 -81
  55. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  56. package/lib/cjs/DevTools.d.ts +74 -71
  57. package/lib/cjs/DevTools.d.ts.map +1 -1
  58. package/lib/cjs/DevTools.js +156 -154
  59. package/lib/cjs/DevTools.js.map +1 -1
  60. package/lib/cjs/DisplayStyle.d.ts +106 -106
  61. package/lib/cjs/DisplayStyle.js +253 -256
  62. package/lib/cjs/DisplayStyle.js.map +1 -1
  63. package/lib/cjs/ECDb.d.ts +194 -191
  64. package/lib/cjs/ECDb.d.ts.map +1 -1
  65. package/lib/cjs/ECDb.js +351 -350
  66. package/lib/cjs/ECDb.js.map +1 -1
  67. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  68. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  69. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  70. package/lib/cjs/ECSqlStatement.d.ts +473 -473
  71. package/lib/cjs/ECSqlStatement.js +791 -791
  72. package/lib/cjs/Element.d.ts +1113 -1109
  73. package/lib/cjs/Element.d.ts.map +1 -1
  74. package/lib/cjs/Element.js +1424 -1427
  75. package/lib/cjs/Element.js.map +1 -1
  76. package/lib/cjs/ElementAspect.d.ts +176 -179
  77. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  78. package/lib/cjs/ElementAspect.js +203 -211
  79. package/lib/cjs/ElementAspect.js.map +1 -1
  80. package/lib/cjs/ElementGraphics.d.ts +9 -9
  81. package/lib/cjs/ElementGraphics.js +41 -41
  82. package/lib/cjs/ElementGraphics.js.map +1 -1
  83. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  84. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  85. package/lib/cjs/ElementTreeWalker.js +409 -409
  86. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  87. package/lib/cjs/Entity.d.ts +106 -106
  88. package/lib/cjs/Entity.d.ts.map +1 -1
  89. package/lib/cjs/Entity.js +135 -134
  90. package/lib/cjs/Entity.js.map +1 -1
  91. package/lib/cjs/EntityReferences.d.ts +49 -49
  92. package/lib/cjs/EntityReferences.d.ts.map +1 -1
  93. package/lib/cjs/EntityReferences.js +95 -95
  94. package/lib/cjs/ExportGraphics.d.ts +317 -317
  95. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  96. package/lib/cjs/ExportGraphics.js +208 -208
  97. package/lib/cjs/ExternalSource.d.ts +96 -96
  98. package/lib/cjs/ExternalSource.js +131 -131
  99. package/lib/cjs/ExternalSource.js.map +1 -1
  100. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  101. package/lib/cjs/GeoCoordConfig.js +85 -85
  102. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  103. package/lib/cjs/GeometrySummary.d.ts +4 -4
  104. package/lib/cjs/GeometrySummary.js +333 -333
  105. package/lib/cjs/GeometrySummary.js.map +1 -1
  106. package/lib/cjs/HubMock.d.ts +94 -94
  107. package/lib/cjs/HubMock.js +220 -222
  108. package/lib/cjs/HubMock.js.map +1 -1
  109. package/lib/cjs/IModelCloneContext.d.ts +8 -8
  110. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  111. package/lib/cjs/IModelCloneContext.js +15 -15
  112. package/lib/cjs/IModelDb.d.ts +1222 -1196
  113. package/lib/cjs/IModelDb.d.ts.map +1 -1
  114. package/lib/cjs/IModelDb.js +2389 -2392
  115. package/lib/cjs/IModelDb.js.map +1 -1
  116. package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
  117. package/lib/cjs/IModelElementCloneContext.js +159 -159
  118. package/lib/cjs/IModelHost.d.ts +368 -369
  119. package/lib/cjs/IModelHost.d.ts.map +1 -1
  120. package/lib/cjs/IModelHost.js +474 -496
  121. package/lib/cjs/IModelHost.js.map +1 -1
  122. package/lib/cjs/IModelJsFs.d.ts +62 -62
  123. package/lib/cjs/IModelJsFs.js +139 -140
  124. package/lib/cjs/IModelJsFs.js.map +1 -1
  125. package/lib/cjs/IpcHost.d.ts +104 -104
  126. package/lib/cjs/IpcHost.js +276 -278
  127. package/lib/cjs/IpcHost.js.map +1 -1
  128. package/lib/cjs/LineStyle.d.ts +311 -311
  129. package/lib/cjs/LineStyle.js +295 -295
  130. package/lib/cjs/LocalHub.d.ts +162 -162
  131. package/lib/cjs/LocalHub.d.ts.map +1 -1
  132. package/lib/cjs/LocalHub.js +579 -584
  133. package/lib/cjs/LocalHub.js.map +1 -1
  134. package/lib/cjs/LocalhostIpcHost.d.ts +21 -20
  135. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  136. package/lib/cjs/LocalhostIpcHost.js +79 -81
  137. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  138. package/lib/cjs/Material.d.ts +131 -131
  139. package/lib/cjs/Material.js +180 -181
  140. package/lib/cjs/Material.js.map +1 -1
  141. package/lib/cjs/Model.d.ts +392 -392
  142. package/lib/cjs/Model.d.ts.map +1 -1
  143. package/lib/cjs/Model.js +489 -485
  144. package/lib/cjs/Model.js.map +1 -1
  145. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  146. package/lib/cjs/NativeAppStorage.js +202 -202
  147. package/lib/cjs/NativeAppStorage.js.map +1 -1
  148. package/lib/cjs/NativeHost.d.ts +52 -52
  149. package/lib/cjs/NativeHost.d.ts.map +1 -1
  150. package/lib/cjs/NativeHost.js +158 -163
  151. package/lib/cjs/NativeHost.js.map +1 -1
  152. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  153. package/lib/cjs/NavigationRelationship.js +225 -225
  154. package/lib/cjs/NavigationRelationship.js.map +1 -1
  155. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  156. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  157. package/lib/cjs/PromiseMemoizer.js +101 -101
  158. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  159. package/lib/cjs/PropertyStore.d.ts +132 -132
  160. package/lib/cjs/PropertyStore.js +11 -11
  161. package/lib/cjs/Relationship.d.ts +416 -416
  162. package/lib/cjs/Relationship.js +494 -494
  163. package/lib/cjs/Relationship.js.map +1 -1
  164. package/lib/cjs/RpcBackend.d.ts +5 -5
  165. package/lib/cjs/RpcBackend.js +32 -32
  166. package/lib/cjs/SQLiteDb.d.ts +219 -219
  167. package/lib/cjs/SQLiteDb.js +212 -214
  168. package/lib/cjs/SQLiteDb.js.map +1 -1
  169. package/lib/cjs/Schema.d.ts +55 -55
  170. package/lib/cjs/Schema.js +83 -83
  171. package/lib/cjs/Schema.js.map +1 -1
  172. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  173. package/lib/cjs/ServerBasedLocks.js +168 -168
  174. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  175. package/lib/cjs/SqliteStatement.d.ts +360 -360
  176. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  177. package/lib/cjs/SqliteStatement.js +586 -586
  178. package/lib/cjs/Texture.d.ts +58 -58
  179. package/lib/cjs/Texture.js +82 -82
  180. package/lib/cjs/Texture.js.map +1 -1
  181. package/lib/cjs/TileStorage.d.ts +44 -18
  182. package/lib/cjs/TileStorage.d.ts.map +1 -1
  183. package/lib/cjs/TileStorage.js +109 -90
  184. package/lib/cjs/TileStorage.js.map +1 -1
  185. package/lib/cjs/TxnManager.d.ts +202 -202
  186. package/lib/cjs/TxnManager.d.ts.map +1 -1
  187. package/lib/cjs/TxnManager.js +356 -356
  188. package/lib/cjs/TxnManager.js.map +1 -1
  189. package/lib/cjs/ViewDefinition.d.ts +435 -439
  190. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  191. package/lib/cjs/ViewDefinition.js +646 -646
  192. package/lib/cjs/ViewDefinition.js.map +1 -1
  193. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  194. package/lib/cjs/ViewStateHydrator.js +103 -103
  195. package/lib/cjs/core-backend.d.ts +183 -184
  196. package/lib/cjs/core-backend.d.ts.map +1 -1
  197. package/lib/cjs/core-backend.js +207 -204
  198. package/lib/cjs/core-backend.js.map +1 -1
  199. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  200. package/lib/cjs/domains/FunctionalElements.js +145 -145
  201. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  202. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  203. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  204. package/lib/cjs/domains/FunctionalSchema.js +39 -40
  205. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  206. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  207. package/lib/cjs/domains/GenericElements.js +263 -263
  208. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  209. package/lib/cjs/domains/GenericSchema.js +28 -28
  210. package/lib/cjs/rpc/multipart.d.ts +11 -11
  211. package/lib/cjs/rpc/multipart.js +71 -71
  212. package/lib/cjs/rpc/tracing.d.ts +28 -28
  213. package/lib/cjs/rpc/tracing.js +73 -74
  214. package/lib/cjs/rpc/tracing.js.map +1 -1
  215. package/lib/cjs/rpc/web/logging.d.ts +9 -9
  216. package/lib/cjs/rpc/web/logging.js +43 -43
  217. package/lib/cjs/rpc/web/request.d.ts +6 -6
  218. package/lib/cjs/rpc/web/request.js +73 -74
  219. package/lib/cjs/rpc/web/request.js.map +1 -1
  220. package/lib/cjs/rpc/web/response.d.ts +6 -6
  221. package/lib/cjs/rpc/web/response.js +105 -106
  222. package/lib/cjs/rpc/web/response.js.map +1 -1
  223. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  224. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  225. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
  226. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
  227. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  228. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
  229. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  230. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +190 -205
  231. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  233. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
  234. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  235. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  236. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
  237. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  238. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  239. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  240. package/lib/cjs/workspace/Settings.d.ts +186 -186
  241. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  242. package/lib/cjs/workspace/Settings.js +154 -155
  243. package/lib/cjs/workspace/Settings.js.map +1 -1
  244. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  245. package/lib/cjs/workspace/SettingsSchemas.js +190 -191
  246. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  247. package/lib/cjs/workspace/Workspace.d.ts +411 -414
  248. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  249. package/lib/cjs/workspace/Workspace.js +521 -543
  250. package/lib/cjs/workspace/Workspace.js.map +1 -1
  251. package/package.json +22 -24
  252. package/lib/cjs/AliCloudStorageService.d.ts +0 -24
  253. package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
  254. package/lib/cjs/AliCloudStorageService.js +0 -72
  255. package/lib/cjs/AliCloudStorageService.js.map +0 -1
  256. package/lib/cjs/CloudStorageBackend.d.ts +0 -59
  257. package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
  258. package/lib/cjs/CloudStorageBackend.js +0 -174
  259. package/lib/cjs/CloudStorageBackend.js.map +0 -1
@@ -1,544 +1,522 @@
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 Workspace
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EditableWorkspaceDb = exports.ITwinWorkspaceDb = exports.ITwinWorkspaceContainer = exports.ITwinWorkspace = exports.WorkspaceSetting = void 0;
11
- const crypto_1 = require("crypto");
12
- const fs = require("fs-extra");
13
- const path_1 = require("path");
14
- const semver = require("semver");
15
- const core_bentley_1 = require("@itwin/core-bentley");
16
- const core_common_1 = require("@itwin/core-common");
17
- const CloudSqlite_1 = require("../CloudSqlite");
18
- const IModelHost_1 = require("../IModelHost");
19
- const IModelJsFs_1 = require("../IModelJsFs");
20
- const SQLiteDb_1 = require("../SQLiteDb");
21
- const Settings_1 = require("./Settings");
22
- const SettingsSchemas_1 = require("./SettingsSchemas");
23
- /* eslint-disable @typescript-eslint/naming-convention */
24
- // cspell:ignore rowid primarykey julianday
25
- /** The Settings used by Workspace api
26
- * @beta
27
- */
28
- exports.WorkspaceSetting = {
29
- Accounts: "cloud/accounts",
30
- Containers: "cloud/containers",
31
- Databases: "workspace/databases",
32
- };
33
- /** @internal */
34
- class ITwinWorkspace {
35
- constructor(settings, opts) {
36
- var _a;
37
- this._containers = new Map();
38
- this.settings = settings;
39
- this.containerDir = (_a = opts === null || opts === void 0 ? void 0 : opts.containerDir) !== null && _a !== void 0 ? _a : (0, path_1.join)(IModelHost_1.IModelHost.cacheDir, "Workspace");
40
- this._cloudCache = opts === null || opts === void 0 ? void 0 : opts.testCloudCache;
41
- let settingsFiles = opts === null || opts === void 0 ? void 0 : opts.settingsFiles;
42
- if (settingsFiles) {
43
- if (typeof settingsFiles === "string")
44
- settingsFiles = [settingsFiles];
45
- settingsFiles.forEach((file) => settings.addFile(file, Settings_1.SettingsPriority.application));
46
- }
47
- }
48
- get cloudCache() {
49
- if (undefined === this._cloudCache)
50
- this._cloudCache = ITwinWorkspace.getSharedCloudCache();
51
- return this._cloudCache;
52
- }
53
- static getSharedCloudCache() {
54
- if (undefined === this._sharedCloudCache) {
55
- const rootDir = (0, path_1.join)(IModelHost_1.IModelHost.cacheDir, "Workspace", "cloud");
56
- IModelJsFs_1.IModelJsFs.recursiveMkDirSync(rootDir);
57
- this._sharedCloudCache = CloudSqlite_1.CloudSqlite.createCloudCache({ rootDir, cacheSize: "20G", name: "workspace" });
58
- }
59
- return this._sharedCloudCache;
60
- }
61
- static finalize() {
62
- if (this._sharedCloudCache) {
63
- this._sharedCloudCache.destroy();
64
- this._sharedCloudCache = undefined;
65
- }
66
- }
67
- addContainer(toAdd) {
68
- if (undefined !== this._containers.get(toAdd.id))
69
- throw new Error("container already exists in workspace");
70
- this._containers.set(toAdd.id, toAdd);
71
- }
72
- findContainer(containerId) {
73
- return this._containers.get(containerId);
74
- }
75
- getContainer(props, account) {
76
- var _a;
77
- return (_a = this.findContainer(props.containerId)) !== null && _a !== void 0 ? _a : new ITwinWorkspaceContainer(this, props, account);
78
- }
79
- getWorkspaceDbFromProps(dbProps, containerProps, account) {
80
- return this.getContainer(containerProps, account).getWorkspaceDb(dbProps);
81
- }
82
- async getWorkspaceDb(dbAlias, tokenFunc) {
83
- const dbProps = this.resolveDatabase(dbAlias);
84
- const containerProps = this.resolveContainer(dbProps.containerName);
85
- const account = containerProps.accountName !== "" ? this.resolveAccount(containerProps.accountName) : undefined;
86
- let container = this.findContainer(containerProps.containerId);
87
- if (undefined === container) {
88
- if (tokenFunc && account)
89
- containerProps.accessToken = await tokenFunc(containerProps, account);
90
- container = this.getContainer(containerProps, account);
91
- }
92
- return container === null || container === void 0 ? void 0 : container.getWorkspaceDb(dbProps);
93
- }
94
- loadSettingsDictionary(settingRsc, db, priority) {
95
- const setting = db.getString(settingRsc);
96
- if (undefined === setting)
97
- throw new Error(`could not load setting resource ${settingRsc}`);
98
- this.settings.addJson(`${db.container.id}/${db.dbName}/${settingRsc}`, priority, setting);
99
- }
100
- close() {
101
- this.settings.close();
102
- for (const [_id, container] of this._containers)
103
- container.close();
104
- this._containers.clear();
105
- }
106
- resolveAccount(accountName) {
107
- const resolved = this.settings.resolveSetting(exports.WorkspaceSetting.Accounts, (val) => {
108
- if (Array.isArray(val)) {
109
- for (const entry of val) {
110
- if (typeof entry === "object" && entry.name === accountName)
111
- return SettingsSchemas_1.SettingsSchemas.validateArrayObject(entry, exports.WorkspaceSetting.Accounts, accountName);
112
- }
113
- }
114
- return undefined; // keep going through all settings dictionaries
115
- });
116
- if (resolved === undefined)
117
- throw new Error(`no setting "${exports.WorkspaceSetting.Accounts}" entry for "${accountName}"`);
118
- return resolved;
119
- }
120
- resolveContainer(containerName) {
121
- const resolved = this.settings.resolveSetting(exports.WorkspaceSetting.Containers, (val) => {
122
- if (Array.isArray(val)) {
123
- for (const entry of val) {
124
- if (typeof entry === "object" && entry.name === containerName)
125
- return SettingsSchemas_1.SettingsSchemas.validateArrayObject(entry, exports.WorkspaceSetting.Containers, containerName);
126
- }
127
- }
128
- return undefined; // keep going through all settings dictionaries
129
- });
130
- if (resolved === undefined)
131
- throw new Error(`no setting "${exports.WorkspaceSetting.Containers}" entry for "${containerName}"`);
132
- return resolved;
133
- }
134
- resolveDatabase(databaseName) {
135
- const resolved = this.settings.resolveSetting(exports.WorkspaceSetting.Databases, (val) => {
136
- if (Array.isArray(val)) {
137
- for (const entry of val) {
138
- if (typeof entry === "object" && entry.name === databaseName)
139
- return SettingsSchemas_1.SettingsSchemas.validateArrayObject(entry, exports.WorkspaceSetting.Databases, databaseName);
140
- }
141
- }
142
- return undefined; // keep going through all settings dictionaries
143
- });
144
- if (resolved === undefined)
145
- throw new Error(`no setting "${exports.WorkspaceSetting.Databases}" entry for "${databaseName}"`);
146
- return resolved;
147
- }
148
- }
149
- exports.ITwinWorkspace = ITwinWorkspace;
150
- /** @internal */
151
- class ITwinWorkspaceContainer {
152
- constructor(workspace, props, account) {
153
- this._wsDbs = new Map();
154
- ITwinWorkspaceContainer.validateContainerId(props.containerId);
155
- this.workspace = workspace;
156
- this.id = props.containerId;
157
- if ((account === null || account === void 0 ? void 0 : account.accessName) && account.storageType)
158
- this.cloudContainer = CloudSqlite_1.CloudSqlite.createCloudContainer({ accessToken: "", ...props, ...account });
159
- workspace.addContainer(this);
160
- this.filesDir = (0, path_1.join)(this.dirName, "Files");
161
- const cloudContainer = this.cloudContainer;
162
- if (undefined === cloudContainer)
163
- return;
164
- cloudContainer.connect(this.workspace.cloudCache);
165
- if (false !== props.syncOnConnect) {
166
- try {
167
- cloudContainer.checkForChanges();
168
- }
169
- catch (e) {
170
- // must be offline
171
- }
172
- }
173
- }
174
- get dirName() { return (0, path_1.join)(this.workspace.containerDir, this.id); }
175
- static noLeadingOrTrailingSpaces(name, msg) {
176
- if (name.trim() !== name)
177
- throw new Error(`${msg} [${name}] may not have leading or tailing spaces`);
178
- }
179
- /** rules for ContainerIds (from Azure, see https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata)
180
- * - may only contain lower case letters, numbers or dashes
181
- * - may not start or end with with a dash nor have more than one dash in a row
182
- * - may not be shorter than 3 or longer than 63 characters
183
- */
184
- static validateContainerId(id) {
185
- if (!/^(?=.{3,63}$)[a-z0-9]+(-[a-z0-9]+)*$/g.test(id))
186
- throw new Error(`invalid containerId: [${id}]`);
187
- }
188
- static validateDbName(dbName) {
189
- if (dbName === "" || dbName.length > 255 || /[#\.<>:"/\\"`'|?*\u0000-\u001F]/g.test(dbName) || /^(con|prn|aux|nul|com\d|lpt\d)$/i.test(dbName))
190
- throw new Error(`invalid dbName: [${dbName}]`);
191
- this.noLeadingOrTrailingSpaces(dbName, "dbName");
192
- }
193
- static validateVersion(version) {
194
- var _a, _b;
195
- version = version !== null && version !== void 0 ? version : "1.0.0";
196
- if (version) {
197
- const opts = { loose: true, includePrerelease: true };
198
- // clean allows prerelease, so try it first. If that fails attempt to coerce it (coerce strips prerelease even if you say not to.)
199
- const semVersion = (_a = semver.clean(version, opts)) !== null && _a !== void 0 ? _a : (_b = semver.coerce(version, opts)) === null || _b === void 0 ? void 0 : _b.version;
200
- if (!semVersion)
201
- throw new Error("invalid version specification");
202
- version = semVersion;
203
- }
204
- return version;
205
- }
206
- static parseDbFileName(dbFileName) {
207
- const parts = dbFileName.split(":");
208
- return { dbName: parts[0], version: parts[1] };
209
- }
210
- static makeDbFileName(dbName, version) {
211
- return `${dbName}:${this.validateVersion(version)}`;
212
- }
213
- static resolveCloudFileName(cloudContainer, props) {
214
- var _a;
215
- const dbName = props.dbName;
216
- const dbs = cloudContainer.queryDatabases(`${dbName}*`); // get all databases that start with dbName
217
- const versions = [];
218
- for (const db of dbs) {
219
- const thisDb = ITwinWorkspaceContainer.parseDbFileName(db);
220
- if (thisDb.dbName === dbName && "string" === typeof thisDb.version && thisDb.version.length > 0)
221
- versions.push(thisDb.version);
222
- }
223
- if (versions.length === 0)
224
- versions[0] = "1.0.0";
225
- const range = (_a = props.version) !== null && _a !== void 0 ? _a : "*";
226
- try {
227
- const version = semver.maxSatisfying(versions, range, { loose: true, includePrerelease: props.includePrerelease });
228
- if (version)
229
- return `${dbName}:${version}`;
230
- }
231
- catch (e) {
232
- }
233
- throw new Error(`No version of [${dbName}] available for "${range}"`);
234
- }
235
- /**
236
- * Create a copy of an existing [[WorkspaceDb]] in a cloud container with a new version number.
237
- * @param cloudContainer The attached cloud container holding the existing WorkspaceDb
238
- * @param fromProps Properties that describe the source WorkspaceDb for the new version
239
- * @param versionType The type of version increment to apply to the existing version.
240
- * @note This requires that the cloudContainer is attached and the write lock on the container be held. The copy should be modified with
241
- * new content before the write lock is released, and thereafter should never be modified again.
242
- */
243
- static async makeNewVersion(cloudContainer, fromProps, versionType) {
244
- const oldName = this.resolveCloudFileName(cloudContainer, fromProps);
245
- const oldDb = this.parseDbFileName(oldName);
246
- const newVersion = semver.inc(oldDb.version, versionType);
247
- if (!newVersion)
248
- throw new Error("invalid version");
249
- const newName = this.makeDbFileName(oldDb.dbName, newVersion);
250
- await cloudContainer.copyDatabase(oldName, newName);
251
- return { oldName, newName };
252
- }
253
- /**
254
- * Convert a WorkspaceDb.Props specification into a DbFileName. For cloud-based containers, this resolves to the dbName, incorporating the appropriate
255
- * version. For file-based containers, this returns a local filename of a WorkspaceDb file with the extension ".itwin-workspace"
256
- */
257
- resolveDbFileName(props) {
258
- const cloudContainer = this.cloudContainer;
259
- if (undefined === cloudContainer)
260
- return (0, path_1.join)(this.dirName, `${props.dbName}.${ITwinWorkspaceDb.fileExt}`); // local file, versions not allowed
261
- return ITwinWorkspaceContainer.resolveCloudFileName(cloudContainer, props);
262
- }
263
- addWorkspaceDb(toAdd) {
264
- if (undefined !== this._wsDbs.get(toAdd.dbName))
265
- throw new Error(`workspaceDb ${toAdd.dbName} already exists in workspace`);
266
- this._wsDbs.set(toAdd.dbName, toAdd);
267
- }
268
- getWorkspaceDb(props) {
269
- var _a;
270
- const db = (_a = this._wsDbs.get(props.dbName)) !== null && _a !== void 0 ? _a : new ITwinWorkspaceDb(props, this);
271
- if (!db.isOpen)
272
- db.open();
273
- return db;
274
- }
275
- dropWorkspaceDb(toDrop) {
276
- const name = toDrop.dbName;
277
- const wsDb = this._wsDbs.get(name);
278
- if (wsDb === toDrop) {
279
- this._wsDbs.delete(name);
280
- wsDb.close();
281
- }
282
- }
283
- close() {
284
- var _a;
285
- for (const [_name, db] of this._wsDbs)
286
- db.close();
287
- this._wsDbs.clear();
288
- (_a = this.cloudContainer) === null || _a === void 0 ? void 0 : _a.disconnect();
289
- }
290
- /** Delete all local files extracted by [[WorkspaceDb.getFile]] for this container. */
291
- purgeContainerFiles() {
292
- IModelJsFs_1.IModelJsFs.purgeDirSync(this.filesDir);
293
- }
294
- }
295
- exports.ITwinWorkspaceContainer = ITwinWorkspaceContainer;
296
- /**
297
- * Implementation of WorkspaceDb
298
- * @internal
299
- */
300
- class ITwinWorkspaceDb {
301
- constructor(props, container) {
302
- /** the SQLiteDb for this WorkspaceDb*/
303
- this.sqliteDb = new SQLiteDb_1.SQLiteDb();
304
- /** called before db is closed */
305
- this.onClose = new core_bentley_1.BeEvent();
306
- ITwinWorkspaceContainer.validateDbName(props.dbName);
307
- this.dbName = props.dbName;
308
- this.container = container;
309
- this.dbFileName = container.resolveDbFileName(props);
310
- container.addWorkspaceDb(this);
311
- }
312
- /** true if this WorkspaceDb is currently open */
313
- get isOpen() { return this.sqliteDb.isOpen; }
314
- queryFileResource(rscName) {
315
- const info = this.sqliteDb.nativeDb.queryEmbeddedFile(rscName);
316
- if (undefined === info)
317
- return undefined;
318
- // since resource names can contain illegal characters, path separators, etc., we make the local file name from its hash, in hex.
319
- let localFileName = (0, path_1.join)(this.container.filesDir, (0, crypto_1.createHash)("sha1").update(this.dbFileName).update(rscName).digest("hex"));
320
- if (info.fileExt !== "") // since some applications may expect to see the extension, append it here if it was supplied.
321
- localFileName = `${localFileName}.${info.fileExt}`;
322
- return { localFileName, info };
323
- }
324
- open() {
325
- this.sqliteDb.openDb(this.dbFileName, core_bentley_1.OpenMode.Readonly, this.container.cloudContainer);
326
- }
327
- close() {
328
- if (this.isOpen) {
329
- this.onClose.raiseEvent();
330
- this.sqliteDb.closeDb();
331
- this.container.dropWorkspaceDb(this);
332
- }
333
- }
334
- getString(rscName) {
335
- return this.sqliteDb.withSqliteStatement("SELECT value from strings WHERE id=?", (stmt) => {
336
- stmt.bindString(1, rscName);
337
- return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValueString(0) : undefined;
338
- });
339
- }
340
- /** Get a BlobIO reader for a blob WorkspaceResource.
341
- * @note when finished, caller *must* call `close` on the BlobIO.
342
- */
343
- getBlobReader(rscName) {
344
- return this.sqliteDb.withSqliteStatement("SELECT rowid from blobs WHERE id=?", (stmt) => {
345
- stmt.bindString(1, rscName);
346
- const blobReader = SQLiteDb_1.SQLiteDb.createBlobIO();
347
- blobReader.open(this.sqliteDb.nativeDb, { tableName: "blobs", columnName: "value", row: stmt.getValueInteger(0) });
348
- return blobReader;
349
- });
350
- }
351
- getBlob(rscName) {
352
- return this.sqliteDb.withSqliteStatement("SELECT value from blobs WHERE id=?", (stmt) => {
353
- stmt.bindString(1, rscName);
354
- return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValueBlob(0) : undefined;
355
- });
356
- }
357
- getFile(rscName, targetFileName) {
358
- const file = this.queryFileResource(rscName);
359
- if (!file)
360
- return undefined;
361
- const info = file.info;
362
- const localFileName = targetFileName !== null && targetFileName !== void 0 ? targetFileName : file.localFileName;
363
- // check whether the file is already up to date.
364
- const stat = fs.existsSync(localFileName) && fs.statSync(localFileName);
365
- if (stat && Math.round(stat.mtimeMs) === info.date && stat.size === info.size)
366
- return localFileName; // yes, we're done
367
- // extractEmbeddedFile fails if the file exists or if the directory does not exist
368
- if (stat)
369
- fs.removeSync(localFileName);
370
- else
371
- IModelJsFs_1.IModelJsFs.recursiveMkDirSync((0, path_1.dirname)(localFileName));
372
- this.sqliteDb.nativeDb.extractEmbeddedFile({ name: rscName, localFileName });
373
- const date = new Date(info.date);
374
- fs.utimesSync(localFileName, date, date); // set the last-modified date of the file to match date in container
375
- fs.chmodSync(localFileName, "0444"); // set file readonly
376
- return localFileName;
377
- }
378
- prefetch(opts) {
379
- const cloudContainer = this.container.cloudContainer;
380
- if (cloudContainer === undefined)
381
- throw new Error("no cloud container to prefetch");
382
- return CloudSqlite_1.CloudSqlite.startCloudPrefetch(cloudContainer, this.dbFileName, opts);
383
- }
384
- }
385
- exports.ITwinWorkspaceDb = ITwinWorkspaceDb;
386
- /** file extension for local WorkspaceDbs */
387
- ITwinWorkspaceDb.fileExt = "itwin-workspace";
388
- /**
389
- * An editable [[WorkspaceDb]]. This is used by administrators for creating and modifying `WorkspaceDb`s.
390
- * For cloud-backed containers, the write token must be obtained before this class may be used. Only one user at at time
391
- * may be editing.
392
- * @internal
393
- */
394
- class EditableWorkspaceDb extends ITwinWorkspaceDb {
395
- static validateResourceName(name) {
396
- ITwinWorkspaceContainer.noLeadingOrTrailingSpaces(name, "resource name");
397
- if (name.length > 1024)
398
- throw new Error("resource name too long");
399
- }
400
- validateResourceSize(val) {
401
- const len = typeof val === "string" ? val.length : val.byteLength;
402
- if (len > (1024 * 1024 * 1024)) // one gigabyte
403
- throw new Error("value is too large");
404
- }
405
- open() {
406
- this.sqliteDb.openDb(this.dbFileName, core_bentley_1.OpenMode.ReadWrite, this.container.cloudContainer);
407
- }
408
- getFileModifiedTime(localFileName) {
409
- return Math.round(fs.statSync(localFileName).mtimeMs);
410
- }
411
- performWriteSql(rscName, sql, bind) {
412
- this.sqliteDb.withSqliteStatement(sql, (stmt) => {
413
- stmt.bindString(1, rscName);
414
- bind === null || bind === void 0 ? void 0 : bind(stmt);
415
- const rc = stmt.step();
416
- if (core_bentley_1.DbResult.BE_SQLITE_DONE !== rc) {
417
- if (core_bentley_1.DbResult.BE_SQLITE_CONSTRAINT_PRIMARYKEY === rc)
418
- throw new core_common_1.IModelError(rc, `resource "${rscName}" already exists`);
419
- throw new core_common_1.IModelError(rc, `workspace [${sql}]`);
420
- }
421
- });
422
- this.sqliteDb.saveChanges();
423
- }
424
- async createDb(version) {
425
- if (!this.container.cloudContainer) {
426
- EditableWorkspaceDb.createEmpty(this.dbFileName);
427
- }
428
- else {
429
- // currently the only way to create a workspaceDb in a cloud container is to create a temporary workspaceDb and upload it.
430
- const tempDbFile = (0, path_1.join)(IModelHost_1.KnownLocations.tmpdir, `empty.${ITwinWorkspaceDb.fileExt}`);
431
- if (fs.existsSync(tempDbFile))
432
- IModelJsFs_1.IModelJsFs.removeSync(tempDbFile);
433
- EditableWorkspaceDb.createEmpty(tempDbFile);
434
- this.dbFileName = ITwinWorkspaceContainer.makeDbFileName(this.dbName, version);
435
- await CloudSqlite_1.CloudSqlite.uploadDb(this.container.cloudContainer, { localFileName: tempDbFile, dbName: this.dbFileName });
436
- IModelJsFs_1.IModelJsFs.removeSync(tempDbFile);
437
- }
438
- this.open();
439
- }
440
- /** Create a new, empty, EditableWorkspaceDb for importing Workspace resources. */
441
- static createEmpty(fileName) {
442
- const db = new SQLiteDb_1.SQLiteDb();
443
- IModelJsFs_1.IModelJsFs.recursiveMkDirSync((0, path_1.dirname)(fileName));
444
- db.createDb(fileName);
445
- const timeStampCol = "lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))";
446
- db.executeSQL(`CREATE TABLE strings(id TEXT PRIMARY KEY NOT NULL,value TEXT,${timeStampCol})`);
447
- db.executeSQL(`CREATE TABLE blobs(id TEXT PRIMARY KEY NOT NULL,value BLOB,${timeStampCol})`);
448
- const createTrigger = (tableName) => {
449
- db.executeSQL(`CREATE TRIGGER ${tableName}_timeStamp AFTER UPDATE ON ${tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${tableName} SET lastMod=julianday('now') WHERE id=new.id; END`);
450
- };
451
- createTrigger("strings");
452
- createTrigger("blobs");
453
- db.closeDb(true);
454
- }
455
- /** Add a new string resource to this WorkspaceDb.
456
- * @param rscName The name of the string resource.
457
- * @param val The string to save.
458
- */
459
- addString(rscName, val) {
460
- EditableWorkspaceDb.validateResourceName(rscName);
461
- this.validateResourceSize(val);
462
- this.performWriteSql(rscName, "INSERT INTO strings(id,value) VALUES(?,?)", (stmt) => stmt.bindString(2, val));
463
- }
464
- /** Update an existing string resource with a new value.
465
- * @param rscName The name of the string resource.
466
- * @param val The new value.
467
- * @throws if rscName does not exist
468
- */
469
- updateString(rscName, val) {
470
- this.validateResourceSize(val);
471
- this.performWriteSql(rscName, "UPDATE strings SET value=?2 WHERE id=?1", (stmt) => stmt.bindString(2, val));
472
- }
473
- /** Remove a string resource. */
474
- removeString(rscName) {
475
- this.performWriteSql(rscName, "DELETE FROM strings WHERE id=?");
476
- }
477
- /** Add a new blob resource to this WorkspaceDb.
478
- * @param rscName The name of the blob resource.
479
- * @param val The blob to save.
480
- */
481
- addBlob(rscName, val) {
482
- EditableWorkspaceDb.validateResourceName(rscName);
483
- this.validateResourceSize(val);
484
- this.performWriteSql(rscName, "INSERT INTO blobs(id,value) VALUES(?,?)", (stmt) => stmt.bindBlob(2, val));
485
- }
486
- /** Update an existing blob resource with a new value.
487
- * @param rscName The name of the blob resource.
488
- * @param val The new value.
489
- * @throws if rscName does not exist
490
- */
491
- updateBlob(rscName, val) {
492
- this.validateResourceSize(val);
493
- this.performWriteSql(rscName, "UPDATE blobs SET value=?2 WHERE id=?1", (stmt) => stmt.bindBlob(2, val));
494
- }
495
- /** Get a BlobIO writer for a previously-added blob WorkspaceResource.
496
- * @note after writing is complete, caller must call `close` on the BlobIO and must call `saveChanges` on the `db`.
497
- */
498
- getBlobWriter(rscName) {
499
- return this.sqliteDb.withSqliteStatement("SELECT rowid from blobs WHERE id=?", (stmt) => {
500
- stmt.bindString(1, rscName);
501
- const blobWriter = SQLiteDb_1.SQLiteDb.createBlobIO();
502
- blobWriter.open(this.sqliteDb.nativeDb, { tableName: "blobs", columnName: "value", row: stmt.getValueInteger(0), writeable: true });
503
- return blobWriter;
504
- });
505
- }
506
- /** Remove a blob resource. */
507
- removeBlob(rscName) {
508
- this.performWriteSql(rscName, "DELETE FROM blobs WHERE id=?");
509
- }
510
- /** Copy the contents of an existing local file into this WorkspaceDb as a file resource.
511
- * @param rscName The name of the file resource.
512
- * @param localFileName The name of a local file to be read.
513
- * @param fileExt The extension (do not include the leading ".") to be appended to the generated fileName
514
- * when this WorkspaceDb is extracted from the WorkspaceDb. By default the characters after the last "." in `localFileName`
515
- * are used. Pass this argument to override that.
516
- */
517
- addFile(rscName, localFileName, fileExt) {
518
- EditableWorkspaceDb.validateResourceName(rscName);
519
- fileExt = fileExt !== null && fileExt !== void 0 ? fileExt : (0, path_1.extname)(localFileName);
520
- if ((fileExt === null || fileExt === void 0 ? void 0 : fileExt[0]) === ".")
521
- fileExt = fileExt.slice(1);
522
- this.sqliteDb.nativeDb.embedFile({ name: rscName, localFileName, date: this.getFileModifiedTime(localFileName), fileExt });
523
- }
524
- /** Replace an existing file resource with the contents of another local file.
525
- * @param rscName The name of the file resource.
526
- * @param localFileName The name of a local file to be read.
527
- * @throws if rscName does not exist
528
- */
529
- updateFile(rscName, localFileName) {
530
- this.queryFileResource(rscName); // throws if not present
531
- this.sqliteDb.nativeDb.replaceEmbeddedFile({ name: rscName, localFileName, date: this.getFileModifiedTime(localFileName) });
532
- }
533
- /** Remove a file resource. */
534
- removeFile(rscName) {
535
- const file = this.queryFileResource(rscName);
536
- if (undefined === file)
537
- throw new Error(`file resource "${rscName}" does not exist`);
538
- if (file && fs.existsSync(file.localFileName))
539
- fs.unlinkSync(file.localFileName);
540
- this.sqliteDb.nativeDb.removeEmbeddedFile(rscName);
541
- }
542
- }
543
- exports.EditableWorkspaceDb = EditableWorkspaceDb;
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 Workspace
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.EditableWorkspaceDb = exports.ITwinWorkspaceDb = exports.ITwinWorkspaceContainer = exports.ITwinWorkspace = exports.WorkspaceSetting = void 0;
11
+ const crypto_1 = require("crypto");
12
+ const fs = require("fs-extra");
13
+ const path_1 = require("path");
14
+ const semver = require("semver");
15
+ const core_bentley_1 = require("@itwin/core-bentley");
16
+ const core_common_1 = require("@itwin/core-common");
17
+ const CloudSqlite_1 = require("../CloudSqlite");
18
+ const IModelHost_1 = require("../IModelHost");
19
+ const IModelJsFs_1 = require("../IModelJsFs");
20
+ const SQLiteDb_1 = require("../SQLiteDb");
21
+ const Settings_1 = require("./Settings");
22
+ const SettingsSchemas_1 = require("./SettingsSchemas");
23
+ /* eslint-disable @typescript-eslint/naming-convention */
24
+ // cspell:ignore rowid primarykey julianday
25
+ /** The Settings used by Workspace api
26
+ * @beta
27
+ */
28
+ exports.WorkspaceSetting = {
29
+ Accounts: "cloud/accounts",
30
+ Containers: "cloud/containers",
31
+ Databases: "workspace/databases",
32
+ };
33
+ /** @internal */
34
+ class ITwinWorkspace {
35
+ getCloudCache() {
36
+ return this._cloudCache ??= CloudSqlite_1.CloudSqlite.CloudCaches.getCache({ cacheName: "Workspace", cacheSize: "20G" });
37
+ }
38
+ constructor(settings, opts) {
39
+ this._containers = new Map();
40
+ this.settings = settings;
41
+ this.containerDir = opts?.containerDir ?? (0, path_1.join)(IModelHost_1.IModelHost.cacheDir, "Workspace");
42
+ this._cloudCache = opts?.testCloudCache;
43
+ let settingsFiles = opts?.settingsFiles;
44
+ if (settingsFiles) {
45
+ if (typeof settingsFiles === "string")
46
+ settingsFiles = [settingsFiles];
47
+ settingsFiles.forEach((file) => settings.addFile(file, Settings_1.SettingsPriority.application));
48
+ }
49
+ }
50
+ addContainer(toAdd) {
51
+ if (undefined !== this._containers.get(toAdd.id))
52
+ throw new Error("container already exists in workspace");
53
+ this._containers.set(toAdd.id, toAdd);
54
+ }
55
+ findContainer(containerId) {
56
+ return this._containers.get(containerId);
57
+ }
58
+ getContainer(props, account) {
59
+ return this.findContainer(props.containerId) ?? new ITwinWorkspaceContainer(this, props, account);
60
+ }
61
+ getWorkspaceDbFromProps(dbProps, containerProps, account) {
62
+ return this.getContainer(containerProps, account).getWorkspaceDb(dbProps);
63
+ }
64
+ async getWorkspaceDb(dbAlias, tokenFunc) {
65
+ const dbProps = this.resolveDatabase(dbAlias);
66
+ const containerProps = this.resolveContainer(dbProps.containerName);
67
+ const account = containerProps.accountName !== "" ? this.resolveAccount(containerProps.accountName) : undefined;
68
+ let container = this.findContainer(containerProps.containerId);
69
+ if (undefined === container) {
70
+ if (tokenFunc && account)
71
+ containerProps.accessToken = await tokenFunc(containerProps, account);
72
+ container = this.getContainer(containerProps, account);
73
+ }
74
+ return container?.getWorkspaceDb(dbProps);
75
+ }
76
+ loadSettingsDictionary(settingRsc, db, priority) {
77
+ const setting = db.getString(settingRsc);
78
+ if (undefined === setting)
79
+ throw new Error(`could not load setting resource ${settingRsc}`);
80
+ this.settings.addJson(`${db.container.id}/${db.dbName}/${settingRsc}`, priority, setting);
81
+ }
82
+ close() {
83
+ this.settings.close();
84
+ for (const [_id, container] of this._containers)
85
+ container.close();
86
+ this._containers.clear();
87
+ }
88
+ resolveAccount(accountName) {
89
+ const resolved = this.settings.resolveSetting(exports.WorkspaceSetting.Accounts, (val) => {
90
+ if (Array.isArray(val)) {
91
+ for (const entry of val) {
92
+ if (typeof entry === "object" && entry.name === accountName)
93
+ return SettingsSchemas_1.SettingsSchemas.validateArrayObject(entry, exports.WorkspaceSetting.Accounts, accountName);
94
+ }
95
+ }
96
+ return undefined; // keep going through all settings dictionaries
97
+ });
98
+ if (resolved === undefined)
99
+ throw new Error(`no setting "${exports.WorkspaceSetting.Accounts}" entry for "${accountName}"`);
100
+ return resolved;
101
+ }
102
+ resolveContainer(containerName) {
103
+ const resolved = this.settings.resolveSetting(exports.WorkspaceSetting.Containers, (val) => {
104
+ if (Array.isArray(val)) {
105
+ for (const entry of val) {
106
+ if (typeof entry === "object" && entry.name === containerName)
107
+ return SettingsSchemas_1.SettingsSchemas.validateArrayObject(entry, exports.WorkspaceSetting.Containers, containerName);
108
+ }
109
+ }
110
+ return undefined; // keep going through all settings dictionaries
111
+ });
112
+ if (resolved === undefined)
113
+ throw new Error(`no setting "${exports.WorkspaceSetting.Containers}" entry for "${containerName}"`);
114
+ return resolved;
115
+ }
116
+ resolveDatabase(databaseName) {
117
+ const resolved = this.settings.resolveSetting(exports.WorkspaceSetting.Databases, (val) => {
118
+ if (Array.isArray(val)) {
119
+ for (const entry of val) {
120
+ if (typeof entry === "object" && entry.name === databaseName)
121
+ return SettingsSchemas_1.SettingsSchemas.validateArrayObject(entry, exports.WorkspaceSetting.Databases, databaseName);
122
+ }
123
+ }
124
+ return undefined; // keep going through all settings dictionaries
125
+ });
126
+ if (resolved === undefined)
127
+ throw new Error(`no setting "${exports.WorkspaceSetting.Databases}" entry for "${databaseName}"`);
128
+ return resolved;
129
+ }
130
+ }
131
+ exports.ITwinWorkspace = ITwinWorkspace;
132
+ /** @internal */
133
+ class ITwinWorkspaceContainer {
134
+ get dirName() { return (0, path_1.join)(this.workspace.containerDir, this.id); }
135
+ static noLeadingOrTrailingSpaces(name, msg) {
136
+ if (name.trim() !== name)
137
+ throw new Error(`${msg} [${name}] may not have leading or tailing spaces`);
138
+ }
139
+ /** rules for ContainerIds (from Azure, see https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata)
140
+ * - may only contain lower case letters, numbers or dashes
141
+ * - may not start or end with with a dash nor have more than one dash in a row
142
+ * - may not be shorter than 3 or longer than 63 characters
143
+ */
144
+ static validateContainerId(id) {
145
+ if (!/^(?=.{3,63}$)[a-z0-9]+(-[a-z0-9]+)*$/g.test(id))
146
+ throw new Error(`invalid containerId: [${id}]`);
147
+ }
148
+ static validateDbName(dbName) {
149
+ if (dbName === "" || dbName.length > 255 || /[#\.<>:"/\\"`'|?*\u0000-\u001F]/g.test(dbName) || /^(con|prn|aux|nul|com\d|lpt\d)$/i.test(dbName))
150
+ throw new Error(`invalid dbName: [${dbName}]`);
151
+ this.noLeadingOrTrailingSpaces(dbName, "dbName");
152
+ }
153
+ constructor(workspace, props, account) {
154
+ this._wsDbs = new Map();
155
+ ITwinWorkspaceContainer.validateContainerId(props.containerId);
156
+ this.workspace = workspace;
157
+ this.id = props.containerId;
158
+ if (account?.accessName && account.storageType)
159
+ this.cloudContainer = CloudSqlite_1.CloudSqlite.createCloudContainer({ accessToken: "", ...props, ...account });
160
+ workspace.addContainer(this);
161
+ this.filesDir = (0, path_1.join)(this.dirName, "Files");
162
+ const cloudContainer = this.cloudContainer;
163
+ if (undefined === cloudContainer)
164
+ return;
165
+ cloudContainer.connect(this.workspace.getCloudCache());
166
+ if (false !== props.syncOnConnect) {
167
+ try {
168
+ cloudContainer.checkForChanges();
169
+ }
170
+ catch (e) {
171
+ // must be offline
172
+ }
173
+ }
174
+ }
175
+ static validateVersion(version) {
176
+ version = version ?? "1.0.0";
177
+ if (version) {
178
+ const opts = { loose: true, includePrerelease: true };
179
+ // clean allows prerelease, so try it first. If that fails attempt to coerce it (coerce strips prerelease even if you say not to.)
180
+ const semVersion = semver.clean(version, opts) ?? semver.coerce(version, opts)?.version;
181
+ if (!semVersion)
182
+ throw new Error("invalid version specification");
183
+ version = semVersion;
184
+ }
185
+ return version;
186
+ }
187
+ static parseDbFileName(dbFileName) {
188
+ const parts = dbFileName.split(":");
189
+ return { dbName: parts[0], version: parts[1] };
190
+ }
191
+ static makeDbFileName(dbName, version) {
192
+ return `${dbName}:${this.validateVersion(version)}`;
193
+ }
194
+ static resolveCloudFileName(cloudContainer, props) {
195
+ const dbName = props.dbName;
196
+ const dbs = cloudContainer.queryDatabases(`${dbName}*`); // get all databases that start with dbName
197
+ const versions = [];
198
+ for (const db of dbs) {
199
+ const thisDb = ITwinWorkspaceContainer.parseDbFileName(db);
200
+ if (thisDb.dbName === dbName && "string" === typeof thisDb.version && thisDb.version.length > 0)
201
+ versions.push(thisDb.version);
202
+ }
203
+ if (versions.length === 0)
204
+ versions[0] = "1.0.0";
205
+ const range = props.version ?? "*";
206
+ try {
207
+ const version = semver.maxSatisfying(versions, range, { loose: true, includePrerelease: props.includePrerelease });
208
+ if (version)
209
+ return `${dbName}:${version}`;
210
+ }
211
+ catch (e) {
212
+ }
213
+ throw new Error(`No version of [${dbName}] available for "${range}"`);
214
+ }
215
+ /**
216
+ * Create a copy of an existing [[WorkspaceDb]] in a cloud container with a new version number.
217
+ * @param cloudContainer The attached cloud container holding the existing WorkspaceDb
218
+ * @param fromProps Properties that describe the source WorkspaceDb for the new version
219
+ * @param versionType The type of version increment to apply to the existing version.
220
+ * @note This requires that the cloudContainer is attached and the write lock on the container be held. The copy should be modified with
221
+ * new content before the write lock is released, and thereafter should never be modified again.
222
+ */
223
+ static async makeNewVersion(cloudContainer, fromProps, versionType) {
224
+ const oldName = this.resolveCloudFileName(cloudContainer, fromProps);
225
+ const oldDb = this.parseDbFileName(oldName);
226
+ const newVersion = semver.inc(oldDb.version, versionType);
227
+ if (!newVersion)
228
+ throw new Error("invalid version");
229
+ const newName = this.makeDbFileName(oldDb.dbName, newVersion);
230
+ await cloudContainer.copyDatabase(oldName, newName);
231
+ return { oldName, newName };
232
+ }
233
+ /**
234
+ * Convert a WorkspaceDb.Props specification into a DbFileName. For cloud-based containers, this resolves to the dbName, incorporating the appropriate
235
+ * version. For file-based containers, this returns a local filename of a WorkspaceDb file with the extension ".itwin-workspace"
236
+ */
237
+ resolveDbFileName(props) {
238
+ const cloudContainer = this.cloudContainer;
239
+ if (undefined === cloudContainer)
240
+ return (0, path_1.join)(this.dirName, `${props.dbName}.${ITwinWorkspaceDb.fileExt}`); // local file, versions not allowed
241
+ return ITwinWorkspaceContainer.resolveCloudFileName(cloudContainer, props);
242
+ }
243
+ addWorkspaceDb(toAdd) {
244
+ if (undefined !== this._wsDbs.get(toAdd.dbName))
245
+ throw new Error(`workspaceDb ${toAdd.dbName} already exists in workspace`);
246
+ this._wsDbs.set(toAdd.dbName, toAdd);
247
+ }
248
+ getWorkspaceDb(props) {
249
+ const db = this._wsDbs.get(props.dbName) ?? new ITwinWorkspaceDb(props, this);
250
+ if (!db.isOpen)
251
+ db.open();
252
+ return db;
253
+ }
254
+ dropWorkspaceDb(toDrop) {
255
+ const name = toDrop.dbName;
256
+ const wsDb = this._wsDbs.get(name);
257
+ if (wsDb === toDrop) {
258
+ this._wsDbs.delete(name);
259
+ wsDb.close();
260
+ }
261
+ }
262
+ close() {
263
+ for (const [_name, db] of this._wsDbs)
264
+ db.close();
265
+ this._wsDbs.clear();
266
+ this.cloudContainer?.disconnect();
267
+ }
268
+ /** Delete all local files extracted by [[WorkspaceDb.getFile]] for this container. */
269
+ purgeContainerFiles() {
270
+ IModelJsFs_1.IModelJsFs.purgeDirSync(this.filesDir);
271
+ }
272
+ }
273
+ exports.ITwinWorkspaceContainer = ITwinWorkspaceContainer;
274
+ /**
275
+ * Implementation of WorkspaceDb
276
+ * @internal
277
+ */
278
+ class ITwinWorkspaceDb {
279
+ /** true if this WorkspaceDb is currently open */
280
+ get isOpen() { return this.sqliteDb.isOpen; }
281
+ queryFileResource(rscName) {
282
+ const info = this.sqliteDb.nativeDb.queryEmbeddedFile(rscName);
283
+ if (undefined === info)
284
+ return undefined;
285
+ // since resource names can contain illegal characters, path separators, etc., we make the local file name from its hash, in hex.
286
+ let localFileName = (0, path_1.join)(this.container.filesDir, (0, crypto_1.createHash)("sha1").update(this.dbFileName).update(rscName).digest("hex"));
287
+ if (info.fileExt !== "") // since some applications may expect to see the extension, append it here if it was supplied.
288
+ localFileName = `${localFileName}.${info.fileExt}`;
289
+ return { localFileName, info };
290
+ }
291
+ constructor(props, container) {
292
+ /** the SQLiteDb for this WorkspaceDb*/
293
+ this.sqliteDb = new SQLiteDb_1.SQLiteDb();
294
+ /** called before db is closed */
295
+ this.onClose = new core_bentley_1.BeEvent();
296
+ ITwinWorkspaceContainer.validateDbName(props.dbName);
297
+ this.dbName = props.dbName;
298
+ this.container = container;
299
+ this.dbFileName = container.resolveDbFileName(props);
300
+ container.addWorkspaceDb(this);
301
+ }
302
+ open() {
303
+ this.sqliteDb.openDb(this.dbFileName, core_bentley_1.OpenMode.Readonly, this.container.cloudContainer);
304
+ }
305
+ close() {
306
+ if (this.isOpen) {
307
+ this.onClose.raiseEvent();
308
+ this.sqliteDb.closeDb();
309
+ this.container.dropWorkspaceDb(this);
310
+ }
311
+ }
312
+ getString(rscName) {
313
+ return this.sqliteDb.withSqliteStatement("SELECT value from strings WHERE id=?", (stmt) => {
314
+ stmt.bindString(1, rscName);
315
+ return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValueString(0) : undefined;
316
+ });
317
+ }
318
+ /** Get a BlobIO reader for a blob WorkspaceResource.
319
+ * @note when finished, caller *must* call `close` on the BlobIO.
320
+ */
321
+ getBlobReader(rscName) {
322
+ return this.sqliteDb.withSqliteStatement("SELECT rowid from blobs WHERE id=?", (stmt) => {
323
+ stmt.bindString(1, rscName);
324
+ const blobReader = SQLiteDb_1.SQLiteDb.createBlobIO();
325
+ blobReader.open(this.sqliteDb.nativeDb, { tableName: "blobs", columnName: "value", row: stmt.getValueInteger(0) });
326
+ return blobReader;
327
+ });
328
+ }
329
+ getBlob(rscName) {
330
+ return this.sqliteDb.withSqliteStatement("SELECT value from blobs WHERE id=?", (stmt) => {
331
+ stmt.bindString(1, rscName);
332
+ return core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getValueBlob(0) : undefined;
333
+ });
334
+ }
335
+ getFile(rscName, targetFileName) {
336
+ const file = this.queryFileResource(rscName);
337
+ if (!file)
338
+ return undefined;
339
+ const info = file.info;
340
+ const localFileName = targetFileName ?? file.localFileName;
341
+ // check whether the file is already up to date.
342
+ const stat = fs.existsSync(localFileName) && fs.statSync(localFileName);
343
+ if (stat && Math.round(stat.mtimeMs) === info.date && stat.size === info.size)
344
+ return localFileName; // yes, we're done
345
+ // extractEmbeddedFile fails if the file exists or if the directory does not exist
346
+ if (stat)
347
+ fs.removeSync(localFileName);
348
+ else
349
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync((0, path_1.dirname)(localFileName));
350
+ this.sqliteDb.nativeDb.extractEmbeddedFile({ name: rscName, localFileName });
351
+ const date = new Date(info.date);
352
+ fs.utimesSync(localFileName, date, date); // set the last-modified date of the file to match date in container
353
+ fs.chmodSync(localFileName, "0444"); // set file readonly
354
+ return localFileName;
355
+ }
356
+ prefetch(opts) {
357
+ const cloudContainer = this.container.cloudContainer;
358
+ if (cloudContainer === undefined)
359
+ throw new Error("no cloud container to prefetch");
360
+ return CloudSqlite_1.CloudSqlite.startCloudPrefetch(cloudContainer, this.dbFileName, opts);
361
+ }
362
+ }
363
+ /** file extension for local WorkspaceDbs */
364
+ ITwinWorkspaceDb.fileExt = "itwin-workspace";
365
+ exports.ITwinWorkspaceDb = ITwinWorkspaceDb;
366
+ /**
367
+ * An editable [[WorkspaceDb]]. This is used by administrators for creating and modifying `WorkspaceDb`s.
368
+ * For cloud-backed containers, the write token must be obtained before this class may be used. Only one user at at time
369
+ * may be editing.
370
+ * @internal
371
+ */
372
+ class EditableWorkspaceDb extends ITwinWorkspaceDb {
373
+ static validateResourceName(name) {
374
+ ITwinWorkspaceContainer.noLeadingOrTrailingSpaces(name, "resource name");
375
+ if (name.length > 1024)
376
+ throw new Error("resource name too long");
377
+ }
378
+ validateResourceSize(val) {
379
+ const len = typeof val === "string" ? val.length : val.byteLength;
380
+ if (len > (1024 * 1024 * 1024)) // one gigabyte
381
+ throw new Error("value is too large");
382
+ }
383
+ open() {
384
+ this.sqliteDb.openDb(this.dbFileName, core_bentley_1.OpenMode.ReadWrite, this.container.cloudContainer);
385
+ }
386
+ getFileModifiedTime(localFileName) {
387
+ return Math.round(fs.statSync(localFileName).mtimeMs);
388
+ }
389
+ performWriteSql(rscName, sql, bind) {
390
+ this.sqliteDb.withSqliteStatement(sql, (stmt) => {
391
+ stmt.bindString(1, rscName);
392
+ bind?.(stmt);
393
+ const rc = stmt.step();
394
+ if (core_bentley_1.DbResult.BE_SQLITE_DONE !== rc) {
395
+ if (core_bentley_1.DbResult.BE_SQLITE_CONSTRAINT_PRIMARYKEY === rc)
396
+ throw new core_common_1.IModelError(rc, `resource "${rscName}" already exists`);
397
+ throw new core_common_1.IModelError(rc, `workspace [${sql}]`);
398
+ }
399
+ });
400
+ this.sqliteDb.saveChanges();
401
+ }
402
+ async createDb(version) {
403
+ if (!this.container.cloudContainer) {
404
+ EditableWorkspaceDb.createEmpty(this.dbFileName);
405
+ }
406
+ else {
407
+ // currently the only way to create a workspaceDb in a cloud container is to create a temporary workspaceDb and upload it.
408
+ const tempDbFile = (0, path_1.join)(IModelHost_1.KnownLocations.tmpdir, `empty.${ITwinWorkspaceDb.fileExt}`);
409
+ if (fs.existsSync(tempDbFile))
410
+ IModelJsFs_1.IModelJsFs.removeSync(tempDbFile);
411
+ EditableWorkspaceDb.createEmpty(tempDbFile);
412
+ this.dbFileName = ITwinWorkspaceContainer.makeDbFileName(this.dbName, version);
413
+ await CloudSqlite_1.CloudSqlite.uploadDb(this.container.cloudContainer, { localFileName: tempDbFile, dbName: this.dbFileName });
414
+ IModelJsFs_1.IModelJsFs.removeSync(tempDbFile);
415
+ }
416
+ this.open();
417
+ }
418
+ /** Create a new, empty, EditableWorkspaceDb for importing Workspace resources. */
419
+ static createEmpty(fileName) {
420
+ const db = new SQLiteDb_1.SQLiteDb();
421
+ IModelJsFs_1.IModelJsFs.recursiveMkDirSync((0, path_1.dirname)(fileName));
422
+ db.createDb(fileName);
423
+ const timeStampCol = "lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))";
424
+ db.executeSQL(`CREATE TABLE strings(id TEXT PRIMARY KEY NOT NULL,value TEXT,${timeStampCol})`);
425
+ db.executeSQL(`CREATE TABLE blobs(id TEXT PRIMARY KEY NOT NULL,value BLOB,${timeStampCol})`);
426
+ const createTrigger = (tableName) => {
427
+ db.executeSQL(`CREATE TRIGGER ${tableName}_timeStamp AFTER UPDATE ON ${tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${tableName} SET lastMod=julianday('now') WHERE id=new.id; END`);
428
+ };
429
+ createTrigger("strings");
430
+ createTrigger("blobs");
431
+ db.closeDb(true);
432
+ }
433
+ /** Add a new string resource to this WorkspaceDb.
434
+ * @param rscName The name of the string resource.
435
+ * @param val The string to save.
436
+ */
437
+ addString(rscName, val) {
438
+ EditableWorkspaceDb.validateResourceName(rscName);
439
+ this.validateResourceSize(val);
440
+ this.performWriteSql(rscName, "INSERT INTO strings(id,value) VALUES(?,?)", (stmt) => stmt.bindString(2, val));
441
+ }
442
+ /** Update an existing string resource with a new value.
443
+ * @param rscName The name of the string resource.
444
+ * @param val The new value.
445
+ * @throws if rscName does not exist
446
+ */
447
+ updateString(rscName, val) {
448
+ this.validateResourceSize(val);
449
+ this.performWriteSql(rscName, "UPDATE strings SET value=?2 WHERE id=?1", (stmt) => stmt.bindString(2, val));
450
+ }
451
+ /** Remove a string resource. */
452
+ removeString(rscName) {
453
+ this.performWriteSql(rscName, "DELETE FROM strings WHERE id=?");
454
+ }
455
+ /** Add a new blob resource to this WorkspaceDb.
456
+ * @param rscName The name of the blob resource.
457
+ * @param val The blob to save.
458
+ */
459
+ addBlob(rscName, val) {
460
+ EditableWorkspaceDb.validateResourceName(rscName);
461
+ this.validateResourceSize(val);
462
+ this.performWriteSql(rscName, "INSERT INTO blobs(id,value) VALUES(?,?)", (stmt) => stmt.bindBlob(2, val));
463
+ }
464
+ /** Update an existing blob resource with a new value.
465
+ * @param rscName The name of the blob resource.
466
+ * @param val The new value.
467
+ * @throws if rscName does not exist
468
+ */
469
+ updateBlob(rscName, val) {
470
+ this.validateResourceSize(val);
471
+ this.performWriteSql(rscName, "UPDATE blobs SET value=?2 WHERE id=?1", (stmt) => stmt.bindBlob(2, val));
472
+ }
473
+ /** Get a BlobIO writer for a previously-added blob WorkspaceResource.
474
+ * @note after writing is complete, caller must call `close` on the BlobIO and must call `saveChanges` on the `db`.
475
+ */
476
+ getBlobWriter(rscName) {
477
+ return this.sqliteDb.withSqliteStatement("SELECT rowid from blobs WHERE id=?", (stmt) => {
478
+ stmt.bindString(1, rscName);
479
+ const blobWriter = SQLiteDb_1.SQLiteDb.createBlobIO();
480
+ blobWriter.open(this.sqliteDb.nativeDb, { tableName: "blobs", columnName: "value", row: stmt.getValueInteger(0), writeable: true });
481
+ return blobWriter;
482
+ });
483
+ }
484
+ /** Remove a blob resource. */
485
+ removeBlob(rscName) {
486
+ this.performWriteSql(rscName, "DELETE FROM blobs WHERE id=?");
487
+ }
488
+ /** Copy the contents of an existing local file into this WorkspaceDb as a file resource.
489
+ * @param rscName The name of the file resource.
490
+ * @param localFileName The name of a local file to be read.
491
+ * @param fileExt The extension (do not include the leading ".") to be appended to the generated fileName
492
+ * when this WorkspaceDb is extracted from the WorkspaceDb. By default the characters after the last "." in `localFileName`
493
+ * are used. Pass this argument to override that.
494
+ */
495
+ addFile(rscName, localFileName, fileExt) {
496
+ EditableWorkspaceDb.validateResourceName(rscName);
497
+ fileExt = fileExt ?? (0, path_1.extname)(localFileName);
498
+ if (fileExt?.[0] === ".")
499
+ fileExt = fileExt.slice(1);
500
+ this.sqliteDb.nativeDb.embedFile({ name: rscName, localFileName, date: this.getFileModifiedTime(localFileName), fileExt });
501
+ }
502
+ /** Replace an existing file resource with the contents of another local file.
503
+ * @param rscName The name of the file resource.
504
+ * @param localFileName The name of a local file to be read.
505
+ * @throws if rscName does not exist
506
+ */
507
+ updateFile(rscName, localFileName) {
508
+ this.queryFileResource(rscName); // throws if not present
509
+ this.sqliteDb.nativeDb.replaceEmbeddedFile({ name: rscName, localFileName, date: this.getFileModifiedTime(localFileName) });
510
+ }
511
+ /** Remove a file resource. */
512
+ removeFile(rscName) {
513
+ const file = this.queryFileResource(rscName);
514
+ if (undefined === file)
515
+ throw new Error(`file resource "${rscName}" does not exist`);
516
+ if (file && fs.existsSync(file.localFileName))
517
+ fs.unlinkSync(file.localFileName);
518
+ this.sqliteDb.nativeDb.removeEmbeddedFile(rscName);
519
+ }
520
+ }
521
+ exports.EditableWorkspaceDb = EditableWorkspaceDb;
544
522
  //# sourceMappingURL=Workspace.js.map