@itwin/ecschema2ts 5.4.0-dev.7 → 5.5.0-dev.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.js","sourceRoot":"","sources":["../../src/ecschema2ts.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gEAEkC;AAOlC,MAAM,uBAAuB,GAAW,+BAA+B,CAAC;AACxE,MAAM,kBAAkB,GAAW,iBAAiB,CAAC;AACrD,MAAM,gBAAgB,GAAyC;IAC7D,gBAAgB,EAAE;QAChB,UAAU,EAAE,oBAAoB;QAChC,oBAAoB,EAAE,kBAAkB;KACzC;IACD,iBAAiB,EAAE;QACjB,UAAU,EAAE,qBAAqB;QACjC,oBAAoB,EAAE,mBAAmB;KAC1C;IACD,cAAc,EAAE;QACd,UAAU,EAAE,sBAAsB;QAClC,oBAAoB,EAAE,gBAAgB;KACvC;IACD,eAAe,EAAE;QACf,UAAU,EAAE,qBAAqB;QACjC,oBAAoB,EAAE,iBAAiB;KACxC;CACF,CAAC;AAEF;;GAEG;AACH,MAAa,YAAY;IACf,qBAAqB,CAAc;IACnC,qCAAqC,CAAsB;IAC3D,OAAO,CAAU;IACjB,eAAe,CAAe;IAEtC;QACE,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAE1B,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/C,IAAI,CAAC,qCAAqC,GAAG,IAAI,GAAG,EAAkB,CAAC;QACvE,KAAK,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;YACnC,IAAI,gBAAgB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzC,MAAM,UAAU,GAAW,gBAAgB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC;gBAC5D,MAAM,cAAc,GAAW,gBAAgB,CAAC,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AO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAllBD,oCAklBC","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 {\n ECClass, ECClassModifier, EntityClass, Enumeration, EnumerationProperty, Mixin, PrimitiveProperty, PrimitiveType, Schema, SchemaItem, SchemaItemType, StructClass, StructProperty,\n} from \"@itwin/ecschema-metadata\";\n\ninterface TsBentleyModule {\n moduleName: string;\n resolvedConflictName: string;\n}\n\nconst customHandledPropertyCA: string = \"BisCore.CustomHandledProperty\";\nconst elementECClassName: string = \"BisCore.Element\";\nconst tsBentleyModules: { [index: string]: TsBentleyModule } = {\n tsIModelJsCommon: {\n moduleName: \"@itwin/core-common\",\n resolvedConflictName: \"BeIModelJsCommon\",\n },\n tsIModelJsBackend: {\n moduleName: \"@itwin/core-backend\",\n resolvedConflictName: \"BeIModelJsBackend\",\n },\n tsGeometryCore: {\n moduleName: \"@itwin/core-geometry\",\n resolvedConflictName: \"BeGeometryCore\",\n },\n tsBentleyJsCore: {\n moduleName: \"@itwin/core-bentley\",\n resolvedConflictName: \"BeBentleyJsCore\",\n },\n};\n\n/**\n * @beta\n */\nexport class ECSchemaToTs {\n private _tsBentleyModuleNames: Set<string>;\n private _tsBentleyModuleResolvedConflictNames: Map<string, string>;\n private _schema?: Schema;\n private _schemaItemList: SchemaItem[];\n\n public constructor() {\n this._schema = undefined;\n this._schemaItemList = [];\n\n this._tsBentleyModuleNames = new Set<string>();\n this._tsBentleyModuleResolvedConflictNames = new Map<string, string>();\n for (const key in tsBentleyModules) {\n if (tsBentleyModules.hasOwnProperty(key)) {\n const moduleName: string = tsBentleyModules[key].moduleName;\n const resolvedPrefix: string = tsBentleyModules[key].resolvedConflictName;\n this._tsBentleyModuleNames.add(moduleName);\n this._tsBentleyModuleResolvedConflictNames.set(moduleName, resolvedPrefix);\n }\n }\n }\n\n /**\n * Given the schema, the function will converted it to typescript strings\n * @param schema The schema to be converted to typescript strings\n */\n public convertSchemaToTs(schema: Schema): { schemaTsString: string, elemTsString: string, propsTsString: string } {\n // convert schema to typescript String\n this._schema = schema;\n this.dependencyToFront();\n const schemaTsString = this.convertSchemaToTsClass();\n const elemTsString = this.convertElemToTsClasses();\n const propsTsString = this.convertPropsToTsInterfaces();\n\n return { schemaTsString, elemTsString, propsTsString };\n }\n\n /**\n * The function will push all the base classes to be the first ones in the schema item list.\n * For example, if class A extends base class B and base class C, B and C will be on the first of the list and then A at the end.\n * If B extends C, then B will be first and C will be next in the list and then A at the end.\n * If B and C does not depend on each other, the order of B and C will not be important.\n * The arrangement is to make sure that base class will be converted first and then, derived classes and so on\n */\n private dependencyToFront(): void {\n const uniqueItemName: Set<string> = new Set<string>();\n const schemaItemsList: SchemaItem[] = [];\n for (const schemaItem of this._schema!.getItems()) {\n // base class to the item list first;\n switch (schemaItem.schemaItemType) {\n case SchemaItemType.StructClass:\n case SchemaItemType.Mixin:\n case SchemaItemType.EntityClass:\n const ecClass = schemaItem as ECClass;\n const baseList = this.getAllBaseClasses(ecClass);\n for (let i = baseList.length - 1; i >= 0; --i) {\n const base = baseList[i];\n if (base.schema.schemaKey.compareByName(this._schema!.schemaKey) && !uniqueItemName.has(base.name)) {\n schemaItemsList.push(baseList[i]);\n uniqueItemName.add(base.name);\n }\n }\n break;\n default:\n break;\n }\n\n if (!uniqueItemName.has(schemaItem.name)) {\n uniqueItemName.add(schemaItem.name);\n schemaItemsList.push(schemaItem);\n }\n }\n\n this._schemaItemList = schemaItemsList;\n }\n\n /**\n * The function converts the schema meta data to typescript Schema class\n */\n private convertSchemaToTsClass(): string {\n const schemaName = this._schema!.schemaKey.name;\n let outputString: string = \"\";\n\n // import modules\n outputString += \"import { ClassRegistry, Schema, Schemas } from \\\"@itwin/core-backend\\\";\\n\";\n outputString += `import * as elementsModule from \"./${schemaName}Elements\";\\n\\n`;\n\n // create new schema class\n outputString += `export class ${schemaName} extends Schema {\\n`;\n\n // schemaName() method\n outputString += ` public static get schemaName(): string { return \"${schemaName}\"; }\\n\\n`;\n\n // registerSchema method\n outputString += \" public static registerSchema() {\\n\";\n outputString += ` if (!Schemas.getRegisteredSchema(${schemaName}.name))\\n`;\n outputString += ` Schemas.registerSchema(${schemaName});\\n`;\n outputString += \" }\\n\\n\";\n\n // constructor\n outputString += \" protected constructor() {\\n\";\n outputString += \" super();\\n\";\n outputString += ` ClassRegistry.registerModule(elementsModule, ${schemaName});\\n`;\n outputString += \" }\\n\";\n\n outputString += \"}\\n\\n\";\n\n return outputString;\n }\n\n /**\n * The function converts the schema item to respective typescript classes\n */\n private convertElemToTsClasses(): string {\n const classNameToModule: Map<string, string> = new Map<string, string>();\n let classTs: string = \"\";\n for (const schemaItem of this._schemaItemList) {\n switch (schemaItem.schemaItemType) {\n case SchemaItemType.EntityClass:\n classTs += this.convertEntityToTs(schemaItem as EntityClass, classNameToModule);\n break;\n case SchemaItemType.Enumeration:\n classTs += this.convertEnumToTs(schemaItem as Enumeration);\n break;\n default:\n continue;\n }\n }\n\n let outputString: string = this.convertImportToTsImport(classNameToModule);\n outputString += `\\n${classTs}`;\n return outputString;\n }\n\n /**\n * The function converts the schema item properties to respective typescript props interfaces\n */\n private convertPropsToTsInterfaces(): string {\n const classNameToModule: Map<string, string> = new Map<string, string>();\n let interfacesTs: string = \"\";\n for (const schemaItem of this._schemaItemList) {\n switch (schemaItem.schemaItemType) {\n case SchemaItemType.EntityClass:\n case SchemaItemType.Mixin:\n case SchemaItemType.StructClass:\n interfacesTs += this.convertECClassPropsToTsInterface(schemaItem as (Mixin | StructClass | EntityClass), classNameToModule);\n break;\n default:\n continue;\n }\n }\n\n let outputString: string = this.convertImportToTsImport(classNameToModule);\n outputString += `\\n${interfacesTs}`;\n return outputString;\n }\n\n /**\n * Convert mixin or struct class or entity class to respective typescript interface\n * @param ecClass Schema mixin or struct or entity to be converted typescript interface\n * @param classNameToModule Typescrip modules to be updated after the conversion\n */\n private convertECClassPropsToTsInterface(ecClass: Mixin | StructClass | EntityClass, classNameToModule: Map<string, string>): string {\n let interfacesTs: string = \"\";\n\n // no interface props for BisCore Element\n if (ecClass.fullName === elementECClassName)\n return interfacesTs;\n\n // only generate props interface for entity if the class has properties\n if (ecClass.schemaItemType === SchemaItemType.EntityClass && !ecClass.hasLocalProperties)\n return interfacesTs;\n\n // convert description to typescript comment only for mixin or struct\n if (ecClass.schemaItemType !== SchemaItemType.EntityClass && ecClass.description)\n interfacesTs += `${this.convertDescriptionToTsComment(ecClass.description)}\\n`;\n\n // build interface for props in ecClass\n interfacesTs += `export interface ${ecClass.name}`;\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\n interfacesTs += \"Props\";\n\n // Extend it with base ecClass Props interface if there is any\n const baseClasses = this.getBaseClassWithProps(ecClass);\n if (baseClasses.length > 0) {\n interfacesTs += \" extends \";\n\n let separator = \"\";\n for (const base of baseClasses) {\n interfacesTs += separator + this.addImportBasePropsClass(classNameToModule, base, ecClass);\n separator = \", \";\n }\n } else if (ecClass.schemaItemType === SchemaItemType.EntityClass)\n interfacesTs += ` extends ${this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsCommon.moduleName, \"EntityProps\")}`;\n\n // build props for ecClass\n interfacesTs += \" {\";\n const propertiesTs = this.convertPropsToTsVars(ecClass, classNameToModule);\n for (const varDeclarationLine of propertiesTs)\n interfacesTs += `\\n ${varDeclarationLine}`;\n interfacesTs += \"\\n}\\n\\n\";\n\n return interfacesTs;\n }\n\n /**\n * Convert schema enumeration to typescript enumeration\n * @param ecEnum Schema enumeration to be converted to typescript enumeration\n */\n private convertEnumToTs(ecEnum: Enumeration): string {\n let outputString: string = \"\";\n if (ecEnum.description)\n outputString += `${this.convertDescriptionToTsComment(ecEnum.description)}\\n`;\n\n outputString += `export const enum ${ecEnum.name} {\\n`;\n for (const ecEnumerator of ecEnum.enumerators) {\n outputString += ` ${ecEnumerator.label}`;\n if (ecEnum.isInt)\n outputString += ` = ${ecEnumerator.value}`;\n else if (ecEnum.isString)\n outputString += ` = \"${ecEnumerator.value}\"`;\n outputString += \",\\n\";\n }\n\n outputString += \"}\\n\\n\";\n return outputString;\n }\n\n /**\n * Convert schema entity to typescript entity class. The typescript class will implement respective props\n * typescript interface if the schema entity class has properties\n * @param ecClass Schema class to be converted to typescript class\n * @param classNameToModule Typescrip modules to be updated after the conversion\n */\n private convertEntityToTs(ecClass: EntityClass, classNameToModule: Map<string, string>): string {\n let outputString: string = \"\";\n if (ecClass.description)\n outputString += `${this.convertDescriptionToTsComment(ecClass.description)}\\n`;\n\n let modifier: string = \"\";\n if (ecClass.modifier === ECClassModifier.Abstract)\n modifier = \"abstract \";\n outputString += `export ${modifier}class ${ecClass.name} extends `;\n\n // extend base class if there is any. Default will be Entity class defined in @itwin/core-backend\n const base = ecClass.getBaseClassSync();\n if (base)\n outputString += this.addImportBaseClass(classNameToModule, base, ecClass);\n else\n outputString += this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsBackend.moduleName, \"Entity\");\n\n // determine prop type to pass in the constructor\n let propsBaseTsType: string;\n const propsBase = this.getBaseClassWithProps(ecClass);\n if (ecClass.fullName !== elementECClassName && ecClass.hasLocalProperties) {\n const moduleName: string = `${this._schema!.schemaKey.name}ElementProps`;\n propsBaseTsType = this.addImportClass(classNameToModule, moduleName, `${ecClass.name}Props`);\n } else if (propsBase.length > 0)\n propsBaseTsType = this.addImportBasePropsClass(classNameToModule, propsBase[0], ecClass);\n else\n propsBaseTsType = this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsCommon.moduleName, \"EntityProps\");\n\n // implement the ecClass props if it has properties\n if (`${ecClass.name}Props` === propsBaseTsType)\n outputString += ` implements ${propsBaseTsType}`;\n\n // write constructor and className function for class\n const iModelDbTsType: string = this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsBackend.moduleName, \"IModelDb\");\n\n outputString += \" {\\n\";\n outputString += ` public static get className(): string { return \"${ecClass.name}\"; }\\n\\n`;\n outputString += ` public constructor (props: ${propsBaseTsType}, iModel: ${iModelDbTsType}) {\\n`;\n outputString += \" super(props, iModel);\\n\";\n outputString += \" }\\n\";\n outputString += \"}\\n\\n\";\n\n return outputString;\n }\n\n /**\n * Convert class properties to typescript member declaration\n * @param ecClass The schema class that has the properties to be converted to typescript member variables\n * @param classNameToModule Typescrip modules to be updated after the conversion\n */\n private convertPropsToTsVars(ecClass: ECClass, classNameToModule: Map<string, string>): string[] {\n if (!ecClass.hasLocalProperties)\n return [];\n\n const outputStrings: string[] = [];\n for (const ecProperty of ecClass.getPropertiesSync(true)) {\n // not generate ts variable declaration for property that has CustomHandledProperty ca\n if (ecProperty.customAttributes && ecProperty.customAttributes.has(customHandledPropertyCA))\n continue;\n\n let varDeclarationLine: string = `${this.lowerPropertyName(ecProperty.name)}?: `;\n if (ecProperty.isPrimitive()) {\n // determine Ts type of the primitive\n let typeTs: string = \"\";\n if (ecProperty.extendedTypeName)\n typeTs = this.convertExtendedTypeNameToTsType(ecProperty.extendedTypeName, classNameToModule);\n else if (ecProperty.isEnumeration()) {\n const ecEnumProperty = ecProperty as EnumerationProperty;\n const ecEnum = ecEnumProperty.enumeration!;\n typeTs = this.addImportClass(classNameToModule, `${ecEnum.schemaKey.name}Elements`, ecEnum.name);\n } else {\n const ecPrimitiveProperty = ecProperty as PrimitiveProperty;\n typeTs = this.convertPrimitiveTypeToTsType(ecPrimitiveProperty.primitiveType, classNameToModule);\n }\n\n varDeclarationLine += typeTs;\n } else if (ecProperty.isStruct()) {\n // import struct class if it is in different schema\n const ecStructProperty = ecProperty as StructProperty;\n const structClass = ecStructProperty.structClass;\n if (!structClass.schema.schemaKey.compareByName(ecClass.schema.schemaKey))\n varDeclarationLine += this.addImportClass(classNameToModule, `${structClass.schema.schemaKey.name}ElementProps`, structClass.name);\n else\n varDeclarationLine += structClass.name;\n\n } else if (ecProperty.isNavigation())\n varDeclarationLine += this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsCommon.moduleName, \"RelatedElementProps\");\n\n if (ecProperty.isArray())\n varDeclarationLine += \"[]\";\n varDeclarationLine += \";\";\n\n outputStrings.push(varDeclarationLine);\n }\n\n return outputStrings;\n }\n\n /**\n * Convert schema extended type to typescript type\n * @param typeName Schema extended type to be converted to typescript type\n * @param classNameToModule Typescrip modules to be updated after the conversion\n */\n private convertExtendedTypeNameToTsType(typeName: string, classNameToModule: Map<string, string>): string {\n switch (typeName) {\n case \"Json\":\n return \"any\";\n case \"BeGuid\":\n return this.addImportClass(classNameToModule, tsBentleyModules.tsBentleyJsCore.moduleName, \"GuidString\");\n default:\n return \"any\";\n }\n }\n\n /**\n * Convert schema primitive type to typescript type\n * @param type Schema primitive type to be converted to typescript type\n * @param classNameToModule Typescrip modules to be updated after the conversion\n */\n private convertPrimitiveTypeToTsType(type: PrimitiveType, classNameToModule: Map<string, string>) {\n switch (type) {\n case PrimitiveType.Binary:\n return \"any\";\n case PrimitiveType.Boolean:\n return \"boolean\";\n case PrimitiveType.DateTime:\n return \"Date\";\n case PrimitiveType.Double:\n return \"number\";\n case PrimitiveType.Integer:\n return \"number\";\n case PrimitiveType.Long:\n // eslint-disable-next-line no-console\n console.log(\"Primitive type Long is not currently supported during conversion. It will be treated as type 'any'\");\n return \"any\";\n case PrimitiveType.String:\n return \"string\";\n case PrimitiveType.Point2d:\n return this.addImportClass(classNameToModule, tsBentleyModules.tsGeometryCore.moduleName, \"Point2d\");\n case PrimitiveType.Point3d:\n return this.addImportClass(classNameToModule, tsBentleyModules.tsGeometryCore.moduleName, \"Point3d\");\n case PrimitiveType.IGeometry:\n // eslint-disable-next-line no-console\n console.log(\"Primitive type IGeometry is not currently supported during conversion. It will be treated as type 'any'\");\n return \"any\";\n default:\n // eslint-disable-next-line no-console\n console.log(\"Unknown primitive type during conversion. It will be treated as type 'any'\");\n return \"any\";\n }\n }\n\n /**\n * Convert schema description to typescript comment\n * @param description Schema description to be converted to typescript comment\n */\n private convertDescriptionToTsComment(description: string) {\n let outputString: string = \"/**\\n\";\n\n let wordCount: number = 0;\n let begin: number = 0;\n let spaceBegin: number = 0;\n let spaceIdx: number = description.indexOf(\" \", spaceBegin);\n while (spaceIdx !== -1) {\n // new line for every 20 words\n ++wordCount;\n if (wordCount === 20) {\n wordCount = 0;\n outputString += ` * ${description.substring(begin, spaceIdx)}\\n`;\n begin = spaceIdx + 1;\n }\n\n spaceBegin = spaceIdx + 1;\n while (description[spaceBegin] === \" \")\n ++spaceBegin;\n\n spaceIdx = description.indexOf(\" \", spaceBegin);\n }\n\n // append the last word\n outputString += ` * ${description.substring(begin)}\\n`;\n\n outputString += \" */\";\n return outputString;\n }\n\n /**\n * Convert all modules needed for the converted schema types to typescript import statements\n * @param classNameToModule Modules to be converted to typescript imports statement\n */\n private convertImportToTsImport(classNameToModule: Map<string, string>): string {\n const moduleToTsTypes: Map<string, Set<string>> = new Map<string, Set<string>>();\n classNameToModule.forEach((moduleNames: string, className: string) => {\n if (!moduleToTsTypes.has(moduleNames))\n moduleToTsTypes.set(moduleNames, new Set<string>());\n\n moduleToTsTypes.get(moduleNames)!.add(className);\n });\n\n let outputString: string = \"\";\n moduleToTsTypes.forEach((classNames: Set<string>, moduleName: string) => {\n if (!this._tsBentleyModuleNames.has(moduleName))\n moduleName = `./${moduleName}`;\n\n outputString += \"import { \";\n let separator = \"\";\n for (const className of classNames) {\n outputString += separator + className;\n separator = \", \";\n }\n outputString += ` } from \"${moduleName}\";\\n`;\n });\n\n return outputString;\n }\n\n /**\n * Traverse the inheritance tree to retrieve first base classes that have properties\n * @param ecClass Schema class to be traverse\n */\n private getBaseClassWithProps(ecClass: ECClass): ECClass[] {\n const res: ECClass[] = [];\n const visited: Set<string> = new Set<string>();\n visited.add(ecClass.fullName);\n this.traverseBaseClass(ecClass, visited, (base: ECClass) => {\n if (base.hasLocalProperties) {\n res.push(base);\n return false;\n }\n\n return true;\n });\n\n return res;\n }\n\n /**\n * Traverse the inheritance tree to retrieve base classes of a schema class\n * @param ecClass Schema class to be traverse\n */\n private getAllBaseClasses(ecClass: ECClass): ECClass[] {\n const res: ECClass[] = [];\n const visited: Set<string> = new Set<string>();\n visited.add(ecClass.fullName);\n this.traverseBaseClass(ecClass, visited, (base: ECClass) => {\n res.push(base);\n return true;\n });\n\n return res;\n }\n\n /**\n * Traverse the inheritance tree horizontally and vertically of a schema class\n * @param ecClass Schema class to be traverse\n * @param visited Set of classes that are already visited\n * @param shouldTraverseDown Lambda to determine if it should traverse more vertically\n */\n private traverseBaseClass(ecClass: ECClass, visited: Set<string>, shouldTraverseDown: (base: ECClass) => boolean): void {\n const base = ecClass.getBaseClassSync();\n if (base === undefined || visited.has(base.fullName))\n return;\n\n const baseList: ECClass[] = [base];\n if (ecClass.schemaItemType === SchemaItemType.EntityClass) {\n const entity = ecClass as EntityClass;\n for (const mixin of entity.getMixinsSync())\n baseList.push(mixin);\n }\n\n for (const eachBase of baseList) {\n visited.add(eachBase.fullName);\n if (shouldTraverseDown(eachBase))\n this.traverseBaseClass(eachBase, visited, shouldTraverseDown);\n }\n }\n\n /**\n * Add required typescript class that is to be imported from a required module during Schema conversion to typescript. If there is naming conflict\n * it will resolve it by appending prefix name with class name, for example: import { element as BisCoreElement } from \"BisCoreElement\";\n * @param classNameToModule Typescript modules that is needed for the conversion. It maps typescript class with the required modules\n * @param refModule Typescript module that the typescrip class comes from\n * @param className Required Typescript class for the conversion\n */\n private addImportClass(classNameToModule: Map<string, string>, refModule: string, className: string): string {\n if (!classNameToModule.has(className)) {\n classNameToModule.set(className, refModule);\n return className;\n }\n\n if (classNameToModule.get(className) === refModule)\n return className;\n\n let resolvedPrefix: string = refModule;\n if (this._tsBentleyModuleResolvedConflictNames.has(refModule))\n resolvedPrefix = this._tsBentleyModuleResolvedConflictNames.get(refModule)!;\n\n const renameClassName = `${className} as ${resolvedPrefix}${className}`;\n if (!classNameToModule.has(renameClassName)) {\n classNameToModule.set(renameClassName, refModule);\n }\n\n return resolvedPrefix + className;\n }\n\n /**\n * Add appropriate typescript props interface to the classNameToModule and return the corresponding typescript base props interface\n * @param classNameToModule Typescript modules that is needed for the conversion. It maps typescript class with the required modules\n * @param baseECClass Base class of ecClass that has properties. Its name will be used to derived typescript base props interface\n * @param ecClass ECClass to be converted to Typescript\n */\n private addImportBasePropsClass(classNameToModule: Map<string, string>, baseECClass: ECClass, ecClass: ECClass): string {\n let baseName: string = baseECClass.name;\n if (baseECClass.schemaItemType === SchemaItemType.EntityClass)\n baseName += \"Props\";\n\n // find external module to import\n let externalModule: string = \"\";\n const shouldImportJsCommon = (baseECClass.fullName === elementECClassName) ||\n (baseECClass.schema.schemaKey.name === \"BisCore\" && ecClass.schema.schemaKey.name !== \"BisCore\");\n if (shouldImportJsCommon)\n externalModule = tsBentleyModules.tsIModelJsCommon.moduleName;\n else if (!baseECClass.schema.schemaKey.compareByName(ecClass.schema.schemaKey))\n externalModule = `${baseECClass.schema.schemaKey.name}ElementProps`;\n\n if (externalModule.length !== 0)\n baseName = this.addImportClass(classNameToModule, externalModule, baseName);\n\n return baseName;\n }\n\n /**\n * Add appropriate typescript base class to the classNameToModule and return the corresponding typescript base class\n * @param classNameToModule Typescript modules that is needed for the conversion. It maps typescript class with the required modules\n * @param baseECClass Base class of ecClass\n * @param ecClass ECClass to be converted to Typescript\n */\n private addImportBaseClass(classNameToModule: Map<string, string>, baseECClass: ECClass, ecClass: ECClass): string {\n let baseName: string = baseECClass.name;\n\n // find external module to import for base class\n let externalModule: string = \"\";\n if (baseECClass.schema.schemaKey.name === \"BisCore\" && ecClass.schema.schemaKey.name !== \"BisCore\")\n externalModule = tsBentleyModules.tsIModelJsBackend.moduleName;\n else if (!baseECClass.schema.schemaKey.compareByName(ecClass.schema.schemaKey))\n externalModule = `${baseECClass.schema.schemaKey.name}Elements`;\n\n if (externalModule.length !== 0)\n baseName = this.addImportClass(classNameToModule, externalModule, baseName);\n\n return baseName;\n }\n\n /**\n * Lower the first character of the property name\n * @param propName Property name\n */\n private lowerPropertyName(propName: string): string {\n return propName.charAt(0).toLowerCase() + propName.slice(1);\n }\n}\n"]}
1
+ {"version":3,"file":"ecschema2ts.js","sourceRoot":"","sources":["../../src/ecschema2ts.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gEAEkC;AAOlC,MAAM,uBAAuB,GAAW,+BAA+B,CAAC;AACxE,MAAM,kBAAkB,GAAW,iBAAiB,CAAC;AACrD,MAAM,gBAAgB,GAAyC;IAC7D,gBAAgB,EAAE;QAChB,UAAU,EAAE,oBAAoB;QAChC,oBAAoB,EAAE,kBAAkB;KACzC;IACD,iBAAiB,EAAE;QACjB,UAAU,EAAE,qBAAqB;QACjC,oBAAoB,EAAE,mBAAmB;KAC1C;IACD,cAAc,EAAE;QACd,UAAU,EAAE,sBAAsB;QAClC,oBAAoB,EAAE,gBAAgB;KACvC;IACD,eAAe,EAAE;QACf,UAAU,EAAE,qBAAqB;QACjC,oBAAoB,EAAE,iBAAiB;KACxC;CACF,CAAC;AAEF;;GAEG;AACH,MAAa,YAAY;IACf,qBAAqB,CAAc;IACnC,qCAAqC,CAAsB;IAC3D,OAAO,CAAU;IACjB,eAAe,CAAe;IAEtC;QACE,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAE1B,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/C,IAAI,CAAC,qCAAqC,GAAG,IAAI,GAAG,EAAkB,CAAC;QACvE,KAAK,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;YACnC,IAAI,gBAAgB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzC,MAAM,UAAU,GAAW,gBAAgB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC;gBAC5D,MAAM,cAAc,GAAW,gBAAgB,CAAC,GAAG,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AQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAllBD,oCAklBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport {\r\n ECClass, ECClassModifier, EntityClass, Enumeration, EnumerationProperty, Mixin, PrimitiveProperty, PrimitiveType, Schema, SchemaItem, SchemaItemType, StructClass, StructProperty,\r\n} from \"@itwin/ecschema-metadata\";\r\n\r\ninterface TsBentleyModule {\r\n moduleName: string;\r\n resolvedConflictName: string;\r\n}\r\n\r\nconst customHandledPropertyCA: string = \"BisCore.CustomHandledProperty\";\r\nconst elementECClassName: string = \"BisCore.Element\";\r\nconst tsBentleyModules: { [index: string]: TsBentleyModule } = {\r\n tsIModelJsCommon: {\r\n moduleName: \"@itwin/core-common\",\r\n resolvedConflictName: \"BeIModelJsCommon\",\r\n },\r\n tsIModelJsBackend: {\r\n moduleName: \"@itwin/core-backend\",\r\n resolvedConflictName: \"BeIModelJsBackend\",\r\n },\r\n tsGeometryCore: {\r\n moduleName: \"@itwin/core-geometry\",\r\n resolvedConflictName: \"BeGeometryCore\",\r\n },\r\n tsBentleyJsCore: {\r\n moduleName: \"@itwin/core-bentley\",\r\n resolvedConflictName: \"BeBentleyJsCore\",\r\n },\r\n};\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class ECSchemaToTs {\r\n private _tsBentleyModuleNames: Set<string>;\r\n private _tsBentleyModuleResolvedConflictNames: Map<string, string>;\r\n private _schema?: Schema;\r\n private _schemaItemList: SchemaItem[];\r\n\r\n public constructor() {\r\n this._schema = undefined;\r\n this._schemaItemList = [];\r\n\r\n this._tsBentleyModuleNames = new Set<string>();\r\n this._tsBentleyModuleResolvedConflictNames = new Map<string, string>();\r\n for (const key in tsBentleyModules) {\r\n if (tsBentleyModules.hasOwnProperty(key)) {\r\n const moduleName: string = tsBentleyModules[key].moduleName;\r\n const resolvedPrefix: string = tsBentleyModules[key].resolvedConflictName;\r\n this._tsBentleyModuleNames.add(moduleName);\r\n this._tsBentleyModuleResolvedConflictNames.set(moduleName, resolvedPrefix);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Given the schema, the function will converted it to typescript strings\r\n * @param schema The schema to be converted to typescript strings\r\n */\r\n public convertSchemaToTs(schema: Schema): { schemaTsString: string, elemTsString: string, propsTsString: string } {\r\n // convert schema to typescript String\r\n this._schema = schema;\r\n this.dependencyToFront();\r\n const schemaTsString = this.convertSchemaToTsClass();\r\n const elemTsString = this.convertElemToTsClasses();\r\n const propsTsString = this.convertPropsToTsInterfaces();\r\n\r\n return { schemaTsString, elemTsString, propsTsString };\r\n }\r\n\r\n /**\r\n * The function will push all the base classes to be the first ones in the schema item list.\r\n * For example, if class A extends base class B and base class C, B and C will be on the first of the list and then A at the end.\r\n * If B extends C, then B will be first and C will be next in the list and then A at the end.\r\n * If B and C does not depend on each other, the order of B and C will not be important.\r\n * The arrangement is to make sure that base class will be converted first and then, derived classes and so on\r\n */\r\n private dependencyToFront(): void {\r\n const uniqueItemName: Set<string> = new Set<string>();\r\n const schemaItemsList: SchemaItem[] = [];\r\n for (const schemaItem of this._schema!.getItems()) {\r\n // base class to the item list first;\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.StructClass:\r\n case SchemaItemType.Mixin:\r\n case SchemaItemType.EntityClass:\r\n const ecClass = schemaItem as ECClass;\r\n const baseList = this.getAllBaseClasses(ecClass);\r\n for (let i = baseList.length - 1; i >= 0; --i) {\r\n const base = baseList[i];\r\n if (base.schema.schemaKey.compareByName(this._schema!.schemaKey) && !uniqueItemName.has(base.name)) {\r\n schemaItemsList.push(baseList[i]);\r\n uniqueItemName.add(base.name);\r\n }\r\n }\r\n break;\r\n default:\r\n break;\r\n }\r\n\r\n if (!uniqueItemName.has(schemaItem.name)) {\r\n uniqueItemName.add(schemaItem.name);\r\n schemaItemsList.push(schemaItem);\r\n }\r\n }\r\n\r\n this._schemaItemList = schemaItemsList;\r\n }\r\n\r\n /**\r\n * The function converts the schema meta data to typescript Schema class\r\n */\r\n private convertSchemaToTsClass(): string {\r\n const schemaName = this._schema!.schemaKey.name;\r\n let outputString: string = \"\";\r\n\r\n // import modules\r\n outputString += \"import { ClassRegistry, Schema, Schemas } from \\\"@itwin/core-backend\\\";\\n\";\r\n outputString += `import * as elementsModule from \"./${schemaName}Elements\";\\n\\n`;\r\n\r\n // create new schema class\r\n outputString += `export class ${schemaName} extends Schema {\\n`;\r\n\r\n // schemaName() method\r\n outputString += ` public static get schemaName(): string { return \"${schemaName}\"; }\\n\\n`;\r\n\r\n // registerSchema method\r\n outputString += \" public static registerSchema() {\\n\";\r\n outputString += ` if (!Schemas.getRegisteredSchema(${schemaName}.name))\\n`;\r\n outputString += ` Schemas.registerSchema(${schemaName});\\n`;\r\n outputString += \" }\\n\\n\";\r\n\r\n // constructor\r\n outputString += \" protected constructor() {\\n\";\r\n outputString += \" super();\\n\";\r\n outputString += ` ClassRegistry.registerModule(elementsModule, ${schemaName});\\n`;\r\n outputString += \" }\\n\";\r\n\r\n outputString += \"}\\n\\n\";\r\n\r\n return outputString;\r\n }\r\n\r\n /**\r\n * The function converts the schema item to respective typescript classes\r\n */\r\n private convertElemToTsClasses(): string {\r\n const classNameToModule: Map<string, string> = new Map<string, string>();\r\n let classTs: string = \"\";\r\n for (const schemaItem of this._schemaItemList) {\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.EntityClass:\r\n classTs += this.convertEntityToTs(schemaItem as EntityClass, classNameToModule);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n classTs += this.convertEnumToTs(schemaItem as Enumeration);\r\n break;\r\n default:\r\n continue;\r\n }\r\n }\r\n\r\n let outputString: string = this.convertImportToTsImport(classNameToModule);\r\n outputString += `\\n${classTs}`;\r\n return outputString;\r\n }\r\n\r\n /**\r\n * The function converts the schema item properties to respective typescript props interfaces\r\n */\r\n private convertPropsToTsInterfaces(): string {\r\n const classNameToModule: Map<string, string> = new Map<string, string>();\r\n let interfacesTs: string = \"\";\r\n for (const schemaItem of this._schemaItemList) {\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.EntityClass:\r\n case SchemaItemType.Mixin:\r\n case SchemaItemType.StructClass:\r\n interfacesTs += this.convertECClassPropsToTsInterface(schemaItem as (Mixin | StructClass | EntityClass), classNameToModule);\r\n break;\r\n default:\r\n continue;\r\n }\r\n }\r\n\r\n let outputString: string = this.convertImportToTsImport(classNameToModule);\r\n outputString += `\\n${interfacesTs}`;\r\n return outputString;\r\n }\r\n\r\n /**\r\n * Convert mixin or struct class or entity class to respective typescript interface\r\n * @param ecClass Schema mixin or struct or entity to be converted typescript interface\r\n * @param classNameToModule Typescrip modules to be updated after the conversion\r\n */\r\n private convertECClassPropsToTsInterface(ecClass: Mixin | StructClass | EntityClass, classNameToModule: Map<string, string>): string {\r\n let interfacesTs: string = \"\";\r\n\r\n // no interface props for BisCore Element\r\n if (ecClass.fullName === elementECClassName)\r\n return interfacesTs;\r\n\r\n // only generate props interface for entity if the class has properties\r\n if (ecClass.schemaItemType === SchemaItemType.EntityClass && !ecClass.hasLocalProperties)\r\n return interfacesTs;\r\n\r\n // convert description to typescript comment only for mixin or struct\r\n if (ecClass.schemaItemType !== SchemaItemType.EntityClass && ecClass.description)\r\n interfacesTs += `${this.convertDescriptionToTsComment(ecClass.description)}\\n`;\r\n\r\n // build interface for props in ecClass\r\n interfacesTs += `export interface ${ecClass.name}`;\r\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\r\n interfacesTs += \"Props\";\r\n\r\n // Extend it with base ecClass Props interface if there is any\r\n const baseClasses = this.getBaseClassWithProps(ecClass);\r\n if (baseClasses.length > 0) {\r\n interfacesTs += \" extends \";\r\n\r\n let separator = \"\";\r\n for (const base of baseClasses) {\r\n interfacesTs += separator + this.addImportBasePropsClass(classNameToModule, base, ecClass);\r\n separator = \", \";\r\n }\r\n } else if (ecClass.schemaItemType === SchemaItemType.EntityClass)\r\n interfacesTs += ` extends ${this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsCommon.moduleName, \"EntityProps\")}`;\r\n\r\n // build props for ecClass\r\n interfacesTs += \" {\";\r\n const propertiesTs = this.convertPropsToTsVars(ecClass, classNameToModule);\r\n for (const varDeclarationLine of propertiesTs)\r\n interfacesTs += `\\n ${varDeclarationLine}`;\r\n interfacesTs += \"\\n}\\n\\n\";\r\n\r\n return interfacesTs;\r\n }\r\n\r\n /**\r\n * Convert schema enumeration to typescript enumeration\r\n * @param ecEnum Schema enumeration to be converted to typescript enumeration\r\n */\r\n private convertEnumToTs(ecEnum: Enumeration): string {\r\n let outputString: string = \"\";\r\n if (ecEnum.description)\r\n outputString += `${this.convertDescriptionToTsComment(ecEnum.description)}\\n`;\r\n\r\n outputString += `export const enum ${ecEnum.name} {\\n`;\r\n for (const ecEnumerator of ecEnum.enumerators) {\r\n outputString += ` ${ecEnumerator.label}`;\r\n if (ecEnum.isInt)\r\n outputString += ` = ${ecEnumerator.value}`;\r\n else if (ecEnum.isString)\r\n outputString += ` = \"${ecEnumerator.value}\"`;\r\n outputString += \",\\n\";\r\n }\r\n\r\n outputString += \"}\\n\\n\";\r\n return outputString;\r\n }\r\n\r\n /**\r\n * Convert schema entity to typescript entity class. The typescript class will implement respective props\r\n * typescript interface if the schema entity class has properties\r\n * @param ecClass Schema class to be converted to typescript class\r\n * @param classNameToModule Typescrip modules to be updated after the conversion\r\n */\r\n private convertEntityToTs(ecClass: EntityClass, classNameToModule: Map<string, string>): string {\r\n let outputString: string = \"\";\r\n if (ecClass.description)\r\n outputString += `${this.convertDescriptionToTsComment(ecClass.description)}\\n`;\r\n\r\n let modifier: string = \"\";\r\n if (ecClass.modifier === ECClassModifier.Abstract)\r\n modifier = \"abstract \";\r\n outputString += `export ${modifier}class ${ecClass.name} extends `;\r\n\r\n // extend base class if there is any. Default will be Entity class defined in @itwin/core-backend\r\n const base = ecClass.getBaseClassSync();\r\n if (base)\r\n outputString += this.addImportBaseClass(classNameToModule, base, ecClass);\r\n else\r\n outputString += this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsBackend.moduleName, \"Entity\");\r\n\r\n // determine prop type to pass in the constructor\r\n let propsBaseTsType: string;\r\n const propsBase = this.getBaseClassWithProps(ecClass);\r\n if (ecClass.fullName !== elementECClassName && ecClass.hasLocalProperties) {\r\n const moduleName: string = `${this._schema!.schemaKey.name}ElementProps`;\r\n propsBaseTsType = this.addImportClass(classNameToModule, moduleName, `${ecClass.name}Props`);\r\n } else if (propsBase.length > 0)\r\n propsBaseTsType = this.addImportBasePropsClass(classNameToModule, propsBase[0], ecClass);\r\n else\r\n propsBaseTsType = this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsCommon.moduleName, \"EntityProps\");\r\n\r\n // implement the ecClass props if it has properties\r\n if (`${ecClass.name}Props` === propsBaseTsType)\r\n outputString += ` implements ${propsBaseTsType}`;\r\n\r\n // write constructor and className function for class\r\n const iModelDbTsType: string = this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsBackend.moduleName, \"IModelDb\");\r\n\r\n outputString += \" {\\n\";\r\n outputString += ` public static get className(): string { return \"${ecClass.name}\"; }\\n\\n`;\r\n outputString += ` public constructor (props: ${propsBaseTsType}, iModel: ${iModelDbTsType}) {\\n`;\r\n outputString += \" super(props, iModel);\\n\";\r\n outputString += \" }\\n\";\r\n outputString += \"}\\n\\n\";\r\n\r\n return outputString;\r\n }\r\n\r\n /**\r\n * Convert class properties to typescript member declaration\r\n * @param ecClass The schema class that has the properties to be converted to typescript member variables\r\n * @param classNameToModule Typescrip modules to be updated after the conversion\r\n */\r\n private convertPropsToTsVars(ecClass: ECClass, classNameToModule: Map<string, string>): string[] {\r\n if (!ecClass.hasLocalProperties)\r\n return [];\r\n\r\n const outputStrings: string[] = [];\r\n for (const ecProperty of ecClass.getPropertiesSync(true)) {\r\n // not generate ts variable declaration for property that has CustomHandledProperty ca\r\n if (ecProperty.customAttributes && ecProperty.customAttributes.has(customHandledPropertyCA))\r\n continue;\r\n\r\n let varDeclarationLine: string = `${this.lowerPropertyName(ecProperty.name)}?: `;\r\n if (ecProperty.isPrimitive()) {\r\n // determine Ts type of the primitive\r\n let typeTs: string = \"\";\r\n if (ecProperty.extendedTypeName)\r\n typeTs = this.convertExtendedTypeNameToTsType(ecProperty.extendedTypeName, classNameToModule);\r\n else if (ecProperty.isEnumeration()) {\r\n const ecEnumProperty = ecProperty as EnumerationProperty;\r\n const ecEnum = ecEnumProperty.enumeration!;\r\n typeTs = this.addImportClass(classNameToModule, `${ecEnum.schemaKey.name}Elements`, ecEnum.name);\r\n } else {\r\n const ecPrimitiveProperty = ecProperty as PrimitiveProperty;\r\n typeTs = this.convertPrimitiveTypeToTsType(ecPrimitiveProperty.primitiveType, classNameToModule);\r\n }\r\n\r\n varDeclarationLine += typeTs;\r\n } else if (ecProperty.isStruct()) {\r\n // import struct class if it is in different schema\r\n const ecStructProperty = ecProperty as StructProperty;\r\n const structClass = ecStructProperty.structClass;\r\n if (!structClass.schema.schemaKey.compareByName(ecClass.schema.schemaKey))\r\n varDeclarationLine += this.addImportClass(classNameToModule, `${structClass.schema.schemaKey.name}ElementProps`, structClass.name);\r\n else\r\n varDeclarationLine += structClass.name;\r\n\r\n } else if (ecProperty.isNavigation())\r\n varDeclarationLine += this.addImportClass(classNameToModule, tsBentleyModules.tsIModelJsCommon.moduleName, \"RelatedElementProps\");\r\n\r\n if (ecProperty.isArray())\r\n varDeclarationLine += \"[]\";\r\n varDeclarationLine += \";\";\r\n\r\n outputStrings.push(varDeclarationLine);\r\n }\r\n\r\n return outputStrings;\r\n }\r\n\r\n /**\r\n * Convert schema extended type to typescript type\r\n * @param typeName Schema extended type to be converted to typescript type\r\n * @param classNameToModule Typescrip modules to be updated after the conversion\r\n */\r\n private convertExtendedTypeNameToTsType(typeName: string, classNameToModule: Map<string, string>): string {\r\n switch (typeName) {\r\n case \"Json\":\r\n return \"any\";\r\n case \"BeGuid\":\r\n return this.addImportClass(classNameToModule, tsBentleyModules.tsBentleyJsCore.moduleName, \"GuidString\");\r\n default:\r\n return \"any\";\r\n }\r\n }\r\n\r\n /**\r\n * Convert schema primitive type to typescript type\r\n * @param type Schema primitive type to be converted to typescript type\r\n * @param classNameToModule Typescrip modules to be updated after the conversion\r\n */\r\n private convertPrimitiveTypeToTsType(type: PrimitiveType, classNameToModule: Map<string, string>) {\r\n switch (type) {\r\n case PrimitiveType.Binary:\r\n return \"any\";\r\n case PrimitiveType.Boolean:\r\n return \"boolean\";\r\n case PrimitiveType.DateTime:\r\n return \"Date\";\r\n case PrimitiveType.Double:\r\n return \"number\";\r\n case PrimitiveType.Integer:\r\n return \"number\";\r\n case PrimitiveType.Long:\r\n // eslint-disable-next-line no-console\r\n console.log(\"Primitive type Long is not currently supported during conversion. It will be treated as type 'any'\");\r\n return \"any\";\r\n case PrimitiveType.String:\r\n return \"string\";\r\n case PrimitiveType.Point2d:\r\n return this.addImportClass(classNameToModule, tsBentleyModules.tsGeometryCore.moduleName, \"Point2d\");\r\n case PrimitiveType.Point3d:\r\n return this.addImportClass(classNameToModule, tsBentleyModules.tsGeometryCore.moduleName, \"Point3d\");\r\n case PrimitiveType.IGeometry:\r\n // eslint-disable-next-line no-console\r\n console.log(\"Primitive type IGeometry is not currently supported during conversion. It will be treated as type 'any'\");\r\n return \"any\";\r\n default:\r\n // eslint-disable-next-line no-console\r\n console.log(\"Unknown primitive type during conversion. It will be treated as type 'any'\");\r\n return \"any\";\r\n }\r\n }\r\n\r\n /**\r\n * Convert schema description to typescript comment\r\n * @param description Schema description to be converted to typescript comment\r\n */\r\n private convertDescriptionToTsComment(description: string) {\r\n let outputString: string = \"/**\\n\";\r\n\r\n let wordCount: number = 0;\r\n let begin: number = 0;\r\n let spaceBegin: number = 0;\r\n let spaceIdx: number = description.indexOf(\" \", spaceBegin);\r\n while (spaceIdx !== -1) {\r\n // new line for every 20 words\r\n ++wordCount;\r\n if (wordCount === 20) {\r\n wordCount = 0;\r\n outputString += ` * ${description.substring(begin, spaceIdx)}\\n`;\r\n begin = spaceIdx + 1;\r\n }\r\n\r\n spaceBegin = spaceIdx + 1;\r\n while (description[spaceBegin] === \" \")\r\n ++spaceBegin;\r\n\r\n spaceIdx = description.indexOf(\" \", spaceBegin);\r\n }\r\n\r\n // append the last word\r\n outputString += ` * ${description.substring(begin)}\\n`;\r\n\r\n outputString += \" */\";\r\n return outputString;\r\n }\r\n\r\n /**\r\n * Convert all modules needed for the converted schema types to typescript import statements\r\n * @param classNameToModule Modules to be converted to typescript imports statement\r\n */\r\n private convertImportToTsImport(classNameToModule: Map<string, string>): string {\r\n const moduleToTsTypes: Map<string, Set<string>> = new Map<string, Set<string>>();\r\n classNameToModule.forEach((moduleNames: string, className: string) => {\r\n if (!moduleToTsTypes.has(moduleNames))\r\n moduleToTsTypes.set(moduleNames, new Set<string>());\r\n\r\n moduleToTsTypes.get(moduleNames)!.add(className);\r\n });\r\n\r\n let outputString: string = \"\";\r\n moduleToTsTypes.forEach((classNames: Set<string>, moduleName: string) => {\r\n if (!this._tsBentleyModuleNames.has(moduleName))\r\n moduleName = `./${moduleName}`;\r\n\r\n outputString += \"import { \";\r\n let separator = \"\";\r\n for (const className of classNames) {\r\n outputString += separator + className;\r\n separator = \", \";\r\n }\r\n outputString += ` } from \"${moduleName}\";\\n`;\r\n });\r\n\r\n return outputString;\r\n }\r\n\r\n /**\r\n * Traverse the inheritance tree to retrieve first base classes that have properties\r\n * @param ecClass Schema class to be traverse\r\n */\r\n private getBaseClassWithProps(ecClass: ECClass): ECClass[] {\r\n const res: ECClass[] = [];\r\n const visited: Set<string> = new Set<string>();\r\n visited.add(ecClass.fullName);\r\n this.traverseBaseClass(ecClass, visited, (base: ECClass) => {\r\n if (base.hasLocalProperties) {\r\n res.push(base);\r\n return false;\r\n }\r\n\r\n return true;\r\n });\r\n\r\n return res;\r\n }\r\n\r\n /**\r\n * Traverse the inheritance tree to retrieve base classes of a schema class\r\n * @param ecClass Schema class to be traverse\r\n */\r\n private getAllBaseClasses(ecClass: ECClass): ECClass[] {\r\n const res: ECClass[] = [];\r\n const visited: Set<string> = new Set<string>();\r\n visited.add(ecClass.fullName);\r\n this.traverseBaseClass(ecClass, visited, (base: ECClass) => {\r\n res.push(base);\r\n return true;\r\n });\r\n\r\n return res;\r\n }\r\n\r\n /**\r\n * Traverse the inheritance tree horizontally and vertically of a schema class\r\n * @param ecClass Schema class to be traverse\r\n * @param visited Set of classes that are already visited\r\n * @param shouldTraverseDown Lambda to determine if it should traverse more vertically\r\n */\r\n private traverseBaseClass(ecClass: ECClass, visited: Set<string>, shouldTraverseDown: (base: ECClass) => boolean): void {\r\n const base = ecClass.getBaseClassSync();\r\n if (base === undefined || visited.has(base.fullName))\r\n return;\r\n\r\n const baseList: ECClass[] = [base];\r\n if (ecClass.schemaItemType === SchemaItemType.EntityClass) {\r\n const entity = ecClass as EntityClass;\r\n for (const mixin of entity.getMixinsSync())\r\n baseList.push(mixin);\r\n }\r\n\r\n for (const eachBase of baseList) {\r\n visited.add(eachBase.fullName);\r\n if (shouldTraverseDown(eachBase))\r\n this.traverseBaseClass(eachBase, visited, shouldTraverseDown);\r\n }\r\n }\r\n\r\n /**\r\n * Add required typescript class that is to be imported from a required module during Schema conversion to typescript. If there is naming conflict\r\n * it will resolve it by appending prefix name with class name, for example: import { element as BisCoreElement } from \"BisCoreElement\";\r\n * @param classNameToModule Typescript modules that is needed for the conversion. It maps typescript class with the required modules\r\n * @param refModule Typescript module that the typescrip class comes from\r\n * @param className Required Typescript class for the conversion\r\n */\r\n private addImportClass(classNameToModule: Map<string, string>, refModule: string, className: string): string {\r\n if (!classNameToModule.has(className)) {\r\n classNameToModule.set(className, refModule);\r\n return className;\r\n }\r\n\r\n if (classNameToModule.get(className) === refModule)\r\n return className;\r\n\r\n let resolvedPrefix: string = refModule;\r\n if (this._tsBentleyModuleResolvedConflictNames.has(refModule))\r\n resolvedPrefix = this._tsBentleyModuleResolvedConflictNames.get(refModule)!;\r\n\r\n const renameClassName = `${className} as ${resolvedPrefix}${className}`;\r\n if (!classNameToModule.has(renameClassName)) {\r\n classNameToModule.set(renameClassName, refModule);\r\n }\r\n\r\n return resolvedPrefix + className;\r\n }\r\n\r\n /**\r\n * Add appropriate typescript props interface to the classNameToModule and return the corresponding typescript base props interface\r\n * @param classNameToModule Typescript modules that is needed for the conversion. It maps typescript class with the required modules\r\n * @param baseECClass Base class of ecClass that has properties. Its name will be used to derived typescript base props interface\r\n * @param ecClass ECClass to be converted to Typescript\r\n */\r\n private addImportBasePropsClass(classNameToModule: Map<string, string>, baseECClass: ECClass, ecClass: ECClass): string {\r\n let baseName: string = baseECClass.name;\r\n if (baseECClass.schemaItemType === SchemaItemType.EntityClass)\r\n baseName += \"Props\";\r\n\r\n // find external module to import\r\n let externalModule: string = \"\";\r\n const shouldImportJsCommon = (baseECClass.fullName === elementECClassName) ||\r\n (baseECClass.schema.schemaKey.name === \"BisCore\" && ecClass.schema.schemaKey.name !== \"BisCore\");\r\n if (shouldImportJsCommon)\r\n externalModule = tsBentleyModules.tsIModelJsCommon.moduleName;\r\n else if (!baseECClass.schema.schemaKey.compareByName(ecClass.schema.schemaKey))\r\n externalModule = `${baseECClass.schema.schemaKey.name}ElementProps`;\r\n\r\n if (externalModule.length !== 0)\r\n baseName = this.addImportClass(classNameToModule, externalModule, baseName);\r\n\r\n return baseName;\r\n }\r\n\r\n /**\r\n * Add appropriate typescript base class to the classNameToModule and return the corresponding typescript base class\r\n * @param classNameToModule Typescript modules that is needed for the conversion. It maps typescript class with the required modules\r\n * @param baseECClass Base class of ecClass\r\n * @param ecClass ECClass to be converted to Typescript\r\n */\r\n private addImportBaseClass(classNameToModule: Map<string, string>, baseECClass: ECClass, ecClass: ECClass): string {\r\n let baseName: string = baseECClass.name;\r\n\r\n // find external module to import for base class\r\n let externalModule: string = \"\";\r\n if (baseECClass.schema.schemaKey.name === \"BisCore\" && ecClass.schema.schemaKey.name !== \"BisCore\")\r\n externalModule = tsBentleyModules.tsIModelJsBackend.moduleName;\r\n else if (!baseECClass.schema.schemaKey.compareByName(ecClass.schema.schemaKey))\r\n externalModule = `${baseECClass.schema.schemaKey.name}Elements`;\r\n\r\n if (externalModule.length !== 0)\r\n baseName = this.addImportClass(classNameToModule, externalModule, baseName);\r\n\r\n return baseName;\r\n }\r\n\r\n /**\r\n * Lower the first character of the property name\r\n * @param propName Property name\r\n */\r\n private lowerPropertyName(propName: string): string {\r\n return propName.charAt(0).toLowerCase() + propName.slice(1);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ecschema2ts_cli.js","sourceRoot":"","sources":["../../src/ecschema2ts_cli.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;AAE/F,+BAA+B;AAC/B,6BAA6B;AAC7B,uCAAuC;AACvC,+BAA+B;AAC/B,+BAA+B;AAE/B,qDAAyD;AACzD,gEAAyD;AAEzD,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,kBAAkB;AAClB,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AACrD,OAAO,CAAC,MAAM,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,CAAC;AAC7D,OAAO,CAAC,MAAM,CAAC,yBAAyB,EAAE,2CAA2C,CAAC,CAAC;AACvF,OAAO,CAAC,MAAM,CAAC,6BAA6B,EAAE,kDAAkD,EAAE,kBAAkB,CAAC,CAAC;AACtH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,CAAC;AAEjB,IAAI,CAAC,OAAO,CAAC,KAAK,IA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AC;IACpG,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,qBAAqB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,gBAAgB;IAChB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC,EAAE,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\n/* eslint-disable no-console */\nimport * as path from \"path\";\nimport * as commander from \"commander\";\nimport * as chalk from \"chalk\";\nimport * as fs from \"fs-extra\";\n\nimport { ECSchemaToTsXmlWriter } from \"./ecschema2ts_io\";\nimport { SchemaContext } from \"@itwin/ecschema-metadata\";\n\nfunction commaSeparatedList(value: string): string[] {\n return value.split(\",\");\n}\n\n// Program options\nconst program = new commander.Command(\"ecschema2ts\");\nprogram.option(\"-i, --input <required>\", \"ECSchemaXml file\");\nprogram.option(\"-o, --output <required>\", \"Directory to put the out typescript file.\");\nprogram.option(\"-r, --references <optional>\", \"A comma-separated list of reference schema paths\", commaSeparatedList);\nprogram.parse(process.argv);\n\nif (process.argv.length === 0)\n program.help();\n\nif (!program.input || !program.output) {\n console.log(chalk.red(\"Invalid input. For help use the '-h' option.\"));\n process.exit(1);\n}\n\n// begin converting schema file to typescript\nconsole.log(`Creating a typescript file for ${program.input}.`);\n\n// check references path\nconst referencePaths: string[] = [];\nif (undefined !== program.references) {\n for (const ref of program.references) {\n const refPath = path.normalize(ref);\n try {\n fs.accessSync(refPath);\n } catch (err: any) {\n console.warn(chalk.yellow(err.toString()));\n console.warn(chalk.yellow(`The reference path ${refPath} does not exist. Skipping...`));\n continue;\n }\n\n console.log(`Adding reference path '${refPath}'.`);\n referencePaths.push(refPath);\n }\n}\n\n(async () => { // eslint-disable-line @typescript-eslint/no-floating-promises\n // convert schema file to typescript\n let createdFiles;\n try {\n const writer = new ECSchemaToTsXmlWriter(program.output);\n createdFiles = await writer.convertSchemaFile(new SchemaContext(), program.input, referencePaths);\n } catch (err: any) {\n console.log(chalk.red(`Failed to create: ${err.message}`));\n process.exit(1);\n }\n\n // output result\n console.log(chalk.green(`${createdFiles}`));\n})();\n"]}
1
+ {"version":3,"file":"ecschema2ts_cli.js","sourceRoot":"","sources":["../../src/ecschema2ts_cli.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;AAE/F,+BAA+B;AAC/B,6BAA6B;AAC7B,uCAAuC;AACvC,+BAA+B;AAC/B,+BAA+B;AAE/B,qDAAyD;AACzD,gEAAyD;AAEzD,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,kBAAkB;AAClB,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AACrD,OAAO,CAAC,MAAM,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,CAAC;AAC7D,OAAO,CAAC,MAAM,CAAC,yBAAyB,EAAE,2CAA2C,CAAC,CAAC;AACvF,OAAO,CAAC,MAAM,CAAC,6BAA6B,EAAE,kDAAkD,EAAE,kBAAkB,CAAC,CAAC;AACtH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,CAAC;AAEjB,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CA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AAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,gBAAgB;IAChB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/* eslint-disable no-console */\r\nimport * as path from \"path\";\r\nimport * as commander from \"commander\";\r\nimport * as chalk from \"chalk\";\r\nimport * as fs from \"fs-extra\";\r\n\r\nimport { ECSchemaToTsXmlWriter } from \"./ecschema2ts_io\";\r\nimport { SchemaContext } from \"@itwin/ecschema-metadata\";\r\n\r\nfunction commaSeparatedList(value: string): string[] {\r\n return value.split(\",\");\r\n}\r\n\r\n// Program options\r\nconst program = new commander.Command(\"ecschema2ts\");\r\nprogram.option(\"-i, --input <required>\", \"ECSchemaXml file\");\r\nprogram.option(\"-o, --output <required>\", \"Directory to put the out typescript file.\");\r\nprogram.option(\"-r, --references <optional>\", \"A comma-separated list of reference schema paths\", commaSeparatedList);\r\nprogram.parse(process.argv);\r\n\r\nif (process.argv.length === 0)\r\n program.help();\r\n\r\nif (!program.input || !program.output) {\r\n console.log(chalk.red(\"Invalid input. For help use the '-h' option.\"));\r\n process.exit(1);\r\n}\r\n\r\n// begin converting schema file to typescript\r\nconsole.log(`Creating a typescript file for ${program.input}.`);\r\n\r\n// check references path\r\nconst referencePaths: string[] = [];\r\nif (undefined !== program.references) {\r\n for (const ref of program.references) {\r\n const refPath = path.normalize(ref);\r\n try {\r\n fs.accessSync(refPath);\r\n } catch (err: any) {\r\n console.warn(chalk.yellow(err.toString()));\r\n console.warn(chalk.yellow(`The reference path ${refPath} does not exist. Skipping...`));\r\n continue;\r\n }\r\n\r\n console.log(`Adding reference path '${refPath}'.`);\r\n referencePaths.push(refPath);\r\n }\r\n}\r\n\r\n(async () => { // eslint-disable-line @typescript-eslint/no-floating-promises\r\n // convert schema file to typescript\r\n let createdFiles;\r\n try {\r\n const writer = new ECSchemaToTsXmlWriter(program.output);\r\n createdFiles = await writer.convertSchemaFile(new SchemaContext(), program.input, referencePaths);\r\n } catch (err: any) {\r\n console.log(chalk.red(`Failed to create: ${err.message}`));\r\n process.exit(1);\r\n }\r\n\r\n // output result\r\n console.log(chalk.green(`${createdFiles}`));\r\n})();\r\n"]}
@@ -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,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,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;IAEM,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QACjG,OAAO,IAAI,CAAC,SAAS,CAAC,S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,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"]}
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,GAAG,aAAa,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,SAAS,CAAC,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACvF,OA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C,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":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as path from \"path\";\r\nimport * as fs from \"fs\";\r\nimport { ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater, SchemaJsonFileLocater } from \"@itwin/ecschema-locaters\";\r\nimport { DOMParser } from \"@xmldom/xmldom\";\r\nimport { ECSchemaXmlContext, IModelHost } from \"@itwin/core-backend\";\r\nimport { ECSchemaToTs } from \"./ecschema2ts\";\r\n\r\nconst unitsSchemaKey = new SchemaKey(\"Units\", 1, 0, 0);\r\nconst formatsSchemaKey = new SchemaKey(\"Formats\", 1, 0, 0);\r\n\r\n/**\r\n * The class is used to parse xml file by using native context. It converts the xml schema\r\n * to json schema and then, use Typescript side json deserialization to convert it to schema object.\r\n * @beta\r\n */\r\nclass SchemaBackendFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n private _nativeContext: ECSchemaXmlContext;\r\n\r\n public constructor(nativeContext: ECSchemaXmlContext) {\r\n super();\r\n this._nativeContext = nativeContext;\r\n }\r\n\r\n /**\r\n * Async version of getSchemaSync()\r\n * @param key The schema key needed to locate the schema in the search path\r\n * @param matchType The SchemaMatchType\r\n * @param context The schema context used to parse schema\r\n */\r\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\r\n return this.getSchemaSync(key, matchType, context);\r\n }\r\n\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n return this.getSchema(schemaKey, matchType, context);\r\n }\r\n\r\n /**\r\n * Attempt to retrieve a schema with the given schema key by using the configured search path.\r\n * @param key The schema key needed to locate the schema in the search path\r\n * @param matchType The SchemaMatchType\r\n * @param context The schema context used to parse schema\r\n */\r\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\r\n const localPath: Set<string> = new Set<string>();\r\n return this.getSchemaRecursively(key, matchType, context, localPath);\r\n }\r\n\r\n /**\r\n * Retrieve the schema key from schema Xml file. It looks very similar to `SchemaXmlFileLocater.getSchemaKey(string):SchemaKey` but not quite.\r\n * Because the schema version in 3.1 and below doesn't contain write version, we will have to manually add\r\n * 0 as a write version for it before converting to schema key\r\n * @param data content of the schema Xml file\r\n */\r\n public getSchemaKey(data: string): SchemaKey {\r\n const matches = data.match(/<ECSchema ([^]+?)>/g);\r\n if (!matches || matches.length !== 1)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\r\n\r\n // parse name and version\r\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\r\n const version = matches[0].match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !version || version.length !== 2)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\r\n\r\n const versionStr: string = this.resolveECVersionString(version[1]);\r\n const key = new SchemaKey(name[1], ECVersion.fromString(versionStr));\r\n return key;\r\n }\r\n\r\n /**\r\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\r\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.\r\n * In case of cyclic dependency, it will throw error\r\n * @param key The schema key needed to locate the schema in the search path\r\n * @param matchType The SchemaMatchType\r\n * @param context The schema context used to parse schema\r\n * @param localPath The path of the recursion is following used to detect cyclic dependency\r\n */\r\n private getSchemaRecursively(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext, localPath: Set<string>): Schema | undefined {\r\n // load the schema file\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\r\n if (0 === candidates.length)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaPath = maxCandidate.fileName;\r\n if (undefined === this.fileExistsSync(schemaPath))\r\n return undefined;\r\n\r\n // mark that schema is already visited\r\n const schemaKeyName = maxCandidate.toString();\r\n localPath.add(schemaKeyName);\r\n\r\n // resolve all the references before beginning parsing the current schema\r\n const domParser: DOMParser = new DOMParser();\r\n const schemaXmlDocument: Document = domParser.parseFromString(fs.readFileSync(schemaPath, \"utf8\"));\r\n const referenceKeys: SchemaKey[] = this.getReferenceSchemaKeys(schemaXmlDocument);\r\n for (const referenceKey of referenceKeys) {\r\n const referenceKeyName = referenceKey.toString();\r\n\r\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\r\n if (undefined === context.getSchemaSync(referenceKey, matchType)) {\r\n const referenceSchema = this.getSchemaRecursively(referenceKey, SchemaMatchType.LatestWriteCompatible, context, localPath);\r\n if (!referenceSchema) {\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema,\r\n `Could not locate reference schema, ${referenceKey.name}.${referenceKey.version.toString()} of schema ${key.name}.${key.version.toString()}`);\r\n }\r\n } else if (localPath.has(referenceKeyName)) {\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Schema ${schemaKeyName} and ${referenceKeyName} form cyclic dependency`);\r\n }\r\n }\r\n\r\n localPath.delete(schemaKeyName);\r\n\r\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\r\n const schemaJson = this._nativeContext.readSchemaFromXmlFile(schemaPath);\r\n return Schema.fromJsonSync(schemaJson, context);\r\n }\r\n\r\n /**\r\n * Retrieve the reference schema keys by parsing the current Schema XML DOM\r\n * @param schemaXmlDocument Current schema XML DOM document\r\n */\r\n private getReferenceSchemaKeys(schemaXmlDocument: Document): SchemaKey[] {\r\n const referenceDocuments = schemaXmlDocument.getElementsByTagName(\"ECSchemaReference\");\r\n const referenceSchemaKeys: SchemaKey[] = [];\r\n\r\n // unfortunately, for-of loop cannot work with HTMLCollectionOf<Element> type here\r\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\r\n for (let i = 0; i < referenceDocuments.length; ++i) {\r\n const element = referenceDocuments[i];\r\n const name = this.getRequiredXmlAttribute(element, \"name\",\r\n \"The schema has an invalid ECSchemaReference attribute. One of the reference is missing the 'name' attribute\");\r\n let version = this.getRequiredXmlAttribute(element, \"version\",\r\n \"The schema has an invalid ECSchemaReference attribute. One of the reference is missing the 'version' attribute\");\r\n version = this.resolveECVersionString(version);\r\n\r\n const key = new SchemaKey(name, ECVersion.fromString(version));\r\n referenceSchemaKeys.push(key);\r\n }\r\n\r\n return referenceSchemaKeys;\r\n }\r\n\r\n /**\r\n * Retrieve the value of the attribute in the DOM Element\r\n * @param xmlElement The DOM Element\r\n * @param attribute The required attribute name of the DOM Element\r\n * @param errorMessage The error message if there is no attribute found in the DOM Element\r\n */\r\n private getRequiredXmlAttribute(xmlElement: Element, attribute: string, errorMessage: string): string {\r\n const value = xmlElement.getAttribute(attribute);\r\n if (!value)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, errorMessage);\r\n\r\n return value;\r\n }\r\n\r\n /**\r\n * Attempt to check the ECVersion. If the ECVersion contains only read and minor version, it will add 00 to the write version.\r\n * Error will be thrown if the version format doesn't contain at least the read and minor version\r\n * @param version raw ECVersion string retrieved from the Schema XML DOM Element\r\n */\r\n private resolveECVersionString(version: string): string {\r\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\r\n let versionNumbers: string[] = version.split(\".\");\r\n if (versionNumbers.length < 2)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `'version' number does not at least have read and minor number in the given file`);\r\n else if (versionNumbers.length === 2) {\r\n versionNumbers.push(\"00\");\r\n const [readNumber, minorNumber, writeNumber] = versionNumbers;\r\n versionNumbers = [readNumber, writeNumber, minorNumber];\r\n }\r\n\r\n return versionNumbers.join(\".\");\r\n }\r\n}\r\n\r\n/**\r\n * Deserializes ECXml and ECJson schema files.\r\n */\r\nclass SchemaDeserializer {\r\n /**\r\n * Deserializes the specified ECXml schema file in the given schema context.\r\n * @param schemaFilePath The path to a valid ECXml schema file.\r\n * @param schemaContext The schema context in which to deserialize the schema.\r\n * @param referencePaths Optional paths to search when locating schema references.\r\n */\r\n public async deserializeXmlFile(schemaFilePath: string, schemaContext: SchemaContext, referencePaths?: string[]): Promise<Schema> {\r\n // If the schema file doesn't exist, throw an error\r\n if (!fs.existsSync(schemaFilePath))\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaFilePath}`);\r\n\r\n await IModelHost.startup({ cacheDir: path.join(__dirname, \".cache\") });\r\n\r\n // add reference paths to the native context\r\n if (undefined === referencePaths)\r\n referencePaths = [];\r\n referencePaths.push(path.dirname(schemaFilePath));\r\n\r\n const nativeContext = new ECSchemaXmlContext();\r\n const locater = new SchemaBackendFileLocater(nativeContext);\r\n for (const refPath of referencePaths) {\r\n locater.addSchemaSearchPath(refPath);\r\n nativeContext.addSchemaPath(refPath);\r\n }\r\n\r\n // parsing the current xml schema\r\n let schema: Schema | undefined;\r\n try {\r\n const schemaKey = locater.getSchemaKey(fs.readFileSync(schemaFilePath, \"utf8\"));\r\n\r\n // Units and Formats have to be added to the ts side context first because the native context will add them automatically to\r\n // the schema as references even if the schema does not use them\r\n if (!schemaKey.compareByName(unitsSchemaKey) && !schemaKey.compareByName(formatsSchemaKey)) {\r\n locater.getSchemaSync(unitsSchemaKey, SchemaMatchType.LatestWriteCompatible, schemaContext);\r\n locater.getSchemaSync(formatsSchemaKey, SchemaMatchType.LatestWriteCompatible, schemaContext);\r\n }\r\n\r\n schema = locater.getSchemaSync(schemaKey, SchemaMatchType.Exact, schemaContext);\r\n } finally {\r\n await IModelHost.shutdown();\r\n }\r\n\r\n return schema!;\r\n }\r\n\r\n /**\r\n * Deserializes the specified ECJson schema file in the given schema context.\r\n * @param schemaFilePath The path to a valid ECJson schema file.\r\n * @param context The schema context in which to deserialize the schema.\r\n * @param referencePaths Optional paths to search when locating schema references.\r\n */\r\n public deserializeJsonFile(schemaFilePath: string, context: SchemaContext, referencePaths?: string[]): Schema {\r\n // If the schema file doesn't exist, throw an error\r\n if (!fs.existsSync(schemaFilePath))\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema JSON file at ${schemaFilePath}`);\r\n\r\n // add locater to the context\r\n if (!referencePaths)\r\n referencePaths = [];\r\n referencePaths.push(path.dirname(schemaFilePath));\r\n\r\n const locater = new SchemaJsonFileLocater();\r\n locater.addSchemaSearchPaths(referencePaths);\r\n context.addLocater(locater);\r\n\r\n // If the file cannot be parsed, throw an error.\r\n const schemaString = fs.readFileSync(schemaFilePath, \"utf8\");\r\n let schemaJson: any;\r\n try {\r\n schemaJson = JSON.parse(schemaString);\r\n } catch (e: any) {\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, e.message);\r\n }\r\n return Schema.fromJsonSync(schemaJson, context);\r\n }\r\n}\r\n\r\n/**\r\n * Abstract interface to write the result of converting schema file to ts to different output (files, stdout, and so on).\r\n * Schema file path can be json or xml or both or an obscured file format depending how the concrete class interprets it.\r\n */\r\nexport interface ECSchemaToTsFileWriter {\r\n convertSchemaFile(context: SchemaContext, schemaPath: string, referencePaths?: string[]): Promise<string>;\r\n}\r\n\r\n/**\r\n * Concrete class to write ecschema2ts result to file\r\n */\r\nexport class ECSchemaToTsXmlWriter implements ECSchemaToTsFileWriter {\r\n private _ecschema2ts: ECSchemaToTs;\r\n private _deserializer: SchemaDeserializer;\r\n private _outdir: string;\r\n\r\n public constructor(outdir: string) {\r\n this._ecschema2ts = new ECSchemaToTs();\r\n this._deserializer = new SchemaDeserializer();\r\n this._outdir = outdir;\r\n }\r\n\r\n /**\r\n * Given a valid schema file path, the converted typescript files will be\r\n * created in the provided output directory. If the output directory does not exist the file will not be\r\n * created.\r\n * @param context Schema context used to find reference schema\r\n * @param schemaPath The full path to the ECSchema xml file\r\n * @param outdir The path to the directory to write the generated typescript file.\r\n */\r\n public async convertSchemaFile(context: SchemaContext, schemaPath: string, referencePaths?: string[]): Promise<string> {\r\n // check if outdir is correct path\r\n if (!this._outdir)\r\n throw new Error(`The out directory ${this._outdir} is invalid.`);\r\n\r\n this._outdir = path.normalize(this._outdir) + path.sep;\r\n if (!fs.existsSync(this._outdir))\r\n throw new Error(`The out directory ${this._outdir} does not exist.`);\r\n\r\n // convert schema to typescript String\r\n const schema = await this._deserializer.deserializeXmlFile(schemaPath, context, referencePaths);\r\n const tsString = this._ecschema2ts.convertSchemaToTs(schema);\r\n const schemaTsString = tsString.schemaTsString;\r\n const elemTsString = tsString.elemTsString;\r\n const propsTsString = tsString.propsTsString;\r\n\r\n // write to file\r\n let createdFilesLog: string = \"\";\r\n\r\n const schemaFile = `${this._outdir}${schema.schemaKey.name}.ts`;\r\n fs.writeFileSync(schemaFile, schemaTsString);\r\n createdFilesLog += `Successfully created typescript file, \"${schemaFile}\".\\r\\n`;\r\n\r\n const elemFile = `${this._outdir}${schema.schemaKey.name}Elements.ts`;\r\n fs.writeFileSync(elemFile, elemTsString);\r\n createdFilesLog += `Successfully created typescript file, \"${elemFile}\".\\r\\n`;\r\n\r\n const propsElemFile = `${this._outdir}${schema.schemaKey.name}ElementProps.ts`;\r\n fs.writeFileSync(propsElemFile, propsTsString);\r\n createdFilesLog += `Successfully created typescript file, \"propsElemFile\".\\r\\n`;\r\n\r\n return createdFilesLog;\r\n }\r\n}\r\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.4.0-dev.7",
5
+ "version": "5.5.0-dev.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.4.0-dev.7"
42
+ "@itwin/build-tools": "5.5.0-dev.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/core-bentley": "5.4.0-dev.7",
51
- "@itwin/ecschema-metadata": "5.4.0-dev.7",
52
- "@itwin/ecschema-locaters": "5.4.0-dev.7",
53
- "@itwin/core-backend": "5.4.0-dev.7",
54
- "@itwin/core-common": "5.4.0-dev.7",
55
- "@itwin/core-geometry": "5.4.0-dev.7"
50
+ "@itwin/core-bentley": "5.5.0-dev.1",
51
+ "@itwin/core-common": "5.5.0-dev.1",
52
+ "@itwin/ecschema-locaters": "5.5.0-dev.1",
53
+ "@itwin/core-geometry": "5.5.0-dev.1",
54
+ "@itwin/ecschema-metadata": "5.5.0-dev.1",
55
+ "@itwin/core-backend": "5.5.0-dev.1"
56
56
  },
57
57
  "nyc": {
58
58
  "extends": "./node_modules/@itwin/build-tools/.nycrc"