@itwin/core-backend 3.4.0-dev.8 → 3.5.0-dev.4

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 (261) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -17
  3. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  4. package/lib/cjs/AliCloudStorageService.js +71 -68
  5. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  6. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  7. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  8. package/lib/cjs/BackendHubAccess.js +41 -41
  9. package/lib/cjs/BackendHubAccess.js.map +1 -1
  10. package/lib/cjs/BackendLoggerCategory.d.ts +91 -87
  11. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  12. package/lib/cjs/BackendLoggerCategory.js +99 -95
  13. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  14. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  15. package/lib/cjs/BisCoreSchema.js +60 -60
  16. package/lib/cjs/BisCoreSchema.js.map +1 -1
  17. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  18. package/lib/cjs/BriefcaseManager.js +405 -405
  19. package/lib/cjs/BriefcaseManager.js.map +1 -1
  20. package/lib/cjs/Category.d.ts +153 -153
  21. package/lib/cjs/Category.js +243 -243
  22. package/lib/cjs/Category.js.map +1 -1
  23. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  24. package/lib/cjs/ChangeSummaryManager.js +445 -445
  25. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  26. package/lib/cjs/ChangedElementsDb.d.ts +99 -98
  27. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  28. package/lib/cjs/ChangedElementsDb.js +165 -165
  29. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  30. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  31. package/lib/cjs/ChangedElementsManager.js +88 -88
  32. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  33. package/lib/cjs/CheckpointManager.d.ts +120 -122
  34. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  35. package/lib/cjs/CheckpointManager.js +343 -354
  36. package/lib/cjs/CheckpointManager.js.map +1 -1
  37. package/lib/cjs/ClassRegistry.d.ts +71 -71
  38. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  39. package/lib/cjs/ClassRegistry.js +215 -213
  40. package/lib/cjs/ClassRegistry.js.map +1 -1
  41. package/lib/cjs/CloudSqlite.d.ts +350 -0
  42. package/lib/cjs/CloudSqlite.d.ts.map +1 -0
  43. package/lib/cjs/CloudSqlite.js +152 -0
  44. package/lib/cjs/CloudSqlite.js.map +1 -0
  45. package/lib/cjs/CloudStorageBackend.d.ts +58 -46
  46. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  47. package/lib/cjs/CloudStorageBackend.js +173 -164
  48. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  49. package/lib/cjs/CodeService.d.ts +397 -0
  50. package/lib/cjs/CodeService.d.ts.map +1 -0
  51. package/lib/cjs/CodeService.js +64 -0
  52. package/lib/cjs/CodeService.js.map +1 -0
  53. package/lib/cjs/CodeSpecs.d.ts +50 -50
  54. package/lib/cjs/CodeSpecs.js +112 -112
  55. package/lib/cjs/CodeSpecs.js.map +1 -1
  56. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  57. package/lib/cjs/ConcurrentQuery.js +30 -30
  58. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  59. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  60. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  61. package/lib/cjs/CustomViewState3dCreator.js +113 -98
  62. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  63. package/lib/cjs/DevTools.d.ts +71 -71
  64. package/lib/cjs/DevTools.d.ts.map +1 -1
  65. package/lib/cjs/DevTools.js +154 -154
  66. package/lib/cjs/DevTools.js.map +1 -1
  67. package/lib/cjs/DisplayStyle.d.ts +106 -106
  68. package/lib/cjs/DisplayStyle.js +256 -256
  69. package/lib/cjs/DisplayStyle.js.map +1 -1
  70. package/lib/cjs/ECDb.d.ts +191 -191
  71. package/lib/cjs/ECDb.js +350 -350
  72. package/lib/cjs/ECDb.js.map +1 -1
  73. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  74. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  76. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  77. package/lib/cjs/ECSqlStatement.js +791 -791
  78. package/lib/cjs/ECSqlStatement.js.map +1 -1
  79. package/lib/cjs/Element.d.ts +1109 -1109
  80. package/lib/cjs/Element.d.ts.map +1 -1
  81. package/lib/cjs/Element.js +1420 -1417
  82. package/lib/cjs/Element.js.map +1 -1
  83. package/lib/cjs/ElementAspect.d.ts +156 -156
  84. package/lib/cjs/ElementAspect.js +178 -178
  85. package/lib/cjs/ElementAspect.js.map +1 -1
  86. package/lib/cjs/ElementGraphics.d.ts +9 -9
  87. package/lib/cjs/ElementGraphics.js +41 -41
  88. package/lib/cjs/ElementGraphics.js.map +1 -1
  89. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  90. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  91. package/lib/cjs/ElementTreeWalker.js +409 -409
  92. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  93. package/lib/cjs/Entity.d.ts +76 -76
  94. package/lib/cjs/Entity.js +82 -82
  95. package/lib/cjs/Entity.js.map +1 -1
  96. package/lib/cjs/ExportGraphics.d.ts +317 -317
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  98. package/lib/cjs/ExportGraphics.js +208 -208
  99. package/lib/cjs/ExportGraphics.js.map +1 -1
  100. package/lib/cjs/ExternalSource.d.ts +94 -94
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  102. package/lib/cjs/ExternalSource.js +125 -125
  103. package/lib/cjs/ExternalSource.js.map +1 -1
  104. package/lib/cjs/GeoCoordConfig.d.ts +19 -13
  105. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  106. package/lib/cjs/GeoCoordConfig.js +82 -73
  107. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  108. package/lib/cjs/GeometrySummary.d.ts +4 -4
  109. package/lib/cjs/GeometrySummary.js +380 -380
  110. package/lib/cjs/GeometrySummary.js.map +1 -1
  111. package/lib/cjs/HubMock.d.ts +93 -93
  112. package/lib/cjs/HubMock.d.ts.map +1 -1
  113. package/lib/cjs/HubMock.js +190 -190
  114. package/lib/cjs/HubMock.js.map +1 -1
  115. package/lib/cjs/IModelCloneContext.d.ts +85 -85
  116. package/lib/cjs/IModelCloneContext.js +150 -150
  117. package/lib/cjs/IModelCloneContext.js.map +1 -1
  118. package/lib/cjs/IModelDb.d.ts +1164 -1151
  119. package/lib/cjs/IModelDb.d.ts.map +1 -1
  120. package/lib/cjs/IModelDb.js +2324 -2286
  121. package/lib/cjs/IModelDb.js.map +1 -1
  122. package/lib/cjs/IModelHost.d.ts +361 -347
  123. package/lib/cjs/IModelHost.d.ts.map +1 -1
  124. package/lib/cjs/IModelHost.js +489 -455
  125. package/lib/cjs/IModelHost.js.map +1 -1
  126. package/lib/cjs/IModelJsFs.d.ts +62 -62
  127. package/lib/cjs/IModelJsFs.d.ts.map +1 -1
  128. package/lib/cjs/IModelJsFs.js +140 -140
  129. package/lib/cjs/IModelJsFs.js.map +1 -1
  130. package/lib/cjs/IpcHost.d.ts +98 -98
  131. package/lib/cjs/IpcHost.js +234 -234
  132. package/lib/cjs/IpcHost.js.map +1 -1
  133. package/lib/cjs/LineStyle.d.ts +311 -311
  134. package/lib/cjs/LineStyle.js +295 -295
  135. package/lib/cjs/LineStyle.js.map +1 -1
  136. package/lib/cjs/LocalHub.d.ts +162 -162
  137. package/lib/cjs/LocalHub.js +587 -587
  138. package/lib/cjs/LocalHub.js.map +1 -1
  139. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  140. package/lib/cjs/LocalhostIpcHost.js +81 -81
  141. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  142. package/lib/cjs/Material.d.ts +103 -101
  143. package/lib/cjs/Material.d.ts.map +1 -1
  144. package/lib/cjs/Material.js +147 -145
  145. package/lib/cjs/Material.js.map +1 -1
  146. package/lib/cjs/Model.d.ts +386 -386
  147. package/lib/cjs/Model.d.ts.map +1 -1
  148. package/lib/cjs/Model.js +471 -468
  149. package/lib/cjs/Model.js.map +1 -1
  150. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  151. package/lib/cjs/NativeAppStorage.js +202 -202
  152. package/lib/cjs/NativeAppStorage.js.map +1 -1
  153. package/lib/cjs/NativeHost.d.ts +52 -52
  154. package/lib/cjs/NativeHost.js +168 -168
  155. package/lib/cjs/NativeHost.js.map +1 -1
  156. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  157. package/lib/cjs/NavigationRelationship.js +225 -225
  158. package/lib/cjs/NavigationRelationship.js.map +1 -1
  159. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  160. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  161. package/lib/cjs/PromiseMemoizer.js +101 -95
  162. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  163. package/lib/cjs/PropertyStore.d.ts +133 -0
  164. package/lib/cjs/PropertyStore.d.ts.map +1 -0
  165. package/lib/cjs/PropertyStore.js +12 -0
  166. package/lib/cjs/PropertyStore.js.map +1 -0
  167. package/lib/cjs/Relationship.d.ts +400 -400
  168. package/lib/cjs/Relationship.js +465 -465
  169. package/lib/cjs/Relationship.js.map +1 -1
  170. package/lib/cjs/RpcBackend.d.ts +28 -28
  171. package/lib/cjs/RpcBackend.js +126 -126
  172. package/lib/cjs/RpcBackend.js.map +1 -1
  173. package/lib/cjs/SQLiteDb.d.ts +219 -173
  174. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  175. package/lib/cjs/SQLiteDb.js +214 -211
  176. package/lib/cjs/SQLiteDb.js.map +1 -1
  177. package/lib/cjs/Schema.d.ts +55 -55
  178. package/lib/cjs/Schema.js +83 -83
  179. package/lib/cjs/Schema.js.map +1 -1
  180. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  181. package/lib/cjs/ServerBasedLocks.js +168 -168
  182. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  183. package/lib/cjs/SqliteStatement.d.ts +283 -271
  184. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  185. package/lib/cjs/SqliteStatement.js +448 -426
  186. package/lib/cjs/SqliteStatement.js.map +1 -1
  187. package/lib/cjs/Texture.d.ts +58 -58
  188. package/lib/cjs/Texture.js +82 -82
  189. package/lib/cjs/Texture.js.map +1 -1
  190. package/lib/cjs/TileStorage.d.ts +19 -0
  191. package/lib/cjs/TileStorage.d.ts.map +1 -0
  192. package/lib/cjs/TileStorage.js +91 -0
  193. package/lib/cjs/TileStorage.js.map +1 -0
  194. package/lib/cjs/TxnManager.d.ts +202 -202
  195. package/lib/cjs/TxnManager.d.ts.map +1 -1
  196. package/lib/cjs/TxnManager.js +356 -353
  197. package/lib/cjs/TxnManager.js.map +1 -1
  198. package/lib/cjs/ViewDefinition.d.ts +435 -435
  199. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  200. package/lib/cjs/ViewDefinition.js +635 -629
  201. package/lib/cjs/ViewDefinition.js.map +1 -1
  202. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  203. package/lib/cjs/ViewStateHydrator.js +103 -103
  204. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  205. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  206. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  207. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -21
  208. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  209. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  210. package/lib/cjs/core-backend.d.ts +182 -175
  211. package/lib/cjs/core-backend.d.ts.map +1 -1
  212. package/lib/cjs/core-backend.js +202 -195
  213. package/lib/cjs/core-backend.js.map +1 -1
  214. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  215. package/lib/cjs/domains/FunctionalElements.js +145 -145
  216. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  217. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  218. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  219. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  220. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  221. package/lib/cjs/domains/GenericElements.js +263 -263
  222. package/lib/cjs/domains/GenericElements.js.map +1 -1
  223. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  224. package/lib/cjs/domains/GenericSchema.js +28 -28
  225. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  226. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  227. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  228. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  229. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  230. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  231. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -20
  233. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  234. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -195
  235. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  237. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  238. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -165
  239. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  241. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  242. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  243. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  245. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  246. package/lib/cjs/workspace/Settings.d.ts +186 -186
  247. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  248. package/lib/cjs/workspace/Settings.js +155 -152
  249. package/lib/cjs/workspace/Settings.js.map +1 -1
  250. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  251. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  252. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  253. package/lib/cjs/workspace/Workspace.d.ts +414 -401
  254. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  255. package/lib/cjs/workspace/Workspace.js +543 -534
  256. package/lib/cjs/workspace/Workspace.js.map +1 -1
  257. package/package.json +19 -20
  258. package/lib/cjs/IModelSchemaLoader.d.ts +0 -26
  259. package/lib/cjs/IModelSchemaLoader.d.ts.map +0 -1
  260. package/lib/cjs/IModelSchemaLoader.js +0 -122
  261. package/lib/cjs/IModelSchemaLoader.js.map +0 -1
@@ -1,96 +1,102 @@
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 Utils
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.PromiseMemoizer = exports.QueryablePromise = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
13
- /** Wrapper around a promise that allows synchronous queries of it's state
14
- * @internal
15
- */
16
- class QueryablePromise {
17
- constructor(promise) {
18
- this.promise = promise;
19
- this._fulfilled = false;
20
- this._rejected = false;
21
- this.promise
22
- .then((res) => { this.result = res; this._fulfilled = true; })
23
- .catch((err) => { this.error = err; this._rejected = true; });
24
- }
25
- get isPending() { return !this.isFulfilled && !this.isRejected; }
26
- get isFulfilled() { return this._fulfilled; }
27
- get isRejected() { return this._rejected; }
28
- }
29
- exports.QueryablePromise = QueryablePromise;
30
- /** Utility to cache and retrieve results of long running asynchronous functions.
31
- * The cache is keyed on the input arguments passed to these functions
32
- * @internal
33
- */
34
- class PromiseMemoizer {
35
- /**
36
- * Constructor
37
- * @param memoizeFn Function to memoize
38
- * @param generateKeyFn Function to generate the key for the memoized function
39
- * @param maxCacheSize Maximum size of the memoizer cache.
40
- * If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these
41
- * may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize
42
- * threshold, the entire cache is then cleared.
43
- */
44
- constructor(memoizeFn, generateKeyFn, maxCacheSize = 500, cacheTimeout = 30000) {
45
- this._cachedPromises = new Map();
46
- this._timers = new Map();
47
- /** Call the memoized function */
48
- this.memoize = (...args) => {
49
- const key = this._generateKeyFn(...args);
50
- let qp = this._cachedPromises.get(key);
51
- if (qp)
52
- return qp;
53
- if (this._cachedPromises.size >= this._maxCacheSize) {
54
- if (this._maxCacheSize > 1)
55
- core_bentley_1.Logger.logError(BackendLoggerCategory_1.BackendLoggerCategory.PromiseMemoizer, "Cleared too many unresolved entries in memoizer cache");
56
- this.clearCache();
57
- }
58
- const removeCachedPromise = (v) => {
59
- const cleanUp = () => {
60
- this._cachedPromises.delete(key);
61
- this._timers.delete(key);
62
- };
63
- this._timers.set(key, setTimeout(cleanUp, this._cacheTimeout));
64
- return v;
65
- };
66
- const p = this._memoizeFn(...args).then(removeCachedPromise, (e) => { throw removeCachedPromise(e); });
67
- qp = new QueryablePromise(p);
68
- this._cachedPromises.set(key, qp);
69
- return qp;
70
- };
71
- /** Delete the memoized function */
72
- this.deleteMemoized = (...args) => {
73
- const key = this._generateKeyFn(...args);
74
- this._cachedPromises.delete(key);
75
- const timer = this._timers.get(key);
76
- if (timer)
77
- clearTimeout(timer);
78
- };
79
- /** Clear all entries in the memoizer cache */
80
- this.clearCache = () => {
81
- this._cachedPromises.clear();
82
- };
83
- this.dispose = () => {
84
- for (const timer of this._timers.values())
85
- clearTimeout(timer);
86
- this._timers.clear();
87
- this.clearCache();
88
- };
89
- this._memoizeFn = memoizeFn;
90
- this._generateKeyFn = generateKeyFn;
91
- this._maxCacheSize = maxCacheSize;
92
- this._cacheTimeout = cacheTimeout;
93
- }
94
- }
95
- exports.PromiseMemoizer = PromiseMemoizer;
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 Utils
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PromiseMemoizer = exports.QueryablePromise = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
13
+ /** Wrapper around a promise that allows synchronous queries of it's state
14
+ * @internal
15
+ */
16
+ class QueryablePromise {
17
+ constructor(promise) {
18
+ this.promise = promise;
19
+ this._fulfilled = false;
20
+ this._rejected = false;
21
+ this.promise.then((res) => {
22
+ this.result = res;
23
+ this._fulfilled = true;
24
+ }).catch((err) => {
25
+ this.error = err;
26
+ this._rejected = true;
27
+ });
28
+ }
29
+ get isPending() { return !this.isFulfilled && !this.isRejected; }
30
+ get isFulfilled() { return this._fulfilled; }
31
+ get isRejected() { return this._rejected; }
32
+ }
33
+ exports.QueryablePromise = QueryablePromise;
34
+ /** Utility to cache and retrieve results of long running asynchronous functions.
35
+ * The cache is keyed on the input arguments passed to these functions
36
+ * @internal
37
+ */
38
+ class PromiseMemoizer {
39
+ /**
40
+ * Constructor
41
+ * @param memoizeFn Function to memoize
42
+ * @param generateKeyFn Function to generate the key for the memoized function
43
+ * @param maxCacheSize Maximum size of the memoizer cache.
44
+ * If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these
45
+ * may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize
46
+ * threshold, the entire cache is then cleared.
47
+ */
48
+ constructor(memoizeFn, generateKeyFn, maxCacheSize = 500, cacheTimeout = 30000) {
49
+ this._cachedPromises = new Map();
50
+ this._timers = new Map();
51
+ /** Call the memoized function */
52
+ this.memoize = (...args) => {
53
+ const key = this._generateKeyFn(...args);
54
+ let qp = this._cachedPromises.get(key);
55
+ if (qp)
56
+ return qp;
57
+ if (this._cachedPromises.size >= this._maxCacheSize) {
58
+ if (this._maxCacheSize > 1)
59
+ core_bentley_1.Logger.logError(BackendLoggerCategory_1.BackendLoggerCategory.PromiseMemoizer, "Cleared too many unresolved entries in memoizer cache");
60
+ this.clearCache();
61
+ }
62
+ const removeCachedPromise = (v) => {
63
+ const cleanUp = () => {
64
+ this._cachedPromises.delete(key);
65
+ this._timers.delete(key);
66
+ };
67
+ this._timers.set(key, setTimeout(cleanUp, this._cacheTimeout));
68
+ return v;
69
+ };
70
+ const p = this._memoizeFn(...args).then(removeCachedPromise, (e) => {
71
+ throw removeCachedPromise(e);
72
+ });
73
+ qp = new QueryablePromise(p);
74
+ this._cachedPromises.set(key, qp);
75
+ return qp;
76
+ };
77
+ /** Delete the memoized function */
78
+ this.deleteMemoized = (...args) => {
79
+ const key = this._generateKeyFn(...args);
80
+ this._cachedPromises.delete(key);
81
+ const timer = this._timers.get(key);
82
+ if (timer)
83
+ clearTimeout(timer);
84
+ };
85
+ /** Clear all entries in the memoizer cache */
86
+ this.clearCache = () => {
87
+ this._cachedPromises.clear();
88
+ };
89
+ this.dispose = () => {
90
+ for (const timer of this._timers.values())
91
+ clearTimeout(timer);
92
+ this._timers.clear();
93
+ this.clearCache();
94
+ };
95
+ this._memoizeFn = memoizeFn;
96
+ this._generateKeyFn = generateKeyFn;
97
+ this._maxCacheSize = maxCacheSize;
98
+ this._cacheTimeout = cacheTimeout;
99
+ }
100
+ }
101
+ exports.PromiseMemoizer = PromiseMemoizer;
96
102
  //# sourceMappingURL=PromiseMemoizer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PromiseMemoizer.js","sourceRoot":"","sources":["../../src/PromiseMemoizer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,mEAAgE;AAEhE;;GAEG;AACH,MAAa,gBAAgB;IAU3B,YAAmC,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAN9C,eAAU,GAAY,KAAK,CAAC;QAC5B,cAAS,GAAY,KAAK,CAAC;QAMjC,IAAI,CAAC,OAAO;aACT,IAAI,CAAC,CAAC,GAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;aAChE,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IAPD,IAAW,SAAS,KAAc,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IACjF,IAAW,WAAW,KAAc,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7D,IAAW,UAAU,KAAc,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;CAM5D;AAfD,4CAeC;AAOD;;;GAGG;AACH,MAAa,eAAe;IAQ1B;;;;;;;;OAQG;IAC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CAAC,CAAC;YACvG,EAAE,GAAG,IAAI,gBAAgB,CAAI,CAAC,CAAC,CAAC;YAChC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAClC,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;QAEF,mCAAmC;QAC5B,mBAAc,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;YACzC,MAAM,GAAG,GAAW,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;YACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACpC,IAAI,KAAK;gBACP,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,8CAA8C;QACvC,eAAU,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEK,YAAO,GAAG,GAAG,EAAE;YACpB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBACvC,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,CAAC;QArDA,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;CAkDF;AAxED,0CAwEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { IDisposable, Logger } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\n\r\n/** Wrapper around a promise that allows synchronous queries of it's state\r\n * @internal\r\n */\r\nexport class QueryablePromise<T> {\r\n public result?: T;\r\n public error?: any;\r\n\r\n private _fulfilled: boolean = false;\r\n private _rejected: boolean = false;\r\n\r\n public get isPending(): boolean { return !this.isFulfilled && !this.isRejected; }\r\n public get isFulfilled(): boolean { return this._fulfilled; }\r\n public get isRejected(): boolean { return this._rejected; }\r\n public constructor(public readonly promise: Promise<T>) {\r\n this.promise\r\n .then((res: T) => { this.result = res; this._fulfilled = true; })\r\n .catch((err: any) => { this.error = err; this._rejected = true; });\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport type MemoizeFnType<T> = (...args: any[]) => Promise<T>;\r\n/** @internal */\r\nexport type GenerateKeyFnType = (...args: any[]) => string;\r\n\r\n/** Utility to cache and retrieve results of long running asynchronous functions.\r\n * The cache is keyed on the input arguments passed to these functions\r\n * @internal\r\n */\r\nexport class PromiseMemoizer<T> implements IDisposable {\r\n private readonly _cachedPromises: Map<string, QueryablePromise<T>> = new Map<string, QueryablePromise<T>>();\r\n private readonly _timers: Map<string, NodeJS.Timer> = new Map<string, NodeJS.Timer>();\r\n private readonly _memoizeFn: MemoizeFnType<T>;\r\n private readonly _generateKeyFn: GenerateKeyFnType;\r\n private readonly _maxCacheSize: number;\r\n private readonly _cacheTimeout: number;\r\n\r\n /**\r\n * Constructor\r\n * @param memoizeFn Function to memoize\r\n * @param generateKeyFn Function to generate the key for the memoized function\r\n * @param maxCacheSize Maximum size of the memoizer cache.\r\n * If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these\r\n * may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize\r\n * threshold, the entire cache is then cleared.\r\n */\r\n public constructor(memoizeFn: MemoizeFnType<T>, generateKeyFn: GenerateKeyFnType, maxCacheSize: number = 500, cacheTimeout: number = 30000) {\r\n this._memoizeFn = memoizeFn;\r\n this._generateKeyFn = generateKeyFn;\r\n this._maxCacheSize = maxCacheSize;\r\n this._cacheTimeout = cacheTimeout;\r\n }\r\n\r\n /** Call the memoized function */\r\n public memoize = (...args: any[]): QueryablePromise<T> => {\r\n const key: string = this._generateKeyFn(...args);\r\n let qp: QueryablePromise<T> | undefined = this._cachedPromises.get(key);\r\n if (qp)\r\n return qp;\r\n\r\n if (this._cachedPromises.size >= this._maxCacheSize) {\r\n if (this._maxCacheSize > 1)\r\n Logger.logError(BackendLoggerCategory.PromiseMemoizer, \"Cleared too many unresolved entries in memoizer cache\");\r\n this.clearCache();\r\n }\r\n\r\n const removeCachedPromise = (v: T) => {\r\n const cleanUp = () => {\r\n this._cachedPromises.delete(key);\r\n this._timers.delete(key);\r\n };\r\n this._timers.set(key, setTimeout(cleanUp, this._cacheTimeout));\r\n return v;\r\n };\r\n\r\n const p = this._memoizeFn(...args).then(removeCachedPromise, (e) => { throw removeCachedPromise(e); });\r\n qp = new QueryablePromise<T>(p);\r\n this._cachedPromises.set(key, qp);\r\n return qp;\r\n };\r\n\r\n /** Delete the memoized function */\r\n public deleteMemoized = (...args: any[]) => {\r\n const key: string = this._generateKeyFn(...args);\r\n this._cachedPromises.delete(key);\r\n const timer = this._timers.get(key);\r\n if (timer)\r\n clearTimeout(timer);\r\n };\r\n\r\n /** Clear all entries in the memoizer cache */\r\n public clearCache = () => {\r\n this._cachedPromises.clear();\r\n };\r\n\r\n public dispose = () => {\r\n for (const timer of this._timers.values())\r\n clearTimeout(timer);\r\n this._timers.clear();\r\n this.clearCache();\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"PromiseMemoizer.js","sourceRoot":"","sources":["../../src/PromiseMemoizer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,mEAAgE;AAEhE;;GAEG;AACH,MAAa,gBAAgB;IAU3B,YAAmC,OAAmB;Q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CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,8CAA8C;QACvC,eAAU,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEK,YAAO,GAAG,GAAG,EAAE;YACpB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBACvC,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,CAAC;QAxDA,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;CAqDF;AA3ED,0CA2EC","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/** @packageDocumentation\n * @module Utils\n */\n\nimport { IDisposable, Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\n\n/** Wrapper around a promise that allows synchronous queries of it's state\n * @internal\n */\nexport class QueryablePromise<T> {\n public result?: T;\n public error?: any;\n\n private _fulfilled: boolean = false;\n private _rejected: boolean = false;\n\n public get isPending(): boolean { return !this.isFulfilled && !this.isRejected; }\n public get isFulfilled(): boolean { return this._fulfilled; }\n public get isRejected(): boolean { return this._rejected; }\n public constructor(public readonly promise: Promise<T>) {\n this.promise.then((res: T) => {\n this.result = res;\n this._fulfilled = true;\n }).catch((err: any) => {\n this.error = err;\n this._rejected = true;\n });\n }\n}\n\n/** @internal */\nexport type MemoizeFnType<T> = (...args: any[]) => Promise<T>;\n/** @internal */\nexport type GenerateKeyFnType = (...args: any[]) => string;\n\n/** Utility to cache and retrieve results of long running asynchronous functions.\n * The cache is keyed on the input arguments passed to these functions\n * @internal\n */\nexport class PromiseMemoizer<T> implements IDisposable {\n private readonly _cachedPromises: Map<string, QueryablePromise<T>> = new Map<string, QueryablePromise<T>>();\n private readonly _timers: Map<string, NodeJS.Timer> = new Map<string, NodeJS.Timer>();\n private readonly _memoizeFn: MemoizeFnType<T>;\n private readonly _generateKeyFn: GenerateKeyFnType;\n private readonly _maxCacheSize: number;\n private readonly _cacheTimeout: number;\n\n /**\n * Constructor\n * @param memoizeFn Function to memoize\n * @param generateKeyFn Function to generate the key for the memoized function\n * @param maxCacheSize Maximum size of the memoizer cache.\n * If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these\n * may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize\n * threshold, the entire cache is then cleared.\n */\n public constructor(memoizeFn: MemoizeFnType<T>, generateKeyFn: GenerateKeyFnType, maxCacheSize: number = 500, cacheTimeout: number = 30000) {\n this._memoizeFn = memoizeFn;\n this._generateKeyFn = generateKeyFn;\n this._maxCacheSize = maxCacheSize;\n this._cacheTimeout = cacheTimeout;\n }\n\n /** Call the memoized function */\n public memoize = (...args: any[]): QueryablePromise<T> => {\n const key: string = this._generateKeyFn(...args);\n let qp: QueryablePromise<T> | undefined = this._cachedPromises.get(key);\n if (qp)\n return qp;\n\n if (this._cachedPromises.size >= this._maxCacheSize) {\n if (this._maxCacheSize > 1)\n Logger.logError(BackendLoggerCategory.PromiseMemoizer, \"Cleared too many unresolved entries in memoizer cache\");\n this.clearCache();\n }\n\n const removeCachedPromise = (v: T) => {\n const cleanUp = () => {\n this._cachedPromises.delete(key);\n this._timers.delete(key);\n };\n this._timers.set(key, setTimeout(cleanUp, this._cacheTimeout));\n return v;\n };\n\n const p = this._memoizeFn(...args).then(removeCachedPromise, (e) => {\n throw removeCachedPromise(e);\n });\n\n qp = new QueryablePromise<T>(p);\n this._cachedPromises.set(key, qp);\n return qp;\n };\n\n /** Delete the memoized function */\n public deleteMemoized = (...args: any[]) => {\n const key: string = this._generateKeyFn(...args);\n this._cachedPromises.delete(key);\n const timer = this._timers.get(key);\n if (timer)\n clearTimeout(timer);\n };\n\n /** Clear all entries in the memoizer cache */\n public clearCache = () => {\n this._cachedPromises.clear();\n };\n\n public dispose = () => {\n for (const timer of this._timers.values())\n clearTimeout(timer);\n this._timers.clear();\n this.clearCache();\n };\n}\n"]}
@@ -0,0 +1,133 @@
1
+ import { AccessToken } from "@itwin/core-bentley";
2
+ import { CloudSqlite } from "./CloudSqlite";
3
+ import { SettingObject } from "./workspace/Settings";
4
+ /**
5
+ * A persistent storage for a set of values of type `PropertyType`, each with a unique `PropertyName`.
6
+ * `PropertyStore`s are stored in cloud containers, and require an access token that grants permission to read and/or write them.
7
+ * All write operations will fail without an access token that grants write permission.
8
+ * A `PropertyStore` is cached on a local drive so reads are fast and inexpensive, and may even be done offline after a prefetch.
9
+ * However, that means that callers are responsible for synchronizing the local cache to ensure it includes changes
10
+ * made by others, as appropriate (see [[synchronizeWithCloud]]).
11
+ * @alpha */
12
+ export interface PropertyStore {
13
+ /** The collection of property values in the PropertyStore as of the last time it was synchronized. */
14
+ readonly values: PropertyStore.Values;
15
+ /** Parameters for obtaining the write lock on the container for a PropertyStore.*/
16
+ readonly lockParams: CloudSqlite.ObtainLockParams;
17
+ /**
18
+ * The token that grants access to the cloud container for this PropertyStore. If it does not grant write permissions, all
19
+ * write operations will fail. It should be refreshed (via a timer) before it expires.
20
+ */
21
+ sasToken: AccessToken;
22
+ /**
23
+ * Synchronize the local values in this PropertyStore with any changes by made by others.
24
+ * @note This is called automatically whenever any write operation is performed on the PropertyStore. It is only necessary to
25
+ * call this directly if you have not changed the PropertyStore recently, but wish to perform a readonly operation and want to
26
+ * ensure it is up-to-date as of now.
27
+ * @note There is no guarantee that the Values are up-to-date even immediately after calling this method, since others
28
+ * may be modifying them at any time.
29
+ */
30
+ synchronizeWithCloud(): void;
31
+ /** initiate a prefetch operation on this PropertyStore
32
+ * @internal
33
+ */
34
+ startPrefetch(): CloudSqlite.CloudPrefetch;
35
+ /** Save a single property in this PropertyStore. If the property already exists, its value is overwritten.
36
+ * @note This will obtain the write lock, save the value, and then release the write lock.
37
+ */
38
+ saveProperty(name: PropertyStore.PropertyName, value: PropertyStore.PropertyType): Promise<void>;
39
+ /** Save an array of properties in this PropertyStore. If a property already exists, its value is overwritten.
40
+ * @note This will obtain the write lock, save the values, and then release the write lock.
41
+ */
42
+ saveProperties(props: PropertyStore.PropertyArray): Promise<void>;
43
+ /** Delete a single property from this PropertyStore. If the value does not exist, this method does nothing.
44
+ * @note This will obtain the write lock, delete the value, and then release the write lock.
45
+ */
46
+ deleteProperty(propName: PropertyStore.PropertyName): Promise<void>;
47
+ /** Delete an array of properties from this PropertyStore. Any value that does not exist is ignored.
48
+ * @note This will obtain the write lock, delete the values, and then release the write lock.
49
+ */
50
+ deleteProperties(propNames: PropertyStore.PropertyName[]): Promise<void>;
51
+ }
52
+ /** @alpha */
53
+ export declare namespace PropertyStore {
54
+ /** @internal */
55
+ let openPropertyStore: ((props: CloudSqlite.ContainerAccessProps) => PropertyStore) | undefined;
56
+ /** The set of valid types for properties in a PropertyStore. */
57
+ type PropertyType = string | number | boolean | Uint8Array | SettingObject;
58
+ /** The name of a Property. May not have leading or trailing spaces, and must be between 3 and 2048 characters long. */
59
+ type PropertyName = string;
60
+ /** An array of PropertyName/PropertyType pairs to be stored in a PropertyStore. */
61
+ type PropertyArray = {
62
+ name: PropertyName;
63
+ value: PropertyType;
64
+ }[];
65
+ /** The return status of an iteration function. The value "stop" causes the iteration to terminate. */
66
+ type IterationReturn = void | "stop";
67
+ /** An iteration function over Properties in a PropertyStore. It is called with the name of a each Property. */
68
+ type PropertyIteration = (name: string) => IterationReturn;
69
+ /** A filter used to limit and/or sort the values returned by an iteration. */
70
+ interface PropertyFilter {
71
+ /** A value filter. May include wild cards when used with `GLOB` or `LIKE` */
72
+ readonly value?: string;
73
+ /** The comparison operator for `value`. Default is `=` */
74
+ readonly valueCompare?: "GLOB" | "LIKE" | "NOT GLOB" | "NOT LIKE" | "=" | "<" | ">";
75
+ /** Order results ascending or descending. If not supplied, the results are unordered (random). */
76
+ readonly orderBy?: "ASC" | "DESC";
77
+ /** An SQL expression to further filter results. This string is appended to the `WHERE` clause with an `AND` (that should not be part of the sqlExpression) */
78
+ readonly sqlExpression?: string;
79
+ }
80
+ /**
81
+ * A readonly set of Property values in a PropertyStore.
82
+ * @alpha
83
+ */
84
+ interface Values {
85
+ /** get the value of a Property by name.
86
+ * @returns the property's value if it exists, `undefined` otherwise.
87
+ */
88
+ getProperty(name: PropertyName): PropertyType | undefined;
89
+ /** Get the value of a string property by name.
90
+ * @returns the property's value if it exists and is a string, `undefined` otherwise.
91
+ */
92
+ getString(name: PropertyName): string | undefined;
93
+ /** Get the value of a string property by name.
94
+ * @returns the property's value if it exists and is a string, otherwise the supplied default value.
95
+ */
96
+ getString(name: PropertyName, defaultValue: string): string;
97
+ /** Get the value of a boolean property by name.
98
+ * @returns the property's value if it exists and is a boolean, `undefined` otherwise.
99
+ */
100
+ getBoolean(name: PropertyName): boolean | undefined;
101
+ /** Get the value of a boolean property by name.
102
+ * @returns the property's value if it exists and is a boolean, otherwise the supplied default value.
103
+ */
104
+ getBoolean(name: PropertyName, defaultValue: boolean): boolean;
105
+ /** Get the value of a number property by name.
106
+ * @returns the property's value if it exists and is a number, `undefined` otherwise.
107
+ */
108
+ getNumber(name: PropertyName): number | undefined;
109
+ /** Get the value of a number property by name.
110
+ * @returns the property's value if it exists and is a number, otherwise the supplied default value.
111
+ */
112
+ getNumber(name: PropertyName, defaultValue: number): number;
113
+ /** Get the value of a blob property by name.
114
+ * @returns the property's value if it exists and is a blob, `undefined` otherwise.
115
+ */
116
+ getBlob(name: PropertyName): Uint8Array | undefined;
117
+ /** Get the value of a blob property by name.
118
+ * @returns the property's value if it exists and is a blob, otherwise the supplied default value.
119
+ */
120
+ getBlob(name: PropertyName, defaultValue: Uint8Array): Uint8Array;
121
+ /** Get the value of an object property by name.
122
+ * @returns the property's value if it exists and is an object, `undefined` otherwise.
123
+ */
124
+ getObject<T extends SettingObject>(name: PropertyName): T | undefined;
125
+ /** Get the value of an object property by name.
126
+ * @returns the property's value if it exists and is an object, otherwise the supplied default value.
127
+ */
128
+ getObject<T extends SettingObject>(name: PropertyName, defaultValue: T): T;
129
+ /** call an iteration function for each property, optionally applying a filter */
130
+ forAllProperties(iter: PropertyIteration, filter?: PropertyFilter): void;
131
+ }
132
+ }
133
+ //# sourceMappingURL=PropertyStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyStore.d.ts","sourceRoot":"","sources":["../../src/PropertyStore.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;YAOY;AACZ,MAAM,WAAW,aAAa;IAE5B,sGAAsG;IACtG,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;IAEtC,mFAAmF;IACnF,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,gBAAgB,CAAC;IAElD;;;OAGG;IACH,QAAQ,EAAE,WAAW,CAAC;IAEtB;;;;;;;OAOG;IACH,oBAAoB,IAAI,IAAI,CAAC;IAE7B;;OAEG;IACH,aAAa,IAAI,WAAW,CAAC,aAAa,CAAC;IAE3C;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,YAAY,EAAE,KAAK,EAAE,aAAa,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE;;OAEG;IACH,cAAc,CAAC,QAA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SAAS,CAAC;QAC1D;;UAEE;QACF,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;QAClD;;UAEE;QACF,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5D;;UAEE;QACF,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;QACpD;;UAEE;QACF,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC;QAC/D;;UAEE;QACF,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;QAClD;;UAEE;QACF,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5D;;UAEE;QACF,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;QACpD;;UAEE;QACF,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,GAAG,UAAU,CAAC;QAClE;;UAEE;QACF,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,GAAG,SAAS,CAAC;QACtE;;UAEE;QACF,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC;QAC3E,iFAAiF;QACjF,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;KAC1E;CACF"}
@@ -0,0 +1,12 @@
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.PropertyStore = void 0;
8
+ /** @alpha */
9
+ var PropertyStore;
10
+ (function (PropertyStore) {
11
+ })(PropertyStore = exports.PropertyStore || (exports.PropertyStore = {}));
12
+ //# sourceMappingURL=PropertyStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyStore.js","sourceRoot":"","sources":["../../src/PropertyStore.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AA6D/F,aAAa;AACb,IAAiB,aAAa,CA+E7B;AA/ED,WAAiB,aAAa;AA+E9B,CAAC,EA/EgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QA+E7B","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 { AccessToken } from \"@itwin/core-bentley\";\nimport { CloudSqlite } from \"./CloudSqlite\";\nimport { SettingObject } from \"./workspace/Settings\";\n\n/**\n * A persistent storage for a set of values of type `PropertyType`, each with a unique `PropertyName`.\n * `PropertyStore`s are stored in cloud containers, and require an access token that grants permission to read and/or write them.\n * All write operations will fail without an access token that grants write permission.\n * A `PropertyStore` is cached on a local drive so reads are fast and inexpensive, and may even be done offline after a prefetch.\n * However, that means that callers are responsible for synchronizing the local cache to ensure it includes changes\n * made by others, as appropriate (see [[synchronizeWithCloud]]).\n * @alpha */\nexport interface PropertyStore {\n\n /** The collection of property values in the PropertyStore as of the last time it was synchronized. */\n readonly values: PropertyStore.Values;\n\n /** Parameters for obtaining the write lock on the container for a PropertyStore.*/\n readonly lockParams: CloudSqlite.ObtainLockParams;\n\n /**\n * The token that grants access to the cloud container for this PropertyStore. If it does not grant write permissions, all\n * write operations will fail. It should be refreshed (via a timer) before it expires.\n */\n sasToken: AccessToken;\n\n /**\n * Synchronize the local values in this PropertyStore with any changes by made by others.\n * @note This is called automatically whenever any write operation is performed on the PropertyStore. It is only necessary to\n * call this directly if you have not changed the PropertyStore recently, but wish to perform a readonly operation and want to\n * ensure it is up-to-date as of now.\n * @note There is no guarantee that the Values are up-to-date even immediately after calling this method, since others\n * may be modifying them at any time.\n */\n synchronizeWithCloud(): void;\n\n /** initiate a prefetch operation on this PropertyStore\n * @internal\n */\n startPrefetch(): CloudSqlite.CloudPrefetch;\n\n /** Save a single property in this PropertyStore. If the property already exists, its value is overwritten.\n * @note This will obtain the write lock, save the value, and then release the write lock.\n */\n saveProperty(name: PropertyStore.PropertyName, value: PropertyStore.PropertyType): Promise<void>;\n /** Save an array of properties in this PropertyStore. If a property already exists, its value is overwritten.\n * @note This will obtain the write lock, save the values, and then release the write lock.\n */\n saveProperties(props: PropertyStore.PropertyArray): Promise<void>;\n /** Delete a single property from this PropertyStore. If the value does not exist, this method does nothing.\n * @note This will obtain the write lock, delete the value, and then release the write lock.\n */\n deleteProperty(propName: PropertyStore.PropertyName): Promise<void>;\n /** Delete an array of properties from this PropertyStore. Any value that does not exist is ignored.\n * @note This will obtain the write lock, delete the values, and then release the write lock.\n */\n deleteProperties(propNames: PropertyStore.PropertyName[]): Promise<void>;\n}\n\n/** @alpha */\nexport namespace PropertyStore {\n /** @internal */\n export let openPropertyStore: ((props: CloudSqlite.ContainerAccessProps) => PropertyStore) | undefined;\n\n /** The set of valid types for properties in a PropertyStore. */\n export type PropertyType = string | number | boolean | Uint8Array | SettingObject;\n /** The name of a Property. May not have leading or trailing spaces, and must be between 3 and 2048 characters long. */\n export type PropertyName = string;\n /** An array of PropertyName/PropertyType pairs to be stored in a PropertyStore. */\n export type PropertyArray = { name: PropertyName, value: PropertyType }[];\n /** The return status of an iteration function. The value \"stop\" causes the iteration to terminate. */\n export type IterationReturn = void | \"stop\";\n /** An iteration function over Properties in a PropertyStore. It is called with the name of a each Property. */\n export type PropertyIteration = (name: string) => IterationReturn;\n\n /** A filter used to limit and/or sort the values returned by an iteration. */\n export interface PropertyFilter {\n /** A value filter. May include wild cards when used with `GLOB` or `LIKE` */\n readonly value?: string;\n /** The comparison operator for `value`. Default is `=` */\n readonly valueCompare?: \"GLOB\" | \"LIKE\" | \"NOT GLOB\" | \"NOT LIKE\" | \"=\" | \"<\" | \">\";\n /** Order results ascending or descending. If not supplied, the results are unordered (random). */\n readonly orderBy?: \"ASC\" | \"DESC\";\n /** An SQL expression to further filter results. This string is appended to the `WHERE` clause with an `AND` (that should not be part of the sqlExpression) */\n readonly sqlExpression?: string;\n }\n\n /**\n * A readonly set of Property values in a PropertyStore.\n * @alpha\n */\n export interface Values {\n /** get the value of a Property by name.\n * @returns the property's value if it exists, `undefined` otherwise.\n */\n getProperty(name: PropertyName): PropertyType | undefined;\n /** Get the value of a string property by name.\n * @returns the property's value if it exists and is a string, `undefined` otherwise.\n */\n getString(name: PropertyName): string | undefined;\n /** Get the value of a string property by name.\n * @returns the property's value if it exists and is a string, otherwise the supplied default value.\n */\n getString(name: PropertyName, defaultValue: string): string;\n /** Get the value of a boolean property by name.\n * @returns the property's value if it exists and is a boolean, `undefined` otherwise.\n */\n getBoolean(name: PropertyName): boolean | undefined;\n /** Get the value of a boolean property by name.\n * @returns the property's value if it exists and is a boolean, otherwise the supplied default value.\n */\n getBoolean(name: PropertyName, defaultValue: boolean): boolean;\n /** Get the value of a number property by name.\n * @returns the property's value if it exists and is a number, `undefined` otherwise.\n */\n getNumber(name: PropertyName): number | undefined;\n /** Get the value of a number property by name.\n * @returns the property's value if it exists and is a number, otherwise the supplied default value.\n */\n getNumber(name: PropertyName, defaultValue: number): number;\n /** Get the value of a blob property by name.\n * @returns the property's value if it exists and is a blob, `undefined` otherwise.\n */\n getBlob(name: PropertyName): Uint8Array | undefined;\n /** Get the value of a blob property by name.\n * @returns the property's value if it exists and is a blob, otherwise the supplied default value.\n */\n getBlob(name: PropertyName, defaultValue: Uint8Array): Uint8Array;\n /** Get the value of an object property by name.\n * @returns the property's value if it exists and is an object, `undefined` otherwise.\n */\n getObject<T extends SettingObject>(name: PropertyName): T | undefined;\n /** Get the value of an object property by name.\n * @returns the property's value if it exists and is an object, otherwise the supplied default value.\n */\n getObject<T extends SettingObject>(name: PropertyName, defaultValue: T): T;\n /** call an iteration function for each property, optionally applying a filter */\n forAllProperties(iter: PropertyIteration, filter?: PropertyFilter): void;\n }\n}\n"]}