@itwin/imodel-transformer 2.0.0-dev.5 → 2.0.0-dev.51
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.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 +34 -36
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/ChangesetScanner.d.ts +60 -0
- package/lib/cjs/ChangesetScanner.d.ts.map +1 -0
- package/lib/cjs/ChangesetScanner.js +101 -0
- package/lib/cjs/ChangesetScanner.js.map +1 -0
- package/lib/cjs/ECReferenceTypesCache.d.ts +0 -3
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +61 -103
- 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 +82 -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 +43 -0
- package/lib/cjs/ElementAspectExportProcessor.d.ts.map +1 -0
- package/lib/cjs/ElementAspectExportProcessor.js +167 -0
- package/lib/cjs/ElementAspectExportProcessor.js.map +1 -0
- package/lib/cjs/ElementBulkDelete.d.ts +11 -0
- package/lib/cjs/ElementBulkDelete.d.ts.map +1 -0
- package/lib/cjs/ElementBulkDelete.js +55 -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/EntityMap.d.ts.map +1 -1
- package/lib/cjs/EntityMap.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts +8 -8
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +55 -32
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +11 -5
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +94 -58
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts +109 -35
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +698 -224
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.d.ts +73 -32
- package/lib/cjs/IModelImporter.d.ts.map +1 -1
- package/lib/cjs/IModelImporter.js +278 -144
- 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 +126 -206
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +652 -1198
- 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 +182 -0
- package/lib/cjs/ProvenanceManager.d.ts.map +1 -0
- package/lib/cjs/ProvenanceManager.js +743 -0
- package/lib/cjs/ProvenanceManager.js.map +1 -0
- package/lib/cjs/SyncTypeResolver.d.ts +34 -0
- package/lib/cjs/SyncTypeResolver.d.ts.map +1 -0
- package/lib/cjs/SyncTypeResolver.js +98 -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 +19 -0
- package/lib/cjs/imodel-transformer.d.ts.map +1 -1
- package/lib/cjs/imodel-transformer.js +53 -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 +65 -43
- 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/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,29 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module iModels
|
|
3
|
+
*/
|
|
4
|
+
import { SchemaDifferenceResult } from "@itwin/ecschema-editing";
|
|
5
|
+
import { Schema } from "@itwin/ecschema-metadata";
|
|
6
|
+
import { SchemaProcessingContext, SchemaProcessingResult, SchemaProcessingStrategy } from "./SchemaProcessingStrategy";
|
|
7
|
+
/**
|
|
8
|
+
* Processes ordinary schemas with newer-version selection and unions compatible
|
|
9
|
+
* differences for existing dynamic schemas. Dynamic schema root read and write
|
|
10
|
+
* versions must match; only the minor version may differ.
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export declare class DynamicSchemaUnionStrategy implements SchemaProcessingStrategy {
|
|
14
|
+
/**
|
|
15
|
+
* Transform schema differences before conflict validation and merging.
|
|
16
|
+
* A subclass that changes the differencing result is responsible for ensuring
|
|
17
|
+
* that its changes are safe for the source and target schemas.
|
|
18
|
+
* @param sourceSchema The source schema being processed.
|
|
19
|
+
* @param targetSchema The existing target schema.
|
|
20
|
+
* @param differences The complete result from [[getSchemaDifferences]].
|
|
21
|
+
* @returns The differencing result to validate and merge.
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
protected onSchemaDifferences(_sourceSchema: Schema, _targetSchema: Schema, differences: SchemaDifferenceResult): Promise<SchemaDifferenceResult>;
|
|
25
|
+
/** Select ordinary schemas and union compatible dynamic schema differences. */
|
|
26
|
+
processSchemas(context: SchemaProcessingContext): Promise<SchemaProcessingResult[]>;
|
|
27
|
+
private createPlan;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=DynamicSchemaUnionStrategy.d.ts.map
|
|
@@ -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,4BAA4B,CAAC;AAsBpC;;;;;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"}
|
|
@@ -0,0 +1,212 @@
|
|
|
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.DynamicSchemaUnionStrategy = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const ecschema_editing_1 = require("@itwin/ecschema-editing");
|
|
13
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
14
|
+
const IModelTransformerError_1 = require("../IModelTransformerError");
|
|
15
|
+
/**
|
|
16
|
+
* Processes ordinary schemas with newer-version selection and unions compatible
|
|
17
|
+
* differences for existing dynamic schemas. Dynamic schema root read and write
|
|
18
|
+
* versions must match; only the minor version may differ.
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
class DynamicSchemaUnionStrategy {
|
|
22
|
+
/**
|
|
23
|
+
* Transform schema differences before conflict validation and merging.
|
|
24
|
+
* A subclass that changes the differencing result is responsible for ensuring
|
|
25
|
+
* that its changes are safe for the source and target schemas.
|
|
26
|
+
* @param sourceSchema The source schema being processed.
|
|
27
|
+
* @param targetSchema The existing target schema.
|
|
28
|
+
* @param differences The complete result from [[getSchemaDifferences]].
|
|
29
|
+
* @returns The differencing result to validate and merge.
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
async onSchemaDifferences(_sourceSchema, _targetSchema, differences) {
|
|
33
|
+
return differences;
|
|
34
|
+
}
|
|
35
|
+
/** Select ordinary schemas and union compatible dynamic schema differences. */
|
|
36
|
+
async processSchemas(context) {
|
|
37
|
+
const plans = [];
|
|
38
|
+
const conflicts = [];
|
|
39
|
+
for (const sourceSchema of context.sourceSchemas) {
|
|
40
|
+
try {
|
|
41
|
+
plans.push(await this.createPlan(sourceSchema, context.targetSchemas));
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (core_bentley_1.ITwinError.isError(error, IModelTransformerError_1.IModelTransformerErrorScope, IModelTransformerError_1.IModelTransformerError.SchemaConflict)) {
|
|
45
|
+
conflicts.push(error);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throwSchemaConflicts(conflicts);
|
|
52
|
+
const schemaEditingContext = new ecschema_metadata_1.SchemaContext();
|
|
53
|
+
const schemaCandidates = new Map();
|
|
54
|
+
for (const plan of plans) {
|
|
55
|
+
if (plan.kind === "dynamic-merge") {
|
|
56
|
+
collectSchemaCandidates(plan.target, schemaCandidates, true);
|
|
57
|
+
collectSchemaReferences(plan.source, schemaCandidates);
|
|
58
|
+
}
|
|
59
|
+
else if (plan.kind === "dynamic-noop") {
|
|
60
|
+
collectSchemaCandidates(plan.source, schemaCandidates, false);
|
|
61
|
+
collectSchemaReferences(plan.source, schemaCandidates);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const { schema } of schemaCandidates.values()) {
|
|
65
|
+
await schemaEditingContext.addSchema(schema);
|
|
66
|
+
}
|
|
67
|
+
const schemaMerger = new ecschema_editing_1.SchemaMerger(schemaEditingContext);
|
|
68
|
+
const results = [];
|
|
69
|
+
for (const plan of plans) {
|
|
70
|
+
switch (plan.kind) {
|
|
71
|
+
case "new":
|
|
72
|
+
if (plan.source.isDynamic ||
|
|
73
|
+
(await context.shouldExportSchema(plan.source.schemaKey))) {
|
|
74
|
+
results.push({ kind: "source", schema: plan.source });
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case "ordinary":
|
|
78
|
+
if (await context.shouldExportSchema(plan.source.schemaKey)) {
|
|
79
|
+
results.push({ kind: "source", schema: plan.source });
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case "dynamic-noop":
|
|
83
|
+
break;
|
|
84
|
+
case "dynamic-merge": {
|
|
85
|
+
const mergedSchema = await schemaMerger.merge({
|
|
86
|
+
...plan.differences,
|
|
87
|
+
conflicts: undefined,
|
|
88
|
+
});
|
|
89
|
+
const sourceVersion = plan.source.schemaKey.version;
|
|
90
|
+
mergedSchema.setVersion(sourceVersion.read, sourceVersion.write, incrementMinorVersion(sourceVersion, plan.target.schemaKey.version));
|
|
91
|
+
results.push({ kind: "generated", schema: mergedSchema });
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
appendRequiredNoOpSchemas(results, plans);
|
|
97
|
+
return results;
|
|
98
|
+
}
|
|
99
|
+
async createPlan(source, targetSchemas) {
|
|
100
|
+
const target = await targetSchemas.getSchema(source.name);
|
|
101
|
+
if (target === undefined)
|
|
102
|
+
return { kind: "new", source };
|
|
103
|
+
if (source.isDynamic !== target.isDynamic) {
|
|
104
|
+
throw createSchemaConflictError(source, "Schema DynamicSchema marker changed", new Error("The source and target DynamicSchema markers differ."));
|
|
105
|
+
}
|
|
106
|
+
if (!source.isDynamic)
|
|
107
|
+
return { kind: "ordinary", source, target };
|
|
108
|
+
const sourceVersion = source.schemaKey.version;
|
|
109
|
+
const targetVersion = target.schemaKey.version;
|
|
110
|
+
if (sourceVersion.read !== targetVersion.read ||
|
|
111
|
+
sourceVersion.write !== targetVersion.write) {
|
|
112
|
+
throw createSchemaConflictError(source, "Dynamic schema has incompatible root versions", new Error(`source ${sourceVersion.toString(false)}, target ${targetVersion.toString(false)}`));
|
|
113
|
+
}
|
|
114
|
+
const differences = await this.onSchemaDifferences(source, target, await (0, ecschema_editing_1.getSchemaDifferences)(target, source));
|
|
115
|
+
const unresolvedConflicts = (differences.conflicts ?? []).filter((conflict) => !isCompatibleReferenceVersionConflict(conflict));
|
|
116
|
+
if (unresolvedConflicts.length > 0) {
|
|
117
|
+
throw createSchemaConflictError(source, "Schema conflict", new ecschema_editing_1.SchemaConflictsError(`Schema '${source.name}' has unresolved conflicts`, unresolvedConflicts, source.schemaKey, target.schemaKey));
|
|
118
|
+
}
|
|
119
|
+
return differences.differences.length === 0
|
|
120
|
+
? { kind: "dynamic-noop", source, target }
|
|
121
|
+
: { kind: "dynamic-merge", source, target, differences };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.DynamicSchemaUnionStrategy = DynamicSchemaUnionStrategy;
|
|
125
|
+
function createSchemaConflictError(schema, operation, cause) {
|
|
126
|
+
return core_bentley_1.ITwinError.create({
|
|
127
|
+
message: `${operation} for '${schema.schemaKey.toString(false)}': ${cause.message}`,
|
|
128
|
+
iTwinErrorId: {
|
|
129
|
+
scope: IModelTransformerError_1.IModelTransformerErrorScope,
|
|
130
|
+
key: IModelTransformerError_1.IModelTransformerError.SchemaConflict,
|
|
131
|
+
},
|
|
132
|
+
cause,
|
|
133
|
+
schemaKey: schema.schemaKey.toString(false),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function throwSchemaConflicts(conflicts) {
|
|
137
|
+
if (conflicts.length === 1)
|
|
138
|
+
throw conflicts[0];
|
|
139
|
+
if (conflicts.length > 1)
|
|
140
|
+
throw new AggregateError(conflicts, "Schema processing failed");
|
|
141
|
+
}
|
|
142
|
+
function appendRequiredNoOpSchemas(results, plans) {
|
|
143
|
+
const noOpSchemas = new Map(plans
|
|
144
|
+
.filter((plan) => plan.kind === "dynamic-noop")
|
|
145
|
+
.map((plan) => [plan.source.name.toLowerCase(), plan.source]));
|
|
146
|
+
const requiredNoOpSchemas = new Set();
|
|
147
|
+
const schemasToVisit = results.map((result) => result.schema);
|
|
148
|
+
for (const schema of schemasToVisit) {
|
|
149
|
+
for (const reference of schema.references) {
|
|
150
|
+
const schemaName = reference.name.toLowerCase();
|
|
151
|
+
const noOpSchema = noOpSchemas.get(schemaName);
|
|
152
|
+
if (noOpSchema === undefined || requiredNoOpSchemas.has(schemaName))
|
|
153
|
+
continue;
|
|
154
|
+
requiredNoOpSchemas.add(schemaName);
|
|
155
|
+
schemasToVisit.push(noOpSchema);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (const schemaName of requiredNoOpSchemas) {
|
|
159
|
+
const schema = noOpSchemas.get(schemaName);
|
|
160
|
+
if (schema !== undefined)
|
|
161
|
+
results.push({ kind: "source", schema });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function incrementMinorVersion(sourceVersion, targetVersion) {
|
|
165
|
+
const maximumVersion = sourceVersion.compare(targetVersion) >= 0 ? sourceVersion : targetVersion;
|
|
166
|
+
if (maximumVersion.minor >= 9_999_999) {
|
|
167
|
+
throw new Error(`Cannot increment schema version ${maximumVersion.toString(false)}`);
|
|
168
|
+
}
|
|
169
|
+
return maximumVersion.minor + 1;
|
|
170
|
+
}
|
|
171
|
+
function isCompatibleReferenceVersionConflict(conflict) {
|
|
172
|
+
if (conflict.code !== ecschema_editing_1.ConflictCode.ConflictingReferenceVersion)
|
|
173
|
+
return false;
|
|
174
|
+
if (typeof conflict.source !== "string" ||
|
|
175
|
+
typeof conflict.target !== "string")
|
|
176
|
+
return false;
|
|
177
|
+
const sourceVersion = ecschema_metadata_1.SchemaKey.parseString(conflict.source).version;
|
|
178
|
+
const targetVersion = ecschema_metadata_1.SchemaKey.parseString(conflict.target).version;
|
|
179
|
+
return (sourceVersion.read === targetVersion.read &&
|
|
180
|
+
sourceVersion.write === targetVersion.write);
|
|
181
|
+
}
|
|
182
|
+
function collectSchemaCandidates(schema, candidates, isTargetRoot, visited = new Set()) {
|
|
183
|
+
const traversalKey = schema.schemaKey.toString();
|
|
184
|
+
if (visited.has(traversalKey))
|
|
185
|
+
return;
|
|
186
|
+
visited.add(traversalKey);
|
|
187
|
+
const schemaName = schema.name.toLowerCase();
|
|
188
|
+
const existing = candidates.get(schemaName);
|
|
189
|
+
if (existing === undefined) {
|
|
190
|
+
candidates.set(schemaName, { schema, isTargetRoot });
|
|
191
|
+
}
|
|
192
|
+
else if (existing.schema.schemaKey.version.read !== schema.schemaKey.version.read ||
|
|
193
|
+
existing.schema.schemaKey.version.write !== schema.schemaKey.version.write) {
|
|
194
|
+
throw createSchemaConflictError(schema, "Schema reference has incompatible read/write versions", new Error(`${existing.schema.schemaKey.version.read}.${existing.schema.schemaKey.version.write} ` +
|
|
195
|
+
`and ${schema.schemaKey.version.read}.${schema.schemaKey.version.write} differ. ` +
|
|
196
|
+
"Only minor-version reference differences are supported."));
|
|
197
|
+
}
|
|
198
|
+
else if (isTargetRoot ||
|
|
199
|
+
(!existing.isTargetRoot &&
|
|
200
|
+
schema.schemaKey.version.compare(existing.schema.schemaKey.version) > 0)) {
|
|
201
|
+
candidates.set(schemaName, { schema, isTargetRoot });
|
|
202
|
+
}
|
|
203
|
+
for (const reference of schema.references) {
|
|
204
|
+
collectSchemaCandidates(reference, candidates, false, visited);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function collectSchemaReferences(schema, candidates) {
|
|
208
|
+
for (const reference of schema.references) {
|
|
209
|
+
collectSchemaCandidates(reference, candidates, false);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=DynamicSchemaUnionStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicSchemaUnionStrategy.js","sourceRoot":"","sources":["../../../src/schema-processing/DynamicSchemaUnionStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAAiD;AACjD,8DAOiC;AACjC,gEAKkC;AAClC,sEAGmC;AA4BnC;;;;;GAKG;AACH;IACE;;;;;;;;;OASG;IACO,KAAK,CAAC,mBAAmB,CACjC,aAAqB,EACrB,aAAqB,EACrB,WAAmC;QAE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E,CAAC;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\";\nimport {\n ReadonlySchemaAccessor,\n SchemaProcessingContext,\n SchemaProcessingResult,\n SchemaProcessingStrategy,\n} from \"./SchemaProcessingStrategy\";\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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
2
|
+
import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
|
|
3
|
+
import { ExportSchemaResult, IModelExporter } from "../IModelExporter";
|
|
4
|
+
import { SchemaProcessingStrategy } from "./SchemaProcessingStrategy";
|
|
5
|
+
interface SchemaProcessingCoordinatorArgs {
|
|
6
|
+
exporter: IModelExporter;
|
|
7
|
+
targetDb: IModelDb;
|
|
8
|
+
getSchemaExportDirectory: () => string;
|
|
9
|
+
shouldExportSchema: (schemaKey: SchemaKey) => Promise<boolean>;
|
|
10
|
+
serializeSourceSchema: (schema: Schema) => Promise<void | ExportSchemaResult>;
|
|
11
|
+
}
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare class SchemaProcessingCoordinator {
|
|
14
|
+
private readonly _args;
|
|
15
|
+
private readonly _longNamedSchemas;
|
|
16
|
+
constructor(_args: SchemaProcessingCoordinatorArgs);
|
|
17
|
+
process(strategy: SchemaProcessingStrategy): Promise<void>;
|
|
18
|
+
serializeSourceSchema(schema: Schema): Promise<ExportSchemaResult>;
|
|
19
|
+
private get _schemaExportDirectory();
|
|
20
|
+
private serializeSchema;
|
|
21
|
+
private getSchemaExportFileName;
|
|
22
|
+
private createLongNameResolvingSchemaContext;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=SchemaProcessingCoordinator.d.ts.map
|
|
@@ -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,mBAAmB,CAAC;AAKvE,OAAO,EAGL,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,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"}
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
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");
|
|
46
|
+
/** @internal */
|
|
47
|
+
class SchemaProcessingCoordinator {
|
|
48
|
+
_args;
|
|
49
|
+
_longNamedSchemas = new Map();
|
|
50
|
+
constructor(_args) {
|
|
51
|
+
this._args = _args;
|
|
52
|
+
}
|
|
53
|
+
async process(strategy) {
|
|
54
|
+
let processingFailure;
|
|
55
|
+
try {
|
|
56
|
+
core_backend_1.IModelJsFs.mkdirSync(this._schemaExportDirectory);
|
|
57
|
+
this._longNamedSchemas.clear();
|
|
58
|
+
const sourceSchemas = [];
|
|
59
|
+
for await (const schema of this._args.exporter.enumerateSchemas()) {
|
|
60
|
+
sourceSchemas.push(schema);
|
|
61
|
+
}
|
|
62
|
+
const targetSchemaLoader = new ecschema_metadata_1.SchemaLoader((name) => this._args.targetDb.getSchemaProps(name));
|
|
63
|
+
const targetSchemas = {
|
|
64
|
+
getSchema: async (schemaName) => targetSchemaLoader.tryGetSchema(schemaName),
|
|
65
|
+
};
|
|
66
|
+
const processedSchemas = await strategy.processSchemas({
|
|
67
|
+
sourceSchemas: orderSchemasByDependencies(sourceSchemas),
|
|
68
|
+
targetSchemas,
|
|
69
|
+
shouldExportSchema: this._args.shouldExportSchema,
|
|
70
|
+
});
|
|
71
|
+
for (const result of processedSchemas) {
|
|
72
|
+
await this.serializeSchema(result);
|
|
73
|
+
}
|
|
74
|
+
const exportedSchemaFiles = core_backend_1.IModelJsFs.readdirSync(this._schemaExportDirectory);
|
|
75
|
+
if (exportedSchemaFiles.length > 0) {
|
|
76
|
+
await this._args.targetDb.importSchemas(exportedSchemaFiles.map((fileName) => path.join(this._schemaExportDirectory, fileName)), {
|
|
77
|
+
ecSchemaXmlContext: this._longNamedSchemas.size > 0
|
|
78
|
+
? this.createLongNameResolvingSchemaContext()
|
|
79
|
+
: undefined,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
processingFailure = error;
|
|
85
|
+
}
|
|
86
|
+
let cleanupFailure;
|
|
87
|
+
try {
|
|
88
|
+
core_backend_1.IModelJsFs.removeSync(this._schemaExportDirectory);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
cleanupFailure = error;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
this._longNamedSchemas.clear();
|
|
95
|
+
}
|
|
96
|
+
if (processingFailure !== undefined && cleanupFailure !== undefined) {
|
|
97
|
+
throw new AggregateError([processingFailure, cleanupFailure], "Schema processing and cleanup failed", { cause: processingFailure });
|
|
98
|
+
}
|
|
99
|
+
// Preserve failures from custom strategies and upstream libraries exactly.
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
101
|
+
if (processingFailure !== undefined)
|
|
102
|
+
throw processingFailure;
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
104
|
+
if (cleanupFailure !== undefined)
|
|
105
|
+
throw cleanupFailure;
|
|
106
|
+
}
|
|
107
|
+
async serializeSourceSchema(schema) {
|
|
108
|
+
const schemaFileName = this.getSchemaExportFileName(schema.name);
|
|
109
|
+
this._args.exporter.sourceDb.exportSchema({
|
|
110
|
+
schemaName: schema.name,
|
|
111
|
+
outputDirectory: this._schemaExportDirectory,
|
|
112
|
+
outputFileName: schemaFileName,
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
schemaPath: path.join(this._schemaExportDirectory, schemaFileName),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
get _schemaExportDirectory() {
|
|
119
|
+
return this._args.getSchemaExportDirectory();
|
|
120
|
+
}
|
|
121
|
+
async serializeSchema(result) {
|
|
122
|
+
if (result.kind === "source") {
|
|
123
|
+
await this._args.serializeSourceSchema(result.schema);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const schemaLocaters = await import("@itwin/ecschema-locaters");
|
|
127
|
+
const schemaFileName = this.getSchemaExportFileName(result.schema.name);
|
|
128
|
+
const schemaXml = await schemaLocaters.SchemaXml.writeString(result.schema);
|
|
129
|
+
core_backend_1.IModelJsFs.writeFileSync(path.join(this._schemaExportDirectory, schemaFileName), schemaXml);
|
|
130
|
+
}
|
|
131
|
+
getSchemaExportFileName(schemaName) {
|
|
132
|
+
const extension = ".ecschema.xml";
|
|
133
|
+
let schemaFileName = schemaName + extension;
|
|
134
|
+
const systemMaxPathSegmentSize = 255;
|
|
135
|
+
const windowsMaxPathLimit = 260;
|
|
136
|
+
if (schemaFileName.length > systemMaxPathSegmentSize ||
|
|
137
|
+
path.join(this._schemaExportDirectory, schemaFileName).length >=
|
|
138
|
+
windowsMaxPathLimit) {
|
|
139
|
+
schemaFileName = `${schemaName.slice(0, 100)}${this._longNamedSchemas.size}${extension}`;
|
|
140
|
+
this._longNamedSchemas.set(schemaName, schemaFileName);
|
|
141
|
+
}
|
|
142
|
+
return schemaFileName;
|
|
143
|
+
}
|
|
144
|
+
createLongNameResolvingSchemaContext() {
|
|
145
|
+
const context = new core_backend_1.ECSchemaXmlContext();
|
|
146
|
+
context.setSchemaLocater((key) => {
|
|
147
|
+
const schemaFileName = this._longNamedSchemas.get(key.name);
|
|
148
|
+
return schemaFileName === undefined
|
|
149
|
+
? undefined
|
|
150
|
+
: path.join(this._schemaExportDirectory, schemaFileName);
|
|
151
|
+
});
|
|
152
|
+
return context;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.SchemaProcessingCoordinator = SchemaProcessingCoordinator;
|
|
156
|
+
function orderSchemasByDependencies(schemas) {
|
|
157
|
+
const schemasByName = new Map(schemas.map((schema) => [schema.name.toLowerCase(), schema]));
|
|
158
|
+
const state = new Map();
|
|
159
|
+
const orderedSchemas = [];
|
|
160
|
+
const stack = [];
|
|
161
|
+
const visit = (schema) => {
|
|
162
|
+
const schemaName = schema.name.toLowerCase();
|
|
163
|
+
const currentState = state.get(schemaName);
|
|
164
|
+
if (currentState === "visited")
|
|
165
|
+
return;
|
|
166
|
+
if (currentState === "visiting") {
|
|
167
|
+
const cycleStart = stack.indexOf(schemaName);
|
|
168
|
+
const schemaNames = stack.slice(cycleStart);
|
|
169
|
+
throw core_bentley_1.ITwinError.create({
|
|
170
|
+
message: `Schema dependency cycle detected: ${[
|
|
171
|
+
...schemaNames,
|
|
172
|
+
schemaName,
|
|
173
|
+
].join(" -> ")}`,
|
|
174
|
+
iTwinErrorId: {
|
|
175
|
+
scope: IModelTransformerError_1.IModelTransformerErrorScope,
|
|
176
|
+
key: IModelTransformerError_1.IModelTransformerError.SchemaDependencyCycle,
|
|
177
|
+
},
|
|
178
|
+
schemaNames,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
state.set(schemaName, "visiting");
|
|
182
|
+
stack.push(schemaName);
|
|
183
|
+
for (const reference of schema.references) {
|
|
184
|
+
const referencedSchema = schemasByName.get(reference.name.toLowerCase());
|
|
185
|
+
if (referencedSchema !== undefined)
|
|
186
|
+
visit(referencedSchema);
|
|
187
|
+
}
|
|
188
|
+
stack.pop();
|
|
189
|
+
state.set(schemaName, "visited");
|
|
190
|
+
orderedSchemas.push(schema);
|
|
191
|
+
};
|
|
192
|
+
for (const schema of schemas)
|
|
193
|
+
visit(schema);
|
|
194
|
+
return orderedSchemas;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=SchemaProcessingCoordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaProcessingCoordinator.js","sourceRoot":"","sources":["../../../src/schema-processing/SchemaProcessingCoordinator.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhG,MAAY,IAAI,sCAAkB;AAClC,sDAAiD;AACjD,sDAA+E;AAC/E,gEAA2E;AAE3E,sEAGmC;AAenC,gBAAgB;AAChB;IAGsC,KAAK;IAFxB,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE/D,YAAoC,KAAsC;qBAAtC,KAAK;IAAoC,CAAC;IAEvE,KAAK,CAAC,OAAO,CAAC,QAAkC;QACrD,IAAI,iBAA0B,CAAC;QAC/B,IAAI,CAAC;YACH,yBAAU,CAAC,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YAClD,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;YAE/B,MAAM,aAAa,GAAa,EAAE,CAAC;YACnC,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAE,CAAC;gBAClE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AE,+CAAsB,CAAC,qBAAqB;iBAClD;gBACD,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvB,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YAC1C,MAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YACzE,IAAI,gBAAgB,KAAK,SAAS;gBAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC9D,CAAC;QACD,KAAK,CAAC,GAAG,EAAE,CAAC;QACZ,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACjC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,cAAc,CAAC;AACxB,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 * as path from \"node:path\";\nimport { ITwinError } from \"@itwin/core-bentley\";\nimport { ECSchemaXmlContext, IModelDb, IModelJsFs } from \"@itwin/core-backend\";\nimport { Schema, SchemaKey, SchemaLoader } from \"@itwin/ecschema-metadata\";\nimport { ExportSchemaResult, IModelExporter } from \"../IModelExporter\";\nimport {\n IModelTransformerError,\n IModelTransformerErrorScope,\n} from \"../IModelTransformerError\";\nimport {\n ReadonlySchemaAccessor,\n SchemaProcessingResult,\n SchemaProcessingStrategy,\n} from \"./SchemaProcessingStrategy\";\n\ninterface SchemaProcessingCoordinatorArgs {\n exporter: IModelExporter;\n targetDb: IModelDb;\n getSchemaExportDirectory: () => string;\n shouldExportSchema: (schemaKey: SchemaKey) => Promise<boolean>;\n serializeSourceSchema: (schema: Schema) => Promise<void | ExportSchemaResult>;\n}\n\n/** @internal */\nexport class SchemaProcessingCoordinator {\n private readonly _longNamedSchemas = new Map<string, string>();\n\n public constructor(private readonly _args: SchemaProcessingCoordinatorArgs) {}\n\n public async process(strategy: SchemaProcessingStrategy): Promise<void> {\n let processingFailure: unknown;\n try {\n IModelJsFs.mkdirSync(this._schemaExportDirectory);\n this._longNamedSchemas.clear();\n\n const sourceSchemas: Schema[] = [];\n for await (const schema of this._args.exporter.enumerateSchemas()) {\n sourceSchemas.push(schema);\n }\n const targetSchemaLoader = new SchemaLoader((name) =>\n this._args.targetDb.getSchemaProps(name)\n );\n const targetSchemas: ReadonlySchemaAccessor = {\n getSchema: async (schemaName) =>\n targetSchemaLoader.tryGetSchema(schemaName),\n };\n const processedSchemas = await strategy.processSchemas({\n sourceSchemas: orderSchemasByDependencies(sourceSchemas),\n targetSchemas,\n shouldExportSchema: this._args.shouldExportSchema,\n });\n\n for (const result of processedSchemas) {\n await this.serializeSchema(result);\n }\n const exportedSchemaFiles = IModelJsFs.readdirSync(\n this._schemaExportDirectory\n );\n if (exportedSchemaFiles.length > 0) {\n await this._args.targetDb.importSchemas(\n exportedSchemaFiles.map((fileName) =>\n path.join(this._schemaExportDirectory, fileName)\n ),\n {\n ecSchemaXmlContext:\n this._longNamedSchemas.size > 0\n ? this.createLongNameResolvingSchemaContext()\n : undefined,\n }\n );\n }\n } catch (error: unknown) {\n processingFailure = error;\n }\n\n let cleanupFailure: unknown;\n try {\n IModelJsFs.removeSync(this._schemaExportDirectory);\n } catch (error: unknown) {\n cleanupFailure = error;\n } finally {\n this._longNamedSchemas.clear();\n }\n\n if (processingFailure !== undefined && cleanupFailure !== undefined) {\n throw new AggregateError(\n [processingFailure, cleanupFailure],\n \"Schema processing and cleanup failed\",\n { cause: processingFailure }\n );\n }\n // Preserve failures from custom strategies and upstream libraries exactly.\n // eslint-disable-next-line @typescript-eslint/only-throw-error\n if (processingFailure !== undefined) throw processingFailure;\n // eslint-disable-next-line @typescript-eslint/only-throw-error\n if (cleanupFailure !== undefined) throw cleanupFailure;\n }\n\n public async serializeSourceSchema(\n schema: Schema\n ): Promise<ExportSchemaResult> {\n const schemaFileName = this.getSchemaExportFileName(schema.name);\n this._args.exporter.sourceDb.exportSchema({\n schemaName: schema.name,\n outputDirectory: this._schemaExportDirectory,\n outputFileName: schemaFileName,\n });\n return {\n schemaPath: path.join(this._schemaExportDirectory, schemaFileName),\n };\n }\n\n private get _schemaExportDirectory(): string {\n return this._args.getSchemaExportDirectory();\n }\n\n private async serializeSchema(result: SchemaProcessingResult): Promise<void> {\n if (result.kind === \"source\") {\n await this._args.serializeSourceSchema(result.schema);\n return;\n }\n\n const schemaLocaters = await import(\"@itwin/ecschema-locaters\");\n const schemaFileName = this.getSchemaExportFileName(result.schema.name);\n const schemaXml = await schemaLocaters.SchemaXml.writeString(result.schema);\n IModelJsFs.writeFileSync(\n path.join(this._schemaExportDirectory, schemaFileName),\n schemaXml\n );\n }\n\n private getSchemaExportFileName(schemaName: string): string {\n const extension = \".ecschema.xml\";\n let schemaFileName = schemaName + extension;\n const systemMaxPathSegmentSize = 255;\n const windowsMaxPathLimit = 260;\n if (\n schemaFileName.length > systemMaxPathSegmentSize ||\n path.join(this._schemaExportDirectory, schemaFileName).length >=\n windowsMaxPathLimit\n ) {\n schemaFileName = `${schemaName.slice(0, 100)}${\n this._longNamedSchemas.size\n }${extension}`;\n this._longNamedSchemas.set(schemaName, schemaFileName);\n }\n return schemaFileName;\n }\n\n private createLongNameResolvingSchemaContext(): ECSchemaXmlContext {\n const context = new ECSchemaXmlContext();\n context.setSchemaLocater((key) => {\n const schemaFileName = this._longNamedSchemas.get(key.name);\n return schemaFileName === undefined\n ? undefined\n : path.join(this._schemaExportDirectory, schemaFileName);\n });\n return context;\n }\n}\n\ninterface SchemaDependencyCycleError extends ITwinError {\n schemaNames: readonly string[];\n}\n\nfunction orderSchemasByDependencies(schemas: Schema[]): Schema[] {\n const schemasByName = new Map(\n schemas.map((schema) => [schema.name.toLowerCase(), schema])\n );\n const state = new Map<string, \"visiting\" | \"visited\">();\n const orderedSchemas: Schema[] = [];\n const stack: string[] = [];\n\n const visit = (schema: Schema): void => {\n const schemaName = schema.name.toLowerCase();\n const currentState = state.get(schemaName);\n if (currentState === \"visited\") return;\n if (currentState === \"visiting\") {\n const cycleStart = stack.indexOf(schemaName);\n const schemaNames = stack.slice(cycleStart);\n throw ITwinError.create<SchemaDependencyCycleError>({\n message: `Schema dependency cycle detected: ${[\n ...schemaNames,\n schemaName,\n ].join(\" -> \")}`,\n iTwinErrorId: {\n scope: IModelTransformerErrorScope,\n key: IModelTransformerError.SchemaDependencyCycle,\n },\n schemaNames,\n });\n }\n\n state.set(schemaName, \"visiting\");\n stack.push(schemaName);\n for (const reference of schema.references) {\n const referencedSchema = schemasByName.get(reference.name.toLowerCase());\n if (referencedSchema !== undefined) visit(referencedSchema);\n }\n stack.pop();\n state.set(schemaName, \"visited\");\n orderedSchemas.push(schema);\n };\n\n for (const schema of schemas) visit(schema);\n return orderedSchemas;\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module iModels
|
|
3
|
+
*/
|
|
4
|
+
import { Schema, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
+
/**
|
|
6
|
+
* The result of processing one schema.
|
|
7
|
+
* @beta
|
|
8
|
+
*/
|
|
9
|
+
export type SchemaProcessingResult = {
|
|
10
|
+
kind: "source";
|
|
11
|
+
schema: Schema;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "generated";
|
|
14
|
+
schema: Schema;
|
|
15
|
+
};
|
|
16
|
+
/** Read-only access to schemas already present in the target iModel.
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
export interface ReadonlySchemaAccessor {
|
|
20
|
+
/** Load a target schema by name, or return `undefined` when it is absent. */
|
|
21
|
+
getSchema(schemaName: string): Promise<Schema | undefined>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Context supplied to a [[SchemaProcessingStrategy]].
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export interface SchemaProcessingContext {
|
|
28
|
+
/** Source schemas in dependency order. */
|
|
29
|
+
readonly sourceSchemas: readonly Schema[];
|
|
30
|
+
/** Read-only access to schemas already present in the target. */
|
|
31
|
+
readonly targetSchemas: ReadonlySchemaAccessor;
|
|
32
|
+
/** The schema-selection hook used by the default transformer path. */
|
|
33
|
+
readonly shouldExportSchema: (schemaKey: SchemaKey) => Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Selects source schemas and produces definitions for import into a target iModel.
|
|
37
|
+
* @beta
|
|
38
|
+
*/
|
|
39
|
+
export interface SchemaProcessingStrategy {
|
|
40
|
+
/** Select source schemas and produce definitions for import into the target iModel. */
|
|
41
|
+
processSchemas(context: SchemaProcessingContext): Promise<SchemaProcessingResult[]>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for [[IModelTransformer.processSchemas]].
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export interface ProcessSchemasOptions {
|
|
48
|
+
/** Strategy used to select and process source schemas. */
|
|
49
|
+
strategy?: SchemaProcessingStrategy;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Selects source schemas that are absent from the target or have a newer version.
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
export declare class NewerVersionSchemaImportStrategy implements SchemaProcessingStrategy {
|
|
56
|
+
/** Select schemas that are absent from the target or have a newer version. */
|
|
57
|
+
processSchemas(context: SchemaProcessingContext): Promise<SchemaProcessingResult[]>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=SchemaProcessingStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaProcessingStrategy.d.ts","sourceRoot":"","sources":["../../../src/schema-processing/SchemaProcessingStrategy.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC5D;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,0CAA0C;IAC1C,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,iEAAiE;IACjE,QAAQ,CAAC,aAAa,EAAE,sBAAsB,CAAC;IAC/C,sEAAsE;IACtE,QAAQ,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACzE;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,uFAAuF;IACvF,cAAc,CACZ,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,wBAAwB,CAAC;CACrC;AAED;;;GAGG;AACH,qBAAa,gCACX,YAAW,wBAAwB;IAEnC,8EAA8E;IACjE,cAAc,CACzB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAQnC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.NewerVersionSchemaImportStrategy = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Selects source schemas that are absent from the target or have a newer version.
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
class NewerVersionSchemaImportStrategy {
|
|
16
|
+
/** Select schemas that are absent from the target or have a newer version. */
|
|
17
|
+
async processSchemas(context) {
|
|
18
|
+
const results = [];
|
|
19
|
+
for (const schema of context.sourceSchemas) {
|
|
20
|
+
if (await context.shouldExportSchema(schema.schemaKey)) {
|
|
21
|
+
results.push({ kind: "source", schema });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return results;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.NewerVersionSchemaImportStrategy = NewerVersionSchemaImportStrategy;
|
|
28
|
+
//# sourceMappingURL=SchemaProcessingStrategy.js.map
|