@itwin/core-backend 3.4.0-dev.48 → 3.4.0-dev.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/lib/cjs/AliCloudStorageService.d.ts +23 -17
  2. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  3. package/lib/cjs/AliCloudStorageService.js +71 -68
  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 -82
  9. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  10. package/lib/cjs/BackendLoggerCategory.js +99 -90
  11. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  12. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  13. package/lib/cjs/BisCoreSchema.js +60 -60
  14. package/lib/cjs/BisCoreSchema.js.map +1 -1
  15. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  16. package/lib/cjs/BriefcaseManager.js +405 -405
  17. package/lib/cjs/BriefcaseManager.js.map +1 -1
  18. package/lib/cjs/Category.d.ts +153 -153
  19. package/lib/cjs/Category.js +243 -243
  20. package/lib/cjs/Category.js.map +1 -1
  21. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  22. package/lib/cjs/ChangeSummaryManager.js +445 -445
  23. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  24. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  25. package/lib/cjs/ChangedElementsDb.js +165 -165
  26. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  27. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  28. package/lib/cjs/ChangedElementsManager.js +88 -88
  29. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  30. package/lib/cjs/CheckpointManager.d.ts +120 -122
  31. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  32. package/lib/cjs/CheckpointManager.js +343 -354
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/ClassRegistry.d.ts +71 -71
  35. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  36. package/lib/cjs/ClassRegistry.js +215 -213
  37. package/lib/cjs/ClassRegistry.js.map +1 -1
  38. package/lib/cjs/CloudSqlite.d.ts +328 -328
  39. package/lib/cjs/CloudSqlite.js +135 -135
  40. package/lib/cjs/CloudSqlite.js.map +1 -1
  41. package/lib/cjs/CloudStorageBackend.d.ts +58 -46
  42. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  43. package/lib/cjs/CloudStorageBackend.js +173 -164
  44. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  45. package/lib/cjs/CodeService.d.ts +391 -391
  46. package/lib/cjs/CodeService.d.ts.map +1 -1
  47. package/lib/cjs/CodeService.js +63 -61
  48. package/lib/cjs/CodeService.js.map +1 -1
  49. package/lib/cjs/CodeSpecs.d.ts +50 -50
  50. package/lib/cjs/CodeSpecs.js +112 -112
  51. package/lib/cjs/CodeSpecs.js.map +1 -1
  52. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  53. package/lib/cjs/ConcurrentQuery.js +30 -30
  54. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  55. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  56. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  57. package/lib/cjs/CustomViewState3dCreator.js +113 -99
  58. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  59. package/lib/cjs/DevTools.d.ts +71 -71
  60. package/lib/cjs/DevTools.d.ts.map +1 -1
  61. package/lib/cjs/DevTools.js +154 -154
  62. package/lib/cjs/DevTools.js.map +1 -1
  63. package/lib/cjs/DisplayStyle.d.ts +106 -106
  64. package/lib/cjs/DisplayStyle.js +256 -256
  65. package/lib/cjs/DisplayStyle.js.map +1 -1
  66. package/lib/cjs/ECDb.d.ts +191 -191
  67. package/lib/cjs/ECDb.js +350 -350
  68. package/lib/cjs/ECDb.js.map +1 -1
  69. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  70. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  71. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  72. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  73. package/lib/cjs/ECSqlStatement.js +791 -791
  74. package/lib/cjs/ECSqlStatement.js.map +1 -1
  75. package/lib/cjs/Element.d.ts +1109 -1109
  76. package/lib/cjs/Element.d.ts.map +1 -1
  77. package/lib/cjs/Element.js +1420 -1421
  78. package/lib/cjs/Element.js.map +1 -1
  79. package/lib/cjs/ElementAspect.d.ts +156 -156
  80. package/lib/cjs/ElementAspect.js +178 -178
  81. package/lib/cjs/ElementAspect.js.map +1 -1
  82. package/lib/cjs/ElementGraphics.d.ts +9 -9
  83. package/lib/cjs/ElementGraphics.js +41 -41
  84. package/lib/cjs/ElementGraphics.js.map +1 -1
  85. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  86. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  87. package/lib/cjs/ElementTreeWalker.js +409 -409
  88. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  89. package/lib/cjs/Entity.d.ts +76 -76
  90. package/lib/cjs/Entity.js +82 -82
  91. package/lib/cjs/Entity.js.map +1 -1
  92. package/lib/cjs/ExportGraphics.d.ts +317 -317
  93. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  94. package/lib/cjs/ExportGraphics.js +208 -208
  95. package/lib/cjs/ExportGraphics.js.map +1 -1
  96. package/lib/cjs/ExternalSource.d.ts +94 -94
  97. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  98. package/lib/cjs/ExternalSource.js +125 -125
  99. package/lib/cjs/ExternalSource.js.map +1 -1
  100. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  101. package/lib/cjs/GeoCoordConfig.js +82 -82
  102. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  103. package/lib/cjs/GeometrySummary.d.ts +4 -4
  104. package/lib/cjs/GeometrySummary.js +380 -380
  105. package/lib/cjs/GeometrySummary.js.map +1 -1
  106. package/lib/cjs/HubMock.d.ts +93 -93
  107. package/lib/cjs/HubMock.js +190 -190
  108. package/lib/cjs/HubMock.js.map +1 -1
  109. package/lib/cjs/IModelCloneContext.d.ts +85 -85
  110. package/lib/cjs/IModelCloneContext.js +150 -150
  111. package/lib/cjs/IModelCloneContext.js.map +1 -1
  112. package/lib/cjs/IModelDb.d.ts +1164 -1164
  113. package/lib/cjs/IModelDb.d.ts.map +1 -1
  114. package/lib/cjs/IModelDb.js +2324 -2321
  115. package/lib/cjs/IModelDb.js.map +1 -1
  116. package/lib/cjs/IModelHost.d.ts +361 -347
  117. package/lib/cjs/IModelHost.d.ts.map +1 -1
  118. package/lib/cjs/IModelHost.js +491 -457
  119. package/lib/cjs/IModelHost.js.map +1 -1
  120. package/lib/cjs/IModelJsFs.d.ts +62 -62
  121. package/lib/cjs/IModelJsFs.js +140 -140
  122. package/lib/cjs/IModelJsFs.js.map +1 -1
  123. package/lib/cjs/IpcHost.d.ts +98 -98
  124. package/lib/cjs/IpcHost.js +234 -234
  125. package/lib/cjs/IpcHost.js.map +1 -1
  126. package/lib/cjs/LineStyle.d.ts +311 -311
  127. package/lib/cjs/LineStyle.js +295 -295
  128. package/lib/cjs/LineStyle.js.map +1 -1
  129. package/lib/cjs/LocalHub.d.ts +162 -162
  130. package/lib/cjs/LocalHub.js +587 -587
  131. package/lib/cjs/LocalHub.js.map +1 -1
  132. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  133. package/lib/cjs/LocalhostIpcHost.js +81 -81
  134. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  135. package/lib/cjs/Material.d.ts +103 -103
  136. package/lib/cjs/Material.js +147 -147
  137. package/lib/cjs/Material.js.map +1 -1
  138. package/lib/cjs/Model.d.ts +386 -386
  139. package/lib/cjs/Model.d.ts.map +1 -1
  140. package/lib/cjs/Model.js +471 -468
  141. package/lib/cjs/Model.js.map +1 -1
  142. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  143. package/lib/cjs/NativeAppStorage.js +202 -202
  144. package/lib/cjs/NativeAppStorage.js.map +1 -1
  145. package/lib/cjs/NativeHost.d.ts +52 -52
  146. package/lib/cjs/NativeHost.js +168 -168
  147. package/lib/cjs/NativeHost.js.map +1 -1
  148. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  149. package/lib/cjs/NavigationRelationship.js +225 -225
  150. package/lib/cjs/NavigationRelationship.js.map +1 -1
  151. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  152. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  153. package/lib/cjs/PromiseMemoizer.js +101 -95
  154. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  155. package/lib/cjs/PropertyStore.d.ts +132 -132
  156. package/lib/cjs/PropertyStore.js +11 -11
  157. package/lib/cjs/PropertyStore.js.map +1 -1
  158. package/lib/cjs/Relationship.d.ts +400 -400
  159. package/lib/cjs/Relationship.js +465 -465
  160. package/lib/cjs/Relationship.js.map +1 -1
  161. package/lib/cjs/RpcBackend.d.ts +28 -28
  162. package/lib/cjs/RpcBackend.js +126 -126
  163. package/lib/cjs/RpcBackend.js.map +1 -1
  164. package/lib/cjs/SQLiteDb.d.ts +219 -219
  165. package/lib/cjs/SQLiteDb.js +214 -214
  166. package/lib/cjs/SQLiteDb.js.map +1 -1
  167. package/lib/cjs/Schema.d.ts +55 -55
  168. package/lib/cjs/Schema.js +83 -83
  169. package/lib/cjs/Schema.js.map +1 -1
  170. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  171. package/lib/cjs/ServerBasedLocks.js +168 -168
  172. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  173. package/lib/cjs/SqliteStatement.d.ts +283 -283
  174. package/lib/cjs/SqliteStatement.js +448 -448
  175. package/lib/cjs/SqliteStatement.js.map +1 -1
  176. package/lib/cjs/Texture.d.ts +58 -58
  177. package/lib/cjs/Texture.js +82 -82
  178. package/lib/cjs/Texture.js.map +1 -1
  179. package/lib/cjs/TileStorage.d.ts +19 -0
  180. package/lib/cjs/TileStorage.d.ts.map +1 -0
  181. package/lib/cjs/TileStorage.js +91 -0
  182. package/lib/cjs/TileStorage.js.map +1 -0
  183. package/lib/cjs/TxnManager.d.ts +202 -202
  184. package/lib/cjs/TxnManager.d.ts.map +1 -1
  185. package/lib/cjs/TxnManager.js +356 -353
  186. package/lib/cjs/TxnManager.js.map +1 -1
  187. package/lib/cjs/ViewDefinition.d.ts +435 -435
  188. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  189. package/lib/cjs/ViewDefinition.js +635 -629
  190. package/lib/cjs/ViewDefinition.js.map +1 -1
  191. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  192. package/lib/cjs/ViewStateHydrator.js +103 -103
  193. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  194. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  195. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  196. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  197. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  198. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  199. package/lib/cjs/core-backend.d.ts +182 -178
  200. package/lib/cjs/core-backend.d.ts.map +1 -1
  201. package/lib/cjs/core-backend.js +202 -198
  202. package/lib/cjs/core-backend.js.map +1 -1
  203. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  204. package/lib/cjs/domains/FunctionalElements.js +145 -145
  205. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  206. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  207. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  208. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  209. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  210. package/lib/cjs/domains/GenericElements.js +263 -263
  211. package/lib/cjs/domains/GenericElements.js.map +1 -1
  212. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  213. package/lib/cjs/domains/GenericSchema.js +28 -28
  214. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  215. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  216. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  217. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  218. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  219. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  220. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  221. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -20
  222. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  223. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -195
  224. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  225. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  226. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  227. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -165
  228. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  229. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  230. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  231. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  233. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  234. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  235. package/lib/cjs/workspace/Settings.d.ts +186 -186
  236. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  237. package/lib/cjs/workspace/Settings.js +155 -152
  238. package/lib/cjs/workspace/Settings.js.map +1 -1
  239. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  240. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  241. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  242. package/lib/cjs/workspace/Workspace.d.ts +405 -405
  243. package/lib/cjs/workspace/Workspace.js +539 -539
  244. package/lib/cjs/workspace/Workspace.js.map +1 -1
  245. package/package.json +17 -13
@@ -1,192 +1,192 @@
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.SettingsSchemas = 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
- * The registry of available [[SettingSchemaGroup]]s.
18
- * The registry is used for editing Settings files and for finding default values for settings.
19
- * @beta
20
- */
21
- class SettingsSchemas {
22
- constructor() { } // singleton
23
- /** Clear the contents of the registry and remove all event listeners.
24
- * @note This is really only necessary for tests of the Settings system.
25
- * @internal
26
- */
27
- static reset() {
28
- this._allGroups.clear();
29
- this.allSchemas.clear();
30
- this.onSchemaChanged.clear();
31
- }
32
- /** @internal */
33
- static validateArrayObject(val, schemaName, msg) {
34
- const schema = this.allSchemas.get(schemaName);
35
- const items = schema === null || schema === void 0 ? void 0 : schema.items;
36
- if (undefined === items)
37
- return val;
38
- const required = items.required;
39
- const properties = items.properties;
40
- if (undefined === required || undefined === properties)
41
- return val;
42
- for (const entry of required) {
43
- const entryType = properties[entry].type;
44
- const value = val[entry];
45
- if (entryType === "array" && Array.isArray(value))
46
- continue;
47
- if (typeof value !== entryType)
48
- throw new Error(`invalid "${schemaName}" setting entry for "${msg}": ${entry} is ${value}`);
49
- }
50
- return val;
51
- }
52
- /**
53
- * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used
54
- * 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.
55
- */
56
- static addGroup(settingsGroup) {
57
- if (!Array.isArray(settingsGroup))
58
- settingsGroup = [settingsGroup];
59
- this.doAdd(settingsGroup);
60
- this.onSchemaChanged.raiseEvent();
61
- }
62
- /** Add a [[SettingSchemaGroup]] from stringified json5. */
63
- static addJson(settingSchema) {
64
- this.addGroup((0, json5_1.parse)(settingSchema));
65
- }
66
- /** Add a [[SettingSchemaGroup]] from a json5 file. */
67
- static addFile(fileName) {
68
- try {
69
- this.addJson(fs.readFileSync(fileName, "utf-8"));
70
- }
71
- catch (e) {
72
- throw new Error(`parsing SettingSchema file "${fileName}": ${e.message}"`);
73
- }
74
- }
75
- /** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
76
- static addDirectory(dirName) {
77
- for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
78
- const ext = (0, path_1.extname)(fileName);
79
- if (ext === ".json5" || ext === ".json")
80
- this.addFile((0, path_1.join)(dirName, fileName));
81
- }
82
- }
83
- /** Remove a previously added [[SettingSchemaGroup]] by groupName */
84
- static removeGroup(groupName) {
85
- this.doRemove(groupName);
86
- this.onSchemaChanged.raiseEvent();
87
- }
88
- static doAdd(settingsGroup) {
89
- settingsGroup.forEach((group) => {
90
- if (undefined === group.groupName)
91
- throw new Error(`settings group has no "groupName" member`);
92
- this.doRemove(group.groupName);
93
- this.validateAndAdd(group);
94
- this._allGroups.set(group.groupName, group);
95
- });
96
- }
97
- static doRemove(groupName) {
98
- const group = this._allGroups.get(groupName);
99
- if (undefined !== (group === null || group === void 0 ? void 0 : group.properties)) {
100
- for (const key of Object.keys(group.properties))
101
- this.allSchemas.delete(key);
102
- }
103
- this._allGroups.delete(groupName);
104
- }
105
- static validateName(name) {
106
- if (!name.trim())
107
- throw new Error(`empty property name`);
108
- if (this.allSchemas.has(name))
109
- throw new Error(`property "${name}" is already defined`);
110
- }
111
- static validateProperty(name, property) {
112
- if (!property)
113
- throw new Error(`missing required property ${name}`);
114
- if (!property.type)
115
- throw new Error(`property ${name} has no type`);
116
- switch (property.type) {
117
- case "boolean":
118
- case "integer":
119
- case "null":
120
- case "number":
121
- case "string":
122
- return;
123
- case "object":
124
- const required = property.required;
125
- const props = property.properties;
126
- if (required && props) {
127
- for (const entry of required)
128
- this.validateProperty(entry, props[entry]);
129
- }
130
- if (props) {
131
- for (const key of Object.keys(props))
132
- try {
133
- this.validateProperty(key, props[key]);
134
- }
135
- catch (e) {
136
- throw new Error(`property ${key} of ${name}: ${e.message}`);
137
- }
138
- }
139
- return;
140
- case "array":
141
- if (typeof property.items !== "object")
142
- throw new Error(`array property ${name} has no items member`);
143
- try {
144
- this.validateProperty("items", property.items);
145
- }
146
- catch (e) {
147
- throw new Error(`array property ${name}: ${e.message}`);
148
- }
149
- return;
150
- default:
151
- throw new Error(`property ${name} has illegal type "${property.type}"`);
152
- }
153
- }
154
- static validateAndAdd(group) {
155
- var _a;
156
- const properties = group.properties;
157
- if (undefined === properties)
158
- throw new Error(`group ${group.groupName} has no properties`);
159
- for (const key of Object.keys(properties)) {
160
- this.validateName(key);
161
- this.validateProperty(key, properties[key]);
162
- const property = properties[key];
163
- property.default = (_a = property.default) !== null && _a !== void 0 ? _a : this.getDefaultValue(property.type);
164
- this.allSchemas.set(key, property);
165
- }
166
- }
167
- static getDefaultValue(type) {
168
- type = Array.isArray(type) ? type[0] : type;
169
- switch (type) {
170
- case "boolean":
171
- return false;
172
- case "integer":
173
- case "number":
174
- return 0;
175
- case "string":
176
- return "";
177
- case "array":
178
- return [];
179
- case "object":
180
- return {};
181
- default:
182
- return undefined;
183
- }
184
- }
185
- }
186
- exports.SettingsSchemas = SettingsSchemas;
187
- SettingsSchemas._allGroups = new Map();
188
- /** a map of all registered [[SettingSchema]]s */
189
- SettingsSchemas.allSchemas = new Map();
190
- /** event that signals that the values in [[allSchemas]] have changed in some way. */
191
- SettingsSchemas.onSchemaChanged = new core_bentley_1.BeEvent();
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.SettingsSchemas = 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
+ * The registry of available [[SettingSchemaGroup]]s.
18
+ * The registry is used for editing Settings files and for finding default values for settings.
19
+ * @beta
20
+ */
21
+ class SettingsSchemas {
22
+ constructor() { } // singleton
23
+ /** Clear the contents of the registry and remove all event listeners.
24
+ * @note This is really only necessary for tests of the Settings system.
25
+ * @internal
26
+ */
27
+ static reset() {
28
+ this._allGroups.clear();
29
+ this.allSchemas.clear();
30
+ this.onSchemaChanged.clear();
31
+ }
32
+ /** @internal */
33
+ static validateArrayObject(val, schemaName, msg) {
34
+ const schema = this.allSchemas.get(schemaName);
35
+ const items = schema === null || schema === void 0 ? void 0 : schema.items;
36
+ if (undefined === items)
37
+ return val;
38
+ const required = items.required;
39
+ const properties = items.properties;
40
+ if (undefined === required || undefined === properties)
41
+ return val;
42
+ for (const entry of required) {
43
+ const entryType = properties[entry].type;
44
+ const value = val[entry];
45
+ if (entryType === "array" && Array.isArray(value))
46
+ continue;
47
+ if (typeof value !== entryType)
48
+ throw new Error(`invalid "${schemaName}" setting entry for "${msg}": ${entry} is ${value}`);
49
+ }
50
+ return val;
51
+ }
52
+ /**
53
+ * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used
54
+ * 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.
55
+ */
56
+ static addGroup(settingsGroup) {
57
+ if (!Array.isArray(settingsGroup))
58
+ settingsGroup = [settingsGroup];
59
+ this.doAdd(settingsGroup);
60
+ this.onSchemaChanged.raiseEvent();
61
+ }
62
+ /** Add a [[SettingSchemaGroup]] from stringified json5. */
63
+ static addJson(settingSchema) {
64
+ this.addGroup((0, json5_1.parse)(settingSchema));
65
+ }
66
+ /** Add a [[SettingSchemaGroup]] from a json5 file. */
67
+ static addFile(fileName) {
68
+ try {
69
+ this.addJson(fs.readFileSync(fileName, "utf-8"));
70
+ }
71
+ catch (e) {
72
+ throw new Error(`parsing SettingSchema file "${fileName}": ${e.message}"`);
73
+ }
74
+ }
75
+ /** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
76
+ static addDirectory(dirName) {
77
+ for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
78
+ const ext = (0, path_1.extname)(fileName);
79
+ if (ext === ".json5" || ext === ".json")
80
+ this.addFile((0, path_1.join)(dirName, fileName));
81
+ }
82
+ }
83
+ /** Remove a previously added [[SettingSchemaGroup]] by groupName */
84
+ static removeGroup(groupName) {
85
+ this.doRemove(groupName);
86
+ this.onSchemaChanged.raiseEvent();
87
+ }
88
+ static doAdd(settingsGroup) {
89
+ settingsGroup.forEach((group) => {
90
+ if (undefined === group.groupName)
91
+ throw new Error(`settings group has no "groupName" member`);
92
+ this.doRemove(group.groupName);
93
+ this.validateAndAdd(group);
94
+ this._allGroups.set(group.groupName, group);
95
+ });
96
+ }
97
+ static doRemove(groupName) {
98
+ const group = this._allGroups.get(groupName);
99
+ if (undefined !== (group === null || group === void 0 ? void 0 : group.properties)) {
100
+ for (const key of Object.keys(group.properties))
101
+ this.allSchemas.delete(key);
102
+ }
103
+ this._allGroups.delete(groupName);
104
+ }
105
+ static validateName(name) {
106
+ if (!name.trim())
107
+ throw new Error(`empty property name`);
108
+ if (this.allSchemas.has(name))
109
+ throw new Error(`property "${name}" is already defined`);
110
+ }
111
+ static validateProperty(name, property) {
112
+ if (!property)
113
+ throw new Error(`missing required property ${name}`);
114
+ if (!property.type)
115
+ throw new Error(`property ${name} has no type`);
116
+ switch (property.type) {
117
+ case "boolean":
118
+ case "integer":
119
+ case "null":
120
+ case "number":
121
+ case "string":
122
+ return;
123
+ case "object":
124
+ const required = property.required;
125
+ const props = property.properties;
126
+ if (required && props) {
127
+ for (const entry of required)
128
+ this.validateProperty(entry, props[entry]);
129
+ }
130
+ if (props) {
131
+ for (const key of Object.keys(props))
132
+ try {
133
+ this.validateProperty(key, props[key]);
134
+ }
135
+ catch (e) {
136
+ throw new Error(`property ${key} of ${name}: ${e.message}`);
137
+ }
138
+ }
139
+ return;
140
+ case "array":
141
+ if (typeof property.items !== "object")
142
+ throw new Error(`array property ${name} has no items member`);
143
+ try {
144
+ this.validateProperty("items", property.items);
145
+ }
146
+ catch (e) {
147
+ throw new Error(`array property ${name}: ${e.message}`);
148
+ }
149
+ return;
150
+ default:
151
+ throw new Error(`property ${name} has illegal type "${property.type}"`);
152
+ }
153
+ }
154
+ static validateAndAdd(group) {
155
+ var _a;
156
+ const properties = group.properties;
157
+ if (undefined === properties)
158
+ throw new Error(`group ${group.groupName} has no properties`);
159
+ for (const key of Object.keys(properties)) {
160
+ this.validateName(key);
161
+ this.validateProperty(key, properties[key]);
162
+ const property = properties[key];
163
+ property.default = (_a = property.default) !== null && _a !== void 0 ? _a : this.getDefaultValue(property.type);
164
+ this.allSchemas.set(key, property);
165
+ }
166
+ }
167
+ static getDefaultValue(type) {
168
+ type = Array.isArray(type) ? type[0] : type;
169
+ switch (type) {
170
+ case "boolean":
171
+ return false;
172
+ case "integer":
173
+ case "number":
174
+ return 0;
175
+ case "string":
176
+ return "";
177
+ case "array":
178
+ return [];
179
+ case "object":
180
+ return {};
181
+ default:
182
+ return undefined;
183
+ }
184
+ }
185
+ }
186
+ exports.SettingsSchemas = SettingsSchemas;
187
+ SettingsSchemas._allGroups = new Map();
188
+ /** a map of all registered [[SettingSchema]]s */
189
+ SettingsSchemas.allSchemas = new Map();
190
+ /** event that signals that the values in [[allSchemas]] have changed in some way. */
191
+ SettingsSchemas.onSchemaChanged = new core_bentley_1.BeEvent();
192
192
  //# sourceMappingURL=SettingsSchemas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SettingsSchemas.js","sourceRoot":"","sources":["../../../src/workspace/SettingsSchemas.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAAuG;AAEvG,8CAA2C;AAgC3C;;;;GAIG;AACH,MAAa,eAAe;IAC1B,gBAAwB,CAAC,CAAC,YAAY;IAOtC;;;OAGG;IACI,MAAM,CAAC,KAAK;QACjB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,mBAAmB,CAAI,GAAM,EAAE,UAAkB,EAAE,GAAW;QAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC;QAC5B,IAAI,SAAS,KAAK,KAAK;YACrB,OAAO,GAAG,CAAC;QACb,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACpC,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,UAAU;YACpD,OAAO,GAAG,CAAC;QAEb,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;YAC5B,M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C,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,QAAQ,IAAI,EAAE;YACZ,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACX,OAAO,CAAC,CAAC;YACX,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;YACZ,KAAK,OAAO;gBACV,OAAO,EAAE,CAAC;YACZ,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;YACZ;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC;;AA1LH,0CA2LC;AAzLyB,0BAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC3E,iDAAiD;AAC1B,0BAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;AACrE,qFAAqF;AAC9D,+BAAe,GAAG,IAAI,sBAAO,EAAc,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Workspace\n */\n\nimport * as fs from \"fs-extra\";\nimport { parse } from \"json5\";\nimport { extname, join } from \"path\";\nimport { BeEvent, JSONSchema, JSONSchemaType, JSONSchemaTypeName, Mutable } from \"@itwin/core-bentley\";\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\nimport { IModelJsFs } from \"../IModelJsFs\";\n\n/**\n * The properties of a single Setting, used by the settings editor. This interface also includes the\n * default value if it is not specified in any Settings file.\n * This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.\n * @note the `type` member is marked optional in JSONSchema but is required for Settings.\n * @beta\n */\nexport interface SettingSchema extends Readonly<JSONSchema> {\n readonly items?: SettingSchema; // must be single object, not array\n readonly type: JSONSchemaTypeName; // type is required for settings\n readonly properties?: { [name: string]: SettingSchema };\n\n /** whether the setting replaces lower priority entries with the same name or combines with them. */\n readonly cumulative?: true;\n}\n\n/**\n * The properties of a group of [[SettingSchema]]s for an application. Groups can be added and removed from [[SettingsSchemas]]\n * and are identified by their (required) `groupName` member\n * @beta\n */\nexport interface SettingSchemaGroup {\n readonly groupName: string;\n readonly properties: { [name: string]: SettingSchema };\n readonly order?: number;\n readonly title?: string;\n readonly description?: string;\n readonly extensionId?: string;\n}\n\n/**\n * The registry of available [[SettingSchemaGroup]]s.\n * The registry is used for editing Settings files and for finding default values for settings.\n * @beta\n */\nexport class SettingsSchemas {\n private constructor() { } // singleton\n private static readonly _allGroups = new Map<string, SettingSchemaGroup>();\n /** a map of all registered [[SettingSchema]]s */\n public static readonly allSchemas = new Map<string, SettingSchema>();\n /** event that signals that the values in [[allSchemas]] have changed in some way. */\n public static readonly onSchemaChanged = new BeEvent<() => void>();\n\n /** Clear the contents of the registry and remove all event listeners.\n * @note This is really only necessary for tests of the Settings system.\n * @internal\n */\n public static reset() {\n this._allGroups.clear();\n this.allSchemas.clear();\n this.onSchemaChanged.clear();\n }\n\n /** @internal */\n public static validateArrayObject<T>(val: T, schemaName: string, msg: string): T {\n const schema = this.allSchemas.get(schemaName);\n const items = schema?.items;\n if (undefined === items)\n return val;\n const required = items.required;\n const properties = items.properties;\n if (undefined === required || undefined === properties)\n return val;\n\n for (const entry of required) {\n const entryType = properties[entry].type;\n const value = (val as any)[entry];\n if (entryType === \"array\" && Array.isArray(value))\n continue;\n if (typeof value !== entryType)\n throw new Error(`invalid \"${schemaName}\" setting entry for \"${msg}\": ${entry} is ${value}`);\n }\n return val;\n }\n\n /**\n * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used\n * 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.\n */\n public static addGroup(settingsGroup: SettingSchemaGroup | SettingSchemaGroup[]): void {\n if (!Array.isArray(settingsGroup))\n settingsGroup = [settingsGroup];\n\n this.doAdd(settingsGroup);\n this.onSchemaChanged.raiseEvent();\n }\n\n /** Add a [[SettingSchemaGroup]] from stringified json5. */\n public static addJson(settingSchema: string): void {\n this.addGroup(parse(settingSchema));\n }\n\n /** Add a [[SettingSchemaGroup]] from a json5 file. */\n public static addFile(fileName: LocalFileName): void {\n try {\n this.addJson(fs.readFileSync(fileName, \"utf-8\"));\n } catch (e: any) {\n throw new Error(`parsing SettingSchema file \"${fileName}\": ${e.message}\"`);\n }\n }\n\n /** Add all files with a either \".json\" or \".json5\" extension from a supplied directory. */\n public static addDirectory(dirName: LocalDirName) {\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));\n }\n }\n\n /** Remove a previously added [[SettingSchemaGroup]] by groupName */\n public static removeGroup(groupName: string): void {\n this.doRemove(groupName);\n this.onSchemaChanged.raiseEvent();\n }\n\n private static doAdd(settingsGroup: SettingSchemaGroup[]) {\n settingsGroup.forEach((group) => {\n if (undefined === group.groupName)\n throw new Error(`settings group has no \"groupName\" member`);\n\n this.doRemove(group.groupName);\n this.validateAndAdd(group);\n this._allGroups.set(group.groupName, group);\n });\n }\n\n private static doRemove(groupName: string) {\n const group = this._allGroups.get(groupName);\n if (undefined !== group?.properties) {\n for (const key of Object.keys(group.properties))\n this.allSchemas.delete(key);\n }\n this._allGroups.delete(groupName);\n }\n\n private static validateName(name: string) {\n if (!name.trim())\n throw new Error(`empty property name`);\n if (this.allSchemas.has(name))\n throw new Error(`property \"${name}\" is already defined`);\n }\n\n private static validateProperty(name: string, property: SettingSchema | undefined) {\n if (!property)\n throw new Error(`missing required property ${name}`);\n\n if (!property.type)\n throw new Error(`property ${name} has no type`);\n\n switch (property.type) {\n case \"boolean\":\n case \"integer\":\n case \"null\":\n case \"number\":\n case \"string\":\n return;\n\n case \"object\":\n const required = property.required;\n const props = property.properties;\n if (required && props) {\n for (const entry of required)\n this.validateProperty(entry, props[entry]);\n }\n if (props) {\n for (const key of Object.keys(props))\n try {\n this.validateProperty(key, props[key]);\n } catch (e: any) {\n throw new Error(`property ${key} of ${name}: ${e.message}`);\n }\n }\n return;\n\n case \"array\":\n if (typeof property.items !== \"object\")\n throw new Error(`array property ${name} has no items member`);\n try {\n this.validateProperty(\"items\", property.items);\n } catch (e: any) {\n throw new Error(`array property ${name}: ${e.message}`);\n }\n return;\n\n default:\n throw new Error(`property ${name} has illegal type \"${property.type}\"`);\n }\n }\n\n private static validateAndAdd(group: SettingSchemaGroup) {\n const properties = group.properties;\n if (undefined === properties)\n throw new Error(`group ${group.groupName} has no properties`);\n\n for (const key of Object.keys(properties)) {\n this.validateName(key);\n this.validateProperty(key, properties[key]);\n const property: Mutable<SettingSchema> = properties[key];\n property.default = property.default ?? this.getDefaultValue(property.type);\n this.allSchemas.set(key, property);\n }\n }\n\n private static getDefaultValue(type: JSONSchemaTypeName | JSONSchemaTypeName[]): JSONSchemaType | undefined {\n type = Array.isArray(type) ? type[0] : type;\n switch (type) {\n case \"boolean\":\n return false;\n case \"integer\":\n case \"number\":\n return 0;\n case \"string\":\n return \"\";\n case \"array\":\n return [];\n case \"object\":\n return {};\n default:\n return undefined;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"SettingsSchemas.js","sourceRoot":"","sources":["../../../src/workspace/SettingsSchemas.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAAuG;AAEvG,8CAA2C;AAgC3C;;;;GAIG;AACH,MAAa,eAAe;IAC1B,gBAAwB,CAAC,CAAC,YAAY;IAOtC;;;OAGG;IACI,MAAM,CAAC,KAAK;QACjB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,mBAAmB,CAAI,GAAM,EAAE,UAAkB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CAAC,CAAC;YACvB,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5C,MAAM,QAAQ,GAA2B,UAAU,CAAC,GAAG,CAAC,CAAC;YACzD,QAAQ,CAAC,OAAO,GAAG,MAAA,QAAQ,CAAC,OAAO,mCAAI,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC3E,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SACpC;IACH,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,IAA+C;QAC5E,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,QAAQ,IAAI,EAAE;YACZ,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACX,OAAO,CAAC,CAAC;YACX,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;YACZ,KAAK,OAAO;gBACV,OAAO,EAAE,CAAC;YACZ,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;YACZ;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC;;AA1LH,0CA2LC;AAzLyB,0BAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC3E,iDAAiD;AAC1B,0BAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;AACrE,qFAAqF;AAC9D,+BAAe,GAAG,IAAI,sBAAO,EAAc,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @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, JSONSchema, JSONSchemaType, JSONSchemaTypeName, Mutable } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\n/**\r\n * The properties of a single Setting, used by the settings editor. This interface also includes the\r\n * default value if it is not specified in any Settings file.\r\n * This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.\r\n * @note the `type` member is marked optional in JSONSchema but is required for Settings.\r\n * @beta\r\n */\r\nexport interface SettingSchema extends Readonly<JSONSchema> {\r\n readonly items?: SettingSchema; // must be single object, not array\r\n readonly type: JSONSchemaTypeName; // type is required for settings\r\n readonly properties?: { [name: string]: SettingSchema };\r\n\r\n /** whether the setting replaces lower priority entries with the same name or combines with them. */\r\n readonly cumulative?: true;\r\n}\r\n\r\n/**\r\n * The properties of a group of [[SettingSchema]]s for an application. Groups can be added and removed from [[SettingsSchemas]]\r\n * and are identified by their (required) `groupName` member\r\n * @beta\r\n */\r\nexport interface SettingSchemaGroup {\r\n readonly groupName: string;\r\n readonly properties: { [name: string]: SettingSchema };\r\n readonly order?: number;\r\n readonly title?: string;\r\n readonly description?: string;\r\n readonly extensionId?: string;\r\n}\r\n\r\n/**\r\n * The registry of available [[SettingSchemaGroup]]s.\r\n * The registry is used for editing Settings files and for finding default values for settings.\r\n * @beta\r\n */\r\nexport class SettingsSchemas {\r\n private constructor() { } // singleton\r\n private static readonly _allGroups = new Map<string, SettingSchemaGroup>();\r\n /** a map of all registered [[SettingSchema]]s */\r\n public static readonly allSchemas = new Map<string, SettingSchema>();\r\n /** event that signals that the values in [[allSchemas]] have changed in some way. */\r\n public static readonly onSchemaChanged = new BeEvent<() => void>();\r\n\r\n /** Clear the contents of the registry and remove all event listeners.\r\n * @note This is really only necessary for tests of the Settings system.\r\n * @internal\r\n */\r\n public static reset() {\r\n this._allGroups.clear();\r\n this.allSchemas.clear();\r\n this.onSchemaChanged.clear();\r\n }\r\n\r\n /** @internal */\r\n public static validateArrayObject<T>(val: T, schemaName: string, msg: string): T {\r\n const schema = this.allSchemas.get(schemaName);\r\n const items = schema?.items;\r\n if (undefined === items)\r\n return val;\r\n const required = items.required;\r\n const properties = items.properties;\r\n if (undefined === required || undefined === properties)\r\n return val;\r\n\r\n for (const entry of required) {\r\n const entryType = properties[entry].type;\r\n const value = (val as any)[entry];\r\n if (entryType === \"array\" && Array.isArray(value))\r\n continue;\r\n if (typeof value !== entryType)\r\n throw new Error(`invalid \"${schemaName}\" setting entry for \"${msg}\": ${entry} is ${value}`);\r\n }\r\n return val;\r\n }\r\n\r\n /**\r\n * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used\r\n * 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.\r\n */\r\n public static addGroup(settingsGroup: SettingSchemaGroup | SettingSchemaGroup[]): void {\r\n if (!Array.isArray(settingsGroup))\r\n settingsGroup = [settingsGroup];\r\n\r\n this.doAdd(settingsGroup);\r\n this.onSchemaChanged.raiseEvent();\r\n }\r\n\r\n /** Add a [[SettingSchemaGroup]] from stringified json5. */\r\n public static addJson(settingSchema: string): void {\r\n this.addGroup(parse(settingSchema));\r\n }\r\n\r\n /** Add a [[SettingSchemaGroup]] from a json5 file. */\r\n public static addFile(fileName: LocalFileName): void {\r\n try {\r\n this.addJson(fs.readFileSync(fileName, \"utf-8\"));\r\n } catch (e: any) {\r\n throw new Error(`parsing SettingSchema file \"${fileName}\": ${e.message}\"`);\r\n }\r\n }\r\n\r\n /** Add all files with a either \".json\" or \".json5\" extension from a supplied directory. */\r\n public static addDirectory(dirName: LocalDirName) {\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));\r\n }\r\n }\r\n\r\n /** Remove a previously added [[SettingSchemaGroup]] by groupName */\r\n public static removeGroup(groupName: string): void {\r\n this.doRemove(groupName);\r\n this.onSchemaChanged.raiseEvent();\r\n }\r\n\r\n private static doAdd(settingsGroup: SettingSchemaGroup[]) {\r\n settingsGroup.forEach((group) => {\r\n if (undefined === group.groupName)\r\n throw new Error(`settings group has no \"groupName\" member`);\r\n\r\n this.doRemove(group.groupName);\r\n this.validateAndAdd(group);\r\n this._allGroups.set(group.groupName, group);\r\n });\r\n }\r\n\r\n private static doRemove(groupName: string) {\r\n const group = this._allGroups.get(groupName);\r\n if (undefined !== group?.properties) {\r\n for (const key of Object.keys(group.properties))\r\n this.allSchemas.delete(key);\r\n }\r\n this._allGroups.delete(groupName);\r\n }\r\n\r\n private static validateName(name: string) {\r\n if (!name.trim())\r\n throw new Error(`empty property name`);\r\n if (this.allSchemas.has(name))\r\n throw new Error(`property \"${name}\" is already defined`);\r\n }\r\n\r\n private static validateProperty(name: string, property: SettingSchema | undefined) {\r\n if (!property)\r\n throw new Error(`missing required property ${name}`);\r\n\r\n if (!property.type)\r\n throw new Error(`property ${name} has no type`);\r\n\r\n switch (property.type) {\r\n case \"boolean\":\r\n case \"integer\":\r\n case \"null\":\r\n case \"number\":\r\n case \"string\":\r\n return;\r\n\r\n case \"object\":\r\n const required = property.required;\r\n const props = property.properties;\r\n if (required && props) {\r\n for (const entry of required)\r\n this.validateProperty(entry, props[entry]);\r\n }\r\n if (props) {\r\n for (const key of Object.keys(props))\r\n try {\r\n this.validateProperty(key, props[key]);\r\n } catch (e: any) {\r\n throw new Error(`property ${key} of ${name}: ${e.message}`);\r\n }\r\n }\r\n return;\r\n\r\n case \"array\":\r\n if (typeof property.items !== \"object\")\r\n throw new Error(`array property ${name} has no items member`);\r\n try {\r\n this.validateProperty(\"items\", property.items);\r\n } catch (e: any) {\r\n throw new Error(`array property ${name}: ${e.message}`);\r\n }\r\n return;\r\n\r\n default:\r\n throw new Error(`property ${name} has illegal type \"${property.type}\"`);\r\n }\r\n }\r\n\r\n private static validateAndAdd(group: SettingSchemaGroup) {\r\n const properties = group.properties;\r\n if (undefined === properties)\r\n throw new Error(`group ${group.groupName} has no properties`);\r\n\r\n for (const key of Object.keys(properties)) {\r\n this.validateName(key);\r\n this.validateProperty(key, properties[key]);\r\n const property: Mutable<SettingSchema> = properties[key];\r\n property.default = property.default ?? this.getDefaultValue(property.type);\r\n this.allSchemas.set(key, property);\r\n }\r\n }\r\n\r\n private static getDefaultValue(type: JSONSchemaTypeName | JSONSchemaTypeName[]): JSONSchemaType | undefined {\r\n type = Array.isArray(type) ? type[0] : type;\r\n switch (type) {\r\n case \"boolean\":\r\n return false;\r\n case \"integer\":\r\n case \"number\":\r\n return 0;\r\n case \"string\":\r\n return \"\";\r\n case \"array\":\r\n return [];\r\n case \"object\":\r\n return {};\r\n default:\r\n return undefined;\r\n }\r\n }\r\n}\r\n"]}