@itwin/core-backend 3.4.5 → 3.4.7

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 (226) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -23
  3. package/lib/cjs/AliCloudStorageService.js +71 -71
  4. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  5. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  6. package/lib/cjs/BackendHubAccess.js +41 -41
  7. package/lib/cjs/BackendHubAccess.js.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.d.ts +91 -91
  9. package/lib/cjs/BackendLoggerCategory.js +99 -99
  10. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  11. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  12. package/lib/cjs/BisCoreSchema.js +60 -60
  13. package/lib/cjs/BisCoreSchema.js.map +1 -1
  14. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  15. package/lib/cjs/BriefcaseManager.js +405 -405
  16. package/lib/cjs/BriefcaseManager.js.map +1 -1
  17. package/lib/cjs/Category.d.ts +153 -153
  18. package/lib/cjs/Category.js +243 -243
  19. package/lib/cjs/Category.js.map +1 -1
  20. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  21. package/lib/cjs/ChangeSummaryManager.js +445 -445
  22. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  23. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  24. package/lib/cjs/ChangedElementsDb.js +165 -165
  25. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  26. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  27. package/lib/cjs/ChangedElementsManager.js +88 -88
  28. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  29. package/lib/cjs/CheckpointManager.d.ts +120 -120
  30. package/lib/cjs/CheckpointManager.js +343 -343
  31. package/lib/cjs/CheckpointManager.js.map +1 -1
  32. package/lib/cjs/ClassRegistry.d.ts +79 -79
  33. package/lib/cjs/ClassRegistry.js +249 -249
  34. package/lib/cjs/ClassRegistry.js.map +1 -1
  35. package/lib/cjs/CloudSqlite.d.ts +349 -349
  36. package/lib/cjs/CloudSqlite.js +151 -151
  37. package/lib/cjs/CloudSqlite.js.map +1 -1
  38. package/lib/cjs/CloudStorageBackend.d.ts +58 -58
  39. package/lib/cjs/CloudStorageBackend.js +173 -173
  40. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  41. package/lib/cjs/CodeService.d.ts +396 -396
  42. package/lib/cjs/CodeService.js +63 -63
  43. package/lib/cjs/CodeService.js.map +1 -1
  44. package/lib/cjs/CodeSpecs.d.ts +50 -50
  45. package/lib/cjs/CodeSpecs.js +112 -112
  46. package/lib/cjs/CodeSpecs.js.map +1 -1
  47. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  48. package/lib/cjs/ConcurrentQuery.js +30 -30
  49. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  50. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  51. package/lib/cjs/CustomViewState3dCreator.js +81 -81
  52. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  53. package/lib/cjs/DevTools.d.ts +71 -71
  54. package/lib/cjs/DevTools.js +154 -154
  55. package/lib/cjs/DevTools.js.map +1 -1
  56. package/lib/cjs/DisplayStyle.d.ts +106 -106
  57. package/lib/cjs/DisplayStyle.js +256 -256
  58. package/lib/cjs/DisplayStyle.js.map +1 -1
  59. package/lib/cjs/ECDb.d.ts +191 -191
  60. package/lib/cjs/ECDb.js +350 -350
  61. package/lib/cjs/ECDb.js.map +1 -1
  62. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  63. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  64. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  65. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  66. package/lib/cjs/ECSqlStatement.js +791 -791
  67. package/lib/cjs/ECSqlStatement.js.map +1 -1
  68. package/lib/cjs/Element.d.ts +1120 -1120
  69. package/lib/cjs/Element.js +1438 -1438
  70. package/lib/cjs/Element.js.map +1 -1
  71. package/lib/cjs/ElementAspect.d.ts +161 -161
  72. package/lib/cjs/ElementAspect.js +187 -187
  73. package/lib/cjs/ElementAspect.js.map +1 -1
  74. package/lib/cjs/ElementGraphics.d.ts +9 -9
  75. package/lib/cjs/ElementGraphics.js +41 -41
  76. package/lib/cjs/ElementGraphics.js.map +1 -1
  77. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  78. package/lib/cjs/ElementTreeWalker.js +409 -409
  79. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  80. package/lib/cjs/Entity.d.ts +106 -106
  81. package/lib/cjs/Entity.js +134 -134
  82. package/lib/cjs/Entity.js.map +1 -1
  83. package/lib/cjs/EntityReferences.d.ts +45 -45
  84. package/lib/cjs/EntityReferences.js +91 -91
  85. package/lib/cjs/EntityReferences.js.map +1 -1
  86. package/lib/cjs/ExportGraphics.d.ts +317 -317
  87. package/lib/cjs/ExportGraphics.js +208 -208
  88. package/lib/cjs/ExportGraphics.js.map +1 -1
  89. package/lib/cjs/ExternalSource.d.ts +96 -96
  90. package/lib/cjs/ExternalSource.js +131 -131
  91. package/lib/cjs/ExternalSource.js.map +1 -1
  92. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  93. package/lib/cjs/GeoCoordConfig.js +82 -82
  94. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  95. package/lib/cjs/GeometrySummary.d.ts +4 -4
  96. package/lib/cjs/GeometrySummary.js +380 -380
  97. package/lib/cjs/GeometrySummary.js.map +1 -1
  98. package/lib/cjs/HubMock.d.ts +93 -93
  99. package/lib/cjs/HubMock.js +190 -190
  100. package/lib/cjs/HubMock.js.map +1 -1
  101. package/lib/cjs/IModelCloneContext.d.ts +89 -89
  102. package/lib/cjs/IModelCloneContext.js +159 -159
  103. package/lib/cjs/IModelCloneContext.js.map +1 -1
  104. package/lib/cjs/IModelDb.d.ts +1180 -1180
  105. package/lib/cjs/IModelDb.js +2371 -2371
  106. package/lib/cjs/IModelDb.js.map +1 -1
  107. package/lib/cjs/IModelHost.d.ts +361 -361
  108. package/lib/cjs/IModelHost.js +489 -489
  109. package/lib/cjs/IModelHost.js.map +1 -1
  110. package/lib/cjs/IModelJsFs.d.ts +62 -62
  111. package/lib/cjs/IModelJsFs.js +140 -140
  112. package/lib/cjs/IModelJsFs.js.map +1 -1
  113. package/lib/cjs/IpcHost.d.ts +98 -98
  114. package/lib/cjs/IpcHost.js +234 -234
  115. package/lib/cjs/IpcHost.js.map +1 -1
  116. package/lib/cjs/LineStyle.d.ts +311 -311
  117. package/lib/cjs/LineStyle.js +295 -295
  118. package/lib/cjs/LineStyle.js.map +1 -1
  119. package/lib/cjs/LocalHub.d.ts +162 -162
  120. package/lib/cjs/LocalHub.js +587 -587
  121. package/lib/cjs/LocalHub.js.map +1 -1
  122. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  123. package/lib/cjs/LocalhostIpcHost.js +81 -81
  124. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  125. package/lib/cjs/Material.d.ts +103 -103
  126. package/lib/cjs/Material.js +147 -147
  127. package/lib/cjs/Material.js.map +1 -1
  128. package/lib/cjs/Model.d.ts +392 -392
  129. package/lib/cjs/Model.js +485 -485
  130. package/lib/cjs/Model.js.map +1 -1
  131. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  132. package/lib/cjs/NativeAppStorage.js +202 -202
  133. package/lib/cjs/NativeAppStorage.js.map +1 -1
  134. package/lib/cjs/NativeHost.d.ts +52 -52
  135. package/lib/cjs/NativeHost.js +168 -168
  136. package/lib/cjs/NativeHost.js.map +1 -1
  137. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  138. package/lib/cjs/NavigationRelationship.js +225 -225
  139. package/lib/cjs/NavigationRelationship.js.map +1 -1
  140. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  141. package/lib/cjs/PromiseMemoizer.js +101 -101
  142. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  143. package/lib/cjs/PropertyStore.d.ts +132 -132
  144. package/lib/cjs/PropertyStore.js +11 -11
  145. package/lib/cjs/PropertyStore.js.map +1 -1
  146. package/lib/cjs/Relationship.d.ts +416 -416
  147. package/lib/cjs/Relationship.js +494 -494
  148. package/lib/cjs/Relationship.js.map +1 -1
  149. package/lib/cjs/RpcBackend.d.ts +28 -28
  150. package/lib/cjs/RpcBackend.js +126 -126
  151. package/lib/cjs/RpcBackend.js.map +1 -1
  152. package/lib/cjs/SQLiteDb.d.ts +219 -219
  153. package/lib/cjs/SQLiteDb.js +214 -214
  154. package/lib/cjs/SQLiteDb.js.map +1 -1
  155. package/lib/cjs/Schema.d.ts +55 -55
  156. package/lib/cjs/Schema.js +83 -83
  157. package/lib/cjs/Schema.js.map +1 -1
  158. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  159. package/lib/cjs/ServerBasedLocks.js +168 -168
  160. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  161. package/lib/cjs/SqliteStatement.d.ts +283 -283
  162. package/lib/cjs/SqliteStatement.js +448 -448
  163. package/lib/cjs/SqliteStatement.js.map +1 -1
  164. package/lib/cjs/Texture.d.ts +58 -58
  165. package/lib/cjs/Texture.js +82 -82
  166. package/lib/cjs/Texture.js.map +1 -1
  167. package/lib/cjs/TileStorage.d.ts +18 -18
  168. package/lib/cjs/TileStorage.js +90 -90
  169. package/lib/cjs/TileStorage.js.map +1 -1
  170. package/lib/cjs/TxnManager.d.ts +202 -202
  171. package/lib/cjs/TxnManager.js +356 -356
  172. package/lib/cjs/TxnManager.js.map +1 -1
  173. package/lib/cjs/ViewDefinition.d.ts +439 -439
  174. package/lib/cjs/ViewDefinition.js +646 -646
  175. package/lib/cjs/ViewDefinition.js.map +1 -1
  176. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  177. package/lib/cjs/ViewStateHydrator.js +103 -103
  178. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  179. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  180. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  181. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  182. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  183. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  184. package/lib/cjs/core-backend.d.ts +183 -183
  185. package/lib/cjs/core-backend.js +203 -203
  186. package/lib/cjs/core-backend.js.map +1 -1
  187. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  188. package/lib/cjs/domains/FunctionalElements.js +145 -145
  189. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  190. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  191. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  192. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  193. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  194. package/lib/cjs/domains/GenericElements.js +263 -263
  195. package/lib/cjs/domains/GenericElements.js.map +1 -1
  196. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  197. package/lib/cjs/domains/GenericSchema.js +28 -28
  198. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  199. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  200. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  201. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  202. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +46 -46
  203. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +287 -287
  204. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  205. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -22
  206. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +202 -202
  207. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  208. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  209. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -168
  210. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  211. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  212. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  213. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  214. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  215. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  216. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  217. package/lib/cjs/workspace/Settings.d.ts +186 -186
  218. package/lib/cjs/workspace/Settings.js +155 -155
  219. package/lib/cjs/workspace/Settings.js.map +1 -1
  220. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  221. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  222. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  223. package/lib/cjs/workspace/Workspace.d.ts +414 -414
  224. package/lib/cjs/workspace/Workspace.js +543 -543
  225. package/lib/cjs/workspace/Workspace.js.map +1 -1
  226. package/package.json +13 -13
@@ -1,156 +1,156 @@
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.BaseSettings = exports.SettingsPriority = void 0;
11
- const fs = require("fs-extra");
12
- const json5_1 = require("json5");
13
- const path_1 = require("path");
14
- const core_bentley_1 = require("@itwin/core-bentley");
15
- const IModelJsFs_1 = require("../IModelJsFs");
16
- /**
17
- * Values for SettingsPriority determine the sort order for Settings. Higher values take precedence over lower values.
18
- * @beta
19
- */
20
- var SettingsPriority;
21
- (function (SettingsPriority) {
22
- /** values supplied default-settings files */
23
- SettingsPriority[SettingsPriority["defaults"] = 100] = "defaults";
24
- /** values supplied by applications at runtime */
25
- SettingsPriority[SettingsPriority["application"] = 200] = "application";
26
- /** values that apply to all iTwins for an organization. */
27
- SettingsPriority[SettingsPriority["organization"] = 300] = "organization";
28
- /** values that apply to all iModels in an iTwin. */
29
- SettingsPriority[SettingsPriority["iTwin"] = 400] = "iTwin";
30
- /** values that apply to a single iModel. */
31
- SettingsPriority[SettingsPriority["iModel"] = 500] = "iModel";
32
- })(SettingsPriority = exports.SettingsPriority || (exports.SettingsPriority = {}));
33
- /** @internal */
34
- function deepClone(obj) {
35
- if (!obj || typeof obj !== "object")
36
- return obj;
37
- const result = Array.isArray(obj) ? [] : {};
38
- Object.keys(obj).forEach((key) => {
39
- const val = obj[key];
40
- if (val && typeof val === "object") {
41
- result[key] = deepClone(val);
42
- }
43
- else {
44
- result[key] = val;
45
- }
46
- });
47
- return result;
48
- }
49
- class SettingsDictionary {
50
- constructor(name, priority, settings) {
51
- this.name = name;
52
- this.priority = priority;
53
- this.settings = settings;
54
- }
55
- getSetting(settingName) {
56
- return this.settings[settingName];
57
- }
58
- }
59
- /**
60
- * Internal implementation of Settings interface.
61
- * @internal
62
- */
63
- class BaseSettings {
64
- constructor() {
65
- this._dictionaries = [];
66
- this.onSettingsChanged = new core_bentley_1.BeEvent();
67
- }
68
- verifyPriority(_priority) { }
69
- close() { }
70
- addFile(fileName, priority) {
71
- this.addJson(fileName, priority, fs.readFileSync(fileName, "utf-8"));
72
- }
73
- addDirectory(dirName, priority) {
74
- for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
75
- const ext = (0, path_1.extname)(fileName);
76
- if (ext === ".json5" || ext === ".json")
77
- this.addFile((0, path_1.join)(dirName, fileName), priority);
78
- }
79
- }
80
- addJson(dictionaryName, priority, settingsJson) {
81
- this.addDictionary(dictionaryName, priority, (0, json5_1.parse)(settingsJson));
82
- }
83
- addDictionary(dictionaryName, priority, settings) {
84
- this.verifyPriority(priority);
85
- this.dropDictionary(dictionaryName, false); // make sure we don't have the same dictionary twice
86
- const file = new SettingsDictionary(dictionaryName, priority, settings);
87
- const doAdd = () => {
88
- for (let i = 0; i < this._dictionaries.length; ++i) {
89
- if (this._dictionaries[i].priority <= file.priority) {
90
- this._dictionaries.splice(i, 0, file);
91
- return;
92
- }
93
- }
94
- this._dictionaries.push(file);
95
- };
96
- doAdd();
97
- this.onSettingsChanged.raiseEvent();
98
- }
99
- dropDictionary(dictionaryName, raiseEvent = true) {
100
- for (let i = 0; i < this._dictionaries.length; ++i) {
101
- if (this._dictionaries[i].name === dictionaryName) {
102
- this._dictionaries.splice(i, 1);
103
- if (raiseEvent)
104
- this.onSettingsChanged.raiseEvent();
105
- return true;
106
- }
107
- }
108
- return false;
109
- }
110
- resolveSetting(name, resolver, defaultValue) {
111
- for (const dict of this._dictionaries) {
112
- const val = dict.getSetting(name);
113
- const resolved = val && resolver(val, dict.name, dict.priority);
114
- if (undefined !== resolved)
115
- return resolved;
116
- }
117
- return defaultValue;
118
- }
119
- getSetting(name, defaultValue) {
120
- var _a;
121
- return (_a = this.resolveSetting(name, (val) => deepClone(val))) !== null && _a !== void 0 ? _a : defaultValue;
122
- }
123
- /** for debugging. Returns an array of all values for a setting, sorted by priority.
124
- * @note values are not cloned. Do not modify objects or arrays.
125
- */
126
- inspectSetting(name) {
127
- const all = [];
128
- this.resolveSetting(name, (value, dictionary, priority) => {
129
- all.push({ value, dictionary, priority });
130
- return undefined;
131
- });
132
- return all;
133
- }
134
- getString(name, defaultValue) {
135
- const out = this.getSetting(name);
136
- return typeof out === "string" ? out : defaultValue;
137
- }
138
- getBoolean(name, defaultValue) {
139
- const out = this.getSetting(name);
140
- return typeof out === "boolean" ? out : defaultValue;
141
- }
142
- getNumber(name, defaultValue) {
143
- const out = this.getSetting(name);
144
- return typeof out === "number" ? out : defaultValue;
145
- }
146
- getObject(name, defaultValue) {
147
- const out = this.getSetting(name);
148
- return typeof out === "object" ? out : defaultValue;
149
- }
150
- getArray(name, defaultValue) {
151
- const out = this.getSetting(name);
152
- return Array.isArray(out) ? out : defaultValue;
153
- }
154
- }
155
- exports.BaseSettings = BaseSettings;
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.BaseSettings = exports.SettingsPriority = void 0;
11
+ const fs = require("fs-extra");
12
+ const json5_1 = require("json5");
13
+ const path_1 = require("path");
14
+ const core_bentley_1 = require("@itwin/core-bentley");
15
+ const IModelJsFs_1 = require("../IModelJsFs");
16
+ /**
17
+ * Values for SettingsPriority determine the sort order for Settings. Higher values take precedence over lower values.
18
+ * @beta
19
+ */
20
+ var SettingsPriority;
21
+ (function (SettingsPriority) {
22
+ /** values supplied default-settings files */
23
+ SettingsPriority[SettingsPriority["defaults"] = 100] = "defaults";
24
+ /** values supplied by applications at runtime */
25
+ SettingsPriority[SettingsPriority["application"] = 200] = "application";
26
+ /** values that apply to all iTwins for an organization. */
27
+ SettingsPriority[SettingsPriority["organization"] = 300] = "organization";
28
+ /** values that apply to all iModels in an iTwin. */
29
+ SettingsPriority[SettingsPriority["iTwin"] = 400] = "iTwin";
30
+ /** values that apply to a single iModel. */
31
+ SettingsPriority[SettingsPriority["iModel"] = 500] = "iModel";
32
+ })(SettingsPriority = exports.SettingsPriority || (exports.SettingsPriority = {}));
33
+ /** @internal */
34
+ function deepClone(obj) {
35
+ if (!obj || typeof obj !== "object")
36
+ return obj;
37
+ const result = Array.isArray(obj) ? [] : {};
38
+ Object.keys(obj).forEach((key) => {
39
+ const val = obj[key];
40
+ if (val && typeof val === "object") {
41
+ result[key] = deepClone(val);
42
+ }
43
+ else {
44
+ result[key] = val;
45
+ }
46
+ });
47
+ return result;
48
+ }
49
+ class SettingsDictionary {
50
+ constructor(name, priority, settings) {
51
+ this.name = name;
52
+ this.priority = priority;
53
+ this.settings = settings;
54
+ }
55
+ getSetting(settingName) {
56
+ return this.settings[settingName];
57
+ }
58
+ }
59
+ /**
60
+ * Internal implementation of Settings interface.
61
+ * @internal
62
+ */
63
+ class BaseSettings {
64
+ constructor() {
65
+ this._dictionaries = [];
66
+ this.onSettingsChanged = new core_bentley_1.BeEvent();
67
+ }
68
+ verifyPriority(_priority) { }
69
+ close() { }
70
+ addFile(fileName, priority) {
71
+ this.addJson(fileName, priority, fs.readFileSync(fileName, "utf-8"));
72
+ }
73
+ addDirectory(dirName, priority) {
74
+ for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
75
+ const ext = (0, path_1.extname)(fileName);
76
+ if (ext === ".json5" || ext === ".json")
77
+ this.addFile((0, path_1.join)(dirName, fileName), priority);
78
+ }
79
+ }
80
+ addJson(dictionaryName, priority, settingsJson) {
81
+ this.addDictionary(dictionaryName, priority, (0, json5_1.parse)(settingsJson));
82
+ }
83
+ addDictionary(dictionaryName, priority, settings) {
84
+ this.verifyPriority(priority);
85
+ this.dropDictionary(dictionaryName, false); // make sure we don't have the same dictionary twice
86
+ const file = new SettingsDictionary(dictionaryName, priority, settings);
87
+ const doAdd = () => {
88
+ for (let i = 0; i < this._dictionaries.length; ++i) {
89
+ if (this._dictionaries[i].priority <= file.priority) {
90
+ this._dictionaries.splice(i, 0, file);
91
+ return;
92
+ }
93
+ }
94
+ this._dictionaries.push(file);
95
+ };
96
+ doAdd();
97
+ this.onSettingsChanged.raiseEvent();
98
+ }
99
+ dropDictionary(dictionaryName, raiseEvent = true) {
100
+ for (let i = 0; i < this._dictionaries.length; ++i) {
101
+ if (this._dictionaries[i].name === dictionaryName) {
102
+ this._dictionaries.splice(i, 1);
103
+ if (raiseEvent)
104
+ this.onSettingsChanged.raiseEvent();
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ resolveSetting(name, resolver, defaultValue) {
111
+ for (const dict of this._dictionaries) {
112
+ const val = dict.getSetting(name);
113
+ const resolved = val && resolver(val, dict.name, dict.priority);
114
+ if (undefined !== resolved)
115
+ return resolved;
116
+ }
117
+ return defaultValue;
118
+ }
119
+ getSetting(name, defaultValue) {
120
+ var _a;
121
+ return (_a = this.resolveSetting(name, (val) => deepClone(val))) !== null && _a !== void 0 ? _a : defaultValue;
122
+ }
123
+ /** for debugging. Returns an array of all values for a setting, sorted by priority.
124
+ * @note values are not cloned. Do not modify objects or arrays.
125
+ */
126
+ inspectSetting(name) {
127
+ const all = [];
128
+ this.resolveSetting(name, (value, dictionary, priority) => {
129
+ all.push({ value, dictionary, priority });
130
+ return undefined;
131
+ });
132
+ return all;
133
+ }
134
+ getString(name, defaultValue) {
135
+ const out = this.getSetting(name);
136
+ return typeof out === "string" ? out : defaultValue;
137
+ }
138
+ getBoolean(name, defaultValue) {
139
+ const out = this.getSetting(name);
140
+ return typeof out === "boolean" ? out : defaultValue;
141
+ }
142
+ getNumber(name, defaultValue) {
143
+ const out = this.getSetting(name);
144
+ return typeof out === "number" ? out : defaultValue;
145
+ }
146
+ getObject(name, defaultValue) {
147
+ const out = this.getSetting(name);
148
+ return typeof out === "object" ? out : defaultValue;
149
+ }
150
+ getArray(name, defaultValue) {
151
+ const out = this.getSetting(name);
152
+ return Array.isArray(out) ? out : defaultValue;
153
+ }
154
+ }
155
+ exports.BaseSettings = BaseSettings;
156
156
  //# sourceMappingURL=Settings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../../src/workspace/Settings.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAA8D;AAE9D,8CAA2C;AAmD3C;;;EAGE;AACF,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IAC1B,6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AAC,CAAC,GAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAC3D,CAAC;IAGM,QAAQ,CAAwB,IAAiB,EAAE,YAAuB;QAC/E,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAW,IAAI,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACjD,CAAC;CACF;AA5GD,oCA4GC","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 Workspace\r\n */\r\n\r\nimport * as fs from \"fs-extra\";\r\nimport { parse } from \"json5\";\r\nimport { extname, join } from \"path\";\r\nimport { BeEvent, JSONSchemaType } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\n/** The type of a Setting, according to its schema\r\n * @beta\r\n */\r\nexport type SettingType = JSONSchemaType;\r\n\r\n/**\r\n * The name of a Setting. SettingNames must be valid JavaScript property names, defined in a [[SettingSchema]].\r\n * @see [SettingName]($docs/learning/backend/Workspace#settingnames)\r\n * @beta\r\n */\r\nexport type SettingName = string;\r\n\r\n/** The name of a [[SettingDictionary]]. `SettingDictionary`s are stored in [[Settings]] and may be removed by DictionaryName.\r\n * DictionaryNames must be valid JavaScript property names.\r\n * @beta\r\n */\r\nexport type DictionaryName = string;\r\n\r\n/**\r\n * A function called by [[Settings.resolveSetting]] for every SettingDictionary with a Setting that matches a name. The\r\n * SettingDictionaries are sorted by priority and this function is called in priority order with the highest priority first.\r\n * When this function returns a non-undefined value, the iteration is stopped and that value is returned. In this way,\r\n * applications can \"combine\" the prioritized Setting values as appropriate. The default implementation of this function\r\n * used by [[Settings.getSetting]] merely returns a clone of the value the first time it is called, so the highest priority\r\n * value is returned.\r\n * @beta\r\n */\r\nexport type SettingResolver<T> = (val: T, dict: DictionaryName, priority: SettingsPriority) => T | undefined;\r\n\r\n/** An entry in the array returned by [[Settings.inspectSetting]]\r\n * @beta\r\n *\r\n */\r\nexport interface SettingInspector<T> { value: T, dictionary: DictionaryName, priority: number }\r\n\r\n/** An object with string-named members (as opposed to an array object).\r\n * @beta\r\n */\r\nexport interface SettingObject {\r\n [name: string]: SettingType;\r\n}\r\n\r\n/**\r\n * An object with Settings as its members. A SettingDictionary also has a name and generally comes from a parsed JSON file, but\r\n * may also be created in memory by applications\r\n * @beta\r\n */\r\nexport type SettingDictionary = SettingObject;\r\n\r\n/**\r\n * Values for SettingsPriority determine the sort order for Settings. Higher values take precedence over lower values.\r\n * @beta\r\n*/\r\nexport enum SettingsPriority {\r\n /** values supplied default-settings files */\r\n defaults = 100,\r\n /** values supplied by applications at runtime */\r\n application = 200,\r\n /** values that apply to all iTwins for an organization. */\r\n organization = 300,\r\n /** values that apply to all iModels in an iTwin. */\r\n iTwin = 400,\r\n /** values that apply to a single iModel. */\r\n iModel = 500,\r\n}\r\n\r\n/** The current set of Settings for a Workspace.\r\n * @beta\r\n */\r\nexport interface Settings {\r\n /** @internal */\r\n close(): void;\r\n\r\n /** Event raised whenever a SettingsDictionary is added or removed. */\r\n readonly onSettingsChanged: BeEvent<() => void>;\r\n\r\n /** Add a SettingDictionary from a local settings file. The file should be in [JSON5](https://json5.org/) format. It is read\r\n * and parsed and the fileName is used as the DictionaryName.\r\n * @param fileName the name of a local settings file of the SettingDictionary. This becomes the DictionaryName.\r\n * @param priority the SettingsPriority for the SettingDictionary\r\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\r\n */\r\n addFile(fileName: LocalFileName, priority: SettingsPriority): void;\r\n\r\n /** Add all files in the supplied directory with the extension \".json\" or \".json5\"\r\n * @param dirName the name of a local settings directory\r\n */\r\n addDirectory(dirName: LocalDirName, priority: SettingsPriority): void;\r\n\r\n /** Add a SettingDictionary from a JSON5 stringified string. The string is parsed and the resultant object is added as a SettingDictionary.\r\n * @param dictionaryName the name of the SettingDictionary\r\n * @param priority the SettingsPriority for the SettingDictionary\r\n * @param settingsJson the JSON5 stringified string to be parsed.\r\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\r\n */\r\n addJson(dictionaryName: DictionaryName, priority: SettingsPriority, settingsJson: string): void;\r\n\r\n /** Add a SettingDictionary object.\r\n * @param dictionaryName the name of the SettingDictionary\r\n * @param priority the SettingsPriority for the SettingDictionary\r\n * @param settings the SettingDictionary object to be added.\r\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\r\n */\r\n addDictionary(dictionaryName: DictionaryName, priority: SettingsPriority, settings: SettingDictionary): void;\r\n\r\n /** Remove a SettingDictionary by name. */\r\n dropDictionary(dictionaryName: DictionaryName): void;\r\n\r\n /**\r\n * Resolve a setting, by name, using a SettingResolver.\r\n * @param settingName The name of the setting to resolve\r\n * @param resolver function to be called for each SettingDictionary with a matching Setting. Iteration stops when it returns a non-undefined value.\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary or resolver never returned a value.\r\n * @returns the resolved setting value.\r\n */\r\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue: T): T;\r\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue?: T): T | undefined;\r\n\r\n /** Get the highest priority setting for a SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary.\r\n * @note This method is generic on SettingType, but no type checking is actually performed at run time. So, if you\r\n * use this method to get a setting with an expected type, but its value is a different type, the return type of this method will be wrong.\r\n * You must always type check the result. Use the non-generic \"get\" methods (e.g. [[getString]]) if you only want the value\r\n * if its type is correct.\r\n */\r\n getSetting<T extends SettingType>(settingName: SettingName, defaultValue?: T): T | undefined;\r\n\r\n /** Get a string setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a string.\r\n */\r\n getString(settingName: SettingName, defaultValue: string): string;\r\n getString(settingName: SettingName, defaultValue?: string): string | undefined;\r\n\r\n /** Get a boolean setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a boolean.\r\n */\r\n getBoolean(settingName: SettingName, defaultValue: boolean): boolean;\r\n getBoolean(settingName: SettingName, defaultValue?: boolean): boolean | undefined;\r\n\r\n /** Get a number setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a number.\r\n */\r\n getNumber(settingName: SettingName, defaultValue: number): number;\r\n getNumber(settingName: SettingName): number | undefined;\r\n\r\n /** Get an object setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not an object.\r\n */\r\n getObject<T extends object>(settingName: SettingName, defaultValue: T): T;\r\n getObject<T extends object>(settingName: SettingName): T | undefined;\r\n\r\n /** Get an array setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not an array.\r\n */\r\n getArray<T extends SettingType>(settingName: SettingName, defaultValue: Array<T>): Array<T>;\r\n getArray<T extends SettingType>(settingName: SettingName): Array<T> | undefined;\r\n\r\n /** Get an array of [[SettingInspector] objects, sorted in priority order, for all Settings that match a SettingName.\r\n * @note this method is mainly for debugging and diagnostics.\r\n */\r\n inspectSetting<T extends SettingType>(name: SettingName): SettingInspector<T>[];\r\n}\r\n\r\n/** @internal */\r\nfunction deepClone<T extends SettingType>(obj: any): T {\r\n if (!obj || typeof obj !== \"object\")\r\n return obj;\r\n\r\n const result = Array.isArray(obj) ? [] : {} as any;\r\n Object.keys(obj).forEach((key: string) => {\r\n const val = obj[key];\r\n if (val && typeof val === \"object\") {\r\n result[key] = deepClone(val);\r\n } else {\r\n result[key] = val;\r\n }\r\n });\r\n return result;\r\n}\r\n\r\nclass SettingsDictionary {\r\n public constructor(public readonly name: string, public readonly priority: SettingsPriority, public readonly settings: SettingDictionary) { }\r\n public getSetting<T extends SettingType>(settingName: string): SettingType | undefined {\r\n return this.settings[settingName] as T | undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Internal implementation of Settings interface.\r\n * @internal\r\n */\r\nexport class BaseSettings implements Settings {\r\n private _dictionaries: SettingsDictionary[] = [];\r\n protected verifyPriority(_priority: SettingsPriority) { }\r\n public close() { }\r\n public readonly onSettingsChanged = new BeEvent<() => void>();\r\n\r\n public addFile(fileName: LocalFileName, priority: SettingsPriority) {\r\n this.addJson(fileName, priority, fs.readFileSync(fileName, \"utf-8\"));\r\n }\r\n\r\n public addDirectory(dirName: LocalDirName, priority: SettingsPriority) {\r\n for (const fileName of IModelJsFs.readdirSync(dirName)) {\r\n const ext = extname(fileName);\r\n if (ext === \".json5\" || ext === \".json\")\r\n this.addFile(join(dirName, fileName), priority);\r\n }\r\n }\r\n\r\n public addJson(dictionaryName: string, priority: SettingsPriority, settingsJson: string) {\r\n this.addDictionary(dictionaryName, priority, parse(settingsJson));\r\n }\r\n\r\n public addDictionary(dictionaryName: string, priority: SettingsPriority, settings: SettingDictionary) {\r\n this.verifyPriority(priority);\r\n this.dropDictionary(dictionaryName, false); // make sure we don't have the same dictionary twice\r\n const file = new SettingsDictionary(dictionaryName, priority, settings);\r\n const doAdd = () => {\r\n for (let i = 0; i < this._dictionaries.length; ++i) {\r\n if (this._dictionaries[i].priority <= file.priority) {\r\n this._dictionaries.splice(i, 0, file);\r\n return;\r\n }\r\n }\r\n this._dictionaries.push(file);\r\n };\r\n doAdd();\r\n this.onSettingsChanged.raiseEvent();\r\n }\r\n\r\n public dropDictionary(dictionaryName: DictionaryName, raiseEvent = true) {\r\n for (let i = 0; i < this._dictionaries.length; ++i) {\r\n if (this._dictionaries[i].name === dictionaryName) {\r\n this._dictionaries.splice(i, 1);\r\n if (raiseEvent)\r\n this.onSettingsChanged.raiseEvent();\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public resolveSetting<T extends SettingType>(name: SettingName, resolver: SettingResolver<T>, defaultValue?: T): T | undefined {\r\n for (const dict of this._dictionaries) {\r\n const val = dict.getSetting(name) as T | undefined;\r\n const resolved = val && resolver(val, dict.name, dict.priority);\r\n if (undefined !== resolved)\r\n return resolved;\r\n }\r\n return defaultValue;\r\n }\r\n\r\n public getSetting<T extends SettingType>(name: SettingName, defaultValue?: T): T | undefined {\r\n return this.resolveSetting(name, (val) => deepClone<T>(val)) ?? defaultValue;\r\n }\r\n\r\n /** for debugging. Returns an array of all values for a setting, sorted by priority.\r\n * @note values are not cloned. Do not modify objects or arrays.\r\n */\r\n public inspectSetting<T extends SettingType>(name: SettingName): SettingInspector<T>[] {\r\n const all: SettingInspector<T>[] = [];\r\n this.resolveSetting<T>(name, (value, dictionary, priority) => {\r\n all.push({ value, dictionary, priority });\r\n return undefined;\r\n });\r\n\r\n return all;\r\n }\r\n\r\n public getString(name: SettingName, defaultValue: string): string;\r\n public getString(name: SettingName): string | undefined;\r\n public getString(name: SettingName, defaultValue?: string): string | undefined {\r\n const out = this.getSetting<string>(name);\r\n return typeof out === \"string\" ? out : defaultValue;\r\n }\r\n public getBoolean(name: SettingName, defaultValue: boolean): boolean;\r\n public getBoolean(name: SettingName): boolean | undefined;\r\n public getBoolean(name: SettingName, defaultValue?: boolean): boolean | undefined {\r\n const out = this.getSetting<boolean>(name);\r\n return typeof out === \"boolean\" ? out : defaultValue;\r\n }\r\n public getNumber(name: SettingName, defaultValue: number): number;\r\n public getNumber(name: SettingName): number | undefined;\r\n public getNumber(name: SettingName, defaultValue?: number): number | undefined {\r\n const out = this.getSetting<number>(name);\r\n return typeof out === \"number\" ? out : defaultValue;\r\n }\r\n public getObject<T extends object>(name: SettingName, defaultValue: T): T;\r\n public getObject<T extends object>(name: SettingName): T | undefined;\r\n public getObject<T extends object>(name: SettingName, defaultValue?: T): T | undefined {\r\n const out = this.getSetting<SettingObject>(name);\r\n return typeof out === \"object\" ? out as T : defaultValue;\r\n }\r\n public getArray<T extends SettingType>(name: SettingName, defaultValue: Array<T>): Array<T>;\r\n public getArray<T extends SettingType>(name: SettingName): Array<T> | undefined;\r\n public getArray<T extends SettingType>(name: SettingName, defaultValue?: Array<T>): Array<T> | undefined {\r\n const out = this.getSetting<Array<T>>(name);\r\n return Array.isArray(out) ? out : defaultValue;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../../src/workspace/Settings.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAA8D;AAE9D,8CAA2C;AAmD3C;;;EAGE;AACF,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IAC1B,6CAA6C;IAC7C,iEAAc,CAAA;IACd,iDAAiD;IACjD,uEAAiB,CAAA;IACjB,2DAA2D;IAC3D,yEAAkB,CAAA;IAClB,oDAAoD;IACpD,2DAAW,CAAA;IACX,4CAA4C;IAC5C,6DAAY,CAAA;AACd,CAAC,EAXW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAW3B;AAyGD,gBAAgB;AAChB,SAAS,SAAS,CAAwB,GAAQ;IAChD,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QACjC,OAAO,GAAG,CAAC;IAEb,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAS,CAAC;IACnD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QACvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAClC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UAAU,CAAC,IAAiB,EAAE,YAAsB;QACzD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAU,IAAI,CAAC,CAAC;QAC3C,OAAO,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACvD,CAAC;IAGM,SAAS,CAAC,IAAiB,EAAE,YAAqB;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAS,IAAI,CAAC,CAAC;QAC1C,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACtD,CAAC;IAGM,SAAS,CAAmB,IAAiB,EAAE,YAAgB;QACpE,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAgB,IAAI,CAAC,CAAC;QACjD,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAC3D,CAAC;IAGM,QAAQ,CAAwB,IAAiB,EAAE,YAAuB;QAC/E,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAW,IAAI,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACjD,CAAC;CACF;AA5GD,oCA4GC","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 Workspace\n */\n\nimport * as fs from \"fs-extra\";\nimport { parse } from \"json5\";\nimport { extname, join } from \"path\";\nimport { BeEvent, JSONSchemaType } from \"@itwin/core-bentley\";\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\nimport { IModelJsFs } from \"../IModelJsFs\";\n\n/** The type of a Setting, according to its schema\n * @beta\n */\nexport type SettingType = JSONSchemaType;\n\n/**\n * The name of a Setting. SettingNames must be valid JavaScript property names, defined in a [[SettingSchema]].\n * @see [SettingName]($docs/learning/backend/Workspace#settingnames)\n * @beta\n */\nexport type SettingName = string;\n\n/** The name of a [[SettingDictionary]]. `SettingDictionary`s are stored in [[Settings]] and may be removed by DictionaryName.\n * DictionaryNames must be valid JavaScript property names.\n * @beta\n */\nexport type DictionaryName = string;\n\n/**\n * A function called by [[Settings.resolveSetting]] for every SettingDictionary with a Setting that matches a name. The\n * SettingDictionaries are sorted by priority and this function is called in priority order with the highest priority first.\n * When this function returns a non-undefined value, the iteration is stopped and that value is returned. In this way,\n * applications can \"combine\" the prioritized Setting values as appropriate. The default implementation of this function\n * used by [[Settings.getSetting]] merely returns a clone of the value the first time it is called, so the highest priority\n * value is returned.\n * @beta\n */\nexport type SettingResolver<T> = (val: T, dict: DictionaryName, priority: SettingsPriority) => T | undefined;\n\n/** An entry in the array returned by [[Settings.inspectSetting]]\n * @beta\n *\n */\nexport interface SettingInspector<T> { value: T, dictionary: DictionaryName, priority: number }\n\n/** An object with string-named members (as opposed to an array object).\n * @beta\n */\nexport interface SettingObject {\n [name: string]: SettingType;\n}\n\n/**\n * An object with Settings as its members. A SettingDictionary also has a name and generally comes from a parsed JSON file, but\n * may also be created in memory by applications\n * @beta\n */\nexport type SettingDictionary = SettingObject;\n\n/**\n * Values for SettingsPriority determine the sort order for Settings. Higher values take precedence over lower values.\n * @beta\n*/\nexport enum SettingsPriority {\n /** values supplied default-settings files */\n defaults = 100,\n /** values supplied by applications at runtime */\n application = 200,\n /** values that apply to all iTwins for an organization. */\n organization = 300,\n /** values that apply to all iModels in an iTwin. */\n iTwin = 400,\n /** values that apply to a single iModel. */\n iModel = 500,\n}\n\n/** The current set of Settings for a Workspace.\n * @beta\n */\nexport interface Settings {\n /** @internal */\n close(): void;\n\n /** Event raised whenever a SettingsDictionary is added or removed. */\n readonly onSettingsChanged: BeEvent<() => void>;\n\n /** Add a SettingDictionary from a local settings file. The file should be in [JSON5](https://json5.org/) format. It is read\n * and parsed and the fileName is used as the DictionaryName.\n * @param fileName the name of a local settings file of the SettingDictionary. This becomes the DictionaryName.\n * @param priority the SettingsPriority for the SettingDictionary\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\n */\n addFile(fileName: LocalFileName, priority: SettingsPriority): void;\n\n /** Add all files in the supplied directory with the extension \".json\" or \".json5\"\n * @param dirName the name of a local settings directory\n */\n addDirectory(dirName: LocalDirName, priority: SettingsPriority): void;\n\n /** Add a SettingDictionary from a JSON5 stringified string. The string is parsed and the resultant object is added as a SettingDictionary.\n * @param dictionaryName the name of the SettingDictionary\n * @param priority the SettingsPriority for the SettingDictionary\n * @param settingsJson the JSON5 stringified string to be parsed.\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\n */\n addJson(dictionaryName: DictionaryName, priority: SettingsPriority, settingsJson: string): void;\n\n /** Add a SettingDictionary object.\n * @param dictionaryName the name of the SettingDictionary\n * @param priority the SettingsPriority for the SettingDictionary\n * @param settings the SettingDictionary object to be added.\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\n */\n addDictionary(dictionaryName: DictionaryName, priority: SettingsPriority, settings: SettingDictionary): void;\n\n /** Remove a SettingDictionary by name. */\n dropDictionary(dictionaryName: DictionaryName): void;\n\n /**\n * Resolve a setting, by name, using a SettingResolver.\n * @param settingName The name of the setting to resolve\n * @param resolver function to be called for each SettingDictionary with a matching Setting. Iteration stops when it returns a non-undefined value.\n * @param defaultValue value returned if settingName is not present in any SettingDictionary or resolver never returned a value.\n * @returns the resolved setting value.\n */\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue: T): T;\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue?: T): T | undefined;\n\n /** Get the highest priority setting for a SettingName.\n * @param settingName The name of the setting\n * @param defaultValue value returned if settingName is not present in any SettingDictionary.\n * @note This method is generic on SettingType, but no type checking is actually performed at run time. So, if you\n * use this method to get a setting with an expected type, but its value is a different type, the return type of this method will be wrong.\n * You must always type check the result. Use the non-generic \"get\" methods (e.g. [[getString]]) if you only want the value\n * if its type is correct.\n */\n getSetting<T extends SettingType>(settingName: SettingName, defaultValue?: T): T | undefined;\n\n /** Get a string setting by SettingName.\n * @param settingName The name of the setting\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a string.\n */\n getString(settingName: SettingName, defaultValue: string): string;\n getString(settingName: SettingName, defaultValue?: string): string | undefined;\n\n /** Get a boolean setting by SettingName.\n * @param settingName The name of the setting\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a boolean.\n */\n getBoolean(settingName: SettingName, defaultValue: boolean): boolean;\n getBoolean(settingName: SettingName, defaultValue?: boolean): boolean | undefined;\n\n /** Get a number setting by SettingName.\n * @param settingName The name of the setting\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a number.\n */\n getNumber(settingName: SettingName, defaultValue: number): number;\n getNumber(settingName: SettingName): number | undefined;\n\n /** Get an object setting by SettingName.\n * @param settingName The name of the setting\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not an object.\n */\n getObject<T extends object>(settingName: SettingName, defaultValue: T): T;\n getObject<T extends object>(settingName: SettingName): T | undefined;\n\n /** Get an array setting by SettingName.\n * @param settingName The name of the setting\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not an array.\n */\n getArray<T extends SettingType>(settingName: SettingName, defaultValue: Array<T>): Array<T>;\n getArray<T extends SettingType>(settingName: SettingName): Array<T> | undefined;\n\n /** Get an array of [[SettingInspector] objects, sorted in priority order, for all Settings that match a SettingName.\n * @note this method is mainly for debugging and diagnostics.\n */\n inspectSetting<T extends SettingType>(name: SettingName): SettingInspector<T>[];\n}\n\n/** @internal */\nfunction deepClone<T extends SettingType>(obj: any): T {\n if (!obj || typeof obj !== \"object\")\n return obj;\n\n const result = Array.isArray(obj) ? [] : {} as any;\n Object.keys(obj).forEach((key: string) => {\n const val = obj[key];\n if (val && typeof val === \"object\") {\n result[key] = deepClone(val);\n } else {\n result[key] = val;\n }\n });\n return result;\n}\n\nclass SettingsDictionary {\n public constructor(public readonly name: string, public readonly priority: SettingsPriority, public readonly settings: SettingDictionary) { }\n public getSetting<T extends SettingType>(settingName: string): SettingType | undefined {\n return this.settings[settingName] as T | undefined;\n }\n}\n\n/**\n * Internal implementation of Settings interface.\n * @internal\n */\nexport class BaseSettings implements Settings {\n private _dictionaries: SettingsDictionary[] = [];\n protected verifyPriority(_priority: SettingsPriority) { }\n public close() { }\n public readonly onSettingsChanged = new BeEvent<() => void>();\n\n public addFile(fileName: LocalFileName, priority: SettingsPriority) {\n this.addJson(fileName, priority, fs.readFileSync(fileName, \"utf-8\"));\n }\n\n public addDirectory(dirName: LocalDirName, priority: SettingsPriority) {\n for (const fileName of IModelJsFs.readdirSync(dirName)) {\n const ext = extname(fileName);\n if (ext === \".json5\" || ext === \".json\")\n this.addFile(join(dirName, fileName), priority);\n }\n }\n\n public addJson(dictionaryName: string, priority: SettingsPriority, settingsJson: string) {\n this.addDictionary(dictionaryName, priority, parse(settingsJson));\n }\n\n public addDictionary(dictionaryName: string, priority: SettingsPriority, settings: SettingDictionary) {\n this.verifyPriority(priority);\n this.dropDictionary(dictionaryName, false); // make sure we don't have the same dictionary twice\n const file = new SettingsDictionary(dictionaryName, priority, settings);\n const doAdd = () => {\n for (let i = 0; i < this._dictionaries.length; ++i) {\n if (this._dictionaries[i].priority <= file.priority) {\n this._dictionaries.splice(i, 0, file);\n return;\n }\n }\n this._dictionaries.push(file);\n };\n doAdd();\n this.onSettingsChanged.raiseEvent();\n }\n\n public dropDictionary(dictionaryName: DictionaryName, raiseEvent = true) {\n for (let i = 0; i < this._dictionaries.length; ++i) {\n if (this._dictionaries[i].name === dictionaryName) {\n this._dictionaries.splice(i, 1);\n if (raiseEvent)\n this.onSettingsChanged.raiseEvent();\n return true;\n }\n }\n return false;\n }\n\n public resolveSetting<T extends SettingType>(name: SettingName, resolver: SettingResolver<T>, defaultValue?: T): T | undefined {\n for (const dict of this._dictionaries) {\n const val = dict.getSetting(name) as T | undefined;\n const resolved = val && resolver(val, dict.name, dict.priority);\n if (undefined !== resolved)\n return resolved;\n }\n return defaultValue;\n }\n\n public getSetting<T extends SettingType>(name: SettingName, defaultValue?: T): T | undefined {\n return this.resolveSetting(name, (val) => deepClone<T>(val)) ?? defaultValue;\n }\n\n /** for debugging. Returns an array of all values for a setting, sorted by priority.\n * @note values are not cloned. Do not modify objects or arrays.\n */\n public inspectSetting<T extends SettingType>(name: SettingName): SettingInspector<T>[] {\n const all: SettingInspector<T>[] = [];\n this.resolveSetting<T>(name, (value, dictionary, priority) => {\n all.push({ value, dictionary, priority });\n return undefined;\n });\n\n return all;\n }\n\n public getString(name: SettingName, defaultValue: string): string;\n public getString(name: SettingName): string | undefined;\n public getString(name: SettingName, defaultValue?: string): string | undefined {\n const out = this.getSetting<string>(name);\n return typeof out === \"string\" ? out : defaultValue;\n }\n public getBoolean(name: SettingName, defaultValue: boolean): boolean;\n public getBoolean(name: SettingName): boolean | undefined;\n public getBoolean(name: SettingName, defaultValue?: boolean): boolean | undefined {\n const out = this.getSetting<boolean>(name);\n return typeof out === \"boolean\" ? out : defaultValue;\n }\n public getNumber(name: SettingName, defaultValue: number): number;\n public getNumber(name: SettingName): number | undefined;\n public getNumber(name: SettingName, defaultValue?: number): number | undefined {\n const out = this.getSetting<number>(name);\n return typeof out === \"number\" ? out : defaultValue;\n }\n public getObject<T extends object>(name: SettingName, defaultValue: T): T;\n public getObject<T extends object>(name: SettingName): T | undefined;\n public getObject<T extends object>(name: SettingName, defaultValue?: T): T | undefined {\n const out = this.getSetting<SettingObject>(name);\n return typeof out === \"object\" ? out as T : defaultValue;\n }\n public getArray<T extends SettingType>(name: SettingName, defaultValue: Array<T>): Array<T>;\n public getArray<T extends SettingType>(name: SettingName): Array<T> | undefined;\n public getArray<T extends SettingType>(name: SettingName, defaultValue?: Array<T>): Array<T> | undefined {\n const out = this.getSetting<Array<T>>(name);\n return Array.isArray(out) ? out : defaultValue;\n }\n}\n"]}
@@ -1,76 +1,76 @@
1
- /** @packageDocumentation
2
- * @module Workspace
3
- */
4
- import { BeEvent, JSONSchema, JSONSchemaTypeName } from "@itwin/core-bentley";
5
- import { LocalDirName, LocalFileName } from "@itwin/core-common";
6
- /**
7
- * The properties of a single Setting, used by the settings editor. This interface also includes the
8
- * default value if it is not specified in any Settings file.
9
- * This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.
10
- * @note the `type` member is marked optional in JSONSchema but is required for Settings.
11
- * @beta
12
- */
13
- export interface SettingSchema extends Readonly<JSONSchema> {
14
- readonly items?: SettingSchema;
15
- readonly type: JSONSchemaTypeName;
16
- readonly properties?: {
17
- [name: string]: SettingSchema;
18
- };
19
- /** whether the setting replaces lower priority entries with the same name or combines with them. */
20
- readonly cumulative?: true;
21
- }
22
- /**
23
- * The properties of a group of [[SettingSchema]]s for an application. Groups can be added and removed from [[SettingsSchemas]]
24
- * and are identified by their (required) `groupName` member
25
- * @beta
26
- */
27
- export interface SettingSchemaGroup {
28
- readonly groupName: string;
29
- readonly properties: {
30
- [name: string]: SettingSchema;
31
- };
32
- readonly order?: number;
33
- readonly title?: string;
34
- readonly description?: string;
35
- readonly extensionId?: string;
36
- }
37
- /**
38
- * The registry of available [[SettingSchemaGroup]]s.
39
- * The registry is used for editing Settings files and for finding default values for settings.
40
- * @beta
41
- */
42
- export declare class SettingsSchemas {
43
- private constructor();
44
- private static readonly _allGroups;
45
- /** a map of all registered [[SettingSchema]]s */
46
- static readonly allSchemas: Map<string, SettingSchema>;
47
- /** event that signals that the values in [[allSchemas]] have changed in some way. */
48
- static readonly onSchemaChanged: BeEvent<() => void>;
49
- /** Clear the contents of the registry and remove all event listeners.
50
- * @note This is really only necessary for tests of the Settings system.
51
- * @internal
52
- */
53
- static reset(): void;
54
- /** @internal */
55
- static validateArrayObject<T>(val: T, schemaName: string, msg: string): T;
56
- /**
57
- * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used
58
- * to identify the group. If a group with the same name is already registered, the old values are first removed and then the new group is added.
59
- */
60
- static addGroup(settingsGroup: SettingSchemaGroup | SettingSchemaGroup[]): void;
61
- /** Add a [[SettingSchemaGroup]] from stringified json5. */
62
- static addJson(settingSchema: string): void;
63
- /** Add a [[SettingSchemaGroup]] from a json5 file. */
64
- static addFile(fileName: LocalFileName): void;
65
- /** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
66
- static addDirectory(dirName: LocalDirName): void;
67
- /** Remove a previously added [[SettingSchemaGroup]] by groupName */
68
- static removeGroup(groupName: string): void;
69
- private static doAdd;
70
- private static doRemove;
71
- private static validateName;
72
- private static validateProperty;
73
- private static validateAndAdd;
74
- private static getDefaultValue;
75
- }
1
+ /** @packageDocumentation
2
+ * @module Workspace
3
+ */
4
+ import { BeEvent, JSONSchema, JSONSchemaTypeName } from "@itwin/core-bentley";
5
+ import { LocalDirName, LocalFileName } from "@itwin/core-common";
6
+ /**
7
+ * The properties of a single Setting, used by the settings editor. This interface also includes the
8
+ * default value if it is not specified in any Settings file.
9
+ * This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.
10
+ * @note the `type` member is marked optional in JSONSchema but is required for Settings.
11
+ * @beta
12
+ */
13
+ export interface SettingSchema extends Readonly<JSONSchema> {
14
+ readonly items?: SettingSchema;
15
+ readonly type: JSONSchemaTypeName;
16
+ readonly properties?: {
17
+ [name: string]: SettingSchema;
18
+ };
19
+ /** whether the setting replaces lower priority entries with the same name or combines with them. */
20
+ readonly cumulative?: true;
21
+ }
22
+ /**
23
+ * The properties of a group of [[SettingSchema]]s for an application. Groups can be added and removed from [[SettingsSchemas]]
24
+ * and are identified by their (required) `groupName` member
25
+ * @beta
26
+ */
27
+ export interface SettingSchemaGroup {
28
+ readonly groupName: string;
29
+ readonly properties: {
30
+ [name: string]: SettingSchema;
31
+ };
32
+ readonly order?: number;
33
+ readonly title?: string;
34
+ readonly description?: string;
35
+ readonly extensionId?: string;
36
+ }
37
+ /**
38
+ * The registry of available [[SettingSchemaGroup]]s.
39
+ * The registry is used for editing Settings files and for finding default values for settings.
40
+ * @beta
41
+ */
42
+ export declare class SettingsSchemas {
43
+ private constructor();
44
+ private static readonly _allGroups;
45
+ /** a map of all registered [[SettingSchema]]s */
46
+ static readonly allSchemas: Map<string, SettingSchema>;
47
+ /** event that signals that the values in [[allSchemas]] have changed in some way. */
48
+ static readonly onSchemaChanged: BeEvent<() => void>;
49
+ /** Clear the contents of the registry and remove all event listeners.
50
+ * @note This is really only necessary for tests of the Settings system.
51
+ * @internal
52
+ */
53
+ static reset(): void;
54
+ /** @internal */
55
+ static validateArrayObject<T>(val: T, schemaName: string, msg: string): T;
56
+ /**
57
+ * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used
58
+ * to identify the group. If a group with the same name is already registered, the old values are first removed and then the new group is added.
59
+ */
60
+ static addGroup(settingsGroup: SettingSchemaGroup | SettingSchemaGroup[]): void;
61
+ /** Add a [[SettingSchemaGroup]] from stringified json5. */
62
+ static addJson(settingSchema: string): void;
63
+ /** Add a [[SettingSchemaGroup]] from a json5 file. */
64
+ static addFile(fileName: LocalFileName): void;
65
+ /** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
66
+ static addDirectory(dirName: LocalDirName): void;
67
+ /** Remove a previously added [[SettingSchemaGroup]] by groupName */
68
+ static removeGroup(groupName: string): void;
69
+ private static doAdd;
70
+ private static doRemove;
71
+ private static validateName;
72
+ private static validateProperty;
73
+ private static validateAndAdd;
74
+ private static getDefaultValue;
75
+ }
76
76
  //# sourceMappingURL=SettingsSchemas.d.ts.map