@itwin/core-backend 4.8.0-dev.2 → 4.8.0-dev.20

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 (230) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/lib/cjs/BackendHubAccess.d.ts +18 -16
  3. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  4. package/lib/cjs/BackendHubAccess.js +16 -15
  5. package/lib/cjs/BackendHubAccess.js.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.d.ts +3 -1
  7. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.js +2 -0
  9. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/BlobContainerService.d.ts +3 -3
  11. package/lib/cjs/BlobContainerService.d.ts.map +1 -1
  12. package/lib/cjs/BlobContainerService.js.map +1 -1
  13. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  14. package/lib/cjs/BriefcaseManager.js +4 -2
  15. package/lib/cjs/BriefcaseManager.js.map +1 -1
  16. package/lib/cjs/Category.d.ts +0 -6
  17. package/lib/cjs/Category.d.ts.map +1 -1
  18. package/lib/cjs/Category.js +0 -6
  19. package/lib/cjs/Category.js.map +1 -1
  20. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
  21. package/lib/cjs/ChangeSummaryManager.js +4 -3
  22. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  23. package/lib/cjs/ChangedElementsDb.d.ts +1 -0
  24. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  25. package/lib/cjs/ChangedElementsDb.js +3 -2
  26. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  27. package/lib/cjs/ChannelControl.d.ts +4 -26
  28. package/lib/cjs/ChannelControl.d.ts.map +1 -1
  29. package/lib/cjs/ChannelControl.js +2 -101
  30. package/lib/cjs/ChannelControl.js.map +1 -1
  31. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  32. package/lib/cjs/CheckpointManager.js +2 -1
  33. package/lib/cjs/CheckpointManager.js.map +1 -1
  34. package/lib/cjs/CloudSqlite.d.ts +49 -24
  35. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  36. package/lib/cjs/CloudSqlite.js +66 -7
  37. package/lib/cjs/CloudSqlite.js.map +1 -1
  38. package/lib/cjs/CodeService.d.ts +4 -4
  39. package/lib/cjs/CodeService.d.ts.map +1 -1
  40. package/lib/cjs/CodeService.js.map +1 -1
  41. package/lib/cjs/DevTools.d.ts.map +1 -1
  42. package/lib/cjs/DevTools.js +2 -1
  43. package/lib/cjs/DevTools.js.map +1 -1
  44. package/lib/cjs/DisplayStyle.d.ts +0 -3
  45. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  46. package/lib/cjs/DisplayStyle.js +0 -3
  47. package/lib/cjs/DisplayStyle.js.map +1 -1
  48. package/lib/cjs/ECDb.js +2 -2
  49. package/lib/cjs/ECDb.js.map +1 -1
  50. package/lib/cjs/ECSchemaXmlContext.js +2 -2
  51. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  52. package/lib/cjs/ECSqlStatement.d.ts +6 -3
  53. package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
  54. package/lib/cjs/ECSqlStatement.js +3 -3
  55. package/lib/cjs/ECSqlStatement.js.map +1 -1
  56. package/lib/cjs/Element.d.ts +3 -60
  57. package/lib/cjs/Element.d.ts.map +1 -1
  58. package/lib/cjs/Element.js +8 -64
  59. package/lib/cjs/Element.js.map +1 -1
  60. package/lib/cjs/ElementAspect.d.ts +0 -5
  61. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  62. package/lib/cjs/ElementAspect.js +4 -8
  63. package/lib/cjs/ElementAspect.js.map +1 -1
  64. package/lib/cjs/GeoCoordConfig.d.ts +10 -0
  65. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  66. package/lib/cjs/GeoCoordConfig.js +22 -24
  67. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  68. package/lib/cjs/GeographicCRSServices.js +2 -2
  69. package/lib/cjs/GeographicCRSServices.js.map +1 -1
  70. package/lib/cjs/IModelDb.d.ts +27 -97
  71. package/lib/cjs/IModelDb.d.ts.map +1 -1
  72. package/lib/cjs/IModelDb.js +131 -55
  73. package/lib/cjs/IModelDb.js.map +1 -1
  74. package/lib/cjs/IModelElementCloneContext.js +2 -2
  75. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  76. package/lib/cjs/IModelHost.d.ts +13 -4
  77. package/lib/cjs/IModelHost.d.ts.map +1 -1
  78. package/lib/cjs/IModelHost.js +39 -32
  79. package/lib/cjs/IModelHost.js.map +1 -1
  80. package/lib/cjs/IpcHost.d.ts.map +1 -1
  81. package/lib/cjs/IpcHost.js +2 -1
  82. package/lib/cjs/IpcHost.js.map +1 -1
  83. package/lib/cjs/LocalHub.d.ts +2 -2
  84. package/lib/cjs/LocalHub.d.ts.map +1 -1
  85. package/lib/cjs/LocalHub.js +17 -17
  86. package/lib/cjs/LocalHub.js.map +1 -1
  87. package/lib/cjs/LockControl.d.ts +66 -0
  88. package/lib/cjs/LockControl.d.ts.map +1 -0
  89. package/lib/cjs/LockControl.js +11 -0
  90. package/lib/cjs/LockControl.js.map +1 -0
  91. package/lib/cjs/Material.d.ts +2 -5
  92. package/lib/cjs/Material.d.ts.map +1 -1
  93. package/lib/cjs/Material.js +6 -4
  94. package/lib/cjs/Material.js.map +1 -1
  95. package/lib/cjs/Model.d.ts +0 -22
  96. package/lib/cjs/Model.d.ts.map +1 -1
  97. package/lib/cjs/Model.js +4 -25
  98. package/lib/cjs/Model.js.map +1 -1
  99. package/lib/cjs/PropertyStore.d.ts +17 -7
  100. package/lib/cjs/PropertyStore.d.ts.map +1 -1
  101. package/lib/cjs/PropertyStore.js +11 -5
  102. package/lib/cjs/PropertyStore.js.map +1 -1
  103. package/lib/cjs/Relationship.d.ts +0 -12
  104. package/lib/cjs/Relationship.d.ts.map +1 -1
  105. package/lib/cjs/Relationship.js +0 -12
  106. package/lib/cjs/Relationship.js.map +1 -1
  107. package/lib/cjs/SQLiteDb.d.ts +2 -3
  108. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  109. package/lib/cjs/SQLiteDb.js +5 -6
  110. package/lib/cjs/SQLiteDb.js.map +1 -1
  111. package/lib/cjs/SchemaSync.d.ts +1 -1
  112. package/lib/cjs/SchemaSync.d.ts.map +1 -1
  113. package/lib/cjs/SchemaSync.js +2 -2
  114. package/lib/cjs/SchemaSync.js.map +1 -1
  115. package/lib/cjs/SchemaUtils.js +3 -3
  116. package/lib/cjs/SchemaUtils.js.map +1 -1
  117. package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
  118. package/lib/cjs/SqliteChangesetReader.js +2 -2
  119. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  120. package/lib/cjs/SqliteStatement.js +2 -2
  121. package/lib/cjs/SqliteStatement.js.map +1 -1
  122. package/lib/cjs/TextAnnotationGeometry.d.ts +5 -1
  123. package/lib/cjs/TextAnnotationGeometry.d.ts.map +1 -1
  124. package/lib/cjs/TextAnnotationGeometry.js +11 -8
  125. package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
  126. package/lib/cjs/TextAnnotationLayout.d.ts +21 -13
  127. package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
  128. package/lib/cjs/TextAnnotationLayout.js +134 -92
  129. package/lib/cjs/TextAnnotationLayout.js.map +1 -1
  130. package/lib/cjs/TxnManager.d.ts +2 -1
  131. package/lib/cjs/TxnManager.d.ts.map +1 -1
  132. package/lib/cjs/TxnManager.js +2 -1
  133. package/lib/cjs/TxnManager.js.map +1 -1
  134. package/lib/cjs/ViewDefinition.d.ts +1 -18
  135. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  136. package/lib/cjs/ViewDefinition.js +1 -18
  137. package/lib/cjs/ViewDefinition.js.map +1 -1
  138. package/lib/cjs/ViewStore.d.ts +16 -2
  139. package/lib/cjs/ViewStore.d.ts.map +1 -1
  140. package/lib/cjs/ViewStore.js +14 -1
  141. package/lib/cjs/ViewStore.js.map +1 -1
  142. package/lib/cjs/assets/Settings/Schemas/Base.Schema.json +33 -0
  143. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +17 -21
  144. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +80 -38
  145. package/lib/cjs/assets/Settings/backend.setting.json5 +8 -119
  146. package/lib/cjs/core-backend.d.ts +3 -2
  147. package/lib/cjs/core-backend.d.ts.map +1 -1
  148. package/lib/cjs/core-backend.js +4 -6
  149. package/lib/cjs/core-backend.js.map +1 -1
  150. package/lib/cjs/domains/FunctionalElements.d.ts +0 -10
  151. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
  152. package/lib/cjs/domains/FunctionalElements.js +0 -10
  153. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  154. package/lib/cjs/domains/GenericElements.d.ts +0 -18
  155. package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
  156. package/lib/cjs/domains/GenericElements.js +0 -18
  157. package/lib/cjs/domains/GenericElements.js.map +1 -1
  158. package/lib/cjs/internal/ChangesetConflictArgs.d.ts +24 -0
  159. package/lib/cjs/internal/ChangesetConflictArgs.d.ts.map +1 -0
  160. package/lib/cjs/internal/ChangesetConflictArgs.js +7 -0
  161. package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -0
  162. package/lib/cjs/internal/ChannelAdmin.d.ts +34 -0
  163. package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -0
  164. package/lib/cjs/internal/ChannelAdmin.js +117 -0
  165. package/lib/cjs/internal/ChannelAdmin.js.map +1 -0
  166. package/lib/cjs/internal/NativePlatform.d.ts +15 -0
  167. package/lib/cjs/internal/NativePlatform.d.ts.map +1 -0
  168. package/lib/cjs/internal/NativePlatform.js +49 -0
  169. package/lib/cjs/internal/NativePlatform.js.map +1 -0
  170. package/lib/cjs/internal/NoLocks.d.ts +6 -0
  171. package/lib/cjs/internal/NoLocks.d.ts.map +1 -0
  172. package/lib/cjs/internal/NoLocks.js +30 -0
  173. package/lib/cjs/internal/NoLocks.js.map +1 -0
  174. package/lib/cjs/{ServerBasedLocks.d.ts → internal/ServerBasedLocks.d.ts} +10 -17
  175. package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -0
  176. package/lib/cjs/{ServerBasedLocks.js → internal/ServerBasedLocks.js} +22 -17
  177. package/lib/cjs/internal/ServerBasedLocks.js.map +1 -0
  178. package/lib/cjs/internal/Symbols.d.ts +9 -0
  179. package/lib/cjs/internal/Symbols.d.ts.map +1 -0
  180. package/lib/cjs/internal/Symbols.js +19 -0
  181. package/lib/cjs/internal/Symbols.js.map +1 -0
  182. package/lib/cjs/internal/cross-package.d.ts +3 -0
  183. package/lib/cjs/internal/cross-package.d.ts.map +1 -0
  184. package/lib/cjs/internal/cross-package.js +14 -0
  185. package/lib/cjs/internal/cross-package.js.map +1 -0
  186. package/lib/cjs/internal/workspace/SettingsImpl.d.ts +43 -0
  187. package/lib/cjs/internal/workspace/SettingsImpl.d.ts.map +1 -0
  188. package/lib/cjs/internal/workspace/SettingsImpl.js +161 -0
  189. package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -0
  190. package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts +6 -0
  191. package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -0
  192. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +276 -0
  193. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -0
  194. package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts +41 -0
  195. package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts.map +1 -0
  196. package/lib/cjs/internal/workspace/WorkspaceImpl.js +696 -0
  197. package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -0
  198. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts +10 -0
  199. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts.map +1 -0
  200. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js +41 -0
  201. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -0
  202. package/lib/cjs/rpc/tracing.js +1 -1
  203. package/lib/cjs/rpc/tracing.js.map +1 -1
  204. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -0
  205. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
  206. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +5 -2
  207. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  208. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  209. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +2 -1
  210. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  211. package/lib/cjs/workspace/Settings.d.ts +167 -138
  212. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  213. package/lib/cjs/workspace/Settings.js +68 -138
  214. package/lib/cjs/workspace/Settings.js.map +1 -1
  215. package/lib/cjs/workspace/SettingsSchemas.d.ts +112 -48
  216. package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -1
  217. package/lib/cjs/workspace/SettingsSchemas.js +1 -172
  218. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  219. package/lib/cjs/workspace/Workspace.d.ts +411 -277
  220. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  221. package/lib/cjs/workspace/Workspace.js +76 -457
  222. package/lib/cjs/workspace/Workspace.js.map +1 -1
  223. package/lib/cjs/workspace/WorkspaceEditor.d.ts +245 -0
  224. package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -0
  225. package/lib/cjs/workspace/WorkspaceEditor.js +34 -0
  226. package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -0
  227. package/package.json +15 -14
  228. package/lib/cjs/ServerBasedLocks.d.ts.map +0 -1
  229. package/lib/cjs/ServerBasedLocks.js.map +0 -1
  230. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +0 -45
@@ -0,0 +1,161 @@
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
+ var _a, _b;
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.SettingsImpl = void 0;
12
+ const fs = require("fs-extra");
13
+ const json5_1 = require("json5");
14
+ const path_1 = require("path");
15
+ const core_bentley_1 = require("@itwin/core-bentley");
16
+ const IModelJsFs_1 = require("../../IModelJsFs");
17
+ const Settings_1 = require("../../workspace/Settings");
18
+ const IModelHost_1 = require("../../IModelHost");
19
+ const Symbols_1 = require("../Symbols");
20
+ const dictionaryMatches = (d1, d2) => {
21
+ return (d1.workspaceDb === d2.workspaceDb) && (d1.name === d2.name);
22
+ };
23
+ class SettingsDictionaryImpl {
24
+ constructor(props, settings) {
25
+ this[_a] = undefined;
26
+ this.props = { ...props }; // make a copy so it can't be changed by caller
27
+ this.settings = settings;
28
+ }
29
+ getSetting(settingName) {
30
+ const value = this.settings[settingName];
31
+ return undefined !== value ? Settings_1.Setting.clone(value) : undefined;
32
+ }
33
+ }
34
+ _a = Symbols_1._implementationProhibited;
35
+ /**
36
+ * Internal implementation of Settings interface.
37
+ * @internal
38
+ */
39
+ class SettingsImpl {
40
+ constructor() {
41
+ this[_b] = undefined;
42
+ this.dictionaries = [];
43
+ this.onSettingsChanged = new core_bentley_1.BeEvent();
44
+ }
45
+ verifyPriority(_priority) { }
46
+ close() { }
47
+ addFile(fileName, priority) {
48
+ this.addJson({ name: fileName, priority }, fs.readFileSync(fileName, "utf-8"));
49
+ }
50
+ addDirectory(dirName, priority) {
51
+ for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
52
+ const ext = (0, path_1.extname)(fileName);
53
+ if (ext === ".json5" || ext === ".json")
54
+ this.addFile((0, path_1.join)(dirName, fileName), priority);
55
+ }
56
+ }
57
+ addJson(props, settingsJson) {
58
+ this.addDictionary(props, (0, json5_1.parse)(settingsJson));
59
+ }
60
+ addDictionary(props, settings) {
61
+ this.verifyPriority(props.priority);
62
+ this.dropDictionary(props, false); // make sure we don't have the same dictionary twice
63
+ const dict = new SettingsDictionaryImpl(props, settings);
64
+ const doAdd = () => {
65
+ for (let i = 0; i < this.dictionaries.length; ++i) {
66
+ if (this.dictionaries[i].props.priority <= dict.props.priority) {
67
+ this.dictionaries.splice(i, 0, dict);
68
+ return;
69
+ }
70
+ }
71
+ this.dictionaries.push(dict);
72
+ };
73
+ doAdd();
74
+ this.onSettingsChanged.raiseEvent();
75
+ }
76
+ getDictionary(source) {
77
+ for (const dictionary of this.dictionaries) {
78
+ if (dictionaryMatches(dictionary.props, source))
79
+ return dictionary;
80
+ }
81
+ return undefined;
82
+ }
83
+ dropDictionary(source, raiseEvent = true) {
84
+ for (let i = 0; i < this.dictionaries.length; ++i) {
85
+ if (dictionaryMatches(this.dictionaries[i].props, source)) {
86
+ this.dictionaries.splice(i, 1);
87
+ if (raiseEvent)
88
+ this.onSettingsChanged.raiseEvent();
89
+ return true;
90
+ }
91
+ }
92
+ return false;
93
+ }
94
+ *getSettingEntries(settingName) {
95
+ for (const dictionary of this.dictionaries) {
96
+ const value = dictionary.getSetting(settingName);
97
+ if (undefined !== value) {
98
+ yield { value, dictionary };
99
+ }
100
+ }
101
+ }
102
+ *getSettingValues(settingName) {
103
+ for (const entry of this.getSettingEntries(settingName)) {
104
+ yield entry.value;
105
+ }
106
+ }
107
+ getSetting(settingName, defaultValue) {
108
+ for (const value of this.getSettingValues(settingName)) {
109
+ return value;
110
+ }
111
+ return defaultValue;
112
+ }
113
+ // get the setting and verify the result is either undefined or the correct type. If so, return it. Otherwise throw an exception.
114
+ getResult(name, expectedType) {
115
+ const out = this.getSetting(name);
116
+ if (out === undefined || typeof out === expectedType)
117
+ return out;
118
+ throw new Error(`setting "${name}" is not a ${expectedType}: ${typeof out}`);
119
+ }
120
+ getString(name, defaultValue) {
121
+ return this.getResult(name, "string") ?? defaultValue;
122
+ }
123
+ getBoolean(name, defaultValue) {
124
+ return this.getResult(name, "boolean") ?? defaultValue;
125
+ }
126
+ getNumber(name, defaultValue) {
127
+ return this.getResult(name, "number") ?? defaultValue;
128
+ }
129
+ getObject(name, defaultValue) {
130
+ const out = this.getResult(name, "object");
131
+ return out ? IModelHost_1.IModelHost.settingsSchemas.validateSetting(out, name) : defaultValue;
132
+ }
133
+ getArray(name, defaultValue) {
134
+ if (IModelHost_1.IModelHost.settingsSchemas.settingDefs.get(name)?.combineArray) {
135
+ return this.getCombinedArray(name, defaultValue);
136
+ }
137
+ const out = this.getSetting(name);
138
+ if (out === undefined)
139
+ return defaultValue;
140
+ if (!Array.isArray(out))
141
+ throw new Error(`setting ${name} is not an array: ${out}`);
142
+ return IModelHost_1.IModelHost.settingsSchemas.validateSetting(out, name);
143
+ }
144
+ getCombinedArray(name, defaultValue) {
145
+ let foundSetting = false;
146
+ const out = [];
147
+ for (const array of this.getSettingValues(name)) {
148
+ foundSetting = true;
149
+ IModelHost_1.IModelHost.settingsSchemas.validateSetting(array, name);
150
+ for (const value of array) {
151
+ if (undefined === out.find((x) => Settings_1.Setting.areEqual(x, value))) {
152
+ out.push(value);
153
+ }
154
+ }
155
+ }
156
+ return foundSetting ? out : defaultValue;
157
+ }
158
+ }
159
+ exports.SettingsImpl = SettingsImpl;
160
+ _b = Symbols_1._implementationProhibited;
161
+ //# sourceMappingURL=SettingsImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SettingsImpl.js","sourceRoot":"","sources":["../../../../src/internal/workspace/SettingsImpl.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAA8C;AAE9C,iDAA8C;AA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OAAO,IAAI,CAAC,gBAAgB,CAAI,IAAI,EAAE,YAAY,CAAC,CAAC;QACtD,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAM,IAAI,CAAC,CAAC;QACvC,IAAI,GAAG,KAAK,SAAS;YACnB,OAAO,YAAY,CAAC;QACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,qBAAqB,GAAG,EAAE,CAAC,CAAC;QAC7D,OAAO,uBAAU,CAAC,eAAe,CAAC,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;IAEO,gBAAgB,CAAoB,IAAiB,EAAE,YAAkB;QAC/E,IAAI,YAAY,GAAG,KAAK,CAAC;QACzB,MAAM,GAAG,GAAQ,EAAE,CAAC;QACpB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,gBAAgB,CAAM,IAAI,CAAC,EAAE,CAAC;YACrD,YAAY,GAAG,IAAI,CAAC;YAEpB,uBAAU,CAAC,eAAe,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACxD,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,SAAS,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;oBAC9D,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IAC3C,CAAC;CACF;AA9ID,oCA8IC;KA7IkB,mCAAyB","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 } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsFs } from \"../../IModelJsFs\";\r\nimport { Setting, SettingName, Settings, SettingsContainer, SettingsDictionary, SettingsDictionaryProps, SettingsDictionarySource, SettingsPriority } from \"../../workspace/Settings\";\r\nimport { IModelHost } from \"../../IModelHost\";\r\nimport { _implementationProhibited } from \"../Symbols\";\r\n\r\nconst dictionaryMatches = (d1: SettingsDictionarySource, d2: SettingsDictionarySource): boolean => {\r\n return (d1.workspaceDb === d2.workspaceDb) && (d1.name === d2.name);\r\n};\r\n\r\nclass SettingsDictionaryImpl implements SettingsDictionary {\r\n public readonly [_implementationProhibited] = undefined;\r\n public readonly props: SettingsDictionaryProps;\r\n public readonly settings: SettingsContainer;\r\n\r\n public constructor(props: SettingsDictionaryProps, settings: SettingsContainer) {\r\n this.props = { ...props }; // make a copy so it can't be changed by caller\r\n this.settings = settings;\r\n }\r\n\r\n public getSetting<T extends Setting>(settingName: string): T | undefined {\r\n const value = this.settings[settingName] as T | undefined;\r\n return undefined !== value ? Setting.clone(value) : undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Internal implementation of Settings interface.\r\n * @internal\r\n */\r\nexport class SettingsImpl implements Settings {\r\n public readonly [_implementationProhibited] = undefined;\r\n public dictionaries: SettingsDictionary[] = [];\r\n protected verifyPriority(_priority: SettingsPriority) { }\r\n public close() { }\r\n public readonly onSettingsChanged = new BeEvent<() => void>();\r\n\r\n public addFile(fileName: LocalFileName, priority: SettingsPriority) {\r\n this.addJson({ name: fileName, priority }, fs.readFileSync(fileName, \"utf-8\"));\r\n }\r\n\r\n public addDirectory(dirName: LocalDirName, priority: SettingsPriority) {\r\n for (const fileName of IModelJsFs.readdirSync(dirName)) {\r\n const ext = extname(fileName);\r\n if (ext === \".json5\" || ext === \".json\")\r\n this.addFile(join(dirName, fileName), priority);\r\n }\r\n }\r\n\r\n public addJson(props: SettingsDictionaryProps, settingsJson: string) {\r\n this.addDictionary(props, parse(settingsJson));\r\n }\r\n\r\n public addDictionary(props: SettingsDictionaryProps, settings: SettingsContainer) {\r\n this.verifyPriority(props.priority);\r\n this.dropDictionary(props, false); // make sure we don't have the same dictionary twice\r\n const dict = new SettingsDictionaryImpl(props, settings);\r\n const doAdd = () => {\r\n for (let i = 0; i < this.dictionaries.length; ++i) {\r\n if (this.dictionaries[i].props.priority <= dict.props.priority) {\r\n this.dictionaries.splice(i, 0, dict);\r\n return;\r\n }\r\n }\r\n this.dictionaries.push(dict);\r\n };\r\n doAdd();\r\n this.onSettingsChanged.raiseEvent();\r\n }\r\n\r\n public getDictionary(source: SettingsDictionarySource): SettingsDictionary | undefined {\r\n for (const dictionary of this.dictionaries) {\r\n if (dictionaryMatches(dictionary.props, source))\r\n return dictionary;\r\n }\r\n return undefined;\r\n }\r\n\r\n public dropDictionary(source: SettingsDictionarySource, raiseEvent = true) {\r\n for (let i = 0; i < this.dictionaries.length; ++i) {\r\n if (dictionaryMatches(this.dictionaries[i].props, source)) {\r\n this.dictionaries.splice(i, 1);\r\n if (raiseEvent)\r\n this.onSettingsChanged.raiseEvent();\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public * getSettingEntries<T extends Setting>(settingName: SettingName): Iterable<{ value: T, dictionary: SettingsDictionary}> {\r\n for (const dictionary of this.dictionaries) {\r\n const value = dictionary.getSetting<T>(settingName);\r\n if (undefined !== value) {\r\n yield { value, dictionary };\r\n }\r\n }\r\n }\r\n\r\n public * getSettingValues<T extends Setting>(settingName: SettingName): Iterable<T> {\r\n for (const entry of this.getSettingEntries<T>(settingName)) {\r\n yield entry.value;\r\n }\r\n }\r\n\r\n public getSetting<T extends Setting>(settingName: SettingName, defaultValue?: T): T | undefined {\r\n for (const value of this.getSettingValues<T>(settingName)) {\r\n return value;\r\n }\r\n\r\n return defaultValue;\r\n }\r\n\r\n // get the setting and verify the result is either undefined or the correct type. If so, return it. Otherwise throw an exception.\r\n private getResult<T extends Setting>(name: SettingName, expectedType: string) {\r\n const out = this.getSetting<T>(name);\r\n if (out === undefined || typeof out === expectedType)\r\n return out;\r\n throw new Error(`setting \"${name}\" is not a ${expectedType}: ${typeof out}`);\r\n }\r\n public getString(name: SettingName, defaultValue: string): string;\r\n public getString(name: SettingName): string | undefined;\r\n public getString(name: SettingName, defaultValue?: string): string | undefined {\r\n return this.getResult<string>(name, \"string\") ?? defaultValue;\r\n }\r\n public getBoolean(name: SettingName, defaultValue: boolean): boolean;\r\n public getBoolean(name: SettingName): boolean | undefined;\r\n public getBoolean(name: SettingName, defaultValue?: boolean): boolean | undefined {\r\n return this.getResult<boolean>(name, \"boolean\") ?? defaultValue;\r\n }\r\n public getNumber(name: SettingName, defaultValue: number): number;\r\n public getNumber(name: SettingName): number | undefined;\r\n public getNumber(name: SettingName, defaultValue?: number): number | undefined {\r\n return this.getResult<number>(name, \"number\") ?? defaultValue;\r\n }\r\n public getObject<T extends object>(name: SettingName, defaultValue: T): T;\r\n public getObject<T extends object>(name: SettingName): T | undefined;\r\n public getObject<T extends object>(name: SettingName, defaultValue?: T): T | undefined {\r\n const out = this.getResult<T>(name, \"object\");\r\n return out ? IModelHost.settingsSchemas.validateSetting(out, name) : defaultValue;\r\n }\r\n public getArray<T extends Setting>(name: SettingName, defaultValue: T[]): T[];\r\n public getArray<T extends Setting>(name: SettingName): T[] | undefined;\r\n public getArray<T extends Setting>(name: SettingName, defaultValue?: T[]): T[] | undefined {\r\n if (IModelHost.settingsSchemas.settingDefs.get(name)?.combineArray) {\r\n return this.getCombinedArray<T>(name, defaultValue);\r\n }\r\n\r\n const out = this.getSetting<T[]>(name);\r\n if (out === undefined)\r\n return defaultValue;\r\n if (!Array.isArray(out))\r\n throw new Error(`setting ${name} is not an array: ${out}`);\r\n return IModelHost.settingsSchemas.validateSetting(out, name);\r\n }\r\n\r\n private getCombinedArray<T extends Setting>(name: SettingName, defaultValue?: T[]): T[] | undefined {\r\n let foundSetting = false;\r\n const out: T[] = [];\r\n for (const array of this.getSettingValues<T[]>(name)) {\r\n foundSetting = true;\r\n\r\n IModelHost.settingsSchemas.validateSetting(array, name);\r\n for (const value of array) {\r\n if (undefined === out.find((x) => Setting.areEqual(x, value))) {\r\n out.push(value);\r\n }\r\n }\r\n }\r\n\r\n return foundSetting ? out : defaultValue;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,6 @@
1
+ /** @packageDocumentation
2
+ * @module Workspace
3
+ */
4
+ import { SettingsSchemas } from "../../workspace/SettingsSchemas";
5
+ export declare function constructSettingsSchemas(): SettingsSchemas;
6
+ //# sourceMappingURL=SettingsSchemasImpl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SettingsSchemasImpl.d.ts","sourceRoot":"","sources":["../../../../src/internal/workspace/SettingsSchemasImpl.ts"],"names":[],"mappings":"AAIA;;GAEG;AAQH,OAAO,EAAqC,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAyRrG,wBAAgB,wBAAwB,IAAI,eAAe,CAE1D"}
@@ -0,0 +1,276 @@
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
+ var _a;
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.constructSettingsSchemas = void 0;
12
+ const fs = require("fs-extra");
13
+ const json5_1 = require("json5");
14
+ const path_1 = require("path");
15
+ const core_bentley_1 = require("@itwin/core-bentley");
16
+ const IModelJsFs_1 = require("../../IModelJsFs");
17
+ const Symbols_1 = require("../Symbols");
18
+ const makeSettingKey = (prefix, key) => `${prefix}/${key}`;
19
+ class SettingsSchemasImpl {
20
+ constructor() {
21
+ this[_a] = undefined;
22
+ this._allGroups = new Map();
23
+ /** a map of all registered Setting Definitions */
24
+ this.settingDefs = new Map();
25
+ /** a map of all registered TypeDefs */
26
+ this.typeDefs = new Map();
27
+ /** event that signals that the values in [[allSchemas]] have changed in some way. */
28
+ this.onSchemaChanged = new core_bentley_1.BeEvent();
29
+ }
30
+ verifyType(val, expectedType, path) {
31
+ if (expectedType === "integer") {
32
+ if (Number.isInteger(val))
33
+ return;
34
+ }
35
+ else if (expectedType === "null") {
36
+ if (val === null || val === undefined)
37
+ return;
38
+ }
39
+ else if (typeof val === expectedType)
40
+ return;
41
+ throw new Error(`value for ${path}: "${val}" is wrong type, expected ${expectedType}`);
42
+ }
43
+ validateSetting(value, settingName) {
44
+ const settingDef = this.settingDefs.get(settingName);
45
+ if (undefined !== settingDef) // if there's no setting definition, there's no rules so just return ok
46
+ this.validateProperty(value, settingDef, settingName);
47
+ return value;
48
+ }
49
+ /** @internal */
50
+ getObjectProperties(propDef, scope) {
51
+ let required = propDef.required;
52
+ let properties = propDef.properties;
53
+ // if this object extends a typeDef, add typeDef's properties and required values, recursively
54
+ if (propDef.extends !== undefined) {
55
+ const typeDef = this.typeDefs.get(propDef.extends);
56
+ if (undefined === typeDef)
57
+ throw new Error(`typeDef ${propDef.extends} does not exist for ${scope}`);
58
+ const expanded = this.getObjectProperties(typeDef, `${scope}.${propDef.extends}`);
59
+ if (expanded.required)
60
+ required = required ? [...required, ...expanded.required] : expanded.required;
61
+ if (expanded.properties) {
62
+ properties = properties ? { ...expanded.properties, ...properties } : expanded.properties;
63
+ }
64
+ }
65
+ properties = properties ?? {};
66
+ return { required, properties };
67
+ }
68
+ /** @internal */
69
+ getArrayItems(propDef, scope) {
70
+ let items = propDef.items;
71
+ if (undefined === items && propDef.extends) {
72
+ const typeDef = this.typeDefs.get(propDef.extends);
73
+ if (undefined === typeDef)
74
+ throw new Error(`typeDef ${propDef.extends} does not exist for ${scope}`);
75
+ items = typeDef.items;
76
+ }
77
+ if (undefined === items)
78
+ throw new Error(`array ${scope} has no items definition`);
79
+ return items;
80
+ }
81
+ validateProperty(val, propDef, path) {
82
+ switch (propDef.type) {
83
+ case "boolean":
84
+ case "number":
85
+ case "string":
86
+ case "integer":
87
+ case "null":
88
+ return this.verifyType(val, propDef.type, path);
89
+ case "array":
90
+ if (!Array.isArray(val))
91
+ throw new Error(`Property ${path} must be an array`);
92
+ const items = this.getArrayItems(propDef, path);
93
+ for (let i = 0; i < val.length; ++i)
94
+ this.validateProperty(val[i], items, `${path}[${i}]`);
95
+ return;
96
+ }
97
+ if (!val || typeof val !== "object")
98
+ throw new Error(`${path} must be an object`);
99
+ const { required, properties } = this.getObjectProperties(propDef, path);
100
+ // first ensure all required properties are present
101
+ if (undefined !== required) {
102
+ for (const entry of required) {
103
+ const value = val[entry];
104
+ if (undefined === value)
105
+ throw new Error(`required value for "${entry}" is missing in "${path}"`);
106
+ }
107
+ }
108
+ // you can supply default values in typeDefs. See if any members are undefined that have a default.
109
+ if (undefined !== properties) {
110
+ for (const [key, prop] of Object.entries(properties)) {
111
+ if (val[key] === undefined && prop.default)
112
+ val[key] = prop.default;
113
+ }
114
+ }
115
+ // then validate all values in the supplied object are valid
116
+ for (const key of Object.keys(val)) {
117
+ const prop = properties[key];
118
+ if (prop !== undefined) { // note: extra values are ignored.
119
+ this.validateProperty(val[key], prop, `${path}.${key}`);
120
+ }
121
+ }
122
+ }
123
+ /**
124
+ * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `schemaPrefix` member that is used
125
+ * 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.
126
+ */
127
+ addGroup(settingsGroup) {
128
+ if (!Array.isArray(settingsGroup))
129
+ settingsGroup = [settingsGroup];
130
+ this.doAdd(settingsGroup);
131
+ this.onSchemaChanged.raiseEvent();
132
+ }
133
+ /** Add a [[SettingSchemaGroup]] from stringified json5. */
134
+ addJson(settingSchema) {
135
+ this.addGroup((0, json5_1.parse)(settingSchema));
136
+ }
137
+ /** Add a [[SettingSchemaGroup]] from a json5 file. */
138
+ addFile(fileName) {
139
+ try {
140
+ this.addJson(fs.readFileSync(fileName, "utf-8"));
141
+ }
142
+ catch (e) {
143
+ throw new Error(`parsing SettingSchema file "${fileName}": ${e.message}"`);
144
+ }
145
+ }
146
+ /** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
147
+ addDirectory(dirName) {
148
+ for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
149
+ const ext = (0, path_1.extname)(fileName);
150
+ if (ext === ".json5" || ext === ".json")
151
+ this.addFile((0, path_1.join)(dirName, fileName));
152
+ }
153
+ }
154
+ /** Remove a previously added [[SettingSchemaGroup]] by schemaPrefix */
155
+ removeGroup(schemaPrefix) {
156
+ this.doRemove(schemaPrefix);
157
+ this.onSchemaChanged.raiseEvent();
158
+ }
159
+ doAdd(settingsGroup) {
160
+ settingsGroup.forEach((group) => {
161
+ if (undefined === group.schemaPrefix)
162
+ throw new Error(`settings group has no "schemaPrefix" member`);
163
+ this.doRemove(group.schemaPrefix);
164
+ this.validateAndAdd(group);
165
+ this._allGroups.set(group.schemaPrefix, group);
166
+ });
167
+ }
168
+ doRemove(schemaPrefix) {
169
+ const group = this._allGroups.get(schemaPrefix);
170
+ if (undefined !== group?.settingDefs) {
171
+ for (const key of Object.keys(group.settingDefs))
172
+ this.settingDefs.delete(makeSettingKey(schemaPrefix, key));
173
+ }
174
+ if (undefined !== group?.typeDefs) {
175
+ for (const key of Object.keys(group.typeDefs))
176
+ this.settingDefs.delete(makeSettingKey(schemaPrefix, key));
177
+ }
178
+ this._allGroups.delete(schemaPrefix);
179
+ }
180
+ validateName(name) {
181
+ if (!name.trim())
182
+ throw new Error(`empty property name`);
183
+ }
184
+ verifyPropertyDef(name, property) {
185
+ if (!property)
186
+ throw new Error(`missing required property ${name}`);
187
+ if (!property.type)
188
+ throw new Error(`property ${name} has no type`);
189
+ switch (property.type) {
190
+ case "boolean":
191
+ case "integer":
192
+ case "null":
193
+ case "number":
194
+ case "string":
195
+ return;
196
+ case "object":
197
+ const required = property.required;
198
+ const props = property.properties;
199
+ if (required && props) {
200
+ for (const entry of required) {
201
+ if (undefined === props[entry])
202
+ throw new Error(`missing required property of ${name}: "${entry}"`);
203
+ }
204
+ }
205
+ if (props) {
206
+ for (const key of Object.keys(props))
207
+ try {
208
+ this.verifyPropertyDef(key, props[key]);
209
+ }
210
+ catch (e) {
211
+ throw new Error(`property ${key} of ${name}: ${e.message}`);
212
+ }
213
+ }
214
+ return;
215
+ case "array":
216
+ if (typeof property.extends === "string")
217
+ return;
218
+ if (typeof property.items !== "object")
219
+ throw new Error(`array property ${name} has no items member`);
220
+ try {
221
+ this.verifyPropertyDef("items", property.items);
222
+ }
223
+ catch (e) {
224
+ throw new Error(`array property ${name}: ${e.message}`);
225
+ }
226
+ return;
227
+ default:
228
+ throw new Error(`property ${name} has illegal type "${property.type}"`);
229
+ }
230
+ }
231
+ validateAndAdd(group) {
232
+ const settingDefs = group.settingDefs;
233
+ if (undefined !== settingDefs) {
234
+ for (const key of Object.keys(settingDefs)) {
235
+ this.validateName(key);
236
+ this.verifyPropertyDef(key, settingDefs[key]);
237
+ const property = settingDefs[key];
238
+ (0, core_bentley_1.assert)(undefined !== property);
239
+ property.default = property.default ?? this.getDefaultValue(property.type);
240
+ this.settingDefs.set(makeSettingKey(group.schemaPrefix, key), property);
241
+ }
242
+ }
243
+ const typeDefs = group.typeDefs ?? {};
244
+ for (const key of Object.keys(typeDefs)) {
245
+ this.validateName(key);
246
+ this.verifyPropertyDef(key, typeDefs[key]);
247
+ const typeDef = typeDefs[key];
248
+ (0, core_bentley_1.assert)(undefined !== typeDef);
249
+ this.typeDefs.set(makeSettingKey(group.schemaPrefix, key), typeDef);
250
+ }
251
+ }
252
+ getDefaultValue(type) {
253
+ type = Array.isArray(type) ? type[0] : type;
254
+ switch (type) {
255
+ case "boolean":
256
+ return false;
257
+ case "integer":
258
+ case "number":
259
+ return 0;
260
+ case "string":
261
+ return "";
262
+ case "array":
263
+ return [];
264
+ case "object":
265
+ return {};
266
+ default:
267
+ return undefined;
268
+ }
269
+ }
270
+ }
271
+ _a = Symbols_1._implementationProhibited;
272
+ function constructSettingsSchemas() {
273
+ return new SettingsSchemasImpl();
274
+ }
275
+ exports.constructSettingsSchemas = constructSettingsSchemas;
276
+ //# sourceMappingURL=SettingsSchemasImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SettingsSchemasImpl.js","sourceRoot":"","sources":["../../../../src/internal/workspace/SettingsSchemasImpl.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAAmG;AAEnG,iDAA8C;AAE9C,wCAAuD;AAEvD,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC;AAE3E,MAAM,mBAAmB;IAAzB;QACkB,QAA2B,GAAG,SAAS,CAAC;QACvC,eAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;QACpE,mDAAmD;QACnC,gBAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC/D,wCAAwC;QACxB,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC5D,qFAAqF;QACrE,oBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;IA0Q9D,CAAC;IAxQS,UAAU,CAAI,GAAM,EAAE,YAAgC,EAAE,IAAY;QAC1E,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;gBACvB,OAAO;QACX,CAAC;aAAM,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;YACnC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;gBACnC,OAAO;QACX,CAAC;aAAM,IAAI,OAAO,GAAG,KA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AAC,YAAY,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;QACtC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAA,qBAAM,EAAC,SAAS,KAAK,OAAO,CAAC,CAAC;YAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAEO,eAAe,CAAC,IAA+C;QACrE,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,QAAQ,IAAI,EAAE,CAAC;YACb,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;QACrB,CAAC;IACH,CAAC;CACF;KAjRkB,mCAAyB;AAmR5C,SAAgB,wBAAwB;IACtC,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC;AAFD,4DAEC","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 { assert, BeEvent, JSONSchemaType, JSONSchemaTypeName, Mutable } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsFs } from \"../../IModelJsFs\";\r\nimport { SettingGroupSchema, SettingSchema, SettingsSchemas } from \"../../workspace/SettingsSchemas\";\r\nimport { _implementationProhibited } from \"../Symbols\";\r\n\r\nconst makeSettingKey = (prefix: string, key: string) => `${prefix}/${key}`;\r\n\r\nclass SettingsSchemasImpl implements SettingsSchemas {\r\n public readonly [_implementationProhibited] = undefined;\r\n private readonly _allGroups = new Map<string, SettingGroupSchema>();\r\n /** a map of all registered Setting Definitions */\r\n public readonly settingDefs = new Map<string, SettingSchema>();\r\n /** a map of all registered TypeDefs */\r\n public readonly typeDefs = new Map<string, SettingSchema>();\r\n /** event that signals that the values in [[allSchemas]] have changed in some way. */\r\n public readonly onSchemaChanged = new BeEvent<() => void>();\r\n\r\n private verifyType<T>(val: T, expectedType: JSONSchemaTypeName, path: string) {\r\n if (expectedType === \"integer\") {\r\n if (Number.isInteger(val))\r\n return;\r\n } else if (expectedType === \"null\") {\r\n if (val === null || val === undefined)\r\n return;\r\n } else if (typeof val === expectedType)\r\n return;\r\n\r\n throw new Error(`value for ${path}: \"${val}\" is wrong type, expected ${expectedType}`);\r\n }\r\n\r\n public validateSetting<T>(value: T, settingName: string): T {\r\n const settingDef = this.settingDefs.get(settingName);\r\n if (undefined !== settingDef) // if there's no setting definition, there's no rules so just return ok\r\n this.validateProperty(value, settingDef, settingName);\r\n return value;\r\n }\r\n\r\n /** @internal */\r\n public getObjectProperties(propDef: Readonly<SettingSchema>, scope: string): { required?: string[], properties: { [name: string]: SettingSchema } } {\r\n let required = propDef.required;\r\n let properties = propDef.properties;\r\n\r\n // if this object extends a typeDef, add typeDef's properties and required values, recursively\r\n if (propDef.extends !== undefined) {\r\n const typeDef = this.typeDefs.get(propDef.extends);\r\n if (undefined === typeDef)\r\n throw new Error(`typeDef ${propDef.extends} does not exist for ${scope}`);\r\n const expanded = this.getObjectProperties(typeDef, `${scope}.${propDef.extends}`);\r\n if (expanded.required)\r\n required = required ? [...required, ...expanded.required] : expanded.required;\r\n if (expanded.properties) {\r\n properties = properties ? { ...expanded.properties, ...properties } : expanded.properties;\r\n }\r\n }\r\n properties = properties ?? {};\r\n return { required, properties };\r\n }\r\n\r\n /** @internal */\r\n public getArrayItems(propDef: Readonly<SettingSchema>, scope: string): SettingSchema {\r\n let items = propDef.items;\r\n if (undefined === items && propDef.extends) {\r\n const typeDef = this.typeDefs.get(propDef.extends);\r\n if (undefined === typeDef)\r\n throw new Error(`typeDef ${propDef.extends} does not exist for ${scope}`);\r\n items = typeDef.items;\r\n }\r\n if (undefined === items)\r\n throw new Error(`array ${scope} has no items definition`);\r\n return items;\r\n }\r\n\r\n private validateProperty<T>(val: T, propDef: Readonly<SettingSchema>, path: string) {\r\n switch (propDef.type) {\r\n case \"boolean\":\r\n case \"number\":\r\n case \"string\":\r\n case \"integer\":\r\n case \"null\":\r\n return this.verifyType(val, propDef.type, path);\r\n\r\n case \"array\":\r\n if (!Array.isArray(val))\r\n throw new Error(`Property ${path} must be an array`);\r\n const items = this.getArrayItems(propDef, path);\r\n for (let i = 0; i < val.length; ++i)\r\n this.validateProperty(val[i], items, `${path}[${i}]`);\r\n return;\r\n }\r\n if (!val || typeof val !== \"object\")\r\n throw new Error(`${path} must be an object`);\r\n\r\n const { required, properties } = this.getObjectProperties(propDef, path);\r\n\r\n // first ensure all required properties are present\r\n if (undefined !== required) {\r\n for (const entry of required) {\r\n const value = (val as any)[entry];\r\n if (undefined === value)\r\n throw new Error(`required value for \"${entry}\" is missing in \"${path}\"`);\r\n }\r\n }\r\n\r\n // you can supply default values in typeDefs. See if any members are undefined that have a default.\r\n if (undefined !== properties) {\r\n for (const [key, prop] of Object.entries(properties)) {\r\n if ((val as any)[key] === undefined && prop.default)\r\n (val as any)[key] = prop.default;\r\n }\r\n }\r\n\r\n // then validate all values in the supplied object are valid\r\n for (const key of Object.keys(val)) {\r\n const prop = properties[key];\r\n if (prop !== undefined) { // note: extra values are ignored.\r\n this.validateProperty((val as any)[key], prop, `${path}.${key}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `schemaPrefix` 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 addGroup(settingsGroup: SettingGroupSchema | SettingGroupSchema[]): 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 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 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 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 schemaPrefix */\r\n public removeGroup(schemaPrefix: string): void {\r\n this.doRemove(schemaPrefix);\r\n this.onSchemaChanged.raiseEvent();\r\n }\r\n\r\n private doAdd(settingsGroup: SettingGroupSchema[]) {\r\n settingsGroup.forEach((group) => {\r\n if (undefined === group.schemaPrefix)\r\n throw new Error(`settings group has no \"schemaPrefix\" member`);\r\n\r\n this.doRemove(group.schemaPrefix);\r\n this.validateAndAdd(group);\r\n this._allGroups.set(group.schemaPrefix, group);\r\n });\r\n }\r\n\r\n private doRemove(schemaPrefix: string) {\r\n const group = this._allGroups.get(schemaPrefix);\r\n if (undefined !== group?.settingDefs) {\r\n for (const key of Object.keys(group.settingDefs))\r\n this.settingDefs.delete(makeSettingKey(schemaPrefix, key));\r\n }\r\n if (undefined !== group?.typeDefs) {\r\n for (const key of Object.keys(group.typeDefs))\r\n this.settingDefs.delete(makeSettingKey(schemaPrefix, key));\r\n }\r\n this._allGroups.delete(schemaPrefix);\r\n }\r\n\r\n private validateName(name: string) {\r\n if (!name.trim())\r\n throw new Error(`empty property name`);\r\n }\r\n\r\n private verifyPropertyDef(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 if (undefined === props[entry])\r\n throw new Error(`missing required property of ${name}: \"${entry}\"`);\r\n }\r\n }\r\n if (props) {\r\n for (const key of Object.keys(props))\r\n try {\r\n this.verifyPropertyDef(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.extends === \"string\")\r\n return;\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.verifyPropertyDef(\"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 validateAndAdd(group: SettingGroupSchema) {\r\n const settingDefs = group.settingDefs;\r\n if (undefined !== settingDefs) {\r\n for (const key of Object.keys(settingDefs)) {\r\n this.validateName(key);\r\n this.verifyPropertyDef(key, settingDefs[key]);\r\n const property: Mutable<SettingSchema> | undefined = settingDefs[key];\r\n assert(undefined !== property);\r\n property.default = property.default ?? this.getDefaultValue(property.type);\r\n this.settingDefs.set(makeSettingKey(group.schemaPrefix, key), property);\r\n }\r\n }\r\n const typeDefs = group.typeDefs ?? {};\r\n for (const key of Object.keys(typeDefs)) {\r\n this.validateName(key);\r\n this.verifyPropertyDef(key, typeDefs[key]);\r\n const typeDef = typeDefs[key];\r\n assert(undefined !== typeDef);\r\n this.typeDefs.set(makeSettingKey(group.schemaPrefix, key), typeDef);\r\n }\r\n }\r\n\r\n private 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\r\nexport function constructSettingsSchemas(): SettingsSchemas {\r\n return new SettingsSchemasImpl();\r\n}\r\n"]}
@@ -0,0 +1,41 @@
1
+ /** @packageDocumentation
2
+ * @module Workspace
3
+ */
4
+ import { FilePropertyProps } from "@itwin/core-common";
5
+ import { Settings } from "../../workspace/Settings";
6
+ import { Workspace, WorkspaceContainer, WorkspaceContainerId, WorkspaceDb, WorkspaceDbFullName, WorkspaceDbLoadError, WorkspaceDbName, WorkspaceDbProps, WorkspaceDbVersion, WorkspaceOpts } from "../../workspace/Workspace";
7
+ import { WorkspaceEditor } from "../../workspace/WorkspaceEditor";
8
+ /** file extension for local WorkspaceDbs */
9
+ export declare const workspaceDbFileExt = "itwin-workspace";
10
+ export declare function constructWorkspaceDb(props: WorkspaceDbProps, container: WorkspaceContainer): WorkspaceDb;
11
+ export declare function constructWorkspace(settings: Settings, opts?: WorkspaceOpts): OwnedWorkspace;
12
+ export declare function constructWorkspaceEditor(): WorkspaceEditor;
13
+ export declare function noLeadingOrTrailingSpaces(name: string, msg: string): void;
14
+ export declare function validateWorkspaceDbName(dbName: WorkspaceDbName): void;
15
+ /**
16
+ * Validate that a WorkspaceContainer.Id is valid.
17
+ * The rules for ContainerIds (from Azure, see https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata):
18
+ * - may only contain lower case letters, numbers or dashes
19
+ * - may not start or end with with a dash nor have more than one dash in a row
20
+ * - may not be shorter than 3 or longer than 63 characters
21
+ */
22
+ export declare function validateWorkspaceContainerId(id: WorkspaceContainerId): void;
23
+ export declare function validateWorkspaceDbVersion(version?: WorkspaceDbVersion): string;
24
+ /**
25
+ * Parse the name stored in a WorkspaceContainer into the dbName and version number. A single WorkspaceContainer may hold
26
+ * many versions of the same WorkspaceDb. The name of the Db in the WorkspaceContainer is in the format "name:version". This
27
+ * function splits them into separate strings.
28
+ */
29
+ export declare function parseWorkspaceDbFileName(dbFileName: WorkspaceDbFullName): {
30
+ dbName: WorkspaceDbName;
31
+ version: WorkspaceDbVersion;
32
+ };
33
+ /** Create a dbName for a WorkspaceDb from its base name and version. This will be in the format "name:version" */
34
+ export declare function makeWorkspaceDbFileName(dbName: WorkspaceDbName, version?: WorkspaceDbVersion): WorkspaceDbName;
35
+ export declare const workspaceManifestProperty: FilePropertyProps;
36
+ export declare function throwWorkspaceDbLoadErrors(msg: string, errors: WorkspaceDbLoadError[]): never;
37
+ export interface OwnedWorkspace extends Workspace {
38
+ /** Only the owner of a Workspace may close it. */
39
+ close(): void;
40
+ }
41
+ //# sourceMappingURL=WorkspaceImpl.d.ts.map
@@ -0,0 +1 @@
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