@itwin/ecschema-locaters 4.0.0-dev.8 → 4.0.0-dev.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -1,178 +1,178 @@
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.StubSchemaXmlFileLocater = void 0;
8
- const path = require("path");
9
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
10
- const SchemaFileLocater_1 = require("./SchemaFileLocater");
11
- /** @packageDocumentation
12
- * @module Locaters
13
- */
14
- function isECv2Schema(schemaText) {
15
- return /<ECSchema[^>]*xmlns=".*ECXML.2.0"/.test(schemaText);
16
- }
17
- /**
18
- * A SchemaLocater implementation for locating XML Schema files
19
- * from the file system using configurable search paths. Returns only
20
- * Schemas from XML files with their keys populated.
21
- * @internal
22
- */
23
- class StubSchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
24
- /**
25
- * Loads a Schema from an XML file on the file system.
26
- * @param schemaPath The path to the Schema file.
27
- * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
28
- * the schema will be read from the provided schemaPath.
29
- */
30
- loadSchema(schemaPath, schemaText) {
31
- schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);
32
- if (!schemaText)
33
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);
34
- this.addSchemaSearchPaths([path.dirname(schemaPath)]);
35
- const key = this.getSchemaKey(schemaText);
36
- const alias = this.getSchemaAlias(schemaText);
37
- const context = new ecschema_metadata_1.SchemaContext();
38
- context.addLocater(this);
39
- // Load the schema and return it
40
- const schema = new ecschema_metadata_1.Schema(context, new SchemaFileLocater_1.FileSchemaKey(key, schemaPath, schemaText), alias);
41
- this.addSchemaReferences(schema, context, ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible);
42
- return schema;
43
- }
44
- /**
45
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
46
- * to locate the XML Schema file from the file system. Returns only Schemas from XML files with
47
- * their keys populated.
48
- * @param key The SchemaKey of the Schema to retrieve.
49
- * @param matchType The SchemaMatchType.
50
- * @param context The SchemaContext that will control the lifetime of the schema.
51
- */
52
- async getSchema(key, matchType, context) {
53
- return this.getSchemaSync(key, matchType, context);
54
- }
55
- /**
56
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
57
- * to locate the XML Schema file from the file system. Returns only Schemas from XML files with
58
- * their keys populated.
59
- * @param key The SchemaKey of the Schema to retrieve.
60
- * @param matchType The SchemaMatchType.
61
- * @param context The SchemaContext that will control the lifetime of the schema.
62
- */
63
- getSchemaSync(key, matchType, context) {
64
- const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
65
- if (!candidates || candidates.length === 0)
66
- return undefined;
67
- const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1]; // eslint-disable-line @typescript-eslint/unbound-method
68
- const alias = this.getSchemaAlias(maxCandidate.schemaText);
69
- const schema = new ecschema_metadata_1.Schema(context, maxCandidate, alias);
70
- context.addSchemaSync(schema);
71
- this.addSchemaReferences(schema, context, ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible);
72
- return schema;
73
- }
74
- /**
75
- * Constructs a SchemaKey based on the information in the Schema XML.
76
- * @param schemaXml The Schema XML as a string.
77
- */
78
- getSchemaKey(schemaXml) {
79
- const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
80
- if (!matches || matches.length !== 1)
81
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
82
- const name = matches[0].match(/schemaName="(.+?)"/);
83
- const version = matches[0].match(/version="(.+?)"/);
84
- if (!name || name.length !== 2 || !version || version.length !== 2)
85
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
86
- let ecVersion;
87
- if (isECv2Schema(schemaXml))
88
- ecVersion = this.fromECv2String(version[1]);
89
- else
90
- ecVersion = ecschema_metadata_1.ECVersion.fromString(version[1]);
91
- const key = new ecschema_metadata_1.SchemaKey(name[1], ecVersion);
92
- return key;
93
- }
94
- /**
95
- * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
96
- * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
97
- */
98
- getSchemaReferenceKeys(schemaKey) {
99
- return this._getSchemaReferenceKeys(schemaKey);
100
- }
101
- /**
102
- * Adds schemas to the references collection for the given Schema by locating
103
- * the referenced schemas.
104
- * @param schema The schema for which to add the references.
105
- * @param context The SchemaContext that will control the lifetime of the schema.
106
- * @param refMatchType The SchemaMatchType to use when locating schema references.
107
- */
108
- addSchemaReferences(schema, context, refMatchType) {
109
- const refKeys = this.getSchemaReferenceKeys(schema.schemaKey);
110
- for (const key of refKeys) {
111
- const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;
112
- if (!refSchema)
113
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);
114
- schema.references.push(refSchema);
115
- }
116
- }
117
- /**
118
- * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
119
- * @param data The Schema XML string.
120
- */
121
- _getSchemaReferenceKeys(xmlSchemaKey) {
122
- const file = xmlSchemaKey.schemaText;
123
- if (!file)
124
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);
125
- const data = file.toString().replace(/(\s*)<!--.*?-->/g, ""); // ignore any comments in the XML file when getting the array of SchemaKeys
126
- const keys = [];
127
- const matches = data.match(/<ECSchemaReference ([^]+?)\/>/g);
128
- if (!matches)
129
- return keys;
130
- for (const match of matches) {
131
- const name = match.match(/name="(.+?)"/);
132
- const versionMatch = match.match(/version="(.+?)"/);
133
- if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)
134
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);
135
- // write version maybe missing, so insert "0"
136
- let versionString = versionMatch[1];
137
- const versionParts = versionString.split(".");
138
- if (versionParts.length === 2)
139
- versionParts.splice(1, 0, "0");
140
- versionString = versionParts.join(".");
141
- const key = new ecschema_metadata_1.SchemaKey(name[1], ecschema_metadata_1.ECVersion.fromString(versionString));
142
- keys.push(key);
143
- }
144
- return keys;
145
- }
146
- /**
147
- * Gets the Schema alias from the Schema XML.
148
- * @param data The Schema XML as a string.
149
- */
150
- getSchemaAlias(schemaXml) {
151
- let match;
152
- if (isECv2Schema(schemaXml)) {
153
- match = schemaXml.match(/<ECSchema.*nameSpacePrefix="(?<alias>\w+)"/);
154
- }
155
- else {
156
- match = schemaXml.match(/<ECSchema.*alias="(?<alias>\w+)"/);
157
- }
158
- if (!match || !match.groups.alias) {
159
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);
160
- }
161
- return match.groups.alias;
162
- }
163
- /**
164
- * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
165
- * and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
166
- * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
167
- */
168
- fromECv2String(versionString) {
169
- const [read, minor] = versionString.split(".");
170
- if (!read)
171
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
172
- if (!minor)
173
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
174
- return new ecschema_metadata_1.ECVersion(+read, 0, +minor);
175
- }
176
- }
177
- exports.StubSchemaXmlFileLocater = StubSchemaXmlFileLocater;
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.StubSchemaXmlFileLocater = void 0;
8
+ const path = require("path");
9
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
10
+ const SchemaFileLocater_1 = require("./SchemaFileLocater");
11
+ /** @packageDocumentation
12
+ * @module Locaters
13
+ */
14
+ function isECv2Schema(schemaText) {
15
+ return /<ECSchema[^>]*xmlns=".*ECXML.2.0"/.test(schemaText);
16
+ }
17
+ /**
18
+ * A SchemaLocater implementation for locating XML Schema files
19
+ * from the file system using configurable search paths. Returns only
20
+ * Schemas from XML files with their keys populated.
21
+ * @internal
22
+ */
23
+ class StubSchemaXmlFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
24
+ /**
25
+ * Loads a Schema from an XML file on the file system.
26
+ * @param schemaPath The path to the Schema file.
27
+ * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
28
+ * the schema will be read from the provided schemaPath.
29
+ */
30
+ loadSchema(schemaPath, schemaText) {
31
+ schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);
32
+ if (!schemaText)
33
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);
34
+ this.addSchemaSearchPaths([path.dirname(schemaPath)]);
35
+ const key = this.getSchemaKey(schemaText);
36
+ const alias = this.getSchemaAlias(schemaText);
37
+ const context = new ecschema_metadata_1.SchemaContext();
38
+ context.addLocater(this);
39
+ // Load the schema and return it
40
+ const schema = new ecschema_metadata_1.Schema(context, new SchemaFileLocater_1.FileSchemaKey(key, schemaPath, schemaText), alias);
41
+ this.addSchemaReferences(schema, context, ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible);
42
+ return schema;
43
+ }
44
+ /**
45
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
46
+ * to locate the XML Schema file from the file system. Returns only Schemas from XML files with
47
+ * their keys populated.
48
+ * @param key The SchemaKey of the Schema to retrieve.
49
+ * @param matchType The SchemaMatchType.
50
+ * @param context The SchemaContext that will control the lifetime of the schema.
51
+ */
52
+ async getSchema(key, matchType, context) {
53
+ return this.getSchemaSync(key, matchType, context);
54
+ }
55
+ /**
56
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
57
+ * to locate the XML Schema file from the file system. Returns only Schemas from XML files with
58
+ * their keys populated.
59
+ * @param key The SchemaKey of the Schema to retrieve.
60
+ * @param matchType The SchemaMatchType.
61
+ * @param context The SchemaContext that will control the lifetime of the schema.
62
+ */
63
+ getSchemaSync(key, matchType, context) {
64
+ const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
65
+ if (!candidates || candidates.length === 0)
66
+ return undefined;
67
+ const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1]; // eslint-disable-line @typescript-eslint/unbound-method
68
+ const alias = this.getSchemaAlias(maxCandidate.schemaText);
69
+ const schema = new ecschema_metadata_1.Schema(context, maxCandidate, alias);
70
+ context.addSchemaSync(schema);
71
+ this.addSchemaReferences(schema, context, ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible);
72
+ return schema;
73
+ }
74
+ /**
75
+ * Constructs a SchemaKey based on the information in the Schema XML.
76
+ * @param schemaXml The Schema XML as a string.
77
+ */
78
+ getSchemaKey(schemaXml) {
79
+ const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
80
+ if (!matches || matches.length !== 1)
81
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
82
+ const name = matches[0].match(/schemaName="(.+?)"/);
83
+ const version = matches[0].match(/version="(.+?)"/);
84
+ if (!name || name.length !== 2 || !version || version.length !== 2)
85
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
86
+ let ecVersion;
87
+ if (isECv2Schema(schemaXml))
88
+ ecVersion = this.fromECv2String(version[1]);
89
+ else
90
+ ecVersion = ecschema_metadata_1.ECVersion.fromString(version[1]);
91
+ const key = new ecschema_metadata_1.SchemaKey(name[1], ecVersion);
92
+ return key;
93
+ }
94
+ /**
95
+ * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
96
+ * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
97
+ */
98
+ getSchemaReferenceKeys(schemaKey) {
99
+ return this._getSchemaReferenceKeys(schemaKey);
100
+ }
101
+ /**
102
+ * Adds schemas to the references collection for the given Schema by locating
103
+ * the referenced schemas.
104
+ * @param schema The schema for which to add the references.
105
+ * @param context The SchemaContext that will control the lifetime of the schema.
106
+ * @param refMatchType The SchemaMatchType to use when locating schema references.
107
+ */
108
+ addSchemaReferences(schema, context, refMatchType) {
109
+ const refKeys = this.getSchemaReferenceKeys(schema.schemaKey);
110
+ for (const key of refKeys) {
111
+ const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;
112
+ if (!refSchema)
113
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);
114
+ schema.references.push(refSchema);
115
+ }
116
+ }
117
+ /**
118
+ * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
119
+ * @param data The Schema XML string.
120
+ */
121
+ _getSchemaReferenceKeys(xmlSchemaKey) {
122
+ const file = xmlSchemaKey.schemaText;
123
+ if (!file)
124
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);
125
+ const data = file.toString().replace(/(\s*)<!--.*?-->/g, ""); // ignore any comments in the XML file when getting the array of SchemaKeys
126
+ const keys = [];
127
+ const matches = data.match(/<ECSchemaReference ([^]+?)\/>/g);
128
+ if (!matches)
129
+ return keys;
130
+ for (const match of matches) {
131
+ const name = match.match(/name="(.+?)"/);
132
+ const versionMatch = match.match(/version="(.+?)"/);
133
+ if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)
134
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);
135
+ // write version maybe missing, so insert "0"
136
+ let versionString = versionMatch[1];
137
+ const versionParts = versionString.split(".");
138
+ if (versionParts.length === 2)
139
+ versionParts.splice(1, 0, "0");
140
+ versionString = versionParts.join(".");
141
+ const key = new ecschema_metadata_1.SchemaKey(name[1], ecschema_metadata_1.ECVersion.fromString(versionString));
142
+ keys.push(key);
143
+ }
144
+ return keys;
145
+ }
146
+ /**
147
+ * Gets the Schema alias from the Schema XML.
148
+ * @param data The Schema XML as a string.
149
+ */
150
+ getSchemaAlias(schemaXml) {
151
+ let match;
152
+ if (isECv2Schema(schemaXml)) {
153
+ match = schemaXml.match(/<ECSchema.*nameSpacePrefix="(?<alias>\w+)"/);
154
+ }
155
+ else {
156
+ match = schemaXml.match(/<ECSchema.*alias="(?<alias>\w+)"/);
157
+ }
158
+ if (!match || !match.groups.alias) {
159
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);
160
+ }
161
+ return match.groups.alias;
162
+ }
163
+ /**
164
+ * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
165
+ * and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
166
+ * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
167
+ */
168
+ fromECv2String(versionString) {
169
+ const [read, minor] = versionString.split(".");
170
+ if (!read)
171
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
172
+ if (!minor)
173
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
174
+ return new ecschema_metadata_1.ECVersion(+read, 0, +minor);
175
+ }
176
+ }
177
+ exports.StubSchemaXmlFileLocater = StubSchemaXmlFileLocater;
178
178
  //# sourceMappingURL=StubSchemaXmlFileLocater.js.map
@@ -1,18 +1,18 @@
1
- export * from "./SchemaFileLocater";
2
- export * from "./SchemaJsonFileLocater";
3
- export * from "./SchemaXmlFileLocater";
4
- export * from "./StubSchemaXmlFileLocater";
5
- /** @docs-package-description
6
- * The ecschema-locaters package contains classes for locating ECSchemas within a given
7
- * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
8
- * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
9
- */
10
- /**
11
- * @docs-group-description Locaters
12
- * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
13
- */
14
- /**
15
- * @docs-group-description Utils
16
- * A set of utility classes used throughout the package.
17
- */
1
+ export * from "./SchemaFileLocater";
2
+ export * from "./SchemaJsonFileLocater";
3
+ export * from "./SchemaXmlFileLocater";
4
+ export * from "./StubSchemaXmlFileLocater";
5
+ /** @docs-package-description
6
+ * The ecschema-locaters package contains classes for locating ECSchemas within a given
7
+ * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
8
+ * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
9
+ */
10
+ /**
11
+ * @docs-group-description Locaters
12
+ * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
13
+ */
14
+ /**
15
+ * @docs-group-description Utils
16
+ * A set of utility classes used throughout the package.
17
+ */
18
18
  //# sourceMappingURL=ecschema-locaters.d.ts.map
@@ -1,34 +1,38 @@
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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./SchemaFileLocater"), exports);
18
- __exportStar(require("./SchemaJsonFileLocater"), exports);
19
- __exportStar(require("./SchemaXmlFileLocater"), exports);
20
- __exportStar(require("./StubSchemaXmlFileLocater"), exports);
21
- /** @docs-package-description
22
- * The ecschema-locaters package contains classes for locating ECSchemas within a given
23
- * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
24
- * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
25
- */
26
- /**
27
- * @docs-group-description Locaters
28
- * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
29
- */
30
- /**
31
- * @docs-group-description Utils
32
- * A set of utility classes used throughout the package.
33
- */
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ __exportStar(require("./SchemaFileLocater"), exports);
22
+ __exportStar(require("./SchemaJsonFileLocater"), exports);
23
+ __exportStar(require("./SchemaXmlFileLocater"), exports);
24
+ __exportStar(require("./StubSchemaXmlFileLocater"), exports);
25
+ /** @docs-package-description
26
+ * The ecschema-locaters package contains classes for locating ECSchemas within a given
27
+ * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
28
+ * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
29
+ */
30
+ /**
31
+ * @docs-group-description Locaters
32
+ * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
33
+ */
34
+ /**
35
+ * @docs-group-description Utils
36
+ * A set of utility classes used throughout the package.
37
+ */
34
38
  //# sourceMappingURL=ecschema-locaters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecschema-locaters.js","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,sDAAoC;AACpC,0DAAwC;AACxC,yDAAuC;AACvC,6DAA2C;AAE3C;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nexport * from \"./SchemaFileLocater\";\r\nexport * from \"./SchemaJsonFileLocater\";\r\nexport * from \"./SchemaXmlFileLocater\";\r\nexport * from \"./StubSchemaXmlFileLocater\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-locaters package contains classes for locating ECSchemas within a given\r\n * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater\r\n * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).\r\n */\r\n/**\r\n * @docs-group-description Locaters\r\n * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * A set of utility classes used throughout the package.\r\n */\r\n"]}
1
+ {"version":3,"file":"ecschema-locaters.js","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;AAE/F,sDAAoC;AACpC,0DAAwC;AACxC,yDAAuC;AACvC,6DAA2C;AAE3C;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nexport * from \"./SchemaFileLocater\";\r\nexport * from \"./SchemaJsonFileLocater\";\r\nexport * from \"./SchemaXmlFileLocater\";\r\nexport * from \"./StubSchemaXmlFileLocater\";\r\n\r\n/** @docs-package-description\r\n * The ecschema-locaters package contains classes for locating ECSchemas within a given\r\n * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater\r\n * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).\r\n */\r\n/**\r\n * @docs-group-description Locaters\r\n * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * A set of utility classes used throughout the package.\r\n */\r\n"]}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=SchemaFileUtility.test.d.ts.map