@itwin/imodel-transformer 2.0.0-dev.7 → 2.0.0-dev.70

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.
Files changed (132) hide show
  1. package/README.md +13 -27
  2. package/lib/cjs/Algo.d.ts +0 -4
  3. package/lib/cjs/Algo.d.ts.map +1 -1
  4. package/lib/cjs/Algo.js +0 -11
  5. package/lib/cjs/Algo.js.map +1 -1
  6. package/lib/cjs/BigMap.d.ts.map +1 -1
  7. package/lib/cjs/BigMap.js.map +1 -1
  8. package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
  9. package/lib/cjs/BranchProvenanceInitializer.js +26 -26
  10. package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
  11. package/lib/cjs/ChangedElementForest.d.ts +14 -0
  12. package/lib/cjs/ChangedElementForest.d.ts.map +1 -0
  13. package/lib/cjs/ChangedElementForest.js +86 -0
  14. package/lib/cjs/ChangedElementForest.js.map +1 -0
  15. package/lib/cjs/ChangesetScanner.d.ts +141 -0
  16. package/lib/cjs/ChangesetScanner.d.ts.map +1 -0
  17. package/lib/cjs/ChangesetScanner.js +187 -0
  18. package/lib/cjs/ChangesetScanner.js.map +1 -0
  19. package/lib/cjs/ECReferenceTypesCache.d.ts +0 -4
  20. package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
  21. package/lib/cjs/ECReferenceTypesCache.js +61 -111
  22. package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
  23. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.d.ts.map +1 -1
  24. package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
  25. package/lib/cjs/ElementAspectCleanup.d.ts +16 -0
  26. package/lib/cjs/ElementAspectCleanup.d.ts.map +1 -0
  27. package/lib/cjs/ElementAspectCleanup.js +87 -0
  28. package/lib/cjs/ElementAspectCleanup.js.map +1 -0
  29. package/lib/cjs/ElementAspectExportCoordinator.d.ts +44 -0
  30. package/lib/cjs/ElementAspectExportCoordinator.d.ts.map +1 -0
  31. package/lib/cjs/ElementAspectExportCoordinator.js +148 -0
  32. package/lib/cjs/ElementAspectExportCoordinator.js.map +1 -0
  33. package/lib/cjs/ElementAspectExportProcessor.d.ts +44 -0
  34. package/lib/cjs/ElementAspectExportProcessor.d.ts.map +1 -0
  35. package/lib/cjs/ElementAspectExportProcessor.js +152 -0
  36. package/lib/cjs/ElementAspectExportProcessor.js.map +1 -0
  37. package/lib/cjs/ElementBulkDelete.d.ts +30 -0
  38. package/lib/cjs/ElementBulkDelete.d.ts.map +1 -0
  39. package/lib/cjs/ElementBulkDelete.js +358 -0
  40. package/lib/cjs/ElementBulkDelete.js.map +1 -0
  41. package/lib/cjs/EntityExistenceCache.d.ts +43 -0
  42. package/lib/cjs/EntityExistenceCache.d.ts.map +1 -0
  43. package/lib/cjs/EntityExistenceCache.js +91 -0
  44. package/lib/cjs/EntityExistenceCache.js.map +1 -0
  45. package/lib/cjs/EntityUnifier.d.ts +7 -7
  46. package/lib/cjs/EntityUnifier.d.ts.map +1 -1
  47. package/lib/cjs/EntityUnifier.js +55 -24
  48. package/lib/cjs/EntityUnifier.js.map +1 -1
  49. package/lib/cjs/IModelCloneContext.d.ts +9 -3
  50. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  51. package/lib/cjs/IModelCloneContext.js +56 -22
  52. package/lib/cjs/IModelCloneContext.js.map +1 -1
  53. package/lib/cjs/IModelExporter.d.ts +171 -43
  54. package/lib/cjs/IModelExporter.d.ts.map +1 -1
  55. package/lib/cjs/IModelExporter.js +946 -247
  56. package/lib/cjs/IModelExporter.js.map +1 -1
  57. package/lib/cjs/IModelImporter.d.ts +75 -30
  58. package/lib/cjs/IModelImporter.d.ts.map +1 -1
  59. package/lib/cjs/IModelImporter.js +292 -132
  60. package/lib/cjs/IModelImporter.js.map +1 -1
  61. package/lib/cjs/IModelTransformContext.d.ts +54 -0
  62. package/lib/cjs/IModelTransformContext.d.ts.map +1 -0
  63. package/lib/cjs/IModelTransformContext.js +3 -0
  64. package/lib/cjs/IModelTransformContext.js.map +1 -0
  65. package/lib/cjs/IModelTransformer.d.ts +180 -206
  66. package/lib/cjs/IModelTransformer.d.ts.map +1 -1
  67. package/lib/cjs/IModelTransformer.js +811 -1278
  68. package/lib/cjs/IModelTransformer.js.map +1 -1
  69. package/lib/cjs/IModelTransformerError.d.ts +84 -0
  70. package/lib/cjs/IModelTransformerError.d.ts.map +1 -0
  71. package/lib/cjs/IModelTransformerError.js +93 -0
  72. package/lib/cjs/IModelTransformerError.js.map +1 -0
  73. package/lib/cjs/ProvenanceManager.d.ts +177 -0
  74. package/lib/cjs/ProvenanceManager.d.ts.map +1 -0
  75. package/lib/cjs/ProvenanceManager.js +719 -0
  76. package/lib/cjs/ProvenanceManager.js.map +1 -0
  77. package/lib/cjs/SourceClassKinds.d.ts +22 -0
  78. package/lib/cjs/SourceClassKinds.d.ts.map +1 -0
  79. package/lib/cjs/SourceClassKinds.js +60 -0
  80. package/lib/cjs/SourceClassKinds.js.map +1 -0
  81. package/lib/cjs/SyncTypeResolver.d.ts +32 -0
  82. package/lib/cjs/SyncTypeResolver.d.ts.map +1 -0
  83. package/lib/cjs/SyncTypeResolver.js +92 -0
  84. package/lib/cjs/SyncTypeResolver.js.map +1 -0
  85. package/lib/cjs/TransformerLoggerCategory.d.ts +1 -1
  86. package/lib/cjs/TransformerLoggerCategory.js +1 -1
  87. package/lib/cjs/TransformerLoggerCategory.js.map +1 -1
  88. package/lib/cjs/TransformerPackageMetadata.d.ts +8 -0
  89. package/lib/cjs/TransformerPackageMetadata.d.ts.map +1 -0
  90. package/lib/cjs/TransformerPackageMetadata.js +47 -0
  91. package/lib/cjs/TransformerPackageMetadata.js.map +1 -0
  92. package/lib/cjs/imodel-transformer.d.ts +28 -0
  93. package/lib/cjs/imodel-transformer.d.ts.map +1 -1
  94. package/lib/cjs/imodel-transformer.js +61 -34
  95. package/lib/cjs/imodel-transformer.js.map +1 -1
  96. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts +29 -0
  97. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.d.ts.map +1 -0
  98. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js +212 -0
  99. package/lib/cjs/schema-processing/DynamicSchemaUnionStrategy.js.map +1 -0
  100. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts +25 -0
  101. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.d.ts.map +1 -0
  102. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js +196 -0
  103. package/lib/cjs/schema-processing/SchemaProcessingCoordinator.js.map +1 -0
  104. package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts +59 -0
  105. package/lib/cjs/schema-processing/SchemaProcessingStrategy.d.ts.map +1 -0
  106. package/lib/cjs/schema-processing/SchemaProcessingStrategy.js +28 -0
  107. package/lib/cjs/schema-processing/SchemaProcessingStrategy.js.map +1 -0
  108. package/lib/cjs/schema-processing.d.ts +7 -0
  109. package/lib/cjs/schema-processing.d.ts.map +1 -0
  110. package/lib/cjs/schema-processing.js +27 -0
  111. package/lib/cjs/schema-processing.js.map +1 -0
  112. package/package.json +70 -57
  113. package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts +0 -16
  114. package/lib/cjs/DetachedExportElementAspectsStrategy.d.ts.map +0 -1
  115. package/lib/cjs/DetachedExportElementAspectsStrategy.js +0 -106
  116. package/lib/cjs/DetachedExportElementAspectsStrategy.js.map +0 -1
  117. package/lib/cjs/ElementCascadingDeleter.d.ts +0 -22
  118. package/lib/cjs/ElementCascadingDeleter.d.ts.map +0 -1
  119. package/lib/cjs/ElementCascadingDeleter.js +0 -57
  120. package/lib/cjs/ElementCascadingDeleter.js.map +0 -1
  121. package/lib/cjs/EntityMap.d.ts +0 -26
  122. package/lib/cjs/EntityMap.d.ts.map +0 -1
  123. package/lib/cjs/EntityMap.js +0 -54
  124. package/lib/cjs/EntityMap.js.map +0 -1
  125. package/lib/cjs/ExportElementAspectsStrategy.d.ts +0 -35
  126. package/lib/cjs/ExportElementAspectsStrategy.d.ts.map +0 -1
  127. package/lib/cjs/ExportElementAspectsStrategy.js +0 -52
  128. package/lib/cjs/ExportElementAspectsStrategy.js.map +0 -1
  129. package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts +0 -12
  130. package/lib/cjs/ExportElementAspectsWithElementsStrategy.d.ts.map +0 -1
  131. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js +0 -47
  132. package/lib/cjs/ExportElementAspectsWithElementsStrategy.js.map +0 -1
@@ -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,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YACD,MAAM,kBAAkB,GAAG,IAAI,gCAAY,CAAC,CAAC,IAAI,EAAE,EAAE,CACnD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CACzC,CAAC;YACF,MAAM,aAAa,GAA2B;gBAC5C,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CAC9B,kBAAkB,CAAC,YAAY,CAAC,UAAU,CAAC;aAC9C,CAAC;YACF,MAAM,gBAAgB,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC;gBACrD,aAAa,EAAE,0BAA0B,CA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C;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,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E;;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,gCAAiC,YAAW,wBAAwB;IAC/E,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaProcessingStrategy.js","sourceRoot":"","sources":["../../../src/schema-processing/SchemaProcessingStrategy.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAoDH;;;GAGG;AACH;IACE,8EAA8E;IACvE,KAAK,CAAC,cAAc,CACzB,OAAgC;QAEhC,MAAM,OAAO,GAA6B,EAAE,CAAC;QAC7C,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3C,IAAI,MAAM,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;gBACvD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { Schema, SchemaKey } from \"@itwin/ecschema-metadata\";\n\n/**\n * The result of processing one schema.\n * @beta\n */\nexport type SchemaProcessingResult =\n { kind: \"source\"; schema: Schema } | { kind: \"generated\"; schema: Schema };\n\n/** Read-only access to schemas already present in the target iModel.\n * @beta\n */\nexport interface ReadonlySchemaAccessor {\n /** Load a target schema by name, or return `undefined` when it is absent. */\n getSchema(schemaName: string): Promise<Schema | undefined>;\n}\n\n/**\n * Context supplied to a [[SchemaProcessingStrategy]].\n * @beta\n */\nexport interface SchemaProcessingContext {\n /** Source schemas in dependency order. */\n readonly sourceSchemas: readonly Schema[];\n /** Read-only access to schemas already present in the target. */\n readonly targetSchemas: ReadonlySchemaAccessor;\n /** The schema-selection hook used by the default transformer path. */\n readonly shouldExportSchema: (schemaKey: SchemaKey) => Promise<boolean>;\n}\n\n/**\n * Selects source schemas and produces definitions for import into a target iModel.\n * @beta\n */\nexport interface SchemaProcessingStrategy {\n /** Select source schemas and produce definitions for import into the target iModel. */\n processSchemas(\n context: SchemaProcessingContext\n ): Promise<SchemaProcessingResult[]>;\n}\n\n/**\n * Options for [[IModelTransformer.processSchemas]].\n * @beta\n */\nexport interface ProcessSchemasOptions {\n /** Strategy used to select and process source schemas. */\n strategy?: SchemaProcessingStrategy;\n}\n\n/**\n * Selects source schemas that are absent from the target or have a newer version.\n * @beta\n */\nexport class NewerVersionSchemaImportStrategy implements SchemaProcessingStrategy {\n /** Select schemas that are absent from the target or have a newer version. */\n public async processSchemas(\n context: SchemaProcessingContext\n ): Promise<SchemaProcessingResult[]> {\n const results: SchemaProcessingResult[] = [];\n for (const schema of context.sourceSchemas) {\n if (await context.shouldExportSchema(schema.schemaKey)) {\n results.push({ kind: \"source\", schema });\n }\n }\n return results;\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /** @packageDocumentation
2
+ * Optional schema-processing strategies for `@itwin/imodel-transformer`.
3
+ * @module iModels
4
+ */
5
+ export * from "./schema-processing/SchemaProcessingStrategy";
6
+ export * from "./schema-processing/DynamicSchemaUnionStrategy";
7
+ //# sourceMappingURL=schema-processing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-processing.d.ts","sourceRoot":"","sources":["../../src/schema-processing.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,cAAc,8CAA8C,CAAC;AAC7D,cAAc,gDAAgD,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*---------------------------------------------------------------------------------------------
18
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
19
+ * See LICENSE.md in the project root for license terms and full copyright notice.
20
+ *--------------------------------------------------------------------------------------------*/
21
+ /** @packageDocumentation
22
+ * Optional schema-processing strategies for `@itwin/imodel-transformer`.
23
+ * @module iModels
24
+ */
25
+ __exportStar(require("./schema-processing/SchemaProcessingStrategy"), exports);
26
+ __exportStar(require("./schema-processing/DynamicSchemaUnionStrategy"), exports);
27
+ //# sourceMappingURL=schema-processing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-processing.js","sourceRoot":"","sources":["../../src/schema-processing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG;;;GAGG;AACH,+EAA6D;AAC7D,iFAA+D","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 * Optional schema-processing strategies for `@itwin/imodel-transformer`.\n * @module iModels\n */\nexport * from \"./schema-processing/SchemaProcessingStrategy\";\nexport * from \"./schema-processing/DynamicSchemaUnionStrategy\";\n"]}
package/package.json CHANGED
@@ -1,31 +1,53 @@
1
1
  {
2
2
  "name": "@itwin/imodel-transformer",
3
- "version": "2.0.0-dev.7",
3
+ "version": "2.0.0-dev.70",
4
4
  "description": "API for exporting an iModel's parts and also importing them into another iModel",
5
5
  "main": "lib/cjs/imodel-transformer.js",
6
- "typings": "lib/cjs/imodel-transformer",
6
+ "typings": "lib/cjs/imodel-transformer.d.ts",
7
+ "typesVersions": {
8
+ "*": {
9
+ "schema-processing": [
10
+ "lib/cjs/schema-processing.d.ts"
11
+ ]
12
+ }
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./lib/cjs/imodel-transformer.d.ts",
17
+ "require": "./lib/cjs/imodel-transformer.js",
18
+ "default": "./lib/cjs/imodel-transformer.js"
19
+ },
20
+ "./schema-processing": {
21
+ "types": "./lib/cjs/schema-processing.d.ts",
22
+ "require": "./lib/cjs/schema-processing.js",
23
+ "default": "./lib/cjs/schema-processing.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
7
27
  "license": "MIT",
8
28
  "engines": {
9
- "node": "^22.12.0"
29
+ "node": "^22.12.0 || ^24.18.0"
10
30
  },
11
31
  "scripts": {
12
- "build": "npm run -s build:cjs && npm run -s copy:test-assets && npm run -s extract-api",
13
- "build:cjs": "tsc 1>&2 --outDir lib/cjs",
14
- "clean": "rimraf lib",
32
+ "build": "npm run -s typecheck && npm run -s build:cjs && npm run -s extract-api",
33
+ "build:cjs": "tsc -p tsconfig.build.json 1>&2 --outDir lib/cjs",
34
+ "clean": "node ../../scripts/rm.js lib",
15
35
  "docs": "npm run -s docs:extract && npm run -s docs:reference && npm run -s docs:changelog",
16
- "docs:changelog": "cpx ./CHANGELOG.md ../../build/docs/reference/imodel-transformer",
36
+ "docs:changelog": "node scripts/copyChangelog.js",
17
37
  "# env var is workaround, need to contribute a better rush-less root-package.json detector to betools": "",
18
38
  "docs:reference": "cross-env RUSHSTACK_FILE_ERROR_BASE_FOLDER='../..' betools docs --includes=../../build/docs/extract --json=../../build/docs/reference/imodel-transformer/file.json --tsIndexFile=imodel-transformer.ts --onlyJson",
19
39
  "docs:extract": "betools extract --fileExt=ts --extractFrom=./src/test --recursive --out=../../build/docs/extract",
20
- "copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/cjs/test/assets",
21
- "cover": "nyc npm -s test",
22
- "extract-api": "betools extract-api --entry=imodel-transformer --apiReportFolder=../../common/api --apiReportTempFolder=../../common/api/temp --apiSummaryFolder=../../common/api/summary",
23
- "lint": "eslint -f visualstudio --quiet \"./src/**/*.ts\" 1>&2",
24
- "lint:no-tests": "eslint -f visualstudio --quiet \"./src/*.ts\" 1>&2",
25
- "lint:fix": "eslint --fix -f visualstudio --quiet \"./src/**/*.ts\" 1>&2",
40
+ "cover": "vitest run --coverage",
41
+ "extract-api": "npm run -s extract-api:root && npm run -s extract-api:schema-processing",
42
+ "extract-api:root": "betools extract-api --entry=imodel-transformer --apiReportFolder=../../common/api --apiReportTempFolder=../../common/api/temp --apiSummaryFolder=../../common/api/summary",
43
+ "extract-api:schema-processing": "betools extract-api --entry=schema-processing --apiReportFolder=../../common/api --apiReportTempFolder=../../common/api/temp --apiSummaryFolder=../../common/api/summary",
44
+ "lint": "eslint --quiet \"./src/**/*.ts\" 1>&2",
45
+ "lint:no-tests": "eslint --quiet \"./src/*.ts\" 1>&2",
46
+ "lint:fix": "eslint --fix --quiet \"./src/**/*.ts\" 1>&2",
26
47
  "format": "prettier \"./src/**/*.ts\" --write",
27
- "lint:with-warnings": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2",
28
- "test": "mocha \"lib/cjs/test/**/*.test.js\" --timeout 0 --reporter-option maxDiffSize=0 --require source-map-support/register",
48
+ "lint:with-warnings": "eslint \"./src/**/*.ts\" 1>&2",
49
+ "test": "vitest run",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit --incremental false 1>&2",
29
51
  "no-internal-report": "no-internal-report src/**/*.ts"
30
52
  },
31
53
  "repository": {
@@ -49,59 +71,50 @@
49
71
  "This package relies on @internal APIs in iTwin.js, and therefore has very strict peerDep versions",
50
72
  "We perform a version check at runtime to ensure this.",
51
73
  "Every new iTwin.js version must be validated, and fixes are rarely ported to old versions.",
52
- "Removing Dependencies on internal APIs is ongoing.",
53
- "You can find a script to see the latest @itwin/imodel-transformer version for your iTwin.js version in the README"
74
+ "Removing Dependencies on internal APIs is ongoing."
54
75
  ],
55
76
  "peerDependencies": {
56
- "@itwin/core-backend": "^5.2.4",
57
- "@itwin/core-bentley": "^5.2.4",
58
- "@itwin/core-common": "^5.2.4",
59
- "@itwin/core-geometry": "^5.2.4",
60
- "@itwin/core-quantity": "^5.2.4",
61
- "@itwin/ecschema-metadata": "^5.2.4"
77
+ "@itwin/core-backend": "^5.14.2",
78
+ "@itwin/core-bentley": "^5.14.2",
79
+ "@itwin/core-common": "^5.14.2",
80
+ "@itwin/core-geometry": "^5.14.2",
81
+ "@itwin/core-quantity": "^5.14.2",
82
+ "@itwin/ecschema-editing": "^5.14.2",
83
+ "@itwin/ecschema-locaters": "^5.14.2",
84
+ "@itwin/ecschema-metadata": "^5.14.2"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "@itwin/ecschema-editing": {
88
+ "optional": true
89
+ },
90
+ "@itwin/ecschema-locaters": {
91
+ "optional": true
92
+ }
62
93
  },
63
94
  "//devDependencies": [
64
95
  "NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
65
- "NOTE: All tools used by scripts in this package must be listed as devDependencies"
96
+ "NOTE: All tools used by scripts in this package must be listed as devDependencies, except ESLint and Prettier tooling, which the workspace root declares"
66
97
  ],
67
98
  "devDependencies": {
68
- "@itwin/build-tools": "^5.2.4",
69
- "@itwin/core-backend": "^5.2.4",
70
- "@itwin/core-bentley": "^5.2.4",
71
- "@itwin/core-common": "^5.2.4",
72
- "@itwin/core-geometry": "^5.2.4",
73
- "@itwin/core-quantity": "^5.2.4",
74
- "@itwin/ecschema-locaters": "^5.2.4",
75
- "@itwin/ecschema-metadata": "^5.2.4",
76
- "@itwin/eslint-plugin": "^5.2.1",
77
- "@types/chai": "^4.3.20",
78
- "@types/chai-as-promised": "^7.1.8",
79
- "@types/mocha": "^8.2.3",
80
- "@types/node": "^22.18.8",
81
- "@types/node-fetch": "^2.6.13",
99
+ "@itwin/build-tools": "^5.14.2",
100
+ "@itwin/core-backend": "^5.14.2",
101
+ "@itwin/core-bentley": "^5.14.2",
102
+ "@itwin/core-common": "^5.14.2",
103
+ "@itwin/core-geometry": "^5.14.2",
104
+ "@itwin/core-quantity": "^5.14.2",
105
+ "@itwin/ecschema-editing": "5.14.2",
106
+ "@itwin/ecschema-locaters": "5.14.2",
107
+ "@itwin/ecschema-metadata": "^5.14.2",
108
+ "@itwin/imodel-transformer-test-utils": "0.0.0",
109
+ "@types/node": "^22.18.12",
82
110
  "@types/semver": "^7.7.1",
83
- "@types/sinon": "^9.0.11",
84
- "@typescript-eslint/parser": "^8.45.0",
85
- "chai": "^4.5.0",
86
- "chai-as-promised": "^7.1.2",
87
- "cpx2": "^3.0.2",
111
+ "@vitest/coverage-v8": "4.1.10",
88
112
  "cross-env": "^5.2.1",
89
- "eslint": "^9.36.0",
90
- "eslint-config-prettier": "^9.1.2",
91
- "js-base64": "^3.7.8",
92
- "mocha": "^10.8.2",
93
- "npm-run-all": "^4.1.5",
94
- "nyc": "^15.1.0",
95
- "prettier": "^3.6.2",
96
- "rimraf": "^3.0.2",
97
- "sinon": "^9.2.4",
98
- "source-map-support": "^0.5.21",
99
- "typescript": "^5.9.3"
113
+ "@typescript/native": "npm:typescript@~7.0.2",
114
+ "typescript": "npm:@typescript/typescript6@~6.0.2",
115
+ "vitest": "4.1.10"
100
116
  },
101
117
  "dependencies": {
102
118
  "semver": "^7.7.2"
103
- },
104
- "nyc": {
105
- "extends": "./node_modules/@itwin/build-tools/.nycrc"
106
119
  }
107
120
  }
@@ -1,16 +0,0 @@
1
- import { ExportElementAspectsStrategy } from "./ExportElementAspectsStrategy";
2
- /**
3
- * Detached ElementAspect export strategy for [[IModelExporter]].
4
- * This strategy exports all ElementAspects separately from the Elements that own them.
5
- *
6
- * @note Since aspects are exported separately from elements that own them, this strategy will export aspects of filtered out elements by default and
7
- * this needs to be handled by ElementAspectHandler
8
- * @internal
9
- */
10
- export declare class DetachedExportElementAspectsStrategy extends ExportElementAspectsStrategy {
11
- exportAllElementAspects(): Promise<void>;
12
- private exportAspectsLoop;
13
- private queryAspects;
14
- exportElementAspectsForElement(_elementId: string): Promise<void>;
15
- }
16
- //# sourceMappingURL=DetachedExportElementAspectsStrategy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DetachedExportElementAspectsStrategy.d.ts","sourceRoot":"","sources":["../../src/DetachedExportElementAspectsStrategy.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAQ9E;;;;;;;GAOG;AACH,qBAAa,oCAAqC,SAAQ,4BAA4B;IAC9D,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;YAsDhD,iBAAiB;YAahB,YAAY;IA8DL,8BAA8B,CAClD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;CAGjB"}