@itwin/ecschema-locaters 4.0.0-dev.6 → 4.0.0-dev.60

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/SchemaFileLocater.d.ts +82 -82
  3. package/lib/cjs/SchemaFileLocater.js +212 -212
  4. package/lib/cjs/SchemaFileLocater.js.map +1 -1
  5. package/lib/cjs/SchemaFileUtility.d.ts +17 -17
  6. package/lib/cjs/SchemaFileUtility.js +48 -48
  7. package/lib/cjs/SchemaFileUtility.js.map +1 -1
  8. package/lib/cjs/SchemaJsonFileLocater.d.ts +33 -33
  9. package/lib/cjs/SchemaJsonFileLocater.js +90 -90
  10. package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
  11. package/lib/cjs/SchemaXmlFileLocater.d.ts +33 -33
  12. package/lib/cjs/SchemaXmlFileLocater.js +93 -93
  13. package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
  14. package/lib/cjs/StubSchemaXmlFileLocater.d.ts +69 -69
  15. package/lib/cjs/StubSchemaXmlFileLocater.js +177 -177
  16. package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
  17. package/lib/cjs/ecschema-locaters.d.ts +17 -17
  18. package/lib/cjs/ecschema-locaters.js +37 -33
  19. package/lib/cjs/ecschema-locaters.js.map +1 -1
  20. package/lib/cjs/test/SchemaFileUtility.test.d.ts +1 -1
  21. package/lib/cjs/test/SchemaFileUtility.test.js +56 -56
  22. package/lib/cjs/test/SchemaFileUtility.test.js.map +1 -1
  23. package/lib/cjs/test/SchemaJsonFileLocator.test.d.ts +1 -1
  24. package/lib/cjs/test/SchemaJsonFileLocator.test.js +119 -119
  25. package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
  26. package/lib/cjs/test/SchemaXmlFileLocator.test.d.ts +1 -1
  27. package/lib/cjs/test/SchemaXmlFileLocator.test.js +180 -180
  28. package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
  29. package/lib/cjs/test/StubSchemaXmlFileLocater.test.d.ts +1 -1
  30. package/lib/cjs/test/StubSchemaXmlFileLocater.test.js +170 -170
  31. package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
  32. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaFileLocater.js","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,gEAA6F;AAE7F;;GAEG;AAEH,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;QAC7B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;SAAM;QACL,YAAY,GAAG,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC;QACzC,IAAI,YAAY,GAAG,SAAS,CAAC,MAAM,EAAE;YACnC,SAAS,IAAI,SAAS,CAAC,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC,MA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,CAAC,qBAAqB,MAAM,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;SACnG;aAAM;YACL,gBAAgB,GAAG,YAAY,CAAC,qBAAqB,MAAM,EAAE,EAAE,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;SAC3K;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;YACzC,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;SAC5G;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CAaF;AA9KD,8CA8KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as fs from \"fs\";\r\nimport * as glob from \"glob\";\r\nimport * as path from \"path\";\r\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\n\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\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 * @beta\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 * @beta - Needs further testing and possibly moved to a separate package.\r\n */\r\nexport abstract class SchemaFileLocater {\r\n public searchPaths: string[];\r\n\r\n constructor() {\r\n this.searchPaths = [];\r\n }\r\n\r\n public 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 public readUtf8FileToStringSync(filePath: string): string | undefined {\r\n return fs.readFileSync(filePath, \"utf-8\");\r\n }\r\n\r\n public 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 public 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 = new glob.GlobSync(fullPath, { sync: true });\r\n for (const match of result.found) {\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 */\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 public abstract getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | 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 */\r\n public compareSchemaKeyByVersion = (lhs: FileSchemaKey, rhs: FileSchemaKey): number => {\r\n return lhs.compareByVersion(rhs);\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaFileLocater.js","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,gEAA6F;AAE7F;;GAEG;AAEH,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,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BAAsB,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;SAC5G;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CAaF;AA9KD,8CA8KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as fs from \"fs\";\nimport * as glob from \"glob\";\nimport * as path from \"path\";\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\n\n/** @packageDocumentation\n * @module Locaters\n */\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 = new glob.GlobSync(fullPath, { sync: true });\n for (const match of result.found) {\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 public abstract getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | 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,18 +1,18 @@
1
- import { Schema } from "@itwin/ecschema-metadata";
2
- /** @packageDocumentation
3
- * @module Utils
4
- */
5
- /**
6
- * Utility class to assist in creating serialized EC Schemas on the file system.
7
- * @beta
8
- */
9
- export declare class SchemaFileUtility {
10
- /**
11
- * Writes a Schema to an xml file to the specified output path.
12
- * @param schema The Schema to serialize.
13
- * @param outputPath The directory in which to create the file.
14
- */
15
- static writeSchemaXmlFile(schema: Schema, outputPath: string): Promise<void>;
16
- private static getSchemaPath;
17
- }
1
+ import { Schema } from "@itwin/ecschema-metadata";
2
+ /** @packageDocumentation
3
+ * @module Utils
4
+ */
5
+ /**
6
+ * Utility class to assist in creating serialized EC Schemas on the file system.
7
+ * @beta
8
+ */
9
+ export declare class SchemaFileUtility {
10
+ /**
11
+ * Writes a Schema to an xml file to the specified output path.
12
+ * @param schema The Schema to serialize.
13
+ * @param outputPath The directory in which to create the file.
14
+ */
15
+ static writeSchemaXmlFile(schema: Schema, outputPath: string): Promise<void>;
16
+ private static getSchemaPath;
17
+ }
18
18
  //# sourceMappingURL=SchemaFileUtility.d.ts.map
@@ -1,49 +1,49 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchemaFileUtility = void 0;
4
- /*---------------------------------------------------------------------------------------------
5
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
- * See LICENSE.md in the project root for license terms and full copyright notice.
7
- *--------------------------------------------------------------------------------------------*/
8
- const fs = require("fs-extra");
9
- const path = require("path");
10
- const xmldom_1 = require("@xmldom/xmldom");
11
- /** @packageDocumentation
12
- * @module Utils
13
- */
14
- /**
15
- * Utility class to assist in creating serialized EC Schemas on the file system.
16
- * @beta
17
- */
18
- class SchemaFileUtility {
19
- /**
20
- * Writes a Schema to an xml file to the specified output path.
21
- * @param schema The Schema to serialize.
22
- * @param outputPath The directory in which to create the file.
23
- */
24
- static async writeSchemaXmlFile(schema, outputPath) {
25
- let xmlDoc = new xmldom_1.DOMParser().parseFromString(`<?xml version="1.0" encoding="UTF-8"?>`, "application/xml");
26
- const baseFile = this.getSchemaPath(schema, outputPath);
27
- xmlDoc = await schema.toXml(xmlDoc);
28
- const serializer = new xmldom_1.XMLSerializer();
29
- const xml = serializer.serializeToString(xmlDoc);
30
- try {
31
- await fs.writeFile(baseFile, xml);
32
- }
33
- catch (err) {
34
- const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;
35
- throw new Error(msg);
36
- }
37
- }
38
- static getSchemaPath(schema, outputPath) {
39
- const realDir = path.normalize(outputPath);
40
- const test = fs.pathExistsSync(realDir);
41
- if (!test) {
42
- const msg = `The output directory '${realDir}' does not exist.`;
43
- throw new Error(msg);
44
- }
45
- return path.resolve(realDir, `${schema.name}.ecschema.xml`);
46
- }
47
- }
48
- exports.SchemaFileUtility = SchemaFileUtility;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaFileUtility = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const fs = require("fs-extra");
9
+ const path = require("path");
10
+ const xmldom_1 = require("@xmldom/xmldom");
11
+ /** @packageDocumentation
12
+ * @module Utils
13
+ */
14
+ /**
15
+ * Utility class to assist in creating serialized EC Schemas on the file system.
16
+ * @beta
17
+ */
18
+ class SchemaFileUtility {
19
+ /**
20
+ * Writes a Schema to an xml file to the specified output path.
21
+ * @param schema The Schema to serialize.
22
+ * @param outputPath The directory in which to create the file.
23
+ */
24
+ static async writeSchemaXmlFile(schema, outputPath) {
25
+ let xmlDoc = new xmldom_1.DOMParser().parseFromString(`<?xml version="1.0" encoding="UTF-8"?>`, "application/xml");
26
+ const baseFile = this.getSchemaPath(schema, outputPath);
27
+ xmlDoc = await schema.toXml(xmlDoc);
28
+ const serializer = new xmldom_1.XMLSerializer();
29
+ const xml = serializer.serializeToString(xmlDoc);
30
+ try {
31
+ await fs.writeFile(baseFile, xml);
32
+ }
33
+ catch (err) {
34
+ const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;
35
+ throw new Error(msg);
36
+ }
37
+ }
38
+ static getSchemaPath(schema, outputPath) {
39
+ const realDir = path.normalize(outputPath);
40
+ const test = fs.pathExistsSync(realDir);
41
+ if (!test) {
42
+ const msg = `The output directory '${realDir}' does not exist.`;
43
+ throw new Error(msg);
44
+ }
45
+ return path.resolve(realDir, `${schema.name}.ecschema.xml`);
46
+ }
47
+ }
48
+ exports.SchemaFileUtility = SchemaFileUtility;
49
49
  //# sourceMappingURL=SchemaFileUtility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaFileUtility.js","sourceRoot":"","sources":["../../src/SchemaFileUtility.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAA+B;AAC/B,6BAA6B;AAC7B,2CAA0D;AAG1D;;GAEG;AAEH;;;GAGG;AACH,MAAa,iBAAiB;IAE5B;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,UAAkB;QACvE,IAAI,MAAM,GAAG,IAAI,kBAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAC1G,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAExD,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,sBAAa,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAEjD,IAAI;YACF,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;SACnC;QAAC,OAAO,GAAQ,EAAE;YACjB,MAAM,GAAG,GAAG,sCAAsC,QAAQ,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;IACH,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,MAAc,EAAE,UAAkB;QAC7D,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;YACT,MAAM,GAAG,GAAG,yBAAyB,OAAO,mBAAmB,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;CACF;AAjCD,8CAiCC","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\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/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\n/**\r\n * Utility class to assist in creating serialized EC Schemas on the file system.\r\n * @beta\r\n */\r\nexport class SchemaFileUtility {\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 public static async writeSchemaXmlFile(schema: Schema, outputPath: string) {\r\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\r\n const baseFile = this.getSchemaPath(schema, outputPath);\r\n\r\n xmlDoc = await schema.toXml(xmlDoc);\r\n const serializer = new XMLSerializer();\r\n const xml = serializer.serializeToString(xmlDoc);\r\n\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 private static 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
+ {"version":3,"file":"SchemaFileUtility.js","sourceRoot":"","sources":["../../src/SchemaFileUtility.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAA+B;AAC/B,6BAA6B;AAC7B,2CAA0D;AAG1D;;GAEG;AAEH;;;GAGG;AACH,MAAa,iBAAiB;IAE5B;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,UAAkB;QACvE,IAAI,MAAM,GAAG,IAAI,kBAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAC1G,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAExD,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,sBAAa,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAEjD,IAAI;YACF,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;SACnC;QAAC,OAAO,GAAQ,EAAE;YACjB,MAAM,GAAG,GAAG,sCAAsC,QAAQ,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;IACH,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,MAAc,EAAE,UAAkB;QAC7D,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;YACT,MAAM,GAAG,GAAG,yBAAyB,OAAO,mBAAmB,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;CACF;AAjCD,8CAiCC","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*--------------------------------------------------------------------------------------------*/\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/** @packageDocumentation\n * @module Utils\n */\n\n/**\n * Utility class to assist in creating serialized EC Schemas on the file system.\n * @beta\n */\nexport class SchemaFileUtility {\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 public static async writeSchemaXmlFile(schema: Schema, outputPath: string) {\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\n const baseFile = this.getSchemaPath(schema, outputPath);\n\n xmlDoc = await schema.toXml(xmlDoc);\n const serializer = new XMLSerializer();\n const xml = serializer.serializeToString(xmlDoc);\n\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 private static 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,34 +1,34 @@
1
- import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
- import { SchemaFileLocater } from "./SchemaFileLocater";
3
- /** @packageDocumentation
4
- * @module Locaters
5
- */
6
- /**
7
- * A SchemaLocator implementation for locating JSON Schema files
8
- * from the file system using configurable search paths.
9
- * @beta
10
- */
11
- export declare class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {
12
- /**
13
- * Constructs a SchemaKey based on the information in the Schema JSON
14
- * @param data The Schema JSON as a string
15
- */
16
- protected getSchemaKey(data: string): SchemaKey;
17
- /**
18
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
19
- * search paths to locate the JSON schema file from the file system.
20
- * @param key The SchemaKey of the Schema to retrieve.
21
- * @param matchType The SchemaMatchType.
22
- * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
23
- */
24
- getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
25
- /**
26
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
27
- * search paths to locate the JSON schema file from the file system.
28
- * @param key The SchemaKey of the Schema to retrieve.
29
- * @param matchType The SchemaMatchType
30
- * @param context The SchemaContext that will control the lifetime of the schema.
31
- */
32
- getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
33
- }
1
+ import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
+ import { SchemaFileLocater } from "./SchemaFileLocater";
3
+ /** @packageDocumentation
4
+ * @module Locaters
5
+ */
6
+ /**
7
+ * A SchemaLocator implementation for locating JSON Schema files
8
+ * from the file system using configurable search paths.
9
+ * @beta
10
+ */
11
+ export declare class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {
12
+ /**
13
+ * Constructs a SchemaKey based on the information in the Schema JSON
14
+ * @param data The Schema JSON as a string
15
+ */
16
+ protected getSchemaKey(data: string): SchemaKey;
17
+ /**
18
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
19
+ * search paths to locate the JSON schema file from the file system.
20
+ * @param key The SchemaKey of the Schema to retrieve.
21
+ * @param matchType The SchemaMatchType.
22
+ * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
23
+ */
24
+ getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
25
+ /**
26
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
27
+ * search paths to locate the JSON schema file from the file system.
28
+ * @param key The SchemaKey of the Schema to retrieve.
29
+ * @param matchType The SchemaMatchType
30
+ * @param context The SchemaContext that will control the lifetime of the schema.
31
+ */
32
+ getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
33
+ }
34
34
  //# sourceMappingURL=SchemaJsonFileLocater.d.ts.map
@@ -1,91 +1,91 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SchemaJsonFileLocater = void 0;
8
- const fs = require("fs");
9
- const path = require("path");
10
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
11
- const SchemaFileLocater_1 = require("./SchemaFileLocater");
12
- /** @packageDocumentation
13
- * @module Locaters
14
- */
15
- /**
16
- * A SchemaLocator implementation for locating JSON Schema files
17
- * from the file system using configurable search paths.
18
- * @beta
19
- */
20
- class SchemaJsonFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
21
- /**
22
- * Constructs a SchemaKey based on the information in the Schema JSON
23
- * @param data The Schema JSON as a string
24
- */
25
- getSchemaKey(data) {
26
- const dataJson = JSON.parse(data);
27
- // Check if the name is present
28
- if (!(dataJson.name))
29
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);
30
- // Check if versions is present
31
- if (!(dataJson.version))
32
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);
33
- // Get the name and version from the JSON
34
- const schemaName = dataJson.name;
35
- const schemaVersion = dataJson.version;
36
- const key = new ecschema_metadata_1.SchemaKey(schemaName.toString(), ecschema_metadata_1.ECVersion.fromString(schemaVersion.toString()));
37
- return key;
38
- }
39
- /**
40
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
41
- * search paths to locate the JSON schema file from the file system.
42
- * @param key The SchemaKey of the Schema to retrieve.
43
- * @param matchType The SchemaMatchType.
44
- * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
45
- */
46
- async getSchema(schemaKey, matchType, context) {
47
- // Grab all schema files that match the schema key
48
- const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
49
- if (!candidates || candidates.length === 0)
50
- return undefined;
51
- // eslint-disable-next-line @typescript-eslint/unbound-method
52
- const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
53
- const schemaPath = maxCandidate.fileName;
54
- // Load the file
55
- if (!await this.fileExists(schemaPath))
56
- return undefined;
57
- const schemaText = await this.readUtf8FileToString(schemaPath);
58
- if (!schemaText)
59
- return undefined;
60
- this.addSchemaSearchPaths([path.dirname(schemaPath)]);
61
- const schema = await ecschema_metadata_1.Schema.fromJson(schemaText, context);
62
- return schema;
63
- }
64
- /**
65
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
66
- * search paths to locate the JSON schema file from the file system.
67
- * @param key The SchemaKey of the Schema to retrieve.
68
- * @param matchType The SchemaMatchType
69
- * @param context The SchemaContext that will control the lifetime of the schema.
70
- */
71
- getSchemaSync(schemaKey, matchType, context) {
72
- // Grab all schema files that match the schema key
73
- const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
74
- if (!candidates || candidates.length === 0)
75
- return undefined;
76
- // eslint-disable-next-line @typescript-eslint/unbound-method
77
- const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
78
- const schemaPath = maxCandidate.fileName;
79
- // Load the file
80
- if (!fs.existsSync(schemaPath))
81
- return undefined;
82
- const schemaText = fs.readFileSync(schemaPath, "utf-8");
83
- if (!schemaText)
84
- return undefined;
85
- this.addSchemaSearchPaths([path.dirname(schemaPath)]);
86
- const schema = ecschema_metadata_1.Schema.fromJsonSync(schemaText, context);
87
- return schema;
88
- }
89
- }
90
- exports.SchemaJsonFileLocater = SchemaJsonFileLocater;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SchemaJsonFileLocater = void 0;
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
11
+ const SchemaFileLocater_1 = require("./SchemaFileLocater");
12
+ /** @packageDocumentation
13
+ * @module Locaters
14
+ */
15
+ /**
16
+ * A SchemaLocator implementation for locating JSON Schema files
17
+ * from the file system using configurable search paths.
18
+ * @beta
19
+ */
20
+ class SchemaJsonFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
21
+ /**
22
+ * Constructs a SchemaKey based on the information in the Schema JSON
23
+ * @param data The Schema JSON as a string
24
+ */
25
+ getSchemaKey(data) {
26
+ const dataJson = JSON.parse(data);
27
+ // Check if the name is present
28
+ if (!(dataJson.name))
29
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);
30
+ // Check if versions is present
31
+ if (!(dataJson.version))
32
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);
33
+ // Get the name and version from the JSON
34
+ const schemaName = dataJson.name;
35
+ const schemaVersion = dataJson.version;
36
+ const key = new ecschema_metadata_1.SchemaKey(schemaName.toString(), ecschema_metadata_1.ECVersion.fromString(schemaVersion.toString()));
37
+ return key;
38
+ }
39
+ /**
40
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
41
+ * search paths to locate the JSON schema file from the file system.
42
+ * @param key The SchemaKey of the Schema to retrieve.
43
+ * @param matchType The SchemaMatchType.
44
+ * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
45
+ */
46
+ async getSchema(schemaKey, matchType, context) {
47
+ // Grab all schema files that match the schema key
48
+ const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
49
+ if (!candidates || candidates.length === 0)
50
+ return undefined;
51
+ // eslint-disable-next-line @typescript-eslint/unbound-method
52
+ const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
53
+ const schemaPath = maxCandidate.fileName;
54
+ // Load the file
55
+ if (!await this.fileExists(schemaPath))
56
+ return undefined;
57
+ const schemaText = await this.readUtf8FileToString(schemaPath);
58
+ if (!schemaText)
59
+ return undefined;
60
+ this.addSchemaSearchPaths([path.dirname(schemaPath)]);
61
+ const schema = await ecschema_metadata_1.Schema.fromJson(schemaText, context);
62
+ return schema;
63
+ }
64
+ /**
65
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
66
+ * search paths to locate the JSON schema file from the file system.
67
+ * @param key The SchemaKey of the Schema to retrieve.
68
+ * @param matchType The SchemaMatchType
69
+ * @param context The SchemaContext that will control the lifetime of the schema.
70
+ */
71
+ getSchemaSync(schemaKey, matchType, context) {
72
+ // Grab all schema files that match the schema key
73
+ const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
74
+ if (!candidates || candidates.length === 0)
75
+ return undefined;
76
+ // eslint-disable-next-line @typescript-eslint/unbound-method
77
+ const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
78
+ const schemaPath = maxCandidate.fileName;
79
+ // Load the file
80
+ if (!fs.existsSync(schemaPath))
81
+ return undefined;
82
+ const schemaText = fs.readFileSync(schemaPath, "utf-8");
83
+ if (!schemaText)
84
+ return undefined;
85
+ this.addSchemaSearchPaths([path.dirname(schemaPath)]);
86
+ const schema = ecschema_metadata_1.Schema.fromJsonSync(schemaText, context);
87
+ return schema;
88
+ }
89
+ }
90
+ exports.SchemaJsonFileLocater = SchemaJsonFileLocater;
91
91
  //# sourceMappingURL=SchemaJsonFileLocater.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,gEAEkC;AAClC,2DAAuE;AAEvE;;GAEG;AAEH;;;;GAIG;AACH,MAAa,qBAAsB,SAAQ,qCAAiB;IAE1D;;;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C;CACF;AAtFD,sDAsFC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\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 * @beta\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 */\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 ECObjectsError(ECObjectsStatus.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 ECObjectsError(ECObjectsStatus.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<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | 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 // eslint-disable-next-line @typescript-eslint/unbound-method\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 const schema = await Schema.fromJson(schemaText, context);\r\n return schema as T;\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<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | 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 // eslint-disable-next-line @typescript-eslint/unbound-method\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 as T;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaJs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AAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,0BAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAtFD,sDAsFC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\n/** @packageDocumentation\n * @module Locaters\n */\n\n/**\n * A SchemaLocator implementation for locating JSON Schema files\n * from the file system using configurable search paths.\n * @beta\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 */\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 ECObjectsError(ECObjectsStatus.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 ECObjectsError(ECObjectsStatus.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<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | 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 // eslint-disable-next-line @typescript-eslint/unbound-method\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 const schema = await Schema.fromJson(schemaText, context);\n return schema as T;\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<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | 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 // eslint-disable-next-line @typescript-eslint/unbound-method\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 as T;\n }\n}\n"]}
@@ -1,34 +1,34 @@
1
- import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
- import { SchemaFileLocater } from "./SchemaFileLocater";
3
- /** @packageDocumentation
4
- * @module Locaters
5
- */
6
- /**
7
- * A SchemaLocater implementation for locating XML Schema files
8
- * from the file system using configurable search paths.
9
- * @beta This is a workaround the current lack of a full xml parser.
10
- */
11
- export declare class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
12
- /**
13
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
14
- * to locate the XML Schema file from the file system.
15
- * @param key The SchemaKey of the Schema to retrieve.
16
- * @param matchType The SchemaMatchType.
17
- * @param context The SchemaContext that will control the lifetime of the schema.
18
- */
19
- getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
20
- /**
21
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
22
- * to locate the XML Schema file from the file system.
23
- * @param key The SchemaKey of the Schema to retrieve.
24
- * @param matchType The SchemaMatchType.
25
- * @param context The SchemaContext that will control the lifetime of the schema.
26
- */
27
- getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
28
- /**
29
- * Constructs a SchemaKey based on the information in the Schema XML.
30
- * @param data The Schema XML as a string.
31
- */
32
- getSchemaKey(data: string): SchemaKey;
33
- }
1
+ import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
+ import { SchemaFileLocater } from "./SchemaFileLocater";
3
+ /** @packageDocumentation
4
+ * @module Locaters
5
+ */
6
+ /**
7
+ * A SchemaLocater implementation for locating XML Schema files
8
+ * from the file system using configurable search paths.
9
+ * @beta This is a workaround the current lack of a full xml parser.
10
+ */
11
+ export declare class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
12
+ /**
13
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
14
+ * to locate the XML Schema file from the file system.
15
+ * @param key The SchemaKey of the Schema to retrieve.
16
+ * @param matchType The SchemaMatchType.
17
+ * @param context The SchemaContext that will control the lifetime of the schema.
18
+ */
19
+ getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
20
+ /**
21
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
22
+ * to locate the XML Schema file from the file system.
23
+ * @param key The SchemaKey of the Schema to retrieve.
24
+ * @param matchType The SchemaMatchType.
25
+ * @param context The SchemaContext that will control the lifetime of the schema.
26
+ */
27
+ getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
28
+ /**
29
+ * Constructs a SchemaKey based on the information in the Schema XML.
30
+ * @param data The Schema XML as a string.
31
+ */
32
+ getSchemaKey(data: string): SchemaKey;
33
+ }
34
34
  //# sourceMappingURL=SchemaXmlFileLocater.d.ts.map