@itwin/core-backend 3.4.0-dev.0 → 3.4.0-dev.3

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 CHANGED
@@ -1,6 +1,16 @@
1
1
  # Change Log - @itwin/core-backend
2
2
 
3
- This log was last generated on Wed, 13 Jul 2022 15:45:52 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 01 Aug 2022 13:36:56 GMT and should not be manually modified.
4
+
5
+ ## 3.2.7
6
+ Mon, 01 Aug 2022 13:36:56 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 3.2.6
11
+ Fri, 15 Jul 2022 19:04:43 GMT
12
+
13
+ _Version update only_
4
14
 
5
15
  ## 3.2.5
6
16
  Wed, 13 Jul 2022 15:45:52 GMT
@@ -80,9 +80,9 @@ export declare enum BackendLoggerCategory {
80
80
  */
81
81
  NativeApp = "core-backend.NativeApp",
82
82
  /** The logger category used by the following classes:
83
- * - [[ViewStateHydrater]]
83
+ * - [[ViewStateHydrator]]
84
84
  * @internal
85
85
  */
86
- ViewStateHydrater = "core-backend.ViewStateHydrater"
86
+ ViewStateHydrator = "core-backend.ViewStateHydrator"
87
87
  }
88
88
  //# sourceMappingURL=BackendLoggerCategory.d.ts.map
@@ -88,9 +88,9 @@ var BackendLoggerCategory;
88
88
  */
89
89
  BackendLoggerCategory["NativeApp"] = "core-backend.NativeApp";
90
90
  /** The logger category used by the following classes:
91
- * - [[ViewStateHydrater]]
91
+ * - [[ViewStateHydrator]]
92
92
  * @internal
93
93
  */
94
- BackendLoggerCategory["ViewStateHydrater"] = "core-backend.ViewStateHydrater";
94
+ BackendLoggerCategory["ViewStateHydrator"] = "core-backend.ViewStateHydrator";
95
95
  })(BackendLoggerCategory = exports.BackendLoggerCategory || (exports.BackendLoggerCategory = {}));
96
96
  //# sourceMappingURL=BackendLoggerCategory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BackendLoggerCategory.js","sourceRoot":"","sources":["../../src/BackendLoggerCategory.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;;GAIG;AACH,IAAY,qBA8FX;AA9FD,WAAY,qBAAqB;IAC/B,+DAA+D;IAC/D,qEAA4C,CAAA;IAE5C;;OAEG;IACH,6DAAoC,CAAA;IAEpC;;OAEG;IACH,2DAAkC,CAAA;IAElC;;;;OAIG;IACH,mDAA0B,CAAA;IAE1B;;OAEG;IACH,+DAAsC,CAAA;IAEtC;;OAEG;IACH,6EAAoD,CAAA;IAEpD;;;OAGG;IACH,2DAAkC,CAAA;IAElC;;OAEG;IACH,+DAAsC,CAAA;IAEtC;;OAEG;IACH,mFAA0D,CAAA;IAE1D;;OAEG;IACH,2EAAkD,CAAA;IAElD;;OAEG;IACH,mEAA0C,CAAA;IAE1C;;OAEG;IACH,yDAAgC,CAAA;IAEhC;;OAEG;IACH,yEAAgD,CAAA;IAChD;;OAEG;IACH,6DAAoC,CAAA;IAEpC;;;OAGG;IACH,+EAAsD,CAAA;IAEtD;;;OAGG;IACH,yDAAgC,CAAA;IAEhC;;;OAGG;IACH,6DAAoC,CAAA;IAEpC;;;OAGG;IACH,6EAAoD,CAAA;AACtD,CAAC,EA9FW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QA8FhC","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 Logging\r\n */\r\n\r\n/** Logger categories used by this package\r\n * @note All logger categories in this package start with the `core-backend` prefix.\r\n * @see [Logger]($bentley)\r\n * @public\r\n */\r\nexport enum BackendLoggerCategory {\r\n /** The logger category used by API related to authorization */\r\n Authorization = \"core-backend.Authorization\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[CodeSpecs]]\r\n */\r\n CodeSpecs = \"core-backend.CodeSpecs\",\r\n\r\n /** The logger category used by the [[DevTools]] class and related classes.\r\n * @internal\r\n */\r\n DevTools = \"core-backend.DevTools\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[ChangeSummaryManager]]\r\n * - [[ECDb]]\r\n * - [[ECSqlStatement]]\r\n */\r\n ECDb = \"core-backend.ECDb\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[Functional]]\r\n */\r\n Functional = \"core-backend.Functional\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[LinearReferencing]]\r\n */\r\n LinearReferencing = \"core-backend.LinearReferencing\",\r\n\r\n /** The logger category used by the following classes:\r\n * - BriefcaseManager\r\n * - [[IModelDb]]\r\n */\r\n IModelDb = \"core-backend.IModelDb\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[IModelHost]]\r\n */\r\n IModelHost = \"core-backend.IModelHost\",\r\n\r\n /** The logger category used by the following classes:\r\n * - TileRequestMemoizer\r\n */\r\n IModelTileRequestRpc = \"core-backend.IModelTileRequestRpc\",\r\n\r\n /** The logger category used by the following classes:\r\n * - IModelTileRpcImpl (Tile Uploading)\r\n */\r\n IModelTileUpload = \"core-backend.IModelTileUpload\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[Relationship]]\r\n */\r\n Relationship = \"core-backend.Relationship\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[Schemas]]\r\n */\r\n Schemas = \"core-backend.Schemas\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[PromiseMemoizer]]\r\n */\r\n PromiseMemoizer = \"core-backend.PromiseMemoizer\",\r\n /** The logger category used by the following classes:\r\n * - [[EventSink]]\r\n */\r\n EventSink = \"core-backend.EventSink\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[IModelSchemaLoader]]\r\n * @alpha\r\n */\r\n IModelSchemaLoader = \"core-backend.IModelSchemaLoader\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[iModels]]\r\n * @alpha\r\n */\r\n Editing = \"core-backend.Editing\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[NativeHost]], [[NativeAppStorage]]\r\n * @internal\r\n */\r\n NativeApp = \"core-backend.NativeApp\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[ViewStateHydrater]]\r\n * @internal\r\n */\r\n ViewStateHydrater = \"core-backend.ViewStateHydrater\",\r\n}\r\n"]}
1
+ {"version":3,"file":"BackendLoggerCategory.js","sourceRoot":"","sources":["../../src/BackendLoggerCategory.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;;GAIG;AACH,IAAY,qBA8FX;AA9FD,WAAY,qBAAqB;IAC/B,+DAA+D;IAC/D,qEAA4C,CAAA;IAE5C;;OAEG;IACH,6DAAoC,CAAA;IAEpC;;OAEG;IACH,2DAAkC,CAAA;IAElC;;;;OAIG;IACH,mDAA0B,CAAA;IAE1B;;OAEG;IACH,+DAAsC,CAAA;IAEtC;;OAEG;IACH,6EAAoD,CAAA;IAEpD;;;OAGG;IACH,2DAAkC,CAAA;IAElC;;OAEG;IACH,+DAAsC,CAAA;IAEtC;;OAEG;IACH,mFAA0D,CAAA;IAE1D;;OAEG;IACH,2EAAkD,CAAA;IAElD;;OAEG;IACH,mEAA0C,CAAA;IAE1C;;OAEG;IACH,yDAAgC,CAAA;IAEhC;;OAEG;IACH,yEAAgD,CAAA;IAChD;;OAEG;IACH,6DAAoC,CAAA;IAEpC;;;OAGG;IACH,+EAAsD,CAAA;IAEtD;;;OAGG;IACH,yDAAgC,CAAA;IAEhC;;;OAGG;IACH,6DAAoC,CAAA;IAEpC;;;OAGG;IACH,6EAAoD,CAAA;AACtD,CAAC,EA9FW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QA8FhC","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 Logging\r\n */\r\n\r\n/** Logger categories used by this package\r\n * @note All logger categories in this package start with the `core-backend` prefix.\r\n * @see [Logger]($bentley)\r\n * @public\r\n */\r\nexport enum BackendLoggerCategory {\r\n /** The logger category used by API related to authorization */\r\n Authorization = \"core-backend.Authorization\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[CodeSpecs]]\r\n */\r\n CodeSpecs = \"core-backend.CodeSpecs\",\r\n\r\n /** The logger category used by the [[DevTools]] class and related classes.\r\n * @internal\r\n */\r\n DevTools = \"core-backend.DevTools\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[ChangeSummaryManager]]\r\n * - [[ECDb]]\r\n * - [[ECSqlStatement]]\r\n */\r\n ECDb = \"core-backend.ECDb\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[Functional]]\r\n */\r\n Functional = \"core-backend.Functional\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[LinearReferencing]]\r\n */\r\n LinearReferencing = \"core-backend.LinearReferencing\",\r\n\r\n /** The logger category used by the following classes:\r\n * - BriefcaseManager\r\n * - [[IModelDb]]\r\n */\r\n IModelDb = \"core-backend.IModelDb\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[IModelHost]]\r\n */\r\n IModelHost = \"core-backend.IModelHost\",\r\n\r\n /** The logger category used by the following classes:\r\n * - TileRequestMemoizer\r\n */\r\n IModelTileRequestRpc = \"core-backend.IModelTileRequestRpc\",\r\n\r\n /** The logger category used by the following classes:\r\n * - IModelTileRpcImpl (Tile Uploading)\r\n */\r\n IModelTileUpload = \"core-backend.IModelTileUpload\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[Relationship]]\r\n */\r\n Relationship = \"core-backend.Relationship\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[Schemas]]\r\n */\r\n Schemas = \"core-backend.Schemas\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[PromiseMemoizer]]\r\n */\r\n PromiseMemoizer = \"core-backend.PromiseMemoizer\",\r\n /** The logger category used by the following classes:\r\n * - [[EventSink]]\r\n */\r\n EventSink = \"core-backend.EventSink\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[IModelSchemaLoader]]\r\n * @alpha\r\n */\r\n IModelSchemaLoader = \"core-backend.IModelSchemaLoader\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[iModels]]\r\n * @alpha\r\n */\r\n Editing = \"core-backend.Editing\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[NativeHost]], [[NativeAppStorage]]\r\n * @internal\r\n */\r\n NativeApp = \"core-backend.NativeApp\",\r\n\r\n /** The logger category used by the following classes:\r\n * - [[ViewStateHydrator]]\r\n * @internal\r\n */\r\n ViewStateHydrator = \"core-backend.ViewStateHydrator\",\r\n}\r\n"]}
@@ -0,0 +1,140 @@
1
+ /** @packageDocumentation
2
+ * @module Elements
3
+ */
4
+ import { Id64String } from "@itwin/core-bentley";
5
+ import { IModelDb } from "./IModelDb";
6
+ import { Model } from "./Model";
7
+ /** @beta */
8
+ export interface ElementTreeWalkerModelInfo {
9
+ model: Model;
10
+ isDefinitionModel: boolean;
11
+ }
12
+ /** Records the path that a tree search took to reach an element or model. This object is immutable.
13
+ * @beta
14
+ */
15
+ export declare class ElementTreeWalkerScope {
16
+ readonly topElement: Id64String;
17
+ /** path of parent elements and enclosing models */
18
+ readonly path: Array<Id64String | ElementTreeWalkerModelInfo>;
19
+ /** cached info about the immediately enclosing model (i.e., the last model in path) */
20
+ readonly enclosingModelInfo: ElementTreeWalkerModelInfo;
21
+ constructor(topElement: Id64String, model: Model);
22
+ constructor(enclosingScope: ElementTreeWalkerScope, newScope: Id64String | Model);
23
+ get enclosingModel(): Model;
24
+ get inDefinitionModel(): boolean;
25
+ get inRepositoryModel(): boolean;
26
+ static createTopScope(iModel: IModelDb, topElementId: Id64String): ElementTreeWalkerScope;
27
+ private fmtItem;
28
+ toString(): string;
29
+ }
30
+ /** Does a depth-first search on the tree defined by an element and its sub-models and children.
31
+ * Sub-models are visited before their modeled elements, and children are visited before their parents.
32
+ *
33
+ * The following callbacks allow the subclass to exclude elements and sub-trees from the search:
34
+ * * [[ElementTreeBottomUp.shouldExploreModel]], [[ElementTreeBottomUp.shouldExploreChildren]]
35
+ * * [[ElementTreeBottomUp.shouldVisitElement]], [[ElementTreeBottomUp.shouldVisitModel]]
36
+ *
37
+ * The [[ElementTreeBottomUp.visitElement]] and [[ElementTreeBottomUp.visitModel]] callbacks allow
38
+ * the subclass to process the elements and models that are encountered in the search.
39
+ * @beta
40
+ */
41
+ export declare abstract class ElementTreeBottomUp {
42
+ protected _iModel: IModelDb;
43
+ constructor(_iModel: IModelDb);
44
+ /** Return true if the search should recurse into this model */
45
+ protected shouldExploreModel(_model: Model, _scope: ElementTreeWalkerScope): boolean;
46
+ /** Return true if the search should recurse into the children (if any) of this element */
47
+ protected shouldExploreChildren(_parentId: Id64String, _scope: ElementTreeWalkerScope): boolean;
48
+ /** Return true if the search should visit this element */
49
+ protected shouldVisitElement(_elementId: Id64String, _scope: ElementTreeWalkerScope): boolean;
50
+ /** Return true if the search should visit this model */
51
+ protected shouldVisitModel(_model: Model, _scope: ElementTreeWalkerScope): boolean;
52
+ /** Called to visit a model */
53
+ protected abstract visitModel(model: Model, scope: ElementTreeWalkerScope): void;
54
+ /** Called to visit an element */
55
+ protected abstract visitElement(elementId: Id64String, scope: ElementTreeWalkerScope): void;
56
+ /** The main tree-walking function */
57
+ protected processElementTree(element: Id64String, scope: ElementTreeWalkerScope): void;
58
+ /** process the children of the specified parent element */
59
+ private _processChildren;
60
+ /** process the elements in the specified model */
61
+ private _processSubModel;
62
+ }
63
+ /** Deletes an entire element tree, including sub-models and child elements.
64
+ * Items are deleted in bottom-up order. Definitions and Subjects are deleted after normal elements.
65
+ * @beta
66
+ */
67
+ export declare class ElementTreeDeleter extends ElementTreeBottomUp {
68
+ private _special;
69
+ private _topElement;
70
+ private _topScope;
71
+ constructor(iModel: IModelDb, topElement: Id64String, scope?: ElementTreeWalkerScope);
72
+ protected shouldExploreModel(_model: Model): boolean;
73
+ protected shouldVisitElement(_elementId: Id64String): boolean;
74
+ protected visitModel(model: Model, _scope: ElementTreeWalkerScope): void;
75
+ protected visitElement(elementId: Id64String, _scope: ElementTreeWalkerScope): void;
76
+ /** Delete the element tree. */
77
+ deleteElementTree(): void;
78
+ }
79
+ /** Does a breadth-first search on the tree defined by an element and its sub-models and children.
80
+ * Parents are visited first, then children, then sub-models.
81
+ * The subclass can "prune" sub-trees from the search. When a sub-tree is "pruned" the search does *not* recurse into it.
82
+ * If a sub-tree is not pruned, then the search does recurse into it.
83
+ * @beta
84
+ */
85
+ declare abstract class ElementTreeTopDown {
86
+ protected _iModel: IModelDb;
87
+ constructor(_iModel: IModelDb);
88
+ /** Should the search *not* recurse into this sub-tree? */
89
+ protected shouldPrune(_elementId: Id64String, _scope: ElementTreeWalkerScope): boolean;
90
+ protected abstract prune(_elementId: Id64String, _scope: ElementTreeWalkerScope): void;
91
+ protected processElementTree(element: Id64String, scope: ElementTreeWalkerScope): void;
92
+ private _processChildren;
93
+ private _processSubModel;
94
+ }
95
+ /** Signature of the filter function used by ElementSubTreeDeleter.
96
+ * @param elementId The sub-tree parent element.
97
+ * @param scope The path followed by the top-down search to the element
98
+ * @return true if the element and its children and sub-models should be deleted.
99
+ * @beta
100
+ */
101
+ export declare type ElementSubTreeDeleteFilter = (elementId: Id64String, scope: ElementTreeWalkerScope) => boolean;
102
+ /** Deletes the element sub-trees that are chosen by a supplied filter function.
103
+ * This class uses ElementTreeTopDown to visit element sub-trees in top-down order.
104
+ * When the filter function chooses a sub-tree, this class uses ElementTreeDeleter to delete it.
105
+ * Note that when a sub-tree is selected and deleted, its children and sub-models are not visited.
106
+ * @beta
107
+ */
108
+ export declare class ElementSubTreeDeleter extends ElementTreeTopDown {
109
+ private _special;
110
+ private _topElement;
111
+ private _topScope;
112
+ private _shouldPruneCb;
113
+ /** Construct an ElementSubTreeDeleter. @see pruneElementTree.
114
+ * @param iModel The iModel
115
+ * @param topElement Where to start the search.
116
+ * @param shouldPruneCb Callback that selects sub-trees that should be deleted.
117
+ */
118
+ constructor(iModel: IModelDb, topElement: Id64String, shouldPruneCb: ElementSubTreeDeleteFilter, scope?: ElementTreeWalkerScope);
119
+ protected shouldPrune(elementId: Id64String, scope: ElementTreeWalkerScope): boolean;
120
+ protected prune(elementId: Id64String, scope: ElementTreeWalkerScope): void;
121
+ /** Traverses the tree of elements, beginning with the top element, and deletes all selected sub-trees. */
122
+ pruneElementTree(): void;
123
+ }
124
+ /** Deletes an element tree starting with the specified top element. The top element is also deleted. Uses ElementTreeDeleter.
125
+ * @param iModel The iModel
126
+ * @param topElement The parent of the sub-tree
127
+ * @beta
128
+ */
129
+ export declare function deleteElementTree(iModel: IModelDb, topElement: Id64String): void;
130
+ /** Deletes all element sub-trees that are selected by the supplied filter. Uses ElementSubTreeDeleter.
131
+ * If the filter selects the top element itself, then the entire tree (including the top element) is deleted.
132
+ * That has the same effect as calling [[deleteElementTree]] on the top element.
133
+ * @param iModel The iModel
134
+ * @param topElement Where to start the search.
135
+ * @param filter Callback that selects sub-trees that should be deleted.
136
+ * @beta
137
+ */
138
+ export declare function deleteElementSubTrees(iModel: IModelDb, topElement: Id64String, filter: ElementSubTreeDeleteFilter): void;
139
+ export {};
140
+ //# sourceMappingURL=ElementTreeWalker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElementTreeWalker.d.ts","sourceRoot":"","sources":["../../src/ElementTreeWalker.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAA+B,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AAKhG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAmB,KAAK,EAAE,MAAM,SAAS,CAAC;AAIjD,YAAY;AACZ,MAAM,WAAW,0BAA0B;IAAG,KAAK,EAAE,KAAK,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE;AAwBxF;;GAEG;AACH,qBAAa,sBAAsB;IACjC,SAAgB,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KG;AACH,oBAAY,0BAA0B,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,sBAAsB,KAAK,OAAO,CAAC;AAE3G;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,kBAAkB;IAC3D,OAAO,CAAC,QAAQ,CAA0C;IAE1D,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,SAAS,CAAyB;IAE1C,OAAO,CAAC,cAAc,CAA6B;IAEnD;;;;OAIG;gBACgB,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,KAAK,CAAC,EAAE,sBAAsB;cAOnH,WAAW,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAE7F,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAO3E,0GAA0G;IACnG,gBAAgB;CAIxB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAGhF;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,0BAA0B,GAAG,IAAI,CAGxH"}
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteElementSubTrees = exports.deleteElementTree = exports.ElementSubTreeDeleter = exports.ElementTreeDeleter = exports.ElementTreeBottomUp = exports.ElementTreeWalkerScope = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ /** @packageDocumentation
9
+ * @module Elements
10
+ */
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
14
+ const Category_1 = require("./Category");
15
+ const Element_1 = require("./Element");
16
+ const IModelDb_1 = require("./IModelDb");
17
+ const Model_1 = require("./Model");
18
+ const loggerCategory = `${BackendLoggerCategory_1.BackendLoggerCategory.IModelDb}.ElementTreeWalker`;
19
+ function isModelEmpty(iModel, modelId) {
20
+ return iModel.withPreparedStatement(`select count(*) from ${Element_1.Element.classFullName} where Model.Id = ?`, (stmt) => {
21
+ stmt.bindId(1, modelId);
22
+ stmt.step();
23
+ return stmt.getValue(0).getInteger() === 0;
24
+ });
25
+ }
26
+ function isDefinitionModel(model) {
27
+ return (model.id !== core_common_1.IModel.repositoryModelId) && (model instanceof Model_1.DefinitionModel);
28
+ }
29
+ var ElementPruningClassification;
30
+ (function (ElementPruningClassification) {
31
+ ElementPruningClassification[ElementPruningClassification["PRUNING_CLASS_Normal"] = 0] = "PRUNING_CLASS_Normal";
32
+ ElementPruningClassification[ElementPruningClassification["PRUNING_CLASS_Subject"] = 1] = "PRUNING_CLASS_Subject";
33
+ ElementPruningClassification[ElementPruningClassification["PRUNING_CLASS_Definition"] = 2] = "PRUNING_CLASS_Definition";
34
+ ElementPruningClassification[ElementPruningClassification["PRUNING_CLASS_DefinitionPartition"] = 3] = "PRUNING_CLASS_DefinitionPartition";
35
+ })(ElementPruningClassification || (ElementPruningClassification = {}));
36
+ function classifyElementForPruning(iModel, elementId) {
37
+ const el = iModel.elements.getElement(elementId);
38
+ return (el instanceof Element_1.Subject) ? ElementPruningClassification.PRUNING_CLASS_Subject :
39
+ (el instanceof Element_1.DefinitionElement) ? ElementPruningClassification.PRUNING_CLASS_Definition :
40
+ (el instanceof Element_1.DefinitionPartition) ? ElementPruningClassification.PRUNING_CLASS_DefinitionPartition :
41
+ ElementPruningClassification.PRUNING_CLASS_Normal;
42
+ }
43
+ /** Records the path that a tree search took to reach an element or model. This object is immutable.
44
+ * @beta
45
+ */
46
+ class ElementTreeWalkerScope {
47
+ constructor(arg1, arg2) {
48
+ this.topElement = "";
49
+ /** path of parent elements and enclosing models */
50
+ this.path = [];
51
+ if (typeof arg1 === "string") {
52
+ // normal constructor
53
+ (0, core_bentley_1.assert)(arg2 instanceof Model_1.Model);
54
+ this.topElement = arg1;
55
+ this.path.push(this.enclosingModelInfo = { model: arg2, isDefinitionModel: isDefinitionModel(arg2) });
56
+ }
57
+ else if (arg1 instanceof ElementTreeWalkerScope) {
58
+ // copy-like constructor
59
+ this.topElement = arg1.topElement;
60
+ this.path = [...arg1.path];
61
+ if (typeof arg2 === "string") {
62
+ // with new parent
63
+ this.path.push(arg2);
64
+ this.enclosingModelInfo = arg1.enclosingModelInfo;
65
+ }
66
+ else {
67
+ // with new enclosing model
68
+ this.path.push(this.enclosingModelInfo = { model: arg2, isDefinitionModel: isDefinitionModel(arg2) });
69
+ }
70
+ }
71
+ else {
72
+ throw new Error("invalid constructor signature");
73
+ }
74
+ }
75
+ get enclosingModel() { return this.enclosingModelInfo.model; }
76
+ get inDefinitionModel() { return this.enclosingModelInfo.isDefinitionModel; } // NB: this will return false for the RepositoryModel!
77
+ get inRepositoryModel() { return this.enclosingModelInfo.model.id === IModelDb_1.IModelDb.repositoryModelId; }
78
+ static createTopScope(iModel, topElementId) {
79
+ const topElement = iModel.elements.getElement(topElementId);
80
+ const topElementModel = iModel.models.getModel(topElement.model);
81
+ return new ElementTreeWalkerScope(topElementId, topElementModel);
82
+ }
83
+ fmtItem(v) {
84
+ if (typeof v === "string")
85
+ return `element ${v}`;
86
+ return `model ${v.model.id} ${v.isDefinitionModel ? "(DEFN)" : ""}`;
87
+ }
88
+ toString() {
89
+ return `[ ${this.path.map((v) => this.fmtItem(v)).join(" / ")} ]`;
90
+ }
91
+ }
92
+ exports.ElementTreeWalkerScope = ElementTreeWalkerScope;
93
+ function fmtElement(iModel, elementId) {
94
+ const el = iModel.elements.getElement(elementId);
95
+ return `${el.id} ${el.classFullName} ${el.code.value} ${el.getDisplayLabel()}`;
96
+ }
97
+ function fmtModel(model) {
98
+ return `${model.id} ${model.classFullName} ${model.name}`;
99
+ }
100
+ let isTraceEnabledChecked = -1;
101
+ function isTraceEnabled() {
102
+ if (isTraceEnabledChecked === -1)
103
+ isTraceEnabledChecked = core_bentley_1.Logger.isEnabled(loggerCategory, core_bentley_1.LogLevel.Trace) ? 1 : 0;
104
+ return isTraceEnabledChecked === 1;
105
+ }
106
+ function logElement(op, iModel, elementId, scope) {
107
+ if (isTraceEnabled())
108
+ core_bentley_1.Logger.logTrace(loggerCategory, `${op} ${fmtElement(iModel, elementId)} ${scope === null || scope === void 0 ? void 0 : scope.toString()}`);
109
+ }
110
+ function logModel(op, iModel, modelId, scope) {
111
+ if (!isTraceEnabled())
112
+ return;
113
+ const model = iModel.models.getModel(modelId);
114
+ core_bentley_1.Logger.logTrace(loggerCategory, `${op} ${fmtModel(model)} ${scope === null || scope === void 0 ? void 0 : scope.toString()}`);
115
+ }
116
+ /** Does a depth-first search on the tree defined by an element and its sub-models and children.
117
+ * Sub-models are visited before their modeled elements, and children are visited before their parents.
118
+ *
119
+ * The following callbacks allow the subclass to exclude elements and sub-trees from the search:
120
+ * * [[ElementTreeBottomUp.shouldExploreModel]], [[ElementTreeBottomUp.shouldExploreChildren]]
121
+ * * [[ElementTreeBottomUp.shouldVisitElement]], [[ElementTreeBottomUp.shouldVisitModel]]
122
+ *
123
+ * The [[ElementTreeBottomUp.visitElement]] and [[ElementTreeBottomUp.visitModel]] callbacks allow
124
+ * the subclass to process the elements and models that are encountered in the search.
125
+ * @beta
126
+ */
127
+ class ElementTreeBottomUp {
128
+ constructor(_iModel) {
129
+ this._iModel = _iModel;
130
+ }
131
+ /** Return true if the search should recurse into this model */
132
+ shouldExploreModel(_model, _scope) { return true; }
133
+ /** Return true if the search should recurse into the children (if any) of this element */
134
+ shouldExploreChildren(_parentId, _scope) { return true; }
135
+ /** Return true if the search should visit this element */
136
+ shouldVisitElement(_elementId, _scope) { return true; }
137
+ /** Return true if the search should visit this model */
138
+ shouldVisitModel(_model, _scope) { return true; }
139
+ /** The main tree-walking function */
140
+ processElementTree(element, scope) {
141
+ const subModel = this._iModel.models.tryGetModel(element);
142
+ if (subModel !== undefined) {
143
+ if (this.shouldExploreModel(subModel, scope))
144
+ this._processSubModel(subModel, scope);
145
+ if (this.shouldVisitModel(subModel, scope))
146
+ this.visitModel(subModel, scope);
147
+ }
148
+ if (this.shouldExploreChildren(element, scope))
149
+ this._processChildren(element, scope);
150
+ if (this.shouldVisitElement(element, scope))
151
+ this.visitElement(element, scope);
152
+ }
153
+ /** process the children of the specified parent element */
154
+ _processChildren(parentElement, parentScope) {
155
+ const children = this._iModel.elements.queryChildren(parentElement);
156
+ if (children.length === 0)
157
+ return;
158
+ const childrenScope = new ElementTreeWalkerScope(parentScope, parentElement);
159
+ for (const childElement of children)
160
+ this.processElementTree(childElement, childrenScope);
161
+ }
162
+ /** process the elements in the specified model */
163
+ _processSubModel(model, parenScope) {
164
+ const scope = new ElementTreeWalkerScope(parenScope, model);
165
+ // Visit only the top-level parents. processElementTree will visit their children (bottom-up).
166
+ model.iModel.withPreparedStatement(`select ECInstanceId from bis:Element where Model.id=? and Parent.Id is null`, (stmt) => {
167
+ stmt.bindId(1, model.id);
168
+ while (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
169
+ const elementId = stmt.getValue(0).getId();
170
+ this.processElementTree(elementId, scope);
171
+ }
172
+ });
173
+ }
174
+ }
175
+ exports.ElementTreeBottomUp = ElementTreeBottomUp;
176
+ /** Helper class that manages the deletion of definitions and subjects */
177
+ class SpecialElements {
178
+ constructor() {
179
+ this.definitionModels = [];
180
+ this.definitions = [];
181
+ this.subjects = [];
182
+ }
183
+ recordSpecialElement(iModel, elementId) {
184
+ // Defer Definitions and Subjects
185
+ const cls = classifyElementForPruning(iModel, elementId);
186
+ if (cls === ElementPruningClassification.PRUNING_CLASS_Subject) {
187
+ this.subjects.push(elementId);
188
+ return true;
189
+ }
190
+ else if (cls === ElementPruningClassification.PRUNING_CLASS_Definition) {
191
+ this.definitions.push(elementId);
192
+ return true;
193
+ }
194
+ else if (cls === ElementPruningClassification.PRUNING_CLASS_DefinitionPartition) {
195
+ this.definitionModels.push(elementId);
196
+ return true;
197
+ }
198
+ return false; // not a special element
199
+ }
200
+ // It's dangerous to pass a mixture of SubCategories and Categories to deleteDefinitionElements.
201
+ // That function will delete the Categories first, which automatically deletes all their child
202
+ // SubCategories (in native code). If a SubCategory in the list is one of those children, then
203
+ // deleteDefinitionElements will try and fail with an exception to delete that SubCategory in a subsequent step.
204
+ // To work around this, we delete the SubCategories first, then everything else.
205
+ _siftSpecialElements(iModel) {
206
+ const subCategories = [];
207
+ const other = [];
208
+ this.definitions.forEach((elementId) => {
209
+ if (iModel.elements.tryGetElement(elementId, Category_1.SubCategory) !== undefined)
210
+ subCategories.push(elementId);
211
+ else
212
+ other.push(elementId);
213
+ });
214
+ return [subCategories, other];
215
+ }
216
+ deleteSpecialElements(iModel) {
217
+ for (const definitions of this._siftSpecialElements(iModel)) {
218
+ if (isTraceEnabled())
219
+ definitions.forEach((e) => logElement("try delete", iModel, e));
220
+ iModel.elements.deleteDefinitionElements(definitions); // will not deleted definitions that are still in use.
221
+ }
222
+ for (const m of this.definitionModels) {
223
+ if (!isModelEmpty(iModel, m)) {
224
+ logModel("Model not empty - cannot delete - may contain Definitions that are still in use", iModel, m);
225
+ }
226
+ else {
227
+ logModel("delete", iModel, m);
228
+ iModel.models.deleteModel(m);
229
+ iModel.elements.deleteElement(m);
230
+ }
231
+ }
232
+ for (const e of this.subjects) {
233
+ if (iModel.elements.queryChildren(e).length !== 0) {
234
+ logElement("Subject still has children - cannot delete - may have child DefinitionModels", iModel, e);
235
+ }
236
+ else {
237
+ logElement("delete", iModel, e);
238
+ iModel.elements.deleteElement(e);
239
+ }
240
+ }
241
+ }
242
+ }
243
+ /** Deletes an entire element tree, including sub-models and child elements.
244
+ * Items are deleted in bottom-up order. Definitions and Subjects are deleted after normal elements.
245
+ * @beta
246
+ */
247
+ class ElementTreeDeleter extends ElementTreeBottomUp {
248
+ constructor(iModel, topElement, scope) {
249
+ super(iModel);
250
+ this._special = new SpecialElements();
251
+ this._topElement = topElement;
252
+ this._topScope = scope !== null && scope !== void 0 ? scope : ElementTreeWalkerScope.createTopScope(this._iModel, this._topElement);
253
+ }
254
+ shouldExploreModel(_model) { return true; }
255
+ shouldVisitElement(_elementId) { return true; }
256
+ visitModel(model, _scope) {
257
+ if (isDefinitionModel(model))
258
+ return; // we recorded definition models in visitElement when we encountered the DefinitionPartition elements.
259
+ // visitElement was called first, and it deleted the elements in the model. So, now it's safe to delete the model itself.
260
+ // TODO: will fail if model has an element that is sub-modeled by a **DefinitionModel**. I hope that never occurs!
261
+ logModel("delete", this._iModel, model.id, _scope);
262
+ model.delete();
263
+ }
264
+ visitElement(elementId, _scope) {
265
+ if (!this._special.recordSpecialElement(this._iModel, elementId)) {
266
+ logElement("delete", this._iModel, elementId, _scope);
267
+ this._iModel.elements.deleteElement(elementId);
268
+ }
269
+ }
270
+ /** Delete the element tree. */
271
+ deleteElementTree() {
272
+ this.processElementTree(this._topElement, this._topScope); // Delete the "normal" elements and record the special elements for deferred processing
273
+ this._special.deleteSpecialElements(this._iModel);
274
+ }
275
+ }
276
+ exports.ElementTreeDeleter = ElementTreeDeleter;
277
+ /** Does a breadth-first search on the tree defined by an element and its sub-models and children.
278
+ * Parents are visited first, then children, then sub-models.
279
+ * The subclass can "prune" sub-trees from the search. When a sub-tree is "pruned" the search does *not* recurse into it.
280
+ * If a sub-tree is not pruned, then the search does recurse into it.
281
+ * @beta
282
+ */
283
+ class ElementTreeTopDown {
284
+ constructor(_iModel) {
285
+ this._iModel = _iModel;
286
+ }
287
+ /** Should the search *not* recurse into this sub-tree? */
288
+ shouldPrune(_elementId, _scope) { return false; }
289
+ processElementTree(element, scope) {
290
+ if (this.shouldPrune(element, scope)) {
291
+ this.prune(element, scope);
292
+ return;
293
+ }
294
+ this._processChildren(element, scope);
295
+ const subModel = this._iModel.models.tryGetModel(element);
296
+ if (subModel !== undefined) {
297
+ this._processSubModel(subModel, scope);
298
+ }
299
+ }
300
+ _processChildren(element, scope) {
301
+ let parentScope;
302
+ for (const childElement of this._iModel.elements.queryChildren(element)) {
303
+ if (parentScope === undefined)
304
+ parentScope = new ElementTreeWalkerScope(scope, element);
305
+ this.processElementTree(childElement, parentScope);
306
+ }
307
+ }
308
+ _processSubModel(subModel, scope) {
309
+ const subModelScope = new ElementTreeWalkerScope(scope, subModel);
310
+ // Visit only the top-level parents. processElementTree will recurse into their children.
311
+ this._iModel.withPreparedStatement(`select ECInstanceId from bis:Element where Model.id=? and Parent.Id is null`, (stmt) => {
312
+ stmt.bindId(1, subModel.id);
313
+ while (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
314
+ const elementId = stmt.getValue(0).getId();
315
+ this.processElementTree(elementId, subModelScope);
316
+ }
317
+ });
318
+ }
319
+ }
320
+ /** Deletes the element sub-trees that are chosen by a supplied filter function.
321
+ * This class uses ElementTreeTopDown to visit element sub-trees in top-down order.
322
+ * When the filter function chooses a sub-tree, this class uses ElementTreeDeleter to delete it.
323
+ * Note that when a sub-tree is selected and deleted, its children and sub-models are not visited.
324
+ * @beta
325
+ */
326
+ class ElementSubTreeDeleter extends ElementTreeTopDown {
327
+ /** Construct an ElementSubTreeDeleter. @see pruneElementTree.
328
+ * @param iModel The iModel
329
+ * @param topElement Where to start the search.
330
+ * @param shouldPruneCb Callback that selects sub-trees that should be deleted.
331
+ */
332
+ constructor(iModel, topElement, shouldPruneCb, scope) {
333
+ super(iModel);
334
+ this._special = new SpecialElements();
335
+ this._topElement = topElement;
336
+ this._topScope = scope !== null && scope !== void 0 ? scope : ElementTreeWalkerScope.createTopScope(this._iModel, this._topElement);
337
+ this._shouldPruneCb = shouldPruneCb;
338
+ }
339
+ shouldPrune(elementId, scope) { return this._shouldPruneCb(elementId, scope); }
340
+ prune(elementId, scope) {
341
+ if (!this._special.recordSpecialElement(this._iModel, elementId)) {
342
+ const del = new ElementTreeDeleter(this._iModel, elementId, scope);
343
+ del.deleteElementTree();
344
+ }
345
+ }
346
+ /** Traverses the tree of elements, beginning with the top element, and deletes all selected sub-trees. */
347
+ pruneElementTree() {
348
+ this.processElementTree(this._topElement, this._topScope); // deletes normal elements and their sub-trees, defers special elements
349
+ this._special.deleteSpecialElements(this._iModel);
350
+ }
351
+ }
352
+ exports.ElementSubTreeDeleter = ElementSubTreeDeleter;
353
+ /** Deletes an element tree starting with the specified top element. The top element is also deleted. Uses ElementTreeDeleter.
354
+ * @param iModel The iModel
355
+ * @param topElement The parent of the sub-tree
356
+ * @beta
357
+ */
358
+ function deleteElementTree(iModel, topElement) {
359
+ const del = new ElementTreeDeleter(iModel, topElement);
360
+ del.deleteElementTree();
361
+ }
362
+ exports.deleteElementTree = deleteElementTree;
363
+ /** Deletes all element sub-trees that are selected by the supplied filter. Uses ElementSubTreeDeleter.
364
+ * If the filter selects the top element itself, then the entire tree (including the top element) is deleted.
365
+ * That has the same effect as calling [[deleteElementTree]] on the top element.
366
+ * @param iModel The iModel
367
+ * @param topElement Where to start the search.
368
+ * @param filter Callback that selects sub-trees that should be deleted.
369
+ * @beta
370
+ */
371
+ function deleteElementSubTrees(iModel, topElement, filter) {
372
+ const del = new ElementSubTreeDeleter(iModel, topElement, filter);
373
+ del.pruneElementTree();
374
+ }
375
+ exports.deleteElementSubTrees = deleteElementSubTrees;
376
+ //# sourceMappingURL=ElementTreeWalker.js.map