@itwin/ecschema-locaters 5.5.0-dev.2 → 5.5.0-dev.5
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.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/SchemaFileLocater.js.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
- package/lib/cjs/SchemaStringLocater.js.map +1 -1
- package/lib/cjs/SchemaXml.js.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.js.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/ecschema-locaters.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaJson.test.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaXml.test.js.map +1 -1
- package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXml.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlStringLocater.test.js.map +1 -1
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
- package/lib/esm/SchemaFileLocater.js.map +1 -1
- package/lib/esm/SchemaJsonFileLocater.js.map +1 -1
- package/lib/esm/SchemaStringLocater.js.map +1 -1
- package/lib/esm/SchemaXml.js.map +1 -1
- package/lib/esm/SchemaXmlFileLocater.js.map +1 -1
- package/lib/esm/SchemaXmlStringLocater.js.map +1 -1
- package/lib/esm/StubSchemaXmlFileLocater.js.map +1 -1
- package/lib/esm/ecschema-locaters.js.map +1 -1
- package/lib/esm/test/ConcurrentGetSchemaJson.test.js.map +1 -1
- package/lib/esm/test/ConcurrentGetSchemaXml.test.js.map +1 -1
- package/lib/esm/test/SchemaJsonFileLocator.test.js.map +1 -1
- package/lib/esm/test/SchemaXml.test.js.map +1 -1
- package/lib/esm/test/SchemaXmlFileLocator.test.js.map +1 -1
- package/lib/esm/test/SchemaXmlStringLocater.test.js.map +1 -1
- package/lib/esm/test/StubSchemaXmlFileLocater.test.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaFileLocater.js","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAyB,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,IAAc,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACrD,OAAO,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,WAAW;YAC3C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,YAAoB,EAAE,SAAiB,EAAE,EAAE;IAC1E,YAAY,GAAG,YAAY,IAAI,CAAC,CAAC,CAAC,iDAAiD;IACnF,SAAS,GAAG,MAAM,CAAC,CAAC,OAAO,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzE,IAAI,GAAG,CAAC,MAAM,GAAG,YAAY,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,YAAY,GAAG,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC;QACzC,IAAI,YAAY,GAAG,SAAS,CAAC,M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YD;;;;;;OAMG;IACI,yBAAyB,GAAG,CAAC,GAAkB,EAAE,GAAkB,EAAU,EAAE;QACpF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport * as fs from \"fs\";\nimport { globSync } from \"glob\";\nimport * as path from \"path\";\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\n\nconst formatString = (format: string, ...args: string[]) => {\n return format.replace(/{(\\d+)}/g, (match, theNumber) => {\n return typeof args[theNumber] !== \"undefined\"\n ? args[theNumber]\n : match;\n });\n};\n\nconst padStartEx = (str: string, targetLength: number, padString: string) => {\n targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;\n padString = String((typeof padString !== \"undefined\" ? padString : \" \"));\n if (str.length > targetLength) {\n return String(str);\n } else {\n targetLength = targetLength - str.length;\n if (targetLength > padString.length) {\n padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed\n }\n return padString.slice(0, targetLength) + str;\n }\n};\n\n/**\n * A SchemaKey implementation that aids in identifying Schema files via the\n * addition of two properties: fileName and schemaText. The fileName contains the\n * full path to the file on disk and schemaText is the full string representation\n * of the Schema.\n * @internal\n */\nexport class FileSchemaKey extends SchemaKey {\n // The schema file associated with the SchemaKey\n public fileName: string;\n // The JSON text for the schema loaded\n public schemaText?: string;\n\n /**\n * Initializes a new FileSchemaKey object.\n * @param key The EC SchemaKey identifying the Schema.\n * @param fileName The full path to the Schema file.\n * @param schemaText The string representation of the Schema\n * loaded from disk. Optional.\n */\n constructor(key: SchemaKey, fileName: string, schemaJson?: string) {\n super(key.name, key.version);\n this.fileName = fileName;\n this.schemaText = schemaJson;\n }\n}\n\n/**\n * Abstract class to hold common/overlapping functionality between SchemaJsonFileLocater and SchemaXmlFileLocater\n * @public @preview\n */\nexport abstract class SchemaFileLocater {\n /** @internal */\n public searchPaths: string[];\n\n constructor() {\n this.searchPaths = [];\n }\n\n /** @internal */\n protected async readUtf8FileToString(filePath: string): Promise<string | undefined> {\n return new Promise<string | undefined>((resolve, reject) => {\n fs.readFile(filePath, \"utf-8\", (err, data) => {\n if (err)\n reject(err);\n else\n resolve(data);\n });\n });\n }\n\n /** @internal */\n protected readUtf8FileToStringSync(filePath: string): string | undefined {\n return fs.readFileSync(filePath, \"utf-8\");\n }\n\n /** @internal */\n protected async fileExists(filePath: string): Promise<boolean | undefined> {\n return new Promise<boolean | undefined>((resolve) => {\n fs.access(filePath, fs.constants.F_OK, (err) => {\n resolve(err ? false : true);\n });\n });\n }\n\n /** @internal */\n protected fileExistsSync(filePath: string): boolean | undefined {\n return fs.existsSync(filePath);\n }\n\n /**\n * Adds more search paths used by this locator to find the\n * Schema files.\n * @param schemaPaths An array of search paths to add\n */\n public addSchemaSearchPaths(schemaPaths: string[]) {\n // If the path is not in the schemaPaths array, add it\n for (const schemaPath of schemaPaths)\n this.addSchemaSearchPath(schemaPath);\n }\n\n /**\n * Add one search path used by this locator to find the\n * Schema files.\n * @param schemaPath A search path to add\n */\n public addSchemaSearchPath(schemaPath: string) {\n // If the path is not in the schemaPaths array, add it\n if (!this.searchPaths.find((entry) => entry === schemaPath))\n this.searchPaths.push(schemaPath);\n }\n\n protected abstract getSchemaKey(data: string): SchemaKey;\n\n /**\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey. This method\n * only attempts to find schema files that have no version in the file name.\n * @param foundFiles The collection of SchemaKeys found in the given directory.\n * @param schemaPath The directory in which to search for the Schemas.\n * @param schemaName The short name of the Schema (without version).\n * @param desiredKey The SchemaKey used to find matching Schema files.\n * @param matchType The SchemaMatchType to use when comparing the desiredKey and the keys found during the search.\n * @param format The type of file that the schema key refers to. json or xml\n */\n private addCandidateNoExtSchemaKey(foundFiles: FileSchemaKey[], schemaPath: string, schemaName: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\n const fullPath = path.join(schemaPath, `${schemaName}.ecschema.${format}`);\n\n // If the file does not exist, end\n if (!fs.existsSync(fullPath))\n return;\n\n // Read the file\n const file = fs.readFileSync(fullPath);\n if (!file)\n return;\n\n // Get the schema key\n const key = this.getSchemaKey(file.toString());\n\n // If the key matches, put it in foundFiles\n if (key.matches(desiredKey, matchType))\n foundFiles.push(new FileSchemaKey(key, fullPath, file.toString()));\n }\n\n /**\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey\n * @param foundFiles The collection of SchemaKeys found in the given directory\n * @param schemaPath The directory in which to search for the Schemas\n * @param fileFilter The file filter, potentially with wildcards, used to locate the Schema files.\n * @param desiredKey The schemaKey used to find matching Schema files\n * @param matchType The SchemaMatchType to use when comparing the desired Key and the keys found during the search.\n * @param format The type of file that the schema key refers to. json or xml\n */\n private addCandidateSchemaKeys(foundFiles: FileSchemaKey[], schemaPath: string, fileFilter: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\n const fullPath = path.join(schemaPath, fileFilter);\n\n const result = globSync(fullPath, { windowsPathsNoEscape: true });\n for (const match of result) {\n let fileName = path.basename(match, (`.ecschema.${format}`));\n // TODO: should this be moved or handled elsewhere?\n // Handles two version file names - SchemaKey.parseString supports only 3 version names.\n if (/[^\\d]\\.\\d?\\d\\.\\d?\\d$/.test(fileName)) {\n const parts = fileName.split(\".\");\n parts.splice(2, 0, \"00\");\n fileName = parts.join(\".\");\n }\n\n const file = fs.readFileSync(match);\n if (!file)\n continue;\n\n const schemaKey = SchemaKey.parseString(fileName);\n if (schemaKey.matches(desiredKey, matchType))\n foundFiles.push(new FileSchemaKey(schemaKey, match, file.toString()));\n }\n }\n\n /**\n * Attempts to find all Schema files in the configurable search paths that match\n * the desired SchemaKey.\n * @param desiredKey The SchemaKey to match.\n * @param matchType The SchemaMatchType.\n * @param format The type of file that the schema key refers to. json or xml\n * @internal\n */\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType, format: string): FileSchemaKey[] {\n const foundFiles = new Array<FileSchemaKey>();\n\n let twoVersionSuffix: string;\n let threeVersionSuffix: string;\n const readVersion = desiredKey.readVersion.toString();\n const writeVersion = desiredKey.writeVersion.toString();\n const minorVersion = desiredKey.minorVersion.toString();\n\n if (matchType === SchemaMatchType.Latest) {\n twoVersionSuffix = (`.*.*.ecschema.${format}`);\n threeVersionSuffix = (`.*.*.*.ecschema.${format}`);\n } else if (matchType === SchemaMatchType.LatestWriteCompatible) {\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\n threeVersionSuffix = formatString(`.{0}.{1}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\n } else if (matchType === SchemaMatchType.LatestReadCompatible) {\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\n threeVersionSuffix = formatString(`.{0}.*.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\n } else {\n twoVersionSuffix = formatString(`.{0}.{1}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\n threeVersionSuffix = formatString(`.{0}.{1}.{2}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"), padStartEx(minorVersion, 2, \"0\"));\n }\n\n const twoVersionExpression = desiredKey.name + twoVersionSuffix;\n const threeVersionExpression = desiredKey.name + threeVersionSuffix;\n\n for (const searchPath of this.searchPaths) {\n this.addCandidateNoExtSchemaKey(foundFiles, searchPath, desiredKey.name, desiredKey, matchType, format);\n this.addCandidateSchemaKeys(foundFiles, searchPath, twoVersionExpression, desiredKey, matchType, format);\n this.addCandidateSchemaKeys(foundFiles, searchPath, threeVersionExpression, desiredKey, matchType, format);\n }\n\n return foundFiles;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;\n\n /**\n * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the\n * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.\n * @param lhs The 'left-hand' FileSchemaKey.\n * @param rhs The 'right-hand' FileSchemaKey.\n * @internal\n */\n public compareSchemaKeyByVersion = (lhs: FileSchemaKey, rhs: FileSchemaKey): number => {\n return lhs.compareByVersion(rhs);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaFileLocater.js","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAyB,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,IAAc,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACrD,OAAO,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,WAAW;YAC3C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,YAAoB,EAAE,SAAiB,EAAE,EAAE;IAC1E,YA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AAC,0BAA0B,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YACxG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YACzG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC7G,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAYD;;;;;;OAMG;IACI,yBAAyB,GAAG,CAAC,GAAkB,EAAE,GAAkB,EAAU,EAAE;QACpF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport { globSync } from \"glob\";\r\nimport * as path from \"path\";\r\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\n\r\nconst formatString = (format: string, ...args: string[]) => {\r\n return format.replace(/{(\\d+)}/g, (match, theNumber) => {\r\n return typeof args[theNumber] !== \"undefined\"\r\n ? args[theNumber]\r\n : match;\r\n });\r\n};\r\n\r\nconst padStartEx = (str: string, targetLength: number, padString: string) => {\r\n targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;\r\n padString = String((typeof padString !== \"undefined\" ? padString : \" \"));\r\n if (str.length > targetLength) {\r\n return String(str);\r\n } else {\r\n targetLength = targetLength - str.length;\r\n if (targetLength > padString.length) {\r\n padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed\r\n }\r\n return padString.slice(0, targetLength) + str;\r\n }\r\n};\r\n\r\n/**\r\n * A SchemaKey implementation that aids in identifying Schema files via the\r\n * addition of two properties: fileName and schemaText. The fileName contains the\r\n * full path to the file on disk and schemaText is the full string representation\r\n * of the Schema.\r\n * @internal\r\n */\r\nexport class FileSchemaKey extends SchemaKey {\r\n // The schema file associated with the SchemaKey\r\n public fileName: string;\r\n // The JSON text for the schema loaded\r\n public schemaText?: string;\r\n\r\n /**\r\n * Initializes a new FileSchemaKey object.\r\n * @param key The EC SchemaKey identifying the Schema.\r\n * @param fileName The full path to the Schema file.\r\n * @param schemaText The string representation of the Schema\r\n * loaded from disk. Optional.\r\n */\r\n constructor(key: SchemaKey, fileName: string, schemaJson?: string) {\r\n super(key.name, key.version);\r\n this.fileName = fileName;\r\n this.schemaText = schemaJson;\r\n }\r\n}\r\n\r\n/**\r\n * Abstract class to hold common/overlapping functionality between SchemaJsonFileLocater and SchemaXmlFileLocater\r\n * @public @preview\r\n */\r\nexport abstract class SchemaFileLocater {\r\n /** @internal */\r\n public searchPaths: string[];\r\n\r\n constructor() {\r\n this.searchPaths = [];\r\n }\r\n\r\n /** @internal */\r\n protected async readUtf8FileToString(filePath: string): Promise<string | undefined> {\r\n return new Promise<string | undefined>((resolve, reject) => {\r\n fs.readFile(filePath, \"utf-8\", (err, data) => {\r\n if (err)\r\n reject(err);\r\n else\r\n resolve(data);\r\n });\r\n });\r\n }\r\n\r\n /** @internal */\r\n protected readUtf8FileToStringSync(filePath: string): string | undefined {\r\n return fs.readFileSync(filePath, \"utf-8\");\r\n }\r\n\r\n /** @internal */\r\n protected async fileExists(filePath: string): Promise<boolean | undefined> {\r\n return new Promise<boolean | undefined>((resolve) => {\r\n fs.access(filePath, fs.constants.F_OK, (err) => {\r\n resolve(err ? false : true);\r\n });\r\n });\r\n }\r\n\r\n /** @internal */\r\n protected fileExistsSync(filePath: string): boolean | undefined {\r\n return fs.existsSync(filePath);\r\n }\r\n\r\n /**\r\n * Adds more search paths used by this locator to find the\r\n * Schema files.\r\n * @param schemaPaths An array of search paths to add\r\n */\r\n public addSchemaSearchPaths(schemaPaths: string[]) {\r\n // If the path is not in the schemaPaths array, add it\r\n for (const schemaPath of schemaPaths)\r\n this.addSchemaSearchPath(schemaPath);\r\n }\r\n\r\n /**\r\n * Add one search path used by this locator to find the\r\n * Schema files.\r\n * @param schemaPath A search path to add\r\n */\r\n public addSchemaSearchPath(schemaPath: string) {\r\n // If the path is not in the schemaPaths array, add it\r\n if (!this.searchPaths.find((entry) => entry === schemaPath))\r\n this.searchPaths.push(schemaPath);\r\n }\r\n\r\n protected abstract getSchemaKey(data: string): SchemaKey;\r\n\r\n /**\r\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey. This method\r\n * only attempts to find schema files that have no version in the file name.\r\n * @param foundFiles The collection of SchemaKeys found in the given directory.\r\n * @param schemaPath The directory in which to search for the Schemas.\r\n * @param schemaName The short name of the Schema (without version).\r\n * @param desiredKey The SchemaKey used to find matching Schema files.\r\n * @param matchType The SchemaMatchType to use when comparing the desiredKey and the keys found during the search.\r\n * @param format The type of file that the schema key refers to. json or xml\r\n */\r\n private addCandidateNoExtSchemaKey(foundFiles: FileSchemaKey[], schemaPath: string, schemaName: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\r\n const fullPath = path.join(schemaPath, `${schemaName}.ecschema.${format}`);\r\n\r\n // If the file does not exist, end\r\n if (!fs.existsSync(fullPath))\r\n return;\r\n\r\n // Read the file\r\n const file = fs.readFileSync(fullPath);\r\n if (!file)\r\n return;\r\n\r\n // Get the schema key\r\n const key = this.getSchemaKey(file.toString());\r\n\r\n // If the key matches, put it in foundFiles\r\n if (key.matches(desiredKey, matchType))\r\n foundFiles.push(new FileSchemaKey(key, fullPath, file.toString()));\r\n }\r\n\r\n /**\r\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey\r\n * @param foundFiles The collection of SchemaKeys found in the given directory\r\n * @param schemaPath The directory in which to search for the Schemas\r\n * @param fileFilter The file filter, potentially with wildcards, used to locate the Schema files.\r\n * @param desiredKey The schemaKey used to find matching Schema files\r\n * @param matchType The SchemaMatchType to use when comparing the desired Key and the keys found during the search.\r\n * @param format The type of file that the schema key refers to. json or xml\r\n */\r\n private addCandidateSchemaKeys(foundFiles: FileSchemaKey[], schemaPath: string, fileFilter: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\r\n const fullPath = path.join(schemaPath, fileFilter);\r\n\r\n const result = globSync(fullPath, { windowsPathsNoEscape: true });\r\n for (const match of result) {\r\n let fileName = path.basename(match, (`.ecschema.${format}`));\r\n // TODO: should this be moved or handled elsewhere?\r\n // Handles two version file names - SchemaKey.parseString supports only 3 version names.\r\n if (/[^\\d]\\.\\d?\\d\\.\\d?\\d$/.test(fileName)) {\r\n const parts = fileName.split(\".\");\r\n parts.splice(2, 0, \"00\");\r\n fileName = parts.join(\".\");\r\n }\r\n\r\n const file = fs.readFileSync(match);\r\n if (!file)\r\n continue;\r\n\r\n const schemaKey = SchemaKey.parseString(fileName);\r\n if (schemaKey.matches(desiredKey, matchType))\r\n foundFiles.push(new FileSchemaKey(schemaKey, match, file.toString()));\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to find all Schema files in the configurable search paths that match\r\n * the desired SchemaKey.\r\n * @param desiredKey The SchemaKey to match.\r\n * @param matchType The SchemaMatchType.\r\n * @param format The type of file that the schema key refers to. json or xml\r\n * @internal\r\n */\r\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType, format: string): FileSchemaKey[] {\r\n const foundFiles = new Array<FileSchemaKey>();\r\n\r\n let twoVersionSuffix: string;\r\n let threeVersionSuffix: string;\r\n const readVersion = desiredKey.readVersion.toString();\r\n const writeVersion = desiredKey.writeVersion.toString();\r\n const minorVersion = desiredKey.minorVersion.toString();\r\n\r\n if (matchType === SchemaMatchType.Latest) {\r\n twoVersionSuffix = (`.*.*.ecschema.${format}`);\r\n threeVersionSuffix = (`.*.*.*.ecschema.${format}`);\r\n } else if (matchType === SchemaMatchType.LatestWriteCompatible) {\r\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\r\n threeVersionSuffix = formatString(`.{0}.{1}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\r\n } else if (matchType === SchemaMatchType.LatestReadCompatible) {\r\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\r\n threeVersionSuffix = formatString(`.{0}.*.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\r\n } else {\r\n twoVersionSuffix = formatString(`.{0}.{1}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\r\n threeVersionSuffix = formatString(`.{0}.{1}.{2}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"), padStartEx(minorVersion, 2, \"0\"));\r\n }\r\n\r\n const twoVersionExpression = desiredKey.name + twoVersionSuffix;\r\n const threeVersionExpression = desiredKey.name + threeVersionSuffix;\r\n\r\n for (const searchPath of this.searchPaths) {\r\n this.addCandidateNoExtSchemaKey(foundFiles, searchPath, desiredKey.name, desiredKey, matchType, format);\r\n this.addCandidateSchemaKeys(foundFiles, searchPath, twoVersionExpression, desiredKey, matchType, format);\r\n this.addCandidateSchemaKeys(foundFiles, searchPath, threeVersionExpression, desiredKey, matchType, format);\r\n }\r\n\r\n return foundFiles;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;\r\n\r\n /**\r\n * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the\r\n * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.\r\n * @param lhs The 'left-hand' FileSchemaKey.\r\n * @param rhs The 'right-hand' FileSchemaKey.\r\n * @internal\r\n */\r\n public compareSchemaKeyByVersion = (lhs: FileSchemaKey, rhs: FileSchemaKey): number => {\r\n return lhs.compareByVersion(rhs);\r\n };\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,GACvG,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,iBAAiB;IAE1D;;;;OAIG;IACO,YAAY,CAAC,IAAY;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAElC,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAEnH,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACrB,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAEnH,yCAAyC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC;QACjC,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC;QAEv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AM,CAAC,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QAC3F,kDAAkD;QAClD,MAAM,UAAU,GAAoB,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9F,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YACxC,OAAO,SAAS,CAAC;QAEnB,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5F,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC;QAEzC,gBAAgB;QAChB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC5B,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport {\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\n/**\n * A SchemaLocator implementation for locating JSON Schema files\n * from the file system using configurable search paths.\n * @public @preview\n */\nexport class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {\n\n /**\n * Constructs a SchemaKey based on the information in the Schema JSON\n * @param data The Schema JSON as a string\n * @internal\n */\n protected getSchemaKey(data: string): SchemaKey {\n const dataJson = JSON.parse(data);\n\n // Check if the name is present\n if (!(dataJson.name))\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);\n\n // Check if versions is present\n if (!(dataJson.version))\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);\n\n // Get the name and version from the JSON\n const schemaName = dataJson.name;\n const schemaVersion = dataJson.version;\n\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\n return key;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\n * search paths to locate the JSON schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n await this.getSchemaInfo(schemaKey, matchType, context);\n\n const schema = await context.getCachedSchema(schemaKey, matchType);\n return schema;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n // Grab all schema files that match the schema key\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (!await this.fileExists(schemaPath))\n return undefined;\n\n const schemaText = await this.readUtf8FileToString(schemaPath);\n if (!schemaText)\n return undefined;\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n\n return Schema.startLoadingFromJson(schemaText, context);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\n * search paths to locate the JSON schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n // Grab all schema files that match the schema key\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (!fs.existsSync(schemaPath))\n return undefined;\n\n const schemaText = fs.readFileSync(schemaPath, \"utf-8\");\n if (!schemaText)\n return undefined;\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n\n const schema = Schema.fromJsonSync(schemaText, context);\n return schema;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,GACvG,MAAM,0BAA0B,CAAC;A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AU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport {\r\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\n/**\r\n * A SchemaLocator implementation for locating JSON Schema files\r\n * from the file system using configurable search paths.\r\n * @public @preview\r\n */\r\nexport class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema JSON\r\n * @param data The Schema JSON as a string\r\n * @internal\r\n */\r\n protected getSchemaKey(data: string): SchemaKey {\r\n const dataJson = JSON.parse(data);\r\n\r\n // Check if the name is present\r\n if (!(dataJson.name))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);\r\n\r\n // Check if versions is present\r\n if (!(dataJson.version))\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);\r\n\r\n // Get the name and version from the JSON\r\n const schemaName = dataJson.name;\r\n const schemaVersion = dataJson.version;\r\n\r\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\r\n return key;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\r\n * search paths to locate the JSON schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\r\n await this.getSchemaInfo(schemaKey, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(schemaKey, matchType);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n // Grab all schema files that match the schema key\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\r\n if (!candidates || candidates.length === 0)\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\r\n // Load the file\r\n if (!await this.fileExists(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = await this.readUtf8FileToString(schemaPath);\r\n if (!schemaText)\r\n return undefined;\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n\r\n return Schema.startLoadingFromJson(schemaText, context);\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\r\n * search paths to locate the JSON schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\r\n // Grab all schema files that match the schema key\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\r\n if (!candidates || candidates.length === 0)\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\r\n // Load the file\r\n if (!fs.existsSync(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = fs.readFileSync(schemaPath, \"utf-8\");\r\n if (!schemaText)\r\n return undefined;\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n\r\n const schema = Schema.fromJsonSync(schemaText, context);\r\n return schema;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaStringLocater.js","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAyB,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,iCAAiC;IAC1B,UAAU,CAAS;IAE1B;;;;OAIG;IACH,YAAY,GAAc,EAAE,UAAkB;QAC5C,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,mBAAmB;IAChC,aAAa,CAAW;IAE/B;QACE,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,aAAuB;QAC7C,sDAAsD;QACtD,KAAK,MAAM,YAAY,IAAI,aAAa;YACtC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,YAAoB;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAClD,0DAA0D;QAC1D,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;YACzG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IAID;;;;OAIG;IACO,sBAAsB,CAAC,UAAqB,EAAE,SAA0B;QAChF,MAAM,YAAY,GAAG,IAAI,KAAK,EAAmB,CAAC;QAElD,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC9C,qBAAqB;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YAE5C,2CAA2C;YAC3C,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC;gBACpC,YAAY,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAID;;;;;OAKG;IACI,yBAAyB,GAAG,CAAC,GAAoB,EAAE,GAAoB,EAAU,EAAE;QACxF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\n\n/**\n * A SchemaKey implementation that aids in identifying Schema strings via the\n * addition of the schemaText property. The schemaText is the full XML string\n * representation of the Schema.\n * @beta\n */\nexport class StringSchemaKey extends SchemaKey {\n // The text for the schema loaded\n public schemaText: string;\n\n /**\n * Initializes a new StringSchemaKey object.\n * @param key The EC SchemaKey identifying the Schema.\n * @param schemaText The string representation of the Schema\n */\n constructor(key: SchemaKey, schemaText: string) {\n super(key.name, key.version);\n this.schemaText = schemaText;\n }\n}\n\n/**\n * Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater\n * @beta\n */\nexport abstract class SchemaStringLocater {\n public schemaStrings: string[];\n\n constructor() {\n this.schemaStrings = [];\n }\n\n /**\n * Adds schema strings used by this locator to find the\n * Schemas.\n * @param schemaPaths An array of Schema strings to add\n */\n public addSchemaStrings(schemaStrings: string[]) {\n // If the path is not in the schemaPaths array, add it\n for (const schemaString of schemaStrings)\n this.addSchemaString(schemaString);\n }\n\n /**\n * Adds a schema string used by this locator to locate and load Schemas.\n * @param schemaText The text of the Schema\n */\n public addSchemaString(schemaString: string) {\n const schemaKey = this.getSchemaKey(schemaString);\n // If the string is not in the schemaStrings array, add it\n if (!this.schemaStrings.find((entry) => this.getSchemaKey(entry).matches(schemaKey, SchemaMatchType.Exact)))\n this.schemaStrings.push(schemaString);\n }\n\n protected abstract getSchemaKey(data: string): SchemaKey;\n\n /**\n * Attempts to find all Schema strings that match the desired SchemaKey.\n * @param desiredKey The SchemaKey to match.\n * @param matchType The SchemaMatchType.\n */\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType): StringSchemaKey[] {\n const foundStrings = new Array<StringSchemaKey>();\n\n for (const schemaString of this.schemaStrings) {\n // Get the schema key\n const key = this.getSchemaKey(schemaString);\n\n // If the key matches, put it in foundFiles\n if (key.matches(desiredKey, matchType))\n foundStrings.push(new StringSchemaKey(key, schemaString));\n }\n\n return foundStrings;\n }\n\n public abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;\n\n /**\n * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the\n * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.\n * @param lhs The 'left-hand' StringSchemaKey.\n * @param rhs The 'right-hand' StringSchemaKey.\n */\n public compareSchemaKeyByVersion = (lhs: StringSchemaKey, rhs: StringSchemaKey): number => {\n return lhs.compareByVersion(rhs);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.js","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAyB,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,iCAAiC;IAC1B,UAAU,CAAS;IAE1B;;;;OAIG;IACH,YAAY,GAAc,EAAE,UAAkB;QAC5C,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,mBAAmB;IAChC,aAAa,CAAW;IAE/B;QACE,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,aAAuB;QAC7C,sDAAsD;QACtD,KAAK,MAAM,YAAY,IAAI,aAAa;YACtC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,YAAoB;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAClD,0DAA0D;QAC1D,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;YACzG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IAID;;;;OAIG;IACO,sBAAsB,CAAC,UAAqB,EAAE,SAA0B;QAChF,MAAM,YAAY,GAAG,IAAI,KAAK,EAAmB,CAAC;QAElD,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC9C,qBAAqB;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YAE5C,2CAA2C;YAC3C,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC;gBACpC,YAAY,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAID;;;;;OAKG;IACI,yBAAyB,GAAG,CAAC,GAAoB,EAAE,GAAoB,EAAU,EAAE;QACxF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * A SchemaKey implementation that aids in identifying Schema strings via the\r\n * addition of the schemaText property. The schemaText is the full XML string\r\n * representation of the Schema.\r\n * @beta\r\n */\r\nexport class StringSchemaKey extends SchemaKey {\r\n // The text for the schema loaded\r\n public schemaText: string;\r\n\r\n /**\r\n * Initializes a new StringSchemaKey object.\r\n * @param key The EC SchemaKey identifying the Schema.\r\n * @param schemaText The string representation of the Schema\r\n */\r\n constructor(key: SchemaKey, schemaText: string) {\r\n super(key.name, key.version);\r\n this.schemaText = schemaText;\r\n }\r\n}\r\n\r\n/**\r\n * Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater\r\n * @beta\r\n */\r\nexport abstract class SchemaStringLocater {\r\n public schemaStrings: string[];\r\n\r\n constructor() {\r\n this.schemaStrings = [];\r\n }\r\n\r\n /**\r\n * Adds schema strings used by this locator to find the\r\n * Schemas.\r\n * @param schemaPaths An array of Schema strings to add\r\n */\r\n public addSchemaStrings(schemaStrings: string[]) {\r\n // If the path is not in the schemaPaths array, add it\r\n for (const schemaString of schemaStrings)\r\n this.addSchemaString(schemaString);\r\n }\r\n\r\n /**\r\n * Adds a schema string used by this locator to locate and load Schemas.\r\n * @param schemaText The text of the Schema\r\n */\r\n public addSchemaString(schemaString: string) {\r\n const schemaKey = this.getSchemaKey(schemaString);\r\n // If the string is not in the schemaStrings array, add it\r\n if (!this.schemaStrings.find((entry) => this.getSchemaKey(entry).matches(schemaKey, SchemaMatchType.Exact)))\r\n this.schemaStrings.push(schemaString);\r\n }\r\n\r\n protected abstract getSchemaKey(data: string): SchemaKey;\r\n\r\n /**\r\n * Attempts to find all Schema strings that match the desired SchemaKey.\r\n * @param desiredKey The SchemaKey to match.\r\n * @param matchType The SchemaMatchType.\r\n */\r\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType): StringSchemaKey[] {\r\n const foundStrings = new Array<StringSchemaKey>();\r\n\r\n for (const schemaString of this.schemaStrings) {\r\n // Get the schema key\r\n const key = this.getSchemaKey(schemaString);\r\n\r\n // If the key matches, put it in foundFiles\r\n if (key.matches(desiredKey, matchType))\r\n foundStrings.push(new StringSchemaKey(key, schemaString));\r\n }\r\n\r\n return foundStrings;\r\n }\r\n\r\n public abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;\r\n\r\n /**\r\n * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the\r\n * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.\r\n * @param lhs The 'left-hand' StringSchemaKey.\r\n * @param rhs The 'right-hand' StringSchemaKey.\r\n */\r\n public compareSchemaKeyByVersion = (lhs: StringSchemaKey, rhs: StringSchemaKey): number => {\r\n return lhs.compareByVersion(rhs);\r\n };\r\n}\r\n"]}
|
package/lib/esm/SchemaXml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXml.js","sourceRoot":"","sources":["../../src/SchemaXml.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;GAGG;AACH,MAAM,KAAW,SAAS,CAyCzB;AAzCD,WAAiB,SAAS;IAExB;;;;OAIG;IACI,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,UAAkB;QAChE,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,sCAAsC,QAAQ,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAVqB,mBAAS,YAU9B,CAAA;IAED;;;OAGG;IACI,KAAK,UAAU,WAAW,CAAC,MAAc;QAC9C,IAAI,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAE1G,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;QACvC,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IANqB,qBAAW,cAMhC,CAAA;IAED,SAAS,aAAa,CAAC,MAAc,EAAE,UAAkB;QACvD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,GAAG,GAAG,yBAAyB,OAAO,mBAAmB,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC,EAzCgB,SAAS,KAAT,SAAS,QAyCzB","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/** @packageDocumentation\n * @module Utils\n */\n\nimport * as fs from \"fs-extra\";\nimport * as path from \"path\";\nimport { DOMParser, XMLSerializer } from \"@xmldom/xmldom\";\nimport { Schema } from \"@itwin/ecschema-metadata\";\n\n/**\n * Utility class to assist in creating serialized EC Schemas on the file system.\n * @internal\n */\nexport namespace SchemaXml {\n\n /**\n * Writes a Schema to an xml file to the specified output path.\n * @param schema The Schema to serialize.\n * @param outputPath The directory in which to create the file.\n */\n export async function writeFile(schema: Schema, outputPath: string) {\n const xml = await writeString(schema);\n\n const baseFile = getSchemaPath(schema, outputPath);\n try {\n await fs.writeFile(baseFile, xml);\n } catch (err: any) {\n const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;\n throw new Error(msg);\n }\n }\n\n /**\n * Writes a Schema to an xml string.\n * @param schema The Schema to serialize.\n */\n export async function writeString(schema: Schema): Promise<string> {\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\n\n xmlDoc = await schema.toXml(xmlDoc);\n const serializer = new XMLSerializer();\n return serializer.serializeToString(xmlDoc);\n }\n\n function getSchemaPath(schema: Schema, outputPath: string): string {\n const realDir = path.normalize(outputPath);\n const test = fs.pathExistsSync(realDir);\n if (!test) {\n const msg = `The output directory '${realDir}' does not exist.`;\n throw new Error(msg);\n }\n\n return path.resolve(realDir, `${schema.name}.ecschema.xml`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaXml.js","sourceRoot":"","sources":["../../src/SchemaXml.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;GAGG;AACH,MAAM,KAAW,SAAS,CAyCzB;AAzCD,WAAiB,SAAS;IAExB;;;;OAIG;IACI,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,UAAkB;QAChE,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,sCAAsC,QAAQ,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAVqB,mBAAS,YAU9B,CAAA;IAED;;;OAGG;IACI,KAAK,UAAU,WAAW,CAAC,MAAc;QAC9C,IAAI,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAE1G,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;QACvC,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IANqB,qBAAW,cAMhC,CAAA;IAED,SAAS,aAAa,CAAC,MAAc,EAAE,UAAkB;QACvD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,GAAG,GAAG,yBAAyB,OAAO,mBAAmB,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC,EAzCgB,SAAS,KAAT,SAAS,QAyCzB","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/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport * as fs from \"fs-extra\";\r\nimport * as path from \"path\";\r\nimport { DOMParser, XMLSerializer } from \"@xmldom/xmldom\";\r\nimport { Schema } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * Utility class to assist in creating serialized EC Schemas on the file system.\r\n * @internal\r\n */\r\nexport namespace SchemaXml {\r\n\r\n /**\r\n * Writes a Schema to an xml file to the specified output path.\r\n * @param schema The Schema to serialize.\r\n * @param outputPath The directory in which to create the file.\r\n */\r\n export async function writeFile(schema: Schema, outputPath: string) {\r\n const xml = await writeString(schema);\r\n\r\n const baseFile = getSchemaPath(schema, outputPath);\r\n try {\r\n await fs.writeFile(baseFile, xml);\r\n } catch (err: any) {\r\n const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;\r\n throw new Error(msg);\r\n }\r\n }\r\n\r\n /**\r\n * Writes a Schema to an xml string.\r\n * @param schema The Schema to serialize.\r\n */\r\n export async function writeString(schema: Schema): Promise<string> {\r\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\r\n\r\n xmlDoc = await schema.toXml(xmlDoc);\r\n const serializer = new XMLSerializer();\r\n return serializer.serializeToString(xmlDoc);\r\n }\r\n\r\n function getSchemaPath(schema: Schema, outputPath: string): string {\r\n const realDir = path.normalize(outputPath);\r\n const test = fs.pathExistsSync(realDir);\r\n if (!test) {\r\n const msg = `The output directory '${realDir}' does not exist.`;\r\n throw new Error(msg);\r\n }\r\n\r\n return path.resolve(realDir, `${schema.name}.ecschema.xml`);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OA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AE,WAAW,CAAC,CAAC;QAClE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,iBAAiB,WAAW,8CAA8C,CAAC,CAAC;QAE9F,kDAAkD;QAClD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IACzH,CAAC;IAED;;;;OAIG;IACa,mBAAmB,CAAC,WAAmB;QACrD,OAAO,CAAC,0CAA0C;IACpD,CAAC;IAED;;;;OAIG;IACa,oBAAoB,CAAC,YAAsB;QACzD,OAAO,CAAC,0CAA0C;IACpD,CAAC;CACF","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport * as path from \"path\";\nimport * as fs from \"fs\";\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\nimport { globSync } from \"glob\";\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths.\n * @public @preview This is a workaround the current lack of a full xml parser.\n */\nexport class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n await this.getSchemaInfo(key, matchType, context);\n\n const schema = await context.getCachedSchema(key, matchType);\n return schema;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"xml\");\n\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\n // Load the file\n if (undefined === await this.fileExists(schemaPath))\n return undefined;\n\n const schemaText = await this.readUtf8FileToString(schemaPath);\n if (undefined === schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (!this.fileExistsSync(schemaPath))\n return undefined;\n\n const schemaText = this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param data The Schema XML as a string.\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 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 key = new SchemaKey(name[1], ECVersion.fromString(version[1]));\n return key;\n }\n}\n\n/**\n * This locater is responsible for locating standard schema files that are released by the core-backend package.\n * The locater needs an argument to the known backend assets directory where the core-backend package is installed.\n * This can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.\n *\n * @note This locater is read-only and does not allow adding new schema search paths.\n * @note This locater should be used as a fallback/last chance locater in the schema context as any user defined schema should have higher precedence over the standard schema.\n * @public @preview This is a workaround due to the current lack of a full xml parser.\n */\nexport class PublishedSchemaXmlFileLocater extends SchemaXmlFileLocater implements ISchemaLocater {\n /**\n * Constructs a new PublishedSchemaXmlFileLocater\n * @param knownBackendAssetsDir The assets directory where the core-backend package is installed. Can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.\n */\n public constructor(knownBackendAssetsDir: string) {\n super();\n\n const ecSchemaDir = path.join(knownBackendAssetsDir, \"ECSchemas\");\n if (!fs.existsSync(ecSchemaDir))\n throw new Error(`The directory ${ecSchemaDir} containing standard schemas does not exist.`);\n\n // Pre-defined set of standard schema search paths\n this.searchPaths.push(...globSync(path.join(ecSchemaDir, \"*/\"), { windowsPathsNoEscape: true }).filter(fs.existsSync));\n }\n\n /**\n * Overrides the addSchemaSearchPath method to prevent adding new schema search paths.\n *\n * @param _schemaPath - The schema path to add (ignored).\n */\n public override addSchemaSearchPath(_schemaPath: string): void {\n return; // Do nothing, this is a read-only locator\n }\n\n /**\n * Overrides the addSchemaSearchPaths method to prevent adding new schema search paths.\n *\n * @param _schemaPaths - The schema paths to add (ignored).\n */\n public override addSchemaSearchPaths(_schemaPaths: string[]): void {\n return; // Do nothing, this is a read-only locator\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,EAAmB,gBAAgB,EAAE,SAAS,GACrJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IACzD;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CAAC,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACvF,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,GAA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;QACzD,OAAO,CAAC,0CAA0C;IACpD,CAAC;CACF","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as path from \"path\";\r\nimport * as fs from \"fs\";\r\nimport { DOMParser } from \"@xmldom/xmldom\";\r\nimport {\r\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\nimport { globSync } from \"glob\";\r\n\r\n/**\r\n * A SchemaLocater implementation for locating XML Schema files\r\n * from the file system using configurable search paths.\r\n * @public @preview This is a workaround the current lack of a full xml parser.\r\n */\r\nexport class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\r\n await this.getSchemaInfo(key, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(key, matchType);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"xml\");\r\n\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\r\n // Load the file\r\n if (undefined === await this.fileExists(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = await this.readUtf8FileToString(schemaPath);\r\n if (undefined === schemaText)\r\n return undefined;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n const schema = new Schema(context);\r\n\r\n return reader.readSchemaInfo(schema, document);\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\r\n\r\n if (!candidates || candidates.length === 0)\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\r\n // Load the file\r\n if (!this.fileExistsSync(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = this.readUtf8FileToStringSync(schemaPath);\r\n if (!schemaText)\r\n return undefined;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n let schema: Schema = new Schema(context);\r\n schema = reader.readSchemaSync(schema, document);\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param data The Schema XML as a string.\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 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 key = new SchemaKey(name[1], ECVersion.fromString(version[1]));\r\n return key;\r\n }\r\n}\r\n\r\n/**\r\n * This locater is responsible for locating standard schema files that are released by the core-backend package.\r\n * The locater needs an argument to the known backend assets directory where the core-backend package is installed.\r\n * This can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.\r\n *\r\n * @note This locater is read-only and does not allow adding new schema search paths.\r\n * @note This locater should be used as a fallback/last chance locater in the schema context as any user defined schema should have higher precedence over the standard schema.\r\n * @public @preview This is a workaround due to the current lack of a full xml parser.\r\n */\r\nexport class PublishedSchemaXmlFileLocater extends SchemaXmlFileLocater implements ISchemaLocater {\r\n /**\r\n * Constructs a new PublishedSchemaXmlFileLocater\r\n * @param knownBackendAssetsDir The assets directory where the core-backend package is installed. Can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.\r\n */\r\n public constructor(knownBackendAssetsDir: string) {\r\n super();\r\n\r\n const ecSchemaDir = path.join(knownBackendAssetsDir, \"ECSchemas\");\r\n if (!fs.existsSync(ecSchemaDir))\r\n throw new Error(`The directory ${ecSchemaDir} containing standard schemas does not exist.`);\r\n\r\n // Pre-defined set of standard schema search paths\r\n this.searchPaths.push(...globSync(path.join(ecSchemaDir, \"*/\"), { windowsPathsNoEscape: true }).filter(fs.existsSync));\r\n }\r\n\r\n /**\r\n * Overrides the addSchemaSearchPath method to prevent adding new schema search paths.\r\n *\r\n * @param _schemaPath - The schema path to add (ignored).\r\n */\r\n public override addSchemaSearchPath(_schemaPath: string): void {\r\n return; // Do nothing, this is a read-only locator\r\n }\r\n\r\n /**\r\n * Overrides the addSchemaSearchPaths method to prevent adding new schema search paths.\r\n *\r\n * @param _schemaPaths - The schema paths to add (ignored).\r\n */\r\n public override addSchemaSearchPaths(_schemaPaths: string[]): void {\r\n return; // Do nothing, this is a read-only locator\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlStringLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,EAAmB,gBAAgB,EAAE,SAAS,GACrJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAE7E;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IAE7D;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,CAAC,CAAC;QAElH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAC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AE,CAAC,CAAC;QAEhI,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEjI,OAAO,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CAEF","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { SchemaStringLocater, StringSchemaKey } from \"./SchemaStringLocater\";\n\n/**\n * A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings\n * loaded in memory.\n * @beta\n */\nexport class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param schemaXml The Schema XML as a string.\n */\n public getSchemaKey(schemaXml: string): SchemaKey {\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);\n\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 string`);\n\n const ecVersion = ECVersion.fromString(version[1]);\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n await this.getSchemaInfo(schemaKey, matchType, context);\n\n const schema = await context.getCachedSchema(schemaKey, matchType);\n return schema as Schema;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema;\n }\n\n /**\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\n */\n private fromECv2String(versionString: string): ECVersion {\n const [read, minor] = versionString.split(\".\");\n\n if (!read)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n return new ECVersion(+read, 0, +minor);\n }\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,EAAmB,gBAAgB,EAAE,SAAS,GACrJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAE7E;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IAE7D;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,CAAC,CAAC;QAElH,MAAM,IAAI,GAAG,OAA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C,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAEhI,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEjI,OAAO,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CAEF","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport { DOMParser } from \"@xmldom/xmldom\";\r\nimport {\r\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaStringLocater, StringSchemaKey } from \"./SchemaStringLocater\";\r\n\r\n/**\r\n * A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings\r\n * loaded in memory.\r\n * @beta\r\n */\r\nexport class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param schemaXml The Schema XML as a string.\r\n */\r\n public getSchemaKey(schemaXml: string): SchemaKey {\r\n const matches = schemaXml.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 string`);\r\n\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 string`);\r\n\r\n const ecVersion = ECVersion.fromString(version[1]);\r\n const key = new SchemaKey(name[1], ecVersion);\r\n return key;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\r\n * Schema strings.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\r\n await this.getSchemaInfo(schemaKey, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(schemaKey, matchType);\r\n return schema as Schema;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n // Grab all schema strings that match the schema key\r\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaText = maxCandidate.schemaText;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n const schema = new Schema(context);\r\n\r\n return reader.readSchemaInfo(schema, document);\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\r\n * Schema strings.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\r\n // Grab all schema strings that match the schema key\r\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaText = maxCandidate.schemaText;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n let schema: Schema = new Schema(context);\r\n schema = reader.readSchemaSync(schema, document);\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\r\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\r\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\r\n */\r\n private fromECv2String(versionString: string): ECVersion {\r\n const [read, minor] = versionString.split(\".\");\r\n\r\n if (!read)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, 0, +minor);\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StubSchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/StubSchemaXmlFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAk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AAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport * as path from \"path\";\nimport {\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\nfunction isECv2Schema(schemaText: string): boolean {\n return /<ECSchema[^>]*xmlns=\".*ECXML.2.0\"/.test(schemaText);\n}\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths. Returns only\n * Schemas from XML files with their keys populated.\n * @internal\n */\nexport class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\n /**\n * Loads a Schema from an XML file on the file system.\n * @param schemaPath The path to the Schema file.\n * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,\n * the schema will be read from the provided schemaPath.\n */\n public loadSchema(schemaPath: string, schemaText?: string): Schema {\n schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const key = this.getSchemaKey(schemaText);\n const alias = this.getSchemaAlias(schemaText);\n const context = new SchemaContext();\n context.addLocater(this);\n\n // Load the schema and return it\n const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\n return schema;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the 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 /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n return this.getSchemaSync(key, matchType, context) as SchemaInfo;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const alias = this.getSchemaAlias(maxCandidate.schemaText!);\n const schema = new Schema(context, maxCandidate, alias);\n context.addSchemaSync(schema);\n\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\n return schema;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param schemaXml The Schema XML as a string.\n */\n public getSchemaKey(schemaXml: string): SchemaKey {\n const matches = schemaXml.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 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 let ecVersion: ECVersion;\n if (isECv2Schema(schemaXml))\n ecVersion = this.fromECv2String(version[1]);\n else\n ecVersion = ECVersion.fromString(version[1]);\n\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\n * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.\n */\n private getSchemaReferenceKeys(schemaKey: FileSchemaKey): SchemaKey[] {\n return this._getSchemaReferenceKeys(schemaKey);\n }\n\n /**\n * Adds schemas to the references collection for the given Schema by locating\n * the referenced schemas.\n * @param schema The schema for which to add the references.\n * @param context The SchemaContext that will control the lifetime of the schema.\n * @param refMatchType The SchemaMatchType to use when locating schema references.\n */\n private addSchemaReferences(schema: Schema, context: SchemaContext, refMatchType: SchemaMatchType): void {\n const refKeys = this.getSchemaReferenceKeys(schema.schemaKey as FileSchemaKey);\n\n for (const key of refKeys) {\n const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;\n if (!refSchema)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);\n\n schema.references.push(refSchema);\n }\n }\n\n /**\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\n * @param data The Schema XML string.\n */\n private _getSchemaReferenceKeys(xmlSchemaKey: FileSchemaKey): SchemaKey[] {\n const file = xmlSchemaKey.schemaText;\n\n if (!file)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);\n\n const data = file.toString().replace(/(\\s*)<!--[\\s\\S]*?--!?>/g, \"\"); // ignore any comments in the XML file when getting the array of SchemaKeys\n\n const keys: SchemaKey[] = [];\n const matches = data.match(/<ECSchemaReference ([^]+?)\\/>/g);\n if (!matches)\n return keys;\n\n for (const match of matches) {\n const name = match.match(/name=\"(.+?)\"/);\n const versionMatch = match.match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);\n\n // write version maybe missing, so insert \"0\"\n let versionString = versionMatch[1];\n const versionParts = versionString.split(\".\");\n if (versionParts.length === 2)\n versionParts.splice(1, 0, \"0\");\n\n versionString = versionParts.join(\".\");\n\n const key = new SchemaKey(name[1], ECVersion.fromString(versionString));\n keys.push(key);\n }\n\n return keys;\n }\n\n /**\n * Gets the Schema alias from the Schema XML.\n * @param data The Schema XML as a string.\n */\n private getSchemaAlias(schemaXml: string): string {\n let match: any;\n\n if (isECv2Schema(schemaXml)) {\n match = schemaXml.match(/<ECSchema.*nameSpacePrefix=\"(?<alias>\\w+)\"/) as any;\n } else {\n match = schemaXml.match(/<ECSchema.*alias=\"(?<alias>\\w+)\"/) as any;\n }\n\n if (!match || !match.groups.alias) {\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);\n }\n\n return match.groups.alias;\n }\n\n /**\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\n */\n private fromECv2String(versionString: string): ECVersion {\n const [read, minor] = versionString.split(\".\");\n\n if (!read)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n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AAG,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAEhI,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEjI,OAAO,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\nfunction isECv2Schema(schemaText: string): boolean {\r\n return /<ECSchema[^>]*xmlns=\".*ECXML.2.0\"/.test(schemaText);\r\n}\r\n\r\n/**\r\n * A SchemaLocater implementation for locating XML Schema files\r\n * from the file system using configurable search paths. Returns only\r\n * Schemas from XML files with their keys populated.\r\n * @internal\r\n */\r\nexport class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n /**\r\n * Loads a Schema from an XML file on the file system.\r\n * @param schemaPath The path to the Schema file.\r\n * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,\r\n * the schema will be read from the provided schemaPath.\r\n */\r\n public loadSchema(schemaPath: string, schemaText?: string): Schema {\r\n schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);\r\n if (!schemaText)\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const key = this.getSchemaKey(schemaText);\r\n const alias = this.getSchemaAlias(schemaText);\r\n const context = new SchemaContext();\r\n context.addLocater(this);\r\n\r\n // Load the schema and return it\r\n const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);\r\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the 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 /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n return this.getSchemaSync(key, matchType, context) as SchemaInfo;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\r\n\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const alias = this.getSchemaAlias(maxCandidate.schemaText!);\r\n const schema = new Schema(context, maxCandidate, alias);\r\n context.addSchemaSync(schema);\r\n\r\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param schemaXml The Schema XML as a string.\r\n */\r\n public getSchemaKey(schemaXml: string): SchemaKey {\r\n const matches = schemaXml.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 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 let ecVersion: ECVersion;\r\n if (isECv2Schema(schemaXml))\r\n ecVersion = this.fromECv2String(version[1]);\r\n else\r\n ecVersion = ECVersion.fromString(version[1]);\r\n\r\n const key = new SchemaKey(name[1], ecVersion);\r\n return key;\r\n }\r\n\r\n /**\r\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\r\n * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.\r\n */\r\n private getSchemaReferenceKeys(schemaKey: FileSchemaKey): SchemaKey[] {\r\n return this._getSchemaReferenceKeys(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds schemas to the references collection for the given Schema by locating\r\n * the referenced schemas.\r\n * @param schema The schema for which to add the references.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n * @param refMatchType The SchemaMatchType to use when locating schema references.\r\n */\r\n private addSchemaReferences(schema: Schema, context: SchemaContext, refMatchType: SchemaMatchType): void {\r\n const refKeys = this.getSchemaReferenceKeys(schema.schemaKey as FileSchemaKey);\r\n\r\n for (const key of refKeys) {\r\n const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;\r\n if (!refSchema)\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);\r\n\r\n schema.references.push(refSchema);\r\n }\r\n }\r\n\r\n /**\r\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\r\n * @param data The Schema XML string.\r\n */\r\n private _getSchemaReferenceKeys(xmlSchemaKey: FileSchemaKey): SchemaKey[] {\r\n const file = xmlSchemaKey.schemaText;\r\n\r\n if (!file)\r\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);\r\n\r\n const data = file.toString().replace(/(\\s*)<!--[\\s\\S]*?--!?>/g, \"\"); // ignore any comments in the XML file when getting the array of SchemaKeys\r\n\r\n const keys: SchemaKey[] = [];\r\n const matches = data.match(/<ECSchemaReference ([^]+?)\\/>/g);\r\n if (!matches)\r\n return keys;\r\n\r\n for (const match of matches) {\r\n const name = match.match(/name=\"(.+?)\"/);\r\n const versionMatch = match.match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);\r\n\r\n // write version maybe missing, so insert \"0\"\r\n let versionString = versionMatch[1];\r\n const versionParts = versionString.split(\".\");\r\n if (versionParts.length === 2)\r\n versionParts.splice(1, 0, \"0\");\r\n\r\n versionString = versionParts.join(\".\");\r\n\r\n const key = new SchemaKey(name[1], ECVersion.fromString(versionString));\r\n keys.push(key);\r\n }\r\n\r\n return keys;\r\n }\r\n\r\n /**\r\n * Gets the Schema alias from the Schema XML.\r\n * @param data The Schema XML as a string.\r\n */\r\n private getSchemaAlias(schemaXml: string): string {\r\n let match: any;\r\n\r\n if (isECv2Schema(schemaXml)) {\r\n match = schemaXml.match(/<ECSchema.*nameSpacePrefix=\"(?<alias>\\w+)\"/) as any;\r\n } else {\r\n match = schemaXml.match(/<ECSchema.*alias=\"(?<alias>\\w+)\"/) as any;\r\n }\r\n\r\n if (!match || !match.groups.alias) {\r\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);\r\n }\r\n\r\n return match.groups.alias;\r\n }\r\n\r\n /**\r\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\r\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\r\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\r\n */\r\n private fromECv2String(versionString: string): ECVersion {\r\n const [read, minor] = versionString.split(\".\");\r\n\r\n if (!read)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, 0, +minor);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-locaters.js","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./SchemaFileLocater\";\nexport * from \"./SchemaXml\";\nexport * from \"./SchemaJsonFileLocater\";\nexport * from \"./SchemaXmlFileLocater\";\nexport * from \"./StubSchemaXmlFileLocater\";\nexport * from \"./SchemaXmlStringLocater\";\n\n/** @docs-package-description\n * The ecschema-locaters package contains classes for locating ECSchemas within a given\n * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater\n * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).\n */\n/**\n * @docs-group-description Locaters\n * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).\n */\n/**\n * @docs-group-description Utils\n * A set of utility classes used throughout the package.\n */\n"]}
|
|
1
|
+
{"version":3,"file":"ecschema-locaters.js","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./SchemaFileLocater\";\r\nexport * from \"./SchemaXml\";\r\nexport * from \"./SchemaJsonFileLocater\";\r\nexport * from \"./SchemaXmlFileLocater\";\r\nexport * from \"./StubSchemaXmlFileLocater\";\r\nexport * from \"./SchemaXmlStringLocater\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-locaters package contains classes for locating ECSchemas within a given\r\n * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater\r\n * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).\r\n */\r\n/**\r\n * @docs-group-description Locaters\r\n * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * A set of utility classes used throughout the package.\r\n */\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConcurrentGetSchemaJson.test.js","sourceRoot":"","sources":["../../../src/test/ConcurrentGetSchemaJson.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAU,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3H,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACtD,MAAM,QAAQ,GAAW,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE5D,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,IAAI,OAAsB,CAAC;IAC3B,IAAI,WAA0B,CAAC;IAC/B,IAAI,WAAW,GAA8B,EAAE,CAAC;IAEhD,MAAM,OAAO,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAE5C,MAAM,CAAC,GAAG,EAAE;QACV,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;YAC1B,EA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["/*---------------------------------------------------------------------------------------------\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 { assert, expect } from \"chai\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { ECVersion, Schema, SchemaContext, SchemaJsonLocater, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { SchemaJsonFileLocater } from \"../SchemaJsonFileLocater\";\n\ndescribe(\"Concurrent schema JSON deserialization\", () => {\n const assetDir: string = path.join(__dirname, \"assets\");\n const schemaFolder = path.join(__dirname, \"assets\", \"json\");\n\n const schemaKeys: SchemaKey[] = [];\n let context: SchemaContext;\n let contextSync: SchemaContext;\n let syncSchemas: Array<Schema | undefined> = [];\n\n const locater = new SchemaJsonFileLocater();\n\n before(() => {\n if (!fs.existsSync(assetDir))\n fs.mkdirSync(assetDir);\n if (!fs.existsSync(schemaFolder))\n fs.mkdirSync(schemaFolder);\n\n copySchemasToAssetsDir();\n\n // Deserialize schemas synchronously/serially as standard to compare to\n contextSync = new SchemaContext();\n locater.addSchemaSearchPath(schemaFolder);\n contextSync.addLocater(locater);\n\n const schemaFiles = fs.readdirSync(schemaFolder);\n schemaFiles.forEach((fileName) => {\n const schemaFile = path.join(schemaFolder, fileName);\n const schemaJson = JSON.parse(fs.readFileSync(schemaFile, \"utf-8\"));\n const schemaName = schemaJson.name;\n const schemaVersion = schemaJson.version;\n\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\n schemaKeys.push(key);\n });\n\n syncSchemas = schemaKeys.map((key): Schema | undefined => {\n if (!key)\n return undefined;\n\n const schema = contextSync.getSchemaSync(key, SchemaMatchType.Latest);\n return schema;\n });\n });\n\n beforeEach(() => {\n context = new SchemaContext();\n context.addLocater(locater);\n });\n\n function getSchemaPathFromPackage(packageName: string, schemaFileName: string): string {\n const schemaFile = path.join(__dirname, \"..\", \"..\", \"..\", \"node_modules\", \"@bentley\", packageName, schemaFileName);\n return schemaFile;\n }\n\n function copySchemasToAssetsDir() {\n // Copy Schemas that we need for testing\n fs.copyFileSync(getSchemaPathFromPackage(\"aec-units-schema\", \"AecUnits.ecschema.json\"), path.join(schemaFolder, \"AecUnits.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"architectural-physical-schema\", \"ArchitecturalPhysical.ecschema.json\"), path.join(schemaFolder, \"ArchitecturalPhysical.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"bis-core-schema\", \"BisCore.ecschema.json\"), path.join(schemaFolder, \"BisCore.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"bis-custom-attributes-schema\", \"BisCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"BisCustomAttributes.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"construction-schema\", \"Construction.ecschema.json\"), path.join(schemaFolder, \"Construction.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"core-custom-attributes-schema\", \"CoreCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"CoreCustomAttributes.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"ecdb-map-schema\", \"ECDbMap.ecschema.json\"), path.join(schemaFolder, \"ECDbMap.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"ecdb-schema-policies-schema\", \"ECDbSchemaPolicies.ecschema.json\"), path.join(schemaFolder, \"ECDbSchemaPolicies.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"formats-schema\", \"Formats.ecschema.json\"), path.join(schemaFolder, \"Formats.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"linear-referencing-schema\", \"LinearReferencing.ecschema.json\"), path.join(schemaFolder, \"LinearReferencing.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"physical-material-schema\", \"PhysicalMaterial.ecschema.json\"), path.join(schemaFolder, \"PhysicalMaterial.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"plant-custom-attributes-schema\", \"PlantCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"PlantCustomAttributes.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"quantity-takeoffs-aspects-schema\", \"QuantityTakeoffsAspects.ecschema.json\"), path.join(schemaFolder, \"QuantityTakeoffsAspects.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"spatial-composition-schema\", \"SpatialComposition.ecschema.json\"), path.join(schemaFolder, \"SpatialComposition.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"structural-physical-schema\", \"StructuralPhysical.ecschema.json\"), path.join(schemaFolder, \"StructuralPhysical.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"units-schema\", \"Units.ecschema.json\"), path.join(schemaFolder, \"Units.ecschema.json\"));\n }\n\n it(\"should match schemas deserialized concurrently with schemas deserialized serially\", async () => {\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n });\n const asyncSchemas = await Promise.all(schemaPromises);\n\n for (let i = 0; i < schemaKeys.length; i++) {\n const syncSchema = syncSchemas[i];\n expect(syncSchema).not.to.be.undefined;\n const syncJSON = syncSchema!.toJSON();\n\n const asyncSchema = asyncSchemas[i];\n expect(asyncSchema).not.to.be.undefined;\n const asyncJSON = asyncSchema!.toJSON();\n expect(asyncJSON).to.deep.equal(syncJSON);\n }\n });\n\n it(\"should be able to mix getSchema and getSchemaSync\", async () => {\n const schemaPromises = schemaKeys.map(async (key, index): Promise<Schema | undefined> => {\n if (index % 2 === 0) {\n // Use getSchema() for even indices\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n } else {\n // Use getSchemaSync() for odd indices\n if (!key)\n return undefined;\n\n const schema = context.getSchemaSync(key, SchemaMatchType.Latest);\n return schema;\n }\n });\n const schemas = await Promise.all(schemaPromises);\n\n for (let i = 0; i < schemaKeys.length; i++) {\n const syncSchema = syncSchemas[i];\n expect(syncSchema).not.to.be.undefined;\n const syncJSON = syncSchema!.toJSON();\n\n const schema = schemas[i];\n expect(schema).not.to.be.undefined;\n const schemaJSON = schema!.toJSON();\n expect(schemaJSON).to.deep.equal(syncJSON);\n }\n });\n\n /* Run these tests below one at a time. Running them together doesn't get accurate performance likely bc of disk access caching */\n it.skip(\"should measure regular deserialization performance\", async () => {\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n });\n\n for (const promise of schemaPromises) {\n await promise;\n }\n\n expect(schemaPromises.length).to.equal(schemaKeys.length);\n });\n\n it.skip(\"should measure concurrent deserialization performance\", async () => {\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n });\n const asyncSchemas = await Promise.all(schemaPromises);\n\n expect(asyncSchemas.length).to.equal(schemaKeys.length);\n });\n\n it(\"Concurrently get BisCore with SchemaJsonFileLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonFileLocater = new SchemaJsonFileLocater();\n jsonFileLocater.addSchemaSearchPath(schemaFolder);\n schemaContext.addLocater(jsonFileLocater);\n\n const schemas = await Promise.all(\n [...Array(100).keys()].map(async () => {\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }),\n );\n expect(schemas.length).to.equal(100);\n schemas.forEach((schema) => {\n assert(schema !== undefined);\n expect(schema.fullName).to.equal(\"BisCore\");\n });\n });\n\n it(\"Concurrently get a schema and it's referenced schema with SchemaJsonFileLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonFileLocater = new SchemaJsonFileLocater();\n jsonFileLocater.addSchemaSearchPath(schemaFolder);\n schemaContext.addLocater(jsonFileLocater);\n\n let getBisCoreFirst = 0;\n const schemas = await Promise.all(\n [...Array(2).keys()].map(async () => {\n if (getBisCoreFirst === 0) {\n getBisCoreFirst = 1;\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }\n return schemaContext.getSchema(new SchemaKey(\"CoreCustomAttributes\"));\n }),\n );\n expect(schemas.length).to.equal(2);\n schemas.forEach((schema) => {\n expect(schema).to.not.be.undefined;\n });\n });\n\n const getSchemaProps = (schemaName: string) => {\n if (schemaName === \"BisCore\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"bis\",\n description: \"The BIS core schema contains classes that all other domain schemas extend.\",\n label: \"BIS Core\",\n name: \"BisCore\",\n version: \"01.00.15\",\n references:[{name:\"CoreCustomAttributes\", version:\"01.00.04\"},{name:\"ECDbMap\", version:\"02.00.00\"},{name:\"ECDbSchemaPolicies\", version:\"01.00.00\"}],\n };\n }\n if (schemaName === \"CoreCustomAttributes\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"CoreCA\",\n description: \"Custom attributes to indicate core EC concepts, may include struct classes intended for use in core custom attributes.\",\n label: \"Core Custom Attributes\",\n name: \"CoreCustomAttributes\",\n version: \"01.00.04\",\n };\n }\n if (schemaName === \"ECDbMap\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"ECDbMap\",\n description: \"ECDbMap Desc\",\n label: \"ECDbMap\",\n name: \"ECDbMap\",\n version: \"02.00.00\",\n };\n }\n if (schemaName === \"ECDbSchemaPolicies\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"ECDbSchemaPolicies\",\n description: \"ECDbSchemaPolicies Desc\",\n label: \"ECDbSchemaPolicies\",\n name: \"ECDbSchemaPolicies\",\n version: \"01.00.00\",\n };\n }\n\n return undefined;\n };\n\n it(\"Concurrently get BisCore with SchemaJsonLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonLocater = new SchemaJsonLocater(getSchemaProps);\n schemaContext.addLocater(jsonLocater);\n\n const schemaCount = 1000;\n const schemas = await Promise.all(\n [...Array(schemaCount).keys()].map(async () => {\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }),\n );\n expect(schemas.length).to.equal(schemaCount);\n schemas.forEach((schema) => {\n assert(schema !== undefined);\n expect(schema.fullName).to.equal(\"BisCore\");\n });\n });\n\n it(\"Concurrently get a schema and it's referenced schema with SchemaJsonLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonLocater = new SchemaJsonLocater(getSchemaProps);\n schemaContext.addLocater(jsonLocater);\n\n let getBisCoreFirst = 0;\n const schemaCount = 1000;\n const schemas = await Promise.all(\n [...Array(schemaCount).keys()].map(async () => {\n if (getBisCoreFirst === 0) {\n getBisCoreFirst = 1;\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }\n return schemaContext.getSchema(new SchemaKey(\"CoreCustomAttributes\"));\n }),\n );\n expect(schemas.length).to.equal(schemaCount);\n schemas.forEach((schema) => {\n expect(schema).to.not.be.undefined;\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"ConcurrentGetSchemaJson.test.js","sourceRoot":"","sources":["../../../src/test/ConcurrentGetSchemaJson.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAU,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3H,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACtD,MAAM,QAAQ,GAAW,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;I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AC,sBAAsB,CAAC,CAAC,CAAC;QACxE,CAAC,CAAC,CACH,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACzB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,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\nimport { assert, expect } from \"chai\";\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { ECVersion, Schema, SchemaContext, SchemaJsonLocater, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaJsonFileLocater } from \"../SchemaJsonFileLocater\";\r\n\r\ndescribe(\"Concurrent schema JSON deserialization\", () => {\r\n const assetDir: string = path.join(__dirname, \"assets\");\r\n const schemaFolder = path.join(__dirname, \"assets\", \"json\");\r\n\r\n const schemaKeys: SchemaKey[] = [];\r\n let context: SchemaContext;\r\n let contextSync: SchemaContext;\r\n let syncSchemas: Array<Schema | undefined> = [];\r\n\r\n const locater = new SchemaJsonFileLocater();\r\n\r\n before(() => {\r\n if (!fs.existsSync(assetDir))\r\n fs.mkdirSync(assetDir);\r\n if (!fs.existsSync(schemaFolder))\r\n fs.mkdirSync(schemaFolder);\r\n\r\n copySchemasToAssetsDir();\r\n\r\n // Deserialize schemas synchronously/serially as standard to compare to\r\n contextSync = new SchemaContext();\r\n locater.addSchemaSearchPath(schemaFolder);\r\n contextSync.addLocater(locater);\r\n\r\n const schemaFiles = fs.readdirSync(schemaFolder);\r\n schemaFiles.forEach((fileName) => {\r\n const schemaFile = path.join(schemaFolder, fileName);\r\n const schemaJson = JSON.parse(fs.readFileSync(schemaFile, \"utf-8\"));\r\n const schemaName = schemaJson.name;\r\n const schemaVersion = schemaJson.version;\r\n\r\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\r\n schemaKeys.push(key);\r\n });\r\n\r\n syncSchemas = schemaKeys.map((key): Schema | undefined => {\r\n if (!key)\r\n return undefined;\r\n\r\n const schema = contextSync.getSchemaSync(key, SchemaMatchType.Latest);\r\n return schema;\r\n });\r\n });\r\n\r\n beforeEach(() => {\r\n context = new SchemaContext();\r\n context.addLocater(locater);\r\n });\r\n\r\n function getSchemaPathFromPackage(packageName: string, schemaFileName: string): string {\r\n const schemaFile = path.join(__dirname, \"..\", \"..\", \"..\", \"node_modules\", \"@bentley\", packageName, schemaFileName);\r\n return schemaFile;\r\n }\r\n\r\n function copySchemasToAssetsDir() {\r\n // Copy Schemas that we need for testing\r\n fs.copyFileSync(getSchemaPathFromPackage(\"aec-units-schema\", \"AecUnits.ecschema.json\"), path.join(schemaFolder, \"AecUnits.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"architectural-physical-schema\", \"ArchitecturalPhysical.ecschema.json\"), path.join(schemaFolder, \"ArchitecturalPhysical.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"bis-core-schema\", \"BisCore.ecschema.json\"), path.join(schemaFolder, \"BisCore.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"bis-custom-attributes-schema\", \"BisCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"BisCustomAttributes.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"construction-schema\", \"Construction.ecschema.json\"), path.join(schemaFolder, \"Construction.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"core-custom-attributes-schema\", \"CoreCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"CoreCustomAttributes.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"ecdb-map-schema\", \"ECDbMap.ecschema.json\"), path.join(schemaFolder, \"ECDbMap.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"ecdb-schema-policies-schema\", \"ECDbSchemaPolicies.ecschema.json\"), path.join(schemaFolder, \"ECDbSchemaPolicies.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"formats-schema\", \"Formats.ecschema.json\"), path.join(schemaFolder, \"Formats.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"linear-referencing-schema\", \"LinearReferencing.ecschema.json\"), path.join(schemaFolder, \"LinearReferencing.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"physical-material-schema\", \"PhysicalMaterial.ecschema.json\"), path.join(schemaFolder, \"PhysicalMaterial.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"plant-custom-attributes-schema\", \"PlantCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"PlantCustomAttributes.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"quantity-takeoffs-aspects-schema\", \"QuantityTakeoffsAspects.ecschema.json\"), path.join(schemaFolder, \"QuantityTakeoffsAspects.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"spatial-composition-schema\", \"SpatialComposition.ecschema.json\"), path.join(schemaFolder, \"SpatialComposition.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"structural-physical-schema\", \"StructuralPhysical.ecschema.json\"), path.join(schemaFolder, \"StructuralPhysical.ecschema.json\"));\r\n fs.copyFileSync(getSchemaPathFromPackage(\"units-schema\", \"Units.ecschema.json\"), path.join(schemaFolder, \"Units.ecschema.json\"));\r\n }\r\n\r\n it(\"should match schemas deserialized concurrently with schemas deserialized serially\", async () => {\r\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\r\n if (!key)\r\n return undefined;\r\n\r\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\r\n return schema;\r\n });\r\n const asyncSchemas = await Promise.all(schemaPromises);\r\n\r\n for (let i = 0; i < schemaKeys.length; i++) {\r\n const syncSchema = syncSchemas[i];\r\n expect(syncSchema).not.to.be.undefined;\r\n const syncJSON = syncSchema!.toJSON();\r\n\r\n const asyncSchema = asyncSchemas[i];\r\n expect(asyncSchema).not.to.be.undefined;\r\n const asyncJSON = asyncSchema!.toJSON();\r\n expect(asyncJSON).to.deep.equal(syncJSON);\r\n }\r\n });\r\n\r\n it(\"should be able to mix getSchema and getSchemaSync\", async () => {\r\n const schemaPromises = schemaKeys.map(async (key, index): Promise<Schema | undefined> => {\r\n if (index % 2 === 0) {\r\n // Use getSchema() for even indices\r\n if (!key)\r\n return undefined;\r\n\r\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\r\n return schema;\r\n } else {\r\n // Use getSchemaSync() for odd indices\r\n if (!key)\r\n return undefined;\r\n\r\n const schema = context.getSchemaSync(key, SchemaMatchType.Latest);\r\n return schema;\r\n }\r\n });\r\n const schemas = await Promise.all(schemaPromises);\r\n\r\n for (let i = 0; i < schemaKeys.length; i++) {\r\n const syncSchema = syncSchemas[i];\r\n expect(syncSchema).not.to.be.undefined;\r\n const syncJSON = syncSchema!.toJSON();\r\n\r\n const schema = schemas[i];\r\n expect(schema).not.to.be.undefined;\r\n const schemaJSON = schema!.toJSON();\r\n expect(schemaJSON).to.deep.equal(syncJSON);\r\n }\r\n });\r\n\r\n /* Run these tests below one at a time. Running them together doesn't get accurate performance likely bc of disk access caching */\r\n it.skip(\"should measure regular deserialization performance\", async () => {\r\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\r\n if (!key)\r\n return undefined;\r\n\r\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\r\n return schema;\r\n });\r\n\r\n for (const promise of schemaPromises) {\r\n await promise;\r\n }\r\n\r\n expect(schemaPromises.length).to.equal(schemaKeys.length);\r\n });\r\n\r\n it.skip(\"should measure concurrent deserialization performance\", async () => {\r\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\r\n if (!key)\r\n return undefined;\r\n\r\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\r\n return schema;\r\n });\r\n const asyncSchemas = await Promise.all(schemaPromises);\r\n\r\n expect(asyncSchemas.length).to.equal(schemaKeys.length);\r\n });\r\n\r\n it(\"Concurrently get BisCore with SchemaJsonFileLocater\", async () => {\r\n const schemaContext = new SchemaContext();\r\n const jsonFileLocater = new SchemaJsonFileLocater();\r\n jsonFileLocater.addSchemaSearchPath(schemaFolder);\r\n schemaContext.addLocater(jsonFileLocater);\r\n\r\n const schemas = await Promise.all(\r\n [...Array(100).keys()].map(async () => {\r\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\r\n }),\r\n );\r\n expect(schemas.length).to.equal(100);\r\n schemas.forEach((schema) => {\r\n assert(schema !== undefined);\r\n expect(schema.fullName).to.equal(\"BisCore\");\r\n });\r\n });\r\n\r\n it(\"Concurrently get a schema and it's referenced schema with SchemaJsonFileLocater\", async () => {\r\n const schemaContext = new SchemaContext();\r\n const jsonFileLocater = new SchemaJsonFileLocater();\r\n jsonFileLocater.addSchemaSearchPath(schemaFolder);\r\n schemaContext.addLocater(jsonFileLocater);\r\n\r\n let getBisCoreFirst = 0;\r\n const schemas = await Promise.all(\r\n [...Array(2).keys()].map(async () => {\r\n if (getBisCoreFirst === 0) {\r\n getBisCoreFirst = 1;\r\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\r\n }\r\n return schemaContext.getSchema(new SchemaKey(\"CoreCustomAttributes\"));\r\n }),\r\n );\r\n expect(schemas.length).to.equal(2);\r\n schemas.forEach((schema) => {\r\n expect(schema).to.not.be.undefined;\r\n });\r\n });\r\n\r\n const getSchemaProps = (schemaName: string) => {\r\n if (schemaName === \"BisCore\") {\r\n return {\r\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\r\n alias: \"bis\",\r\n description: \"The BIS core schema contains classes that all other domain schemas extend.\",\r\n label: \"BIS Core\",\r\n name: \"BisCore\",\r\n version: \"01.00.15\",\r\n references:[{name:\"CoreCustomAttributes\", version:\"01.00.04\"},{name:\"ECDbMap\", version:\"02.00.00\"},{name:\"ECDbSchemaPolicies\", version:\"01.00.00\"}],\r\n };\r\n }\r\n if (schemaName === \"CoreCustomAttributes\") {\r\n return {\r\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\r\n alias: \"CoreCA\",\r\n description: \"Custom attributes to indicate core EC concepts, may include struct classes intended for use in core custom attributes.\",\r\n label: \"Core Custom Attributes\",\r\n name: \"CoreCustomAttributes\",\r\n version: \"01.00.04\",\r\n };\r\n }\r\n if (schemaName === \"ECDbMap\") {\r\n return {\r\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\r\n alias: \"ECDbMap\",\r\n description: \"ECDbMap Desc\",\r\n label: \"ECDbMap\",\r\n name: \"ECDbMap\",\r\n version: \"02.00.00\",\r\n };\r\n }\r\n if (schemaName === \"ECDbSchemaPolicies\") {\r\n return {\r\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\r\n alias: \"ECDbSchemaPolicies\",\r\n description: \"ECDbSchemaPolicies Desc\",\r\n label: \"ECDbSchemaPolicies\",\r\n name: \"ECDbSchemaPolicies\",\r\n version: \"01.00.00\",\r\n };\r\n }\r\n\r\n return undefined;\r\n };\r\n\r\n it(\"Concurrently get BisCore with SchemaJsonLocater\", async () => {\r\n const schemaContext = new SchemaContext();\r\n const jsonLocater = new SchemaJsonLocater(getSchemaProps);\r\n schemaContext.addLocater(jsonLocater);\r\n\r\n const schemaCount = 1000;\r\n const schemas = await Promise.all(\r\n [...Array(schemaCount).keys()].map(async () => {\r\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\r\n }),\r\n );\r\n expect(schemas.length).to.equal(schemaCount);\r\n schemas.forEach((schema) => {\r\n assert(schema !== undefined);\r\n expect(schema.fullName).to.equal(\"BisCore\");\r\n });\r\n });\r\n\r\n it(\"Concurrently get a schema and it's referenced schema with SchemaJsonLocater\", async () => {\r\n const schemaContext = new SchemaContext();\r\n const jsonLocater = new SchemaJsonLocater(getSchemaProps);\r\n schemaContext.addLocater(jsonLocater);\r\n\r\n let getBisCoreFirst = 0;\r\n const schemaCount = 1000;\r\n const schemas = await Promise.all(\r\n [...Array(schemaCount).keys()].map(async () => {\r\n if (getBisCoreFirst === 0) {\r\n getBisCoreFirst = 1;\r\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\r\n }\r\n return schemaContext.getSchema(new SchemaKey(\"CoreCustomAttributes\"));\r\n }),\r\n );\r\n expect(schemas.length).to.equal(schemaCount);\r\n schemas.forEach((schema) => {\r\n expect(schema).to.not.be.undefined;\r\n });\r\n });\r\n});\r\n"]}
|