Skip to content

Commit

Permalink
Replace native schemaToXmlString (#217)
Browse files Browse the repository at this point in the history
- Add SchemaTestUtils class that with schemaToXmlString method
- To convert schema to an xml string I added @itwin/ecschema-locaters as they have helper to do this
- In an effort to replace internal apis that are currently deprecated and will be removed in itwin js 5.0 release, we will replace `nativeDb.schemaToXmlString` with `SchemaTestUtils.schemaToXmlString`
  • Loading branch information
derbynn authored Oct 15, 2024
1 parent 37d2ecc commit b08a684
Show file tree
Hide file tree
Showing 6 changed files with 5,258 additions and 4,030 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"
}
1 change: 1 addition & 0 deletions packages/transformer/package.json
Original file line number Diff line number Diff line change
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 b08a684

Please sign in to comment.