@itwin/ecschema-locaters 4.0.0-dev.46 → 4.0.0-dev.48
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/lib/cjs/SchemaFileLocater.d.ts +82 -82
- package/lib/cjs/SchemaFileLocater.js +212 -212
- package/lib/cjs/SchemaFileLocater.js.map +1 -1
- package/lib/cjs/SchemaFileUtility.d.ts +17 -17
- package/lib/cjs/SchemaFileUtility.js +48 -48
- package/lib/cjs/SchemaFileUtility.js.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.d.ts +33 -33
- package/lib/cjs/SchemaJsonFileLocater.js +90 -90
- package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.d.ts +33 -33
- package/lib/cjs/SchemaXmlFileLocater.js +93 -93
- package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.d.ts +69 -69
- package/lib/cjs/StubSchemaXmlFileLocater.js +177 -177
- package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/ecschema-locaters.d.ts +17 -17
- package/lib/cjs/ecschema-locaters.js +33 -33
- package/lib/cjs/ecschema-locaters.js.map +1 -1
- package/lib/cjs/test/SchemaFileUtility.test.d.ts +1 -1
- package/lib/cjs/test/SchemaFileUtility.test.js +56 -56
- package/lib/cjs/test/SchemaFileUtility.test.js.map +1 -1
- package/lib/cjs/test/SchemaJsonFileLocator.test.d.ts +1 -1
- package/lib/cjs/test/SchemaJsonFileLocator.test.js +119 -119
- package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXmlFileLocator.test.d.ts +1 -1
- package/lib/cjs/test/SchemaXmlFileLocator.test.js +180 -180
- package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.d.ts +1 -1
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.js +170 -170
- package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SchemaXmlFileLocater = void 0;
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const xmldom_1 = require("@xmldom/xmldom");
|
|
10
|
-
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
11
|
-
const SchemaFileLocater_1 = require("./SchemaFileLocater");
|
|
12
|
-
/** @packageDocumentation
|
|
13
|
-
* @module Locaters
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* A SchemaLocater implementation for locating XML Schema files
|
|
17
|
-
* from the file system using configurable search paths.
|
|
18
|
-
* @beta This is a workaround the current lack of a full xml parser.
|
|
19
|
-
*/
|
|
20
|
-
class SchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
21
|
-
/**
|
|
22
|
-
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
23
|
-
* to locate the XML Schema file from the file system.
|
|
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
|
-
async getSchema(key, matchType, context) {
|
|
29
|
-
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
30
|
-
if (0 === candidates.length)
|
|
31
|
-
return undefined;
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
33
|
-
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
34
|
-
const schemaPath = maxCandidate.fileName;
|
|
35
|
-
// Load the file
|
|
36
|
-
if (undefined === await this.fileExists(schemaPath))
|
|
37
|
-
return undefined;
|
|
38
|
-
const schemaText = await this.readUtf8FileToString(schemaPath);
|
|
39
|
-
if (undefined === schemaText)
|
|
40
|
-
return undefined;
|
|
41
|
-
const parser = new xmldom_1.DOMParser();
|
|
42
|
-
const document = parser.parseFromString(schemaText);
|
|
43
|
-
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
44
|
-
const reader = new ecschema_metadata_1.SchemaReadHelper(ecschema_metadata_1.XmlParser, context);
|
|
45
|
-
let schema = new ecschema_metadata_1.Schema(context);
|
|
46
|
-
schema = await reader.readSchema(schema, document);
|
|
47
|
-
return schema;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
51
|
-
* to locate the XML Schema file from the file system.
|
|
52
|
-
* @param key The SchemaKey of the Schema to retrieve.
|
|
53
|
-
* @param matchType The SchemaMatchType.
|
|
54
|
-
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
55
|
-
*/
|
|
56
|
-
getSchemaSync(key, matchType, context) {
|
|
57
|
-
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
58
|
-
if (!candidates || candidates.length === 0)
|
|
59
|
-
return undefined;
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
61
|
-
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
62
|
-
const schemaPath = maxCandidate.fileName;
|
|
63
|
-
// Load the file
|
|
64
|
-
if (!this.fileExistsSync(schemaPath))
|
|
65
|
-
return undefined;
|
|
66
|
-
const schemaText = this.readUtf8FileToStringSync(schemaPath);
|
|
67
|
-
if (!schemaText)
|
|
68
|
-
return undefined;
|
|
69
|
-
const parser = new xmldom_1.DOMParser();
|
|
70
|
-
const document = parser.parseFromString(schemaText);
|
|
71
|
-
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
72
|
-
const reader = new ecschema_metadata_1.SchemaReadHelper(ecschema_metadata_1.XmlParser, context);
|
|
73
|
-
let schema = new ecschema_metadata_1.Schema(context);
|
|
74
|
-
schema = reader.readSchemaSync(schema, document);
|
|
75
|
-
return schema;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
79
|
-
* @param data The Schema XML as a string.
|
|
80
|
-
*/
|
|
81
|
-
getSchemaKey(data) {
|
|
82
|
-
const matches = data.match(/<ECSchema ([^]+?)>/g);
|
|
83
|
-
if (!matches || matches.length !== 1)
|
|
84
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
|
|
85
|
-
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
86
|
-
const version = matches[0].match(/version="(.+?)"/);
|
|
87
|
-
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
88
|
-
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
|
|
89
|
-
const key = new ecschema_metadata_1.SchemaKey(name[1], ecschema_metadata_1.ECVersion.fromString(version[1]));
|
|
90
|
-
return key;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.SchemaXmlFileLocater = SchemaXmlFileLocater;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SchemaXmlFileLocater = void 0;
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const xmldom_1 = require("@xmldom/xmldom");
|
|
10
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
11
|
+
const SchemaFileLocater_1 = require("./SchemaFileLocater");
|
|
12
|
+
/** @packageDocumentation
|
|
13
|
+
* @module Locaters
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
17
|
+
* from the file system using configurable search paths.
|
|
18
|
+
* @beta This is a workaround the current lack of a full xml parser.
|
|
19
|
+
*/
|
|
20
|
+
class SchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
|
|
21
|
+
/**
|
|
22
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
23
|
+
* to locate the XML Schema file from the file system.
|
|
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
|
+
async getSchema(key, matchType, context) {
|
|
29
|
+
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
30
|
+
if (0 === candidates.length)
|
|
31
|
+
return undefined;
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
33
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
34
|
+
const schemaPath = maxCandidate.fileName;
|
|
35
|
+
// Load the file
|
|
36
|
+
if (undefined === await this.fileExists(schemaPath))
|
|
37
|
+
return undefined;
|
|
38
|
+
const schemaText = await this.readUtf8FileToString(schemaPath);
|
|
39
|
+
if (undefined === schemaText)
|
|
40
|
+
return undefined;
|
|
41
|
+
const parser = new xmldom_1.DOMParser();
|
|
42
|
+
const document = parser.parseFromString(schemaText);
|
|
43
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
44
|
+
const reader = new ecschema_metadata_1.SchemaReadHelper(ecschema_metadata_1.XmlParser, context);
|
|
45
|
+
let schema = new ecschema_metadata_1.Schema(context);
|
|
46
|
+
schema = await reader.readSchema(schema, document);
|
|
47
|
+
return schema;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
51
|
+
* to locate the XML Schema file from the file system.
|
|
52
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
53
|
+
* @param matchType The SchemaMatchType.
|
|
54
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
55
|
+
*/
|
|
56
|
+
getSchemaSync(key, matchType, context) {
|
|
57
|
+
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
58
|
+
if (!candidates || candidates.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
61
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
62
|
+
const schemaPath = maxCandidate.fileName;
|
|
63
|
+
// Load the file
|
|
64
|
+
if (!this.fileExistsSync(schemaPath))
|
|
65
|
+
return undefined;
|
|
66
|
+
const schemaText = this.readUtf8FileToStringSync(schemaPath);
|
|
67
|
+
if (!schemaText)
|
|
68
|
+
return undefined;
|
|
69
|
+
const parser = new xmldom_1.DOMParser();
|
|
70
|
+
const document = parser.parseFromString(schemaText);
|
|
71
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
72
|
+
const reader = new ecschema_metadata_1.SchemaReadHelper(ecschema_metadata_1.XmlParser, context);
|
|
73
|
+
let schema = new ecschema_metadata_1.Schema(context);
|
|
74
|
+
schema = reader.readSchemaSync(schema, document);
|
|
75
|
+
return schema;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
79
|
+
* @param data The Schema XML as a string.
|
|
80
|
+
*/
|
|
81
|
+
getSchemaKey(data) {
|
|
82
|
+
const matches = data.match(/<ECSchema ([^]+?)>/g);
|
|
83
|
+
if (!matches || matches.length !== 1)
|
|
84
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
|
|
85
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
86
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
87
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
88
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
|
|
89
|
+
const key = new ecschema_metadata_1.SchemaKey(name[1], ecschema_metadata_1.ECVersion.fromString(version[1]));
|
|
90
|
+
return key;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.SchemaXmlFileLocater = SchemaXmlFileLocater;
|
|
94
94
|
//# sourceMappingURL=SchemaXmlFileLocater.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,6BAA6B;AAC7B,2CAA2C;AAC3C,gEAEkC;AAClC,2DAAuE;AAEvE;;GAEG;AAEH;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,qCAAiB;IACzD;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CAAmB,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACzG,MAAM,UAAU,GAAoB,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAEvF,IAAI,CAAC,KAAK,UAAU,CAAC,MAAM;YACzB,OAAO,SAAS,CAAC;QAEnB,6DAA6D;QAC7D,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAA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6E,CAAC,CAAC;QAE5I,MAAM,GAAG,GAAG,IAAI,6BAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,6BAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA1FD,oDA0FC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,6BAA6B;AAC7B,2CAA2C;AAC3C,gEAEkC;AAClC,2DAAuE;AAEvE;;GAEG;AAEH;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,qCAAiB;IACzD;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CAAmB,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACzG,MAAM,UAAU,GAAoB,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAEvF,IAAI,CAAC,KAAK,UAAU,CAAC,MAAM;YACzB,OAAO,SAAS,CAAC;QAEnB,6DAA6D;QAC7D,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5F,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC;QAEzC,gBAAgB;QAChB,IAAI,SAAS,KAAK,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;YACjD,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,UAAU;YAC1B,OAAO,SAAS,CAAC;QAEnB,MAAM,MAAM,GAAG,IAAI,kBAAS,EAAE,CAAC;QAC/B,MAAM,QAAQ,GA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AAC,CAAC,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,IAAI,oCAAgB,CAAC,6BAAS,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,MAAM,GAAW,IAAI,0BAAM,CAAC,OAAO,CAAC,CAAC;QACzC,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEjD,OAAO,MAAW,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,IAAY;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,mDAAmD,CAAC,CAAC;QAElH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAChE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,gBAAgB,EAAE,6EAA6E,CAAC,CAAC;QAE5I,MAAM,GAAG,GAAG,IAAI,6BAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,6BAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA1FD,oDA0FC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as path from \"path\";\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\n/** @packageDocumentation\n * @module Locaters\n */\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths.\n * @beta This is a workaround the current lack of a full xml parser.\n */\nexport class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public async getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\n if (0 === candidates.length)\n return undefined;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (undefined === await this.fileExists(schemaPath))\n return undefined;\n\n const schemaText = await this.readUtf8FileToString(schemaPath);\n if (undefined === schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = await reader.readSchema(schema, document);\n\n return schema as T;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\n if (!candidates || candidates.length === 0)\n return undefined;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (!this.fileExistsSync(schemaPath))\n return undefined;\n\n const schemaText = this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema as T;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param data The Schema XML as a string.\n */\n public getSchemaKey(data: string): SchemaKey {\n const matches = data.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\n\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\n\n const key = new SchemaKey(name[1], ECVersion.fromString(version[1]));\n return key;\n }\n}\n"]}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
2
|
-
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
3
|
-
/**
|
|
4
|
-
* A SchemaLocater implementation for locating XML Schema files
|
|
5
|
-
* from the file system using configurable search paths. Returns only
|
|
6
|
-
* Schemas from XML files with their keys populated.
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export declare class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
|
|
10
|
-
/**
|
|
11
|
-
* Loads a Schema from an XML file on the file system.
|
|
12
|
-
* @param schemaPath The path to the Schema file.
|
|
13
|
-
* @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
|
|
14
|
-
* the schema will be read from the provided schemaPath.
|
|
15
|
-
*/
|
|
16
|
-
loadSchema(schemaPath: string, schemaText?: string): Schema;
|
|
17
|
-
/**
|
|
18
|
-
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
19
|
-
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
20
|
-
* their keys populated.
|
|
21
|
-
* @param key The SchemaKey of the Schema to retrieve.
|
|
22
|
-
* @param matchType The SchemaMatchType.
|
|
23
|
-
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
24
|
-
*/
|
|
25
|
-
getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
28
|
-
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
29
|
-
* their keys populated.
|
|
30
|
-
* @param key The SchemaKey of the Schema to retrieve.
|
|
31
|
-
* @param matchType The SchemaMatchType.
|
|
32
|
-
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
33
|
-
*/
|
|
34
|
-
getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
37
|
-
* @param schemaXml The Schema XML as a string.
|
|
38
|
-
*/
|
|
39
|
-
getSchemaKey(schemaXml: string): SchemaKey;
|
|
40
|
-
/**
|
|
41
|
-
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
42
|
-
* @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
|
|
43
|
-
*/
|
|
44
|
-
private getSchemaReferenceKeys;
|
|
45
|
-
/**
|
|
46
|
-
* Adds schemas to the references collection for the given Schema by locating
|
|
47
|
-
* the referenced schemas.
|
|
48
|
-
* @param schema The schema for which to add the references.
|
|
49
|
-
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
50
|
-
* @param refMatchType The SchemaMatchType to use when locating schema references.
|
|
51
|
-
*/
|
|
52
|
-
private addSchemaReferences;
|
|
53
|
-
/**
|
|
54
|
-
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
55
|
-
* @param data The Schema XML string.
|
|
56
|
-
*/
|
|
57
|
-
private _getSchemaReferenceKeys;
|
|
58
|
-
/**
|
|
59
|
-
* Gets the Schema alias from the Schema XML.
|
|
60
|
-
* @param data The Schema XML as a string.
|
|
61
|
-
*/
|
|
62
|
-
private getSchemaAlias;
|
|
63
|
-
/**
|
|
64
|
-
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
65
|
-
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
66
|
-
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
67
|
-
*/
|
|
68
|
-
private fromECv2String;
|
|
69
|
-
}
|
|
1
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
3
|
+
/**
|
|
4
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
5
|
+
* from the file system using configurable search paths. Returns only
|
|
6
|
+
* Schemas from XML files with their keys populated.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
|
|
10
|
+
/**
|
|
11
|
+
* Loads a Schema from an XML file on the file system.
|
|
12
|
+
* @param schemaPath The path to the Schema file.
|
|
13
|
+
* @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
|
|
14
|
+
* the schema will be read from the provided schemaPath.
|
|
15
|
+
*/
|
|
16
|
+
loadSchema(schemaPath: string, schemaText?: string): Schema;
|
|
17
|
+
/**
|
|
18
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
19
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
20
|
+
* their keys populated.
|
|
21
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
22
|
+
* @param matchType The SchemaMatchType.
|
|
23
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
24
|
+
*/
|
|
25
|
+
getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
28
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
29
|
+
* their keys populated.
|
|
30
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
31
|
+
* @param matchType The SchemaMatchType.
|
|
32
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
33
|
+
*/
|
|
34
|
+
getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
37
|
+
* @param schemaXml The Schema XML as a string.
|
|
38
|
+
*/
|
|
39
|
+
getSchemaKey(schemaXml: string): SchemaKey;
|
|
40
|
+
/**
|
|
41
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
42
|
+
* @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
|
|
43
|
+
*/
|
|
44
|
+
private getSchemaReferenceKeys;
|
|
45
|
+
/**
|
|
46
|
+
* Adds schemas to the references collection for the given Schema by locating
|
|
47
|
+
* the referenced schemas.
|
|
48
|
+
* @param schema The schema for which to add the references.
|
|
49
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
50
|
+
* @param refMatchType The SchemaMatchType to use when locating schema references.
|
|
51
|
+
*/
|
|
52
|
+
private addSchemaReferences;
|
|
53
|
+
/**
|
|
54
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
55
|
+
* @param data The Schema XML string.
|
|
56
|
+
*/
|
|
57
|
+
private _getSchemaReferenceKeys;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the Schema alias from the Schema XML.
|
|
60
|
+
* @param data The Schema XML as a string.
|
|
61
|
+
*/
|
|
62
|
+
private getSchemaAlias;
|
|
63
|
+
/**
|
|
64
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
65
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
66
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
67
|
+
*/
|
|
68
|
+
private fromECv2String;
|
|
69
|
+
}
|
|
70
70
|
//# sourceMappingURL=StubSchemaXmlFileLocater.d.ts.map
|