@itwin/ecschema-locaters 5.0.0-dev.11 → 5.0.0-dev.111
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 +71 -1
- package/lib/cjs/SchemaFileLocater.d.ts +23 -8
- package/lib/cjs/SchemaFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaFileLocater.js +23 -11
- package/lib/cjs/SchemaFileLocater.js.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.d.ts +4 -3
- package/lib/cjs/SchemaJsonFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.js +4 -3
- package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
- package/lib/cjs/SchemaStringLocater.d.ts +2 -2
- package/lib/cjs/SchemaStringLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaStringLocater.js +12 -9
- package/lib/cjs/SchemaStringLocater.js.map +1 -1
- package/lib/cjs/SchemaXml.d.ts +1 -1
- package/lib/cjs/SchemaXml.js +1 -1
- package/lib/cjs/SchemaXml.js.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.d.ts +31 -3
- package/lib/cjs/SchemaXmlFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.js +46 -4
- package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.d.ts +2 -2
- package/lib/cjs/SchemaXmlStringLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.js +4 -4
- package/lib/cjs/SchemaXmlStringLocater.js.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.d.ts +2 -2
- package/lib/cjs/StubSchemaXmlFileLocater.d.ts.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.js +9 -9
- package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/ecschema-locaters.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaJson.test.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaXml.test.js.map +1 -1
- package/lib/cjs/test/SchemaJsonFileLocator.test.js +2 -2
- package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXml.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlFileLocator.test.js +12 -9
- package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlStringLocater.test.js +9 -9
- package/lib/cjs/test/SchemaXmlStringLocater.test.js.map +1 -1
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.js +9 -8
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
- package/lib/esm/SchemaFileLocater.d.ts +101 -0
- package/lib/esm/SchemaFileLocater.d.ts.map +1 -0
- package/lib/esm/SchemaFileLocater.js +220 -0
- package/lib/esm/SchemaFileLocater.js.map +1 -0
- package/lib/esm/SchemaJsonFileLocater.d.ts +43 -0
- package/lib/esm/SchemaJsonFileLocater.d.ts.map +1 -0
- package/lib/esm/SchemaJsonFileLocater.js +97 -0
- package/lib/esm/SchemaJsonFileLocater.js.map +1 -0
- package/lib/esm/SchemaStringLocater.d.ts +54 -0
- package/lib/esm/SchemaStringLocater.d.ts.map +1 -0
- package/lib/esm/SchemaStringLocater.js +83 -0
- package/lib/esm/SchemaStringLocater.js.map +1 -0
- package/lib/esm/SchemaXml.d.ts +22 -0
- package/lib/esm/SchemaXml.d.ts.map +1 -0
- package/lib/esm/SchemaXml.js +55 -0
- package/lib/esm/SchemaXml.js.map +1 -0
- package/lib/esm/SchemaXmlFileLocater.d.ts +70 -0
- package/lib/esm/SchemaXmlFileLocater.d.ts.map +1 -0
- package/lib/esm/SchemaXmlFileLocater.js +140 -0
- package/lib/esm/SchemaXmlFileLocater.js.map +1 -0
- package/lib/esm/SchemaXmlStringLocater.d.ts +48 -0
- package/lib/esm/SchemaXmlStringLocater.d.ts.map +1 -0
- package/lib/esm/SchemaXmlStringLocater.js +100 -0
- package/lib/esm/SchemaXmlStringLocater.js.map +1 -0
- package/lib/esm/StubSchemaXmlFileLocater.d.ts +81 -0
- package/lib/esm/StubSchemaXmlFileLocater.d.ts.map +1 -0
- package/lib/esm/StubSchemaXmlFileLocater.js +184 -0
- package/lib/esm/StubSchemaXmlFileLocater.js.map +1 -0
- package/lib/esm/ecschema-locaters.d.ts +20 -0
- package/lib/esm/ecschema-locaters.d.ts.map +1 -0
- package/lib/esm/ecschema-locaters.js +24 -0
- package/lib/esm/ecschema-locaters.js.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.d.ts +2 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.d.ts.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.js +249 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.js.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.d.ts +2 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.d.ts.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.js +186 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.js.map +1 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.d.ts +2 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.js +118 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.js.map +1 -0
- package/lib/esm/test/SchemaXml.test.d.ts +2 -0
- package/lib/esm/test/SchemaXml.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaXml.test.js +55 -0
- package/lib/esm/test/SchemaXml.test.js.map +1 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.d.ts +2 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.js +182 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.js.map +1 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.d.ts +2 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.js +219 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.js.map +1 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.d.ts +2 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.d.ts.map +1 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.js +170 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.js.map +1 -0
- package/package.json +14 -12
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Locaters
|
|
3
|
+
*/
|
|
4
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaStringLocater } from "./SchemaStringLocater";
|
|
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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | 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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | 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":"AAIA;;GAEG;AAGH,OAAO,EACqC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EACxH,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,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAO7H;;;;;;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,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;IAmBlH;;;;OAIG;IACH,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Locaters
|
|
7
|
+
*/
|
|
8
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
9
|
+
import { ECSchemaError, ECSchemaStatus, ECVersion, Schema, SchemaKey, SchemaReadHelper, XmlParser, } from "@itwin/ecschema-metadata";
|
|
10
|
+
import { SchemaStringLocater } from "./SchemaStringLocater";
|
|
11
|
+
/**
|
|
12
|
+
* A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings
|
|
13
|
+
* loaded in memory.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export class SchemaXmlStringLocater extends SchemaStringLocater {
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
19
|
+
* @param schemaXml The Schema XML as a string.
|
|
20
|
+
*/
|
|
21
|
+
getSchemaKey(schemaXml) {
|
|
22
|
+
const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
|
|
23
|
+
if (!matches || matches.length !== 1)
|
|
24
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);
|
|
25
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
26
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
27
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
28
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given string`);
|
|
29
|
+
const ecVersion = ECVersion.fromString(version[1]);
|
|
30
|
+
const key = new SchemaKey(name[1], ecVersion);
|
|
31
|
+
return key;
|
|
32
|
+
}
|
|
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
|
+
async getSchema(schemaKey, matchType, context) {
|
|
41
|
+
await this.getSchemaInfo(schemaKey, matchType, context);
|
|
42
|
+
const schema = await context.getCachedSchema(schemaKey, matchType);
|
|
43
|
+
return schema;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
47
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
48
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
49
|
+
* @param matchType The match type to use when locating the schema
|
|
50
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
51
|
+
*/
|
|
52
|
+
async getSchemaInfo(schemaKey, matchType, context) {
|
|
53
|
+
// Grab all schema strings that match the schema key
|
|
54
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
55
|
+
if (!candidates || candidates.length === 0)
|
|
56
|
+
return undefined;
|
|
57
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
58
|
+
const schemaText = maxCandidate.schemaText;
|
|
59
|
+
const parser = new DOMParser();
|
|
60
|
+
const document = parser.parseFromString(schemaText);
|
|
61
|
+
const reader = new SchemaReadHelper(XmlParser, context);
|
|
62
|
+
const schema = new Schema(context);
|
|
63
|
+
return reader.readSchemaInfo(schema, document);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
67
|
+
* Schema strings.
|
|
68
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
69
|
+
* @param matchType The SchemaMatchType.
|
|
70
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
71
|
+
*/
|
|
72
|
+
getSchemaSync(schemaKey, matchType, context) {
|
|
73
|
+
// Grab all schema strings that match the schema key
|
|
74
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
75
|
+
if (!candidates || candidates.length === 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
78
|
+
const schemaText = maxCandidate.schemaText;
|
|
79
|
+
const parser = new DOMParser();
|
|
80
|
+
const document = parser.parseFromString(schemaText);
|
|
81
|
+
const reader = new SchemaReadHelper(XmlParser, context);
|
|
82
|
+
let schema = new Schema(context);
|
|
83
|
+
schema = reader.readSchemaSync(schema, document);
|
|
84
|
+
return schema;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
88
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
89
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
90
|
+
*/
|
|
91
|
+
fromECv2String(versionString) {
|
|
92
|
+
const [read, minor] = versionString.split(".");
|
|
93
|
+
if (!read)
|
|
94
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
|
|
95
|
+
if (!minor)
|
|
96
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
|
|
97
|
+
return new ECVersion(+read, 0, +minor);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=SchemaXmlStringLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,aAAa,EAAE,cAAc,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,EAAmB,gBAAgB,EAAE,SAAS,GACrJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAE7E;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IAE7D;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,CAAC,CAAC;QAElH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MA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C,IAAI;YACP,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAEhI,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEjI,OAAO,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CAEF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Locaters\n */\n\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { SchemaStringLocater, StringSchemaKey } from \"./SchemaStringLocater\";\n\n/**\n * A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings\n * loaded in memory.\n * @beta\n */\nexport class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param schemaXml The Schema XML as a string.\n */\n public getSchemaKey(schemaXml: string): SchemaKey {\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);\n\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given string`);\n\n const ecVersion = ECVersion.fromString(version[1]);\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n await this.getSchemaInfo(schemaKey, matchType, context);\n\n const schema = await context.getCachedSchema(schemaKey, matchType);\n return schema as Schema;\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema;\n }\n\n /**\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\n */\n private fromECv2String(versionString: string): ECVersion {\n const [read, minor] = versionString.split(\".\");\n\n if (!read)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n return new ECVersion(+read, 0, +minor);\n }\n\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Locaters
|
|
3
|
+
*/
|
|
4
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
6
|
+
/**
|
|
7
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
8
|
+
* from the file system using configurable search paths. Returns only
|
|
9
|
+
* Schemas from XML files with their keys populated.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
|
|
13
|
+
/**
|
|
14
|
+
* Loads a Schema from an XML file on the file system.
|
|
15
|
+
* @param schemaPath The path to the Schema file.
|
|
16
|
+
* @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
|
|
17
|
+
* the schema will be read from the provided schemaPath.
|
|
18
|
+
*/
|
|
19
|
+
loadSchema(schemaPath: string, schemaText?: string): Schema;
|
|
20
|
+
/**
|
|
21
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
22
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
23
|
+
* their keys populated.
|
|
24
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
25
|
+
* @param matchType The SchemaMatchType.
|
|
26
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
27
|
+
*/
|
|
28
|
+
getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
31
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
32
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
33
|
+
* @param matchType The match type to use when locating the schema
|
|
34
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
35
|
+
*/
|
|
36
|
+
getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
39
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
40
|
+
* their keys populated.
|
|
41
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
42
|
+
* @param matchType The SchemaMatchType.
|
|
43
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
44
|
+
*/
|
|
45
|
+
getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
48
|
+
* @param schemaXml The Schema XML as a string.
|
|
49
|
+
*/
|
|
50
|
+
getSchemaKey(schemaXml: string): SchemaKey;
|
|
51
|
+
/**
|
|
52
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
53
|
+
* @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
|
|
54
|
+
*/
|
|
55
|
+
private getSchemaReferenceKeys;
|
|
56
|
+
/**
|
|
57
|
+
* Adds schemas to the references collection for the given Schema by locating
|
|
58
|
+
* the referenced schemas.
|
|
59
|
+
* @param schema The schema for which to add the references.
|
|
60
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
61
|
+
* @param refMatchType The SchemaMatchType to use when locating schema references.
|
|
62
|
+
*/
|
|
63
|
+
private addSchemaReferences;
|
|
64
|
+
/**
|
|
65
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
66
|
+
* @param data The Schema XML string.
|
|
67
|
+
*/
|
|
68
|
+
private _getSchemaReferenceKeys;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the Schema alias from the Schema XML.
|
|
71
|
+
* @param data The Schema XML as a string.
|
|
72
|
+
*/
|
|
73
|
+
private getSchemaAlias;
|
|
74
|
+
/**
|
|
75
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
76
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
77
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
78
|
+
*/
|
|
79
|
+
private fromECv2String;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=StubSchemaXmlFileLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StubSchemaXmlFileLocater.d.ts","sourceRoot":"","sources":["../../src/StubSchemaXmlFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EACqC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EACxH,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMvE;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,iBAAkB,YAAW,cAAc;IACvF;;;;;OAKG;IACI,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAiBlE;;;;;;;OAOG;IACU,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIvH;;;;;;QAMI;IACS,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAI/H;;;;;;;OAOG;IACI,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;IAe5G;;;OAGG;IACI,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IAoBjD;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAI9B;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAkC/B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAgBtB;;;;OAIG;IACH,OAAO,CAAC,cAAc;CAWvB"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Locaters
|
|
7
|
+
*/
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
import { ECSchemaError, ECSchemaStatus, ECVersion, Schema, SchemaContext, SchemaKey, SchemaMatchType, } from "@itwin/ecschema-metadata";
|
|
10
|
+
import { FileSchemaKey, SchemaFileLocater } from "./SchemaFileLocater";
|
|
11
|
+
function isECv2Schema(schemaText) {
|
|
12
|
+
return /<ECSchema[^>]*xmlns=".*ECXML.2.0"/.test(schemaText);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
16
|
+
* from the file system using configurable search paths. Returns only
|
|
17
|
+
* Schemas from XML files with their keys populated.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export class StubSchemaXmlFileLocater extends SchemaFileLocater {
|
|
21
|
+
/**
|
|
22
|
+
* Loads a Schema from an XML file on the file system.
|
|
23
|
+
* @param schemaPath The path to the Schema file.
|
|
24
|
+
* @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
|
|
25
|
+
* the schema will be read from the provided schemaPath.
|
|
26
|
+
*/
|
|
27
|
+
loadSchema(schemaPath, schemaText) {
|
|
28
|
+
schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);
|
|
29
|
+
if (!schemaText)
|
|
30
|
+
throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);
|
|
31
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
32
|
+
const key = this.getSchemaKey(schemaText);
|
|
33
|
+
const alias = this.getSchemaAlias(schemaText);
|
|
34
|
+
const context = new SchemaContext();
|
|
35
|
+
context.addLocater(this);
|
|
36
|
+
// Load the schema and return it
|
|
37
|
+
const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);
|
|
38
|
+
this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);
|
|
39
|
+
return schema;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
43
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
44
|
+
* their keys populated.
|
|
45
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
46
|
+
* @param matchType The SchemaMatchType.
|
|
47
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
48
|
+
*/
|
|
49
|
+
async getSchema(key, matchType, context) {
|
|
50
|
+
return this.getSchemaSync(key, matchType, context);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
54
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
55
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
56
|
+
* @param matchType The match type to use when locating the schema
|
|
57
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
58
|
+
*/
|
|
59
|
+
async getSchemaInfo(key, matchType, context) {
|
|
60
|
+
return this.getSchemaSync(key, matchType, context);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
64
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
65
|
+
* their keys populated.
|
|
66
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
67
|
+
* @param matchType The SchemaMatchType.
|
|
68
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
69
|
+
*/
|
|
70
|
+
getSchemaSync(key, matchType, context) {
|
|
71
|
+
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
72
|
+
if (!candidates || candidates.length === 0)
|
|
73
|
+
return undefined;
|
|
74
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
75
|
+
const alias = this.getSchemaAlias(maxCandidate.schemaText);
|
|
76
|
+
const schema = new Schema(context, maxCandidate, alias);
|
|
77
|
+
context.addSchemaSync(schema);
|
|
78
|
+
this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);
|
|
79
|
+
return schema;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
83
|
+
* @param schemaXml The Schema XML as a string.
|
|
84
|
+
*/
|
|
85
|
+
getSchemaKey(schemaXml) {
|
|
86
|
+
const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
|
|
87
|
+
if (!matches || matches.length !== 1)
|
|
88
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
|
|
89
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
90
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
91
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
92
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
|
|
93
|
+
let ecVersion;
|
|
94
|
+
if (isECv2Schema(schemaXml))
|
|
95
|
+
ecVersion = this.fromECv2String(version[1]);
|
|
96
|
+
else
|
|
97
|
+
ecVersion = ECVersion.fromString(version[1]);
|
|
98
|
+
const key = new SchemaKey(name[1], ecVersion);
|
|
99
|
+
return key;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
103
|
+
* @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
|
|
104
|
+
*/
|
|
105
|
+
getSchemaReferenceKeys(schemaKey) {
|
|
106
|
+
return this._getSchemaReferenceKeys(schemaKey);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Adds schemas to the references collection for the given Schema by locating
|
|
110
|
+
* the referenced schemas.
|
|
111
|
+
* @param schema The schema for which to add the references.
|
|
112
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
113
|
+
* @param refMatchType The SchemaMatchType to use when locating schema references.
|
|
114
|
+
*/
|
|
115
|
+
addSchemaReferences(schema, context, refMatchType) {
|
|
116
|
+
const refKeys = this.getSchemaReferenceKeys(schema.schemaKey);
|
|
117
|
+
for (const key of refKeys) {
|
|
118
|
+
const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;
|
|
119
|
+
if (!refSchema)
|
|
120
|
+
throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);
|
|
121
|
+
schema.references.push(refSchema);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
126
|
+
* @param data The Schema XML string.
|
|
127
|
+
*/
|
|
128
|
+
_getSchemaReferenceKeys(xmlSchemaKey) {
|
|
129
|
+
const file = xmlSchemaKey.schemaText;
|
|
130
|
+
if (!file)
|
|
131
|
+
throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);
|
|
132
|
+
const data = file.toString().replace(/(\s*)<!--[\s\S]*?--!?>/g, ""); // ignore any comments in the XML file when getting the array of SchemaKeys
|
|
133
|
+
const keys = [];
|
|
134
|
+
const matches = data.match(/<ECSchemaReference ([^]+?)\/>/g);
|
|
135
|
+
if (!matches)
|
|
136
|
+
return keys;
|
|
137
|
+
for (const match of matches) {
|
|
138
|
+
const name = match.match(/name="(.+?)"/);
|
|
139
|
+
const versionMatch = match.match(/version="(.+?)"/);
|
|
140
|
+
if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)
|
|
141
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);
|
|
142
|
+
// write version maybe missing, so insert "0"
|
|
143
|
+
let versionString = versionMatch[1];
|
|
144
|
+
const versionParts = versionString.split(".");
|
|
145
|
+
if (versionParts.length === 2)
|
|
146
|
+
versionParts.splice(1, 0, "0");
|
|
147
|
+
versionString = versionParts.join(".");
|
|
148
|
+
const key = new SchemaKey(name[1], ECVersion.fromString(versionString));
|
|
149
|
+
keys.push(key);
|
|
150
|
+
}
|
|
151
|
+
return keys;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the Schema alias from the Schema XML.
|
|
155
|
+
* @param data The Schema XML as a string.
|
|
156
|
+
*/
|
|
157
|
+
getSchemaAlias(schemaXml) {
|
|
158
|
+
let match;
|
|
159
|
+
if (isECv2Schema(schemaXml)) {
|
|
160
|
+
match = schemaXml.match(/<ECSchema.*nameSpacePrefix="(?<alias>\w+)"/);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
match = schemaXml.match(/<ECSchema.*alias="(?<alias>\w+)"/);
|
|
164
|
+
}
|
|
165
|
+
if (!match || !match.groups.alias) {
|
|
166
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);
|
|
167
|
+
}
|
|
168
|
+
return match.groups.alias;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
172
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
173
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
174
|
+
*/
|
|
175
|
+
fromECv2String(versionString) {
|
|
176
|
+
const [read, minor] = versionString.split(".");
|
|
177
|
+
if (!read)
|
|
178
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
|
|
179
|
+
if (!minor)
|
|
180
|
+
throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
|
|
181
|
+
return new ECVersion(+read, 0, +minor);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=StubSchemaXmlFileLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StubSchemaXmlFileLocater.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AAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAEhI,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEjI,OAAO,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Locaters\n */\n\nimport * as path from \"path\";\nimport {\n ECSchemaError, ECSchemaStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\nfunction isECv2Schema(schemaText: string): boolean {\n return /<ECSchema[^>]*xmlns=\".*ECXML.2.0\"/.test(schemaText);\n}\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths. Returns only\n * Schemas from XML files with their keys populated.\n * @internal\n */\nexport class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\n /**\n * Loads a Schema from an XML file on the file system.\n * @param schemaPath The path to the Schema file.\n * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,\n * the schema will be read from the provided schemaPath.\n */\n public loadSchema(schemaPath: string, schemaText?: string): Schema {\n schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const key = this.getSchemaKey(schemaText);\n const alias = this.getSchemaAlias(schemaText);\n const context = new SchemaContext();\n context.addLocater(this);\n\n // Load the schema and return it\n const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\n return schema;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n return this.getSchemaSync(key, matchType, context);\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n return this.getSchemaSync(key, matchType, context) as SchemaInfo;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const alias = this.getSchemaAlias(maxCandidate.schemaText!);\n const schema = new Schema(context, maxCandidate, alias);\n context.addSchemaSync(schema);\n\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\n return schema;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param schemaXml The Schema XML as a string.\n */\n public getSchemaKey(schemaXml: string): SchemaKey {\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\n\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\n\n let ecVersion: ECVersion;\n if (isECv2Schema(schemaXml))\n ecVersion = this.fromECv2String(version[1]);\n else\n ecVersion = ECVersion.fromString(version[1]);\n\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\n * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.\n */\n private getSchemaReferenceKeys(schemaKey: FileSchemaKey): SchemaKey[] {\n return this._getSchemaReferenceKeys(schemaKey);\n }\n\n /**\n * Adds schemas to the references collection for the given Schema by locating\n * the referenced schemas.\n * @param schema The schema for which to add the references.\n * @param context The SchemaContext that will control the lifetime of the schema.\n * @param refMatchType The SchemaMatchType to use when locating schema references.\n */\n private addSchemaReferences(schema: Schema, context: SchemaContext, refMatchType: SchemaMatchType): void {\n const refKeys = this.getSchemaReferenceKeys(schema.schemaKey as FileSchemaKey);\n\n for (const key of refKeys) {\n const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;\n if (!refSchema)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);\n\n schema.references.push(refSchema);\n }\n }\n\n /**\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\n * @param data The Schema XML string.\n */\n private _getSchemaReferenceKeys(xmlSchemaKey: FileSchemaKey): SchemaKey[] {\n const file = xmlSchemaKey.schemaText;\n\n if (!file)\n throw new ECSchemaError(ECSchemaStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);\n\n const data = file.toString().replace(/(\\s*)<!--[\\s\\S]*?--!?>/g, \"\"); // ignore any comments in the XML file when getting the array of SchemaKeys\n\n const keys: SchemaKey[] = [];\n const matches = data.match(/<ECSchemaReference ([^]+?)\\/>/g);\n if (!matches)\n return keys;\n\n for (const match of matches) {\n const name = match.match(/name=\"(.+?)\"/);\n const versionMatch = match.match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);\n\n // write version maybe missing, so insert \"0\"\n let versionString = versionMatch[1];\n const versionParts = versionString.split(\".\");\n if (versionParts.length === 2)\n versionParts.splice(1, 0, \"0\");\n\n versionString = versionParts.join(\".\");\n\n const key = new SchemaKey(name[1], ECVersion.fromString(versionString));\n keys.push(key);\n }\n\n return keys;\n }\n\n /**\n * Gets the Schema alias from the Schema XML.\n * @param data The Schema XML as a string.\n */\n private getSchemaAlias(schemaXml: string): string {\n let match: any;\n\n if (isECv2Schema(schemaXml)) {\n match = schemaXml.match(/<ECSchema.*nameSpacePrefix=\"(?<alias>\\w+)\"/) as any;\n } else {\n match = schemaXml.match(/<ECSchema.*alias=\"(?<alias>\\w+)\"/) as any;\n }\n\n if (!match || !match.groups.alias) {\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);\n }\n\n return match.groups.alias;\n }\n\n /**\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\n */\n private fromECv2String(versionString: string): ECVersion {\n const [read, minor] = versionString.split(\".\");\n\n if (!read)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECSchemaError(ECSchemaStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n return new ECVersion(+read, 0, +minor);\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from "./SchemaFileLocater";
|
|
2
|
+
export * from "./SchemaXml";
|
|
3
|
+
export * from "./SchemaJsonFileLocater";
|
|
4
|
+
export * from "./SchemaXmlFileLocater";
|
|
5
|
+
export * from "./StubSchemaXmlFileLocater";
|
|
6
|
+
export * from "./SchemaXmlStringLocater";
|
|
7
|
+
/** @docs-package-description
|
|
8
|
+
* The ecschema-locaters package contains classes for locating ECSchemas within a given
|
|
9
|
+
* [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
|
|
10
|
+
* implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @docs-group-description Locaters
|
|
14
|
+
* ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @docs-group-description Utils
|
|
18
|
+
* A set of utility classes used throughout the package.
|
|
19
|
+
*/
|
|
20
|
+
//# sourceMappingURL=ecschema-locaters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecschema-locaters.d.ts","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":"AAKA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export * from "./SchemaFileLocater";
|
|
6
|
+
export * from "./SchemaXml";
|
|
7
|
+
export * from "./SchemaJsonFileLocater";
|
|
8
|
+
export * from "./SchemaXmlFileLocater";
|
|
9
|
+
export * from "./StubSchemaXmlFileLocater";
|
|
10
|
+
export * from "./SchemaXmlStringLocater";
|
|
11
|
+
/** @docs-package-description
|
|
12
|
+
* The ecschema-locaters package contains classes for locating ECSchemas within a given
|
|
13
|
+
* [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
|
|
14
|
+
* implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @docs-group-description Locaters
|
|
18
|
+
* ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @docs-group-description Utils
|
|
22
|
+
* A set of utility classes used throughout the package.
|
|
23
|
+
*/
|
|
24
|
+
//# sourceMappingURL=ecschema-locaters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecschema-locaters.js","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nexport * from \"./SchemaFileLocater\";\nexport * from \"./SchemaXml\";\nexport * from \"./SchemaJsonFileLocater\";\nexport * from \"./SchemaXmlFileLocater\";\nexport * from \"./StubSchemaXmlFileLocater\";\nexport * from \"./SchemaXmlStringLocater\";\n\n/** @docs-package-description\n * The ecschema-locaters package contains classes for locating ECSchemas within a given\n * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater\n * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).\n */\n/**\n * @docs-group-description Locaters\n * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).\n */\n/**\n * @docs-group-description Utils\n * A set of utility classes used throughout the package.\n */\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConcurrentGetSchemaJson.test.d.ts","sourceRoot":"","sources":["../../../src/test/ConcurrentGetSchemaJson.test.ts"],"names":[],"mappings":""}
|