@itwin/ecschema-locaters 5.0.0-dev.78 → 5.0.0-dev.79
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.d.ts +1 -1
- package/lib/cjs/SchemaFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaFileLocater.js.map +1 -1
- package/lib/cjs/SchemaStringLocater.d.ts +1 -1
- package/lib/cjs/SchemaStringLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaStringLocater.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Change Log - @itwin/ecschema-locaters
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 06 Mar 2025 14:16:21 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.10.8
|
|
6
|
+
Thu, 06 Mar 2025 14:13:37 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
4
9
|
|
|
5
10
|
## 4.10.7
|
|
6
11
|
Tue, 18 Feb 2025 17:27:03 GMT
|
|
@@ -73,7 +73,7 @@ export declare abstract class SchemaFileLocater {
|
|
|
73
73
|
* @param matchType The SchemaMatchType.
|
|
74
74
|
* @param format The type of file that the schema key refers to. json or xml
|
|
75
75
|
*/
|
|
76
|
-
protected findEligibleSchemaKeys(desiredKey:
|
|
76
|
+
protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType, format: string): FileSchemaKey[];
|
|
77
77
|
/**
|
|
78
78
|
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
79
79
|
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":"AAIA;;GA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AE,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAClI,kBAAkB,GAAG,YAAY,CAAC,yBAAyB,MAAM,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAC5K,CAAC;QAED,MAAM,oBAAoB,GAAG,UAAU,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAChE,MAAM,sBAAsB,GAAG,UAAU,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAEpE,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,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;;;;;OAKG;IACI,yBAAyB,GAAG,CAAC,GAAkB,EAAE,GAAkB,EAAU,EAAE;QACpF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH;AAtLD,8CAsLC","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 * @beta\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 * @beta - Needs further testing and possibly moved to a separate package.\n */\nexport abstract class SchemaFileLocater {\n public searchPaths: string[];\n\n constructor() {\n this.searchPaths = [];\n }\n\n public 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 public readUtf8FileToStringSync(filePath: string): string | undefined {\n return fs.readFileSync(filePath, \"utf-8\");\n }\n\n public 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 public 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: Readonly<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: Readonly<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 */\n protected findEligibleSchemaKeys(desiredKey: Readonly<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 */\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,yBAAyB;AACzB,+BAAgC;AAChC,6BAA6B;AAC7B,gEAA6F;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,MAAM,EAAE,CAAC;YACpC,SAAS,IAAI,SAAS,CAA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,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH;AAtLD,8CAsLC","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 * @beta\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 * @beta - Needs further testing and possibly moved to a separate package.\n */\nexport abstract class SchemaFileLocater {\n public searchPaths: string[];\n\n constructor() {\n this.searchPaths = [];\n }\n\n public 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 public readUtf8FileToStringSync(filePath: string): string | undefined {\n return fs.readFileSync(filePath, \"utf-8\");\n }\n\n public 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 public 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 */\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 */\n public compareSchemaKeyByVersion = (lhs: FileSchemaKey, rhs: FileSchemaKey): number => {\n return lhs.compareByVersion(rhs);\n };\n}\n"]}
|
|
@@ -41,7 +41,7 @@ export declare abstract class SchemaStringLocater {
|
|
|
41
41
|
* @param desiredKey The SchemaKey to match.
|
|
42
42
|
* @param matchType The SchemaMatchType.
|
|
43
43
|
*/
|
|
44
|
-
protected findEligibleSchemaKeys(desiredKey:
|
|
44
|
+
protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType): StringSchemaKey[];
|
|
45
45
|
abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
46
46
|
/**
|
|
47
47
|
* Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAErC,UAAU,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;gBACS,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM;CAI/C;AAED;;;GAGG;AACH,8BAAsB,mBAAmB;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;;IAM/B;;;;OAIG;IACI,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE;IAM/C;;;OAGG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM;IAO3C,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAExD;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAErC,UAAU,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;gBACS,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM;CAI/C;AAED;;;GAGG;AACH,8BAAsB,mBAAmB;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;;IAM/B;;;;OAIG;IACI,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE;IAM/C;;;OAGG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM;IAO3C,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAExD;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,GAAG,eAAe,EAAE;aAetF,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAE1H;;;;;OAKG;IACI,yBAAyB,QAAS,eAAe,OAAO,eAAe,KAAG,MAAM,CAErF;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaStringLocater.js","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAA6F;AAE7F;;;;;GAKG;AACH,MAAa,eAAgB,SAAQ,6BAAS;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;AAbD,0CAaC;AAED;;;GAGG;AACH,MAAsB,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,mCAAe,CAAC,KAAK,CAAC,CAAC;YACzG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IAID;;;;OAIG;IACO,sBAAsB,CAAC,
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.js","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAA6F;AAE7F;;;;;GAKG;AACH,MAAa,eAAgB,SAAQ,6BAAS;IAC5C,iCAAiC;IAC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E,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;AA9DD,kDA8DC","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/ecschema-locaters",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.79",
|
|
4
4
|
"description": "EC Schema file locaters",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/ecschema-locaters.js",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"rimraf": "^3.0.2",
|
|
55
55
|
"sinon": "^17.0.2",
|
|
56
56
|
"typescript": "~5.6.2",
|
|
57
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
58
|
-
"@itwin/ecschema-metadata": "5.0.0-dev.
|
|
57
|
+
"@itwin/build-tools": "5.0.0-dev.79",
|
|
58
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.79"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"glob": "^10.3.12",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@xmldom/xmldom": "~0.8.5"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@itwin/ecschema-metadata": "5.0.0-dev.
|
|
66
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.79"
|
|
67
67
|
},
|
|
68
68
|
"nyc": {
|
|
69
69
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|