@itwin/core-backend 4.0.0-dev.6 → 4.0.0-dev.61

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 (253) hide show
  1. package/CHANGELOG.md +89 -67
  2. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +41 -41
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
  7. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.js +98 -99
  9. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  11. package/lib/cjs/BisCoreSchema.js +60 -60
  12. package/lib/cjs/BriefcaseManager.d.ts +170 -170
  13. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  14. package/lib/cjs/BriefcaseManager.js +408 -414
  15. package/lib/cjs/BriefcaseManager.js.map +1 -1
  16. package/lib/cjs/Category.d.ts +153 -153
  17. package/lib/cjs/Category.js +243 -243
  18. package/lib/cjs/Category.js.map +1 -1
  19. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  20. package/lib/cjs/ChangeSummaryManager.js +444 -445
  21. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  22. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  23. package/lib/cjs/ChangedElementsDb.js +165 -165
  24. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  25. package/lib/cjs/ChangedElementsManager.js +88 -88
  26. package/lib/cjs/ChannelControl.d.ts +70 -0
  27. package/lib/cjs/ChannelControl.d.ts.map +1 -0
  28. package/lib/cjs/ChannelControl.js +89 -0
  29. package/lib/cjs/ChannelControl.js.map +1 -0
  30. package/lib/cjs/CheckpointManager.d.ts +121 -121
  31. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  32. package/lib/cjs/CheckpointManager.js +351 -349
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/ClassRegistry.d.ts +79 -79
  35. package/lib/cjs/ClassRegistry.js +249 -245
  36. package/lib/cjs/ClassRegistry.js.map +1 -1
  37. package/lib/cjs/CloudSqlite.d.ts +355 -350
  38. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  39. package/lib/cjs/CloudSqlite.js +154 -153
  40. package/lib/cjs/CloudSqlite.js.map +1 -1
  41. package/lib/cjs/CodeService.d.ts +396 -396
  42. package/lib/cjs/CodeService.d.ts.map +1 -1
  43. package/lib/cjs/CodeService.js +63 -63
  44. package/lib/cjs/CodeService.js.map +1 -1
  45. package/lib/cjs/CodeSpecs.d.ts +55 -55
  46. package/lib/cjs/CodeSpecs.js +124 -124
  47. package/lib/cjs/ConcurrentQuery.d.ts +13 -13
  48. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
  49. package/lib/cjs/ConcurrentQuery.js +36 -36
  50. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  51. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  52. package/lib/cjs/CustomViewState3dCreator.js +82 -81
  53. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  54. package/lib/cjs/DevTools.d.ts +74 -71
  55. package/lib/cjs/DevTools.d.ts.map +1 -1
  56. package/lib/cjs/DevTools.js +156 -154
  57. package/lib/cjs/DevTools.js.map +1 -1
  58. package/lib/cjs/DisplayStyle.d.ts +106 -106
  59. package/lib/cjs/DisplayStyle.js +253 -256
  60. package/lib/cjs/DisplayStyle.js.map +1 -1
  61. package/lib/cjs/ECDb.d.ts +194 -191
  62. package/lib/cjs/ECDb.d.ts.map +1 -1
  63. package/lib/cjs/ECDb.js +353 -350
  64. package/lib/cjs/ECDb.js.map +1 -1
  65. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  66. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
  67. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  68. package/lib/cjs/ECSqlStatement.d.ts +473 -473
  69. package/lib/cjs/ECSqlStatement.js +791 -791
  70. package/lib/cjs/Element.d.ts +1113 -1109
  71. package/lib/cjs/Element.d.ts.map +1 -1
  72. package/lib/cjs/Element.js +1424 -1427
  73. package/lib/cjs/Element.js.map +1 -1
  74. package/lib/cjs/ElementAspect.d.ts +176 -179
  75. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  76. package/lib/cjs/ElementAspect.js +203 -211
  77. package/lib/cjs/ElementAspect.js.map +1 -1
  78. package/lib/cjs/ElementGraphics.d.ts +9 -9
  79. package/lib/cjs/ElementGraphics.js +41 -41
  80. package/lib/cjs/ElementGraphics.js.map +1 -1
  81. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  82. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  83. package/lib/cjs/ElementTreeWalker.js +409 -409
  84. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  85. package/lib/cjs/Entity.d.ts +106 -106
  86. package/lib/cjs/Entity.d.ts.map +1 -1
  87. package/lib/cjs/Entity.js +134 -134
  88. package/lib/cjs/Entity.js.map +1 -1
  89. package/lib/cjs/EntityReferences.d.ts +49 -49
  90. package/lib/cjs/EntityReferences.d.ts.map +1 -1
  91. package/lib/cjs/EntityReferences.js +95 -95
  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/ExternalSource.d.ts +96 -96
  96. package/lib/cjs/ExternalSource.js +131 -131
  97. package/lib/cjs/ExternalSource.js.map +1 -1
  98. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  99. package/lib/cjs/GeoCoordConfig.js +85 -85
  100. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  101. package/lib/cjs/GeometrySummary.d.ts +4 -4
  102. package/lib/cjs/GeometrySummary.js +333 -333
  103. package/lib/cjs/GeometrySummary.js.map +1 -1
  104. package/lib/cjs/HubMock.d.ts +94 -94
  105. package/lib/cjs/HubMock.js +220 -222
  106. package/lib/cjs/HubMock.js.map +1 -1
  107. package/lib/cjs/IModelCloneContext.d.ts +8 -8
  108. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  109. package/lib/cjs/IModelCloneContext.js +15 -15
  110. package/lib/cjs/IModelDb.d.ts +1216 -1196
  111. package/lib/cjs/IModelDb.d.ts.map +1 -1
  112. package/lib/cjs/IModelDb.js +2387 -2392
  113. package/lib/cjs/IModelDb.js.map +1 -1
  114. package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
  115. package/lib/cjs/IModelElementCloneContext.js +159 -159
  116. package/lib/cjs/IModelHost.d.ts +356 -369
  117. package/lib/cjs/IModelHost.d.ts.map +1 -1
  118. package/lib/cjs/IModelHost.js +472 -496
  119. package/lib/cjs/IModelHost.js.map +1 -1
  120. package/lib/cjs/IModelJsFs.d.ts +62 -62
  121. package/lib/cjs/IModelJsFs.js +139 -140
  122. package/lib/cjs/IModelJsFs.js.map +1 -1
  123. package/lib/cjs/IpcHost.d.ts +104 -104
  124. package/lib/cjs/IpcHost.js +276 -278
  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/LocalHub.d.ts +162 -162
  129. package/lib/cjs/LocalHub.d.ts.map +1 -1
  130. package/lib/cjs/LocalHub.js +579 -584
  131. package/lib/cjs/LocalHub.js.map +1 -1
  132. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  133. package/lib/cjs/LocalhostIpcHost.js +79 -81
  134. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  135. package/lib/cjs/Material.d.ts +131 -131
  136. package/lib/cjs/Material.js +180 -181
  137. package/lib/cjs/Material.js.map +1 -1
  138. package/lib/cjs/Model.d.ts +392 -392
  139. package/lib/cjs/Model.d.ts.map +1 -1
  140. package/lib/cjs/Model.js +489 -485
  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 +160 -163
  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 -101
  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/Relationship.d.ts +416 -416
  158. package/lib/cjs/Relationship.js +494 -494
  159. package/lib/cjs/Relationship.js.map +1 -1
  160. package/lib/cjs/RpcBackend.d.ts +5 -5
  161. package/lib/cjs/RpcBackend.js +32 -32
  162. package/lib/cjs/SQLiteDb.d.ts +219 -219
  163. package/lib/cjs/SQLiteDb.js +212 -214
  164. package/lib/cjs/SQLiteDb.js.map +1 -1
  165. package/lib/cjs/Schema.d.ts +55 -55
  166. package/lib/cjs/Schema.js +83 -83
  167. package/lib/cjs/Schema.js.map +1 -1
  168. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  169. package/lib/cjs/ServerBasedLocks.js +168 -168
  170. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  171. package/lib/cjs/SqliteStatement.d.ts +360 -360
  172. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  173. package/lib/cjs/SqliteStatement.js +586 -586
  174. package/lib/cjs/Texture.d.ts +58 -58
  175. package/lib/cjs/Texture.js +82 -82
  176. package/lib/cjs/Texture.js.map +1 -1
  177. package/lib/cjs/TileStorage.d.ts +18 -18
  178. package/lib/cjs/TileStorage.js +87 -90
  179. package/lib/cjs/TileStorage.js.map +1 -1
  180. package/lib/cjs/TxnManager.d.ts +202 -202
  181. package/lib/cjs/TxnManager.d.ts.map +1 -1
  182. package/lib/cjs/TxnManager.js +356 -356
  183. package/lib/cjs/TxnManager.js.map +1 -1
  184. package/lib/cjs/ViewDefinition.d.ts +435 -439
  185. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  186. package/lib/cjs/ViewDefinition.js +646 -646
  187. package/lib/cjs/ViewDefinition.js.map +1 -1
  188. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  189. package/lib/cjs/ViewStateHydrator.js +103 -103
  190. package/lib/cjs/core-backend.d.ts +183 -184
  191. package/lib/cjs/core-backend.d.ts.map +1 -1
  192. package/lib/cjs/core-backend.js +207 -204
  193. package/lib/cjs/core-backend.js.map +1 -1
  194. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  195. package/lib/cjs/domains/FunctionalElements.js +145 -145
  196. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  197. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  198. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
  199. package/lib/cjs/domains/FunctionalSchema.js +39 -40
  200. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  201. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  202. package/lib/cjs/domains/GenericElements.js +263 -263
  203. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  204. package/lib/cjs/domains/GenericSchema.js +28 -28
  205. package/lib/cjs/rpc/multipart.d.ts +11 -11
  206. package/lib/cjs/rpc/multipart.js +71 -71
  207. package/lib/cjs/rpc/tracing.d.ts +28 -28
  208. package/lib/cjs/rpc/tracing.js +73 -74
  209. package/lib/cjs/rpc/tracing.js.map +1 -1
  210. package/lib/cjs/rpc/web/logging.d.ts +9 -9
  211. package/lib/cjs/rpc/web/logging.js +43 -43
  212. package/lib/cjs/rpc/web/request.d.ts +6 -6
  213. package/lib/cjs/rpc/web/request.js +73 -74
  214. package/lib/cjs/rpc/web/request.js.map +1 -1
  215. package/lib/cjs/rpc/web/response.d.ts +6 -6
  216. package/lib/cjs/rpc/web/response.js +105 -106
  217. package/lib/cjs/rpc/web/response.js.map +1 -1
  218. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  219. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  220. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
  221. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
  222. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  223. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
  224. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  225. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +187 -205
  226. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  227. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  228. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
  229. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  230. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  231. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
  232. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  233. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  234. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  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 +154 -155
  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 +190 -191
  241. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  242. package/lib/cjs/workspace/Workspace.d.ts +414 -414
  243. package/lib/cjs/workspace/Workspace.js +537 -543
  244. package/lib/cjs/workspace/Workspace.js.map +1 -1
  245. package/package.json +19 -19
  246. package/lib/cjs/AliCloudStorageService.d.ts +0 -24
  247. package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
  248. package/lib/cjs/AliCloudStorageService.js +0 -72
  249. package/lib/cjs/AliCloudStorageService.js.map +0 -1
  250. package/lib/cjs/CloudStorageBackend.d.ts +0 -59
  251. package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
  252. package/lib/cjs/CloudStorageBackend.js +0 -174
  253. 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,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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,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"]}
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,EAAE,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,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;YACzC,MAAM,KAAK,GAAI,GAAW,CAAC,KAAK,CAAC,CAAC;YAClC,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S,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"]}