@itwin/presentation-backend 4.0.0-dev.8 → 4.0.0-dev.81
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 +47 -1
- package/lib/cjs/assets/primary-presentation-rules/ElementProperties.PresentationRuleSet.json +14 -14
- package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +726 -762
- package/lib/cjs/assets/supplemental-presentation-rules/Functional.PresentationRuleSet.json +139 -139
- package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +41 -41
- package/lib/cjs/presentation-backend/BackendLoggerCategory.js +50 -50
- package/lib/cjs/presentation-backend/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/presentation-backend/Constants.d.ts +8 -8
- package/lib/cjs/presentation-backend/Constants.js +40 -36
- package/lib/cjs/presentation-backend/Constants.js.map +1 -1
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +11 -11
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +272 -274
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.d.ts +87 -87
- package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.js +147 -140
- package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.d.ts +106 -106
- package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.js +148 -150
- package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +11 -12
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js +30 -41
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.d.ts +463 -445
- package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.js +317 -311
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +61 -61
- package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js +442 -430
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +62 -62
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +388 -388
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +102 -102
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.js +287 -282
- package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetManager.d.ts +53 -53
- package/lib/cjs/presentation-backend/RulesetManager.js +73 -73
- package/lib/cjs/presentation-backend/RulesetManager.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +140 -140
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js +129 -129
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js.map +1 -1
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +28 -28
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js +226 -229
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +123 -123
- package/lib/cjs/presentation-backend/TemporaryStorage.js +151 -151
- package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -1
- package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +27 -27
- package/lib/cjs/presentation-backend/UpdatesTracker.js +54 -54
- package/lib/cjs/presentation-backend/UpdatesTracker.js.map +1 -1
- package/lib/cjs/presentation-backend/Utils.d.ts +49 -49
- package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Utils.js +107 -106
- package/lib/cjs/presentation-backend/Utils.js.map +1 -1
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +16 -16
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +55 -51
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -1
- package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +21 -21
- package/lib/cjs/presentation-backend/domain/RulesetElements.js +38 -38
- package/lib/cjs/presentation-backend/domain/RulesetElements.js.map +1 -1
- package/lib/cjs/presentation-backend.d.ts +19 -19
- package/lib/cjs/presentation-backend.js +39 -35
- package/lib/cjs/presentation-backend.js.map +1 -1
- package/package.json +20 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionScopesHelper.js","sourceRoot":"","sources":["../../../src/presentation-backend/SelectionScopesHelper.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAqF;AACrF,sDAAiE;AACjE,oEAGoC;AACpC,mCAAwC;AAExC;;;;;GAKG;AACH,MAAa,qBAAqB;IAEhC,uBAAuB;IACvB,gBAAwB,CAAC;IAElB,MAAM,CAAC,kBAAkB;QAC9B,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAE,KAAa,EAAE,WAAmB,EAAkB,EAAE,CAAC,CAAC;YACrG,EAAE,EAAE,OAAO;YACX,KAAK;YACL,WAAW;SACZ,CAAC,CAAC;QACH,OAAO;YACL,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,2BAA2B,CAAC;YACvE,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,qCAAqC,CAAC;YACnF,oBAAoB,CAAC,cAAc,EAAE,cAAc,EAAE,iDAAiD,CAAC;YACv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AAO,IAAI,CAAC,wBAAwB,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YACxG,KAAK,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YAClG,KAAK,YAAY,CAAC;YAClB,KAAK,oBAAoB;gBACvB,OAAO,IAAI,CAAC,iCAAiC,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YAClG,KAAK,qBAAqB,CAAC,CAAC,OAAO,IAAI,CAAC,kCAAkC,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YAC7H,KAAK,yBAAyB,CAAC,CAAC,OAAO,IAAI,CAAC,qCAAqC,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;SACrI;QACD,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CAEF;AAvND,sDAuNC;AAED,MAAM,cAAc,GAAG,CAAC,QAAkC,EAAE,EAAE;IAC5D,OAAO,CAAC,EAAc,EAAE,EAAE;QACxB,IAAI,CAAC,mBAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACvB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,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 Core\r\n */\r\n\r\nimport { GeometricElement, GeometricElement3d, IModelDb } from \"@itwin/core-backend\";\r\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n ComputeSelectionRequestOptions, ElementSelectionScopeProps, InstanceKey, isComputeSelectionRequestOptions, KeySet, PresentationError,\r\n PresentationStatus, SelectionScope, SelectionScopeRequestOptions,\r\n} from \"@itwin/presentation-common\";\r\nimport { getElementKey } from \"./Utils\";\r\n\r\n/**\r\n * Contains helper methods for computing selection scopes. Will get removed\r\n * once rules-driven scopes are implemented.\r\n *\r\n * @internal\r\n */\r\nexport class SelectionScopesHelper {\r\n\r\n // istanbul ignore next\r\n private constructor() { }\r\n\r\n public static getSelectionScopes(): SelectionScope[] {\r\n const createSelectionScope = (scopeId: string, label: string, description: string): SelectionScope => ({\r\n id: scopeId,\r\n label,\r\n description,\r\n });\r\n return [\r\n createSelectionScope(\"element\", \"Element\", \"Select the picked element\"),\r\n createSelectionScope(\"assembly\", \"Assembly\", \"Select parent of the picked element\"),\r\n createSelectionScope(\"top-assembly\", \"Top Assembly\", \"Select the topmost parent of the picked element\"),\r\n // WIP: temporarily comment-out \"category\" and \"model\" scopes since we can't hilite contents of them fast enough\r\n // createSelectionScope(\"category\", \"Category\", \"Select all elements in the picked element's category\"),\r\n // createSelectionScope(\"model\", \"Model\", \"Select all elements in the picked element's model\"),\r\n ];\r\n }\r\n\r\n private static getElementKey(iModel: IModelDb, elementId: Id64String, ancestorLevel: number) {\r\n let currId = elementId;\r\n let parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;\r\n while (parentId && ancestorLevel !== 0) {\r\n currId = parentId;\r\n parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;\r\n --ancestorLevel;\r\n }\r\n return getElementKey(iModel, currId);\r\n }\r\n\r\n private static computeElementSelection(iModel: IModelDb, elementIds: Id64String[], ancestorLevel: number) {\r\n const parentKeys = new KeySet();\r\n elementIds.forEach(skipTransients((id) => {\r\n const key = this.getElementKey(iModel, id, ancestorLevel);\r\n key && parentKeys.add(key);\r\n }));\r\n return parentKeys;\r\n }\r\n\r\n private static computeCategorySelection(iModel: IModelDb, ids: Id64String[]) {\r\n const categoryKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const el = iModel.elements.tryGetElement(id);\r\n if (el instanceof GeometricElement) {\r\n const category = iModel.elements.tryGetElementProps(el.category);\r\n if (category)\r\n categoryKeys.add({ className: category.classFullName, id: category.id! });\r\n }\r\n }));\r\n return categoryKeys;\r\n }\r\n\r\n private static computeModelSelection(iModel: IModelDb, ids: Id64String[]) {\r\n const modelKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const el = iModel.elements.tryGetElementProps(id);\r\n const model = el ? iModel.models.tryGetModelProps(el.model) : undefined;\r\n if (model)\r\n modelKeys.add({ className: model.classFullName, id: model.id! });\r\n }));\r\n return modelKeys;\r\n }\r\n\r\n private static getRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\r\n const query = `\r\n SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId\r\n FROM bis.Element e\r\n LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId\r\n LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId\r\n LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)\r\n INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId\r\n INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id\r\n WHERE e.ECInstanceId = ?\r\n `;\r\n return imodel.withPreparedStatement(query, (stmt): InstanceKey | undefined => {\r\n stmt.bindId(1, graphicalElementId);\r\n // istanbul ignore else\r\n if (DbResult.BE_SQLITE_ROW === stmt.step()) {\r\n const row = stmt.getRow();\r\n if (row.funcElClassName && row.funcElId)\r\n return { className: row.funcElClassName.replace(\".\", \":\"), id: row.funcElId };\r\n }\r\n return undefined;\r\n });\r\n }\r\n\r\n private static findFirstRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\r\n let currId: Id64String | undefined = graphicalElementId;\r\n while (currId) {\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);\r\n if (relatedFunctionalKey)\r\n return relatedFunctionalKey;\r\n currId = imodel.elements.tryGetElementProps(currId)?.parent?.id;\r\n }\r\n return undefined;\r\n }\r\n\r\n private static elementClassDerivesFrom(imodel: IModelDb, elementId: Id64String, baseClassFullName: string): boolean {\r\n const query = `\r\n SELECT 1\r\n FROM bis.Element e\r\n INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId\r\n INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId\r\n INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id\r\n WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?\r\n `;\r\n return imodel.withPreparedStatement(query, (stmt): boolean => {\r\n stmt.bindId(1, elementId);\r\n stmt.bindString(2, baseClassFullName);\r\n return (DbResult.BE_SQLITE_ROW === stmt.step());\r\n });\r\n }\r\n\r\n private static computeFunctionalElementSelection(iModel: IModelDb, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\r\n if (firstFunctionalKey) {\r\n keys.add(firstFunctionalKey);\r\n return;\r\n }\r\n }\r\n let keyToAdd: InstanceKey | undefined;\r\n if (is3d) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n keyToAdd = this.getRelatedFunctionalElementKey(iModel, id);\r\n }\r\n if (!keyToAdd)\r\n keyToAdd = getElementKey(iModel, id);\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static computeFunctionalAssemblySelection(iModel: IModelDb, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n let idToGetAssemblyFor = id;\r\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\r\n if (firstFunctionalKey)\r\n idToGetAssemblyFor = firstFunctionalKey.id;\r\n }\r\n // find the assembly of either the given element or the functional element\r\n const assemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, 1);\r\n let keyToAdd = assemblyKey;\r\n if (is3d && keyToAdd) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);\r\n if (relatedFunctionalKey)\r\n keyToAdd = relatedFunctionalKey;\r\n }\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static computeFunctionalTopAssemblySelection(iModel: IModelDb, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n let idToGetAssemblyFor = id;\r\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\r\n if (firstFunctionalKey)\r\n idToGetAssemblyFor = firstFunctionalKey.id;\r\n }\r\n // find the top assembly of either the given element or the functional element\r\n const topAssemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, Number.MAX_SAFE_INTEGER);\r\n let keyToAdd = topAssemblyKey;\r\n if (is3d && keyToAdd) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);\r\n if (relatedFunctionalKey)\r\n keyToAdd = relatedFunctionalKey;\r\n }\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n public static async computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet>;\r\n public static async computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb>): Promise<KeySet>;\r\n public static async computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb> | SelectionScopeRequestOptions<IModelDb>, elementIds?: Id64String[], scopeId?: string): Promise<KeySet> {\r\n if (!isComputeSelectionRequestOptions(requestOptions)) {\r\n return this.computeSelection({\r\n ...requestOptions,\r\n elementIds: elementIds!,\r\n scope: { id: scopeId! },\r\n });\r\n }\r\n\r\n switch (requestOptions.scope.id) {\r\n case \"element\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, (requestOptions.scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\r\n case \"assembly\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, 1);\r\n case \"top-assembly\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, Number.MAX_SAFE_INTEGER);\r\n case \"category\": return this.computeCategorySelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"model\": return this.computeModelSelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"functional\":\r\n case \"functional-element\":\r\n return this.computeFunctionalElementSelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"functional-assembly\": return this.computeFunctionalAssemblySelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"functional-top-assembly\": return this.computeFunctionalTopAssemblySelection(requestOptions.imodel, requestOptions.elementIds);\r\n }\r\n throw new PresentationError(PresentationStatus.InvalidArgument, \"scopeId\");\r\n }\r\n\r\n}\r\n\r\nconst skipTransients = (callback: (id: Id64String) => void) => {\r\n return (id: Id64String) => {\r\n if (!Id64.isTransient(id))\r\n callback(id);\r\n };\r\n};\r\n"]}
|
|
1
|
+
{"version":3,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AAC;CAEF;AAvND,sDAuNC;AAED,MAAM,cAAc,GAAG,CAAC,QAAkC,EAAE,EAAE;IAC5D,OAAO,CAAC,EAAc,EAAE,EAAE;QACxB,IAAI,CAAC,mBAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACvB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Core\n */\n\nimport { GeometricElement, GeometricElement3d, IModelDb } from \"@itwin/core-backend\";\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport {\n ComputeSelectionRequestOptions, ElementSelectionScopeProps, InstanceKey, isComputeSelectionRequestOptions, KeySet, PresentationError,\n PresentationStatus, SelectionScope, SelectionScopeRequestOptions,\n} from \"@itwin/presentation-common\";\nimport { getElementKey } from \"./Utils\";\n\n/**\n * Contains helper methods for computing selection scopes. Will get removed\n * once rules-driven scopes are implemented.\n *\n * @internal\n */\nexport class SelectionScopesHelper {\n\n // istanbul ignore next\n private constructor() { }\n\n public static getSelectionScopes(): SelectionScope[] {\n const createSelectionScope = (scopeId: string, label: string, description: string): SelectionScope => ({\n id: scopeId,\n label,\n description,\n });\n return [\n createSelectionScope(\"element\", \"Element\", \"Select the picked element\"),\n createSelectionScope(\"assembly\", \"Assembly\", \"Select parent of the picked element\"),\n createSelectionScope(\"top-assembly\", \"Top Assembly\", \"Select the topmost parent of the picked element\"),\n // WIP: temporarily comment-out \"category\" and \"model\" scopes since we can't hilite contents of them fast enough\n // createSelectionScope(\"category\", \"Category\", \"Select all elements in the picked element's category\"),\n // createSelectionScope(\"model\", \"Model\", \"Select all elements in the picked element's model\"),\n ];\n }\n\n private static getElementKey(iModel: IModelDb, elementId: Id64String, ancestorLevel: number) {\n let currId = elementId;\n let parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;\n while (parentId && ancestorLevel !== 0) {\n currId = parentId;\n parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;\n --ancestorLevel;\n }\n return getElementKey(iModel, currId);\n }\n\n private static computeElementSelection(iModel: IModelDb, elementIds: Id64String[], ancestorLevel: number) {\n const parentKeys = new KeySet();\n elementIds.forEach(skipTransients((id) => {\n const key = this.getElementKey(iModel, id, ancestorLevel);\n key && parentKeys.add(key);\n }));\n return parentKeys;\n }\n\n private static computeCategorySelection(iModel: IModelDb, ids: Id64String[]) {\n const categoryKeys = new KeySet();\n ids.forEach(skipTransients((id) => {\n const el = iModel.elements.tryGetElement(id);\n if (el instanceof GeometricElement) {\n const category = iModel.elements.tryGetElementProps(el.category);\n if (category)\n categoryKeys.add({ className: category.classFullName, id: category.id! });\n }\n }));\n return categoryKeys;\n }\n\n private static computeModelSelection(iModel: IModelDb, ids: Id64String[]) {\n const modelKeys = new KeySet();\n ids.forEach(skipTransients((id) => {\n const el = iModel.elements.tryGetElementProps(id);\n const model = el ? iModel.models.tryGetModelProps(el.model) : undefined;\n if (model)\n modelKeys.add({ className: model.classFullName, id: model.id! });\n }));\n return modelKeys;\n }\n\n private static getRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\n const query = `\n SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId\n FROM bis.Element e\n LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId\n LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId\n LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)\n INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId\n INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id\n WHERE e.ECInstanceId = ?\n `;\n return imodel.withPreparedStatement(query, (stmt): InstanceKey | undefined => {\n stmt.bindId(1, graphicalElementId);\n // istanbul ignore else\n if (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const row = stmt.getRow();\n if (row.funcElClassName && row.funcElId)\n return { className: row.funcElClassName.replace(\".\", \":\"), id: row.funcElId };\n }\n return undefined;\n });\n }\n\n private static findFirstRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\n let currId: Id64String | undefined = graphicalElementId;\n while (currId) {\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);\n if (relatedFunctionalKey)\n return relatedFunctionalKey;\n currId = imodel.elements.tryGetElementProps(currId)?.parent?.id;\n }\n return undefined;\n }\n\n private static elementClassDerivesFrom(imodel: IModelDb, elementId: Id64String, baseClassFullName: string): boolean {\n const query = `\n SELECT 1\n FROM bis.Element e\n INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId\n INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId\n INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id\n WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?\n `;\n return imodel.withPreparedStatement(query, (stmt): boolean => {\n stmt.bindId(1, elementId);\n stmt.bindString(2, baseClassFullName);\n return (DbResult.BE_SQLITE_ROW === stmt.step());\n });\n }\n\n private static computeFunctionalElementSelection(iModel: IModelDb, ids: Id64String[]) {\n const keys = new KeySet();\n ids.forEach(skipTransients((id): void => {\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\n if (!is3d) {\n // if the input is not a 3d element, we try to find the first related functional element\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\n if (firstFunctionalKey) {\n keys.add(firstFunctionalKey);\n return;\n }\n }\n let keyToAdd: InstanceKey | undefined;\n if (is3d) {\n // if we're computing scope for a 3d element, try to switch to its related functional element\n keyToAdd = this.getRelatedFunctionalElementKey(iModel, id);\n }\n if (!keyToAdd)\n keyToAdd = getElementKey(iModel, id);\n keyToAdd && keys.add(keyToAdd);\n }));\n return keys;\n }\n\n private static computeFunctionalAssemblySelection(iModel: IModelDb, ids: Id64String[]) {\n const keys = new KeySet();\n ids.forEach(skipTransients((id): void => {\n let idToGetAssemblyFor = id;\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\n if (!is3d) {\n // if the input is not a 3d element, we try to find the first related functional element\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\n if (firstFunctionalKey)\n idToGetAssemblyFor = firstFunctionalKey.id;\n }\n // find the assembly of either the given element or the functional element\n const assemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, 1);\n let keyToAdd = assemblyKey;\n if (is3d && keyToAdd) {\n // if we're computing scope for a 3d element, try to switch to its related functional element\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);\n if (relatedFunctionalKey)\n keyToAdd = relatedFunctionalKey;\n }\n keyToAdd && keys.add(keyToAdd);\n }));\n return keys;\n }\n\n private static computeFunctionalTopAssemblySelection(iModel: IModelDb, ids: Id64String[]) {\n const keys = new KeySet();\n ids.forEach(skipTransients((id): void => {\n let idToGetAssemblyFor = id;\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\n if (!is3d) {\n // if the input is not a 3d element, we try to find the first related functional element\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\n if (firstFunctionalKey)\n idToGetAssemblyFor = firstFunctionalKey.id;\n }\n // find the top assembly of either the given element or the functional element\n const topAssemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, Number.MAX_SAFE_INTEGER);\n let keyToAdd = topAssemblyKey;\n if (is3d && keyToAdd) {\n // if we're computing scope for a 3d element, try to switch to its related functional element\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);\n if (relatedFunctionalKey)\n keyToAdd = relatedFunctionalKey;\n }\n keyToAdd && keys.add(keyToAdd);\n }));\n return keys;\n }\n\n public static async computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet>;\n public static async computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb>): Promise<KeySet>;\n public static async computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb> | SelectionScopeRequestOptions<IModelDb>, elementIds?: Id64String[], scopeId?: string): Promise<KeySet> {\n if (!isComputeSelectionRequestOptions(requestOptions)) {\n return this.computeSelection({\n ...requestOptions,\n elementIds: elementIds!,\n scope: { id: scopeId! },\n });\n }\n\n switch (requestOptions.scope.id) {\n case \"element\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, (requestOptions.scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\n case \"assembly\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, 1);\n case \"top-assembly\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, Number.MAX_SAFE_INTEGER);\n case \"category\": return this.computeCategorySelection(requestOptions.imodel, requestOptions.elementIds);\n case \"model\": return this.computeModelSelection(requestOptions.imodel, requestOptions.elementIds);\n case \"functional\":\n case \"functional-element\":\n return this.computeFunctionalElementSelection(requestOptions.imodel, requestOptions.elementIds);\n case \"functional-assembly\": return this.computeFunctionalAssemblySelection(requestOptions.imodel, requestOptions.elementIds);\n case \"functional-top-assembly\": return this.computeFunctionalTopAssemblySelection(requestOptions.imodel, requestOptions.elementIds);\n }\n throw new PresentationError(PresentationStatus.InvalidArgument, \"scopeId\");\n }\n\n}\n\nconst skipTransients = (callback: (id: Id64String) => void) => {\n return (id: Id64String) => {\n if (!Id64.isTransient(id))\n callback(id);\n };\n};\n"]}
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Core
|
|
3
|
-
*/
|
|
4
|
-
import { IDisposable } from "@itwin/core-bentley";
|
|
5
|
-
/**
|
|
6
|
-
* Configuration properties for [[TemporaryStorage]].
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export interface TemporaryStorageProps<T> {
|
|
10
|
-
/** A method that's called for every value before it's removed from storage */
|
|
11
|
-
cleanupHandler?: (id: string, value: T, reason: "timeout" | "dispose" | "request") => void;
|
|
12
|
-
onDisposedSingle?: (id: string) => void;
|
|
13
|
-
onDisposedAll?: () => void;
|
|
14
|
-
/**
|
|
15
|
-
* An interval at which the storage attempts to clean up its values.
|
|
16
|
-
* When `0` or `undefined` is specified, values are not cleaned up
|
|
17
|
-
* automatically and cleanup has to be initiated manually by calling
|
|
18
|
-
* [[TemporaryStorage.disposeOutdatedValues]].
|
|
19
|
-
*/
|
|
20
|
-
cleanupInterval?: number;
|
|
21
|
-
/**
|
|
22
|
-
* Shortest period of time which the value should be kept in storage
|
|
23
|
-
* unused before it's cleaned up.
|
|
24
|
-
*
|
|
25
|
-
* `undefined` means the values may be kept unused in the storage indefinitely.
|
|
26
|
-
* `0` means the values are removed from the storage on every cleanup (either manual
|
|
27
|
-
* call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled
|
|
28
|
-
* by [[cleanupInterval]])).
|
|
29
|
-
*/
|
|
30
|
-
unusedValueLifetime?: number;
|
|
31
|
-
/**
|
|
32
|
-
* The maximum period of time which the value should be kept in storage
|
|
33
|
-
* before it's cleaned up. The time is measured from the moment the value is added
|
|
34
|
-
* to the storage.
|
|
35
|
-
*
|
|
36
|
-
* `undefined` means the values may be kept indefinitely. `0` means they're removed
|
|
37
|
-
* up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]]
|
|
38
|
-
* or scheduled (controlled by [[cleanupInterval]])).
|
|
39
|
-
*/
|
|
40
|
-
maxValueLifetime?: number;
|
|
41
|
-
}
|
|
42
|
-
/** Value with know last used time */
|
|
43
|
-
interface TemporaryValue<T> {
|
|
44
|
-
created: Date;
|
|
45
|
-
lastUsed: Date;
|
|
46
|
-
value: T;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Storage for values that get removed from it after being unused (not-requested
|
|
50
|
-
* for a specified amount of time).
|
|
51
|
-
*
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
export declare class TemporaryStorage<T> implements IDisposable {
|
|
55
|
-
private _timer?;
|
|
56
|
-
protected _values: Map<string, TemporaryValue<T>>;
|
|
57
|
-
readonly props: TemporaryStorageProps<T>;
|
|
58
|
-
/**
|
|
59
|
-
* Constructor. Creates the storage using supplied params.
|
|
60
|
-
*/
|
|
61
|
-
constructor(props: TemporaryStorageProps<T>);
|
|
62
|
-
/**
|
|
63
|
-
* Destructor. Must be called to clean up the stored values
|
|
64
|
-
* and other resources
|
|
65
|
-
*/
|
|
66
|
-
dispose(): void;
|
|
67
|
-
/**
|
|
68
|
-
* Cleans up values that are currently outdated (based
|
|
69
|
-
* on their max and unused value lifetimes specified through [[Props]]).
|
|
70
|
-
*/
|
|
71
|
-
disposeOutdatedValues: () => void;
|
|
72
|
-
private deleteExistingEntry;
|
|
73
|
-
/**
|
|
74
|
-
* Get a value from the storage.
|
|
75
|
-
*
|
|
76
|
-
* **Note:** requesting a value with this method updates it's last used time.
|
|
77
|
-
*/
|
|
78
|
-
getValue(id: string): T | undefined;
|
|
79
|
-
notifyValueUsed(id: string): void;
|
|
80
|
-
/**
|
|
81
|
-
* Adds a value into the storage.
|
|
82
|
-
* @throws An error when trying to add a value with ID that's already stored in the storage.
|
|
83
|
-
*/
|
|
84
|
-
addValue(id: string, value: T): void;
|
|
85
|
-
/** Deletes a value with given id. */
|
|
86
|
-
deleteValue(id: string): void;
|
|
87
|
-
/**
|
|
88
|
-
* Get all values currently in this storage.
|
|
89
|
-
*
|
|
90
|
-
* **Note:** requesting values with this method **doesn't**
|
|
91
|
-
* update their last used times.
|
|
92
|
-
*/
|
|
93
|
-
get values(): T[];
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Configuration properties for [[FactoryBasedTemporaryStorage]].
|
|
97
|
-
* @internal
|
|
98
|
-
*/
|
|
99
|
-
export interface FactoryBasedTemporaryStorageProps<T> extends TemporaryStorageProps<T> {
|
|
100
|
-
/** A factory method that creates a stored value given it's identifier */
|
|
101
|
-
factory: (id: string, onValueUsed: () => void) => T;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Storage for values that get removed from it after being unused (not-requested
|
|
105
|
-
* for a specified amount of time).
|
|
106
|
-
*
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
export declare class FactoryBasedTemporaryStorage<T> extends TemporaryStorage<T> {
|
|
110
|
-
readonly props: FactoryBasedTemporaryStorageProps<T>;
|
|
111
|
-
/**
|
|
112
|
-
* Constructor. Creates the storage using supplied params.
|
|
113
|
-
*/
|
|
114
|
-
constructor(props: FactoryBasedTemporaryStorageProps<T>);
|
|
115
|
-
/**
|
|
116
|
-
* Get a value from the storage. If the value with the specified id
|
|
117
|
-
* doesn't exist, it gets created.
|
|
118
|
-
*
|
|
119
|
-
* **Note:** requesting a value with this method updates it's last used time.
|
|
120
|
-
*/
|
|
121
|
-
getValue(id: string): T;
|
|
122
|
-
}
|
|
123
|
-
export {};
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Core
|
|
3
|
+
*/
|
|
4
|
+
import { IDisposable } from "@itwin/core-bentley";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration properties for [[TemporaryStorage]].
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface TemporaryStorageProps<T> {
|
|
10
|
+
/** A method that's called for every value before it's removed from storage */
|
|
11
|
+
cleanupHandler?: (id: string, value: T, reason: "timeout" | "dispose" | "request") => void;
|
|
12
|
+
onDisposedSingle?: (id: string) => void;
|
|
13
|
+
onDisposedAll?: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* An interval at which the storage attempts to clean up its values.
|
|
16
|
+
* When `0` or `undefined` is specified, values are not cleaned up
|
|
17
|
+
* automatically and cleanup has to be initiated manually by calling
|
|
18
|
+
* [[TemporaryStorage.disposeOutdatedValues]].
|
|
19
|
+
*/
|
|
20
|
+
cleanupInterval?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Shortest period of time which the value should be kept in storage
|
|
23
|
+
* unused before it's cleaned up.
|
|
24
|
+
*
|
|
25
|
+
* `undefined` means the values may be kept unused in the storage indefinitely.
|
|
26
|
+
* `0` means the values are removed from the storage on every cleanup (either manual
|
|
27
|
+
* call to [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled
|
|
28
|
+
* by [[cleanupInterval]])).
|
|
29
|
+
*/
|
|
30
|
+
unusedValueLifetime?: number;
|
|
31
|
+
/**
|
|
32
|
+
* The maximum period of time which the value should be kept in storage
|
|
33
|
+
* before it's cleaned up. The time is measured from the moment the value is added
|
|
34
|
+
* to the storage.
|
|
35
|
+
*
|
|
36
|
+
* `undefined` means the values may be kept indefinitely. `0` means they're removed
|
|
37
|
+
* up on every cleanup (either manual call to [[TemporaryStorage.disposeOutdatedValues]]
|
|
38
|
+
* or scheduled (controlled by [[cleanupInterval]])).
|
|
39
|
+
*/
|
|
40
|
+
maxValueLifetime?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Value with know last used time */
|
|
43
|
+
interface TemporaryValue<T> {
|
|
44
|
+
created: Date;
|
|
45
|
+
lastUsed: Date;
|
|
46
|
+
value: T;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Storage for values that get removed from it after being unused (not-requested
|
|
50
|
+
* for a specified amount of time).
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export declare class TemporaryStorage<T> implements IDisposable {
|
|
55
|
+
private _timer?;
|
|
56
|
+
protected _values: Map<string, TemporaryValue<T>>;
|
|
57
|
+
readonly props: TemporaryStorageProps<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Constructor. Creates the storage using supplied params.
|
|
60
|
+
*/
|
|
61
|
+
constructor(props: TemporaryStorageProps<T>);
|
|
62
|
+
/**
|
|
63
|
+
* Destructor. Must be called to clean up the stored values
|
|
64
|
+
* and other resources
|
|
65
|
+
*/
|
|
66
|
+
dispose(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Cleans up values that are currently outdated (based
|
|
69
|
+
* on their max and unused value lifetimes specified through [[Props]]).
|
|
70
|
+
*/
|
|
71
|
+
disposeOutdatedValues: () => void;
|
|
72
|
+
private deleteExistingEntry;
|
|
73
|
+
/**
|
|
74
|
+
* Get a value from the storage.
|
|
75
|
+
*
|
|
76
|
+
* **Note:** requesting a value with this method updates it's last used time.
|
|
77
|
+
*/
|
|
78
|
+
getValue(id: string): T | undefined;
|
|
79
|
+
notifyValueUsed(id: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Adds a value into the storage.
|
|
82
|
+
* @throws An error when trying to add a value with ID that's already stored in the storage.
|
|
83
|
+
*/
|
|
84
|
+
addValue(id: string, value: T): void;
|
|
85
|
+
/** Deletes a value with given id. */
|
|
86
|
+
deleteValue(id: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get all values currently in this storage.
|
|
89
|
+
*
|
|
90
|
+
* **Note:** requesting values with this method **doesn't**
|
|
91
|
+
* update their last used times.
|
|
92
|
+
*/
|
|
93
|
+
get values(): T[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configuration properties for [[FactoryBasedTemporaryStorage]].
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
export interface FactoryBasedTemporaryStorageProps<T> extends TemporaryStorageProps<T> {
|
|
100
|
+
/** A factory method that creates a stored value given it's identifier */
|
|
101
|
+
factory: (id: string, onValueUsed: () => void) => T;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Storage for values that get removed from it after being unused (not-requested
|
|
105
|
+
* for a specified amount of time).
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export declare class FactoryBasedTemporaryStorage<T> extends TemporaryStorage<T> {
|
|
110
|
+
readonly props: FactoryBasedTemporaryStorageProps<T>;
|
|
111
|
+
/**
|
|
112
|
+
* Constructor. Creates the storage using supplied params.
|
|
113
|
+
*/
|
|
114
|
+
constructor(props: FactoryBasedTemporaryStorageProps<T>);
|
|
115
|
+
/**
|
|
116
|
+
* Get a value from the storage. If the value with the specified id
|
|
117
|
+
* doesn't exist, it gets created.
|
|
118
|
+
*
|
|
119
|
+
* **Note:** requesting a value with this method updates it's last used time.
|
|
120
|
+
*/
|
|
121
|
+
getValue(id: string): T;
|
|
122
|
+
}
|
|
123
|
+
export {};
|
|
124
124
|
//# sourceMappingURL=TemporaryStorage.d.ts.map
|
|
@@ -1,152 +1,152 @@
|
|
|
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 Core
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.FactoryBasedTemporaryStorage = exports.TemporaryStorage = void 0;
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const presentation_common_1 = require("@itwin/presentation-common");
|
|
13
|
-
/**
|
|
14
|
-
* Storage for values that get removed from it after being unused (not-requested
|
|
15
|
-
* for a specified amount of time).
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
class TemporaryStorage {
|
|
20
|
-
/**
|
|
21
|
-
* Constructor. Creates the storage using supplied params.
|
|
22
|
-
*/
|
|
23
|
-
constructor(props) {
|
|
24
|
-
/**
|
|
25
|
-
* Cleans up values that are currently outdated (based
|
|
26
|
-
* on their max and unused value lifetimes specified through [[Props]]).
|
|
27
|
-
*/
|
|
28
|
-
this.disposeOutdatedValues = () => {
|
|
29
|
-
const now = (new Date()).getTime();
|
|
30
|
-
const valuesToDispose = [];
|
|
31
|
-
for (const [key, entry] of this._values.entries()) {
|
|
32
|
-
if (this.props.maxValueLifetime !== undefined) {
|
|
33
|
-
if (this.props.maxValueLifetime === 0 || (now - entry.created.getTime()) > this.props.maxValueLifetime) {
|
|
34
|
-
valuesToDispose.push(key);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (this.props.unusedValueLifetime !== undefined) {
|
|
39
|
-
if (this.props.unusedValueLifetime === 0 || (now - entry.lastUsed.getTime()) > this.props.unusedValueLifetime) {
|
|
40
|
-
valuesToDispose.push(key);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
for (const id of valuesToDispose)
|
|
46
|
-
this.deleteExistingEntry(id, true);
|
|
47
|
-
};
|
|
48
|
-
this.props = props;
|
|
49
|
-
this._values = new Map();
|
|
50
|
-
if (this.props.cleanupInterval)
|
|
51
|
-
this._timer = setInterval(this.disposeOutdatedValues, this.props.cleanupInterval);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Destructor. Must be called to clean up the stored values
|
|
55
|
-
* and other resources
|
|
56
|
-
*/
|
|
57
|
-
dispose() {
|
|
58
|
-
if (this._timer)
|
|
59
|
-
clearInterval(this._timer);
|
|
60
|
-
if (this.props.cleanupHandler) {
|
|
61
|
-
this._values.forEach((v, id) => {
|
|
62
|
-
this.props.cleanupHandler(id, v.value, "dispose");
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
this._values.clear();
|
|
66
|
-
this.props.onDisposedAll && this.props.onDisposedAll();
|
|
67
|
-
}
|
|
68
|
-
deleteExistingEntry(id, isTimeout) {
|
|
69
|
-
(0, core_bentley_1.assert)(this._values.has(id));
|
|
70
|
-
this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id).value, isTimeout ? "timeout" : "request");
|
|
71
|
-
this._values.delete(id);
|
|
72
|
-
this.props.onDisposedSingle && this.props.onDisposedSingle(id);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Get a value from the storage.
|
|
76
|
-
*
|
|
77
|
-
* **Note:** requesting a value with this method updates it's last used time.
|
|
78
|
-
*/
|
|
79
|
-
getValue(id) {
|
|
80
|
-
if (this._values.has(id)) {
|
|
81
|
-
const v = this._values.get(id);
|
|
82
|
-
v.lastUsed = new Date();
|
|
83
|
-
return v.value;
|
|
84
|
-
}
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
notifyValueUsed(id) {
|
|
88
|
-
const entry = this._values.get(id);
|
|
89
|
-
// istanbul ignore else
|
|
90
|
-
if (entry)
|
|
91
|
-
entry.lastUsed = new Date();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Adds a value into the storage.
|
|
95
|
-
* @throws An error when trying to add a value with ID that's already stored in the storage.
|
|
96
|
-
*/
|
|
97
|
-
addValue(id, value) {
|
|
98
|
-
if (this._values.has(id))
|
|
99
|
-
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, `A value with given ID "${id}" already exists in this storage.`);
|
|
100
|
-
this._values.set(id, { value, created: new Date(), lastUsed: new Date() });
|
|
101
|
-
}
|
|
102
|
-
/** Deletes a value with given id. */
|
|
103
|
-
deleteValue(id) {
|
|
104
|
-
// istanbul ignore else
|
|
105
|
-
if (this._values.has(id))
|
|
106
|
-
this.deleteExistingEntry(id, false);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Get all values currently in this storage.
|
|
110
|
-
*
|
|
111
|
-
* **Note:** requesting values with this method **doesn't**
|
|
112
|
-
* update their last used times.
|
|
113
|
-
*/
|
|
114
|
-
get values() {
|
|
115
|
-
const values = new Array();
|
|
116
|
-
for (const v of this._values.values())
|
|
117
|
-
values.push(v.value);
|
|
118
|
-
return values;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.TemporaryStorage = TemporaryStorage;
|
|
122
|
-
/**
|
|
123
|
-
* Storage for values that get removed from it after being unused (not-requested
|
|
124
|
-
* for a specified amount of time).
|
|
125
|
-
*
|
|
126
|
-
* @internal
|
|
127
|
-
*/
|
|
128
|
-
class FactoryBasedTemporaryStorage extends TemporaryStorage {
|
|
129
|
-
/**
|
|
130
|
-
* Constructor. Creates the storage using supplied params.
|
|
131
|
-
*/
|
|
132
|
-
constructor(props) {
|
|
133
|
-
super(props);
|
|
134
|
-
this.props = props;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get a value from the storage. If the value with the specified id
|
|
138
|
-
* doesn't exist, it gets created.
|
|
139
|
-
*
|
|
140
|
-
* **Note:** requesting a value with this method updates it's last used time.
|
|
141
|
-
*/
|
|
142
|
-
getValue(id) {
|
|
143
|
-
const existingValue = super.getValue(id);
|
|
144
|
-
if (existingValue)
|
|
145
|
-
return existingValue;
|
|
146
|
-
const value = this.props.factory(id, () => this.notifyValueUsed(id));
|
|
147
|
-
this.addValue(id, value);
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
exports.FactoryBasedTemporaryStorage = FactoryBasedTemporaryStorage;
|
|
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 Core
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.FactoryBasedTemporaryStorage = exports.TemporaryStorage = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const presentation_common_1 = require("@itwin/presentation-common");
|
|
13
|
+
/**
|
|
14
|
+
* Storage for values that get removed from it after being unused (not-requested
|
|
15
|
+
* for a specified amount of time).
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
class TemporaryStorage {
|
|
20
|
+
/**
|
|
21
|
+
* Constructor. Creates the storage using supplied params.
|
|
22
|
+
*/
|
|
23
|
+
constructor(props) {
|
|
24
|
+
/**
|
|
25
|
+
* Cleans up values that are currently outdated (based
|
|
26
|
+
* on their max and unused value lifetimes specified through [[Props]]).
|
|
27
|
+
*/
|
|
28
|
+
this.disposeOutdatedValues = () => {
|
|
29
|
+
const now = (new Date()).getTime();
|
|
30
|
+
const valuesToDispose = [];
|
|
31
|
+
for (const [key, entry] of this._values.entries()) {
|
|
32
|
+
if (this.props.maxValueLifetime !== undefined) {
|
|
33
|
+
if (this.props.maxValueLifetime === 0 || (now - entry.created.getTime()) > this.props.maxValueLifetime) {
|
|
34
|
+
valuesToDispose.push(key);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (this.props.unusedValueLifetime !== undefined) {
|
|
39
|
+
if (this.props.unusedValueLifetime === 0 || (now - entry.lastUsed.getTime()) > this.props.unusedValueLifetime) {
|
|
40
|
+
valuesToDispose.push(key);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const id of valuesToDispose)
|
|
46
|
+
this.deleteExistingEntry(id, true);
|
|
47
|
+
};
|
|
48
|
+
this.props = props;
|
|
49
|
+
this._values = new Map();
|
|
50
|
+
if (this.props.cleanupInterval)
|
|
51
|
+
this._timer = setInterval(this.disposeOutdatedValues, this.props.cleanupInterval);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Destructor. Must be called to clean up the stored values
|
|
55
|
+
* and other resources
|
|
56
|
+
*/
|
|
57
|
+
dispose() {
|
|
58
|
+
if (this._timer)
|
|
59
|
+
clearInterval(this._timer);
|
|
60
|
+
if (this.props.cleanupHandler) {
|
|
61
|
+
this._values.forEach((v, id) => {
|
|
62
|
+
this.props.cleanupHandler(id, v.value, "dispose");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
this._values.clear();
|
|
66
|
+
this.props.onDisposedAll && this.props.onDisposedAll();
|
|
67
|
+
}
|
|
68
|
+
deleteExistingEntry(id, isTimeout) {
|
|
69
|
+
(0, core_bentley_1.assert)(this._values.has(id));
|
|
70
|
+
this.props.cleanupHandler && this.props.cleanupHandler(id, this._values.get(id).value, isTimeout ? "timeout" : "request");
|
|
71
|
+
this._values.delete(id);
|
|
72
|
+
this.props.onDisposedSingle && this.props.onDisposedSingle(id);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a value from the storage.
|
|
76
|
+
*
|
|
77
|
+
* **Note:** requesting a value with this method updates it's last used time.
|
|
78
|
+
*/
|
|
79
|
+
getValue(id) {
|
|
80
|
+
if (this._values.has(id)) {
|
|
81
|
+
const v = this._values.get(id);
|
|
82
|
+
v.lastUsed = new Date();
|
|
83
|
+
return v.value;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
notifyValueUsed(id) {
|
|
88
|
+
const entry = this._values.get(id);
|
|
89
|
+
// istanbul ignore else
|
|
90
|
+
if (entry)
|
|
91
|
+
entry.lastUsed = new Date();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Adds a value into the storage.
|
|
95
|
+
* @throws An error when trying to add a value with ID that's already stored in the storage.
|
|
96
|
+
*/
|
|
97
|
+
addValue(id, value) {
|
|
98
|
+
if (this._values.has(id))
|
|
99
|
+
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, `A value with given ID "${id}" already exists in this storage.`);
|
|
100
|
+
this._values.set(id, { value, created: new Date(), lastUsed: new Date() });
|
|
101
|
+
}
|
|
102
|
+
/** Deletes a value with given id. */
|
|
103
|
+
deleteValue(id) {
|
|
104
|
+
// istanbul ignore else
|
|
105
|
+
if (this._values.has(id))
|
|
106
|
+
this.deleteExistingEntry(id, false);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get all values currently in this storage.
|
|
110
|
+
*
|
|
111
|
+
* **Note:** requesting values with this method **doesn't**
|
|
112
|
+
* update their last used times.
|
|
113
|
+
*/
|
|
114
|
+
get values() {
|
|
115
|
+
const values = new Array();
|
|
116
|
+
for (const v of this._values.values())
|
|
117
|
+
values.push(v.value);
|
|
118
|
+
return values;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.TemporaryStorage = TemporaryStorage;
|
|
122
|
+
/**
|
|
123
|
+
* Storage for values that get removed from it after being unused (not-requested
|
|
124
|
+
* for a specified amount of time).
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
class FactoryBasedTemporaryStorage extends TemporaryStorage {
|
|
129
|
+
/**
|
|
130
|
+
* Constructor. Creates the storage using supplied params.
|
|
131
|
+
*/
|
|
132
|
+
constructor(props) {
|
|
133
|
+
super(props);
|
|
134
|
+
this.props = props;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get a value from the storage. If the value with the specified id
|
|
138
|
+
* doesn't exist, it gets created.
|
|
139
|
+
*
|
|
140
|
+
* **Note:** requesting a value with this method updates it's last used time.
|
|
141
|
+
*/
|
|
142
|
+
getValue(id) {
|
|
143
|
+
const existingValue = super.getValue(id);
|
|
144
|
+
if (existingValue)
|
|
145
|
+
return existingValue;
|
|
146
|
+
const value = this.props.factory(id, () => this.notifyValueUsed(id));
|
|
147
|
+
this.addValue(id, value);
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.FactoryBasedTemporaryStorage = FactoryBasedTemporaryStorage;
|
|
152
152
|
//# sourceMappingURL=TemporaryStorage.js.map
|