Skip to content

Commit

Permalink
Merge branch 'main' into dan/extract-api
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRod1999 authored Oct 15, 2024
2 parents 39c4b9b + 0ddf1d1 commit 0c2156f
Show file tree
Hide file tree
Showing 6 changed files with 496 additions and 413 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "add alternative schemaToXmlString",
"packageName": "@itwin/imodel-transformer",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion packages/transformer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itwin/imodel-transformer",
"version": "1.0.0-dev.22",
"version": "1.0.0-dev.23",
"description": "API for exporting an iModel's parts and also importing them into another iModel",
"main": "lib/cjs/transformer.js",
"typings": "lib/cjs/transformer",
Expand Down Expand Up @@ -73,6 +73,7 @@
"@itwin/core-geometry": "4.3.5",
"@itwin/core-quantity": "4.3.5",
"@itwin/ecschema-metadata": "4.3.5",
"@itwin/ecschema-locaters": "4.3.5",
"@itwin/eslint-plugin": "^4.0.2",
"@types/chai": "4.3.1",
"@types/chai-as-promised": "^7.1.5",
Expand Down
32 changes: 32 additions & 0 deletions packages/transformer/src/test/TestUtils/SchemaTestUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { IModelDb } from "@itwin/core-backend";
import { SchemaLoader } from "@itwin/ecschema-metadata";
import { SchemaXml } from "@itwin/ecschema-locaters";

export class SchemaTestUtils {
public static async schemaToXmlString(
schemaName: string,
iModel: IModelDb
): Promise<string> {
try {
// Load the schema properties
const schemaLoader = new SchemaLoader((name: string) =>
iModel.getSchemaProps(name)
);
const schema = schemaLoader.getSchema(schemaName);

if (!schema) {
throw new Error(`Schema with name ${schemaName} not found.`);
}

// Writes a schema to an xml string
const schemaXmlString = await SchemaXml.writeString(schema);
return schemaXmlString;
} catch (error) {
throw error;
}
}
}
1 change: 1 addition & 0 deletions packages/transformer/src/test/TestUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./KnownTestLocations";
export * from "./TestChangeSetUtility";
export * from "./imageData";
export * from "./GeometryTestUtil";
export * from "./SchemaTestUtils";
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import { KnownTestLocations } from "../TestUtils/KnownTestLocations";
import "./TransformerTestStartup"; // calls startup/shutdown IModelHost before/after all tests
import { SchemaLoader } from "@itwin/ecschema-metadata";
import { DetachedExportElementAspectsStrategy } from "../../DetachedExportElementAspectsStrategy";
import { SchemaTestUtils } from "../TestUtils";

describe("IModelTransformer", () => {
const outputDir = path.join(
Expand Down Expand Up @@ -3893,9 +3894,13 @@ describe("IModelTransformer", () => {
assert(biscoreVersion !== undefined);
const fakeSchemaVersion = "1.0.99";
expect(Semver.lt(biscoreVersion, fakeSchemaVersion)).to.be.true;
// eslint-disable-next-line deprecation/deprecation
const biscoreText = sourceDb.nativeDb.schemaToXmlString("BisCore");

const biscoreText = await SchemaTestUtils.schemaToXmlString(
"BisCore",
sourceDb
);
assert(biscoreText !== undefined);

const fakeBisCoreUpdateText = biscoreText
.replace(
/(<ECSchema .*?>)/,
Expand Down
Loading

0 comments on commit 0c2156f

Please sign in to comment.