@itwin/core-backend 4.8.0-dev.3 → 4.8.0-dev.32
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.
- package/CHANGELOG.md +57 -1
- package/lib/cjs/BackendHubAccess.d.ts +18 -16
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js +16 -15
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +3 -1
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +2 -0
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/BlobContainerService.d.ts +3 -3
- package/lib/cjs/BlobContainerService.d.ts.map +1 -1
- package/lib/cjs/BlobContainerService.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +19 -11
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +0 -6
- package/lib/cjs/Category.d.ts.map +1 -1
- package/lib/cjs/Category.js +0 -6
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
- package/lib/cjs/ChangeSummaryManager.js +11 -9
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +1 -0
- package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
- package/lib/cjs/ChangedElementsDb.js +6 -4
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.js +26 -21
- package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
- package/lib/cjs/ChannelControl.d.ts +4 -26
- package/lib/cjs/ChannelControl.d.ts.map +1 -1
- package/lib/cjs/ChannelControl.js +2 -101
- package/lib/cjs/ChannelControl.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +5 -3
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +3 -2
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +49 -24
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +66 -7
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/CodeService.d.ts +4 -4
- package/lib/cjs/CodeService.d.ts.map +1 -1
- package/lib/cjs/CodeService.js.map +1 -1
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js +2 -1
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +0 -3
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +0 -3
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +6 -1
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +19 -14
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +2 -2
- package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
- package/lib/cjs/ECSqlStatement.d.ts +6 -3
- package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
- package/lib/cjs/ECSqlStatement.js +3 -3
- package/lib/cjs/ECSqlStatement.js.map +1 -1
- package/lib/cjs/Element.d.ts +3 -60
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +8 -64
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +0 -5
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +4 -8
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/ElementGraphics.d.ts.map +1 -1
- package/lib/cjs/ElementGraphics.js +2 -1
- package/lib/cjs/ElementGraphics.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +10 -0
- package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
- package/lib/cjs/GeoCoordConfig.js +22 -24
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/GeographicCRSServices.js +2 -2
- package/lib/cjs/GeographicCRSServices.js.map +1 -1
- package/lib/cjs/GeometrySummary.d.ts.map +1 -1
- package/lib/cjs/GeometrySummary.js +2 -1
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +33 -98
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +242 -156
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelElementCloneContext.js +5 -4
- package/lib/cjs/IModelElementCloneContext.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +13 -4
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +39 -32
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +15 -13
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LocalHub.d.ts +2 -2
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +17 -17
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/LockControl.d.ts +73 -0
- package/lib/cjs/LockControl.d.ts.map +1 -0
- package/lib/cjs/LockControl.js +11 -0
- package/lib/cjs/LockControl.js.map +1 -0
- package/lib/cjs/Material.d.ts +2 -5
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +6 -4
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +0 -22
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +5 -26
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +17 -7
- package/lib/cjs/PropertyStore.d.ts.map +1 -1
- package/lib/cjs/PropertyStore.js +11 -5
- package/lib/cjs/PropertyStore.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +0 -12
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +5 -16
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts +8 -4
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +25 -19
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/SchemaSync.d.ts +4 -1
- package/lib/cjs/SchemaSync.d.ts.map +1 -1
- package/lib/cjs/SchemaSync.js +24 -11
- package/lib/cjs/SchemaSync.js.map +1 -1
- package/lib/cjs/SchemaUtils.js +3 -3
- package/lib/cjs/SchemaUtils.js.map +1 -1
- package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
- package/lib/cjs/SqliteChangesetReader.js +2 -2
- package/lib/cjs/SqliteChangesetReader.js.map +1 -1
- package/lib/cjs/SqliteStatement.js +2 -2
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/TextAnnotationGeometry.d.ts +5 -1
- package/lib/cjs/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/cjs/TextAnnotationGeometry.js +11 -8
- package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
- package/lib/cjs/TextAnnotationLayout.d.ts +21 -13
- package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
- package/lib/cjs/TextAnnotationLayout.js +134 -92
- package/lib/cjs/TextAnnotationLayout.js.map +1 -1
- package/lib/cjs/TxnManager.d.ts +2 -1
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +4 -2
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +1 -18
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +1 -18
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStore.d.ts +16 -2
- package/lib/cjs/ViewStore.d.ts.map +1 -1
- package/lib/cjs/ViewStore.js +20 -6
- package/lib/cjs/ViewStore.js.map +1 -1
- package/lib/cjs/assets/Settings/Schemas/Base.Schema.json +33 -0
- package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +17 -21
- package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +80 -38
- package/lib/cjs/assets/Settings/backend.setting.json5 +8 -119
- package/lib/cjs/core-backend.d.ts +4 -2
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +5 -6
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +0 -10
- package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalElements.js +0 -10
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.js +2 -1
- package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
- package/lib/cjs/domains/GenericElements.d.ts +0 -18
- package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
- package/lib/cjs/domains/GenericElements.js +0 -18
- package/lib/cjs/domains/GenericElements.js.map +1 -1
- package/lib/cjs/internal/ChangesetConflictArgs.d.ts +24 -0
- package/lib/cjs/internal/ChangesetConflictArgs.d.ts.map +1 -0
- package/lib/cjs/internal/ChangesetConflictArgs.js +7 -0
- package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -0
- package/lib/cjs/internal/ChannelAdmin.d.ts +34 -0
- package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -0
- package/lib/cjs/internal/ChannelAdmin.js +117 -0
- package/lib/cjs/internal/ChannelAdmin.js.map +1 -0
- package/lib/cjs/internal/NativePlatform.d.ts +15 -0
- package/lib/cjs/internal/NativePlatform.d.ts.map +1 -0
- package/lib/cjs/internal/NativePlatform.js +49 -0
- package/lib/cjs/internal/NativePlatform.js.map +1 -0
- package/lib/cjs/internal/NoLocks.d.ts +6 -0
- package/lib/cjs/internal/NoLocks.d.ts.map +1 -0
- package/lib/cjs/internal/NoLocks.js +31 -0
- package/lib/cjs/internal/NoLocks.js.map +1 -0
- package/lib/cjs/{ServerBasedLocks.d.ts → internal/ServerBasedLocks.d.ts} +10 -16
- package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -0
- package/lib/cjs/{ServerBasedLocks.js → internal/ServerBasedLocks.js} +29 -18
- package/lib/cjs/internal/ServerBasedLocks.js.map +1 -0
- package/lib/cjs/internal/Symbols.d.ts +11 -0
- package/lib/cjs/internal/Symbols.d.ts.map +1 -0
- package/lib/cjs/internal/Symbols.js +21 -0
- package/lib/cjs/internal/Symbols.js.map +1 -0
- package/lib/cjs/internal/cross-package.d.ts +4 -0
- package/lib/cjs/internal/cross-package.d.ts.map +1 -0
- package/lib/cjs/internal/cross-package.js +16 -0
- package/lib/cjs/internal/cross-package.js.map +1 -0
- package/lib/cjs/internal/workspace/SettingsImpl.d.ts +43 -0
- package/lib/cjs/internal/workspace/SettingsImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/SettingsImpl.js +161 -0
- package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts +6 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +276 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts +41 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.js +696 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts +10 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js +42 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -0
- package/lib/cjs/rpc/tracing.d.ts.map +1 -1
- package/lib/cjs/rpc/tracing.js +5 -2
- package/lib/cjs/rpc/tracing.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -0
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +10 -6
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +5 -3
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts +167 -138
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +68 -138
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.d.ts +112 -48
- package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.js +1 -172
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +411 -277
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +76 -457
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/lib/cjs/workspace/WorkspaceEditor.d.ts +245 -0
- package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -0
- package/lib/cjs/workspace/WorkspaceEditor.js +34 -0
- package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -0
- package/package.json +15 -14
- package/lib/cjs/ServerBasedLocks.d.ts.map +0 -1
- package/lib/cjs/ServerBasedLocks.js.map +0 -1
- package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +0 -45
|
@@ -7,150 +7,80 @@
|
|
|
7
7
|
* @module Workspace
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function deepClone(obj) {
|
|
35
|
-
if (!obj || typeof obj !== "object")
|
|
36
|
-
return obj;
|
|
37
|
-
const result = Array.isArray(obj) ? [] : {};
|
|
38
|
-
Object.keys(obj).forEach((key) => {
|
|
39
|
-
const val = obj[key];
|
|
40
|
-
if (val && typeof val === "object") {
|
|
41
|
-
result[key] = deepClone(val);
|
|
10
|
+
exports.SettingsPriority = exports.Setting = void 0;
|
|
11
|
+
const Symbols_1 = require("../internal/Symbols");
|
|
12
|
+
/** @beta */
|
|
13
|
+
var Setting;
|
|
14
|
+
(function (Setting) {
|
|
15
|
+
/** Create a deep copy of a [[Setting]]. */
|
|
16
|
+
function clone(setting) {
|
|
17
|
+
if (!setting || typeof setting !== "object")
|
|
18
|
+
return setting;
|
|
19
|
+
const result = Array.isArray(setting) ? [] : {};
|
|
20
|
+
Object.keys(setting).forEach((key) => result[key] = clone(setting[key]));
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
Setting.clone = clone;
|
|
24
|
+
/** Returns true if `a` and `b` are considered equivalent [[Setting]] values.
|
|
25
|
+
* Settings of primitive types like `number` and `string` are compared using `===`.
|
|
26
|
+
* Settings of type "object" are compared by comparing each property using `areEqual`; the objects are considered
|
|
27
|
+
* equal if they have the exact same set of property names with equivalent values.
|
|
28
|
+
* Settings of type "array" are compared by comparing each element of the arrays use `areEqual`; the arrays are considered
|
|
29
|
+
* equal if they have the same number of elements with equivalent values in the same exact order.
|
|
30
|
+
*/
|
|
31
|
+
function areEqual(a, b) {
|
|
32
|
+
if (a === b) {
|
|
33
|
+
return true;
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
// For primitive types, === suffices.
|
|
36
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
37
|
+
return false;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class SettingsDictionary {
|
|
50
|
-
constructor(name, priority, settings) {
|
|
51
|
-
this.name = name;
|
|
52
|
-
this.priority = priority;
|
|
53
|
-
this.settings = settings;
|
|
54
|
-
}
|
|
55
|
-
getSetting(settingName) {
|
|
56
|
-
return this.settings[settingName];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Internal implementation of Settings interface.
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
class BaseSettings {
|
|
64
|
-
constructor() {
|
|
65
|
-
this._dictionaries = [];
|
|
66
|
-
this.onSettingsChanged = new core_bentley_1.BeEvent();
|
|
67
|
-
}
|
|
68
|
-
verifyPriority(_priority) { }
|
|
69
|
-
close() { }
|
|
70
|
-
addFile(fileName, priority) {
|
|
71
|
-
this.addJson(fileName, priority, fs.readFileSync(fileName, "utf-8"));
|
|
72
|
-
}
|
|
73
|
-
addDirectory(dirName, priority) {
|
|
74
|
-
for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
|
|
75
|
-
const ext = (0, path_1.extname)(fileName);
|
|
76
|
-
if (ext === ".json5" || ext === ".json")
|
|
77
|
-
this.addFile((0, path_1.join)(dirName, fileName), priority);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
addJson(dictionaryName, priority, settingsJson) {
|
|
81
|
-
this.addDictionary(dictionaryName, priority, (0, json5_1.parse)(settingsJson));
|
|
82
|
-
}
|
|
83
|
-
addDictionary(dictionaryName, priority, settings) {
|
|
84
|
-
this.verifyPriority(priority);
|
|
85
|
-
this.dropDictionary(dictionaryName, false); // make sure we don't have the same dictionary twice
|
|
86
|
-
const file = new SettingsDictionary(dictionaryName, priority, settings);
|
|
87
|
-
const doAdd = () => {
|
|
88
|
-
for (let i = 0; i < this._dictionaries.length; ++i) {
|
|
89
|
-
if (this._dictionaries[i].priority <= file.priority) {
|
|
90
|
-
this._dictionaries.splice(i, 0, file);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
39
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
40
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
|
41
|
+
return false;
|
|
93
42
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
dropDictionary(dictionaryName, raiseEvent = true) {
|
|
100
|
-
for (let i = 0; i < this._dictionaries.length; ++i) {
|
|
101
|
-
if (this._dictionaries[i].name === dictionaryName) {
|
|
102
|
-
this._dictionaries.splice(i, 1);
|
|
103
|
-
if (raiseEvent)
|
|
104
|
-
this.onSettingsChanged.raiseEvent();
|
|
105
|
-
return true;
|
|
43
|
+
for (let i = 0; i < a.length; i++) {
|
|
44
|
+
if (!areEqual(a[i], b[i])) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
106
47
|
}
|
|
48
|
+
return true;
|
|
107
49
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
50
|
+
const aKeys = Object.keys(a);
|
|
51
|
+
const bKeys = Object.keys(b);
|
|
52
|
+
if (aKeys.length !== bKeys.length) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
aKeys.sort();
|
|
56
|
+
bKeys.sort();
|
|
57
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
58
|
+
const key = aKeys[i];
|
|
59
|
+
if (key !== bKeys[i]) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (!areEqual(a[key], b[key])) {
|
|
63
|
+
return false;
|
|
116
64
|
}
|
|
117
65
|
}
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
getSetting(name, defaultValue) {
|
|
121
|
-
return this.resolveSetting(name, (val) => deepClone(val)) ?? defaultValue;
|
|
122
|
-
}
|
|
123
|
-
/** for debugging. Returns an array of all values for a setting, sorted by priority.
|
|
124
|
-
* @note values are not cloned. Do not modify objects or arrays.
|
|
125
|
-
*/
|
|
126
|
-
inspectSetting(name) {
|
|
127
|
-
const all = [];
|
|
128
|
-
this.resolveSetting(name, (value, dictionary, priority) => {
|
|
129
|
-
all.push({ value, dictionary, priority });
|
|
130
|
-
return undefined;
|
|
131
|
-
});
|
|
132
|
-
return all;
|
|
133
|
-
}
|
|
134
|
-
getString(name, defaultValue) {
|
|
135
|
-
const out = this.getSetting(name);
|
|
136
|
-
return typeof out === "string" ? out : defaultValue;
|
|
66
|
+
return true;
|
|
137
67
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
exports.
|
|
68
|
+
Setting.areEqual = areEqual;
|
|
69
|
+
})(Setting || (exports.Setting = Setting = {}));
|
|
70
|
+
/** @beta */
|
|
71
|
+
var SettingsPriority;
|
|
72
|
+
(function (SettingsPriority) {
|
|
73
|
+
/** Settings that originate from default setting files loaded automatically at the start of a session. */
|
|
74
|
+
SettingsPriority.defaults = 100;
|
|
75
|
+
/** Settings supplied by an application at runtime. */
|
|
76
|
+
SettingsPriority.application = 200;
|
|
77
|
+
/** Settings that apply to all iTwins for an organization. */
|
|
78
|
+
SettingsPriority.organization = 300;
|
|
79
|
+
/** Settings that apply to all iModels in an iTwin. */
|
|
80
|
+
SettingsPriority.iTwin = 400;
|
|
81
|
+
/** Settings that apply to all branches of an iModel. */
|
|
82
|
+
SettingsPriority.branch = 500;
|
|
83
|
+
/** Settings that apply to a specific iModel. */
|
|
84
|
+
SettingsPriority.iModel = 600;
|
|
85
|
+
})(SettingsPriority || (exports.SettingsPriority = SettingsPriority = {}));
|
|
156
86
|
//# sourceMappingURL=Settings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../../src/workspace/Settings.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAA8D;AAE9D,8CAA2C;AAmD3C;;;EAGE;AACF,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IAC1B,6CAA6C;IAC7C,iEAAc,CAAA;IACd,iDAAiD;IACjD,uEAAiB,CAAA;IACjB,2DAA2D;IAC3D,yEAAkB,CAAA;IAClB,oDAAoD;IACpD,2DAAW,CAAA;IACX,4CAA4C;IAC5C,6DAAY,CAAA;AACd,CAAC,EAXW,gBAAgB,gCAAhB,gBAAgB,QAW3B;AAyGD,gBAAgB;AAChB,SAAS,SAAS,CAAwB,GAAQ;IAChD,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QACjC,OAAO,GAAG,CAAC;IAEb,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAS,CAAC;IACnD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OA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AC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IAIM,SAAS,CAAC,IAAiB,EAAE,YAAqB;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAS,IAAI,CAAC,CAAC;QAC1C,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACtD,CAAC;IAGM,UAAU,CAAC,IAAiB,EAAE,YAAsB;QACzD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAU,IAAI,CAAC,CAAC;QAC3C,OAAO,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACvD,CAAC;IAGM,SAAS,CAAC,IAAiB,EAAE,YAAqB;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAS,IAAI,CAAC,CAAC;QAC1C,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACtD,CAAC;IAGM,SAAS,CAAmB,IAAiB,EAAE,YAAgB;QACpE,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAgB,IAAI,CAAC,CAAC;QACjD,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAQ,CAAC,CAAC,CAAC,YAAY,CAAC;IAC3D,CAAC;IAGM,QAAQ,CAAwB,IAAiB,EAAE,YAAuB;QAC/E,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAW,IAAI,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACjD,CAAC;CACF;AA7GD,oCA6GC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Workspace\r\n */\r\n\r\nimport * as fs from \"fs-extra\";\r\nimport { parse } from \"json5\";\r\nimport { extname, join } from \"path\";\r\nimport { BeEvent, JSONSchemaType } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\n/** The type of a Setting, according to its schema\r\n * @beta\r\n */\r\nexport type SettingType = JSONSchemaType;\r\n\r\n/**\r\n * The name of a Setting. SettingNames must be valid JavaScript property names, defined in a [[SettingSchema]].\r\n * @see [SettingName]($docs/learning/backend/Workspace#settingnames)\r\n * @beta\r\n */\r\nexport type SettingName = string;\r\n\r\n/** The name of a [[SettingDictionary]]. `SettingDictionary`s are stored in [[Settings]] and may be removed by DictionaryName.\r\n * DictionaryNames must be valid JavaScript property names.\r\n * @beta\r\n */\r\nexport type DictionaryName = string;\r\n\r\n/**\r\n * A function called by [[Settings.resolveSetting]] for every SettingDictionary with a Setting that matches a name. The\r\n * SettingDictionaries are sorted by priority and this function is called in priority order with the highest priority first.\r\n * When this function returns a non-undefined value, the iteration is stopped and that value is returned. In this way,\r\n * applications can \"combine\" the prioritized Setting values as appropriate. The default implementation of this function\r\n * used by [[Settings.getSetting]] merely returns a clone of the value the first time it is called, so the highest priority\r\n * value is returned.\r\n * @beta\r\n */\r\nexport type SettingResolver<T> = (val: T, dict: DictionaryName, priority: SettingsPriority) => T | undefined;\r\n\r\n/** An entry in the array returned by [[Settings.inspectSetting]]\r\n * @beta\r\n *\r\n */\r\nexport interface SettingInspector<T> { value: T, dictionary: DictionaryName, priority: number }\r\n\r\n/** An object with string-named members (as opposed to an array object).\r\n * @beta\r\n */\r\nexport interface SettingObject {\r\n [name: string]: SettingType;\r\n}\r\n\r\n/**\r\n * An object with Settings as its members. A SettingDictionary also has a name and generally comes from a parsed JSON file, but\r\n * may also be created in memory by applications\r\n * @beta\r\n */\r\nexport type SettingDictionary = SettingObject;\r\n\r\n/**\r\n * Values for SettingsPriority determine the sort order for Settings. Higher values take precedence over lower values.\r\n * @beta\r\n*/\r\nexport enum SettingsPriority {\r\n /** values supplied default-settings files */\r\n defaults = 100,\r\n /** values supplied by applications at runtime */\r\n application = 200,\r\n /** values that apply to all iTwins for an organization. */\r\n organization = 300,\r\n /** values that apply to all iModels in an iTwin. */\r\n iTwin = 400,\r\n /** values that apply to a single iModel. */\r\n iModel = 500,\r\n}\r\n\r\n/** The current set of Settings for a Workspace.\r\n * @beta\r\n */\r\nexport interface Settings {\r\n /** @internal */\r\n close(): void;\r\n\r\n /** Event raised whenever a SettingsDictionary is added or removed. */\r\n readonly onSettingsChanged: BeEvent<() => void>;\r\n\r\n /** Add a SettingDictionary from a local settings file. The file should be in [JSON5](https://json5.org/) format. It is read\r\n * and parsed and the fileName is used as the DictionaryName.\r\n * @param fileName the name of a local settings file of the SettingDictionary. This becomes the DictionaryName.\r\n * @param priority the SettingsPriority for the SettingDictionary\r\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\r\n */\r\n addFile(fileName: LocalFileName, priority: SettingsPriority): void;\r\n\r\n /** Add all files in the supplied directory with the extension \".json\" or \".json5\"\r\n * @param dirName the name of a local settings directory\r\n */\r\n addDirectory(dirName: LocalDirName, priority: SettingsPriority): void;\r\n\r\n /** Add a SettingDictionary from a JSON5 stringified string. The string is parsed and the resultant object is added as a SettingDictionary.\r\n * @param dictionaryName the name of the SettingDictionary\r\n * @param priority the SettingsPriority for the SettingDictionary\r\n * @param settingsJson the JSON5 stringified string to be parsed.\r\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\r\n */\r\n addJson(dictionaryName: DictionaryName, priority: SettingsPriority, settingsJson: string): void;\r\n\r\n /** Add a SettingDictionary object.\r\n * @param dictionaryName the name of the SettingDictionary\r\n * @param priority the SettingsPriority for the SettingDictionary\r\n * @param settings the SettingDictionary object to be added.\r\n * @note If the SettingDictionary was previously added, the new content overrides the old content.\r\n */\r\n addDictionary(dictionaryName: DictionaryName, priority: SettingsPriority, settings: SettingDictionary): void;\r\n\r\n /** Remove a SettingDictionary by name. */\r\n dropDictionary(dictionaryName: DictionaryName): void;\r\n\r\n /**\r\n * Resolve a setting, by name, using a SettingResolver.\r\n * @param settingName The name of the setting to resolve\r\n * @param resolver function to be called for each SettingDictionary with a matching Setting. Iteration stops when it returns a non-undefined value.\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary or resolver never returned a value.\r\n * @returns the resolved setting value.\r\n */\r\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue: T): T;\r\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue?: T): T | undefined;\r\n\r\n /** Get the highest priority setting for a SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary.\r\n * @note This method is generic on SettingType, but no type checking is actually performed at run time. So, if you\r\n * use this method to get a setting with an expected type, but its value is a different type, the return type of this method will be wrong.\r\n * You must always type check the result. Use the non-generic \"get\" methods (e.g. [[getString]]) if you only want the value\r\n * if its type is correct.\r\n */\r\n getSetting<T extends SettingType>(settingName: SettingName, defaultValue?: T): T | undefined;\r\n\r\n /** Get a string setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a string.\r\n */\r\n getString(settingName: SettingName, defaultValue: string): string;\r\n getString(settingName: SettingName, defaultValue?: string): string | undefined;\r\n\r\n /** Get a boolean setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a boolean.\r\n */\r\n getBoolean(settingName: SettingName, defaultValue: boolean): boolean;\r\n getBoolean(settingName: SettingName, defaultValue?: boolean): boolean | undefined;\r\n\r\n /** Get a number setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not a number.\r\n */\r\n getNumber(settingName: SettingName, defaultValue: number): number;\r\n getNumber(settingName: SettingName): number | undefined;\r\n\r\n /** Get an object setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not an object.\r\n */\r\n getObject<T extends object>(settingName: SettingName, defaultValue: T): T;\r\n getObject<T extends object>(settingName: SettingName): T | undefined;\r\n\r\n /** Get an array setting by SettingName.\r\n * @param settingName The name of the setting\r\n * @param defaultValue value returned if settingName is not present in any SettingDictionary, or if the highest priority setting is not an array.\r\n */\r\n getArray<T extends SettingType>(settingName: SettingName, defaultValue: Array<T>): Array<T>;\r\n getArray<T extends SettingType>(settingName: SettingName): Array<T> | undefined;\r\n\r\n /** Get an array of [[SettingInspector] objects, sorted in priority order, for all Settings that match a SettingName.\r\n * @note this method is mainly for debugging and diagnostics.\r\n */\r\n inspectSetting<T extends SettingType>(name: SettingName): SettingInspector<T>[];\r\n}\r\n\r\n/** @internal */\r\nfunction deepClone<T extends SettingType>(obj: any): T {\r\n if (!obj || typeof obj !== \"object\")\r\n return obj;\r\n\r\n const result = Array.isArray(obj) ? [] : {} as any;\r\n Object.keys(obj).forEach((key: string) => {\r\n const val = obj[key];\r\n if (val && typeof val === \"object\") {\r\n result[key] = deepClone(val);\r\n } else {\r\n result[key] = val;\r\n }\r\n });\r\n return result;\r\n}\r\n\r\nclass SettingsDictionary {\r\n public constructor(public readonly name: string, public readonly priority: SettingsPriority, public readonly settings: SettingDictionary) { }\r\n public getSetting<T extends SettingType>(settingName: string): SettingType | undefined {\r\n return this.settings[settingName] as T | undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Internal implementation of Settings interface.\r\n * @internal\r\n */\r\nexport class BaseSettings implements Settings {\r\n private _dictionaries: SettingsDictionary[] = [];\r\n protected verifyPriority(_priority: SettingsPriority) { }\r\n public close() { }\r\n public readonly onSettingsChanged = new BeEvent<() => void>();\r\n\r\n public addFile(fileName: LocalFileName, priority: SettingsPriority) {\r\n this.addJson(fileName, priority, fs.readFileSync(fileName, \"utf-8\"));\r\n }\r\n\r\n public addDirectory(dirName: LocalDirName, priority: SettingsPriority) {\r\n for (const fileName of IModelJsFs.readdirSync(dirName)) {\r\n const ext = extname(fileName);\r\n if (ext === \".json5\" || ext === \".json\")\r\n this.addFile(join(dirName, fileName), priority);\r\n }\r\n }\r\n\r\n public addJson(dictionaryName: string, priority: SettingsPriority, settingsJson: string) {\r\n this.addDictionary(dictionaryName, priority, parse(settingsJson));\r\n }\r\n\r\n public addDictionary(dictionaryName: string, priority: SettingsPriority, settings: SettingDictionary) {\r\n this.verifyPriority(priority);\r\n this.dropDictionary(dictionaryName, false); // make sure we don't have the same dictionary twice\r\n const file = new SettingsDictionary(dictionaryName, priority, settings);\r\n const doAdd = () => {\r\n for (let i = 0; i < this._dictionaries.length; ++i) {\r\n if (this._dictionaries[i].priority <= file.priority) {\r\n this._dictionaries.splice(i, 0, file);\r\n return;\r\n }\r\n }\r\n this._dictionaries.push(file);\r\n };\r\n doAdd();\r\n this.onSettingsChanged.raiseEvent();\r\n }\r\n\r\n public dropDictionary(dictionaryName: DictionaryName, raiseEvent = true) {\r\n for (let i = 0; i < this._dictionaries.length; ++i) {\r\n if (this._dictionaries[i].name === dictionaryName) {\r\n this._dictionaries.splice(i, 1);\r\n if (raiseEvent)\r\n this.onSettingsChanged.raiseEvent();\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public resolveSetting<T extends SettingType>(name: SettingName, resolver: SettingResolver<T>, defaultValue?: T): T | undefined {\r\n for (const dict of this._dictionaries) {\r\n const val = dict.getSetting(name) as T | undefined;\r\n const resolved = val && resolver(val, dict.name, dict.priority);\r\n if (undefined !== resolved) {\r\n return resolved;\r\n }\r\n }\r\n return defaultValue;\r\n }\r\n\r\n public getSetting<T extends SettingType>(name: SettingName, defaultValue?: T): T | undefined {\r\n return this.resolveSetting(name, (val) => deepClone<T>(val)) ?? defaultValue;\r\n }\r\n\r\n /** for debugging. Returns an array of all values for a setting, sorted by priority.\r\n * @note values are not cloned. Do not modify objects or arrays.\r\n */\r\n public inspectSetting<T extends SettingType>(name: SettingName): SettingInspector<T>[] {\r\n const all: SettingInspector<T>[] = [];\r\n this.resolveSetting<T>(name, (value, dictionary, priority) => {\r\n all.push({ value, dictionary, priority });\r\n return undefined;\r\n });\r\n\r\n return all;\r\n }\r\n\r\n public getString(name: SettingName, defaultValue: string): string;\r\n public getString(name: SettingName): string | undefined;\r\n public getString(name: SettingName, defaultValue?: string): string | undefined {\r\n const out = this.getSetting<string>(name);\r\n return typeof out === \"string\" ? out : defaultValue;\r\n }\r\n public getBoolean(name: SettingName, defaultValue: boolean): boolean;\r\n public getBoolean(name: SettingName): boolean | undefined;\r\n public getBoolean(name: SettingName, defaultValue?: boolean): boolean | undefined {\r\n const out = this.getSetting<boolean>(name);\r\n return typeof out === \"boolean\" ? out : defaultValue;\r\n }\r\n public getNumber(name: SettingName, defaultValue: number): number;\r\n public getNumber(name: SettingName): number | undefined;\r\n public getNumber(name: SettingName, defaultValue?: number): number | undefined {\r\n const out = this.getSetting<number>(name);\r\n return typeof out === \"number\" ? out : defaultValue;\r\n }\r\n public getObject<T extends object>(name: SettingName, defaultValue: T): T;\r\n public getObject<T extends object>(name: SettingName): T | undefined;\r\n public getObject<T extends object>(name: SettingName, defaultValue?: T): T | undefined {\r\n const out = this.getSetting<SettingObject>(name);\r\n return typeof out === \"object\" ? out as T : defaultValue;\r\n }\r\n public getArray<T extends SettingType>(name: SettingName, defaultValue: Array<T>): Array<T>;\r\n public getArray<T extends SettingType>(name: SettingName): Array<T> | undefined;\r\n public getArray<T extends SettingType>(name: SettingName, defaultValue?: Array<T>): Array<T> | undefined {\r\n const out = this.getSetting<Array<T>>(name);\r\n return Array.isArray(out) ? out : defaultValue;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../../src/workspace/Settings.ts"],"names":[],"mappings":";AAAA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AC;IAChC,sDAAsD;IACzC,sBAAK,GAAG,GAAG,CAAC;IACzB,wDAAwD;IAC3C,uBAAM,GAAG,GAAG,CAAC;IAC1B,gDAAgD;IACnC,uBAAM,GAAG,GAAG,CAAC;AAC5B,CAAC,EAbgB,gBAAgB,gCAAhB,gBAAgB,QAahC","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 { BeEvent, JSONSchemaType } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { WorkspaceDb } from \"./Workspace\";\r\nimport { _implementationProhibited } from \"../internal/Symbols\";\r\n\r\n/** The value of a single named parameter within a [[Workspace.settings]] that configures some aspect of the applications run-time behavior.\r\n * Settings are stored in a [[SettingsDictionary]]. A setting is described by its [[SettingSchema]].\r\n * @beta\r\n */\r\nexport type Setting = JSONSchemaType;\r\n\r\n/** @beta */\r\nexport namespace Setting { // eslint-disable-line @typescript-eslint/no-redeclare\r\n /** Create a deep copy of a [[Setting]]. */\r\n export function clone<T extends Setting>(setting: T): T {\r\n if (!setting || typeof setting !== \"object\")\r\n return setting;\r\n\r\n const result = Array.isArray(setting) ? [] : {} as any;\r\n Object.keys(setting).forEach((key: string) => result[key] = clone((setting as any)[key]));\r\n return result;\r\n }\r\n\r\n /** Returns true if `a` and `b` are considered equivalent [[Setting]] values.\r\n * Settings of primitive types like `number` and `string` are compared using `===`.\r\n * Settings of type \"object\" are compared by comparing each property using `areEqual`; the objects are considered\r\n * equal if they have the exact same set of property names with equivalent values.\r\n * Settings of type \"array\" are compared by comparing each element of the arrays use `areEqual`; the arrays are considered\r\n * equal if they have the same number of elements with equivalent values in the same exact order.\r\n */\r\n export function areEqual(a: Setting | undefined, b: Setting | undefined): boolean {\r\n if (a === b) {\r\n return true;\r\n }\r\n\r\n // For primitive types, === suffices.\r\n if (typeof a !== \"object\" || typeof b !== \"object\") {\r\n return false;\r\n }\r\n\r\n if (Array.isArray(a) || Array.isArray(b)) {\r\n if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {\r\n return false;\r\n }\r\n\r\n for (let i = 0; i < a.length; i++) {\r\n if (!areEqual(a[i], b[i])) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n const aKeys = Object.keys(a);\r\n const bKeys = Object.keys(b);\r\n if (aKeys.length !== bKeys.length) {\r\n return false;\r\n }\r\n\r\n aKeys.sort();\r\n bKeys.sort();\r\n for (let i = 0; i < aKeys.length; i++) {\r\n const key = aKeys[i];\r\n if (key !== bKeys[i]) {\r\n return false;\r\n }\r\n\r\n if (!areEqual((a as SettingsContainer)[key], (b as SettingsContainer)[key])) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * The name of a [[Setting]].\r\n * Setting names must be [valid JavaScript property names](https://developer.mozilla.org/en-US/docs/Glossary/property/JavaScript) containing no spaces or periods.\r\n * The name of a setting begins with the schema prefix of the [[SettingGroupSchema]] in which its [[SettingSchema]] is defined.\r\n * A setting name therefore forms a path like file names in a file system.\r\n * For example, the following are setting names defined in the `energyAnalysis`, `iot-scan-visualization`, and `vibration-map` schemas.\r\n *\r\n * ```ts\r\n * \"energyAnalysis/formats/totalWork\"\r\n * \"energyAnalysis/formats/totalHours\"\r\n * \"energyAnalysis/units/power\"\r\n * \"energyAnalysis/units/temperature\"\r\n * \"energyAnalysis/startupMode\"\r\n * \"iot-scan-visualization/ports/cameras\"\r\n * \"vibration-map/filters/scope\"\r\n * \"vibration-map/filters/prefabricated\"\r\n * ```\r\n *\r\n * @beta\r\n */\r\nexport type SettingName = string;\r\n\r\n/** An object that defines the values for any number of [[Setting]]s. Each of its properties' names must conform to the semantics of a [[SettingName]].\r\n * @beta\r\n */\r\nexport interface SettingsContainer {\r\n /** Accesses settings by their names. */\r\n [name: SettingName]: Setting | undefined;\r\n}\r\n\r\n/** Defines the precedence of a [[SettingsDictionary]].\r\n * [[Settings]] may contain multiple dictionaries containing different values for the same [[SettingName]].\r\n * When resolving the value of a [[Setting]], the value from the highest-priority dictionary is used.\r\n * Priorities are grouped into coarse categories like [[SettingsPriority.application]] and [[SettingsPriority.iModel]].\r\n * Settings with priorities less than or equal to [[SettingsPriority.application]] are stored in [[IModelHost.appWorkspace]], while\r\n * those with priorities higher than [[SettingsPriority.application]] are stored inside [[IModelDb.workspace]].\r\n * @beta\r\n */\r\nexport type SettingsPriority = number;\r\n\r\n/** @beta */\r\nexport namespace SettingsPriority { // eslint-disable-line @typescript-eslint/no-redeclare\r\n /** Settings that originate from default setting files loaded automatically at the start of a session. */\r\n export const defaults = 100;\r\n /** Settings supplied by an application at runtime. */\r\n export const application = 200;\r\n /** Settings that apply to all iTwins for an organization. */\r\n export const organization = 300;\r\n /** Settings that apply to all iModels in an iTwin. */\r\n export const iTwin = 400;\r\n /** Settings that apply to all branches of an iModel. */\r\n export const branch = 500;\r\n /** Settings that apply to a specific iModel. */\r\n export const iModel = 600;\r\n}\r\n\r\n/** A named container that supplies values for [[Setting]]s.\r\n * @see [[Settings.addDictionary]] to register a new settings dictionary.\r\n * @beta\r\n */\r\nexport interface SettingsDictionary {\r\n /** @internal */\r\n [_implementationProhibited]: unknown;\r\n\r\n /** Metadata describing the dictionary. */\r\n readonly props: SettingsDictionaryProps;\r\n\r\n /** Obtain a copy of the value of the setting named `settingName` stored in this dictionary, or `undefined` if no such setting exists.\r\n * The returned value is always cloned using [[Setting.clone]].\r\n * @note Generally, applications use methods like [[Settings.getString]] and [[Setting.getArray]] to resolve a setting value from multiple\r\n * dictionaries. Those methods - unlike this one - also validate that `settingName` is of type `T` as defined by its [[SettingSchema]].\r\n */\r\n getSetting<T extends Setting>(settingName: SettingName): T | undefined;\r\n}\r\n\r\n/** Uniquely identifies a [[SettingsDictionary]].\r\n * @beta\r\n */\r\nexport interface SettingsDictionarySource {\r\n /** The name of the dictionary, which must be unique within its [[workspaceDb]], or - if [[workspaceDb]] is undefined - unique among all dictionaries not associated with any [[WorkspaceDb]]. */\r\n readonly name: string;\r\n /** The [[WorkspaceDb]] from which the dictionary originated. */\r\n readonly workspaceDb?: WorkspaceDb;\r\n}\r\n\r\n/** Properties of a [[SettingsDictionary]], defining its name, the [[WorkspaceDb]] (if any) from which it originated, and its [[priority]] relative to other dictionaries.\r\n * @beta\r\n */\r\nexport interface SettingsDictionaryProps extends SettingsDictionarySource {\r\n /** Precedence value determining which setting value to use when multiple dictionaries supply values for the same [[SettingName]]. */\r\n readonly priority: SettingsPriority;\r\n}\r\n\r\n/**\r\n * The collection of [[Setting]]s that supply the run-time configuration of a [[Workspace]].\r\n * The `Settings` object comprises a collection of named [[SettingsDictionary]] objects.\r\n * Methods like [[getSetting]], [[getString]], and [[getArray]] provide access to the value of an individual [[Setting]] by searching\r\n * the [[dictionaries]] in order by their [[SettingsPriority]] to find the highest-priority setting with the requested [[SettingName]].\r\n * Most methods that retrieve [[Setting]] values validate them against their [[SettingSchema]]s to ensure that they are of the correct type.\r\n * A [[SettingsDictionary]] can be added or removed using [[addDictionary]] and [[dropDictionary]].\r\n * Because [[Setting]]s can change at any time during the session, you should avoid caching their values wherever possible.\r\n * If you must cache them (for example, to display in a user interface), you should listen for the [[onSettingsChanged]] event to be\r\n * notified of potential changes.\r\n *\r\n * Settings are accessed via [[Workspace.settings]]. They are defined at the application level by [[IModelHost.appWorkspace]], but individual iModels may supply\r\n * additional iModel-specific settings or overrides for application-level settings. When working in the context of a specific iModel, use [[IModelDb.workspace]]'s `settings`\r\n * property. Any settings not overridden by the iModel will fall back to the settings defined in [[IModelHost.appWorkspace]].\r\n *\r\n * Application settings are loaded into [[IModelHost.appWorkspace]] when the session begins (i.e., when [[IModelHost.startup]] is invoked), and unloaded when it ends (in [[IModelHost.shutdown]]).\r\n * They are read from [JSON5](https://json5.org/) files delivered with the application. The application should register any additional [[SettingsDictionary]]'s '(and their corresponding\r\n * [[SettingGroupSchema]]s) at this time.\r\n *\r\n * iModel-specific settings are stored in the iModel's property table and loaded into [[IModelDb.workspace]] when the iModel is first opened.\r\n * You can add and remove a [[SettingsDictionary]] from the property table using [[IModelDb.saveSettingDictionary]] and [[IModelDb.deleteSettingDictionary]].\r\n *\r\n * See the [learning article]($docs/learning/backend/Workspace) for a detailed overiew and examples.\r\n *\r\n * @see [[IModelHost.appWorkspace]] application-wide settings, and [[IModelDb.workspace]] for settings specific to a given iModel.\r\n * @beta\r\n */\r\nexport interface Settings {\r\n /** @internal */\r\n [_implementationProhibited]: unknown;\r\n\r\n /** @internal */\r\n close(): void;\r\n\r\n /** The set of settings dictionaries from which [[Setting]] values are obtained, sorted by [[SettingsPriority]].\r\n * The set can contain at most one dictionary for each unique combination of name and [[WorkspaceDb]].\r\n * @see [[addDictionary]], [[addFile]], [[addJson]], and [[addDirectory]] to add a new dictionary.\r\n * @see [[dropDictionary]] to remove a dictionary.\r\n * @see [[getDictionary]] to look up a dictionary.\r\n */\r\n readonly dictionaries: readonly SettingsDictionary[];\r\n\r\n /** Event raised whenever a [[SettingsDictionary]] is added or removed. */\r\n readonly onSettingsChanged: BeEvent<() => void>;\r\n\r\n /** Parses the contents of a local [JSON5](https://json5.org/) file as a [[SettingsContainer]] and invokes [[addDictionary]] to\r\n * add a [[SettingsDictionary]] named `fileName` with the specified priority.\r\n * @param fileName the name of a local settings file containing the dictionary.\r\n * @param priority the priority for the dictionary.\r\n */\r\n addFile(fileName: LocalFileName, priority: SettingsPriority): void;\r\n\r\n /** Invokes [[addFile]] for all files in `directory` with the extension \".json\" or \".json5\". */\r\n addDirectory(directory: LocalDirName, priority: SettingsPriority): void;\r\n\r\n /** Parses `settingsJson` as a [[SettingsContainer]] and invokes [[addDictionary]] to add a [[SettingsDictionary]] with the specified `props`.\r\n * This is typically used when reading dictionaries out of a [[WorkspaceDb]], where they are stored as stringified JSON.\r\n */\r\n addJson(props: SettingsDictionaryProps, settingsJson: string): void;\r\n\r\n /** Find a [[SettingsDictionary]] with the same name and [[WorkspaceDb]] as `source`. */\r\n getDictionary(source: SettingsDictionarySource): SettingsDictionary | undefined;\r\n\r\n /** Add a new [[SettingsDictionary]] with the priority, name, and [[WorkspaceDb]] specified by `props` and setting values supplied by `settings`.\r\n * @note If a dictionary with the same name and [[WorkspaceDb]] already exists, it will be replaced.\r\n * @see [[addFile]], [[addJson]], and [[addDirectory]] for convenient ways to add dictionaries from various sources.\r\n */\r\n addDictionary(props: SettingsDictionaryProps, settings: SettingsContainer): void;\r\n\r\n /** Removes a previously-added [[SettingsDictionary]]. */\r\n dropDictionary(props: SettingsDictionarySource): void;\r\n\r\n /** Looks up the highest priority setting value for a SettingName, falling back to a default value if no value for the setting is found.\r\n * The [[dictionaries]] are searched in order by [[SettingsPriority]]; the first one that provides a value for `settingName` wins.\r\n * @param settingName The name of the setting.\r\n * @param defaultValue value returned if settingName is not present in any [[SettingsDictionary]].\r\n * @note This method is generic on [[Setting]] type, but no type checking is actually performed at run time. So, if you\r\n * use this method to get a setting with an expected type, but its value is a different type, the return type of this method will be wrong.\r\n * You must always type check the result. Use the non-generic \"get\" methods like [[getString]] and [[getArray]] if you only want the value\r\n * if its type is correct.\r\n * @note Unlike [[getArray]], this method does not combine arrays - it ignores [[SettingsSchema.combineArrays]].\r\n */\r\n getSetting<T extends Setting>(settingName: SettingName, defaultValue?: T): T | undefined;\r\n\r\n /** Obtain an iterator over all of the values in the [[dictionaries]] for the [[Setting]] identified by `settingName`, ordered by [[SettingsPriority]]. */\r\n getSettingEntries<T extends Setting>(settingName: SettingName): Iterable<{ value: T, dictionary: SettingsDictionary}>;\r\n\r\n /** Obtain an iterator over all of the values in the [[dictionaries]] for the [[Setting]] identified by `settingName`, ordered by [[SettingsPriority]]. */\r\n getSettingValues<T extends Setting>(settingName: SettingName): Iterable<T>;\r\n\r\n /** Look up the value of a string [[Setting]] named `settingName`, returning `defaultValue` if no such value is defined.\r\n * @throws Error if the setting exists but is not a string.\r\n */\r\n getString(settingName: SettingName, defaultValue: string): string;\r\n getString(settingName: SettingName, defaultValue?: string): string | undefined;\r\n\r\n /** Look up the value of a boolean [[Setting]] named `settingName`, returning `defaultValue` if no such value is defined.\r\n * @throws Error if the setting exists but is not a boolean.\r\n */\r\n getBoolean(settingName: SettingName, defaultValue: boolean): boolean;\r\n getBoolean(settingName: SettingName, defaultValue?: boolean): boolean | undefined;\r\n\r\n /** Look up the value of a numeric [[Setting]] named `settingName`, returning `defaultValue` if no such value is defined.\r\n * @throws Error if the setting exists but is not a number.\r\n */\r\n getNumber(settingName: SettingName, defaultValue: number): number;\r\n getNumber(settingName: SettingName): number | undefined;\r\n\r\n /** Look up the value of an object [[Setting]] named `settingName`, returning `defaultValue` if no such value is defined.\r\n * @throws Error if the setting exists but is not an object.\r\n */\r\n getObject<T extends object>(settingName: SettingName, defaultValue: T): T;\r\n getObject<T extends object>(settingName: SettingName): T | undefined;\r\n\r\n /** Look up the value of an array [[Setting]] named `settingName`, returning `defaultValue` if no such value is defined.\r\n * @throws Error if the setting exists but is not an array.\r\n */\r\n getArray<T extends Setting>(settingName: SettingName, defaultValue: Array<T>): Array<T>;\r\n getArray<T extends Setting>(settingName: SettingName): Array<T> | undefined;\r\n}\r\n"]}
|
|
@@ -3,69 +3,133 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BeEvent, JSONSchema, JSONSchemaTypeName } from "@itwin/core-bentley";
|
|
5
5
|
import { LocalDirName, LocalFileName } from "@itwin/core-common";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { _implementationProhibited } from "../internal/Symbols";
|
|
7
|
+
import { SettingName } from "./Settings";
|
|
8
|
+
/** Metadata describing a single [[Setting]] as part of a [[SettingGroupSchema]].
|
|
9
|
+
* Every setting has a [[type]], which can be one of the following:
|
|
10
|
+
* - A primitive type like `string` or `number`;
|
|
11
|
+
* - An object containing any number of named properties, each with their own types; or
|
|
12
|
+
* - An array of elements, all of the same type.
|
|
13
|
+
* This metadata is used to validate setting values against the schema, and to enable user interfaces by which
|
|
14
|
+
* users can view and modify their settings.
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
13
17
|
export interface SettingSchema extends Readonly<JSONSchema> {
|
|
18
|
+
/** For arrays only, the metadata describing every element in the array. */
|
|
14
19
|
readonly items?: SettingSchema;
|
|
20
|
+
/** The name of the [[Setting]]'s data type. */
|
|
15
21
|
readonly type: JSONSchemaTypeName;
|
|
22
|
+
/** For objects and arrays only, the name of a [[SettingSchema]] that provides a base definition for this type.
|
|
23
|
+
* The name is expected to refer to a type definition registered with [[SettingsSchema.typeDefs]].
|
|
24
|
+
* Therefore, it must be the full name, including the [[SettingGroupSchema.schemaPrefix]].
|
|
25
|
+
*/
|
|
26
|
+
readonly extends?: string;
|
|
27
|
+
/** For objects only, the name and metadata of each of the object's properties. */
|
|
16
28
|
readonly properties?: {
|
|
17
|
-
[name:
|
|
29
|
+
[name: SettingName]: SettingSchema;
|
|
18
30
|
};
|
|
19
|
-
/**
|
|
20
|
-
|
|
31
|
+
/** For arrays only, specifies how [[SettingsDictionary.getArray]] resolves the value of the setting.
|
|
32
|
+
* By default, like other types of settings, the setting uses the value of the setting from the highest-priority dictionary.
|
|
33
|
+
* If `combineArray` is `true`, then the value of the setting is computed by combining the elements of every array from every dictionary,
|
|
34
|
+
* ordered by priority and eliminating duplicate elements.
|
|
35
|
+
* Two elements are considered duplicates of one another if [[Setting.areEqual]] returns `true`.
|
|
36
|
+
*/
|
|
37
|
+
readonly combineArray?: boolean;
|
|
21
38
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
/** Metadata describing a group of related [[SettingSchema]]s. You can register setting schema groups via [[SettingsSchemas.addGroup]] and
|
|
40
|
+
* remove them via [[SettingsSchemas.removeGroup]].
|
|
41
|
+
*
|
|
42
|
+
* All of the settings share the same [[schemaPrefix]], which must be unique amongst all other groups.
|
|
43
|
+
* The prefix is combined with the name of each [[SettingSchema]] in the group to form the fully-qualified name used to refer
|
|
44
|
+
* to the setting outside of the group, e.g., when accessing [[SettingsSchemas.settingDefs]] or in [[SettingSchema.extends]].
|
|
45
|
+
* In the following example, the fully-qualified name of the setting named "metric" is "format/units/metric".
|
|
46
|
+
*
|
|
47
|
+
* ```json
|
|
48
|
+
* {
|
|
49
|
+
* "schemaPrefix": "format/units",
|
|
50
|
+
* "settingDefs": {
|
|
51
|
+
* "metric": { "type": "boolean" }
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* A group can also define [[SettingSchema]]s that, rather than describing actual [[Setting]]s, instead describe types that can be extended by [[Setting]]s via
|
|
57
|
+
* [[SettingSchema.extends]]. A [[SettingSchema]] can refer to type definitions defined in its own group or any other group.
|
|
58
|
+
* @beta
|
|
59
|
+
*/
|
|
60
|
+
export interface SettingGroupSchema {
|
|
61
|
+
/** Uniquely identifies this group amongst all other groups.
|
|
62
|
+
* The prefix can use forward-slashes to define logical subgroups - for example, two related groups with the prefixes "units/metric" and "units/imperial".
|
|
63
|
+
* The user interface may parse these prefixes to display both groups under a "units" tab or expandable tree view node.
|
|
64
|
+
*
|
|
65
|
+
* @note Schema prefixes beginning with "itwin" are reserved for use by iTwin.js.
|
|
66
|
+
*/
|
|
67
|
+
readonly schemaPrefix: string;
|
|
68
|
+
/** Metadata for each [[Setting]] in this group. */
|
|
69
|
+
readonly settingDefs?: {
|
|
70
|
+
[name: string]: SettingSchema | undefined;
|
|
31
71
|
};
|
|
72
|
+
/** Metadata for types that can be extended by other [[Setting]]s via [[SettingSchema.extends]]. */
|
|
73
|
+
readonly typeDefs?: {
|
|
74
|
+
[name: string]: SettingSchema | undefined;
|
|
75
|
+
};
|
|
76
|
+
/** An integer used when displaying a list of schemas in a user interface, to sort schemas with a lower `order` before those with a `higher` order. */
|
|
32
77
|
readonly order?: number;
|
|
33
|
-
|
|
34
|
-
readonly description
|
|
35
|
-
readonly extensionId?: string;
|
|
78
|
+
/** A description of this group suitable for displaying to a user. */
|
|
79
|
+
readonly description: string;
|
|
36
80
|
}
|
|
37
81
|
/**
|
|
38
|
-
* The registry of available [[
|
|
82
|
+
* The registry of available [[SettingGroupSchema]]s.
|
|
39
83
|
* The registry is used for editing Settings files and for finding default values for settings.
|
|
40
84
|
* @beta
|
|
41
85
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
86
|
+
/** The registry of metadata describing groups of [[SettingSchema]]s available to the current session.
|
|
87
|
+
* The schemas are used to look up the default values of [[Setting]]s, validate that their values are of the type dictated by the schema, and
|
|
88
|
+
* query metadata like [[SettingsSchema.combineArray]] that modify their behavior.
|
|
89
|
+
* They can also be used to drive a user interface that enables end users to edit [[Settings]].
|
|
90
|
+
*
|
|
91
|
+
* When [[IModelHost.startup]] is invoked at the beginning of a session, schemas delivered with the application - like those describing
|
|
92
|
+
* [[Workspace]]s - are automatically loaded.
|
|
93
|
+
* The application can manually register additional schemas using methods like [[addGroup]], [[addFile]], [[addDirectory]], and [[addJson]].
|
|
94
|
+
* When [[IModelHost.shutdown]] is invoked at the end of a session, all registered schemas are unregistered.
|
|
95
|
+
*
|
|
96
|
+
* See the [learning article]($docs/learning/backend/Workspace) for a detailed overiew and examples.
|
|
97
|
+
*
|
|
98
|
+
* @see [[IModelHost.settingsSchemas]] to access the registry for the current session.
|
|
99
|
+
* @beta
|
|
100
|
+
*/
|
|
101
|
+
export interface SettingsSchemas {
|
|
49
102
|
/** @internal */
|
|
50
|
-
|
|
103
|
+
readonly [_implementationProhibited]: unknown;
|
|
104
|
+
/** The map of each individual registered [[SettingSchema]] defining a [[Setting]], accessed by its fully-qualified name (including its [[SettingGroupSchema.schemaPrefix]]). */
|
|
105
|
+
readonly settingDefs: ReadonlyMap<SettingName, SettingSchema>;
|
|
106
|
+
/** The map of each individual registered [[SettingSchema]] defining a type that can be extended by other [[SettingSchema]]s via [[SettingSchema.extends]],
|
|
107
|
+
* accessed by its fully-qualified name (including its [[SettingGroupSchema.schemaPrefix]]).
|
|
108
|
+
*/
|
|
109
|
+
readonly typeDefs: ReadonlyMap<SettingName, SettingSchema>;
|
|
110
|
+
/** An event raised whenever schemas are added or removed. */
|
|
111
|
+
readonly onSchemaChanged: BeEvent<() => void>;
|
|
51
112
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
113
|
+
* Ensure that the setting value supplied is valid according to its [[SettingSchema]].
|
|
114
|
+
* If no schema has been registered for the setting, no validation is performed.
|
|
115
|
+
* @param value The value of the setting to validate against the schema.
|
|
116
|
+
* @param settingName The fully-qualified setting name.
|
|
117
|
+
* @returns `value` if `value` matches the schema corresponding to `settingName`, or if no such schema has been registered.
|
|
118
|
+
* @throws Error if `value` is invalid according to the schema.
|
|
119
|
+
*/
|
|
120
|
+
validateSetting<T>(value: T, settingName: SettingName): T;
|
|
121
|
+
/** Register one or more [[SettingGroupSchema]]s.
|
|
122
|
+
* If a group with the same [[SettingGroupSchema.prefix]] was previously registered, it will be replaced.
|
|
123
|
+
* Each [[SettingSchema]] in the group will be added to [[settingDefs]] or [[typeDefs]].
|
|
54
124
|
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
private static doAdd;
|
|
65
|
-
private static doRemove;
|
|
66
|
-
private static validateName;
|
|
67
|
-
private static validateProperty;
|
|
68
|
-
private static validateAndAdd;
|
|
69
|
-
private static getDefaultValue;
|
|
125
|
+
addGroup(settingsGroup: SettingGroupSchema | SettingGroupSchema[]): void;
|
|
126
|
+
/** Invokes [[addGroup]] for a [[SettingGroupSchema]] supplied as stringified json5. */
|
|
127
|
+
addJson(settingSchema: string): void;
|
|
128
|
+
/** Invokes [[addGroup]] for a json5 file containiner a [[SettingGroupSchema]]. */
|
|
129
|
+
addFile(fileName: LocalFileName): void;
|
|
130
|
+
/** Invokes [[addFile]] for every json and json5 file in the specified directory. */
|
|
131
|
+
addDirectory(dirName: LocalDirName): void;
|
|
132
|
+
/** Unregisters all [[settingDefs]] and [[typeDefs]] with the specified [[SettingGroupSchema.schemaPrefix]]. */
|
|
133
|
+
removeGroup(schemaPrefix: string): void;
|
|
70
134
|
}
|
|
71
135
|
//# sourceMappingURL=SettingsSchemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsSchemas.d.ts","sourceRoot":"","sources":["../../../src/workspace/SettingsSchemas.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"SettingsSchemas.d.ts","sourceRoot":"","sources":["../../../src/workspace/SettingsSchemas.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;;IAQI;AACJ,MAAM,WAAW,aAAc,SAAQ,QAAQ,CAAC,UAAU,CAAC;IACzD,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAE,C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