@itwin/ecschema2ts 5.0.0-dev.99 → 5.0.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema2ts_io.d.ts","sourceRoot":"","sources":["../../src/ecschema2ts_io.ts"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"ecschema2ts_io.d.ts","sourceRoot":"","sources":["../../src/ecschema2ts_io.ts"],"names":[],"mappings":"AAOA,OAAO,EAAoE,aAAa,EAA0C,MAAM,0BAA0B,CAAC;AAmQnK;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,iBAAiB,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3G;AAED;;GAEG;AACH,qBAAa,qBAAsB,YAAW,sBAAsB;IAClE,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,OAAO,CAAS;gBAEL,MAAM,EAAE,MAAM;IAMjC;;;;;;;OAOG;IACU,iBAAiB,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAiCvH"}
|
|
@@ -56,12 +56,12 @@ class SchemaBackendFileLocater extends ecschema_locaters_1.SchemaFileLocater {
|
|
|
56
56
|
getSchemaKey(data) {
|
|
57
57
|
const matches = data.match(/<ECSchema ([^]+?)>/g);
|
|
58
58
|
if (!matches || matches.length !== 1)
|
|
59
|
-
throw new ecschema_metadata_1.
|
|
59
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
|
|
60
60
|
// parse name and version
|
|
61
61
|
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
62
62
|
const version = matches[0].match(/version="(.+?)"/);
|
|
63
63
|
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
64
|
-
throw new ecschema_metadata_1.
|
|
64
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
|
|
65
65
|
const versionStr = this.resolveECVersionString(version[1]);
|
|
66
66
|
const key = new ecschema_metadata_1.SchemaKey(name[1], ecschema_metadata_1.ECVersion.fromString(versionStr));
|
|
67
67
|
return key;
|
|
@@ -97,11 +97,11 @@ class SchemaBackendFileLocater extends ecschema_locaters_1.SchemaFileLocater {
|
|
|
97
97
|
if (undefined === context.getSchemaSync(referenceKey, matchType)) {
|
|
98
98
|
const referenceSchema = this.getSchemaRecursively(referenceKey, ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible, context, localPath);
|
|
99
99
|
if (!referenceSchema) {
|
|
100
|
-
throw new ecschema_metadata_1.
|
|
100
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.UnableToLocateSchema, `Could not locate reference schema, ${referenceKey.name}.${referenceKey.version.toString()} of schema ${key.name}.${key.version.toString()}`);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
else if (localPath.has(referenceKeyName)) {
|
|
104
|
-
throw new ecschema_metadata_1.
|
|
104
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.InvalidSchemaXML, `Schema ${schemaKeyName} and ${referenceKeyName} form cyclic dependency`);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
localPath.delete(schemaKeyName);
|
|
@@ -137,7 +137,7 @@ class SchemaBackendFileLocater extends ecschema_locaters_1.SchemaFileLocater {
|
|
|
137
137
|
getRequiredXmlAttribute(xmlElement, attribute, errorMessage) {
|
|
138
138
|
const value = xmlElement.getAttribute(attribute);
|
|
139
139
|
if (!value)
|
|
140
|
-
throw new ecschema_metadata_1.
|
|
140
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.InvalidSchemaXML, errorMessage);
|
|
141
141
|
return value;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
@@ -149,7 +149,7 @@ class SchemaBackendFileLocater extends ecschema_locaters_1.SchemaFileLocater {
|
|
|
149
149
|
// check that version at leasts contain read and write number. If so, add 00 to the minor version if there is none existed in the version
|
|
150
150
|
let versionNumbers = version.split(".");
|
|
151
151
|
if (versionNumbers.length < 2)
|
|
152
|
-
throw new ecschema_metadata_1.
|
|
152
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.InvalidSchemaXML, `'version' number does not at least have read and minor number in the given file`);
|
|
153
153
|
else if (versionNumbers.length === 2) {
|
|
154
154
|
versionNumbers.push("00");
|
|
155
155
|
const [readNumber, minorNumber, writeNumber] = versionNumbers;
|
|
@@ -171,7 +171,7 @@ class SchemaDeserializer {
|
|
|
171
171
|
async deserializeXmlFile(schemaFilePath, schemaContext, referencePaths) {
|
|
172
172
|
// If the schema file doesn't exist, throw an error
|
|
173
173
|
if (!fs.existsSync(schemaFilePath))
|
|
174
|
-
throw new ecschema_metadata_1.
|
|
174
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaFilePath}`);
|
|
175
175
|
await core_backend_1.IModelHost.startup({ cacheDir: path.join(__dirname, ".cache") });
|
|
176
176
|
// add reference paths to the native context
|
|
177
177
|
if (undefined === referencePaths)
|
|
@@ -209,7 +209,7 @@ class SchemaDeserializer {
|
|
|
209
209
|
deserializeJsonFile(schemaFilePath, context, referencePaths) {
|
|
210
210
|
// If the schema file doesn't exist, throw an error
|
|
211
211
|
if (!fs.existsSync(schemaFilePath))
|
|
212
|
-
throw new ecschema_metadata_1.
|
|
212
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema JSON file at ${schemaFilePath}`);
|
|
213
213
|
// add locater to the context
|
|
214
214
|
if (!referencePaths)
|
|
215
215
|
referencePaths = [];
|
|
@@ -224,7 +224,7 @@ class SchemaDeserializer {
|
|
|
224
224
|
schemaJson = JSON.parse(schemaString);
|
|
225
225
|
}
|
|
226
226
|
catch (e) {
|
|
227
|
-
throw new ecschema_metadata_1.
|
|
227
|
+
throw new ecschema_metadata_1.ECSchemaError(ecschema_metadata_1.ECSchemaStatus.InvalidECJson, e.message);
|
|
228
228
|
}
|
|
229
229
|
return ecschema_metadata_1.Schema.fromJsonSync(schemaJson, context);
|
|
230
230
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema2ts_io.js","sourceRoot":"","sources":["../../src/ecschema2ts_io.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,6BAA6B;AAC7B,yBAAyB;AACzB,gEAAqK;AACrK,gEAAmG;AACnG,2CAA2C;AAC3C,sDAAqE;AACrE,+CAA6C;AAE7C,MAAM,cAAc,GAAG,IAAI,6BAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACvD,MAAM,gBAAgB,GAAG,IAAI,6BAAS,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3D;;;;GAIG;AACH,MAAM,wBAAyB,SAAQ,qCAAiB;IAC9C,cAAc,CAAqB;IAE3C,YAAmB,aAAiC;QAClD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,SAAS,CAAC,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACvF,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC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C;QAC7C,eAAe,IAAI,0CAA0C,UAAU,QAAQ,CAAC;QAEhF,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC;QACtE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACzC,eAAe,IAAI,0CAA0C,QAAQ,QAAQ,CAAC;QAE9E,MAAM,aAAa,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,iBAAiB,CAAC;QAC/E,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QAC/C,eAAe,IAAI,4DAA4D,CAAC;QAEhF,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AApDD,sDAoDC","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 \"path\";\nimport * as fs from \"fs\";\nimport { ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater, SchemaJsonFileLocater } from \"@itwin/ecschema-locaters\";\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport { ECSchemaXmlContext, IModelHost } from \"@itwin/core-backend\";\nimport { ECSchemaToTs } from \"./ecschema2ts\";\n\nconst unitsSchemaKey = new SchemaKey(\"Units\", 1, 0, 0);\nconst formatsSchemaKey = new SchemaKey(\"Formats\", 1, 0, 0);\n\n/**\n * The class is used to parse xml file by using native context. It converts the xml schema\n * to json schema and then, use Typescript side json deserialization to convert it to schema object.\n * @beta\n */\nclass SchemaBackendFileLocater extends SchemaFileLocater implements ISchemaLocater {\n private _nativeContext: ECSchemaXmlContext;\n\n public constructor(nativeContext: ECSchemaXmlContext) {\n super();\n this._nativeContext = nativeContext;\n }\n\n /**\n * Async version of getSchemaSync()\n * @param key The schema key needed to locate the schema in the search path\n * @param matchType The SchemaMatchType\n * @param context The schema context used to parse schema\n */\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n return this.getSchemaSync(key, matchType, context);\n }\n\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n return this.getSchema(schemaKey, matchType, context);\n }\n\n /**\n * Attempt to retrieve a schema with the given schema key by using the configured search path.\n * @param key The schema key needed to locate the schema in the search path\n * @param matchType The SchemaMatchType\n * @param context The schema context used to parse schema\n */\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n const localPath: Set<string> = new Set<string>();\n return this.getSchemaRecursively(key, matchType, context, localPath);\n }\n\n /**\n * Retrieve the schema key from schema Xml file. It looks very similar to `SchemaXmlFileLocater.getSchemaKey(string):SchemaKey` but not quite.\n * Because the schema version in 3.1 and below doesn't contain write version, we will have to manually add\n * 0 as a write version for it before converting to schema key\n * @param data content of the schema Xml file\n */\n public getSchemaKey(data: string): SchemaKey {\n const matches = data.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\n\n // parse name and version\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\n\n const versionStr: string = this.resolveECVersionString(version[1]);\n const key = new SchemaKey(name[1], ECVersion.fromString(versionStr));\n return key;\n }\n\n /**\n * Attempt to retrieve a schema with the given schema key by using the configured search path. The locater will attempt to parse all the references first\n * before parsing the current schema. That way, both the native and ts side context will have all references needed to parse the current schema.\n * In case of cyclic dependency, it will throw error\n * @param key The schema key needed to locate the schema in the search path\n * @param matchType The SchemaMatchType\n * @param context The schema context used to parse schema\n * @param localPath The path of the recursion is following used to detect cyclic dependency\n */\n private getSchemaRecursively(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext, localPath: Set<string>): Schema | undefined {\n // load the schema file\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n if (0 === candidates.length)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n if (undefined === this.fileExistsSync(schemaPath))\n return undefined;\n\n // mark that schema is already visited\n const schemaKeyName = maxCandidate.toString();\n localPath.add(schemaKeyName);\n\n // resolve all the references before beginning parsing the current schema\n const domParser: DOMParser = new DOMParser();\n const schemaXmlDocument: Document = domParser.parseFromString(fs.readFileSync(schemaPath, \"utf8\"));\n const referenceKeys: SchemaKey[] = this.getReferenceSchemaKeys(schemaXmlDocument);\n for (const referenceKey of referenceKeys) {\n const referenceKeyName = referenceKey.toString();\n\n // jump to the next reference if it is not visited. If it is, check if the current schema refers back to other visited schema node\n if (undefined === context.getSchemaSync(referenceKey, matchType)) {\n const referenceSchema = this.getSchemaRecursively(referenceKey, SchemaMatchType.LatestWriteCompatible, context, localPath);\n if (!referenceSchema) {\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,\n `Could not locate reference schema, ${referenceKey.name}.${referenceKey.version.toString()} of schema ${key.name}.${key.version.toString()}`);\n }\n } else if (localPath.has(referenceKeyName)) {\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Schema ${schemaKeyName} and ${referenceKeyName} form cyclic dependency`);\n }\n }\n\n localPath.delete(schemaKeyName);\n\n // it should be safe to parse the current schema because all the references are in the native context and the TS side schema context at this point\n const schemaJson = this._nativeContext.readSchemaFromXmlFile(schemaPath);\n return Schema.fromJsonSync(schemaJson, context);\n }\n\n /**\n * Retrieve the reference schema keys by parsing the current Schema XML DOM\n * @param schemaXmlDocument Current schema XML DOM document\n */\n private getReferenceSchemaKeys(schemaXmlDocument: Document): SchemaKey[] {\n const referenceDocuments = schemaXmlDocument.getElementsByTagName(\"ECSchemaReference\");\n const referenceSchemaKeys: SchemaKey[] = [];\n\n // unfortunately, for-of loop cannot work with HTMLCollectionOf<Element> type here\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < referenceDocuments.length; ++i) {\n const element = referenceDocuments[i];\n const name = this.getRequiredXmlAttribute(element, \"name\",\n \"The schema has an invalid ECSchemaReference attribute. One of the reference is missing the 'name' attribute\");\n let version = this.getRequiredXmlAttribute(element, \"version\",\n \"The schema has an invalid ECSchemaReference attribute. One of the reference is missing the 'version' attribute\");\n version = this.resolveECVersionString(version);\n\n const key = new SchemaKey(name, ECVersion.fromString(version));\n referenceSchemaKeys.push(key);\n }\n\n return referenceSchemaKeys;\n }\n\n /**\n * Retrieve the value of the attribute in the DOM Element\n * @param xmlElement The DOM Element\n * @param attribute The required attribute name of the DOM Element\n * @param errorMessage The error message if there is no attribute found in the DOM Element\n */\n private getRequiredXmlAttribute(xmlElement: Element, attribute: string, errorMessage: string): string {\n const value = xmlElement.getAttribute(attribute);\n if (!value)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, errorMessage);\n\n return value;\n }\n\n /**\n * Attempt to check the ECVersion. If the ECVersion contains only read and minor version, it will add 00 to the write version.\n * Error will be thrown if the version format doesn't contain at least the read and minor version\n * @param version raw ECVersion string retrieved from the Schema XML DOM Element\n */\n private resolveECVersionString(version: string): string {\n // check that version at leasts contain read and write number. If so, add 00 to the minor version if there is none existed in the version\n let versionNumbers: string[] = version.split(\".\");\n if (versionNumbers.length < 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `'version' number does not at least have read and minor number in the given file`);\n else if (versionNumbers.length === 2) {\n versionNumbers.push(\"00\");\n const [readNumber, minorNumber, writeNumber] = versionNumbers;\n versionNumbers = [readNumber, writeNumber, minorNumber];\n }\n\n return versionNumbers.join(\".\");\n }\n}\n\n/**\n * Deserializes ECXml and ECJson schema files.\n */\nclass SchemaDeserializer {\n /**\n * Deserializes the specified ECXml schema file in the given schema context.\n * @param schemaFilePath The path to a valid ECXml schema file.\n * @param schemaContext The schema context in which to deserialize the schema.\n * @param referencePaths Optional paths to search when locating schema references.\n */\n public async deserializeXmlFile(schemaFilePath: string, schemaContext: SchemaContext, referencePaths?: string[]): Promise<Schema> {\n // If the schema file doesn't exist, throw an error\n if (!fs.existsSync(schemaFilePath))\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaFilePath}`);\n\n await IModelHost.startup({ cacheDir: path.join(__dirname, \".cache\") });\n\n // add reference paths to the native context\n if (undefined === referencePaths)\n referencePaths = [];\n referencePaths.push(path.dirname(schemaFilePath));\n\n const nativeContext = new ECSchemaXmlContext();\n const locater = new SchemaBackendFileLocater(nativeContext);\n for (const refPath of referencePaths) {\n locater.addSchemaSearchPath(refPath);\n nativeContext.addSchemaPath(refPath);\n }\n\n // parsing the current xml schema\n let schema: Schema | undefined;\n try {\n const schemaKey = locater.getSchemaKey(fs.readFileSync(schemaFilePath, \"utf8\"));\n\n // Units and Formats have to be added to the ts side context first because the native context will add them automatically to\n // the schema as references even if the schema does not use them\n if (!schemaKey.compareByName(unitsSchemaKey) && !schemaKey.compareByName(formatsSchemaKey)) {\n locater.getSchemaSync(unitsSchemaKey, SchemaMatchType.LatestWriteCompatible, schemaContext);\n locater.getSchemaSync(formatsSchemaKey, SchemaMatchType.LatestWriteCompatible, schemaContext);\n }\n\n schema = locater.getSchemaSync(schemaKey, SchemaMatchType.Exact, schemaContext);\n } finally {\n await IModelHost.shutdown();\n }\n\n return schema!;\n }\n\n /**\n * Deserializes the specified ECJson schema file in the given schema context.\n * @param schemaFilePath The path to a valid ECJson schema file.\n * @param context The schema context in which to deserialize the schema.\n * @param referencePaths Optional paths to search when locating schema references.\n */\n public deserializeJsonFile(schemaFilePath: string, context: SchemaContext, referencePaths?: string[]): Schema {\n // If the schema file doesn't exist, throw an error\n if (!fs.existsSync(schemaFilePath))\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema JSON file at ${schemaFilePath}`);\n\n // add locater to the context\n if (!referencePaths)\n referencePaths = [];\n referencePaths.push(path.dirname(schemaFilePath));\n\n const locater = new SchemaJsonFileLocater();\n locater.addSchemaSearchPaths(referencePaths);\n context.addLocater(locater);\n\n // If the file cannot be parsed, throw an error.\n const schemaString = fs.readFileSync(schemaFilePath, \"utf8\");\n let schemaJson: any;\n try {\n schemaJson = JSON.parse(schemaString);\n } catch (e: any) {\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, e.message);\n }\n return Schema.fromJsonSync(schemaJson, context);\n }\n}\n\n/**\n * Abstract interface to write the result of converting schema file to ts to different output (files, stdout, and so on).\n * Schema file path can be json or xml or both or an obscured file format depending how the concrete class interprets it.\n */\nexport interface ECSchemaToTsFileWriter {\n convertSchemaFile(context: SchemaContext, schemaPath: string, referencePaths?: string[]): Promise<string>;\n}\n\n/**\n * Concrete class to write ecschema2ts result to file\n */\nexport class ECSchemaToTsXmlWriter implements ECSchemaToTsFileWriter {\n private _ecschema2ts: ECSchemaToTs;\n private _deserializer: SchemaDeserializer;\n private _outdir: string;\n\n public constructor(outdir: string) {\n this._ecschema2ts = new ECSchemaToTs();\n this._deserializer = new SchemaDeserializer();\n this._outdir = outdir;\n }\n\n /**\n * Given a valid schema file path, the converted typescript files will be\n * created in the provided output directory. If the output directory does not exist the file will not be\n * created.\n * @param context Schema context used to find reference schema\n * @param schemaPath The full path to the ECSchema xml file\n * @param outdir The path to the directory to write the generated typescript file.\n */\n public async convertSchemaFile(context: SchemaContext, schemaPath: string, referencePaths?: string[]): Promise<string> {\n // check if outdir is correct path\n if (!this._outdir)\n throw new Error(`The out directory ${this._outdir} is invalid.`);\n\n this._outdir = path.normalize(this._outdir) + path.sep;\n if (!fs.existsSync(this._outdir))\n throw new Error(`The out directory ${this._outdir} does not exist.`);\n\n // convert schema to typescript String\n const schema = await this._deserializer.deserializeXmlFile(schemaPath, context, referencePaths);\n const tsString = this._ecschema2ts.convertSchemaToTs(schema);\n const schemaTsString = tsString.schemaTsString;\n const elemTsString = tsString.elemTsString;\n const propsTsString = tsString.propsTsString;\n\n // write to file\n let createdFilesLog: string = \"\";\n\n const schemaFile = `${this._outdir}${schema.schemaKey.name}.ts`;\n fs.writeFileSync(schemaFile, schemaTsString);\n createdFilesLog += `Successfully created typescript file, \"${schemaFile}\".\\r\\n`;\n\n const elemFile = `${this._outdir}${schema.schemaKey.name}Elements.ts`;\n fs.writeFileSync(elemFile, elemTsString);\n createdFilesLog += `Successfully created typescript file, \"${elemFile}\".\\r\\n`;\n\n const propsElemFile = `${this._outdir}${schema.schemaKey.name}ElementProps.ts`;\n fs.writeFileSync(propsElemFile, propsTsString);\n createdFilesLog += `Successfully created typescript file, \"propsElemFile\".\\r\\n`;\n\n return createdFilesLog;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ecschema2ts_io.js","sourceRoot":"","sources":["../../src/ecschema2ts_io.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,6BAA6B;AAC7B,yBAAyB;AACzB,gEAAmK;AACnK,gEAAmG;AACnG,2CAA2C;AAC3C,sDAAqE;AACrE,+CAA6C;AAE7C,MAAM,cAAc,GAAG,IAAI,6BAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACvD,MAAM,gBAAgB,GAAG,IAAI,6BAAS,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3D;;;;GAIG;AACH,MAAM,wBAAyB,SAAQ,qCAAiB;IAC9C,cAAc,CAAqB;IAE3C,YAAmB,aAAiC;QAClD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAA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AChB,IAAI,eAAe,GAAW,EAAE,CAAC;QAEjC,MAAM,UAAU,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC;QAChE,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC7C,eAAe,IAAI,0CAA0C,UAAU,QAAQ,CAAC;QAEhF,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC;QACtE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACzC,eAAe,IAAI,0CAA0C,QAAQ,QAAQ,CAAC;QAE9E,MAAM,aAAa,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,iBAAiB,CAAC;QAC/E,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QAC/C,eAAe,IAAI,4DAA4D,CAAC;QAEhF,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AApDD,sDAoDC","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 \"path\";\nimport * as fs from \"fs\";\nimport { ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater, SchemaJsonFileLocater } from \"@itwin/ecschema-locaters\";\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport { ECSchemaXmlContext, IModelHost } from \"@itwin/core-backend\";\nimport { ECSchemaToTs } from \"./ecschema2ts\";\n\nconst unitsSchemaKey = new SchemaKey(\"Units\", 1, 0, 0);\nconst formatsSchemaKey = new SchemaKey(\"Formats\", 1, 0, 0);\n\n/**\n * The class is used to parse xml file by using native context. It converts the xml schema\n * to json schema and then, use Typescript side json deserialization to convert it to schema object.\n * @beta\n */\nclass SchemaBackendFileLocater extends SchemaFileLocater implements ISchemaLocater {\n private _nativeContext: ECSchemaXmlContext;\n\n public constructor(nativeContext: ECSchemaXmlContext) {\n super();\n this._nativeContext = nativeContext;\n }\n\n /**\n * Async version of getSchemaSync()\n * @param key The schema key needed to locate the schema in the search path\n * @param matchType The SchemaMatchType\n * @param context The schema context used to parse schema\n */\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n return this.getSchemaSync(key, matchType, context);\n }\n\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n return this.getSchema(schemaKey, matchType, context);\n }\n\n /**\n * Attempt to retrieve a schema with the given schema key by using the configured search path.\n * @param key The schema key needed to locate the schema in the search path\n * @param matchType The SchemaMatchType\n * @param context The schema context used to parse schema\n */\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n const localPath: Set<string> = new Set<string>();\n return this.getSchemaRecursively(key, matchType, context, localPath);\n }\n\n /**\n * Retrieve the schema key from schema Xml file. It looks very similar to `SchemaXmlFileLocater.getSchemaKey(string):SchemaKey` but not quite.\n * Because the schema version in 3.1 and below doesn't contain write version, we will have to manually add\n * 0 as a write version for it before converting to schema key\n * @param data content of the schema Xml file\n */\n public getSchemaKey(data: string): SchemaKey {\n const matches = data.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\n\n // parse name and version\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\n\n const versionStr: string = this.resolveECVersionString(version[1]);\n const key = new SchemaKey(name[1], ECVersion.fromString(versionStr));\n return key;\n }\n\n /**\n * Attempt to retrieve a schema with the given schema key by using the configured search path. The locater will attempt to parse all the references first\n * before parsing the current schema. That way, both the native and ts side context will have all references needed to parse the current schema.\n * In case of cyclic dependency, it will throw error\n * @param key The schema key needed to locate the schema in the search path\n * @param matchType The SchemaMatchType\n * @param context The schema context used to parse schema\n * @param localPath The path of the recursion is following used to detect cyclic dependency\n */\n private getSchemaRecursively(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext, localPath: Set<string>): Schema | undefined {\n // load the schema file\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n if (0 === candidates.length)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n if (undefined === this.fileExistsSync(schemaPath))\n return undefined;\n\n // mark that schema is already visited\n const schemaKeyName = maxCandidate.toString();\n localPath.add(schemaKeyName);\n\n // resolve all the references before beginning parsing the current schema\n const domParser: DOMParser = new DOMParser();\n const schemaXmlDocument: Document = domParser.parseFromString(fs.readFileSync(schemaPath, \"utf8\"));\n const referenceKeys: SchemaKey[] = this.getReferenceSchemaKeys(schemaXmlDocument);\n for (const referenceKey of referenceKeys) {\n const referenceKeyName = referenceKey.toString();\n\n // jump to the next reference if it is not visited. If it is, check if the current schema refers back to other visited schema node\n if (undefined === context.getSchemaSync(referenceKey, matchType)) {\n const referenceSchema = this.getSchemaRecursively(referenceKey, SchemaMatchType.LatestWriteCompatible, context, localPath);\n if (!referenceSchema) {\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema,\n `Could not locate reference schema, ${referenceKey.name}.${referenceKey.version.toString()} of schema ${key.name}.${key.version.toString()}`);\n }\n } else if (localPath.has(referenceKeyName)) {\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Schema ${schemaKeyName} and ${referenceKeyName} form cyclic dependency`);\n }\n }\n\n localPath.delete(schemaKeyName);\n\n // it should be safe to parse the current schema because all the references are in the native context and the TS side schema context at this point\n const schemaJson = this._nativeContext.readSchemaFromXmlFile(schemaPath);\n return Schema.fromJsonSync(schemaJson, context);\n }\n\n /**\n * Retrieve the reference schema keys by parsing the current Schema XML DOM\n * @param schemaXmlDocument Current schema XML DOM document\n */\n private getReferenceSchemaKeys(schemaXmlDocument: Document): SchemaKey[] {\n const referenceDocuments = schemaXmlDocument.getElementsByTagName(\"ECSchemaReference\");\n const referenceSchemaKeys: SchemaKey[] = [];\n\n // unfortunately, for-of loop cannot work with HTMLCollectionOf<Element> type here\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < referenceDocuments.length; ++i) {\n const element = referenceDocuments[i];\n const name = this.getRequiredXmlAttribute(element, \"name\",\n \"The schema has an invalid ECSchemaReference attribute. One of the reference is missing the 'name' attribute\");\n let version = this.getRequiredXmlAttribute(element, \"version\",\n \"The schema has an invalid ECSchemaReference attribute. One of the reference is missing the 'version' attribute\");\n version = this.resolveECVersionString(version);\n\n const key = new SchemaKey(name, ECVersion.fromString(version));\n referenceSchemaKeys.push(key);\n }\n\n return referenceSchemaKeys;\n }\n\n /**\n * Retrieve the value of the attribute in the DOM Element\n * @param xmlElement The DOM Element\n * @param attribute The required attribute name of the DOM Element\n * @param errorMessage The error message if there is no attribute found in the DOM Element\n */\n private getRequiredXmlAttribute(xmlElement: Element, attribute: string, errorMessage: string): string {\n const value = xmlElement.getAttribute(attribute);\n if (!value)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, errorMessage);\n\n return value;\n }\n\n /**\n * Attempt to check the ECVersion. If the ECVersion contains only read and minor version, it will add 00 to the write version.\n * Error will be thrown if the version format doesn't contain at least the read and minor version\n * @param version raw ECVersion string retrieved from the Schema XML DOM Element\n */\n private resolveECVersionString(version: string): string {\n // check that version at leasts contain read and write number. If so, add 00 to the minor version if there is none existed in the version\n let versionNumbers: string[] = version.split(\".\");\n if (versionNumbers.length < 2)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `'version' number does not at least have read and minor number in the given file`);\n else if (versionNumbers.length === 2) {\n versionNumbers.push(\"00\");\n const [readNumber, minorNumber, writeNumber] = versionNumbers;\n versionNumbers = [readNumber, writeNumber, minorNumber];\n }\n\n return versionNumbers.join(\".\");\n }\n}\n\n/**\n * Deserializes ECXml and ECJson schema files.\n */\nclass SchemaDeserializer {\n /**\n * Deserializes the specified ECXml schema file in the given schema context.\n * @param schemaFilePath The path to a valid ECXml schema file.\n * @param schemaContext The schema context in which to deserialize the schema.\n * @param referencePaths Optional paths to search when locating schema references.\n */\n public async deserializeXmlFile(schemaFilePath: string, schemaContext: SchemaContext, referencePaths?: string[]): Promise<Schema> {\n // If the schema file doesn't exist, throw an error\n if (!fs.existsSync(schemaFilePath))\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaFilePath}`);\n\n await IModelHost.startup({ cacheDir: path.join(__dirname, \".cache\") });\n\n // add reference paths to the native context\n if (undefined === referencePaths)\n referencePaths = [];\n referencePaths.push(path.dirname(schemaFilePath));\n\n const nativeContext = new ECSchemaXmlContext();\n const locater = new SchemaBackendFileLocater(nativeContext);\n for (const refPath of referencePaths) {\n locater.addSchemaSearchPath(refPath);\n nativeContext.addSchemaPath(refPath);\n }\n\n // parsing the current xml schema\n let schema: Schema | undefined;\n try {\n const schemaKey = locater.getSchemaKey(fs.readFileSync(schemaFilePath, \"utf8\"));\n\n // Units and Formats have to be added to the ts side context first because the native context will add them automatically to\n // the schema as references even if the schema does not use them\n if (!schemaKey.compareByName(unitsSchemaKey) && !schemaKey.compareByName(formatsSchemaKey)) {\n locater.getSchemaSync(unitsSchemaKey, SchemaMatchType.LatestWriteCompatible, schemaContext);\n locater.getSchemaSync(formatsSchemaKey, SchemaMatchType.LatestWriteCompatible, schemaContext);\n }\n\n schema = locater.getSchemaSync(schemaKey, SchemaMatchType.Exact, schemaContext);\n } finally {\n await IModelHost.shutdown();\n }\n\n return schema!;\n }\n\n /**\n * Deserializes the specified ECJson schema file in the given schema context.\n * @param schemaFilePath The path to a valid ECJson schema file.\n * @param context The schema context in which to deserialize the schema.\n * @param referencePaths Optional paths to search when locating schema references.\n */\n public deserializeJsonFile(schemaFilePath: string, context: SchemaContext, referencePaths?: string[]): Schema {\n // If the schema file doesn't exist, throw an error\n if (!fs.existsSync(schemaFilePath))\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema JSON file at ${schemaFilePath}`);\n\n // add locater to the context\n if (!referencePaths)\n referencePaths = [];\n referencePaths.push(path.dirname(schemaFilePath));\n\n const locater = new SchemaJsonFileLocater();\n locater.addSchemaSearchPaths(referencePaths);\n context.addLocater(locater);\n\n // If the file cannot be parsed, throw an error.\n const schemaString = fs.readFileSync(schemaFilePath, \"utf8\");\n let schemaJson: any;\n try {\n schemaJson = JSON.parse(schemaString);\n } catch (e: any) {\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, e.message);\n }\n return Schema.fromJsonSync(schemaJson, context);\n }\n}\n\n/**\n * Abstract interface to write the result of converting schema file to ts to different output (files, stdout, and so on).\n * Schema file path can be json or xml or both or an obscured file format depending how the concrete class interprets it.\n */\nexport interface ECSchemaToTsFileWriter {\n convertSchemaFile(context: SchemaContext, schemaPath: string, referencePaths?: string[]): Promise<string>;\n}\n\n/**\n * Concrete class to write ecschema2ts result to file\n */\nexport class ECSchemaToTsXmlWriter implements ECSchemaToTsFileWriter {\n private _ecschema2ts: ECSchemaToTs;\n private _deserializer: SchemaDeserializer;\n private _outdir: string;\n\n public constructor(outdir: string) {\n this._ecschema2ts = new ECSchemaToTs();\n this._deserializer = new SchemaDeserializer();\n this._outdir = outdir;\n }\n\n /**\n * Given a valid schema file path, the converted typescript files will be\n * created in the provided output directory. If the output directory does not exist the file will not be\n * created.\n * @param context Schema context used to find reference schema\n * @param schemaPath The full path to the ECSchema xml file\n * @param outdir The path to the directory to write the generated typescript file.\n */\n public async convertSchemaFile(context: SchemaContext, schemaPath: string, referencePaths?: string[]): Promise<string> {\n // check if outdir is correct path\n if (!this._outdir)\n throw new Error(`The out directory ${this._outdir} is invalid.`);\n\n this._outdir = path.normalize(this._outdir) + path.sep;\n if (!fs.existsSync(this._outdir))\n throw new Error(`The out directory ${this._outdir} does not exist.`);\n\n // convert schema to typescript String\n const schema = await this._deserializer.deserializeXmlFile(schemaPath, context, referencePaths);\n const tsString = this._ecschema2ts.convertSchemaToTs(schema);\n const schemaTsString = tsString.schemaTsString;\n const elemTsString = tsString.elemTsString;\n const propsTsString = tsString.propsTsString;\n\n // write to file\n let createdFilesLog: string = \"\";\n\n const schemaFile = `${this._outdir}${schema.schemaKey.name}.ts`;\n fs.writeFileSync(schemaFile, schemaTsString);\n createdFilesLog += `Successfully created typescript file, \"${schemaFile}\".\\r\\n`;\n\n const elemFile = `${this._outdir}${schema.schemaKey.name}Elements.ts`;\n fs.writeFileSync(elemFile, elemTsString);\n createdFilesLog += `Successfully created typescript file, \"${elemFile}\".\\r\\n`;\n\n const propsElemFile = `${this._outdir}${schema.schemaKey.name}ElementProps.ts`;\n fs.writeFileSync(propsElemFile, propsTsString);\n createdFilesLog += `Successfully created typescript file, \"propsElemFile\".\\r\\n`;\n\n return createdFilesLog;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@itwin/ecschema2ts",
|
|
3
3
|
"description": "Command line tools that takes an ECSchema xml file and outputs a typescript module",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "5.0.
|
|
5
|
+
"version": "5.0.1",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ecschema2ts": "./bin/index.js"
|
|
8
8
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"rimraf": "^6.0.1",
|
|
40
40
|
"source-map-support": "^0.5.6",
|
|
41
41
|
"typescript": "~5.6.2",
|
|
42
|
-
"@itwin/build-tools": "5.0.
|
|
42
|
+
"@itwin/build-tools": "5.0.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@xmldom/xmldom": "~0.8.10",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"chalk": "^3.0.0",
|
|
48
48
|
"commander": "^2.14.1",
|
|
49
49
|
"fs-extra": "^8.1.0",
|
|
50
|
-
"@itwin/
|
|
51
|
-
"@itwin/
|
|
52
|
-
"@itwin/
|
|
53
|
-
"@itwin/
|
|
54
|
-
"@itwin/core-geometry": "5.0.
|
|
55
|
-
"@itwin/core-backend": "5.0.
|
|
50
|
+
"@itwin/ecschema-locaters": "5.0.1",
|
|
51
|
+
"@itwin/core-bentley": "5.0.1",
|
|
52
|
+
"@itwin/core-common": "5.0.1",
|
|
53
|
+
"@itwin/ecschema-metadata": "5.0.1",
|
|
54
|
+
"@itwin/core-geometry": "5.0.1",
|
|
55
|
+
"@itwin/core-backend": "5.0.1"
|
|
56
56
|
},
|
|
57
57
|
"nyc": {
|
|
58
58
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|