@itwin/core-backend 4.0.0-dev.10 → 4.0.0-dev.100

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 (270) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +226 -224
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +41 -41
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
  7. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.js +98 -99
  9. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  11. package/lib/cjs/BisCoreSchema.js +60 -60
  12. package/lib/cjs/BlobContainerService.d.ts +120 -0
  13. package/lib/cjs/BlobContainerService.d.ts.map +1 -0
  14. package/lib/cjs/BlobContainerService.js +18 -0
  15. package/lib/cjs/BlobContainerService.js.map +1 -0
  16. package/lib/cjs/BriefcaseManager.d.ts +184 -170
  17. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  18. package/lib/cjs/BriefcaseManager.js +421 -414
  19. package/lib/cjs/BriefcaseManager.js.map +1 -1
  20. package/lib/cjs/Category.d.ts +153 -153
  21. package/lib/cjs/Category.js +243 -243
  22. package/lib/cjs/Category.js.map +1 -1
  23. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  24. package/lib/cjs/ChangeSummaryManager.js +444 -445
  25. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  26. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  27. package/lib/cjs/ChangedElementsDb.js +165 -165
  28. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  29. package/lib/cjs/ChangedElementsManager.js +88 -88
  30. package/lib/cjs/ChannelControl.d.ts +70 -0
  31. package/lib/cjs/ChannelControl.d.ts.map +1 -0
  32. package/lib/cjs/ChannelControl.js +89 -0
  33. package/lib/cjs/ChannelControl.js.map +1 -0
  34. package/lib/cjs/CheckpointManager.d.ts +121 -121
  35. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  36. package/lib/cjs/CheckpointManager.js +351 -349
  37. package/lib/cjs/CheckpointManager.js.map +1 -1
  38. package/lib/cjs/ClassRegistry.d.ts +79 -79
  39. package/lib/cjs/ClassRegistry.js +249 -245
  40. package/lib/cjs/ClassRegistry.js.map +1 -1
  41. package/lib/cjs/CloudSqlite.d.ts +572 -350
  42. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  43. package/lib/cjs/CloudSqlite.js +374 -153
  44. package/lib/cjs/CloudSqlite.js.map +1 -1
  45. package/lib/cjs/CodeService.d.ts +399 -396
  46. package/lib/cjs/CodeService.d.ts.map +1 -1
  47. package/lib/cjs/CodeService.js +63 -63
  48. package/lib/cjs/CodeService.js.map +1 -1
  49. package/lib/cjs/CodeSpecs.d.ts +58 -55
  50. package/lib/cjs/CodeSpecs.d.ts.map +1 -1
  51. package/lib/cjs/CodeSpecs.js +154 -124
  52. package/lib/cjs/CodeSpecs.js.map +1 -1
  53. package/lib/cjs/ConcurrentQuery.d.ts +13 -13
  54. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  55. package/lib/cjs/ConcurrentQuery.js +36 -36
  56. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  57. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  58. package/lib/cjs/CustomViewState3dCreator.js +80 -81
  59. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  60. package/lib/cjs/DevTools.d.ts +74 -71
  61. package/lib/cjs/DevTools.d.ts.map +1 -1
  62. package/lib/cjs/DevTools.js +156 -154
  63. package/lib/cjs/DevTools.js.map +1 -1
  64. package/lib/cjs/DisplayStyle.d.ts +104 -106
  65. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  66. package/lib/cjs/DisplayStyle.js +251 -256
  67. package/lib/cjs/DisplayStyle.js.map +1 -1
  68. package/lib/cjs/ECDb.d.ts +194 -191
  69. package/lib/cjs/ECDb.d.ts.map +1 -1
  70. package/lib/cjs/ECDb.js +351 -350
  71. package/lib/cjs/ECDb.js.map +1 -1
  72. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  73. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  74. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  75. package/lib/cjs/ECSqlStatement.d.ts +473 -473
  76. package/lib/cjs/ECSqlStatement.js +791 -791
  77. package/lib/cjs/Element.d.ts +1105 -1109
  78. package/lib/cjs/Element.d.ts.map +1 -1
  79. package/lib/cjs/Element.js +1416 -1427
  80. package/lib/cjs/Element.js.map +1 -1
  81. package/lib/cjs/ElementAspect.d.ts +175 -179
  82. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  83. package/lib/cjs/ElementAspect.js +202 -211
  84. package/lib/cjs/ElementAspect.js.map +1 -1
  85. package/lib/cjs/ElementGraphics.d.ts +9 -9
  86. package/lib/cjs/ElementGraphics.js +41 -41
  87. package/lib/cjs/ElementGraphics.js.map +1 -1
  88. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  89. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  90. package/lib/cjs/ElementTreeWalker.js +409 -409
  91. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  92. package/lib/cjs/Entity.d.ts +102 -106
  93. package/lib/cjs/Entity.d.ts.map +1 -1
  94. package/lib/cjs/Entity.js +118 -134
  95. package/lib/cjs/Entity.js.map +1 -1
  96. package/lib/cjs/EntityReferences.d.ts +49 -49
  97. package/lib/cjs/EntityReferences.d.ts.map +1 -1
  98. package/lib/cjs/EntityReferences.js +95 -95
  99. package/lib/cjs/ExportGraphics.d.ts +317 -317
  100. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  101. package/lib/cjs/ExportGraphics.js +208 -208
  102. package/lib/cjs/ExternalSource.d.ts +95 -96
  103. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  104. package/lib/cjs/ExternalSource.js +130 -131
  105. package/lib/cjs/ExternalSource.js.map +1 -1
  106. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  107. package/lib/cjs/GeoCoordConfig.js +85 -85
  108. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  109. package/lib/cjs/GeometrySummary.d.ts +4 -4
  110. package/lib/cjs/GeometrySummary.js +333 -333
  111. package/lib/cjs/GeometrySummary.js.map +1 -1
  112. package/lib/cjs/HubMock.d.ts +94 -94
  113. package/lib/cjs/HubMock.js +220 -222
  114. package/lib/cjs/HubMock.js.map +1 -1
  115. package/lib/cjs/IModelCloneContext.d.ts +8 -8
  116. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  117. package/lib/cjs/IModelCloneContext.js +15 -15
  118. package/lib/cjs/IModelDb.d.ts +1222 -1196
  119. package/lib/cjs/IModelDb.d.ts.map +1 -1
  120. package/lib/cjs/IModelDb.js +2389 -2392
  121. package/lib/cjs/IModelDb.js.map +1 -1
  122. package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
  123. package/lib/cjs/IModelElementCloneContext.js +159 -159
  124. package/lib/cjs/IModelHost.d.ts +370 -369
  125. package/lib/cjs/IModelHost.d.ts.map +1 -1
  126. package/lib/cjs/IModelHost.js +476 -496
  127. package/lib/cjs/IModelHost.js.map +1 -1
  128. package/lib/cjs/IModelJsFs.d.ts +62 -62
  129. package/lib/cjs/IModelJsFs.js +139 -140
  130. package/lib/cjs/IModelJsFs.js.map +1 -1
  131. package/lib/cjs/IpcHost.d.ts +104 -104
  132. package/lib/cjs/IpcHost.js +276 -278
  133. package/lib/cjs/IpcHost.js.map +1 -1
  134. package/lib/cjs/LineStyle.d.ts +311 -311
  135. package/lib/cjs/LineStyle.js +295 -295
  136. package/lib/cjs/LocalHub.d.ts +162 -162
  137. package/lib/cjs/LocalHub.d.ts.map +1 -1
  138. package/lib/cjs/LocalHub.js +579 -584
  139. package/lib/cjs/LocalHub.js.map +1 -1
  140. package/lib/cjs/LocalhostIpcHost.d.ts +21 -20
  141. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
  142. package/lib/cjs/LocalhostIpcHost.js +79 -81
  143. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  144. package/lib/cjs/Material.d.ts +131 -131
  145. package/lib/cjs/Material.d.ts.map +1 -1
  146. package/lib/cjs/Material.js +185 -181
  147. package/lib/cjs/Material.js.map +1 -1
  148. package/lib/cjs/Model.d.ts +391 -392
  149. package/lib/cjs/Model.d.ts.map +1 -1
  150. package/lib/cjs/Model.js +487 -485
  151. package/lib/cjs/Model.js.map +1 -1
  152. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  153. package/lib/cjs/NativeAppStorage.js +202 -202
  154. package/lib/cjs/NativeAppStorage.js.map +1 -1
  155. package/lib/cjs/NativeHost.d.ts +52 -52
  156. package/lib/cjs/NativeHost.d.ts.map +1 -1
  157. package/lib/cjs/NativeHost.js +158 -163
  158. package/lib/cjs/NativeHost.js.map +1 -1
  159. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  160. package/lib/cjs/NavigationRelationship.js +225 -225
  161. package/lib/cjs/NavigationRelationship.js.map +1 -1
  162. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  163. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  164. package/lib/cjs/PromiseMemoizer.js +101 -101
  165. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  166. package/lib/cjs/PropertyStore.d.ts +123 -132
  167. package/lib/cjs/PropertyStore.d.ts.map +1 -1
  168. package/lib/cjs/PropertyStore.js +179 -11
  169. package/lib/cjs/PropertyStore.js.map +1 -1
  170. package/lib/cjs/Relationship.d.ts +413 -416
  171. package/lib/cjs/Relationship.d.ts.map +1 -1
  172. package/lib/cjs/Relationship.js +491 -494
  173. package/lib/cjs/Relationship.js.map +1 -1
  174. package/lib/cjs/RpcBackend.d.ts +5 -5
  175. package/lib/cjs/RpcBackend.js +32 -32
  176. package/lib/cjs/SQLiteDb.d.ts +317 -219
  177. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  178. package/lib/cjs/SQLiteDb.js +318 -214
  179. package/lib/cjs/SQLiteDb.js.map +1 -1
  180. package/lib/cjs/Schema.d.ts +55 -55
  181. package/lib/cjs/Schema.js +83 -83
  182. package/lib/cjs/Schema.js.map +1 -1
  183. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  184. package/lib/cjs/ServerBasedLocks.js +168 -168
  185. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  186. package/lib/cjs/SqliteStatement.d.ts +360 -360
  187. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  188. package/lib/cjs/SqliteStatement.js +586 -586
  189. package/lib/cjs/Texture.d.ts +58 -58
  190. package/lib/cjs/Texture.js +82 -82
  191. package/lib/cjs/Texture.js.map +1 -1
  192. package/lib/cjs/TileStorage.d.ts +44 -18
  193. package/lib/cjs/TileStorage.d.ts.map +1 -1
  194. package/lib/cjs/TileStorage.js +109 -90
  195. package/lib/cjs/TileStorage.js.map +1 -1
  196. package/lib/cjs/TxnManager.d.ts +202 -202
  197. package/lib/cjs/TxnManager.d.ts.map +1 -1
  198. package/lib/cjs/TxnManager.js +356 -356
  199. package/lib/cjs/TxnManager.js.map +1 -1
  200. package/lib/cjs/ViewDefinition.d.ts +429 -439
  201. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  202. package/lib/cjs/ViewDefinition.js +640 -646
  203. package/lib/cjs/ViewDefinition.js.map +1 -1
  204. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  205. package/lib/cjs/ViewStateHydrator.js +103 -103
  206. package/lib/cjs/core-backend.d.ts +181 -184
  207. package/lib/cjs/core-backend.d.ts.map +1 -1
  208. package/lib/cjs/core-backend.js +205 -204
  209. package/lib/cjs/core-backend.js.map +1 -1
  210. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  211. package/lib/cjs/domains/FunctionalElements.js +145 -145
  212. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  213. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  214. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  215. package/lib/cjs/domains/FunctionalSchema.js +39 -40
  216. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  217. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  218. package/lib/cjs/domains/GenericElements.js +263 -263
  219. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  220. package/lib/cjs/domains/GenericSchema.js +28 -28
  221. package/lib/cjs/rpc/multipart.d.ts +11 -11
  222. package/lib/cjs/rpc/multipart.js +71 -71
  223. package/lib/cjs/rpc/tracing.d.ts +28 -28
  224. package/lib/cjs/rpc/tracing.js +73 -74
  225. package/lib/cjs/rpc/tracing.js.map +1 -1
  226. package/lib/cjs/rpc/web/logging.d.ts +9 -9
  227. package/lib/cjs/rpc/web/logging.js +43 -43
  228. package/lib/cjs/rpc/web/request.d.ts +6 -6
  229. package/lib/cjs/rpc/web/request.js +73 -74
  230. package/lib/cjs/rpc/web/request.js.map +1 -1
  231. package/lib/cjs/rpc/web/response.d.ts +6 -6
  232. package/lib/cjs/rpc/web/response.js +105 -106
  233. package/lib/cjs/rpc/web/response.js.map +1 -1
  234. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  235. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  236. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
  237. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
  238. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  239. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
  240. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  241. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -205
  242. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  243. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  244. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
  245. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  246. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  247. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
  248. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  249. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  250. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  251. package/lib/cjs/workspace/Settings.d.ts +186 -186
  252. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  253. package/lib/cjs/workspace/Settings.js +155 -155
  254. package/lib/cjs/workspace/Settings.js.map +1 -1
  255. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  256. package/lib/cjs/workspace/SettingsSchemas.js +190 -191
  257. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  258. package/lib/cjs/workspace/Workspace.d.ts +411 -414
  259. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  260. package/lib/cjs/workspace/Workspace.js +521 -543
  261. package/lib/cjs/workspace/Workspace.js.map +1 -1
  262. package/package.json +25 -28
  263. package/lib/cjs/AliCloudStorageService.d.ts +0 -24
  264. package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
  265. package/lib/cjs/AliCloudStorageService.js +0 -72
  266. package/lib/cjs/AliCloudStorageService.js.map +0 -1
  267. package/lib/cjs/CloudStorageBackend.d.ts +0 -59
  268. package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
  269. package/lib/cjs/CloudStorageBackend.js +0 -174
  270. package/lib/cjs/CloudStorageBackend.js.map +0 -1
@@ -1,192 +1,191 @@
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?.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?.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
+ const properties = group.properties;
156
+ if (undefined === properties)
157
+ throw new Error(`group ${group.groupName} has no properties`);
158
+ for (const key of Object.keys(properties)) {
159
+ this.validateName(key);
160
+ this.validateProperty(key, properties[key]);
161
+ const property = properties[key];
162
+ property.default = property.default ?? this.getDefaultValue(property.type);
163
+ this.allSchemas.set(key, property);
164
+ }
165
+ }
166
+ static getDefaultValue(type) {
167
+ type = Array.isArray(type) ? type[0] : type;
168
+ switch (type) {
169
+ case "boolean":
170
+ return false;
171
+ case "integer":
172
+ case "number":
173
+ return 0;
174
+ case "string":
175
+ return "";
176
+ case "array":
177
+ return [];
178
+ case "object":
179
+ return {};
180
+ default:
181
+ return undefined;
182
+ }
183
+ }
184
+ }
185
+ SettingsSchemas._allGroups = new Map();
186
+ /** a map of all registered [[SettingSchema]]s */
187
+ SettingsSchemas.allSchemas = new Map();
188
+ /** event that signals that the values in [[allSchemas]] have changed in some way. */
189
+ SettingsSchemas.onSchemaChanged = new core_bentley_1.BeEvent();
190
+ exports.SettingsSchemas = SettingsSchemas;
192
191
  //# 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,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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"]}
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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,YAAY,CAAC,GAAG,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,QAAQ,CAAC,OAAO,IAAI,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;;AAxLuB,0BAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC3E,iDAAiD;AAC1B,0BAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;AACrE,qFAAqF;AAC9D,+BAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AANxD,0CAAe","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"]}