@itwin/core-backend 3.3.0-dev.40 → 3.3.0-dev.43
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 +11 -1
- package/lib/cjs/BackendHubAccess.d.ts +2 -7
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BisCoreSchema.d.ts +1 -1
- package/lib/cjs/BisCoreSchema.js +1 -1
- package/lib/cjs/BisCoreSchema.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts +10 -11
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +10 -11
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts +14 -4
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +91 -19
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/CodeSpecs.d.ts +1 -1
- package/lib/cjs/CodeSpecs.js +1 -1
- package/lib/cjs/CodeSpecs.js.map +1 -1
- package/lib/cjs/Element.d.ts +8 -8
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +3 -3
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +14 -0
- package/lib/cjs/GeoCoordConfig.d.ts.map +1 -0
- package/lib/cjs/GeoCoordConfig.js +73 -0
- package/lib/cjs/GeoCoordConfig.js.map +1 -0
- package/lib/cjs/HubMock.d.ts.map +1 -1
- package/lib/cjs/HubMock.js +0 -2
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +25 -15
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +43 -34
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +10 -1
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +30 -14
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/LocalHub.d.ts +5 -3
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +1 -1
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts +4 -3
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +5 -4
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts +4 -0
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +4 -0
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +68 -0
- package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +22 -0
- package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +53 -0
- package/lib/cjs/assets/Settings/backend.setting.json5 +139 -0
- package/lib/cjs/core-backend.d.ts +7 -7
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +7 -7
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +8 -12
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts +8 -3
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +9 -0
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.d.ts +76 -0
- package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -0
- package/lib/cjs/workspace/SettingsSchemas.js +192 -0
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -0
- package/lib/cjs/workspace/Workspace.d.ts +241 -146
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +260 -96
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +20 -13
- package/lib/cjs/assets/Settings.schema.json +0 -25
- package/lib/cjs/workspace/SettingsSpecRegistry.d.ts +0 -68
- package/lib/cjs/workspace/SettingsSpecRegistry.d.ts.map +0 -1
- package/lib/cjs/workspace/SettingsSpecRegistry.js +0 -122
- package/lib/cjs/workspace/SettingsSpecRegistry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Settings.d.ts","sourceRoot":"","sources":["../../../src/workspace/Settings.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"Settings.d.ts","sourceRoot":"","sources":["../../../src/workspace/Settings.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGjE;;GAEG;AACH,oBAAY,WAAW,GAAG,cAAc,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,WAAW,GAAG,MAAM,CAAC;AAEjC;;;GAGG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;;;;GAQG;AACH,oBAAY,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,gBAAgB,KAAK,CAAC,GAAG,SAAS,CAAC;AAE7G;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAAI,KAAK,EAAE,CAAC,CAAC;IAAC,UAAU,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AAE/F;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,IAAI,EAAE,MAAM,GA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GAAG,OAAO;IAC7D,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS;IAKlD,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAC1D,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS;IAKhD,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC;IAClE,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,CAAC,GAAG,SAAS;IAK7D,QAAQ,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACpF,QAAQ,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS;CAKhF"}
|
|
@@ -10,7 +10,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.BaseSettings = exports.SettingsPriority = void 0;
|
|
11
11
|
const fs = require("fs-extra");
|
|
12
12
|
const json5_1 = require("json5");
|
|
13
|
+
const path_1 = require("path");
|
|
13
14
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
|
+
const IModelJsFs_1 = require("../IModelJsFs");
|
|
14
16
|
/**
|
|
15
17
|
* Values for SettingsPriority determine the sort order for Settings. Higher values take precedence over lower values.
|
|
16
18
|
* @beta
|
|
@@ -68,6 +70,13 @@ class BaseSettings {
|
|
|
68
70
|
addFile(fileName, priority) {
|
|
69
71
|
this.addJson(fileName, priority, fs.readFileSync(fileName, "utf-8"));
|
|
70
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
|
+
}
|
|
71
80
|
addJson(dictionaryName, priority, settingsJson) {
|
|
72
81
|
this.addDictionary(dictionaryName, priority, (0, json5_1.parse)(settingsJson));
|
|
73
82
|
}
|
|
@@ -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,sDAA8D;AAoD9D;;;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,GAAhB,wBAAgB,KAAhB,wBAAgB,QAW3B;AAoGD,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,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QACvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;SAC9B;aAAM;YACL,MAAM,CA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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;AAhGD,oCAgGC","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 { BeEvent, JSONSchemaType } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\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 [[SettingSpec]].\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 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 | undefined;\r\n resolveSetting<T extends SettingType>(settingName: SettingName, resolver: SettingResolver<T>, defaultValue: T): T;\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 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 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) => { all.push({ value, dictionary, priority }); return undefined; });\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;;;+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,GAAhB,wBAAgB,KAAhB,wBAAgB,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,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QACvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;SAC9B;aAAM;YACL,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;SACnB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,kBAAkB;IACtB,YAAmC,IAAY,EAAkB,QA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AqB;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;AAxGD,oCAwGC","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 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) => { all.push({ value, dictionary, priority }); return undefined; });\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"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Workspace
|
|
3
|
+
*/
|
|
4
|
+
import { BeEvent, JSONSchema, JSONSchemaTypeName } from "@itwin/core-bentley";
|
|
5
|
+
import { LocalDirName, LocalFileName } from "@itwin/core-common";
|
|
6
|
+
/**
|
|
7
|
+
* The properties of a single Setting, used by the settings editor. This interface also includes the
|
|
8
|
+
* default value if it is not specified in any Settings file.
|
|
9
|
+
* This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.
|
|
10
|
+
* @note the `type` member is marked optional in JSONSchema but is required for Settings.
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface SettingSchema extends Readonly<JSONSchema> {
|
|
14
|
+
readonly items?: SettingSchema;
|
|
15
|
+
readonly type: JSONSchemaTypeName;
|
|
16
|
+
readonly properties?: {
|
|
17
|
+
[name: string]: SettingSchema;
|
|
18
|
+
};
|
|
19
|
+
/** whether the setting replaces lower priority entries with the same name or combines with them. */
|
|
20
|
+
readonly cumulative?: true;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The properties of a group of [[SettingSchema]]s for an application. Groups can be added and removed from [[SettingsSchemas]]
|
|
24
|
+
* and are identified by their (required) `groupName` member
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export interface SettingSchemaGroup {
|
|
28
|
+
readonly groupName: string;
|
|
29
|
+
readonly properties: {
|
|
30
|
+
[name: string]: SettingSchema;
|
|
31
|
+
};
|
|
32
|
+
readonly order?: number;
|
|
33
|
+
readonly title?: string;
|
|
34
|
+
readonly description?: string;
|
|
35
|
+
readonly extensionId?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The registry of available [[SettingSchemaGroup]]s.
|
|
39
|
+
* The registry is used for editing Settings files and for finding default values for settings.
|
|
40
|
+
* @beta
|
|
41
|
+
*/
|
|
42
|
+
export declare class SettingsSchemas {
|
|
43
|
+
private constructor();
|
|
44
|
+
private static readonly _allGroups;
|
|
45
|
+
/** a map of all registered [[SettingSchema]]s */
|
|
46
|
+
static readonly allSchemas: Map<string, SettingSchema>;
|
|
47
|
+
/** event that signals that the values in [[allSchemas]] have changed in some way. */
|
|
48
|
+
static readonly onSchemaChanged: BeEvent<() => void>;
|
|
49
|
+
/** Clear the contents of the registry and remove all event listeners.
|
|
50
|
+
* @note This is really only necessary for tests of the Settings system.
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
static reset(): void;
|
|
54
|
+
/** @internal */
|
|
55
|
+
static validateArrayObject<T>(val: T, schemaName: string, msg: string): T;
|
|
56
|
+
/**
|
|
57
|
+
* Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used
|
|
58
|
+
* 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.
|
|
59
|
+
*/
|
|
60
|
+
static addGroup(settingsGroup: SettingSchemaGroup | SettingSchemaGroup[]): void;
|
|
61
|
+
/** Add a [[SettingSchemaGroup]] from stringified json5. */
|
|
62
|
+
static addJson(settingSchema: string): void;
|
|
63
|
+
/** Add a [[SettingSchemaGroup]] from a json5 file. */
|
|
64
|
+
static addFile(fileName: LocalFileName): void;
|
|
65
|
+
/** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
|
|
66
|
+
static addDirectory(dirName: LocalDirName): void;
|
|
67
|
+
/** Remove a previously added [[SettingSchemaGroup]] by groupName */
|
|
68
|
+
static removeGroup(groupName: string): void;
|
|
69
|
+
private static doAdd;
|
|
70
|
+
private static doRemove;
|
|
71
|
+
private static validateName;
|
|
72
|
+
private static validateProperty;
|
|
73
|
+
private static validateAndAdd;
|
|
74
|
+
private static getDefaultValue;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=SettingsSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsSchemas.d.ts","sourceRoot":"","sources":["../../../src/workspace/SettingsSchemas.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAkB,kBAAkB,EAAW,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGjE;;;;;;GAMG;AACH,MAAM,WAAW,aAAc,SAAQ,QAAQ,CAAC,UAAU,CAAC;IACzD,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAC;IAExD,oGAAoG;IACpG,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QA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192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Workspace
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SettingsSchemas = void 0;
|
|
11
|
+
const fs = require("fs-extra");
|
|
12
|
+
const json5_1 = require("json5");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
|
+
const IModelJsFs_1 = require("../IModelJsFs");
|
|
16
|
+
/**
|
|
17
|
+
* The registry of available [[SettingSchemaGroup]]s.
|
|
18
|
+
* The registry is used for editing Settings files and for finding default values for settings.
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
class SettingsSchemas {
|
|
22
|
+
constructor() { } // singleton
|
|
23
|
+
/** Clear the contents of the registry and remove all event listeners.
|
|
24
|
+
* @note This is really only necessary for tests of the Settings system.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
static reset() {
|
|
28
|
+
this._allGroups.clear();
|
|
29
|
+
this.allSchemas.clear();
|
|
30
|
+
this.onSchemaChanged.clear();
|
|
31
|
+
}
|
|
32
|
+
/** @internal */
|
|
33
|
+
static validateArrayObject(val, schemaName, msg) {
|
|
34
|
+
const schema = this.allSchemas.get(schemaName);
|
|
35
|
+
const items = schema === null || schema === void 0 ? void 0 : schema.items;
|
|
36
|
+
if (undefined === items)
|
|
37
|
+
return val;
|
|
38
|
+
const required = items.required;
|
|
39
|
+
const properties = items.properties;
|
|
40
|
+
if (undefined === required || undefined === properties)
|
|
41
|
+
return val;
|
|
42
|
+
for (const entry of required) {
|
|
43
|
+
const entryType = properties[entry].type;
|
|
44
|
+
const value = val[entry];
|
|
45
|
+
if (entryType === "array" && Array.isArray(value))
|
|
46
|
+
continue;
|
|
47
|
+
if (typeof value !== entryType)
|
|
48
|
+
throw new Error(`invalid "${schemaName}" setting entry for "${msg}": ${entry} is ${value}`);
|
|
49
|
+
}
|
|
50
|
+
return val;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used
|
|
54
|
+
* to identify the group. If a group with the same name is already registered, the old values are first removed and then the new group is added.
|
|
55
|
+
*/
|
|
56
|
+
static addGroup(settingsGroup) {
|
|
57
|
+
if (!Array.isArray(settingsGroup))
|
|
58
|
+
settingsGroup = [settingsGroup];
|
|
59
|
+
this.doAdd(settingsGroup);
|
|
60
|
+
this.onSchemaChanged.raiseEvent();
|
|
61
|
+
}
|
|
62
|
+
/** Add a [[SettingSchemaGroup]] from stringified json5. */
|
|
63
|
+
static addJson(settingSchema) {
|
|
64
|
+
this.addGroup((0, json5_1.parse)(settingSchema));
|
|
65
|
+
}
|
|
66
|
+
/** Add a [[SettingSchemaGroup]] from a json5 file. */
|
|
67
|
+
static addFile(fileName) {
|
|
68
|
+
try {
|
|
69
|
+
this.addJson(fs.readFileSync(fileName, "utf-8"));
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
throw new Error(`parsing SettingSchema file "${fileName}": ${e.message}"`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Add all files with a either ".json" or ".json5" extension from a supplied directory. */
|
|
76
|
+
static addDirectory(dirName) {
|
|
77
|
+
for (const fileName of IModelJsFs_1.IModelJsFs.readdirSync(dirName)) {
|
|
78
|
+
const ext = (0, path_1.extname)(fileName);
|
|
79
|
+
if (ext === ".json5" || ext === ".json")
|
|
80
|
+
this.addFile((0, path_1.join)(dirName, fileName));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Remove a previously added [[SettingSchemaGroup]] by groupName */
|
|
84
|
+
static removeGroup(groupName) {
|
|
85
|
+
this.doRemove(groupName);
|
|
86
|
+
this.onSchemaChanged.raiseEvent();
|
|
87
|
+
}
|
|
88
|
+
static doAdd(settingsGroup) {
|
|
89
|
+
settingsGroup.forEach((group) => {
|
|
90
|
+
if (undefined === group.groupName)
|
|
91
|
+
throw new Error(`settings group has no "groupName" member`);
|
|
92
|
+
this.doRemove(group.groupName);
|
|
93
|
+
this.validateAndAdd(group);
|
|
94
|
+
this._allGroups.set(group.groupName, group);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
static doRemove(groupName) {
|
|
98
|
+
const group = this._allGroups.get(groupName);
|
|
99
|
+
if (undefined !== (group === null || group === void 0 ? void 0 : group.properties)) {
|
|
100
|
+
for (const key of Object.keys(group.properties))
|
|
101
|
+
this.allSchemas.delete(key);
|
|
102
|
+
}
|
|
103
|
+
this._allGroups.delete(groupName);
|
|
104
|
+
}
|
|
105
|
+
static validateName(name) {
|
|
106
|
+
if (!name.trim())
|
|
107
|
+
throw new Error(`empty property name`);
|
|
108
|
+
if (this.allSchemas.has(name))
|
|
109
|
+
throw new Error(`property "${name}" is already defined`);
|
|
110
|
+
}
|
|
111
|
+
static validateProperty(name, property) {
|
|
112
|
+
if (!property)
|
|
113
|
+
throw new Error(`missing required property ${name}`);
|
|
114
|
+
if (!property.type)
|
|
115
|
+
throw new Error(`property ${name} has no type`);
|
|
116
|
+
switch (property.type) {
|
|
117
|
+
case "boolean":
|
|
118
|
+
case "integer":
|
|
119
|
+
case "null":
|
|
120
|
+
case "number":
|
|
121
|
+
case "string":
|
|
122
|
+
return;
|
|
123
|
+
case "object":
|
|
124
|
+
const required = property.required;
|
|
125
|
+
const props = property.properties;
|
|
126
|
+
if (required && props) {
|
|
127
|
+
for (const entry of required)
|
|
128
|
+
this.validateProperty(entry, props[entry]);
|
|
129
|
+
}
|
|
130
|
+
if (props) {
|
|
131
|
+
for (const key of Object.keys(props))
|
|
132
|
+
try {
|
|
133
|
+
this.validateProperty(key, props[key]);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
throw new Error(`property ${key} of ${name}: ${e.message}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
case "array":
|
|
141
|
+
if (typeof property.items !== "object")
|
|
142
|
+
throw new Error(`array property ${name} has no items member`);
|
|
143
|
+
try {
|
|
144
|
+
this.validateProperty("items", property.items);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
throw new Error(`array property ${name}: ${e.message}`);
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`property ${name} has illegal type "${property.type}"`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
static validateAndAdd(group) {
|
|
155
|
+
var _a;
|
|
156
|
+
const properties = group.properties;
|
|
157
|
+
if (undefined === properties)
|
|
158
|
+
throw new Error(`group ${group.groupName} has no properties`);
|
|
159
|
+
for (const key of Object.keys(properties)) {
|
|
160
|
+
this.validateName(key);
|
|
161
|
+
this.validateProperty(key, properties[key]);
|
|
162
|
+
const property = properties[key];
|
|
163
|
+
property.default = (_a = property.default) !== null && _a !== void 0 ? _a : this.getDefaultValue(property.type);
|
|
164
|
+
this.allSchemas.set(key, property);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
static getDefaultValue(type) {
|
|
168
|
+
type = Array.isArray(type) ? type[0] : type;
|
|
169
|
+
switch (type) {
|
|
170
|
+
case "boolean":
|
|
171
|
+
return false;
|
|
172
|
+
case "integer":
|
|
173
|
+
case "number":
|
|
174
|
+
return 0;
|
|
175
|
+
case "string":
|
|
176
|
+
return "";
|
|
177
|
+
case "array":
|
|
178
|
+
return [];
|
|
179
|
+
case "object":
|
|
180
|
+
return {};
|
|
181
|
+
default:
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.SettingsSchemas = SettingsSchemas;
|
|
187
|
+
SettingsSchemas._allGroups = new Map();
|
|
188
|
+
/** a map of all registered [[SettingSchema]]s */
|
|
189
|
+
SettingsSchemas.allSchemas = new Map();
|
|
190
|
+
/** event that signals that the values in [[allSchemas]] have changed in some way. */
|
|
191
|
+
SettingsSchemas.onSchemaChanged = new core_bentley_1.BeEvent();
|
|
192
|
+
//# sourceMappingURL=SettingsSchemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsSchemas.js","sourceRoot":"","sources":["../../../src/workspace/SettingsSchemas.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,+BAAqC;AACrC,sDAAuG;AAEvG,8CAA2C;AAgC3C;;;;GAIG;AACH,MAAa,eAAe;IAC1B,gBAAwB,CAAC,CAAC,YAAY;IAOtC;;;OAGG;IACI,MAAM,CAAC,KAAK;QACjB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,mBAAmB,CAAI,GAAM,EAAE,UAAkB,EAAE,GAAW;QAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC;QAC5B,IAAI,SAAS,KAAK,KAAK;YACrB,OAAO,GAAG,CAAC;QACb,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACpC,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,UAAU;YACpD,OAAO,GAAG,CAAC;QAEb,KAAK,MAAM,KAAK,IAAI,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OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,QAAQ,IAAI,EAAE;YACZ,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACX,OAAO,CAAC,CAAC;YACX,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;YACZ,KAAK,OAAO;gBACV,OAAO,EAAE,CAAC;YACZ,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;YACZ;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC;;AA1LH,0CA2LC;AAzLyB,0BAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC3E,iDAAiD;AAC1B,0BAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;AACrE,qFAAqF;AAC9D,+BAAe,GAAG,IAAI,sBAAO,EAAc,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Workspace\r\n */\r\n\r\nimport * as fs from \"fs-extra\";\r\nimport { parse } from \"json5\";\r\nimport { extname, join } from \"path\";\r\nimport { BeEvent, JSONSchema, JSONSchemaType, JSONSchemaTypeName, Mutable } from \"@itwin/core-bentley\";\r\nimport { LocalDirName, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\n/**\r\n * The properties of a single Setting, used by the settings editor. This interface also includes the\r\n * default value if it is not specified in any Settings file.\r\n * This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.\r\n * @note the `type` member is marked optional in JSONSchema but is required for Settings.\r\n * @beta\r\n */\r\nexport interface SettingSchema extends Readonly<JSONSchema> {\r\n readonly items?: SettingSchema; // must be single object, not array\r\n readonly type: JSONSchemaTypeName; // type is required for settings\r\n readonly properties?: { [name: string]: SettingSchema };\r\n\r\n /** whether the setting replaces lower priority entries with the same name or combines with them. */\r\n readonly cumulative?: true;\r\n}\r\n\r\n/**\r\n * The properties of a group of [[SettingSchema]]s for an application. Groups can be added and removed from [[SettingsSchemas]]\r\n * and are identified by their (required) `groupName` member\r\n * @beta\r\n */\r\nexport interface SettingSchemaGroup {\r\n readonly groupName: string;\r\n readonly properties: { [name: string]: SettingSchema };\r\n readonly order?: number;\r\n readonly title?: string;\r\n readonly description?: string;\r\n readonly extensionId?: string;\r\n}\r\n\r\n/**\r\n * The registry of available [[SettingSchemaGroup]]s.\r\n * The registry is used for editing Settings files and for finding default values for settings.\r\n * @beta\r\n */\r\nexport class SettingsSchemas {\r\n private constructor() { } // singleton\r\n private static readonly _allGroups = new Map<string, SettingSchemaGroup>();\r\n /** a map of all registered [[SettingSchema]]s */\r\n public static readonly allSchemas = new Map<string, SettingSchema>();\r\n /** event that signals that the values in [[allSchemas]] have changed in some way. */\r\n public static readonly onSchemaChanged = new BeEvent<() => void>();\r\n\r\n /** Clear the contents of the registry and remove all event listeners.\r\n * @note This is really only necessary for tests of the Settings system.\r\n * @internal\r\n */\r\n public static reset() {\r\n this._allGroups.clear();\r\n this.allSchemas.clear();\r\n this.onSchemaChanged.clear();\r\n }\r\n\r\n /** @internal */\r\n public static validateArrayObject<T>(val: T, schemaName: string, msg: string): T {\r\n const schema = this.allSchemas.get(schemaName);\r\n const items = schema?.items;\r\n if (undefined === items)\r\n return val;\r\n const required = items.required;\r\n const properties = items.properties;\r\n if (undefined === required || undefined === properties)\r\n return val;\r\n\r\n for (const entry of required) {\r\n const entryType = properties[entry].type;\r\n const value = (val as any)[entry];\r\n if (entryType === \"array\" && Array.isArray(value))\r\n continue;\r\n if (typeof value !== entryType)\r\n throw new Error(`invalid \"${schemaName}\" setting entry for \"${msg}\": ${entry} is ${value}`);\r\n }\r\n return val;\r\n }\r\n\r\n /**\r\n * Add one or more [[SettingSchemaGroup]]s. `SettingSchemaGroup`s must include a `groupName` member that is used\r\n * to identify the group. If a group with the same name is already registered, the old values are first removed and then the new group is added.\r\n */\r\n public static addGroup(settingsGroup: SettingSchemaGroup | SettingSchemaGroup[]): void {\r\n if (!Array.isArray(settingsGroup))\r\n settingsGroup = [settingsGroup];\r\n\r\n this.doAdd(settingsGroup);\r\n this.onSchemaChanged.raiseEvent();\r\n }\r\n\r\n /** Add a [[SettingSchemaGroup]] from stringified json5. */\r\n public static addJson(settingSchema: string): void {\r\n this.addGroup(parse(settingSchema));\r\n }\r\n\r\n /** Add a [[SettingSchemaGroup]] from a json5 file. */\r\n public static addFile(fileName: LocalFileName): void {\r\n try {\r\n this.addJson(fs.readFileSync(fileName, \"utf-8\"));\r\n } catch (e: any) {\r\n throw new Error(`parsing SettingSchema file \"${fileName}\": ${e.message}\"`);\r\n }\r\n }\r\n\r\n /** Add all files with a either \".json\" or \".json5\" extension from a supplied directory. */\r\n public static addDirectory(dirName: LocalDirName) {\r\n for (const fileName of IModelJsFs.readdirSync(dirName)) {\r\n const ext = extname(fileName);\r\n if (ext === \".json5\" || ext === \".json\")\r\n this.addFile(join(dirName, fileName));\r\n }\r\n }\r\n\r\n /** Remove a previously added [[SettingSchemaGroup]] by groupName */\r\n public static removeGroup(groupName: string): void {\r\n this.doRemove(groupName);\r\n this.onSchemaChanged.raiseEvent();\r\n }\r\n\r\n private static doAdd(settingsGroup: SettingSchemaGroup[]) {\r\n settingsGroup.forEach((group) => {\r\n if (undefined === group.groupName)\r\n throw new Error(`settings group has no \"groupName\" member`);\r\n\r\n this.doRemove(group.groupName);\r\n this.validateAndAdd(group);\r\n this._allGroups.set(group.groupName, group);\r\n });\r\n }\r\n\r\n private static doRemove(groupName: string) {\r\n const group = this._allGroups.get(groupName);\r\n if (undefined !== group?.properties) {\r\n for (const key of Object.keys(group.properties))\r\n this.allSchemas.delete(key);\r\n }\r\n this._allGroups.delete(groupName);\r\n }\r\n\r\n private static validateName(name: string) {\r\n if (!name.trim())\r\n throw new Error(`empty property name`);\r\n if (this.allSchemas.has(name))\r\n throw new Error(`property \"${name}\" is already defined`);\r\n }\r\n\r\n private static validateProperty(name: string, property: SettingSchema | undefined) {\r\n if (!property)\r\n throw new Error(`missing required property ${name}`);\r\n\r\n if (!property.type)\r\n throw new Error(`property ${name} has no type`);\r\n\r\n switch (property.type) {\r\n case \"boolean\":\r\n case \"integer\":\r\n case \"null\":\r\n case \"number\":\r\n case \"string\":\r\n return;\r\n\r\n case \"object\":\r\n const required = property.required;\r\n const props = property.properties;\r\n if (required && props) {\r\n for (const entry of required)\r\n this.validateProperty(entry, props[entry]);\r\n }\r\n if (props) {\r\n for (const key of Object.keys(props))\r\n try {\r\n this.validateProperty(key, props[key]);\r\n } catch (e: any) {\r\n throw new Error(`property ${key} of ${name}: ${e.message}`);\r\n }\r\n }\r\n return;\r\n\r\n case \"array\":\r\n if (typeof property.items !== \"object\")\r\n throw new Error(`array property ${name} has no items member`);\r\n try {\r\n this.validateProperty(\"items\", property.items);\r\n } catch (e: any) {\r\n throw new Error(`array property ${name}: ${e.message}`);\r\n }\r\n return;\r\n\r\n default:\r\n throw new Error(`property ${name} has illegal type \"${property.type}\"`);\r\n }\r\n }\r\n\r\n private static validateAndAdd(group: SettingSchemaGroup) {\r\n const properties = group.properties;\r\n if (undefined === properties)\r\n throw new Error(`group ${group.groupName} has no properties`);\r\n\r\n for (const key of Object.keys(properties)) {\r\n this.validateName(key);\r\n this.validateProperty(key, properties[key]);\r\n const property: Mutable<SettingSchema> = properties[key];\r\n property.default = property.default ?? this.getDefaultValue(property.type);\r\n this.allSchemas.set(key, property);\r\n }\r\n }\r\n\r\n private static getDefaultValue(type: JSONSchemaTypeName | JSONSchemaTypeName[]): JSONSchemaType | undefined {\r\n type = Array.isArray(type) ? type[0] : type;\r\n switch (type) {\r\n case \"boolean\":\r\n return false;\r\n case \"integer\":\r\n case \"number\":\r\n return 0;\r\n case \"string\":\r\n return \"\";\r\n case \"array\":\r\n return [];\r\n case \"object\":\r\n return {};\r\n default:\r\n return undefined;\r\n }\r\n }\r\n}\r\n"]}
|