@itwin/ecschema-locaters 4.10.0-dev.9 → 5.0.0-dev.0
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 +21 -1
- package/lib/cjs/SchemaJsonFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.js +0 -2
- package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.js +0 -2
- package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.js +0 -2
- package/lib/cjs/SchemaXmlStringLocater.js.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.js +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
# Change Log - @itwin/ecschema-locaters
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 22 Oct 2024 20:03:09 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.9.5
|
|
6
|
+
Tue, 22 Oct 2024 20:01:40 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.9.4
|
|
11
|
+
Wed, 09 Oct 2024 20:22:04 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 4.9.3
|
|
16
|
+
Thu, 03 Oct 2024 19:15:45 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 4.9.2
|
|
21
|
+
Wed, 02 Oct 2024 15:14:43 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
4
24
|
|
|
5
25
|
## 4.9.1
|
|
6
26
|
Wed, 25 Sep 2024 20:10:58 GMT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaJsonFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,iBAAkB,YAAW,cAAc;IAEpF;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAmB/C;;;;;;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;
|
|
1
|
+
{"version":3,"file":"SchemaJsonFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,iBAAkB,YAAW,cAAc;IAEpF;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAmB/C;;;;;;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;IAsBrI;;;;;;OAMG;IACI,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,CAAC,GAAG,SAAS;CAsBhI"}
|
|
@@ -60,7 +60,6 @@ class SchemaJsonFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
|
60
60
|
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
|
|
61
61
|
if (!candidates || candidates.length === 0)
|
|
62
62
|
return undefined;
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
64
63
|
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
65
64
|
const schemaPath = maxCandidate.fileName;
|
|
66
65
|
// Load the file
|
|
@@ -84,7 +83,6 @@ class SchemaJsonFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
|
84
83
|
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
|
|
85
84
|
if (!candidates || candidates.length === 0)
|
|
86
85
|
return undefined;
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
88
86
|
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
89
87
|
const schemaPath = maxCandidate.fileName;
|
|
90
88
|
// Load the file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater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AC;YACxC,OAAO,SAAS,CAAC;QAEnB,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5F,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC;QAEzC,gBAAgB;QAChB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC5B,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,0BAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAjGD,sDAiGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\n/**\r\n * A SchemaLocator implementation for locating JSON Schema files\r\n * from the file system using configurable search paths.\r\n * @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 await this.getSchemaInfo(schemaKey, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(schemaKey, matchType);\r\n return schema as T;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n // Grab all schema files that match the schema key\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaPath = maxCandidate.fileName;\r\n\r\n // Load the file\r\n if (!await this.fileExists(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = await this.readUtf8FileToString(schemaPath);\r\n if (!schemaText)\r\n return undefined;\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n\r\n return Schema.startLoadingFromJson(schemaText, context);\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\r\n * search paths to locate the JSON schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync<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 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEv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GAAG,SAAS;CAa7C"}
|
|
@@ -41,7 +41,6 @@ class SchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
|
41
41
|
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "xml");
|
|
42
42
|
if (0 === candidates.length)
|
|
43
43
|
return undefined;
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
45
44
|
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
46
45
|
const schemaPath = maxCandidate.fileName;
|
|
47
46
|
// Load the file
|
|
@@ -68,7 +67,6 @@ class SchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
|
68
67
|
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
69
68
|
if (!candidates || candidates.length === 0)
|
|
70
69
|
return undefined;
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
72
70
|
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
73
71
|
const schemaPath = maxCandidate.fileName;
|
|
74
72
|
// Load the file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,6BAA6B;AAC7B,2CAA2C;AAC3C,gEAEkC;AAClC,2DAAuE;AAEvE;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,qCAAiB;IACzD;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CAAmB,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACzG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC7D,OAAO,MAAW,CAAC;IACrB,CAAC;I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CAAC;QACrE,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArGD,oDAqGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as path from \"path\";\r\nimport { DOMParser } from \"@xmldom/xmldom\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\n/**\r\n * A SchemaLocater implementation for locating XML Schema files\r\n * from the file system using configurable search paths.\r\n * @beta This is a workaround the current lack of a full xml parser.\r\n */\r\nexport class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public async getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\r\n await this.getSchemaInfo(key, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(key, matchType);\r\n return schema as T;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"xml\");\r\n\r\n if (0 === candidates.length)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaPath = maxCandidate.fileName;\r\n\r\n // Load the file\r\n if (undefined === await this.fileExists(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = await this.readUtf8FileToString(schemaPath);\r\n if (undefined === schemaText)\r\n return undefined;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n const schema = new Schema(context);\r\n\r\n return reader.readSchemaInfo(schema, document);\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\r\n\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaPath = maxCandidate.fileName;\r\n\r\n // Load the file\r\n if (!this.fileExistsSync(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = this.readUtf8FileToStringSync(schemaPath);\r\n if (!schemaText)\r\n return undefined;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n let schema: Schema = new Schema(context);\r\n schema = reader.readSchemaSync(schema, document);\r\n\r\n return schema as T;\r\n }\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param data The Schema XML as a string.\r\n */\r\n public getSchemaKey(data: string): SchemaKey {\r\n const matches = data.match(/<ECSchema ([^]+?)>/g);\r\n if (!matches || matches.length !== 1)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\r\n\r\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\r\n const version = matches[0].match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !version || version.length !== 2)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\r\n\r\n const key = new SchemaKey(name[1], ECVersion.fromString(version[1]));\r\n return key;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,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;;;;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;
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,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;;;;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;IAkBrI;;;;;;OAMG;IACI,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,CAAC,GAAG,SAAS;IAmB/H;;;;OAIG;IACH,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -57,7 +57,6 @@ class SchemaXmlStringLocater extends SchemaStringLocater_1.SchemaStringLocater {
|
|
|
57
57
|
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
58
58
|
if (!candidates || candidates.length === 0)
|
|
59
59
|
return undefined;
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
61
60
|
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
62
61
|
const schemaText = maxCandidate.schemaText;
|
|
63
62
|
const parser = new xmldom_1.DOMParser();
|
|
@@ -78,7 +77,6 @@ class SchemaXmlStringLocater extends SchemaStringLocater_1.SchemaStringLocater {
|
|
|
78
77
|
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
79
78
|
if (!candidates || candidates.length === 0)
|
|
80
79
|
return undefined;
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
82
80
|
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
83
81
|
const schemaText = maxCandidate.schemaText;
|
|
84
82
|
const parser = new xmldom_1.DOMParser();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlStringLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2CAA2C;AAC3C,gEAEkC;AAClC,+DAA6E;AAE7E;;;;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,CAAC,MAAM,KAAK,CAAC;YAChE,MAAM,IAAI,kCAAc,CAAC,mCAAe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B,CAAC;IAED;;;;OAIG;IACK,cAAc,CAAC,aAAqB;QAC1C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAElI,IAAI,CAAC,KAAK;YACR,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;AAvGD,wDAuGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport { DOMParser } from \"@xmldom/xmldom\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaStringLocater, StringSchemaKey } from \"./SchemaStringLocater\";\r\n\r\n/**\r\n * A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings\r\n * loaded in memory.\r\n * @beta\r\n */\r\nexport class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param schemaXml The Schema XML as a string.\r\n */\r\n public getSchemaKey(schemaXml: string): SchemaKey {\r\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\r\n if (!matches || matches.length !== 1)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);\r\n\r\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\r\n const version = matches[0].match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !version || version.length !== 2)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given string`);\r\n\r\n const ecVersion = ECVersion.fromString(version[1]);\r\n const key = new SchemaKey(name[1], ecVersion);\r\n return key;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\r\n * Schema strings.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\r\n await this.getSchemaInfo(schemaKey, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(schemaKey, matchType);\r\n return schema as T;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n // Grab all schema strings that match the schema key\r\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaText = maxCandidate.schemaText;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n const schema = new Schema(context);\r\n\r\n return reader.readSchemaInfo(schema, document);\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\r\n * Schema strings.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\r\n // Grab all schema strings that match the schema key\r\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaText = maxCandidate.schemaText;\r\n\r\n const parser = new DOMParser();\r\n const document = parser.parseFromString(schemaText);\r\n\r\n const reader = new SchemaReadHelper(XmlParser, context);\r\n let schema: Schema = new Schema(context);\r\n schema = reader.readSchemaSync(schema, document);\r\n\r\n return schema as T;\r\n }\r\n\r\n /**\r\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\r\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\r\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\r\n */\r\n private fromECv2String(versionString: string): ECVersion {\r\n const [read, minor] = versionString.split(\".\");\r\n\r\n if (!read)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, 0, +minor);\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -74,7 +74,7 @@ class StubSchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
|
74
74
|
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
75
75
|
if (!candidates || candidates.length === 0)
|
|
76
76
|
return undefined;
|
|
77
|
-
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
77
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
78
78
|
const alias = this.getSchemaAlias(maxCandidate.schemaText);
|
|
79
79
|
const schema = new ecschema_metadata_1.Schema(context, maxCandidate, alias);
|
|
80
80
|
context.addSchemaSync(schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StubSchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/StubSchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,6BAA6B;AAC7B,gEAEkC;AAClC,2DAAuE;AAEvE,SAAS,YAAY,CAAC,UAAkB;IACtC,OAAO,mCAAmC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAa,wBAAyB,SAAQ,qCAAiB;IAC7D;;;;;OAKG;IACI,UAAU,CAAC,UAAkB,EAAE,UAAmB;QACvD,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,CAAC,UAAU;YACb,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,oBAAoB,EAAE,uCAAuC,UAAU,EAAE,CAAC,CAAC;QAEtH,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACtD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAI,iCAAa,EAAE,CAAC;QACpC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEzB,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,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACK,cAAc,CAAC,aAAqB;QAC1C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAElI,IAAI,CAAC,KAAK;YACR,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;CACF;AAnMD,4DAmMC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\nfunction isECv2Schema(schemaText: string): boolean {\r\n return /<ECSchema[^>]*xmlns=\".*ECXML.2.0\"/.test(schemaText);\r\n}\r\n\r\n/**\r\n * A SchemaLocater implementation for locating XML Schema files\r\n * from the file system using configurable search paths. Returns only\r\n * Schemas from XML files with their keys populated.\r\n * @internal\r\n */\r\nexport class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n /**\r\n * Loads a Schema from an XML file on the file system.\r\n * @param schemaPath The path to the Schema file.\r\n * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,\r\n * the schema will be read from the provided schemaPath.\r\n */\r\n public loadSchema(schemaPath: string, schemaText?: string): Schema {\r\n schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);\r\n if (!schemaText)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const key = this.getSchemaKey(schemaText);\r\n const alias = this.getSchemaAlias(schemaText);\r\n const context = new SchemaContext();\r\n context.addLocater(this);\r\n\r\n // Load the schema and return it\r\n const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);\r\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public async getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\r\n return this.getSchemaSync(key, matchType, context) as T;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n return this.getSchemaSync(key, matchType, context) as SchemaInfo;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\r\n\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1]; // eslint-disable-line @typescript-eslint/unbound-method\r\n const alias = this.getSchemaAlias(maxCandidate.schemaText!);\r\n const schema = new Schema(context, maxCandidate, alias) as T;\r\n context.addSchemaSync(schema);\r\n\r\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param schemaXml The Schema XML as a string.\r\n */\r\n public getSchemaKey(schemaXml: string): SchemaKey {\r\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\r\n if (!matches || matches.length !== 1)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\r\n\r\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\r\n const version = matches[0].match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !version || version.length !== 2)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\r\n\r\n let ecVersion: ECVersion;\r\n if (isECv2Schema(schemaXml))\r\n ecVersion = this.fromECv2String(version[1]);\r\n else\r\n ecVersion = ECVersion.fromString(version[1]);\r\n\r\n const key = new SchemaKey(name[1], ecVersion);\r\n return key;\r\n }\r\n\r\n /**\r\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\r\n * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.\r\n */\r\n private getSchemaReferenceKeys(schemaKey: FileSchemaKey): SchemaKey[] {\r\n return this._getSchemaReferenceKeys(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds schemas to the references collection for the given Schema by locating\r\n * the referenced schemas.\r\n * @param schema The schema for which to add the references.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n * @param refMatchType The SchemaMatchType to use when locating schema references.\r\n */\r\n private addSchemaReferences(schema: Schema, context: SchemaContext, refMatchType: SchemaMatchType): void {\r\n const refKeys = this.getSchemaReferenceKeys(schema.schemaKey as FileSchemaKey);\r\n\r\n for (const key of refKeys) {\r\n const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;\r\n if (!refSchema)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);\r\n\r\n schema.references.push(refSchema);\r\n }\r\n }\r\n\r\n /**\r\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\r\n * @param data The Schema XML string.\r\n */\r\n private _getSchemaReferenceKeys(xmlSchemaKey: FileSchemaKey): SchemaKey[] {\r\n const file = xmlSchemaKey.schemaText;\r\n\r\n if (!file)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);\r\n\r\n const data = file.toString().replace(/(\\s*)<!--[\\s\\S]*?--!?>/g, \"\"); // ignore any comments in the XML file when getting the array of SchemaKeys\r\n\r\n const keys: SchemaKey[] = [];\r\n const matches = data.match(/<ECSchemaReference ([^]+?)\\/>/g);\r\n if (!matches)\r\n return keys;\r\n\r\n for (const match of matches) {\r\n const name = match.match(/name=\"(.+?)\"/);\r\n const versionMatch = match.match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);\r\n\r\n // write version maybe missing, so insert \"0\"\r\n let versionString = versionMatch[1];\r\n const versionParts = versionString.split(\".\");\r\n if (versionParts.length === 2)\r\n versionParts.splice(1, 0, \"0\");\r\n\r\n versionString = versionParts.join(\".\");\r\n\r\n const key = new SchemaKey(name[1], ECVersion.fromString(versionString));\r\n keys.push(key);\r\n }\r\n\r\n return keys;\r\n }\r\n\r\n /**\r\n * Gets the Schema alias from the Schema XML.\r\n * @param data The Schema XML as a string.\r\n */\r\n private getSchemaAlias(schemaXml: string): string {\r\n let match: any;\r\n\r\n if (isECv2Schema(schemaXml)) {\r\n match = schemaXml.match(/<ECSchema.*nameSpacePrefix=\"(?<alias>\\w+)\"/) as any;\r\n } else {\r\n match = schemaXml.match(/<ECSchema.*alias=\"(?<alias>\\w+)\"/) as any;\r\n }\r\n\r\n if (!match || !match.groups.alias) {\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);\r\n }\r\n\r\n return match.groups.alias;\r\n }\r\n\r\n /**\r\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\r\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\r\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\r\n */\r\n private fromECv2String(versionString: string): ECVersion {\r\n const [read, minor] = versionString.split(\".\");\r\n\r\n if (!read)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, 0, +minor);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"StubSchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/StubSchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,6BAA6B;AAC7B,gEAEkC;AAClC,2DAAuE;AAEvE,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---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\nfunction isECv2Schema(schemaText: string): boolean {\r\n return /<ECSchema[^>]*xmlns=\".*ECXML.2.0\"/.test(schemaText);\r\n}\r\n\r\n/**\r\n * A SchemaLocater implementation for locating XML Schema files\r\n * from the file system using configurable search paths. Returns only\r\n * Schemas from XML files with their keys populated.\r\n * @internal\r\n */\r\nexport class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n /**\r\n * Loads a Schema from an XML file on the file system.\r\n * @param schemaPath The path to the Schema file.\r\n * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,\r\n * the schema will be read from the provided schemaPath.\r\n */\r\n public loadSchema(schemaPath: string, schemaText?: string): Schema {\r\n schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);\r\n if (!schemaText)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n const key = this.getSchemaKey(schemaText);\r\n const alias = this.getSchemaAlias(schemaText);\r\n const context = new SchemaContext();\r\n context.addLocater(this);\r\n\r\n // Load the schema and return it\r\n const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);\r\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public async getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\r\n return this.getSchemaSync(key, matchType, context) as T;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\r\n return this.getSchemaSync(key, matchType, context) as SchemaInfo;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\r\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\r\n * their keys populated.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\r\n\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const alias = this.getSchemaAlias(maxCandidate.schemaText!);\r\n const schema = new Schema(context, maxCandidate, alias) as T;\r\n context.addSchemaSync(schema);\r\n\r\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema XML.\r\n * @param schemaXml The Schema XML as a string.\r\n */\r\n public getSchemaKey(schemaXml: string): SchemaKey {\r\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\r\n if (!matches || matches.length !== 1)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\r\n\r\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\r\n const version = matches[0].match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !version || version.length !== 2)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\r\n\r\n let ecVersion: ECVersion;\r\n if (isECv2Schema(schemaXml))\r\n ecVersion = this.fromECv2String(version[1]);\r\n else\r\n ecVersion = ECVersion.fromString(version[1]);\r\n\r\n const key = new SchemaKey(name[1], ecVersion);\r\n return key;\r\n }\r\n\r\n /**\r\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\r\n * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.\r\n */\r\n private getSchemaReferenceKeys(schemaKey: FileSchemaKey): SchemaKey[] {\r\n return this._getSchemaReferenceKeys(schemaKey);\r\n }\r\n\r\n /**\r\n * Adds schemas to the references collection for the given Schema by locating\r\n * the referenced schemas.\r\n * @param schema The schema for which to add the references.\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n * @param refMatchType The SchemaMatchType to use when locating schema references.\r\n */\r\n private addSchemaReferences(schema: Schema, context: SchemaContext, refMatchType: SchemaMatchType): void {\r\n const refKeys = this.getSchemaReferenceKeys(schema.schemaKey as FileSchemaKey);\r\n\r\n for (const key of refKeys) {\r\n const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;\r\n if (!refSchema)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);\r\n\r\n schema.references.push(refSchema);\r\n }\r\n }\r\n\r\n /**\r\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\r\n * @param data The Schema XML string.\r\n */\r\n private _getSchemaReferenceKeys(xmlSchemaKey: FileSchemaKey): SchemaKey[] {\r\n const file = xmlSchemaKey.schemaText;\r\n\r\n if (!file)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);\r\n\r\n const data = file.toString().replace(/(\\s*)<!--[\\s\\S]*?--!?>/g, \"\"); // ignore any comments in the XML file when getting the array of SchemaKeys\r\n\r\n const keys: SchemaKey[] = [];\r\n const matches = data.match(/<ECSchemaReference ([^]+?)\\/>/g);\r\n if (!matches)\r\n return keys;\r\n\r\n for (const match of matches) {\r\n const name = match.match(/name=\"(.+?)\"/);\r\n const versionMatch = match.match(/version=\"(.+?)\"/);\r\n if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);\r\n\r\n // write version maybe missing, so insert \"0\"\r\n let versionString = versionMatch[1];\r\n const versionParts = versionString.split(\".\");\r\n if (versionParts.length === 2)\r\n versionParts.splice(1, 0, \"0\");\r\n\r\n versionString = versionParts.join(\".\");\r\n\r\n const key = new SchemaKey(name[1], ECVersion.fromString(versionString));\r\n keys.push(key);\r\n }\r\n\r\n return keys;\r\n }\r\n\r\n /**\r\n * Gets the Schema alias from the Schema XML.\r\n * @param data The Schema XML as a string.\r\n */\r\n private getSchemaAlias(schemaXml: string): string {\r\n let match: any;\r\n\r\n if (isECv2Schema(schemaXml)) {\r\n match = schemaXml.match(/<ECSchema.*nameSpacePrefix=\"(?<alias>\\w+)\"/) as any;\r\n } else {\r\n match = schemaXml.match(/<ECSchema.*alias=\"(?<alias>\\w+)\"/) as any;\r\n }\r\n\r\n if (!match || !match.groups.alias) {\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);\r\n }\r\n\r\n return match.groups.alias;\r\n }\r\n\r\n /**\r\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\r\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\r\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\r\n */\r\n private fromECv2String(versionString: string): ECVersion {\r\n const [read, minor] = versionString.split(\".\");\r\n\r\n if (!read)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\r\n\r\n if (!minor)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\r\n\r\n return new ECVersion(+read, 0, +minor);\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/ecschema-locaters",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-dev.0",
|
|
4
4
|
"description": "EC Schema file locaters",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/ecschema-locaters.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@bentley/spatial-composition-schema": "^1.0.1",
|
|
38
38
|
"@bentley/structural-physical-schema": "^1.0.1",
|
|
39
39
|
"@bentley/units-schema": "^1.0.8",
|
|
40
|
-
"@itwin/eslint-plugin": "
|
|
40
|
+
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
41
41
|
"@types/chai": "4.3.1",
|
|
42
42
|
"@types/chai-as-promised": "^7",
|
|
43
43
|
"@types/fs-extra": "^4.0.7",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"chai": "^4.3.10",
|
|
49
49
|
"chai-as-promised": "^7.1.1",
|
|
50
50
|
"cpx2": "^3.0.0",
|
|
51
|
-
"eslint": "^
|
|
51
|
+
"eslint": "^9.13.0",
|
|
52
52
|
"mocha": "^10.2.0",
|
|
53
53
|
"nyc": "^15.1.0",
|
|
54
54
|
"rimraf": "^3.0.2",
|
|
55
55
|
"sinon": "^17.0.2",
|
|
56
|
-
"typescript": "~5.
|
|
57
|
-
"@itwin/build-tools": "
|
|
58
|
-
"@itwin/ecschema-metadata": "
|
|
56
|
+
"typescript": "~5.6.2",
|
|
57
|
+
"@itwin/build-tools": "5.0.0-dev.0",
|
|
58
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"glob": "^10.3.12",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@xmldom/xmldom": "~0.8.5"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@itwin/ecschema-metadata": "^
|
|
66
|
+
"@itwin/ecschema-metadata": "^5.0.0-dev.0"
|
|
67
67
|
},
|
|
68
68
|
"nyc": {
|
|
69
69
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"clean": "rimraf lib .rush/temp/package-deps*.json",
|
|
76
76
|
"copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/cjs/test/assets",
|
|
77
77
|
"extract-api": "betools extract-api --entry=ecschema-locaters",
|
|
78
|
-
"lint": "eslint
|
|
78
|
+
"lint": "eslint \"./src/**/*.ts\" 1>&2",
|
|
79
79
|
"test": "mocha",
|
|
80
80
|
"docs": "betools docs --includes=../../generated-docs/extract --json=../../generated-docs/core/ecschema-locaters/file.json --tsIndexFile=./ecschema-locaters.ts --onlyJson",
|
|
81
81
|
"cover": "nyc npm -s test",
|