@itwin/core-backend 3.0.0-dev.98 → 3.0.0
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 +211 -67
- package/LICENSE.md +1 -1
- package/lib/cjs/AliCloudStorageService.d.ts +8 -2
- package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
- package/lib/cjs/AliCloudStorageService.js +4 -5
- package/lib/cjs/AliCloudStorageService.js.map +1 -1
- package/lib/cjs/BackendHubAccess.d.ts +9 -9
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BriefcaseManager.js +4 -3
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +1 -1
- package/lib/cjs/Category.d.ts.map +1 -1
- package/lib/cjs/Category.js +6 -6
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
- package/lib/cjs/ChangeSummaryManager.js +2 -0
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +2 -0
- package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
- package/lib/cjs/ChangedElementsDb.js +1 -1
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +10 -7
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +10 -3
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudStorageBackend.d.ts +2 -3
- package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
- package/lib/cjs/CloudStorageBackend.js +5 -2
- package/lib/cjs/CloudStorageBackend.js.map +1 -1
- package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
- package/lib/cjs/ConcurrentQuery.js +7 -0
- package/lib/cjs/ConcurrentQuery.js.map +1 -1
- package/lib/cjs/DevTools.d.ts +2 -2
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js +2 -2
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +2 -2
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +15 -47
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +5 -9
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +11 -14
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.d.ts +1 -0
- package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +10 -4
- package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
- package/lib/cjs/ECSqlStatement.d.ts +8 -8
- package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
- package/lib/cjs/ECSqlStatement.js +24 -15
- package/lib/cjs/ECSqlStatement.js.map +1 -1
- package/lib/cjs/Element.d.ts +16 -16
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +9 -9
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +2 -2
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +2 -2
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/ElementGraphics.js +1 -1
- package/lib/cjs/ElementGraphics.js.map +1 -1
- package/lib/cjs/Entity.d.ts +11 -3
- package/lib/cjs/Entity.d.ts.map +1 -1
- package/lib/cjs/Entity.js +10 -2
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/ExportGraphics.d.ts +1 -1
- package/lib/cjs/ExportGraphics.d.ts.map +1 -1
- package/lib/cjs/ExportGraphics.js +3 -0
- package/lib/cjs/ExportGraphics.js.map +1 -1
- package/lib/cjs/GeometrySummary.d.ts.map +1 -1
- package/lib/cjs/GeometrySummary.js +5 -2
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +44 -26
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +114 -42
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +40 -19
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +70 -20
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelJsFs.js +1 -1
- package/lib/cjs/IModelJsFs.js.map +1 -1
- package/lib/cjs/IpcHost.js +2 -1
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
- package/lib/cjs/LocalhostIpcHost.js +10 -3
- package/lib/cjs/LocalhostIpcHost.js.map +1 -1
- package/lib/cjs/Material.d.ts +1 -1
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +1 -1
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +4 -4
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +3 -3
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/NativeHost.d.ts +4 -22
- package/lib/cjs/NativeHost.d.ts.map +1 -1
- package/lib/cjs/NativeHost.js +4 -56
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +10 -9
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +14 -8
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/RpcBackend.d.ts +4 -0
- package/lib/cjs/RpcBackend.d.ts.map +1 -1
- package/lib/cjs/RpcBackend.js +7 -0
- package/lib/cjs/RpcBackend.js.map +1 -1
- package/lib/cjs/SQLiteDb.js +1 -1
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/ServerBasedLocks.d.ts +4 -10
- package/lib/cjs/ServerBasedLocks.d.ts.map +1 -1
- package/lib/cjs/ServerBasedLocks.js +12 -20
- package/lib/cjs/ServerBasedLocks.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/Texture.js +1 -1
- package/lib/cjs/Texture.js.map +1 -1
- package/lib/cjs/TxnManager.js +1 -1
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +11 -11
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +5 -5
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/assets/Settings.schema.json +25 -0
- package/lib/cjs/core-backend.d.ts +8 -1
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +9 -1
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/domains/GenericElements.d.ts +2 -2
- package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
- package/lib/cjs/domains/GenericElements.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +33 -24
- 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 +10 -7
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +11 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/rpc-impl/WipRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/WipRpcImpl.js +3 -0
- package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts +182 -0
- package/lib/cjs/workspace/Settings.d.ts.map +1 -0
- package/lib/cjs/workspace/Settings.js +144 -0
- package/lib/cjs/workspace/Settings.js.map +1 -0
- package/lib/cjs/workspace/SettingsSpecRegistry.d.ts +68 -0
- package/lib/cjs/workspace/SettingsSpecRegistry.d.ts.map +1 -0
- package/lib/cjs/workspace/SettingsSpecRegistry.js +122 -0
- package/lib/cjs/workspace/SettingsSpecRegistry.js.map +1 -0
- package/lib/cjs/workspace/Workspace.d.ts +306 -0
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -0
- package/lib/cjs/workspace/Workspace.js +372 -0
- package/lib/cjs/workspace/Workspace.js.map +1 -0
- package/package.json +33 -19
|
@@ -0,0 +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,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,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;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"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Workspace
|
|
3
|
+
*/
|
|
4
|
+
import { BeEvent, JSONSchema, JSONSchemaTypeName } from "@itwin/core-bentley";
|
|
5
|
+
/**
|
|
6
|
+
* The properties of a Setting, used by the settings editor. This interface also includes the
|
|
7
|
+
* default value if it is not specified in any Settings file.
|
|
8
|
+
* This interface includes all members of [JSONSchema]($bentley) with the extensions added by VSCode.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export interface SettingSpec extends Readonly<JSONSchema> {
|
|
12
|
+
type: JSONSchemaTypeName | JSONSchemaTypeName[];
|
|
13
|
+
/** labels for items of an enum. */
|
|
14
|
+
readonly enumItemLabels?: string[];
|
|
15
|
+
/** whether the editor should show multiple lines. */
|
|
16
|
+
readonly multilineEdit?: true;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The properties of a group of [[SettingSpec]]s for an application. Groups can be added and removed from the registry
|
|
20
|
+
* and are identified by their (required) `groupName` member
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
export interface SettingsGroupSpec {
|
|
24
|
+
readonly groupName: string;
|
|
25
|
+
readonly properties: {
|
|
26
|
+
[name: string]: SettingSpec;
|
|
27
|
+
};
|
|
28
|
+
readonly order?: number;
|
|
29
|
+
readonly title?: string;
|
|
30
|
+
readonly description?: string;
|
|
31
|
+
readonly extensionId?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The registry of available [[SettingsGroupSpec]]s.
|
|
35
|
+
* The registry is used for editing Settings files and for finding default values for settings.
|
|
36
|
+
* @beta
|
|
37
|
+
*/
|
|
38
|
+
export declare class SettingsSpecRegistry {
|
|
39
|
+
private constructor();
|
|
40
|
+
private static readonly _allGroups;
|
|
41
|
+
/** a map of all registered [[SettingSpec]]s */
|
|
42
|
+
static readonly allSpecs: Map<string, SettingSpec>;
|
|
43
|
+
/** event that signals that the values in [[allSpecs]] have changed in some way. */
|
|
44
|
+
static readonly onSpecsChanged: BeEvent<() => void>;
|
|
45
|
+
/** Clear the contents of the registry and remove all event listeners.
|
|
46
|
+
* @note This is really only necessary for tests of the Settings system.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
static reset(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Add one or more [[SettingsGroupSpec]]s to the registry. `SettingsGroupSpec`s must include a `groupName` member that is used
|
|
52
|
+
* 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.
|
|
53
|
+
* @returns an array of problems found adding properties of the supplied group(s).
|
|
54
|
+
*/
|
|
55
|
+
static addGroup(settingsGroup: SettingsGroupSpec | SettingsGroupSpec[]): string[];
|
|
56
|
+
/** Add a [[SettingsGroupSpec]] from stringified json5. */
|
|
57
|
+
static addJson(settingSpecJson: string): string[];
|
|
58
|
+
/** Add a [[SettingsGroupSpec]] from a json5 file. */
|
|
59
|
+
static addFile(fileName: string): string[];
|
|
60
|
+
/** Remove a previously added [[SettingsGroupSpec]] by groupName */
|
|
61
|
+
static removeGroup(groupName: string): void;
|
|
62
|
+
private static doAdd;
|
|
63
|
+
private static doRemove;
|
|
64
|
+
private static validateProperty;
|
|
65
|
+
private static validateAndAdd;
|
|
66
|
+
private static getDefaultValue;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=SettingsSpecRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsSpecRegistry.d.ts","sourceRoot":"","sources":["../../../src/workspace/SettingsSpecRegistry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAkB,kBAAkB,EAAW,MAAM,qBAAqB,CAAC;AAEvG;;;;;GAKG;AACH,MAAM,WAAW,WAAY,SAAQ,QAAQ,CAAC,UAAU,CAAC;IACvD,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IAChD,mCAAmC;IACnC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IACnC,qDAAqD;IACrD,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,OAAO;IACP,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAwC;IAC1E,+CAA+C;IAC/C,gBAAuB,QAAQ,2BAAkC;IACjE,mFAAmF;IACnF,gBAAuB,cAAc,gBAAqB,IAAI,EAAI;IAElE;;;OAGG;WACW,KAAK;IAMnB;;;;OAIG;WACW,QAAQ,CAAC,aAAa,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,MAAM,EAAE;IAUxF,0DAA0D;WAC5C,OAAO,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,EAAE;IAIxD,qDAAqD;WACvC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAIjD,mEAAmE;WACrD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKlD,OAAO,CAAC,MAAM,CAAC,KAAK;IAWpB,OAAO,CAAC,MAAM,CAAC,QAAQ;IASvB,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAS/B,OAAO,CAAC,MAAM,CAAC,cAAc;IAmB7B,OAAO,CAAC,MAAM,CAAC,eAAe;CAkB/B"}
|
|
@@ -0,0 +1,122 @@
|
|
|
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.SettingsSpecRegistry = void 0;
|
|
11
|
+
const fs = require("fs-extra");
|
|
12
|
+
const json5_1 = require("json5");
|
|
13
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
14
|
+
/**
|
|
15
|
+
* The registry of available [[SettingsGroupSpec]]s.
|
|
16
|
+
* The registry is used for editing Settings files and for finding default values for settings.
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
class SettingsSpecRegistry {
|
|
20
|
+
constructor() { } // singleton
|
|
21
|
+
/** Clear the contents of the registry and remove all event listeners.
|
|
22
|
+
* @note This is really only necessary for tests of the Settings system.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
static reset() {
|
|
26
|
+
this._allGroups.clear();
|
|
27
|
+
this.allSpecs.clear();
|
|
28
|
+
this.onSpecsChanged.clear();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Add one or more [[SettingsGroupSpec]]s to the registry. `SettingsGroupSpec`s must include a `groupName` member that is used
|
|
32
|
+
* 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.
|
|
33
|
+
* @returns an array of problems found adding properties of the supplied group(s).
|
|
34
|
+
*/
|
|
35
|
+
static addGroup(settingsGroup) {
|
|
36
|
+
if (!Array.isArray(settingsGroup))
|
|
37
|
+
settingsGroup = [settingsGroup];
|
|
38
|
+
const problems = [];
|
|
39
|
+
this.doAdd(settingsGroup, problems);
|
|
40
|
+
this.onSpecsChanged.raiseEvent();
|
|
41
|
+
return problems;
|
|
42
|
+
}
|
|
43
|
+
/** Add a [[SettingsGroupSpec]] from stringified json5. */
|
|
44
|
+
static addJson(settingSpecJson) {
|
|
45
|
+
return this.addGroup((0, json5_1.parse)(settingSpecJson));
|
|
46
|
+
}
|
|
47
|
+
/** Add a [[SettingsGroupSpec]] from a json5 file. */
|
|
48
|
+
static addFile(fileName) {
|
|
49
|
+
return this.addJson(fs.readFileSync(fileName, "utf-8"));
|
|
50
|
+
}
|
|
51
|
+
/** Remove a previously added [[SettingsGroupSpec]] by groupName */
|
|
52
|
+
static removeGroup(groupName) {
|
|
53
|
+
this.doRemove(groupName);
|
|
54
|
+
this.onSpecsChanged.raiseEvent();
|
|
55
|
+
}
|
|
56
|
+
static doAdd(settingsGroup, problems) {
|
|
57
|
+
settingsGroup.forEach((group) => {
|
|
58
|
+
if (undefined === group.groupName)
|
|
59
|
+
throw new Error("settings group has no name");
|
|
60
|
+
this.doRemove(group.groupName);
|
|
61
|
+
this.validateAndAdd(group, problems);
|
|
62
|
+
this._allGroups.set(group.groupName, group);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
static doRemove(groupName) {
|
|
66
|
+
const group = this._allGroups.get(groupName);
|
|
67
|
+
if (undefined !== (group === null || group === void 0 ? void 0 : group.properties)) {
|
|
68
|
+
for (const key of Object.keys(group.properties))
|
|
69
|
+
this.allSpecs.delete(key);
|
|
70
|
+
}
|
|
71
|
+
this._allGroups.delete(groupName);
|
|
72
|
+
}
|
|
73
|
+
static validateProperty(property) {
|
|
74
|
+
if (!property.trim())
|
|
75
|
+
return "empty property name";
|
|
76
|
+
if (this.allSpecs.has(property))
|
|
77
|
+
return `property "${property}" is already defined`;
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
static validateAndAdd(group, problems) {
|
|
81
|
+
var _a;
|
|
82
|
+
const properties = group.properties;
|
|
83
|
+
if (undefined === properties)
|
|
84
|
+
return;
|
|
85
|
+
for (const key of Object.keys(properties)) {
|
|
86
|
+
const problem = this.validateProperty(key);
|
|
87
|
+
if (problem) {
|
|
88
|
+
problems === null || problems === void 0 ? void 0 : problems.push(problem);
|
|
89
|
+
delete properties[key];
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const property = properties[key];
|
|
93
|
+
property.default = (_a = property.default) !== null && _a !== void 0 ? _a : this.getDefaultValue(property.type);
|
|
94
|
+
this.allSpecs.set(key, property);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
static getDefaultValue(type) {
|
|
98
|
+
type = Array.isArray(type) ? type[0] : type;
|
|
99
|
+
switch (type) {
|
|
100
|
+
case "boolean":
|
|
101
|
+
return false;
|
|
102
|
+
case "integer":
|
|
103
|
+
case "number":
|
|
104
|
+
return 0;
|
|
105
|
+
case "string":
|
|
106
|
+
return "";
|
|
107
|
+
case "array":
|
|
108
|
+
return [];
|
|
109
|
+
case "object":
|
|
110
|
+
return {};
|
|
111
|
+
default:
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.SettingsSpecRegistry = SettingsSpecRegistry;
|
|
117
|
+
SettingsSpecRegistry._allGroups = new Map();
|
|
118
|
+
/** a map of all registered [[SettingSpec]]s */
|
|
119
|
+
SettingsSpecRegistry.allSpecs = new Map();
|
|
120
|
+
/** event that signals that the values in [[allSpecs]] have changed in some way. */
|
|
121
|
+
SettingsSpecRegistry.onSpecsChanged = new core_bentley_1.BeEvent();
|
|
122
|
+
//# sourceMappingURL=SettingsSpecRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsSpecRegistry.js","sourceRoot":"","sources":["../../../src/workspace/SettingsSpecRegistry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAA+B;AAC/B,iCAA8B;AAC9B,sDAAuG;AA8BvG;;;;GAIG;AACH,MAAa,oBAAoB;IAC/B,gBAAwB,CAAC,CAAC,YAAY;IAOtC;;;OAGG;IACI,MAAM,CAAC,KAAK;QACjB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,aAAsD;QAC3E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;YAC/B,aAAa,GAAG,CAAC,aAAa,CAAC,CAAC;QAElC,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QACpC,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,0DAA0D;IACnD,MAAM,CAAC,OAAO,CAAC,eAAuB;QAC3C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,qDAAqD;IAC9C,MAAM,CAAC,OAAO,CAAC,QAAgB;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,C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ACX,OAAO,EAAE,CAAC;YACZ;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC;;AAlHH,oDAmHC;AAjHyB,+BAAU,GAAG,IAAI,GAAG,EAA6B,CAAC;AAC1E,+CAA+C;AACxB,6BAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;AACjE,mFAAmF;AAC5D,mCAAc,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 { BeEvent, JSONSchema, JSONSchemaType, JSONSchemaTypeName, Mutable } from \"@itwin/core-bentley\";\r\n\r\n/**\r\n * The properties of a 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 * @beta\r\n */\r\nexport interface SettingSpec extends Readonly<JSONSchema> {\r\n type: JSONSchemaTypeName | JSONSchemaTypeName[];\r\n /** labels for items of an enum. */\r\n readonly enumItemLabels?: string[];\r\n /** whether the editor should show multiple lines. */\r\n readonly multilineEdit?: true;\r\n}\r\n\r\n/**\r\n * The properties of a group of [[SettingSpec]]s for an application. Groups can be added and removed from the registry\r\n * and are identified by their (required) `groupName` member\r\n * @beta\r\n */\r\nexport interface SettingsGroupSpec {\r\n readonly groupName: string;\r\n readonly properties: { [name: string]: SettingSpec };\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 [[SettingsGroupSpec]]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 SettingsSpecRegistry {\r\n private constructor() { } // singleton\r\n private static readonly _allGroups = new Map<string, SettingsGroupSpec>();\r\n /** a map of all registered [[SettingSpec]]s */\r\n public static readonly allSpecs = new Map<string, SettingSpec>();\r\n /** event that signals that the values in [[allSpecs]] have changed in some way. */\r\n public static readonly onSpecsChanged = 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.allSpecs.clear();\r\n this.onSpecsChanged.clear();\r\n }\r\n\r\n /**\r\n * Add one or more [[SettingsGroupSpec]]s to the registry. `SettingsGroupSpec`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 * @returns an array of problems found adding properties of the supplied group(s).\r\n */\r\n public static addGroup(settingsGroup: SettingsGroupSpec | SettingsGroupSpec[]): string[] {\r\n if (!Array.isArray(settingsGroup))\r\n settingsGroup = [settingsGroup];\r\n\r\n const problems: string[] = [];\r\n this.doAdd(settingsGroup, problems);\r\n this.onSpecsChanged.raiseEvent();\r\n return problems;\r\n }\r\n\r\n /** Add a [[SettingsGroupSpec]] from stringified json5. */\r\n public static addJson(settingSpecJson: string): string[] {\r\n return this.addGroup(parse(settingSpecJson));\r\n }\r\n\r\n /** Add a [[SettingsGroupSpec]] from a json5 file. */\r\n public static addFile(fileName: string): string[] {\r\n return this.addJson(fs.readFileSync(fileName, \"utf-8\"));\r\n }\r\n\r\n /** Remove a previously added [[SettingsGroupSpec]] by groupName */\r\n public static removeGroup(groupName: string): void {\r\n this.doRemove(groupName);\r\n this.onSpecsChanged.raiseEvent();\r\n }\r\n\r\n private static doAdd(settingsGroup: SettingsGroupSpec[], problems?: string[]) {\r\n settingsGroup.forEach((group) => {\r\n if (undefined === group.groupName)\r\n throw new Error(\"settings group has no name\");\r\n\r\n this.doRemove(group.groupName);\r\n this.validateAndAdd(group, problems);\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.allSpecs.delete(key);\r\n }\r\n this._allGroups.delete(groupName);\r\n }\r\n\r\n private static validateProperty(property: string): string | undefined {\r\n if (!property.trim())\r\n return \"empty property name\";\r\n if (this.allSpecs.has(property))\r\n return `property \"${property}\" is already defined`;\r\n\r\n return undefined;\r\n }\r\n\r\n private static validateAndAdd(group: SettingsGroupSpec, problems?: string[]) {\r\n const properties = group.properties;\r\n if (undefined === properties)\r\n return;\r\n\r\n for (const key of Object.keys(properties)) {\r\n const problem = this.validateProperty(key);\r\n if (problem) {\r\n problems?.push(problem);\r\n delete properties[key];\r\n continue;\r\n }\r\n\r\n const property: Mutable<SettingSpec> = properties[key];\r\n property.default = property.default ?? this.getDefaultValue(property.type);\r\n this.allSpecs.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"]}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Workspace
|
|
3
|
+
*/
|
|
4
|
+
import { CloudSqlite, IModelJsNative } from "@bentley/imodeljs-native";
|
|
5
|
+
import { BeEvent, Optional } from "@itwin/core-bentley";
|
|
6
|
+
import { LocalDirName, LocalFileName } from "@itwin/core-common";
|
|
7
|
+
import { SQLiteDb } from "../SQLiteDb";
|
|
8
|
+
import { Settings, SettingsPriority } from "./Settings";
|
|
9
|
+
/**
|
|
10
|
+
* The name of a WorkspaceContainer. This is the user-supplied name of a WorkspaceContainer, used to specify its *purpose* within a workspace.
|
|
11
|
+
* WorkspaceContainerName can be "aliased" by `WorkspaceSetting.containerAlias` settings so that "resolved" [[WorkspaceContainerId]] that supplies
|
|
12
|
+
* the actual WorkspaceContainer for a WorkspaceContainerName may vary. Also note that more than one WorkspaceContainerName may resolve to the same
|
|
13
|
+
* WorkspaceContainerId, if multiple purposes are served by the same WorkspaceContainer.
|
|
14
|
+
* @note there are no constraints on the contents or length of `WorkspaceContainerName`s, although short descriptive names are recommended.
|
|
15
|
+
* However, when no alias exists in WorkspaceSetting.containerAlias for a WorkspaceContainerName, then the WorkspaceContainerName becomes
|
|
16
|
+
* the WorkspaceContainerId, and the constraints on WorkspaceContainerId apply.
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
export declare type WorkspaceContainerName = string;
|
|
20
|
+
/**
|
|
21
|
+
* The unique identifier of a WorkspaceContainer. This becomes the base name for the local directory holding the WorkspaceDbs from a WorkspaceContainer.
|
|
22
|
+
* `WorkspaceContainerName`s are resolved to WorkspaceContainerId through `WorkspaceSetting.containerAlias` settings,
|
|
23
|
+
* so users may not recognize the actual WorkspaceContainerId supplying resources for a WorkspaceDbName.
|
|
24
|
+
*
|
|
25
|
+
* `WorkspaceContainerId`s :
|
|
26
|
+
* - may only contain lower case letters, numbers or dashes
|
|
27
|
+
* - may not start or end with with a dash
|
|
28
|
+
* - be shorter than 3 or longer than 63 characters
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export declare type WorkspaceContainerId = string;
|
|
32
|
+
/** The name of a WorkspaceDb within a WorkspaceContainer.
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
export declare type WorkspaceDbName = string;
|
|
36
|
+
/**
|
|
37
|
+
* The version name for a WorkspaceDb. More than one version of a WorkspaceDb may be stored in the same WorkspaceContainer. This
|
|
38
|
+
* string identifies a specific version.
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export declare type WorkspaceDbVersion = string;
|
|
42
|
+
/**
|
|
43
|
+
* The name for identifying WorkspaceResources in a [[WorkspaceDb]].
|
|
44
|
+
* * `WorkspaceResourceName`s may not:
|
|
45
|
+
* - be blank or start or end with a space
|
|
46
|
+
* - be longer than 1024 characters
|
|
47
|
+
* @note a single WorkspaceDb may hold WorkspaceResources of type 'blob', 'string' and 'file', all with the same WorkspaceResourceName.
|
|
48
|
+
* @beta
|
|
49
|
+
*/
|
|
50
|
+
export declare type WorkspaceResourceName = string;
|
|
51
|
+
/** supply either container name of id, not both
|
|
52
|
+
* @beta
|
|
53
|
+
*/
|
|
54
|
+
export declare type ContainerNameOrId = {
|
|
55
|
+
containerName: WorkspaceContainerName;
|
|
56
|
+
containerId?: never;
|
|
57
|
+
} | {
|
|
58
|
+
containerId: WorkspaceContainerId;
|
|
59
|
+
containerName?: never;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Properties that specify a WorkspaceContainer.
|
|
63
|
+
* This can either be a WorkspaceContainerName or a WorkspaceContainerId. If id is supplied,
|
|
64
|
+
* it is used directly. Otherwise name must be resolved via [[Workspace.resolveContainerId]].
|
|
65
|
+
* @beta
|
|
66
|
+
*/
|
|
67
|
+
export declare type WorkspaceContainerProps = ContainerNameOrId & {
|
|
68
|
+
cloudProps?: CloudSqlite.TransferProps;
|
|
69
|
+
};
|
|
70
|
+
/** Properties of a WorkspaceDb
|
|
71
|
+
* @beta
|
|
72
|
+
*/
|
|
73
|
+
export declare type WorkspaceDbProps = WorkspaceContainerProps & {
|
|
74
|
+
/** the name of the WorkspaceDb */
|
|
75
|
+
dbName: WorkspaceDbName;
|
|
76
|
+
};
|
|
77
|
+
/** Properties that specify a WorkspaceResource within a WorkspaceDb.
|
|
78
|
+
* @beta
|
|
79
|
+
*/
|
|
80
|
+
export declare type WorkspaceResourceProps = WorkspaceDbProps & {
|
|
81
|
+
/** the name of the resource within [[db]] */
|
|
82
|
+
rscName: WorkspaceResourceName;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* A WorkspaceDb holds workspace resources. `WorkspaceDb`s may just be local files, or they may be stored and
|
|
86
|
+
* synchronized in WorkspaceContainers. Each `WorkspaceResource` in a WorkspaceDb is identified by a [[WorkspaceResourceName]].
|
|
87
|
+
* Resources of type `string` and `blob` may be loaded directly from the `WorkspaceDb`. Resources of type `file` are
|
|
88
|
+
* copied from the WorkspaceDb into a temporary local file so they can be accessed directly.
|
|
89
|
+
* @beta
|
|
90
|
+
*/
|
|
91
|
+
export interface WorkspaceDb {
|
|
92
|
+
readonly container: WorkspaceContainer;
|
|
93
|
+
/** The WorkspaceDbName of this WorkspaceDb. */
|
|
94
|
+
readonly dbName: WorkspaceDbName;
|
|
95
|
+
/** event raised when this WorkspaceDb is closed. */
|
|
96
|
+
readonly onClosed: BeEvent<() => void>;
|
|
97
|
+
/** The name of the local file for holding this WorkspaceDb. */
|
|
98
|
+
readonly localFile: LocalDirName;
|
|
99
|
+
/** Get a string resource from this WorkspaceDb, if present. */
|
|
100
|
+
getString(rscName: WorkspaceResourceName): string | undefined;
|
|
101
|
+
/** Get a blob resource from this WorkspaceDb, if present. */
|
|
102
|
+
getBlob(rscName: WorkspaceResourceName): Uint8Array | undefined;
|
|
103
|
+
/** @internal */
|
|
104
|
+
getBlobReader(rscName: WorkspaceResourceName): IModelJsNative.BlobIO;
|
|
105
|
+
/** Extract a local copy of a file resource from this WorkspaceDb, if present.
|
|
106
|
+
* @param rscName The name of the file resource in the WorkspaceDb
|
|
107
|
+
* @param targetFileName optional name for extracted file. Some applications require files in specific locations or filenames. If
|
|
108
|
+
* you know the full path to use for the extracted file, you can supply it. Generally, it is best to *not* supply the filename and
|
|
109
|
+
* keep the extracted files in the container filesDir.
|
|
110
|
+
* @returns the full path to a file on the local filesystem.
|
|
111
|
+
* @note The file is copied from the file into the local filesystem so it may be accessed directly. This happens only
|
|
112
|
+
* as necessary, if the local file doesn't exist, or if it is out-of-date because it was updated in the file.
|
|
113
|
+
* For this reason, you should not save the local file name, and instead call this method every time you access it, so its
|
|
114
|
+
* content is always holds the correct version.
|
|
115
|
+
* @note The filename will be a hash value, not the resource name.
|
|
116
|
+
* @note Workspace resource files are set readonly as they are copied from the file.
|
|
117
|
+
* To edit them, you must first copy them to another location.
|
|
118
|
+
*/
|
|
119
|
+
getFile(rscName: WorkspaceResourceName, targetFileName?: LocalFileName): LocalFileName | undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for constructing a [[Workspace]].
|
|
123
|
+
* @beta
|
|
124
|
+
*/
|
|
125
|
+
export interface WorkspaceOpts {
|
|
126
|
+
/** The local directory for the WorkspaceDb files. The [[Workspace]] will (only) look in this directory
|
|
127
|
+
* for files named `${this.containerId}/${this.dbId}.itwin-workspace`.
|
|
128
|
+
* @note if not supplied, defaults to `iTwin/Workspace` in the user-local folder.
|
|
129
|
+
*/
|
|
130
|
+
containerDir?: LocalDirName;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Settings and resources that customize an application for the current session.
|
|
134
|
+
* See [Workspaces]($docs/learning/backend/Workspace)
|
|
135
|
+
* @beta
|
|
136
|
+
*/
|
|
137
|
+
export interface Workspace {
|
|
138
|
+
/** The local directory for the WorkspaceDb files with the name `${containerId}.itwin-workspace`. */
|
|
139
|
+
readonly containerDir: LocalDirName;
|
|
140
|
+
/** The [[Settings]] for this Workspace */
|
|
141
|
+
readonly settings: Settings;
|
|
142
|
+
getContainer(props: WorkspaceContainerProps): WorkspaceContainer;
|
|
143
|
+
/**
|
|
144
|
+
* Resolve a WorkspaceContainerProps to a WorkspaceContainerId. If props is an object with an `id` member, that value is returned unchanged.
|
|
145
|
+
* If it is a string, then the highest priority [[WorkspaceSetting.containerAlias]] setting with an entry for the WorkspaceContainerName
|
|
146
|
+
* is used. If no WorkspaceSetting.containerAlias entry for the WorkspaceContainerName can be found, the name is returned as the id.
|
|
147
|
+
*/
|
|
148
|
+
resolveContainerId(props: WorkspaceContainerProps): WorkspaceContainerId;
|
|
149
|
+
/**
|
|
150
|
+
* Get an open [[WorkspaceDb]]. If the WorkspaceDb is present but not open, it is opened first.
|
|
151
|
+
* If `cloudProps` are supplied, and if container is not present or not up-to-date, it is downloaded first.
|
|
152
|
+
* @returns a Promise that is resolved when the container is local, opened, and available for access.
|
|
153
|
+
*/
|
|
154
|
+
getWorkspaceDb(props: WorkspaceDbProps): Promise<WorkspaceDb>;
|
|
155
|
+
/** Load a WorkspaceResource of type string, parse it, and add it to the current Settings for this Workspace.
|
|
156
|
+
* @note settingsRsc must specify a resource holding a stringified JSON representation of a [[SettingDictionary]]
|
|
157
|
+
* @returns a Promise that is resolved when the settings resource has been loaded.
|
|
158
|
+
*/
|
|
159
|
+
loadSettingsDictionary(settingRsc: WorkspaceResourceProps, priority: SettingsPriority): Promise<void>;
|
|
160
|
+
/** Close this Workspace. All WorkspaceContainers are dropped. */
|
|
161
|
+
close(): void;
|
|
162
|
+
}
|
|
163
|
+
/** A WorkspaceContainer holds WorkspaceDbs.
|
|
164
|
+
* @beta
|
|
165
|
+
*/
|
|
166
|
+
export interface WorkspaceContainer {
|
|
167
|
+
readonly dirName: LocalDirName;
|
|
168
|
+
/** the local directory where this WorkspaceContainer will store temporary files extracted for file-resources. */
|
|
169
|
+
readonly filesDir: LocalDirName;
|
|
170
|
+
readonly id: WorkspaceContainerId;
|
|
171
|
+
readonly workspace: Workspace;
|
|
172
|
+
/** @internal */
|
|
173
|
+
addWorkspaceDb(toAdd: ITwinWorkspaceDb): void;
|
|
174
|
+
getWorkspaceDb(props: Optional<WorkspaceDbProps, "containerName">): Promise<WorkspaceDb>;
|
|
175
|
+
/** Close and remove a currently opened [[WorkspaceDb]] from this Workspace. */
|
|
176
|
+
dropWorkspaceDb(container: WorkspaceDb): void;
|
|
177
|
+
/** Close this WorkspaceContainer. All currently opened WorkspaceDbs are dropped. */
|
|
178
|
+
close(): void;
|
|
179
|
+
}
|
|
180
|
+
/** @internal */
|
|
181
|
+
export declare class ITwinWorkspace implements Workspace {
|
|
182
|
+
private _containers;
|
|
183
|
+
readonly containerDir: LocalDirName;
|
|
184
|
+
readonly settings: Settings;
|
|
185
|
+
constructor(settings: Settings, opts?: WorkspaceOpts);
|
|
186
|
+
addContainer(toAdd: ITwinWorkspaceContainer): void;
|
|
187
|
+
getContainer(props: WorkspaceContainerProps): WorkspaceContainer;
|
|
188
|
+
getWorkspaceDb(props: WorkspaceDbProps): Promise<WorkspaceDb>;
|
|
189
|
+
loadSettingsDictionary(settingRsc: WorkspaceResourceProps, priority: SettingsPriority): Promise<void>;
|
|
190
|
+
close(): void;
|
|
191
|
+
resolveContainerId(props: WorkspaceContainerProps): WorkspaceContainerId;
|
|
192
|
+
}
|
|
193
|
+
/** @internal */
|
|
194
|
+
export declare class ITwinWorkspaceContainer implements WorkspaceContainer {
|
|
195
|
+
readonly workspace: ITwinWorkspace;
|
|
196
|
+
readonly filesDir: LocalDirName;
|
|
197
|
+
readonly id: WorkspaceContainerId;
|
|
198
|
+
private _wsDbs;
|
|
199
|
+
get dirName(): string;
|
|
200
|
+
/** rules for ContainerIds (from Azure, see https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata)
|
|
201
|
+
* - may only contain lower case letters, numbers or dashes
|
|
202
|
+
* - may not start or end with with a dash nor have more than one dash in a row
|
|
203
|
+
* - may not be shorter than 3 or longer than 63 characters
|
|
204
|
+
*/
|
|
205
|
+
private static validateContainerId;
|
|
206
|
+
constructor(workspace: ITwinWorkspace, id: WorkspaceContainerId);
|
|
207
|
+
addWorkspaceDb(toAdd: ITwinWorkspaceDb): void;
|
|
208
|
+
getWorkspaceDb(props: Optional<WorkspaceDbProps, "containerName">): Promise<WorkspaceDb>;
|
|
209
|
+
dropWorkspaceDb(toDrop: WorkspaceDb): void;
|
|
210
|
+
close(): void;
|
|
211
|
+
purgeContainerFiles(): void;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* A local file holding a WorkspaceDb.
|
|
215
|
+
* @beta
|
|
216
|
+
*/
|
|
217
|
+
export declare class ITwinWorkspaceDb implements WorkspaceDb {
|
|
218
|
+
readonly sqliteDb: SQLiteDb;
|
|
219
|
+
readonly dbName: WorkspaceDbName;
|
|
220
|
+
readonly container: WorkspaceContainer;
|
|
221
|
+
localFile: LocalFileName;
|
|
222
|
+
readonly onClosed: BeEvent<() => void>;
|
|
223
|
+
protected static noLeadingOrTrailingSpaces(name: string, msg: string): void;
|
|
224
|
+
private static validateDbName;
|
|
225
|
+
get isOpen(): boolean;
|
|
226
|
+
queryFileResource(rscName: WorkspaceResourceName): {
|
|
227
|
+
localFileName: string;
|
|
228
|
+
info: IModelJsNative.EmbedFileQuery;
|
|
229
|
+
} | undefined;
|
|
230
|
+
constructor(dbName: WorkspaceDbName, container: WorkspaceContainer);
|
|
231
|
+
open(): void;
|
|
232
|
+
close(): void;
|
|
233
|
+
getString(rscName: WorkspaceResourceName): string | undefined;
|
|
234
|
+
/** Get a BlobIO reader for a blob WorkspaceResource.
|
|
235
|
+
* @note when finished, caller must call `close` on the BlobIO.
|
|
236
|
+
*/
|
|
237
|
+
getBlobReader(rscName: WorkspaceResourceName): IModelJsNative.BlobIO;
|
|
238
|
+
getBlob(rscName: WorkspaceResourceName): Uint8Array | undefined;
|
|
239
|
+
getFile(rscName: WorkspaceResourceName, targetFileName?: LocalFileName): LocalFileName | undefined;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* An editable [[WorkspaceDb]]. This is used by administrators for creating and modifying `WorkspaceDb`s.
|
|
243
|
+
* For cloud-backed containers, the write token must be obtained before this class may be used. Only one user at at time
|
|
244
|
+
* may be editing.
|
|
245
|
+
* @beta
|
|
246
|
+
*/
|
|
247
|
+
export declare class EditableWorkspaceDb extends ITwinWorkspaceDb {
|
|
248
|
+
private _isCloudOpen;
|
|
249
|
+
private static validateResourceName;
|
|
250
|
+
private validateResourceSize;
|
|
251
|
+
open(): void;
|
|
252
|
+
close(): void;
|
|
253
|
+
private getFileModifiedTime;
|
|
254
|
+
private performWriteSql;
|
|
255
|
+
/** Create a new, empty, EditableWorkspaceDb for importing Workspace resources. */
|
|
256
|
+
create(): void;
|
|
257
|
+
static cloneVersion(oldVersion: WorkspaceDbVersion, newVersion: WorkspaceDbVersion, cloudProps: CloudSqlite.ContainerAccessProps): Promise<void>;
|
|
258
|
+
upload(cloudProps: CloudSqlite.TransferProps): Promise<void>;
|
|
259
|
+
/** Add a new string resource to this WorkspaceDb.
|
|
260
|
+
* @param rscName The name of the string resource.
|
|
261
|
+
* @param val The string to save.
|
|
262
|
+
*/
|
|
263
|
+
addString(rscName: WorkspaceResourceName, val: string): void;
|
|
264
|
+
/** Update an existing string resource with a new value.
|
|
265
|
+
* @param rscName The name of the string resource.
|
|
266
|
+
* @param val The new value.
|
|
267
|
+
* @throws if rscName does not exist
|
|
268
|
+
*/
|
|
269
|
+
updateString(rscName: WorkspaceResourceName, val: string): void;
|
|
270
|
+
/** Remove a string resource. */
|
|
271
|
+
removeString(rscName: WorkspaceResourceName): void;
|
|
272
|
+
/** Add a new blob resource to this WorkspaceDb.
|
|
273
|
+
* @param rscName The name of the blob resource.
|
|
274
|
+
* @param val The blob to save.
|
|
275
|
+
*/
|
|
276
|
+
addBlob(rscName: WorkspaceResourceName, val: Uint8Array): void;
|
|
277
|
+
/** Update an existing blob resource with a new value.
|
|
278
|
+
* @param rscName The name of the blob resource.
|
|
279
|
+
* @param val The new value.
|
|
280
|
+
* @throws if rscName does not exist
|
|
281
|
+
*/
|
|
282
|
+
updateBlob(rscName: WorkspaceResourceName, val: Uint8Array): void;
|
|
283
|
+
/** Get a BlobIO writer for a previously-added blob WorkspaceResource.
|
|
284
|
+
* @note after writing is complete, caller must call `close` on the BlobIO and must call `saveChanges` on the `db`.
|
|
285
|
+
*/
|
|
286
|
+
getBlobWriter(rscName: WorkspaceResourceName): IModelJsNative.BlobIO;
|
|
287
|
+
/** Remove a blob resource. */
|
|
288
|
+
removeBlob(rscName: WorkspaceResourceName): void;
|
|
289
|
+
/** Copy the contents of an existing local file into this WorkspaceDb as a file resource.
|
|
290
|
+
* @param rscName The name of the file resource.
|
|
291
|
+
* @param localFileName The name of a local file to be read.
|
|
292
|
+
* @param fileExt The extension (do not include the leading ".") to be appended to the generated fileName
|
|
293
|
+
* when this WorkspaceDb is extracted from the WorkspaceDb. By default the characters after the last "." in `localFileName`
|
|
294
|
+
* are used. Pass this argument to override that.
|
|
295
|
+
*/
|
|
296
|
+
addFile(rscName: WorkspaceResourceName, localFileName: LocalFileName, fileExt?: string): void;
|
|
297
|
+
/** Replace an existing file resource with the contents of a local file.
|
|
298
|
+
* @param rscName The name of the file resource.
|
|
299
|
+
* @param localFileName The name of a local file to be read.
|
|
300
|
+
* @throws if rscName does not exist
|
|
301
|
+
*/
|
|
302
|
+
updateFile(rscName: WorkspaceResourceName, localFileName: LocalFileName): void;
|
|
303
|
+
/** Remove a file resource. */
|
|
304
|
+
removeFile(rscName: WorkspaceResourceName): void;
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=Workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../../src/workspace/Workspace.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAE,OAAO,EAAsB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAe,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAaxD;;;;;;;;;GASG;AACH,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,oBAAY,oBAAoB,GAAG,MAAM,CAAC;AAE1C;;GAEG;AACH,oBAAY,eAAe,GAAG,MAAM,CAAC;AAErC;;;;G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