@itwin/imodel-transformer 2.0.0-dev.72 → 2.0.0-dev.74
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 +11 -0
- package/lib/Algo.d.ts.map +1 -0
- package/lib/{cjs/Algo.js → Algo.js} +1 -4
- package/lib/Algo.js.map +1 -0
- package/lib/BigMap.d.ts.map +1 -0
- package/lib/{cjs/BigMap.js → BigMap.js} +1 -5
- package/lib/BigMap.js.map +1 -0
- package/lib/BranchProvenanceInitializer.d.ts.map +1 -0
- package/lib/{cjs/BranchProvenanceInitializer.js → BranchProvenanceInitializer.js} +34 -37
- package/lib/BranchProvenanceInitializer.js.map +1 -0
- package/lib/ChangedElementForest.d.ts.map +1 -0
- package/lib/{cjs/ChangedElementForest.js → ChangedElementForest.js} +12 -14
- package/lib/ChangedElementForest.js.map +1 -0
- package/lib/{cjs/ChangesetScanner.d.ts → ChangesetScanner.d.ts} +2 -2
- package/lib/ChangesetScanner.d.ts.map +1 -0
- package/lib/{cjs/ChangesetScanner.js → ChangesetScanner.js} +19 -24
- package/lib/ChangesetScanner.js.map +1 -0
- package/lib/ECReferenceTypesCache.d.ts.map +1 -0
- package/lib/{cjs/ECReferenceTypesCache.js → ECReferenceTypesCache.js} +32 -37
- package/lib/ECReferenceTypesCache.js.map +1 -0
- package/lib/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +1 -0
- package/lib/{cjs/ECSqlReaderAsyncIterableIteratorAdapter.js → ECSqlReaderAsyncIterableIteratorAdapter.js} +2 -7
- package/lib/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -0
- package/lib/ElementAspectCleanup.d.ts.map +1 -0
- package/lib/{cjs/ElementAspectCleanup.js → ElementAspectCleanup.js} +9 -13
- package/lib/ElementAspectCleanup.js.map +1 -0
- package/lib/ElementAspectExportCoordinator.d.ts.map +1 -0
- package/lib/{cjs/ElementAspectExportCoordinator.js → ElementAspectExportCoordinator.js} +1 -5
- package/lib/ElementAspectExportCoordinator.js.map +1 -0
- package/lib/ElementAspectExportProcessor.d.ts.map +1 -0
- package/lib/{cjs/ElementAspectExportProcessor.js → ElementAspectExportProcessor.js} +10 -14
- package/lib/ElementAspectExportProcessor.js.map +1 -0
- package/lib/ElementBulkDelete.d.ts.map +1 -0
- package/lib/{cjs/ElementBulkDelete.js → ElementBulkDelete.js} +9 -12
- package/lib/{cjs/ElementBulkDelete.js.map → ElementBulkDelete.js.map} +1 -1
- package/lib/EntityExistenceCache.d.ts.map +1 -0
- package/lib/{cjs/EntityExistenceCache.js → EntityExistenceCache.js} +4 -8
- package/lib/EntityExistenceCache.js.map +1 -0
- package/lib/EntityUnifier.d.ts.map +1 -0
- package/lib/{cjs/EntityUnifier.js → EntityUnifier.js} +21 -22
- package/lib/EntityUnifier.js.map +1 -0
- package/lib/{cjs/IModelCloneContext.d.ts → IModelCloneContext.d.ts} +2 -2
- package/lib/IModelCloneContext.d.ts.map +1 -0
- package/lib/{cjs/IModelCloneContext.js → IModelCloneContext.js} +52 -56
- package/lib/IModelCloneContext.js.map +1 -0
- package/lib/{cjs/IModelExporter.d.ts → IModelExporter.d.ts} +1 -1
- package/lib/IModelExporter.d.ts.map +1 -0
- package/lib/{cjs/IModelExporter.js → IModelExporter.js} +165 -174
- package/lib/IModelExporter.js.map +1 -0
- package/lib/{cjs/IModelImporter.d.ts → IModelImporter.d.ts} +3 -3
- package/lib/IModelImporter.d.ts.map +1 -0
- package/lib/{cjs/IModelImporter.js → IModelImporter.js} +104 -109
- package/lib/IModelImporter.js.map +1 -0
- package/lib/IModelTransformContext.d.ts.map +1 -0
- package/lib/IModelTransformContext.js +2 -0
- package/lib/IModelTransformContext.js.map +1 -0
- package/lib/{cjs/IModelTransformer.d.ts → IModelTransformer.d.ts} +9 -6
- package/lib/IModelTransformer.d.ts.map +1 -0
- package/lib/{cjs/IModelTransformer.js → IModelTransformer.js} +297 -337
- package/lib/IModelTransformer.js.map +1 -0
- package/lib/IModelTransformerError.d.ts.map +1 -0
- package/lib/{cjs/IModelTransformerError.js → IModelTransformerError.js} +3 -6
- package/lib/IModelTransformerError.js.map +1 -0
- package/lib/{cjs/ProvenanceManager.d.ts → ProvenanceManager.d.ts} +3 -3
- package/lib/ProvenanceManager.d.ts.map +1 -0
- package/lib/{cjs/ProvenanceManager.js → ProvenanceManager.js} +69 -73
- package/lib/ProvenanceManager.js.map +1 -0
- package/lib/SourceClassKinds.d.ts.map +1 -0
- package/lib/{cjs/SourceClassKinds.js → SourceClassKinds.js} +1 -5
- package/lib/SourceClassKinds.js.map +1 -0
- package/lib/SyncTypeResolver.d.ts.map +1 -0
- package/lib/{cjs/SyncTypeResolver.js → SyncTypeResolver.js} +15 -19
- package/lib/SyncTypeResolver.js.map +1 -0
- package/lib/TransformerLoggerCategory.d.ts.map +1 -0
- package/lib/{cjs/TransformerLoggerCategory.js → TransformerLoggerCategory.js} +2 -5
- package/lib/TransformerLoggerCategory.js.map +1 -0
- package/lib/TransformerPackageMetadata.d.ts.map +1 -0
- package/lib/TransformerPackageMetadata.js +8 -0
- package/lib/TransformerPackageMetadata.js.map +1 -0
- package/lib/{cjs/imodel-transformer.d.ts → imodel-transformer.d.ts} +9 -9
- package/lib/imodel-transformer.d.ts.map +1 -0
- package/lib/imodel-transformer.js +88 -0
- package/lib/imodel-transformer.js.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/DynamicSchemaUnionStrategy.d.ts +1 -1
- package/lib/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/DynamicSchemaUnionStrategy.js +16 -20
- package/lib/schema-processing/DynamicSchemaUnionStrategy.js.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingCoordinator.d.ts +2 -2
- package/lib/schema-processing/SchemaProcessingCoordinator.d.ts.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingCoordinator.js +15 -52
- package/lib/schema-processing/SchemaProcessingCoordinator.js.map +1 -0
- package/lib/schema-processing/SchemaProcessingStrategy.d.ts.map +1 -0
- package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingStrategy.js +1 -5
- package/lib/schema-processing/SchemaProcessingStrategy.js.map +1 -0
- package/lib/schema-processing.d.ts +7 -0
- package/lib/schema-processing.d.ts.map +1 -0
- package/lib/schema-processing.js +11 -0
- package/lib/schema-processing.js.map +1 -0
- package/package.json +14 -14
- package/lib/cjs/Algo.d.ts.map +0 -1
- package/lib/cjs/Algo.js.map +0 -1
- package/lib/cjs/BigMap.d.ts.map +0 -1
- package/lib/cjs/BigMap.js.map +0 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +0 -1
- package/lib/cjs/BranchProvenanceInitializer.js.map +0 -1
- package/lib/cjs/ChangedElementForest.d.ts.map +0 -1
- package/lib/cjs/ChangedElementForest.js.map +0 -1
- package/lib/cjs/ChangesetScanner.d.ts.map +0 -1
- package/lib/cjs/ChangesetScanner.js.map +0 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +0 -1
- package/lib/cjs/ECReferenceTypesCache.js.map +0 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +0 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +0 -1
- package/lib/cjs/ElementAspectCleanup.d.ts.map +0 -1
- package/lib/cjs/ElementAspectCleanup.js.map +0 -1
- package/lib/cjs/ElementAspectExportCoordinator.d.ts.map +0 -1
- package/lib/cjs/ElementAspectExportCoordinator.js.map +0 -1
- package/lib/cjs/ElementAspectExportProcessor.d.ts.map +0 -1
- package/lib/cjs/ElementAspectExportProcessor.js.map +0 -1
- package/lib/cjs/ElementBulkDelete.d.ts.map +0 -1
- package/lib/cjs/EntityExistenceCache.d.ts.map +0 -1
- package/lib/cjs/EntityExistenceCache.js.map +0 -1
- package/lib/cjs/EntityUnifier.d.ts.map +0 -1
- package/lib/cjs/EntityUnifier.js.map +0 -1
- package/lib/cjs/IModelCloneContext.d.ts.map +0 -1
- package/lib/cjs/IModelCloneContext.js.map +0 -1
- package/lib/cjs/IModelExporter.d.ts.map +0 -1
- package/lib/cjs/IModelExporter.js.map +0 -1
- package/lib/cjs/IModelImporter.d.ts.map +0 -1
- package/lib/cjs/IModelImporter.js.map +0 -1
- package/lib/cjs/IModelTransformContext.d.ts.map +0 -1
- package/lib/cjs/IModelTransformContext.js +0 -3
- package/lib/cjs/IModelTransformContext.js.map +0 -1
- package/lib/cjs/IModelTransformer.d.ts.map +0 -1
- package/lib/cjs/IModelTransformer.js.map +0 -1
- package/lib/cjs/IModelTransformerError.d.ts.map +0 -1
- package/lib/cjs/IModelTransformerError.js.map +0 -1
- package/lib/cjs/ProvenanceManager.d.ts.map +0 -1
- package/lib/cjs/ProvenanceManager.js.map +0 -1
- package/lib/cjs/SourceClassKinds.d.ts.map +0 -1
- package/lib/cjs/SourceClassKinds.js.map +0 -1
- package/lib/cjs/SyncTypeResolver.d.ts.map +0 -1
- package/lib/cjs/SyncTypeResolver.js.map +0 -1
- package/lib/cjs/TransformerLoggerCategory.d.ts.map +0 -1
- package/lib/cjs/TransformerLoggerCategory.js.map +0 -1
- package/lib/cjs/TransformerPackageMetadata.d.ts.map +0 -1
- package/lib/cjs/TransformerPackageMetadata.js +0 -47
- package/lib/cjs/TransformerPackageMetadata.js.map +0 -1
- package/lib/cjs/imodel-transformer.d.ts.map +0 -1
- package/lib/cjs/imodel-transformer.js +0 -125
- package/lib/cjs/imodel-transformer.js.map +0 -1
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +0 -1
- package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts.map +0 -1
- package/lib/cjs/schema-processing/SchemaProcessingStrategy.js.map +0 -1
- package/lib/cjs/schema-processing.d.ts +0 -7
- package/lib/cjs/schema-processing.d.ts.map +0 -1
- package/lib/cjs/schema-processing.js +0 -27
- package/lib/cjs/schema-processing.js.map +0 -1
- /package/lib/{cjs/Algo.d.ts → Algo.d.ts} +0 -0
- /package/lib/{cjs/BigMap.d.ts → BigMap.d.ts} +0 -0
- /package/lib/{cjs/BranchProvenanceInitializer.d.ts → BranchProvenanceInitializer.d.ts} +0 -0
- /package/lib/{cjs/ChangedElementForest.d.ts → ChangedElementForest.d.ts} +0 -0
- /package/lib/{cjs/ECReferenceTypesCache.d.ts → ECReferenceTypesCache.d.ts} +0 -0
- /package/lib/{cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts → ECSqlReaderAsyncIterableIteratorAdapter.d.ts} +0 -0
- /package/lib/{cjs/ElementAspectCleanup.d.ts → ElementAspectCleanup.d.ts} +0 -0
- /package/lib/{cjs/ElementAspectExportCoordinator.d.ts → ElementAspectExportCoordinator.d.ts} +0 -0
- /package/lib/{cjs/ElementAspectExportProcessor.d.ts → ElementAspectExportProcessor.d.ts} +0 -0
- /package/lib/{cjs/ElementBulkDelete.d.ts → ElementBulkDelete.d.ts} +0 -0
- /package/lib/{cjs/EntityExistenceCache.d.ts → EntityExistenceCache.d.ts} +0 -0
- /package/lib/{cjs/EntityUnifier.d.ts → EntityUnifier.d.ts} +0 -0
- /package/lib/{cjs/IModelTransformContext.d.ts → IModelTransformContext.d.ts} +0 -0
- /package/lib/{cjs/IModelTransformerError.d.ts → IModelTransformerError.d.ts} +0 -0
- /package/lib/{cjs/SourceClassKinds.d.ts → SourceClassKinds.d.ts} +0 -0
- /package/lib/{cjs/SyncTypeResolver.d.ts → SyncTypeResolver.d.ts} +0 -0
- /package/lib/{cjs/TransformerLoggerCategory.d.ts → TransformerLoggerCategory.d.ts} +0 -0
- /package/lib/{cjs/TransformerPackageMetadata.d.ts → TransformerPackageMetadata.d.ts} +0 -0
- /package/lib/{cjs/schema-processing → schema-processing}/SchemaProcessingStrategy.d.ts +0 -0
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SyncTypeResolver = void 0;
|
|
4
1
|
/*---------------------------------------------------------------------------------------------
|
|
5
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
4
|
*--------------------------------------------------------------------------------------------*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
import { ITwinError } from "@itwin/core-bentley";
|
|
6
|
+
import { ElementOwnsExternalSourceAspects, ExternalSourceAspect, } from "@itwin/core-backend";
|
|
7
|
+
import { IModel } from "@itwin/core-common";
|
|
8
|
+
import { ProvenanceManager } from "./ProvenanceManager.js";
|
|
9
|
+
import { IModelTransformerError, IModelTransformerErrorScope, } from "./IModelTransformerError.js";
|
|
13
10
|
/**
|
|
14
11
|
* Encapsulates sync direction determination logic.
|
|
15
12
|
* Given a source and target iModel, resolves whether the transformation is
|
|
16
13
|
* a forward sync, reverse sync, or not a sync at all.
|
|
17
14
|
* @internal
|
|
18
15
|
*/
|
|
19
|
-
class SyncTypeResolver {
|
|
16
|
+
export class SyncTypeResolver {
|
|
20
17
|
static noEsaSyncDirectionErrorMessage = "Couldn't find an external source aspect to determine sync direction. This often means that the master->branch relationship has not been established. Consider running the transformer with wasSourceIModelCopiedToTarget set to true.";
|
|
21
18
|
_syncType;
|
|
22
19
|
_sourceDb;
|
|
@@ -43,31 +40,31 @@ class SyncTypeResolver {
|
|
|
43
40
|
const aspectProps = {
|
|
44
41
|
id: undefined,
|
|
45
42
|
version: undefined,
|
|
46
|
-
classFullName:
|
|
43
|
+
classFullName: ExternalSourceAspect.classFullName,
|
|
47
44
|
element: {
|
|
48
45
|
id: targetScopeElementId,
|
|
49
|
-
relClassName:
|
|
46
|
+
relClassName: ElementOwnsExternalSourceAspects.classFullName,
|
|
50
47
|
},
|
|
51
|
-
scope: { id:
|
|
48
|
+
scope: { id: IModel.rootSubjectId },
|
|
52
49
|
identifier: sourceDb.iModelId,
|
|
53
|
-
kind:
|
|
50
|
+
kind: ExternalSourceAspect.Kind.Scope,
|
|
54
51
|
jsonProperties: undefined,
|
|
55
52
|
};
|
|
56
53
|
// First check if the targetDb is the branch (branch is the provenanceDb)
|
|
57
|
-
const esaPropsFromTargetDb = await
|
|
54
|
+
const esaPropsFromTargetDb = await ProvenanceManager.queryScopeExternalSourceAspect(targetDb, aspectProps);
|
|
58
55
|
if (esaPropsFromTargetDb !== undefined) {
|
|
59
56
|
return "forward";
|
|
60
57
|
}
|
|
61
58
|
// Now check if the sourceDb is the branch
|
|
62
59
|
aspectProps.identifier = targetDb.iModelId;
|
|
63
|
-
const esaPropsFromSourceDb = await
|
|
60
|
+
const esaPropsFromSourceDb = await ProvenanceManager.queryScopeExternalSourceAspect(sourceDb, aspectProps);
|
|
64
61
|
if (esaPropsFromSourceDb !== undefined) {
|
|
65
62
|
return "reverse";
|
|
66
63
|
}
|
|
67
|
-
|
|
64
|
+
ITwinError.throwError({
|
|
68
65
|
iTwinErrorId: {
|
|
69
|
-
scope:
|
|
70
|
-
key:
|
|
66
|
+
scope: IModelTransformerErrorScope,
|
|
67
|
+
key: IModelTransformerError.SynchronizationTypeNotDetermined,
|
|
71
68
|
},
|
|
72
69
|
message: SyncTypeResolver.noEsaSyncDirectionErrorMessage,
|
|
73
70
|
});
|
|
@@ -88,5 +85,4 @@ class SyncTypeResolver {
|
|
|
88
85
|
return this._syncType;
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
|
-
exports.SyncTypeResolver = SyncTypeResolver;
|
|
92
88
|
//# sourceMappingURL=SyncTypeResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncTypeResolver.js","sourceRoot":"","sources":["../src/SyncTypeResolver.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;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AAC;IACxB,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 *--------------------------------------------------------------------------------------------*/\nimport { Id64String, ITwinError } from \"@itwin/core-bentley\";\nimport {\n ElementOwnsExternalSourceAspects,\n ExternalSourceAspect,\n IModelDb,\n} from \"@itwin/core-backend\";\nimport { IModel } from \"@itwin/core-common\";\nimport type { TargetScopeProvenanceJsonProps } from \"./IModelTransformer.js\";\nimport { ProvenanceManager } from \"./ProvenanceManager.js\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"./IModelTransformerError.js\";\n\n/** @internal */\nexport type SyncType = \"not-sync\" | \"forward\" | \"reverse\";\n\n/**\n * Encapsulates sync direction determination logic.\n * Given a source and target iModel, resolves whether the transformation is\n * a forward sync, reverse sync, or not a sync at all.\n * @internal\n */\nexport class SyncTypeResolver {\n public static noEsaSyncDirectionErrorMessage =\n \"Couldn't find an external source aspect to determine sync direction. This often means that the master->branch relationship has not been established. Consider running the transformer with wasSourceIModelCopiedToTarget set to true.\";\n\n private _syncType?: SyncType;\n private readonly _sourceDb: IModelDb;\n private readonly _targetDb: IModelDb;\n private readonly _targetScopeElementId: Id64String;\n private readonly _isProvenanceInitTransform: boolean;\n private readonly _isSyncTransform: boolean;\n\n public constructor(\n sourceDb: IModelDb,\n targetDb: IModelDb,\n targetScopeElementId: Id64String,\n isProvenanceInitTransform: boolean = false,\n isSyncTransform: boolean = false\n ) {\n this._sourceDb = sourceDb;\n this._targetDb = targetDb;\n this._targetScopeElementId = targetScopeElementId;\n this._isProvenanceInitTransform = isProvenanceInitTransform;\n this._isSyncTransform = isSyncTransform;\n }\n\n /**\n * Determines the sync direction \"forward\" or \"reverse\" of a given sourceDb and targetDb by looking for the scoping ESA.\n * If the sourceDb's iModelId is found as the identifier of the expected scoping ESA in the targetDb, then it is a forward synchronization.\n * If the targetDb's iModelId is found as the identifier of the expected scoping ESA in the sourceDb, then it is a reverse synchronization.\n * @note This is a standalone utility that does not depend on instance state.\n * @throws if no scoping ESA can be found in either the sourceDb or targetDb which describes a master branch relationship between the two databases.\n * @returns \"forward\" or \"reverse\"\n */\n public static async determineSyncType(\n sourceDb: IModelDb,\n targetDb: IModelDb,\n targetScopeElementId: Id64String\n ): Promise<\"forward\" | \"reverse\"> {\n const aspectProps = {\n id: undefined as string | undefined,\n version: undefined as string | undefined,\n classFullName: ExternalSourceAspect.classFullName,\n element: {\n id: targetScopeElementId,\n relClassName: ElementOwnsExternalSourceAspects.classFullName,\n },\n scope: { id: IModel.rootSubjectId },\n identifier: sourceDb.iModelId,\n kind: ExternalSourceAspect.Kind.Scope,\n jsonProperties: undefined as TargetScopeProvenanceJsonProps | undefined,\n };\n // First check if the targetDb is the branch (branch is the provenanceDb)\n const esaPropsFromTargetDb =\n await ProvenanceManager.queryScopeExternalSourceAspect(\n targetDb,\n aspectProps\n );\n if (esaPropsFromTargetDb !== undefined) {\n return \"forward\";\n }\n\n // Now check if the sourceDb is the branch\n aspectProps.identifier = targetDb.iModelId;\n const esaPropsFromSourceDb =\n await ProvenanceManager.queryScopeExternalSourceAspect(\n sourceDb,\n aspectProps\n );\n\n if (esaPropsFromSourceDb !== undefined) {\n return \"reverse\";\n }\n ITwinError.throwError({\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.SynchronizationTypeNotDetermined,\n },\n message: SyncTypeResolver.noEsaSyncDirectionErrorMessage,\n });\n }\n\n /** Returns the sync type, lazily resolving it on first call. */\n public async getSyncType(): Promise<SyncType> {\n if (this._syncType === undefined) {\n if (this._isProvenanceInitTransform) {\n this._syncType = \"forward\";\n } else if (!this._isSyncTransform) {\n this._syncType = \"not-sync\";\n } else {\n this._syncType = await SyncTypeResolver.determineSyncType(\n this._sourceDb,\n this._targetDb,\n this._targetScopeElementId\n );\n }\n }\n return this._syncType;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformerLoggerCategory.d.ts","sourceRoot":"","sources":["../src/TransformerLoggerCategory.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;GAIG;AACH,oBAAY,yBAAyB;IACnC;;OAEG;IACH,cAAc,sCAAsC;IAEpD;;OAEG;IACH,cAAc,sCAAsC;IAEpD;;OAEG;IACH,iBAAiB,yCAAyC;IAE1D;;OAEG;IACH,kBAAkB,0CAA0C;IAE5D,qBAAqB,6CAA6C;CACnE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*---------------------------------------------------------------------------------------------
|
|
3
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -6,14 +5,12 @@
|
|
|
6
5
|
/** @packageDocumentation
|
|
7
6
|
* @module Logging
|
|
8
7
|
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TransformerLoggerCategory = void 0;
|
|
11
8
|
/** Logger categories used by this package
|
|
12
9
|
* @note All logger categories in this package start with the `imodel-transformer` prefix.
|
|
13
10
|
* @see [Logger]($bentley)
|
|
14
11
|
* @public
|
|
15
12
|
*/
|
|
16
|
-
var TransformerLoggerCategory;
|
|
13
|
+
export var TransformerLoggerCategory;
|
|
17
14
|
(function (TransformerLoggerCategory) {
|
|
18
15
|
/** The logger category used by the [IModelExporter]($transformer) class.
|
|
19
16
|
* @beta
|
|
@@ -32,5 +29,5 @@ var TransformerLoggerCategory;
|
|
|
32
29
|
*/
|
|
33
30
|
TransformerLoggerCategory["IModelCloneContext"] = "imodel-transformer.IModelCloneContext";
|
|
34
31
|
TransformerLoggerCategory["ECReferenceTypesCache"] = "imodel-transformer.ECReferenceTypesCache";
|
|
35
|
-
})(TransformerLoggerCategory || (
|
|
32
|
+
})(TransformerLoggerCategory || (TransformerLoggerCategory = {}));
|
|
36
33
|
//# sourceMappingURL=TransformerLoggerCategory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformerLoggerCategory.js","sourceRoot":"","sources":["../src/TransformerLoggerCategory.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH;;;;GAIG;AACH,MAAM,CAAN,IAAY,yBAsBX;AAtBD,WAAY,yBAAyB;IACnC;;OAEG;IACH,iFAAoD,CAAA;IAEpD;;OAEG;IACH,iFAAoD,CAAA;IAEpD;;OAEG;IACH,uFAA0D,CAAA;IAE1D;;OAEG;IACH,yFAA4D,CAAA;IAE5D,+FAAkE,CAAA;AACpE,CAAC,EAtBW,yBAAyB,KAAzB,yBAAyB,QAsBpC","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 Logging\n */\n\n/** Logger categories used by this package\n * @note All logger categories in this package start with the `imodel-transformer` prefix.\n * @see [Logger]($bentley)\n * @public\n */\nexport enum TransformerLoggerCategory {\n /** The logger category used by the [IModelExporter]($transformer) class.\n * @beta\n */\n IModelExporter = \"imodel-transformer.IModelExporter\",\n\n /** The logger category used by the [IModelImporter]($transformer) class.\n * @beta\n */\n IModelImporter = \"imodel-transformer.IModelImporter\",\n\n /** The logger category used by the [IModelTransformer]($transformer) class.\n * @beta\n */\n IModelTransformer = \"imodel-transformer.IModelTransformer\",\n\n /** The logger category used while cloning entities and remapping their references.\n * @beta\n */\n IModelCloneContext = \"imodel-transformer.IModelCloneContext\",\n\n ECReferenceTypesCache = \"imodel-transformer.ECReferenceTypesCache\",\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformerPackageMetadata.d.ts","sourceRoot":"","sources":["../src/TransformerPackageMetadata.ts"],"names":[],"mappings":"AAOA,UAAU,0BAA0B;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAGD,eAAO,MAAM,0BAA0B,EAElC,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
// Both src/ (tests) and lib/ (published output) sit directly below the package root.
|
|
7
|
+
export const transformerPackageMetadata = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
8
|
+
//# sourceMappingURL=TransformerPackageMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformerPackageMetadata.js","sourceRoot":"","sources":["../src/TransformerPackageMetadata.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQvC,qFAAqF;AACrF,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAClD,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CACpC,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\nimport { readFileSync } from \"node:fs\";\n\ninterface TransformerPackageMetadata {\n name: string;\n version: string;\n peerDependencies: Record<string, string>;\n}\n\n// Both src/ (tests) and lib/ (published output) sit directly below the package root.\nexport const transformerPackageMetadata = JSON.parse(\n readFileSync(new URL(\"../package.json\", import.meta.url), \"utf8\")\n) as TransformerPackageMetadata;\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from "./TransformerLoggerCategory";
|
|
2
|
-
export * from "./IModelExporter";
|
|
3
|
-
export * from "./IModelImporter";
|
|
4
|
-
export * from "./IModelTransformer";
|
|
5
|
-
export * from "./IModelTransformContext";
|
|
6
|
-
export * from "./schema-processing/SchemaProcessingStrategy";
|
|
7
|
-
export * from "./IModelTransformerError";
|
|
8
|
-
export * from "./BranchProvenanceInitializer";
|
|
9
|
-
export type { CollectedChanges, DeletionBatch, DeletionRecordBase, ElementDeletionRecord, ExternalSourceAspectDeletionRecord, ModelDeletionRecord, RelationshipDeletionRecord, } from "./ChangesetScanner";
|
|
1
|
+
export * from "./TransformerLoggerCategory.js";
|
|
2
|
+
export * from "./IModelExporter.js";
|
|
3
|
+
export * from "./IModelImporter.js";
|
|
4
|
+
export * from "./IModelTransformer.js";
|
|
5
|
+
export * from "./IModelTransformContext.js";
|
|
6
|
+
export * from "./schema-processing/SchemaProcessingStrategy.js";
|
|
7
|
+
export * from "./IModelTransformerError.js";
|
|
8
|
+
export * from "./BranchProvenanceInitializer.js";
|
|
9
|
+
export type { CollectedChanges, DeletionBatch, DeletionRecordBase, ElementDeletionRecord, ExternalSourceAspectDeletionRecord, ModelDeletionRecord, RelationshipDeletionRecord, } from "./ChangesetScanner.js";
|
|
10
10
|
/** @docs-package-description
|
|
11
11
|
* The @itwin/imodel-transformer package contains classes that [backend code]($docs/learning/backend/index.md) can use to
|
|
12
12
|
* traverse iModels, as well as *transform* an iModel into another existing or empty one, by exporting elements from one during
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imodel-transformer.d.ts","sourceRoot":"","sources":["../src/imodel-transformer.ts"],"names":[],"mappings":"AAIA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iDAAiD,CAAC;AAChE,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,YAAY,EACV,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,kCAAkC,EAClC,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAoD/B;;;;;;GAMG;AACH;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export * from "./TransformerLoggerCategory.js";
|
|
6
|
+
export * from "./IModelExporter.js";
|
|
7
|
+
export * from "./IModelImporter.js";
|
|
8
|
+
export * from "./IModelTransformer.js";
|
|
9
|
+
export * from "./IModelTransformContext.js";
|
|
10
|
+
export * from "./schema-processing/SchemaProcessingStrategy.js";
|
|
11
|
+
export * from "./IModelTransformerError.js";
|
|
12
|
+
export * from "./BranchProvenanceInitializer.js";
|
|
13
|
+
import * as semver from "semver";
|
|
14
|
+
import { ITwinError } from "@itwin/core-bentley";
|
|
15
|
+
import coreBackendPackage from "@itwin/core-backend/package.json" with { type: "json" };
|
|
16
|
+
import { IModelTransformerError, IModelTransformerErrorScope, } from "./IModelTransformerError.js";
|
|
17
|
+
import { transformerPackageMetadata } from "./TransformerPackageMetadata.js";
|
|
18
|
+
const { version: ourVersion, name: ourName, peerDependencies, } = transformerPackageMetadata;
|
|
19
|
+
const iTwinCoreBackendVersion = coreBackendPackage.version;
|
|
20
|
+
const ourITwinCoreBackendDepRange = peerDependencies["@itwin/core-backend"];
|
|
21
|
+
const noStrictDepCheckEnvVar = "TRANSFORMER_NO_STRICT_DEP_CHECK";
|
|
22
|
+
// warn if using a prerelease or dev version
|
|
23
|
+
if (semver.prerelease(iTwinCoreBackendVersion)) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.warn(`Warning: dev version detected (${iTwinCoreBackendVersion}). ` +
|
|
26
|
+
"This version is most likely fine, but it may introduce new behavior that could cause " +
|
|
27
|
+
"unexpected issues or changes in the transformer's functionality. Please proceed with caution.");
|
|
28
|
+
}
|
|
29
|
+
if (process.env[noStrictDepCheckEnvVar] !== "1" &&
|
|
30
|
+
!semver.satisfies(iTwinCoreBackendVersion, ourITwinCoreBackendDepRange, {
|
|
31
|
+
includePrerelease: true,
|
|
32
|
+
})) {
|
|
33
|
+
const errHeader = `${ourName}@${ourVersion} only supports @itwin/core-backend@${ourITwinCoreBackendDepRange}, ` +
|
|
34
|
+
`but @itwin/core-backend${iTwinCoreBackendVersion} was resolved when looking for the peer dependency.\n` +
|
|
35
|
+
`If you know exactly what you are doing, you can disable this check by setting ${noStrictDepCheckEnvVar}=1 in the environment\n`;
|
|
36
|
+
ITwinError.throwError({
|
|
37
|
+
iTwinErrorId: {
|
|
38
|
+
scope: IModelTransformerErrorScope,
|
|
39
|
+
key: IModelTransformerError.DependencyVersionMismatch,
|
|
40
|
+
},
|
|
41
|
+
message: errHeader,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** @docs-package-description
|
|
45
|
+
* The @itwin/imodel-transformer package contains classes that [backend code]($docs/learning/backend/index.md) can use to
|
|
46
|
+
* traverse iModels, as well as *transform* an iModel into another existing or empty one, by exporting elements from one during
|
|
47
|
+
* traversal and importing them into another.
|
|
48
|
+
*
|
|
49
|
+
* You can read further in [iModelTransformation and Data Exchange]($docs/learning/transformer/index.md) here.
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* @docs-group-description iModels
|
|
53
|
+
* Classes for working with [iModels]($docs/learning/iModels.md).
|
|
54
|
+
* See [the learning article]($docs/learning/backend/index.md).
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* @docs-group-description Utils
|
|
58
|
+
* Miscellaneous utility classes.
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* @docs-group-description Logging
|
|
62
|
+
* Logger categories used by this package.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* @docs-group-description ChangedElementForest
|
|
66
|
+
* Internal indexing of changed elements and their ancestors for incremental export traversal.
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* @docs-group-description ElementAspectExportCoordinator
|
|
70
|
+
* Internal coordination for scoped, owner-batched ElementAspect export.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* @docs-group-description ElementAspectExportProcessor
|
|
74
|
+
* Internal source queries, filtering, and export callbacks for ElementAspects owned by accepted elements.
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* @docs-group-description ChangedElementForest
|
|
78
|
+
* Internal index of changed elements and their ancestors for incremental traversal.
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* @docs-group-description IModelTransformerError
|
|
82
|
+
* Stable identifiers for errors originating from this package.
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* @docs-group-description TransformerPackageMetadata
|
|
86
|
+
* Internal metadata describing this package and its peer dependencies.
|
|
87
|
+
*/
|
|
88
|
+
//# sourceMappingURL=imodel-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imodel-transformer.js","sourceRoot":"","sources":["../src/imodel-transformer.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iDAAiD,CAAC;AAChE,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;A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L,CAAC;AAED;;;;;;GAMG;AACH;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","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 *--------------------------------------------------------------------------------------------*/\nexport * from \"./TransformerLoggerCategory.js\";\nexport * from \"./IModelExporter.js\";\nexport * from \"./IModelImporter.js\";\nexport * from \"./IModelTransformer.js\";\nexport * from \"./IModelTransformContext.js\";\nexport * from \"./schema-processing/SchemaProcessingStrategy.js\";\nexport * from \"./IModelTransformerError.js\";\nexport * from \"./BranchProvenanceInitializer.js\";\nexport type {\n CollectedChanges,\n DeletionBatch,\n DeletionRecordBase,\n ElementDeletionRecord,\n ExternalSourceAspectDeletionRecord,\n ModelDeletionRecord,\n RelationshipDeletionRecord,\n} from \"./ChangesetScanner.js\";\n\nimport * as semver from \"semver\";\nimport { ITwinError } from \"@itwin/core-bentley\";\nimport coreBackendPackage from \"@itwin/core-backend/package.json\" with { type: \"json\" };\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"./IModelTransformerError.js\";\nimport { transformerPackageMetadata } from \"./TransformerPackageMetadata.js\";\n\nconst {\n version: ourVersion,\n name: ourName,\n peerDependencies,\n} = transformerPackageMetadata;\nconst iTwinCoreBackendVersion = coreBackendPackage.version;\n\nconst ourITwinCoreBackendDepRange = peerDependencies[\"@itwin/core-backend\"];\n\nconst noStrictDepCheckEnvVar = \"TRANSFORMER_NO_STRICT_DEP_CHECK\";\n\n// warn if using a prerelease or dev version\nif (semver.prerelease(iTwinCoreBackendVersion)) {\n // eslint-disable-next-line no-console\n console.warn(\n `Warning: dev version detected (${iTwinCoreBackendVersion}). ` +\n \"This version is most likely fine, but it may introduce new behavior that could cause \" +\n \"unexpected issues or changes in the transformer's functionality. Please proceed with caution.\"\n );\n}\n\nif (\n process.env[noStrictDepCheckEnvVar] !== \"1\" &&\n !semver.satisfies(iTwinCoreBackendVersion, ourITwinCoreBackendDepRange, {\n includePrerelease: true,\n })\n) {\n const errHeader =\n `${ourName}@${ourVersion} only supports @itwin/core-backend@${ourITwinCoreBackendDepRange}, ` +\n `but @itwin/core-backend${iTwinCoreBackendVersion} was resolved when looking for the peer dependency.\\n` +\n `If you know exactly what you are doing, you can disable this check by setting ${noStrictDepCheckEnvVar}=1 in the environment\\n`;\n\n ITwinError.throwError({\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.DependencyVersionMismatch,\n },\n message: errHeader,\n });\n}\n\n/** @docs-package-description\n * The @itwin/imodel-transformer package contains classes that [backend code]($docs/learning/backend/index.md) can use to\n * traverse iModels, as well as *transform* an iModel into another existing or empty one, by exporting elements from one during\n * traversal and importing them into another.\n *\n * You can read further in [iModelTransformation and Data Exchange]($docs/learning/transformer/index.md) here.\n */\n/**\n * @docs-group-description iModels\n * Classes for working with [iModels]($docs/learning/iModels.md).\n * See [the learning article]($docs/learning/backend/index.md).\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description Logging\n * Logger categories used by this package.\n */\n/**\n * @docs-group-description ChangedElementForest\n * Internal indexing of changed elements and their ancestors for incremental export traversal.\n */\n/**\n * @docs-group-description ElementAspectExportCoordinator\n * Internal coordination for scoped, owner-batched ElementAspect export.\n */\n/**\n * @docs-group-description ElementAspectExportProcessor\n * Internal source queries, filtering, and export callbacks for ElementAspects owned by accepted elements.\n */\n/**\n * @docs-group-description ChangedElementForest\n * Internal index of changed elements and their ancestors for incremental traversal.\n */\n/**\n * @docs-group-description IModelTransformerError\n * Stable identifiers for errors originating from this package.\n */\n/**\n * @docs-group-description TransformerPackageMetadata\n * Internal metadata describing this package and its peer dependencies.\n */\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { SchemaDifferenceResult } from "@itwin/ecschema-editing";
|
|
5
5
|
import { Schema } from "@itwin/ecschema-metadata";
|
|
6
|
-
import { SchemaProcessingContext, SchemaProcessingResult, SchemaProcessingStrategy } from "./SchemaProcessingStrategy";
|
|
6
|
+
import { SchemaProcessingContext, SchemaProcessingResult, SchemaProcessingStrategy } from "./SchemaProcessingStrategy.js";
|
|
7
7
|
/**
|
|
8
8
|
* Processes ordinary schemas with newer-version selection and unions compatible
|
|
9
9
|
* differences for existing dynamic schemas. Dynamic schema root read and write
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicSchemaUnionStrategy.d.ts","sourceRoot":"","sources":["../../src/schema-processing/DynamicSchemaUnionStrategy.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAKL,sBAAsB,EAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,MAAM,EAGP,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAEL,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,+BAA+B,CAAC;AAsBvC;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,wBAAwB;IACzE;;;;;;;;;OASG;IACH,UAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,sBAAsB,GAClC,OAAO,CAAC,sBAAsB,CAAC,CAEjC;IAED,+EAA+E;IAClE,cAAc,CACzB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,EAAE,CAAC,CA2EnC;YAEa,UAAU;CAwDzB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*---------------------------------------------------------------------------------------------
|
|
3
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -6,19 +5,17 @@
|
|
|
6
5
|
/** @packageDocumentation
|
|
7
6
|
* @module iModels
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
14
|
-
const IModelTransformerError_1 = require("../IModelTransformerError");
|
|
8
|
+
import { ITwinError } from "@itwin/core-bentley";
|
|
9
|
+
import { ConflictCode, getSchemaDifferences, SchemaConflictsError, SchemaMerger, } from "@itwin/ecschema-editing";
|
|
10
|
+
import { SchemaContext, SchemaKey, } from "@itwin/ecschema-metadata";
|
|
11
|
+
import { IModelTransformerError, IModelTransformerErrorScope, } from "../IModelTransformerError.js";
|
|
15
12
|
/**
|
|
16
13
|
* Processes ordinary schemas with newer-version selection and unions compatible
|
|
17
14
|
* differences for existing dynamic schemas. Dynamic schema root read and write
|
|
18
15
|
* versions must match; only the minor version may differ.
|
|
19
16
|
* @beta
|
|
20
17
|
*/
|
|
21
|
-
class DynamicSchemaUnionStrategy {
|
|
18
|
+
export class DynamicSchemaUnionStrategy {
|
|
22
19
|
/**
|
|
23
20
|
* Transform schema differences before conflict validation and merging.
|
|
24
21
|
* A subclass that changes the differencing result is responsible for ensuring
|
|
@@ -41,7 +38,7 @@ class DynamicSchemaUnionStrategy {
|
|
|
41
38
|
plans.push(await this.createPlan(sourceSchema, context.targetSchemas));
|
|
42
39
|
}
|
|
43
40
|
catch (error) {
|
|
44
|
-
if (
|
|
41
|
+
if (ITwinError.isError(error, IModelTransformerErrorScope, IModelTransformerError.SchemaConflict)) {
|
|
45
42
|
conflicts.push(error);
|
|
46
43
|
continue;
|
|
47
44
|
}
|
|
@@ -49,7 +46,7 @@ class DynamicSchemaUnionStrategy {
|
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
throwSchemaConflicts(conflicts);
|
|
52
|
-
const schemaEditingContext = new
|
|
49
|
+
const schemaEditingContext = new SchemaContext();
|
|
53
50
|
const schemaCandidates = new Map();
|
|
54
51
|
for (const plan of plans) {
|
|
55
52
|
if (plan.kind === "dynamic-merge") {
|
|
@@ -64,7 +61,7 @@ class DynamicSchemaUnionStrategy {
|
|
|
64
61
|
for (const { schema } of schemaCandidates.values()) {
|
|
65
62
|
await schemaEditingContext.addSchema(schema);
|
|
66
63
|
}
|
|
67
|
-
const schemaMerger = new
|
|
64
|
+
const schemaMerger = new SchemaMerger(schemaEditingContext);
|
|
68
65
|
const results = [];
|
|
69
66
|
for (const plan of plans) {
|
|
70
67
|
switch (plan.kind) {
|
|
@@ -111,23 +108,22 @@ class DynamicSchemaUnionStrategy {
|
|
|
111
108
|
sourceVersion.write !== targetVersion.write) {
|
|
112
109
|
throw createSchemaConflictError(source, "Dynamic schema has incompatible root versions", new Error(`source ${sourceVersion.toString(false)}, target ${targetVersion.toString(false)}`));
|
|
113
110
|
}
|
|
114
|
-
const differences = await this.onSchemaDifferences(source, target, await
|
|
111
|
+
const differences = await this.onSchemaDifferences(source, target, await getSchemaDifferences(target, source));
|
|
115
112
|
const unresolvedConflicts = (differences.conflicts ?? []).filter((conflict) => !isCompatibleReferenceVersionConflict(conflict));
|
|
116
113
|
if (unresolvedConflicts.length > 0) {
|
|
117
|
-
throw createSchemaConflictError(source, "Schema conflict", new
|
|
114
|
+
throw createSchemaConflictError(source, "Schema conflict", new SchemaConflictsError(`Schema '${source.name}' has unresolved conflicts`, unresolvedConflicts, source.schemaKey, target.schemaKey));
|
|
118
115
|
}
|
|
119
116
|
return differences.differences.length === 0
|
|
120
117
|
? { kind: "dynamic-noop", source, target }
|
|
121
118
|
: { kind: "dynamic-merge", source, target, differences };
|
|
122
119
|
}
|
|
123
120
|
}
|
|
124
|
-
exports.DynamicSchemaUnionStrategy = DynamicSchemaUnionStrategy;
|
|
125
121
|
function createSchemaConflictError(schema, operation, cause) {
|
|
126
|
-
return
|
|
122
|
+
return ITwinError.create({
|
|
127
123
|
message: `${operation} for '${schema.schemaKey.toString(false)}': ${cause.message}`,
|
|
128
124
|
iTwinErrorId: {
|
|
129
|
-
scope:
|
|
130
|
-
key:
|
|
125
|
+
scope: IModelTransformerErrorScope,
|
|
126
|
+
key: IModelTransformerError.SchemaConflict,
|
|
131
127
|
},
|
|
132
128
|
cause,
|
|
133
129
|
schemaKey: schema.schemaKey.toString(false),
|
|
@@ -169,13 +165,13 @@ function incrementMinorVersion(sourceVersion, targetVersion) {
|
|
|
169
165
|
return maximumVersion.minor + 1;
|
|
170
166
|
}
|
|
171
167
|
function isCompatibleReferenceVersionConflict(conflict) {
|
|
172
|
-
if (conflict.code !==
|
|
168
|
+
if (conflict.code !== ConflictCode.ConflictingReferenceVersion)
|
|
173
169
|
return false;
|
|
174
170
|
if (typeof conflict.source !== "string" ||
|
|
175
171
|
typeof conflict.target !== "string")
|
|
176
172
|
return false;
|
|
177
|
-
const sourceVersion =
|
|
178
|
-
const targetVersion =
|
|
173
|
+
const sourceVersion = SchemaKey.parseString(conflict.source).version;
|
|
174
|
+
const targetVersion = SchemaKey.parseString(conflict.target).version;
|
|
179
175
|
return (sourceVersion.read === targetVersion.read &&
|
|
180
176
|
sourceVersion.write === targetVersion.write);
|
|
181
177
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicSchemaUnionStrategy.js","sourceRoot":"","sources":["../../src/schema-processing/DynamicSchemaUnionStrategy.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAEL,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,EAEpB,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,aAAa,EACb,SAAS,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AA4BtC;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IACrC;;;;;;;;;OASG;IACO,KAAK,CAAC,mBAAmB,CACjC,aAAqB,EACrB,aAAqB,EACrB,WA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;QACD,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,uBAAuB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED,SAAS,uBAAuB,CAC9B,MAAc,EACd,UAAwC;IAExC,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,uBAAuB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;AACH,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 iModels\n */\n\nimport { ITwinError } from \"@itwin/core-bentley\";\nimport {\n AnySchemaDifferenceConflict,\n ConflictCode,\n getSchemaDifferences,\n SchemaConflictsError,\n SchemaDifferenceResult,\n SchemaMerger,\n} from \"@itwin/ecschema-editing\";\nimport {\n ECVersion,\n Schema,\n SchemaContext,\n SchemaKey,\n} from \"@itwin/ecschema-metadata\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"../IModelTransformerError.js\";\nimport {\n ReadonlySchemaAccessor,\n SchemaProcessingContext,\n SchemaProcessingResult,\n SchemaProcessingStrategy,\n} from \"./SchemaProcessingStrategy.js\";\n\ntype SchemaPlan =\n | { kind: \"new\"; source: Schema }\n | { kind: \"ordinary\"; source: Schema; target: Schema }\n | { kind: \"dynamic-noop\"; source: Schema; target: Schema }\n | {\n kind: \"dynamic-merge\";\n source: Schema;\n target: Schema;\n differences: SchemaDifferenceResult;\n };\n\ninterface SchemaCandidate {\n schema: Schema;\n isTargetRoot: boolean;\n}\n\ninterface SchemaConflictError extends ITwinError {\n schemaKey: string;\n}\n\n/**\n * Processes ordinary schemas with newer-version selection and unions compatible\n * differences for existing dynamic schemas. Dynamic schema root read and write\n * versions must match; only the minor version may differ.\n * @beta\n */\nexport class DynamicSchemaUnionStrategy implements SchemaProcessingStrategy {\n /**\n * Transform schema differences before conflict validation and merging.\n * A subclass that changes the differencing result is responsible for ensuring\n * that its changes are safe for the source and target schemas.\n * @param sourceSchema The source schema being processed.\n * @param targetSchema The existing target schema.\n * @param differences The complete result from [[getSchemaDifferences]].\n * @returns The differencing result to validate and merge.\n * @beta\n */\n protected async onSchemaDifferences(\n _sourceSchema: Schema,\n _targetSchema: Schema,\n differences: SchemaDifferenceResult\n ): Promise<SchemaDifferenceResult> {\n return differences;\n }\n\n /** Select ordinary schemas and union compatible dynamic schema differences. */\n public async processSchemas(\n context: SchemaProcessingContext\n ): Promise<SchemaProcessingResult[]> {\n const plans: SchemaPlan[] = [];\n const conflicts: Error[] = [];\n for (const sourceSchema of context.sourceSchemas) {\n try {\n plans.push(await this.createPlan(sourceSchema, context.targetSchemas));\n } catch (error: unknown) {\n if (\n ITwinError.isError(\n error,\n IModelTransformerErrorScope,\n IModelTransformerError.SchemaConflict\n )\n ) {\n conflicts.push(error);\n continue;\n }\n throw error;\n }\n }\n throwSchemaConflicts(conflicts);\n\n const schemaEditingContext = new SchemaContext();\n const schemaCandidates = new Map<string, SchemaCandidate>();\n for (const plan of plans) {\n if (plan.kind === \"dynamic-merge\") {\n collectSchemaCandidates(plan.target, schemaCandidates, true);\n collectSchemaReferences(plan.source, schemaCandidates);\n } else if (plan.kind === \"dynamic-noop\") {\n collectSchemaCandidates(plan.source, schemaCandidates, false);\n collectSchemaReferences(plan.source, schemaCandidates);\n }\n }\n for (const { schema } of schemaCandidates.values()) {\n await schemaEditingContext.addSchema(schema);\n }\n\n const schemaMerger = new SchemaMerger(schemaEditingContext);\n const results: SchemaProcessingResult[] = [];\n for (const plan of plans) {\n switch (plan.kind) {\n case \"new\":\n if (\n plan.source.isDynamic ||\n (await context.shouldExportSchema(plan.source.schemaKey))\n ) {\n results.push({ kind: \"source\", schema: plan.source });\n }\n break;\n case \"ordinary\":\n if (await context.shouldExportSchema(plan.source.schemaKey)) {\n results.push({ kind: \"source\", schema: plan.source });\n }\n break;\n case \"dynamic-noop\":\n break;\n case \"dynamic-merge\": {\n const mergedSchema = await schemaMerger.merge({\n ...plan.differences,\n conflicts: undefined,\n });\n const sourceVersion = plan.source.schemaKey.version;\n mergedSchema.setVersion(\n sourceVersion.read,\n sourceVersion.write,\n incrementMinorVersion(sourceVersion, plan.target.schemaKey.version)\n );\n results.push({ kind: \"generated\", schema: mergedSchema });\n break;\n }\n }\n }\n\n appendRequiredNoOpSchemas(results, plans);\n return results;\n }\n\n private async createPlan(\n source: Schema,\n targetSchemas: ReadonlySchemaAccessor\n ): Promise<SchemaPlan> {\n const target = await targetSchemas.getSchema(source.name);\n if (target === undefined) return { kind: \"new\", source };\n\n if (source.isDynamic !== target.isDynamic) {\n throw createSchemaConflictError(\n source,\n \"Schema DynamicSchema marker changed\",\n new Error(\"The source and target DynamicSchema markers differ.\")\n );\n }\n if (!source.isDynamic) return { kind: \"ordinary\", source, target };\n\n const sourceVersion = source.schemaKey.version;\n const targetVersion = target.schemaKey.version;\n if (\n sourceVersion.read !== targetVersion.read ||\n sourceVersion.write !== targetVersion.write\n ) {\n throw createSchemaConflictError(\n source,\n \"Dynamic schema has incompatible root versions\",\n new Error(\n `source ${sourceVersion.toString(false)}, target ${targetVersion.toString(false)}`\n )\n );\n }\n\n const differences = await this.onSchemaDifferences(\n source,\n target,\n await getSchemaDifferences(target, source)\n );\n const unresolvedConflicts = (differences.conflicts ?? []).filter(\n (conflict) => !isCompatibleReferenceVersionConflict(conflict)\n );\n if (unresolvedConflicts.length > 0) {\n throw createSchemaConflictError(\n source,\n \"Schema conflict\",\n new SchemaConflictsError(\n `Schema '${source.name}' has unresolved conflicts`,\n unresolvedConflicts,\n source.schemaKey,\n target.schemaKey\n )\n );\n }\n\n return differences.differences.length === 0\n ? { kind: \"dynamic-noop\", source, target }\n : { kind: \"dynamic-merge\", source, target, differences };\n }\n}\n\nfunction createSchemaConflictError(\n schema: Schema,\n operation: string,\n cause: Error\n): Error {\n return ITwinError.create<SchemaConflictError>({\n message: `${operation} for '${schema.schemaKey.toString(false)}': ${cause.message}`,\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.SchemaConflict,\n },\n cause,\n schemaKey: schema.schemaKey.toString(false),\n });\n}\n\nfunction throwSchemaConflicts(conflicts: Error[]): void {\n if (conflicts.length === 1) throw conflicts[0];\n if (conflicts.length > 1)\n throw new AggregateError(conflicts, \"Schema processing failed\");\n}\n\nfunction appendRequiredNoOpSchemas(\n results: SchemaProcessingResult[],\n plans: SchemaPlan[]\n): void {\n const noOpSchemas = new Map(\n plans\n .filter((plan) => plan.kind === \"dynamic-noop\")\n .map((plan) => [plan.source.name.toLowerCase(), plan.source])\n );\n const requiredNoOpSchemas = new Set<string>();\n const schemasToVisit = results.map((result) => result.schema);\n for (const schema of schemasToVisit) {\n for (const reference of schema.references) {\n const schemaName = reference.name.toLowerCase();\n const noOpSchema = noOpSchemas.get(schemaName);\n if (noOpSchema === undefined || requiredNoOpSchemas.has(schemaName))\n continue;\n\n requiredNoOpSchemas.add(schemaName);\n schemasToVisit.push(noOpSchema);\n }\n }\n for (const schemaName of requiredNoOpSchemas) {\n const schema = noOpSchemas.get(schemaName);\n if (schema !== undefined) results.push({ kind: \"source\", schema });\n }\n}\n\nfunction incrementMinorVersion(\n sourceVersion: ECVersion,\n targetVersion: ECVersion\n): number {\n const maximumVersion =\n sourceVersion.compare(targetVersion) >= 0 ? sourceVersion : targetVersion;\n if (maximumVersion.minor >= 9_999_999) {\n throw new Error(\n `Cannot increment schema version ${maximumVersion.toString(false)}`\n );\n }\n return maximumVersion.minor + 1;\n}\n\nfunction isCompatibleReferenceVersionConflict(\n conflict: AnySchemaDifferenceConflict\n): boolean {\n if (conflict.code !== ConflictCode.ConflictingReferenceVersion) return false;\n if (\n typeof conflict.source !== \"string\" ||\n typeof conflict.target !== \"string\"\n )\n return false;\n\n const sourceVersion = SchemaKey.parseString(conflict.source).version;\n const targetVersion = SchemaKey.parseString(conflict.target).version;\n return (\n sourceVersion.read === targetVersion.read &&\n sourceVersion.write === targetVersion.write\n );\n}\n\nfunction collectSchemaCandidates(\n schema: Schema,\n candidates: Map<string, SchemaCandidate>,\n isTargetRoot: boolean,\n visited: Set<string> = new Set<string>()\n): void {\n const traversalKey = schema.schemaKey.toString();\n if (visited.has(traversalKey)) return;\n visited.add(traversalKey);\n\n const schemaName = schema.name.toLowerCase();\n const existing = candidates.get(schemaName);\n if (existing === undefined) {\n candidates.set(schemaName, { schema, isTargetRoot });\n } else if (\n existing.schema.schemaKey.version.read !== schema.schemaKey.version.read ||\n existing.schema.schemaKey.version.write !== schema.schemaKey.version.write\n ) {\n throw createSchemaConflictError(\n schema,\n \"Schema reference has incompatible read/write versions\",\n new Error(\n `${existing.schema.schemaKey.version.read}.${existing.schema.schemaKey.version.write} ` +\n `and ${schema.schemaKey.version.read}.${schema.schemaKey.version.write} differ. ` +\n \"Only minor-version reference differences are supported.\"\n )\n );\n } else if (\n isTargetRoot ||\n (!existing.isTargetRoot &&\n schema.schemaKey.version.compare(existing.schema.schemaKey.version) > 0)\n ) {\n candidates.set(schemaName, { schema, isTargetRoot });\n }\n\n for (const reference of schema.references) {\n collectSchemaCandidates(reference, candidates, false, visited);\n }\n}\n\nfunction collectSchemaReferences(\n schema: Schema,\n candidates: Map<string, SchemaCandidate>\n): void {\n for (const reference of schema.references) {\n collectSchemaCandidates(reference, candidates, false);\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IModelDb } from "@itwin/core-backend";
|
|
2
2
|
import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
|
|
3
|
-
import { ExportSchemaResult, IModelExporter } from "../IModelExporter";
|
|
4
|
-
import { SchemaProcessingStrategy } from "./SchemaProcessingStrategy";
|
|
3
|
+
import { ExportSchemaResult, IModelExporter } from "../IModelExporter.js";
|
|
4
|
+
import { SchemaProcessingStrategy } from "./SchemaProcessingStrategy.js";
|
|
5
5
|
interface SchemaProcessingCoordinatorArgs {
|
|
6
6
|
exporter: IModelExporter;
|
|
7
7
|
targetDb: IModelDb;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaProcessingCoordinator.d.ts","sourceRoot":"","sources":["../../src/schema-processing/SchemaProcessingCoordinator.ts"],"names":[],"mappings":"AAOA,OAAO,EAAsB,QAAQ,EAAc,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAgB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK1E,OAAO,EAGL,wBAAwB,EACzB,MAAM,+BAA+B,CAAC;AAEvC,UAAU,+BAA+B;IACvC,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,wBAAwB,EAAE,MAAM,MAAM,CAAC;IACvC,kBAAkB,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/D,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CAAC;CAC/E;AAED,gBAAgB;AAChB,qBAAa,2BAA2B;IAGnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6B;IAE/D,YAAoC,KAAK,EAAE,+BAA+B,EAAI;IAEjE,OAAO,CAAC,QAAQ,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmEtE;IAEY,qBAAqB,CAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,kBAAkB,CAAC,CAU7B;IAED,OAAO,KAAK,sBAAsB,GAEjC;YAEa,eAAe;IAe7B,OAAO,CAAC,uBAAuB;IAkB/B,OAAO,CAAC,oCAAoC;CAU7C"}
|
|
@@ -1,50 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*---------------------------------------------------------------------------------------------
|
|
3
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
4
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
-
var ownKeys = function(o) {
|
|
24
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
-
var ar = [];
|
|
26
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
return ownKeys(o);
|
|
30
|
-
};
|
|
31
|
-
return function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.SchemaProcessingCoordinator = void 0;
|
|
41
|
-
const path = __importStar(require("node:path"));
|
|
42
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
43
|
-
const core_backend_1 = require("@itwin/core-backend");
|
|
44
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
45
|
-
const IModelTransformerError_1 = require("../IModelTransformerError");
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { ITwinError } from "@itwin/core-bentley";
|
|
7
|
+
import { ECSchemaXmlContext, IModelJsFs } from "@itwin/core-backend";
|
|
8
|
+
import { SchemaLoader } from "@itwin/ecschema-metadata";
|
|
9
|
+
import { IModelTransformerError, IModelTransformerErrorScope, } from "../IModelTransformerError.js";
|
|
46
10
|
/** @internal */
|
|
47
|
-
class SchemaProcessingCoordinator {
|
|
11
|
+
export class SchemaProcessingCoordinator {
|
|
48
12
|
_args;
|
|
49
13
|
_longNamedSchemas = new Map();
|
|
50
14
|
constructor(_args) {
|
|
@@ -53,13 +17,13 @@ class SchemaProcessingCoordinator {
|
|
|
53
17
|
async process(strategy) {
|
|
54
18
|
let processingFailure;
|
|
55
19
|
try {
|
|
56
|
-
|
|
20
|
+
IModelJsFs.mkdirSync(this._schemaExportDirectory);
|
|
57
21
|
this._longNamedSchemas.clear();
|
|
58
22
|
const sourceSchemas = [];
|
|
59
23
|
for await (const schema of this._args.exporter.enumerateSchemas()) {
|
|
60
24
|
sourceSchemas.push(schema);
|
|
61
25
|
}
|
|
62
|
-
const targetSchemaLoader = new
|
|
26
|
+
const targetSchemaLoader = new SchemaLoader((name) => this._args.targetDb.getSchemaProps(name));
|
|
63
27
|
const targetSchemas = {
|
|
64
28
|
getSchema: async (schemaName) => targetSchemaLoader.tryGetSchema(schemaName),
|
|
65
29
|
};
|
|
@@ -71,7 +35,7 @@ class SchemaProcessingCoordinator {
|
|
|
71
35
|
for (const result of processedSchemas) {
|
|
72
36
|
await this.serializeSchema(result);
|
|
73
37
|
}
|
|
74
|
-
const exportedSchemaFiles =
|
|
38
|
+
const exportedSchemaFiles = IModelJsFs.readdirSync(this._schemaExportDirectory);
|
|
75
39
|
if (exportedSchemaFiles.length > 0) {
|
|
76
40
|
await this._args.targetDb.importSchemas(exportedSchemaFiles.map((fileName) => path.join(this._schemaExportDirectory, fileName)), {
|
|
77
41
|
ecSchemaXmlContext: this._longNamedSchemas.size > 0
|
|
@@ -85,7 +49,7 @@ class SchemaProcessingCoordinator {
|
|
|
85
49
|
}
|
|
86
50
|
let cleanupFailure;
|
|
87
51
|
try {
|
|
88
|
-
|
|
52
|
+
IModelJsFs.removeSync(this._schemaExportDirectory);
|
|
89
53
|
}
|
|
90
54
|
catch (error) {
|
|
91
55
|
cleanupFailure = error;
|
|
@@ -126,7 +90,7 @@ class SchemaProcessingCoordinator {
|
|
|
126
90
|
const schemaLocaters = await import("@itwin/ecschema-locaters");
|
|
127
91
|
const schemaFileName = this.getSchemaExportFileName(result.schema.name);
|
|
128
92
|
const schemaXml = await schemaLocaters.SchemaXml.writeString(result.schema);
|
|
129
|
-
|
|
93
|
+
IModelJsFs.writeFileSync(path.join(this._schemaExportDirectory, schemaFileName), schemaXml);
|
|
130
94
|
}
|
|
131
95
|
getSchemaExportFileName(schemaName) {
|
|
132
96
|
const extension = ".ecschema.xml";
|
|
@@ -142,7 +106,7 @@ class SchemaProcessingCoordinator {
|
|
|
142
106
|
return schemaFileName;
|
|
143
107
|
}
|
|
144
108
|
createLongNameResolvingSchemaContext() {
|
|
145
|
-
const context = new
|
|
109
|
+
const context = new ECSchemaXmlContext();
|
|
146
110
|
context.setSchemaLocater((key) => {
|
|
147
111
|
const schemaFileName = this._longNamedSchemas.get(key.name);
|
|
148
112
|
return schemaFileName === undefined
|
|
@@ -152,7 +116,6 @@ class SchemaProcessingCoordinator {
|
|
|
152
116
|
return context;
|
|
153
117
|
}
|
|
154
118
|
}
|
|
155
|
-
exports.SchemaProcessingCoordinator = SchemaProcessingCoordinator;
|
|
156
119
|
function orderSchemasByDependencies(schemas) {
|
|
157
120
|
const schemasByName = new Map(schemas.map((schema) => [schema.name.toLowerCase(), schema]));
|
|
158
121
|
const state = new Map();
|
|
@@ -166,14 +129,14 @@ function orderSchemasByDependencies(schemas) {
|
|
|
166
129
|
if (currentState === "visiting") {
|
|
167
130
|
const cycleStart = stack.indexOf(schemaName);
|
|
168
131
|
const schemaNames = stack.slice(cycleStart);
|
|
169
|
-
throw
|
|
132
|
+
throw ITwinError.create({
|
|
170
133
|
message: `Schema dependency cycle detected: ${[
|
|
171
134
|
...schemaNames,
|
|
172
135
|
schemaName,
|
|
173
136
|
].join(" -> ")}`,
|
|
174
137
|
iTwinErrorId: {
|
|
175
|
-
scope:
|
|
176
|
-
key:
|
|
138
|
+
scope: IModelTransformerErrorScope,
|
|
139
|
+
key: IModelTransformerError.SchemaDependencyCycle,
|
|
177
140
|
},
|
|
178
141
|
schemaNames,
|
|
179
142
|
});
|