@itwin/imodel-transformer 2.0.0-dev.7 → 2.0.0-dev.71
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/README.md +13 -27
- package/lib/cjs/Algo.d.ts +0 -4
- package/lib/cjs/Algo.d.ts.map +1 -1
- package/lib/cjs/Algo.js +0 -11
- package/lib/cjs/Algo.js.map +1 -1
- package/lib/cjs/BigMap.d.ts.map +1 -1
- package/lib/cjs/BigMap.js.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.js +26 -26
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/ChangedElementForest.d.ts +14 -0
- package/lib/cjs/ChangedElementForest.d.ts.map +1 -0
- package/lib/cjs/ChangedElementForest.js +86 -0
- package/lib/cjs/ChangedElementForest.js.map +1 -0
- package/lib/cjs/ChangesetScanner.d.ts +141 -0
- package/lib/cjs/ChangesetScanner.d.ts.map +1 -0
- package/lib/cjs/ChangesetScanner.js +187 -0
- package/lib/cjs/ChangesetScanner.js.map +1 -0
- package/lib/cjs/ECReferenceTypesCache.d.ts +0 -4
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +61 -111
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
- package/lib/cjs/ElementAspectCleanup.d.ts +16 -0
- package/lib/cjs/ElementAspectCleanup.d.ts.map +1 -0
- package/lib/cjs/ElementAspectCleanup.js +87 -0
- package/lib/cjs/ElementAspectCleanup.js.map +1 -0
- package/lib/cjs/ElementAspectExportCoordinator.d.ts +44 -0
- package/lib/cjs/ElementAspectExportCoordinator.d.ts.map +1 -0
- package/lib/cjs/ElementAspectExportCoordinator.js +148 -0
- package/lib/cjs/ElementAspectExportCoordinator.js.map +1 -0
- package/lib/cjs/ElementAspectExportProcessor.d.ts +44 -0
- package/lib/cjs/ElementAspectExportProcessor.d.ts.map +1 -0
- package/lib/cjs/ElementAspectExportProcessor.js +152 -0
- package/lib/cjs/ElementAspectExportProcessor.js.map +1 -0
- package/lib/cjs/ElementBulkDelete.d.ts +30 -0
- package/lib/cjs/ElementBulkDelete.d.ts.map +1 -0
- package/lib/cjs/ElementBulkDelete.js +358 -0
- package/lib/cjs/ElementBulkDelete.js.map +1 -0
- package/lib/cjs/EntityExistenceCache.d.ts +43 -0
- package/lib/cjs/EntityExistenceCache.d.ts.map +1 -0
- package/lib/cjs/EntityExistenceCache.js +91 -0
- package/lib/cjs/EntityExistenceCache.js.map +1 -0
- package/lib/cjs/EntityUnifier.d.ts +7 -7
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +55 -24
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +9 -3
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +56 -22
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts +180 -43
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +946 -247
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.d.ts +75 -30
- package/lib/cjs/IModelImporter.d.ts.map +1 -1
- package/lib/cjs/IModelImporter.js +292 -132
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformContext.d.ts +54 -0
- package/lib/cjs/IModelTransformContext.d.ts.map +1 -0
- package/lib/cjs/IModelTransformContext.js +3 -0
- package/lib/cjs/IModelTransformContext.js.map +1 -0
- package/lib/cjs/IModelTransformer.d.ts +184 -206
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +819 -1278
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/lib/cjs/IModelTransformerError.d.ts +84 -0
- package/lib/cjs/IModelTransformerError.d.ts.map +1 -0
- package/lib/cjs/IModelTransformerError.js +93 -0
- package/lib/cjs/IModelTransformerError.js.map +1 -0
- package/lib/cjs/ProvenanceManager.d.ts +177 -0
- package/lib/cjs/ProvenanceManager.d.ts.map +1 -0
- package/lib/cjs/ProvenanceManager.js +719 -0
- package/lib/cjs/ProvenanceManager.js.map +1 -0
- package/lib/cjs/SourceClassKinds.d.ts +22 -0
- package/lib/cjs/SourceClassKinds.d.ts.map +1 -0
- package/lib/cjs/SourceClassKinds.js +60 -0
- package/lib/cjs/SourceClassKinds.js.map +1 -0
- package/lib/cjs/SyncTypeResolver.d.ts +32 -0
- package/lib/cjs/SyncTypeResolver.d.ts.map +1 -0
- package/lib/cjs/SyncTypeResolver.js +92 -0
- package/lib/cjs/SyncTypeResolver.js.map +1 -0
- package/lib/cjs/TransformerLoggerCategory.d.ts +1 -1
- package/lib/cjs/TransformerLoggerCategory.js +1 -1
- package/lib/cjs/TransformerLoggerCategory.js.map +1 -1
- package/lib/cjs/TransformerPackageMetadata.d.ts +8 -0
- package/lib/cjs/TransformerPackageMetadata.d.ts.map +1 -0
- package/lib/cjs/TransformerPackageMetadata.js +47 -0
- package/lib/cjs/TransformerPackageMetadata.js.map +1 -0
- package/lib/cjs/imodel-transformer.d.ts +28 -0
- package/lib/cjs/imodel-transformer.d.ts.map +1 -1
- package/lib/cjs/imodel-transformer.js +61 -34
- package/lib/cjs/imodel-transformer.js.map +1 -1
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts +29 -0
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +1 -0
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js +212 -0
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js.map +1 -0
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts +25 -0
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts.map +1 -0
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js +196 -0
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js.map +1 -0
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts +59 -0
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts.map +1 -0
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.js +28 -0
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.js.map +1 -0
- package/lib/cjs/schema-processing.d.ts +7 -0
- package/lib/cjs/schema-processing.d.ts.map +1 -0
- package/lib/cjs/schema-processing.js +27 -0
- package/lib/cjs/schema-processing.js.map +1 -0
- package/package.json +70 -57
- package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts +0 -16
- package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +0 -1
- package/lib/cjs/DetachedExportElementAspectsStrategy.js +0 -106
- package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +0 -1
- package/lib/cjs/ElementCascadingDeleter.d.ts +0 -22
- package/lib/cjs/ElementCascadingDeleter.d.ts.map +0 -1
- package/lib/cjs/ElementCascadingDeleter.js +0 -57
- package/lib/cjs/ElementCascadingDeleter.js.map +0 -1
- package/lib/cjs/EntityMap.d.ts +0 -26
- package/lib/cjs/EntityMap.d.ts.map +0 -1
- package/lib/cjs/EntityMap.js +0 -54
- package/lib/cjs/EntityMap.js.map +0 -1
- package/lib/cjs/ExportElementAspectsStrategy.d.ts +0 -35
- package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +0 -1
- package/lib/cjs/ExportElementAspectsStrategy.js +0 -52
- package/lib/cjs/ExportElementAspectsStrategy.js.map +0 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts +0 -12
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts.map +0 -1
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +0 -47
- package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module iModels
|
|
3
|
+
*/
|
|
4
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
+
import { Id64String } from "@itwin/core-bentley";
|
|
6
|
+
import { ChangesetFileProps } from "@itwin/core-common";
|
|
7
|
+
import type { ChangedInstanceIds } from "./IModelExporter";
|
|
8
|
+
import { SourceClassKinds } from "./SourceClassKinds";
|
|
9
|
+
/**
|
|
10
|
+
* Identity shared by all deletion records.
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface DeletionRecordBase {
|
|
14
|
+
/** ID of the deleted source instance. */
|
|
15
|
+
ecInstanceId: Id64String;
|
|
16
|
+
/** EC class ID of the deleted source instance. */
|
|
17
|
+
ecClassId: Id64String;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A deleted source element.
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
export interface ElementDeletionRecord extends DeletionRecordBase {
|
|
24
|
+
/** Federation GUID used to find the corresponding target element. Undefined when the element had none. */
|
|
25
|
+
federationGuid?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A deleted source model.
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export type ModelDeletionRecord = DeletionRecordBase;
|
|
32
|
+
/**
|
|
33
|
+
* A deleted source relationship derived from `BisCore:ElementRefersToElements`, excluding `BisCore:ElementDrivesElement`.
|
|
34
|
+
* @beta
|
|
35
|
+
*/
|
|
36
|
+
export interface RelationshipDeletionRecord extends DeletionRecordBase {
|
|
37
|
+
/** Source endpoint of the deleted relationship. */
|
|
38
|
+
sourceECInstanceId: Id64String;
|
|
39
|
+
/** Target endpoint of the deleted relationship. */
|
|
40
|
+
targetECInstanceId: Id64String;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A deleted source ExternalSourceAspect, used to find the target of an element deleted in the same batch.
|
|
44
|
+
* Only aspects of kind `Element` with a scope and identifier are recorded, because only those identify a target element.
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export interface ExternalSourceAspectDeletionRecord extends DeletionRecordBase {
|
|
48
|
+
/** Element that owned the deleted aspect. */
|
|
49
|
+
elementId: Id64String;
|
|
50
|
+
/** Scope of the deleted aspect. */
|
|
51
|
+
scopeId: Id64String;
|
|
52
|
+
/** Kind of the deleted aspect. */
|
|
53
|
+
kind: string;
|
|
54
|
+
/** Identifier of the deleted aspect. */
|
|
55
|
+
identifier: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Deleted source instances from one batch of changes.
|
|
59
|
+
* @note Batches are processed in order. An `Element`-kind ExternalSourceAspect deletion is used to identify element deletions in the same batch. An empty array means nothing of that kind was deleted.
|
|
60
|
+
* @beta
|
|
61
|
+
*/
|
|
62
|
+
export interface DeletionBatch {
|
|
63
|
+
/** Deleted elements. */
|
|
64
|
+
elements: ElementDeletionRecord[];
|
|
65
|
+
/** Deleted models. */
|
|
66
|
+
models: ModelDeletionRecord[];
|
|
67
|
+
/** Deleted relationships derived from `BisCore:ElementRefersToElements`, excluding `BisCore:ElementDrivesElement`. */
|
|
68
|
+
relationships: RelationshipDeletionRecord[];
|
|
69
|
+
/** Deleted `Element`-kind ExternalSourceAspects with a scope and identifier. Aspects of other kinds can be omitted. */
|
|
70
|
+
externalSourceAspects: ExternalSourceAspectDeletionRecord[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Changes read for [[IModelTransformer.collectChanges]].
|
|
74
|
+
* @note The result must describe every change in the given ranges, as the default implementation does. Changes missing from
|
|
75
|
+
* `changedInstanceIds`, including CodeSpec changes, aren't exported. Every relationship in
|
|
76
|
+
* `changedInstanceIds.relationship.deleteIds` needs a matching deletion record, or its deletion is skipped with a warning.
|
|
77
|
+
* An element or model deletion whose target can't be found through its record or the transformation's provenance is ignored.
|
|
78
|
+
* @beta
|
|
79
|
+
*/
|
|
80
|
+
export interface CollectedChanges {
|
|
81
|
+
/** Changed instance IDs, including the owning elements of changed aspects. */
|
|
82
|
+
changedInstanceIds: ChangedInstanceIds;
|
|
83
|
+
/** Deletion batches of any granularity: one per changeset, one per range, or one for all ranges. */
|
|
84
|
+
deletionBatches: DeletionBatch[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The identifiers of a deleted instance that deletion records are built from, as read from a changeset with
|
|
88
|
+
* `PropertyFilter.InstanceKeyAndIdentifiers`.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export interface DeletedInstance {
|
|
92
|
+
ecInstanceId: Id64String;
|
|
93
|
+
ecClassId: Id64String;
|
|
94
|
+
federationGuid?: string;
|
|
95
|
+
sourceECInstanceId?: Id64String;
|
|
96
|
+
targetECInstanceId?: Id64String;
|
|
97
|
+
/** Owner of a deleted aspect. */
|
|
98
|
+
elementId?: Id64String;
|
|
99
|
+
scopeId?: Id64String;
|
|
100
|
+
kind?: string;
|
|
101
|
+
identifier?: string;
|
|
102
|
+
}
|
|
103
|
+
interface ScanOptions {
|
|
104
|
+
/** Receives the changes. When undefined, changes are read only for their deletion records. */
|
|
105
|
+
changedInstanceIds?: ChangedInstanceIds;
|
|
106
|
+
/** Whether to collect deletion records. Defaults to true. */
|
|
107
|
+
collectDeletionRecords?: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Adds a deleted instance to the deletion batch for its class.
|
|
111
|
+
* @note Throws `IModelStatus.NotFound` when the instance's class is missing from the current schemas, because such a
|
|
112
|
+
* deletion can't be classified.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export declare function addDeletionRecord(batch: DeletionBatch, deleted: DeletedInstance, classKinds: SourceClassKinds, iModel: IModelDb): void;
|
|
116
|
+
/**
|
|
117
|
+
* Reads each changeset once, unifies table changes into EC instance changes,
|
|
118
|
+
* normalizes overflow-only inserts and deletes to updates, writes all operations
|
|
119
|
+
* to [[ChangedInstanceIds]], and records the deleted instances needed to process deletions.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
export declare class ChangesetScanner {
|
|
123
|
+
/**
|
|
124
|
+
* Downloads the changesets in each range of an iModel.
|
|
125
|
+
* @param iModel the iModel to download changesets for.
|
|
126
|
+
* @param ranges inclusive ranges of changeset indices.
|
|
127
|
+
* @returns one group of changeset files per range, in the order of `ranges`.
|
|
128
|
+
*/
|
|
129
|
+
static download(iModel: IModelDb, ranges: readonly (readonly [number, number])[]): Promise<ChangesetFileProps[][]>;
|
|
130
|
+
/**
|
|
131
|
+
* Scans each group of changeset files in order with one reader and unifier per file.
|
|
132
|
+
* @param iModel Database used to resolve EC classes.
|
|
133
|
+
* @param csFileGroups Ordered groups of changeset files. Each group produces one deletion batch.
|
|
134
|
+
* @param options Where to write the changes, and whether to collect deletion records.
|
|
135
|
+
* @returns One deletion batch per group, empty when deletion records aren't collected.
|
|
136
|
+
*/
|
|
137
|
+
static scan(iModel: IModelDb, csFileGroups: ChangesetFileProps[][], { changedInstanceIds, collectDeletionRecords }: ScanOptions): Promise<DeletionBatch[]>;
|
|
138
|
+
private static readFiles;
|
|
139
|
+
}
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=ChangesetScanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangesetScanner.d.ts","sourceRoot":"","sources":["../../src/ChangesetScanner.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAKL,QAAQ,EAGT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAc,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAK3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;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AAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,UAAU,CAAC;IAChC,kBAAkB,CAAC,EAAE,UAAU,CAAC;IAChC,iCAAiC;IACjC,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,WAAW;IACnB,8FAA8F;IAC9F,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,6DAA6D;IAC7D,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,gBAAgB,EAC5B,MAAM,EAAE,QAAQ,GACf,IAAI,CA2DN;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B;;;;;OAKG;IACH,OAAoB,QAAQ,CAC1B,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,GAC7C,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAWjC;IAED;;;;;;OAMG;IACH,OAAoB,IAAI,CACtB,MAAM,EAAE,QAAQ,EAChB,YAAY,EAAE,kBAAkB,EAAE,EAAE,EACpC,EAAE,kBAAkB,EAAE,sBAA6B,EAAE,EAAE,WAAW,GACjE,OAAO,CAAC,aAAa,EAAE,CAAC,CAuC1B;IAED,OAAO,CAAC,MAAM,CAAE,SAAS;CA0C1B"}
|
|
@@ -0,0 +1,187 @@
|
|
|
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 iModels
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ChangesetScanner = void 0;
|
|
11
|
+
exports.addDeletionRecord = addDeletionRecord;
|
|
12
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
13
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
14
|
+
const IModelTransformerError_1 = require("./IModelTransformerError");
|
|
15
|
+
const SourceClassKinds_1 = require("./SourceClassKinds");
|
|
16
|
+
/**
|
|
17
|
+
* Adds a deleted instance to the deletion batch for its class.
|
|
18
|
+
* @note Throws `IModelStatus.NotFound` when the instance's class is missing from the current schemas, because such a
|
|
19
|
+
* deletion can't be classified.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
function addDeletionRecord(batch, deleted, classKinds, iModel) {
|
|
23
|
+
const { ecInstanceId, ecClassId } = deleted;
|
|
24
|
+
switch (classKinds.kindOf(ecClassId)) {
|
|
25
|
+
case "element":
|
|
26
|
+
batch.elements.push({
|
|
27
|
+
ecInstanceId,
|
|
28
|
+
ecClassId,
|
|
29
|
+
federationGuid: deleted.federationGuid,
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
case "model":
|
|
33
|
+
batch.models.push({ ecInstanceId, ecClassId });
|
|
34
|
+
return;
|
|
35
|
+
case "relationship": {
|
|
36
|
+
const { sourceECInstanceId, targetECInstanceId } = deleted;
|
|
37
|
+
if (sourceECInstanceId === undefined || targetECInstanceId === undefined)
|
|
38
|
+
core_bentley_1.ITwinError.throwError({
|
|
39
|
+
iTwinErrorId: {
|
|
40
|
+
scope: IModelTransformerError_1.IModelTransformerErrorScope,
|
|
41
|
+
key: IModelTransformerError_1.IModelTransformerError.ChangedInstanceMetadataMissing,
|
|
42
|
+
},
|
|
43
|
+
message: `Relationship deletion ${ecInstanceId} is missing an endpoint.`,
|
|
44
|
+
});
|
|
45
|
+
batch.relationships.push({
|
|
46
|
+
ecInstanceId,
|
|
47
|
+
ecClassId,
|
|
48
|
+
sourceECInstanceId,
|
|
49
|
+
targetECInstanceId,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
case "externalSourceAspect": {
|
|
54
|
+
const { elementId, scopeId, kind, identifier } = deleted;
|
|
55
|
+
// Only an Element-kind aspect with these set can identify a target element.
|
|
56
|
+
if (elementId !== undefined &&
|
|
57
|
+
scopeId !== undefined &&
|
|
58
|
+
kind === core_backend_1.ExternalSourceAspect.Kind.Element &&
|
|
59
|
+
identifier !== undefined)
|
|
60
|
+
batch.externalSourceAspects.push({
|
|
61
|
+
ecInstanceId,
|
|
62
|
+
ecClassId,
|
|
63
|
+
elementId,
|
|
64
|
+
scopeId,
|
|
65
|
+
kind,
|
|
66
|
+
identifier,
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case "aspect":
|
|
71
|
+
case "codeSpec":
|
|
72
|
+
case "skippedRelationship":
|
|
73
|
+
return;
|
|
74
|
+
case undefined:
|
|
75
|
+
// Throws NotFound for a class missing from the current schemas. Other unhandled classes need no records.
|
|
76
|
+
iModel.getClassNameFromId(ecClassId);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Reads each changeset once, unifies table changes into EC instance changes,
|
|
82
|
+
* normalizes overflow-only inserts and deletes to updates, writes all operations
|
|
83
|
+
* to [[ChangedInstanceIds]], and records the deleted instances needed to process deletions.
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
class ChangesetScanner {
|
|
87
|
+
/**
|
|
88
|
+
* Downloads the changesets in each range of an iModel.
|
|
89
|
+
* @param iModel the iModel to download changesets for.
|
|
90
|
+
* @param ranges inclusive ranges of changeset indices.
|
|
91
|
+
* @returns one group of changeset files per range, in the order of `ranges`.
|
|
92
|
+
*/
|
|
93
|
+
static async download(iModel, ranges) {
|
|
94
|
+
const iModelId = iModel.iModelId;
|
|
95
|
+
return Promise.all(ranges.map(async ([first, end]) => core_backend_1.BriefcaseManager.downloadChangesets({
|
|
96
|
+
iModelId,
|
|
97
|
+
range: { first, end },
|
|
98
|
+
targetDir: core_backend_1.BriefcaseManager.getChangeSetsPath(iModelId),
|
|
99
|
+
})));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Scans each group of changeset files in order with one reader and unifier per file.
|
|
103
|
+
* @param iModel Database used to resolve EC classes.
|
|
104
|
+
* @param csFileGroups Ordered groups of changeset files. Each group produces one deletion batch.
|
|
105
|
+
* @param options Where to write the changes, and whether to collect deletion records.
|
|
106
|
+
* @returns One deletion batch per group, empty when deletion records aren't collected.
|
|
107
|
+
*/
|
|
108
|
+
static async scan(iModel, csFileGroups, { changedInstanceIds, collectDeletionRecords = true }) {
|
|
109
|
+
const classKinds = collectDeletionRecords
|
|
110
|
+
? await SourceClassKinds_1.SourceClassKinds.query(iModel)
|
|
111
|
+
: undefined;
|
|
112
|
+
const batches = csFileGroups.map(() => ({
|
|
113
|
+
elements: [],
|
|
114
|
+
models: [],
|
|
115
|
+
relationships: [],
|
|
116
|
+
externalSourceAspects: [],
|
|
117
|
+
}));
|
|
118
|
+
const readChanges = function* () {
|
|
119
|
+
for (const [index, csFiles] of csFileGroups.entries()) {
|
|
120
|
+
for (const change of ChangesetScanner.readFiles(iModel, csFiles)) {
|
|
121
|
+
if (classKinds !== undefined && change.$meta.op === "Deleted")
|
|
122
|
+
addDeletionRecord(batches[index], {
|
|
123
|
+
ecInstanceId: change.ECInstanceId,
|
|
124
|
+
ecClassId: change.ECClassId,
|
|
125
|
+
federationGuid: change.FederationGuid,
|
|
126
|
+
sourceECInstanceId: change.SourceECInstanceId,
|
|
127
|
+
targetECInstanceId: change.TargetECInstanceId,
|
|
128
|
+
elementId: change.Element?.Id,
|
|
129
|
+
scopeId: change.Scope?.Id,
|
|
130
|
+
kind: change.Kind,
|
|
131
|
+
identifier: change.Identifier,
|
|
132
|
+
}, classKinds, iModel);
|
|
133
|
+
yield change;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
if (changedInstanceIds !== undefined)
|
|
138
|
+
await changedInstanceIds.addChanges(readChanges());
|
|
139
|
+
// Without an aggregate, the changes are read only to record their deletions.
|
|
140
|
+
else
|
|
141
|
+
for (const _change of readChanges())
|
|
142
|
+
;
|
|
143
|
+
return batches;
|
|
144
|
+
}
|
|
145
|
+
static *readFiles(iModel, csFiles) {
|
|
146
|
+
for (const csFile of csFiles) {
|
|
147
|
+
const csReader = core_backend_1.ChangesetReader.openFile({
|
|
148
|
+
fileName: csFile.pathname,
|
|
149
|
+
db: iModel,
|
|
150
|
+
propFilter: core_backend_1.PropertyFilter.InstanceKeyAndIdentifiers,
|
|
151
|
+
});
|
|
152
|
+
const changeUnifier = new core_backend_1.PartialChangeUnifier();
|
|
153
|
+
try {
|
|
154
|
+
while (csReader.step())
|
|
155
|
+
changeUnifier.appendFrom(csReader);
|
|
156
|
+
for (const change of changeUnifier.instances) {
|
|
157
|
+
if (change.ECClassId === undefined)
|
|
158
|
+
core_bentley_1.ITwinError.throwError({
|
|
159
|
+
iTwinErrorId: {
|
|
160
|
+
scope: IModelTransformerError_1.IModelTransformerErrorScope,
|
|
161
|
+
key: IModelTransformerError_1.IModelTransformerError.ChangedInstanceMetadataMissing,
|
|
162
|
+
},
|
|
163
|
+
message: `ECClassId was not found for id: ${change.ECInstanceId}! Table is : ${change.$meta.tables}`,
|
|
164
|
+
});
|
|
165
|
+
// Change is recorded at table level, not EC entity level.
|
|
166
|
+
// This normalizes overflow-table expansion records so they do not
|
|
167
|
+
// appear as element inserts or deletes.
|
|
168
|
+
if ((change.$meta.op === "Inserted" || change.$meta.op === "Deleted") &&
|
|
169
|
+
change.$meta.tables.every((table) => table.endsWith("Overflow"))) {
|
|
170
|
+
change.$meta.op = "Updated";
|
|
171
|
+
}
|
|
172
|
+
yield change;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
try {
|
|
177
|
+
changeUnifier[Symbol.dispose]();
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
csReader[Symbol.dispose]();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.ChangesetScanner = ChangesetScanner;
|
|
187
|
+
//# sourceMappingURL=ChangesetScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangesetScanner.js","sourceRoot":"","sources":["../../src/ChangesetScanner.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;AAEH,sDAQ6B;AAC7B,sDAA6D;AAG7D,qEAGkC;AAClC,yDAAsD;AA+GtD;;;;;GAKG;AACH,2BACE,KAAoB,EACpB,OAAwB,EACxB,UAA4B,EAC5B,MAAgB;IAEhB,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC5C,QAAQ,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,KAAK,SAAS;YACZ,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAClB,YAAY;gBACZ,SAAS;gBACT,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC,CAAC,CAAC;YACH,OAAO;QACT,KAAK,OAAO;YACV,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC;YAC/C,OAAO;QACT,KAAK,cAAc,EAAE,CAAC;YACpB,MAAM,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;YAC3D,IAAI,kBAAkB,KAAK,SAAS,IAAI,kBAAkB,KAAK,SAAS;gBACtE,yBAAU,CAAC,UAAU,CAAC;oBACpB,YAAY,EAAE;wBACZ,KAAK,EAAE,oDAA2B;wBAClC,GAAG,EAAE,+CAAsB,C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AAK,CAAC,EAAE,KAAK,SAAS,CAAC;wBACjE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,EAChE,CAAC;wBACD,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC;oBAC9B,CAAC;oBACD,MAAM,MAAM,CAAC;gBACf,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC;oBACH,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBAClC,CAAC;wBAAS,CAAC;oBACT,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF","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 iModels\n */\n\nimport {\n BriefcaseManager,\n ChangeInstance,\n ChangesetReader,\n ExternalSourceAspect,\n IModelDb,\n PartialChangeUnifier,\n PropertyFilter,\n} from \"@itwin/core-backend\";\nimport { Id64String, ITwinError } from \"@itwin/core-bentley\";\nimport { ChangesetFileProps } from \"@itwin/core-common\";\nimport type { ChangedInstanceIds } from \"./IModelExporter\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"./IModelTransformerError\";\nimport { SourceClassKinds } from \"./SourceClassKinds\";\n\n/**\n * Identity shared by all deletion records.\n * @beta\n */\nexport interface DeletionRecordBase {\n /** ID of the deleted source instance. */\n ecInstanceId: Id64String;\n /** EC class ID of the deleted source instance. */\n ecClassId: Id64String;\n}\n\n/**\n * A deleted source element.\n * @beta\n */\nexport interface ElementDeletionRecord extends DeletionRecordBase {\n /** Federation GUID used to find the corresponding target element. Undefined when the element had none. */\n federationGuid?: string;\n}\n\n/**\n * A deleted source model.\n * @beta\n */\nexport type ModelDeletionRecord = DeletionRecordBase;\n\n/**\n * A deleted source relationship derived from `BisCore:ElementRefersToElements`, excluding `BisCore:ElementDrivesElement`.\n * @beta\n */\nexport interface RelationshipDeletionRecord extends DeletionRecordBase {\n /** Source endpoint of the deleted relationship. */\n sourceECInstanceId: Id64String;\n /** Target endpoint of the deleted relationship. */\n targetECInstanceId: Id64String;\n}\n\n/**\n * A deleted source ExternalSourceAspect, used to find the target of an element deleted in the same batch.\n * Only aspects of kind `Element` with a scope and identifier are recorded, because only those identify a target element.\n * @beta\n */\nexport interface ExternalSourceAspectDeletionRecord extends DeletionRecordBase {\n /** Element that owned the deleted aspect. */\n elementId: Id64String;\n /** Scope of the deleted aspect. */\n scopeId: Id64String;\n /** Kind of the deleted aspect. */\n kind: string;\n /** Identifier of the deleted aspect. */\n identifier: string;\n}\n\n/**\n * Deleted source instances from one batch of changes.\n * @note Batches are processed in order. An `Element`-kind ExternalSourceAspect deletion is used to identify element deletions in the same batch. An empty array means nothing of that kind was deleted.\n * @beta\n */\nexport interface DeletionBatch {\n /** Deleted elements. */\n elements: ElementDeletionRecord[];\n /** Deleted models. */\n models: ModelDeletionRecord[];\n /** Deleted relationships derived from `BisCore:ElementRefersToElements`, excluding `BisCore:ElementDrivesElement`. */\n relationships: RelationshipDeletionRecord[];\n /** Deleted `Element`-kind ExternalSourceAspects with a scope and identifier. Aspects of other kinds can be omitted. */\n externalSourceAspects: ExternalSourceAspectDeletionRecord[];\n}\n\n/**\n * Changes read for [[IModelTransformer.collectChanges]].\n * @note The result must describe every change in the given ranges, as the default implementation does. Changes missing from\n * `changedInstanceIds`, including CodeSpec changes, aren't exported. Every relationship in\n * `changedInstanceIds.relationship.deleteIds` needs a matching deletion record, or its deletion is skipped with a warning.\n * An element or model deletion whose target can't be found through its record or the transformation's provenance is ignored.\n * @beta\n */\nexport interface CollectedChanges {\n /** Changed instance IDs, including the owning elements of changed aspects. */\n changedInstanceIds: ChangedInstanceIds;\n /** Deletion batches of any granularity: one per changeset, one per range, or one for all ranges. */\n deletionBatches: DeletionBatch[];\n}\n\n/**\n * The identifiers of a deleted instance that deletion records are built from, as read from a changeset with\n * `PropertyFilter.InstanceKeyAndIdentifiers`.\n * @internal\n */\nexport interface DeletedInstance {\n ecInstanceId: Id64String;\n ecClassId: Id64String;\n federationGuid?: string;\n sourceECInstanceId?: Id64String;\n targetECInstanceId?: Id64String;\n /** Owner of a deleted aspect. */\n elementId?: Id64String;\n scopeId?: Id64String;\n kind?: string;\n identifier?: string;\n}\n\ninterface ScanOptions {\n /** Receives the changes. When undefined, changes are read only for their deletion records. */\n changedInstanceIds?: ChangedInstanceIds;\n /** Whether to collect deletion records. Defaults to true. */\n collectDeletionRecords?: boolean;\n}\n\n/**\n * Adds a deleted instance to the deletion batch for its class.\n * @note Throws `IModelStatus.NotFound` when the instance's class is missing from the current schemas, because such a\n * deletion can't be classified.\n * @internal\n */\nexport function addDeletionRecord(\n batch: DeletionBatch,\n deleted: DeletedInstance,\n classKinds: SourceClassKinds,\n iModel: IModelDb\n): void {\n const { ecInstanceId, ecClassId } = deleted;\n switch (classKinds.kindOf(ecClassId)) {\n case \"element\":\n batch.elements.push({\n ecInstanceId,\n ecClassId,\n federationGuid: deleted.federationGuid,\n });\n return;\n case \"model\":\n batch.models.push({ ecInstanceId, ecClassId });\n return;\n case \"relationship\": {\n const { sourceECInstanceId, targetECInstanceId } = deleted;\n if (sourceECInstanceId === undefined || targetECInstanceId === undefined)\n ITwinError.throwError({\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.ChangedInstanceMetadataMissing,\n },\n message: `Relationship deletion ${ecInstanceId} is missing an endpoint.`,\n });\n batch.relationships.push({\n ecInstanceId,\n ecClassId,\n sourceECInstanceId,\n targetECInstanceId,\n });\n return;\n }\n case \"externalSourceAspect\": {\n const { elementId, scopeId, kind, identifier } = deleted;\n // Only an Element-kind aspect with these set can identify a target element.\n if (\n elementId !== undefined &&\n scopeId !== undefined &&\n kind === ExternalSourceAspect.Kind.Element &&\n identifier !== undefined\n )\n batch.externalSourceAspects.push({\n ecInstanceId,\n ecClassId,\n elementId,\n scopeId,\n kind,\n identifier,\n });\n return;\n }\n case \"aspect\":\n case \"codeSpec\":\n case \"skippedRelationship\":\n return;\n case undefined:\n // Throws NotFound for a class missing from the current schemas. Other unhandled classes need no records.\n iModel.getClassNameFromId(ecClassId);\n return;\n }\n}\n\n/**\n * Reads each changeset once, unifies table changes into EC instance changes,\n * normalizes overflow-only inserts and deletes to updates, writes all operations\n * to [[ChangedInstanceIds]], and records the deleted instances needed to process deletions.\n * @internal\n */\nexport class ChangesetScanner {\n /**\n * Downloads the changesets in each range of an iModel.\n * @param iModel the iModel to download changesets for.\n * @param ranges inclusive ranges of changeset indices.\n * @returns one group of changeset files per range, in the order of `ranges`.\n */\n public static async download(\n iModel: IModelDb,\n ranges: readonly (readonly [number, number])[]\n ): Promise<ChangesetFileProps[][]> {\n const iModelId = iModel.iModelId;\n return Promise.all(\n ranges.map(async ([first, end]) =>\n BriefcaseManager.downloadChangesets({\n iModelId,\n range: { first, end },\n targetDir: BriefcaseManager.getChangeSetsPath(iModelId),\n })\n )\n );\n }\n\n /**\n * Scans each group of changeset files in order with one reader and unifier per file.\n * @param iModel Database used to resolve EC classes.\n * @param csFileGroups Ordered groups of changeset files. Each group produces one deletion batch.\n * @param options Where to write the changes, and whether to collect deletion records.\n * @returns One deletion batch per group, empty when deletion records aren't collected.\n */\n public static async scan(\n iModel: IModelDb,\n csFileGroups: ChangesetFileProps[][],\n { changedInstanceIds, collectDeletionRecords = true }: ScanOptions\n ): Promise<DeletionBatch[]> {\n const classKinds = collectDeletionRecords\n ? await SourceClassKinds.query(iModel)\n : undefined;\n const batches = csFileGroups.map((): DeletionBatch => ({\n elements: [],\n models: [],\n relationships: [],\n externalSourceAspects: [],\n }));\n const readChanges = function* (): Generator<ChangeInstance> {\n for (const [index, csFiles] of csFileGroups.entries()) {\n for (const change of ChangesetScanner.readFiles(iModel, csFiles)) {\n if (classKinds !== undefined && change.$meta.op === \"Deleted\")\n addDeletionRecord(\n batches[index],\n {\n ecInstanceId: change.ECInstanceId,\n ecClassId: change.ECClassId,\n federationGuid: change.FederationGuid,\n sourceECInstanceId: change.SourceECInstanceId,\n targetECInstanceId: change.TargetECInstanceId,\n elementId: change.Element?.Id,\n scopeId: change.Scope?.Id,\n kind: change.Kind,\n identifier: change.Identifier,\n },\n classKinds,\n iModel\n );\n yield change;\n }\n }\n };\n if (changedInstanceIds !== undefined)\n await changedInstanceIds.addChanges(readChanges());\n // Without an aggregate, the changes are read only to record their deletions.\n else for (const _change of readChanges());\n return batches;\n }\n\n private static *readFiles(\n iModel: IModelDb,\n csFiles: ChangesetFileProps[]\n ): Generator<ChangeInstance> {\n for (const csFile of csFiles) {\n const csReader = ChangesetReader.openFile({\n fileName: csFile.pathname,\n db: iModel,\n propFilter: PropertyFilter.InstanceKeyAndIdentifiers,\n });\n const changeUnifier = new PartialChangeUnifier();\n try {\n while (csReader.step()) changeUnifier.appendFrom(csReader);\n for (const change of changeUnifier.instances) {\n if (change.ECClassId === undefined)\n ITwinError.throwError({\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.ChangedInstanceMetadataMissing,\n },\n message: `ECClassId was not found for id: ${change.ECInstanceId}! Table is : ${change.$meta.tables}`,\n });\n // Change is recorded at table level, not EC entity level.\n // This normalizes overflow-table expansion records so they do not\n // appear as element inserts or deletes.\n if (\n (change.$meta.op === \"Inserted\" || change.$meta.op === \"Deleted\") &&\n change.$meta.tables.every((table) => table.endsWith(\"Overflow\"))\n ) {\n change.$meta.op = \"Updated\";\n }\n yield change;\n }\n } finally {\n try {\n changeUnifier[Symbol.dispose]();\n } finally {\n csReader[Symbol.dispose]();\n }\n }\n }\n }\n}\n"]}
|
|
@@ -22,9 +22,6 @@ export declare class ECReferenceTypesCache {
|
|
|
22
22
|
private _propQualifierToRefType;
|
|
23
23
|
private _relClassNameEndToRefTypes;
|
|
24
24
|
private _initedSchemas;
|
|
25
|
-
private _rootBisClassCache;
|
|
26
|
-
private _relationshipInfoCache;
|
|
27
|
-
private _constraintClassCache;
|
|
28
25
|
private static bisRootClassToRefType;
|
|
29
26
|
private getRootBisClass;
|
|
30
27
|
private getAbstractConstraintClass;
|
|
@@ -35,6 +32,5 @@ export declare class ECReferenceTypesCache {
|
|
|
35
32
|
private relInfoFromRelClass;
|
|
36
33
|
getNavPropRefType(schemaName: string, className: string, propName: string): undefined | ConcreteEntityTypes;
|
|
37
34
|
getRelationshipEndType(schemaName: string, className: string): undefined | RelTypeInfo;
|
|
38
|
-
clear(): void;
|
|
39
35
|
}
|
|
40
36
|
//# sourceMappingURL=ECReferenceTypesCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECReferenceTypesCache.d.ts","sourceRoot":"","sources":["../../src/ECReferenceTypesCache.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ECReferenceTypesCache.d.ts","sourceRoot":"","sources":["../../src/ECReferenceTypesCache.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAYtE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAO/C;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,cAEC;CACF;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAqB;IAChC,uGAAuG;IACvG,OAAO,CAAC,uBAAuB,CAG3B;IACJ,OAAO,CAAC,0BAA0B,CAG9B;IACJ,OAAO,CAAC,cAAc,CAAgC;IAEtD,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAWlC;YAEY,eAAe;YA2Bf,0BAA0B;IAaxC,8CAA8C;IACjC,sBAAsB,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BnE;YAEa,kBAAkB;YAalB,UAAU;YAoEV,mBAAmB;IA4D1B,iBAAiB,CACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,SAAS,GAAG,mBAAmB,CAOjC;IAEM,sBAAsB,CAC3B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,SAAS,GAAG,WAAW,CAMzB;CACF"}
|