@itwin/ecschema-locaters 4.1.0-dev.8 → 4.1.0-dev.80
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 +74 -1
- package/lib/cjs/SchemaFileLocater.js.map +1 -1
- package/lib/cjs/SchemaFileUtility.js.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
- package/lib/cjs/SchemaStringLocater.d.ts +54 -0
- package/lib/cjs/SchemaStringLocater.d.ts.map +1 -0
- package/lib/cjs/SchemaStringLocater.js +85 -0
- package/lib/cjs/SchemaStringLocater.js.map +1 -0
- package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.d.ts +48 -0
- package/lib/cjs/SchemaXmlStringLocater.d.ts.map +1 -0
- package/lib/cjs/SchemaXmlStringLocater.js +106 -0
- package/lib/cjs/SchemaXmlStringLocater.js.map +1 -0
- package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/ecschema-locaters.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaJson.test.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaXml.test.js.map +1 -1
- package/lib/cjs/test/SchemaFileUtility.test.js.map +1 -1
- package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlStringLocater.test.d.ts +2 -0
- package/lib/cjs/test/SchemaXmlStringLocater.test.d.ts.map +1 -0
- package/lib/cjs/test/SchemaXmlStringLocater.test.js +221 -0
- package/lib/cjs/test/SchemaXmlStringLocater.test.js.map +1 -0
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
- package/package.json +9 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
# Change Log - @itwin/ecschema-locaters
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 24 Jul 2023 12:35:20 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.0.6
|
|
6
|
+
Mon, 24 Jul 2023 05:07:33 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.0.5
|
|
11
|
+
Tue, 18 Jul 2023 12:21:56 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 4.0.4
|
|
16
|
+
Wed, 12 Jul 2023 15:50:01 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 4.0.3
|
|
21
|
+
Mon, 03 Jul 2023 15:28:41 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 4.0.2
|
|
26
|
+
Wed, 21 Jun 2023 22:04:43 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 4.0.1
|
|
31
|
+
Wed, 21 Jun 2023 20:29:13 GMT
|
|
32
|
+
|
|
33
|
+
_Version update only_
|
|
34
|
+
|
|
35
|
+
## 4.0.0
|
|
36
|
+
Mon, 22 May 2023 15:34:14 GMT
|
|
37
|
+
|
|
38
|
+
### Updates
|
|
39
|
+
|
|
40
|
+
- Updated to support changes to async schema loading and `ISchemaLocater`
|
|
41
|
+
- Update to eslint@8
|
|
42
|
+
|
|
43
|
+
## 3.7.11
|
|
44
|
+
Tue, 11 Jul 2023 17:17:21 GMT
|
|
45
|
+
|
|
46
|
+
_Version update only_
|
|
47
|
+
|
|
48
|
+
## 3.7.10
|
|
49
|
+
Wed, 05 Jul 2023 13:41:21 GMT
|
|
50
|
+
|
|
51
|
+
_Version update only_
|
|
52
|
+
|
|
53
|
+
## 3.7.9
|
|
54
|
+
Tue, 20 Jun 2023 12:51:02 GMT
|
|
55
|
+
|
|
56
|
+
_Version update only_
|
|
57
|
+
|
|
58
|
+
## 3.7.8
|
|
59
|
+
Thu, 01 Jun 2023 17:00:39 GMT
|
|
60
|
+
|
|
61
|
+
_Version update only_
|
|
62
|
+
|
|
63
|
+
## 3.7.7
|
|
64
|
+
Wed, 24 May 2023 17:27:09 GMT
|
|
65
|
+
|
|
66
|
+
_Version update only_
|
|
67
|
+
|
|
68
|
+
## 3.7.6
|
|
69
|
+
Mon, 15 May 2023 18:23:41 GMT
|
|
70
|
+
|
|
71
|
+
_Version update only_
|
|
72
|
+
|
|
73
|
+
## 3.7.5
|
|
74
|
+
Thu, 04 May 2023 19:43:18 GMT
|
|
75
|
+
|
|
76
|
+
_Version update only_
|
|
4
77
|
|
|
5
78
|
## 3.7.4
|
|
6
79
|
Tue, 25 Apr 2023 17:50:35 GMT
|
|
@@ -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,CA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AC;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: Readonly<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: Readonly<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: Readonly<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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;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":["/*---------------------------------------------------------------------------------------------\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: 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 = 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: 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 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 +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,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACxD,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;IAED;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAc;QACvD,IAAI,MAAM,GAAG,IAAI,kBAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAE1G,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,sBAAa,EAAE,CAAC;QACvC,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9C,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;AAzCD,8CAyCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
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;;GA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AE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;CACF;AAzCD,8CAyCC","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 const xml = await this.writeSchemaToXmlString(schema);\n\n const baseFile = this.getSchemaPath(schema, outputPath);\n try {\n await fs.writeFile(baseFile, xml);\n } catch (err: any) {\n const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;\n throw new Error(msg);\n }\n }\n\n /**\n * Writes a Schema to an xml string.\n * @param schema The Schema to serialize.\n */\n public static async writeSchemaToXmlString(schema: Schema): Promise<string> {\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\n\n xmlDoc = await schema.toXml(xmlDoc);\n const serializer = new XMLSerializer();\n return serializer.serializeToString(xmlDoc);\n }\n\n 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"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,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC5B,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,0BAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAnGD,sDAmGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
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;;;OAGG;IACO,YAAY,CAAC,IAAY;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAElC,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAErH,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACrB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAErH,yCAAyC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC;QACjC,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC;QAEvC,MAAM,GAAG,GAAG,IAA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CAAC,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAmB,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QAC7G,kDAAkD;QAClD,MAAM,UAAU,GAAoB,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9F,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YACxC,OAAO,SAAS,CAAC;QAEnB,6DAA6D;QAC7D,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5F,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC;QAEzC,gBAAgB;QAChB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC5B,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,0BAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAnGD,sDAmGC","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, SchemaInfo, 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 await this.getSchemaInfo(schemaKey, matchType, context);\n\n const schema = await context.getCachedSchema(schemaKey, matchType);\n return schema as T;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n // Grab all schema files that match the schema key\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\n if (!candidates || candidates.length === 0)\n return undefined;\n\n // 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 return Schema.startLoadingFromJson(schemaText, context);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\n * search paths to locate the JSON schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync<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"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
2
|
+
/** @packageDocumentation
|
|
3
|
+
* @module Locaters
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A SchemaKey implementation that aids in identifying Schema strings via the
|
|
7
|
+
* addition of the schemaText property. The schemaText is the full XML string
|
|
8
|
+
* representation of the Schema.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export declare class StringSchemaKey extends SchemaKey {
|
|
12
|
+
schemaText: string;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new StringSchemaKey object.
|
|
15
|
+
* @param key The EC SchemaKey identifying the Schema.
|
|
16
|
+
* @param schemaText The string representation of the Schema
|
|
17
|
+
*/
|
|
18
|
+
constructor(key: SchemaKey, schemaText: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class SchemaStringLocater {
|
|
25
|
+
schemaStrings: string[];
|
|
26
|
+
constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Adds schema strings used by this locator to find the
|
|
29
|
+
* Schemas.
|
|
30
|
+
* @param schemaPaths An array of Schema strings to add
|
|
31
|
+
*/
|
|
32
|
+
addSchemaStrings(schemaStrings: string[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a schema string used by this locator to locate and load Schemas.
|
|
35
|
+
* @param schemaText The text of the Schema
|
|
36
|
+
*/
|
|
37
|
+
addSchemaString(schemaString: string): void;
|
|
38
|
+
protected abstract getSchemaKey(data: string): SchemaKey;
|
|
39
|
+
/**
|
|
40
|
+
* Attempts to find all Schema strings that match the desired SchemaKey.
|
|
41
|
+
* @param desiredKey The SchemaKey to match.
|
|
42
|
+
* @param matchType The SchemaMatchType.
|
|
43
|
+
*/
|
|
44
|
+
protected findEligibleSchemaKeys(desiredKey: Readonly<SchemaKey>, matchType: SchemaMatchType): StringSchemaKey[];
|
|
45
|
+
abstract getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
|
|
48
|
+
* left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.
|
|
49
|
+
* @param lhs The 'left-hand' StringSchemaKey.
|
|
50
|
+
* @param rhs The 'right-hand' StringSchemaKey.
|
|
51
|
+
*/
|
|
52
|
+
compareSchemaKeyByVersion: (lhs: StringSchemaKey, rhs: StringSchemaKey) => number;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=SchemaStringLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;GAEG;AAEH;;;;;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,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,eAAe,GAAG,eAAe,EAAE;aAehG,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAEvI;;;;;OAKG;IACI,yBAAyB,QAAS,eAAe,OAAO,eAAe,KAAG,MAAM,CAErF;CACH"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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.SchemaStringLocater = exports.StringSchemaKey = void 0;
|
|
8
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
9
|
+
/** @packageDocumentation
|
|
10
|
+
* @module Locaters
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A SchemaKey implementation that aids in identifying Schema strings via the
|
|
14
|
+
* addition of the schemaText property. The schemaText is the full XML string
|
|
15
|
+
* representation of the Schema.
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
class StringSchemaKey extends ecschema_metadata_1.SchemaKey {
|
|
19
|
+
/**
|
|
20
|
+
* Initializes a new StringSchemaKey object.
|
|
21
|
+
* @param key The EC SchemaKey identifying the Schema.
|
|
22
|
+
* @param schemaText The string representation of the Schema
|
|
23
|
+
*/
|
|
24
|
+
constructor(key, schemaText) {
|
|
25
|
+
super(key.name, key.version);
|
|
26
|
+
this.schemaText = schemaText;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.StringSchemaKey = StringSchemaKey;
|
|
30
|
+
/**
|
|
31
|
+
* Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater
|
|
32
|
+
* @beta
|
|
33
|
+
*/
|
|
34
|
+
class SchemaStringLocater {
|
|
35
|
+
constructor() {
|
|
36
|
+
/**
|
|
37
|
+
* Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
|
|
38
|
+
* left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.
|
|
39
|
+
* @param lhs The 'left-hand' StringSchemaKey.
|
|
40
|
+
* @param rhs The 'right-hand' StringSchemaKey.
|
|
41
|
+
*/
|
|
42
|
+
this.compareSchemaKeyByVersion = (lhs, rhs) => {
|
|
43
|
+
return lhs.compareByVersion(rhs);
|
|
44
|
+
};
|
|
45
|
+
this.schemaStrings = [];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Adds schema strings used by this locator to find the
|
|
49
|
+
* Schemas.
|
|
50
|
+
* @param schemaPaths An array of Schema strings to add
|
|
51
|
+
*/
|
|
52
|
+
addSchemaStrings(schemaStrings) {
|
|
53
|
+
// If the path is not in the schemaPaths array, add it
|
|
54
|
+
for (const schemaString of schemaStrings)
|
|
55
|
+
this.addSchemaString(schemaString);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Adds a schema string used by this locator to locate and load Schemas.
|
|
59
|
+
* @param schemaText The text of the Schema
|
|
60
|
+
*/
|
|
61
|
+
addSchemaString(schemaString) {
|
|
62
|
+
const schemaKey = this.getSchemaKey(schemaString);
|
|
63
|
+
// If the string is not in the schemaStrings array, add it
|
|
64
|
+
if (!this.schemaStrings.find((entry) => this.getSchemaKey(entry).matches(schemaKey, ecschema_metadata_1.SchemaMatchType.Exact)))
|
|
65
|
+
this.schemaStrings.push(schemaString);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Attempts to find all Schema strings that match the desired SchemaKey.
|
|
69
|
+
* @param desiredKey The SchemaKey to match.
|
|
70
|
+
* @param matchType The SchemaMatchType.
|
|
71
|
+
*/
|
|
72
|
+
findEligibleSchemaKeys(desiredKey, matchType) {
|
|
73
|
+
const foundStrings = new Array();
|
|
74
|
+
for (const schemaString of this.schemaStrings) {
|
|
75
|
+
// Get the schema key
|
|
76
|
+
const key = this.getSchemaKey(schemaString);
|
|
77
|
+
// If the key matches, put it in foundFiles
|
|
78
|
+
if (key.matches(desiredKey, matchType))
|
|
79
|
+
foundStrings.push(new StringSchemaKey(key, schemaString));
|
|
80
|
+
}
|
|
81
|
+
return foundStrings;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.SchemaStringLocater = SchemaStringLocater;
|
|
85
|
+
//# sourceMappingURL=SchemaStringLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.js","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gEAA6F;AAE7F;;GAEG;AAEH;;;;;GAKG;AACH,MAAa,eAAgB,SAAQ,6BAAS;IAI5C;;;;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;IAGvC;QAkDA;;;;;WAKG;QACI,8BAAyB,GAAG,CAAC,GAAoB,EAAE,GAAoB,EAAU,EAAE;YACxF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC,CAAC;QAzDA,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,UAA+B,EAAE,SAA0B;QAC1F,MAAM,YAAY,GAAG,IAAI,KAAK,EAAmB,CAAC;QAElD,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE;YAC7C,qBAAqB;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YAE5C,2CAA2C;YAC3C,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC;gBACpC,YAAY,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;SAC7D;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CAaF;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\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\n\n/** @packageDocumentation\n * @module Locaters\n */\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: Readonly<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<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' StringSchemaKey.\n * @param rhs The 'right-hand' StringSchemaKey.\n */\n public compareSchemaKeyByVersion = (lhs: StringSchemaKey, rhs: StringSchemaKey): number => {\n return lhs.compareByVersion(rhs);\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F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,GAAW,IAAI,0BAAM,CAAC,OAAO,CAAC,CAAC;QACzC,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEjD,OAAO,MAAW,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,IAAY;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,mDAAmD,CAAC,CAAC;QAElH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAChE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,6EAA6E,CAAC,CAAC;QAE5I,MAAM,GAAG,GAAG,IAAI,6BAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,6BAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAvGD,oDAuGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,6BAA6B;AAC7B,2CAA2C;AAC3C,gEAEkC;AAClC,2DAAuE;AAEvE;;GAEG;AAEH;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,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jD,OAAO,MAAW,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,IAAY;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,mDAAmD,CAAC,CAAC;QAElH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAChE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,6EAA6E,CAAC,CAAC;QAE5I,MAAM,GAAG,GAAG,IAAI,6BAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,6BAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAvGD,oDAuGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as path from \"path\";\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\n/** @packageDocumentation\n * @module Locaters\n */\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths.\n * @beta This is a workaround the current lack of a full xml parser.\n */\nexport class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public async getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\n await this.getSchemaInfo(key, matchType, context);\n\n const schema = await context.getCachedSchema(key, matchType);\n return schema as T;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"xml\");\n\n if (0 === candidates.length)\n return undefined;\n\n // 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 (undefined === await this.fileExists(schemaPath))\n return undefined;\n\n const schemaText = await this.readUtf8FileToString(schemaPath);\n if (undefined === schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\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 (!this.fileExistsSync(schemaPath))\n return undefined;\n\n const schemaText = this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema as T;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param data The Schema XML as a string.\n */\n public getSchemaKey(data: string): SchemaKey {\n const matches = data.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\n\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\n\n const key = new SchemaKey(name[1], ECVersion.fromString(version[1]));\n return key;\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { SchemaStringLocater } from "./SchemaStringLocater";
|
|
3
|
+
/** @packageDocumentation
|
|
4
|
+
* @module Locaters
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings
|
|
8
|
+
* loaded in memory.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export declare class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
14
|
+
* @param schemaXml The Schema XML as a string.
|
|
15
|
+
*/
|
|
16
|
+
getSchemaKey(schemaXml: string): SchemaKey;
|
|
17
|
+
/**
|
|
18
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
19
|
+
* Schema strings.
|
|
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
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
27
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
28
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
29
|
+
* @param matchType The match type to use when locating the schema
|
|
30
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
31
|
+
*/
|
|
32
|
+
getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
35
|
+
* Schema strings.
|
|
36
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
37
|
+
* @param matchType The SchemaMatchType.
|
|
38
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
39
|
+
*/
|
|
40
|
+
getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
43
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
44
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
45
|
+
*/
|
|
46
|
+
private fromECv2String;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=SchemaXmlStringLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAMA,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAE7E;;GAEG;AAEH;;;;GAIG;AACH,qBAAa,sBAAuB,SAAQ,mBAAoB,YAAW,cAAc;IAEvF;;;OAGG;IACI,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IAejD;;;;;;OAMG;IACU,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAO1I;;;;;;QAMI;IACS,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAmBrI;;;;;;OAMG;IACI,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,CAAC,GAAG,SAAS;IAoB/H;;;;OAIG;IACH,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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.SchemaXmlStringLocater = void 0;
|
|
8
|
+
const xmldom_1 = require("@xmldom/xmldom");
|
|
9
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
10
|
+
const SchemaStringLocater_1 = require("./SchemaStringLocater");
|
|
11
|
+
/** @packageDocumentation
|
|
12
|
+
* @module Locaters
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings
|
|
16
|
+
* loaded in memory.
|
|
17
|
+
* @beta
|
|
18
|
+
*/
|
|
19
|
+
class SchemaXmlStringLocater extends SchemaStringLocater_1.SchemaStringLocater {
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
22
|
+
* @param schemaXml The Schema XML as a string.
|
|
23
|
+
*/
|
|
24
|
+
getSchemaKey(schemaXml) {
|
|
25
|
+
const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
|
|
26
|
+
if (!matches || matches.length !== 1)
|
|
27
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);
|
|
28
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
29
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
30
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
31
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given string`);
|
|
32
|
+
const ecVersion = ecschema_metadata_1.ECVersion.fromString(version[1]);
|
|
33
|
+
const key = new ecschema_metadata_1.SchemaKey(name[1], ecVersion);
|
|
34
|
+
return key;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
38
|
+
* Schema strings.
|
|
39
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
40
|
+
* @param matchType The SchemaMatchType.
|
|
41
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
42
|
+
*/
|
|
43
|
+
async getSchema(schemaKey, matchType, context) {
|
|
44
|
+
await this.getSchemaInfo(schemaKey, matchType, context);
|
|
45
|
+
const schema = await context.getCachedSchema(schemaKey, matchType);
|
|
46
|
+
return schema;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
50
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
51
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
52
|
+
* @param matchType The match type to use when locating the schema
|
|
53
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
54
|
+
*/
|
|
55
|
+
async getSchemaInfo(schemaKey, matchType, context) {
|
|
56
|
+
// Grab all schema strings that match the schema key
|
|
57
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
58
|
+
if (!candidates || candidates.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
61
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
62
|
+
const schemaText = maxCandidate.schemaText;
|
|
63
|
+
const parser = new xmldom_1.DOMParser();
|
|
64
|
+
const document = parser.parseFromString(schemaText);
|
|
65
|
+
const reader = new ecschema_metadata_1.SchemaReadHelper(ecschema_metadata_1.XmlParser, context);
|
|
66
|
+
const schema = new ecschema_metadata_1.Schema(context);
|
|
67
|
+
return reader.readSchemaInfo(schema, document);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
71
|
+
* Schema strings.
|
|
72
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
73
|
+
* @param matchType The SchemaMatchType.
|
|
74
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
75
|
+
*/
|
|
76
|
+
getSchemaSync(schemaKey, matchType, context) {
|
|
77
|
+
// Grab all schema strings that match the schema key
|
|
78
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
79
|
+
if (!candidates || candidates.length === 0)
|
|
80
|
+
return undefined;
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
82
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
83
|
+
const schemaText = maxCandidate.schemaText;
|
|
84
|
+
const parser = new xmldom_1.DOMParser();
|
|
85
|
+
const document = parser.parseFromString(schemaText);
|
|
86
|
+
const reader = new ecschema_metadata_1.SchemaReadHelper(ecschema_metadata_1.XmlParser, context);
|
|
87
|
+
let schema = new ecschema_metadata_1.Schema(context);
|
|
88
|
+
schema = reader.readSchemaSync(schema, document);
|
|
89
|
+
return schema;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
93
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
94
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
95
|
+
*/
|
|
96
|
+
fromECv2String(versionString) {
|
|
97
|
+
const [read, minor] = versionString.split(".");
|
|
98
|
+
if (!read)
|
|
99
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
|
|
100
|
+
if (!minor)
|
|
101
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
|
|
102
|
+
return new ecschema_metadata_1.ECVersion(+read, 0, +minor);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.SchemaXmlStringLocater = SchemaXmlStringLocater;
|
|
106
|
+
//# sourceMappingURL=SchemaXmlStringLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,2CAA2C;AAC3C,gEAEkC;AAClC,+DAA6E;AAE7E;;GAEG;AAEH;;;;GAIG;AACH,MAAa,sBAAuB,SAAQ,yCAAmB;IAE7D;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,qDAAqD,CAAC,CAAC;QAEpH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO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ACR,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEnI,OAAO,IAAI,6BAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CAEF;AAzGD,wDAyGC","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 { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { SchemaStringLocater, StringSchemaKey } from \"./SchemaStringLocater\";\n\n/** @packageDocumentation\n * @module Locaters\n */\n\n/**\n * A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings\n * loaded in memory.\n * @beta\n */\nexport class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param schemaXml The Schema XML as a string.\n */\n public getSchemaKey(schemaXml: string): SchemaKey {\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);\n\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given string`);\n\n const ecVersion = ECVersion.fromString(version[1]);\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\n await this.getSchemaInfo(schemaKey, matchType, context);\n\n const schema = await context.getCachedSchema(schemaKey, matchType);\n return schema as T;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema as T;\n }\n\n /**\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\n */\n private fromECv2String(versionString: string): ECVersion {\n const [read, minor] = versionString.split(\".\");\n\n if (!read)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n return new ECVersion(+read, 0, +minor);\n }\n\n}\n"]}
|