-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace native schemaToXmlString (#217)
- 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
Showing
6 changed files
with
5,258 additions
and
4,030 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@itwin-imodel-transformer-9ed49a07-59ed-4232-99e0-f7b895aa8d4e.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/transformer/src/test/TestUtils/SchemaTestUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.