@itwin/imodel-transformer 2.0.0-dev.43 → 2.0.0-dev.44
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 +1 -1
- package/lib/cjs/IModelExporter.d.ts +5 -0
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +20 -17
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +9 -11
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +19 -64
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/lib/cjs/IModelTransformerError.d.ts +4 -0
- package/lib/cjs/IModelTransformerError.d.ts.map +1 -1
- package/lib/cjs/IModelTransformerError.js +4 -0
- package/lib/cjs/IModelTransformerError.js.map +1 -1
- package/lib/cjs/imodel-transformer.d.ts +1 -0
- package/lib/cjs/imodel-transformer.d.ts.map +1 -1
- package/lib/cjs/imodel-transformer.js +1 -0
- 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 +163 -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 +37 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaProcessingCoordinator.js","sourceRoot":"","sources":["../../../src/schema-processing/SchemaProcessingCoordinator.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,kCAAkC;AAClC,sDAAiD;AACjD,sDAA+E;AAC/E,gEAA2E;AAE3E,sEAGmC;AAenC,gBAAgB;AAChB,MAAa,2BAA2B;IAGF;IAFnB,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE/D,YAAoC,KAAsC;QAAtC,UAAK,GAAL,KAAK,CAAiC;IAAG,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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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;CASrC"}
|
|
@@ -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;;;AAqDH;;;GAGG;AACH,MAAa,gCAAgC;IAG3C,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;AAfD,4EAeC","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 }\n | { 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\n implements SchemaProcessingStrategy\n{\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,9 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/imodel-transformer",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.44",
|
|
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
29
|
"node": "^22.12.0 || ^24.18.0"
|
|
@@ -18,7 +38,9 @@
|
|
|
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
40
|
"cover": "vitest run --coverage",
|
|
21
|
-
"extract-api": "
|
|
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",
|
|
22
44
|
"lint": "eslint -f visualstudio --quiet \"./src/**/*.ts\" 1>&2",
|
|
23
45
|
"lint:no-tests": "eslint -f visualstudio --quiet \"./src/*.ts\" 1>&2",
|
|
24
46
|
"lint:fix": "eslint --fix -f visualstudio --quiet \"./src/**/*.ts\" 1>&2",
|
|
@@ -57,8 +79,18 @@
|
|
|
57
79
|
"@itwin/core-common": "^5.9.1",
|
|
58
80
|
"@itwin/core-geometry": "^5.9.1",
|
|
59
81
|
"@itwin/core-quantity": "^5.9.1",
|
|
82
|
+
"@itwin/ecschema-editing": "^5.9.1",
|
|
83
|
+
"@itwin/ecschema-locaters": "^5.9.1",
|
|
60
84
|
"@itwin/ecschema-metadata": "^5.9.1"
|
|
61
85
|
},
|
|
86
|
+
"peerDependenciesMeta": {
|
|
87
|
+
"@itwin/ecschema-editing": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@itwin/ecschema-locaters": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
93
|
+
},
|
|
62
94
|
"//devDependencies": [
|
|
63
95
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
64
96
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
@@ -70,7 +102,8 @@
|
|
|
70
102
|
"@itwin/core-common": "^5.10.3",
|
|
71
103
|
"@itwin/core-geometry": "^5.10.3",
|
|
72
104
|
"@itwin/core-quantity": "^5.10.3",
|
|
73
|
-
"@itwin/ecschema-
|
|
105
|
+
"@itwin/ecschema-editing": "5.10.3",
|
|
106
|
+
"@itwin/ecschema-locaters": "5.10.3",
|
|
74
107
|
"@itwin/ecschema-metadata": "^5.10.3",
|
|
75
108
|
"@itwin/eslint-plugin": "^5.2.1",
|
|
76
109
|
"@itwin/imodel-transformer-test-utils": "0.0.0",
|