@itwin/ecschema-locaters 3.5.0-dev.8 → 3.5.1

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +72 -1
  2. package/lib/cjs/SchemaFileLocater.d.ts +82 -82
  3. package/lib/cjs/SchemaFileLocater.js +212 -212
  4. package/lib/cjs/SchemaFileLocater.js.map +1 -1
  5. package/lib/cjs/SchemaFileUtility.d.ts +17 -17
  6. package/lib/cjs/SchemaFileUtility.js +48 -48
  7. package/lib/cjs/SchemaFileUtility.js.map +1 -1
  8. package/lib/cjs/SchemaJsonFileLocater.d.ts +33 -33
  9. package/lib/cjs/SchemaJsonFileLocater.js +90 -90
  10. package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
  11. package/lib/cjs/SchemaXmlFileLocater.d.ts +33 -33
  12. package/lib/cjs/SchemaXmlFileLocater.js +93 -93
  13. package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
  14. package/lib/cjs/StubSchemaXmlFileLocater.d.ts +69 -69
  15. package/lib/cjs/StubSchemaXmlFileLocater.js +177 -177
  16. package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
  17. package/lib/cjs/ecschema-locaters.d.ts +17 -17
  18. package/lib/cjs/ecschema-locaters.js +33 -33
  19. package/lib/cjs/ecschema-locaters.js.map +1 -1
  20. package/lib/cjs/test/SchemaFileUtility.test.d.ts +1 -1
  21. package/lib/cjs/test/SchemaFileUtility.test.js +56 -56
  22. package/lib/cjs/test/SchemaFileUtility.test.js.map +1 -1
  23. package/lib/cjs/test/SchemaJsonFileLocator.test.d.ts +1 -1
  24. package/lib/cjs/test/SchemaJsonFileLocator.test.js +119 -119
  25. package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
  26. package/lib/cjs/test/SchemaXmlFileLocator.test.d.ts +1 -1
  27. package/lib/cjs/test/SchemaXmlFileLocator.test.js +180 -180
  28. package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
  29. package/lib/cjs/test/StubSchemaXmlFileLocater.test.d.ts +1 -1
  30. package/lib/cjs/test/StubSchemaXmlFileLocater.test.js +170 -170
  31. package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
  32. package/package.json +7 -7
@@ -1,213 +1,213 @@
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.SchemaFileLocater = exports.FileSchemaKey = void 0;
8
- const fs = require("fs");
9
- const glob = require("glob");
10
- const path = require("path");
11
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
- /** @packageDocumentation
13
- * @module Locaters
14
- */
15
- const formatString = (format, ...args) => {
16
- return format.replace(/{(\d+)}/g, (match, theNumber) => {
17
- return typeof args[theNumber] !== "undefined"
18
- ? args[theNumber]
19
- : match;
20
- });
21
- };
22
- const padStartEx = (str, targetLength, padString) => {
23
- targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;
24
- padString = String((typeof padString !== "undefined" ? padString : " "));
25
- if (str.length > targetLength) {
26
- return String(str);
27
- }
28
- else {
29
- targetLength = targetLength - str.length;
30
- if (targetLength > padString.length) {
31
- padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
32
- }
33
- return padString.slice(0, targetLength) + str;
34
- }
35
- };
36
- /**
37
- * A SchemaKey implementation that aids in identifying Schema files via the
38
- * addition of two properties: fileName and schemaText. The fileName contains the
39
- * full path to the file on disk and schemaText is the full string representation
40
- * of the Schema.
41
- * @beta
42
- */
43
- class FileSchemaKey extends ecschema_metadata_1.SchemaKey {
44
- /**
45
- * Initializes a new FileSchemaKey object.
46
- * @param key The EC SchemaKey identifying the Schema.
47
- * @param fileName The full path to the Schema file.
48
- * @param schemaText The string representation of the Schema
49
- * loaded from disk. Optional.
50
- */
51
- constructor(key, fileName, schemaJson) {
52
- super(key.name, key.version);
53
- this.fileName = fileName;
54
- this.schemaText = schemaJson;
55
- }
56
- }
57
- exports.FileSchemaKey = FileSchemaKey;
58
- /**
59
- * Abstract class to hold common/overlapping functionality between SchemaJsonFileLocater and SchemaXmlFileLocater
60
- * @beta - Needs further testing and possibly moved to a separate package.
61
- */
62
- class SchemaFileLocater {
63
- constructor() {
64
- /**
65
- * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
66
- * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.
67
- * @param lhs The 'left-hand' FileSchemaKey.
68
- * @param rhs The 'right-hand' FileSchemaKey.
69
- */
70
- this.compareSchemaKeyByVersion = (lhs, rhs) => {
71
- return lhs.compareByVersion(rhs);
72
- };
73
- this.searchPaths = [];
74
- }
75
- async readUtf8FileToString(filePath) {
76
- return new Promise((resolve, reject) => {
77
- fs.readFile(filePath, "utf-8", (err, data) => {
78
- if (err)
79
- reject(err);
80
- else
81
- resolve(data);
82
- });
83
- });
84
- }
85
- readUtf8FileToStringSync(filePath) {
86
- return fs.readFileSync(filePath, "utf-8");
87
- }
88
- async fileExists(filePath) {
89
- return new Promise((resolve) => {
90
- fs.access(filePath, fs.constants.F_OK, (err) => {
91
- resolve(err ? false : true);
92
- });
93
- });
94
- }
95
- fileExistsSync(filePath) {
96
- return fs.existsSync(filePath);
97
- }
98
- /**
99
- * Adds more search paths used by this locator to find the
100
- * Schema files.
101
- * @param schemaPaths An array of search paths to add
102
- */
103
- addSchemaSearchPaths(schemaPaths) {
104
- // If the path is not in the schemaPaths array, add it
105
- for (const schemaPath of schemaPaths)
106
- this.addSchemaSearchPath(schemaPath);
107
- }
108
- /**
109
- * Add one search path used by this locator to find the
110
- * Schema files.
111
- * @param schemaPath A search path to add
112
- */
113
- addSchemaSearchPath(schemaPath) {
114
- // If the path is not in the schemaPaths array, add it
115
- if (!this.searchPaths.find((entry) => entry === schemaPath))
116
- this.searchPaths.push(schemaPath);
117
- }
118
- /**
119
- * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey. This method
120
- * only attempts to find schema files that have no version in the file name.
121
- * @param foundFiles The collection of SchemaKeys found in the given directory.
122
- * @param schemaPath The directory in which to search for the Schemas.
123
- * @param schemaName The short name of the Schema (without version).
124
- * @param desiredKey The SchemaKey used to find matching Schema files.
125
- * @param matchType The SchemaMatchType to use when comparing the desiredKey and the keys found during the search.
126
- * @param format The type of file that the schema key refers to. json or xml
127
- */
128
- addCandidateNoExtSchemaKey(foundFiles, schemaPath, schemaName, desiredKey, matchType, format) {
129
- const fullPath = path.join(schemaPath, `${schemaName}.ecschema.${format}`);
130
- // If the file does not exist, end
131
- if (!fs.existsSync(fullPath))
132
- return;
133
- // Read the file
134
- const file = fs.readFileSync(fullPath);
135
- if (!file)
136
- return;
137
- // Get the schema key
138
- const key = this.getSchemaKey(file.toString());
139
- // If the key matches, put it in foundFiles
140
- if (key.matches(desiredKey, matchType))
141
- foundFiles.push(new FileSchemaKey(key, fullPath, file.toString()));
142
- }
143
- /**
144
- * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey
145
- * @param foundFiles The collection of SchemaKeys found in the given directory
146
- * @param schemaPath The directory in which to search for the Schemas
147
- * @param fileFilter The file filter, potentially with wildcards, used to locate the Schema files.
148
- * @param desiredKey The schemaKey used to find matching Schema files
149
- * @param matchType The SchemaMatchType to use when comparing the desired Key and the keys found during the search.
150
- * @param format The type of file that the schema key refers to. json or xml
151
- */
152
- addCandidateSchemaKeys(foundFiles, schemaPath, fileFilter, desiredKey, matchType, format) {
153
- const fullPath = path.join(schemaPath, fileFilter);
154
- const result = new glob.GlobSync(fullPath, { sync: true });
155
- for (const match of result.found) {
156
- let fileName = path.basename(match, (`.ecschema.${format}`));
157
- // TODO: should this be moved or handled elsewhere?
158
- // Handles two version file names - SchemaKey.parseString supports only 3 version names.
159
- if (/[^\d]\.\d?\d\.\d?\d$/.test(fileName)) {
160
- const parts = fileName.split(".");
161
- parts.splice(2, 0, "00");
162
- fileName = parts.join(".");
163
- }
164
- const file = fs.readFileSync(match);
165
- if (!file)
166
- continue;
167
- const schemaKey = ecschema_metadata_1.SchemaKey.parseString(fileName);
168
- if (schemaKey.matches(desiredKey, matchType))
169
- foundFiles.push(new FileSchemaKey(schemaKey, match, file.toString()));
170
- }
171
- }
172
- /**
173
- * Attempts to find all Schema files in the configurable search paths that match
174
- * the desired SchemaKey.
175
- * @param desiredKey The SchemaKey to match.
176
- * @param matchType The SchemaMatchType.
177
- * @param format The type of file that the schema key refers to. json or xml
178
- */
179
- findEligibleSchemaKeys(desiredKey, matchType, format) {
180
- const foundFiles = new Array();
181
- let twoVersionSuffix;
182
- let threeVersionSuffix;
183
- const readVersion = desiredKey.readVersion.toString();
184
- const writeVersion = desiredKey.writeVersion.toString();
185
- const minorVersion = desiredKey.minorVersion.toString();
186
- if (matchType === ecschema_metadata_1.SchemaMatchType.Latest) {
187
- twoVersionSuffix = (`.*.*.ecschema.${format}`);
188
- threeVersionSuffix = (`.*.*.*.ecschema.${format}`);
189
- }
190
- else if (matchType === ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible) {
191
- twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"));
192
- threeVersionSuffix = formatString(`.{0}.{1}.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"), padStartEx(writeVersion, 2, "0"));
193
- }
194
- else if (matchType === ecschema_metadata_1.SchemaMatchType.LatestReadCompatible) {
195
- twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"));
196
- threeVersionSuffix = formatString(`.{0}.*.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"));
197
- }
198
- else {
199
- twoVersionSuffix = formatString(`.{0}.{1}.ecschema.${format}`, padStartEx(readVersion, 2, "0"), padStartEx(writeVersion, 2, "0"));
200
- threeVersionSuffix = formatString(`.{0}.{1}.{2}.ecschema.${format}`, padStartEx(readVersion, 2, "0"), padStartEx(writeVersion, 2, "0"), padStartEx(minorVersion, 2, "0"));
201
- }
202
- const twoVersionExpression = desiredKey.name + twoVersionSuffix;
203
- const threeVersionExpression = desiredKey.name + threeVersionSuffix;
204
- for (const searchPath of this.searchPaths) {
205
- this.addCandidateNoExtSchemaKey(foundFiles, searchPath, desiredKey.name, desiredKey, matchType, format);
206
- this.addCandidateSchemaKeys(foundFiles, searchPath, twoVersionExpression, desiredKey, matchType, format);
207
- this.addCandidateSchemaKeys(foundFiles, searchPath, threeVersionExpression, desiredKey, matchType, format);
208
- }
209
- return foundFiles;
210
- }
211
- }
212
- exports.SchemaFileLocater = SchemaFileLocater;
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.SchemaFileLocater = exports.FileSchemaKey = void 0;
8
+ const fs = require("fs");
9
+ const glob = require("glob");
10
+ const path = require("path");
11
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
+ /** @packageDocumentation
13
+ * @module Locaters
14
+ */
15
+ const formatString = (format, ...args) => {
16
+ return format.replace(/{(\d+)}/g, (match, theNumber) => {
17
+ return typeof args[theNumber] !== "undefined"
18
+ ? args[theNumber]
19
+ : match;
20
+ });
21
+ };
22
+ const padStartEx = (str, targetLength, padString) => {
23
+ targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;
24
+ padString = String((typeof padString !== "undefined" ? padString : " "));
25
+ if (str.length > targetLength) {
26
+ return String(str);
27
+ }
28
+ else {
29
+ targetLength = targetLength - str.length;
30
+ if (targetLength > padString.length) {
31
+ padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
32
+ }
33
+ return padString.slice(0, targetLength) + str;
34
+ }
35
+ };
36
+ /**
37
+ * A SchemaKey implementation that aids in identifying Schema files via the
38
+ * addition of two properties: fileName and schemaText. The fileName contains the
39
+ * full path to the file on disk and schemaText is the full string representation
40
+ * of the Schema.
41
+ * @beta
42
+ */
43
+ class FileSchemaKey extends ecschema_metadata_1.SchemaKey {
44
+ /**
45
+ * Initializes a new FileSchemaKey object.
46
+ * @param key The EC SchemaKey identifying the Schema.
47
+ * @param fileName The full path to the Schema file.
48
+ * @param schemaText The string representation of the Schema
49
+ * loaded from disk. Optional.
50
+ */
51
+ constructor(key, fileName, schemaJson) {
52
+ super(key.name, key.version);
53
+ this.fileName = fileName;
54
+ this.schemaText = schemaJson;
55
+ }
56
+ }
57
+ exports.FileSchemaKey = FileSchemaKey;
58
+ /**
59
+ * Abstract class to hold common/overlapping functionality between SchemaJsonFileLocater and SchemaXmlFileLocater
60
+ * @beta - Needs further testing and possibly moved to a separate package.
61
+ */
62
+ class SchemaFileLocater {
63
+ constructor() {
64
+ /**
65
+ * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
66
+ * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.
67
+ * @param lhs The 'left-hand' FileSchemaKey.
68
+ * @param rhs The 'right-hand' FileSchemaKey.
69
+ */
70
+ this.compareSchemaKeyByVersion = (lhs, rhs) => {
71
+ return lhs.compareByVersion(rhs);
72
+ };
73
+ this.searchPaths = [];
74
+ }
75
+ async readUtf8FileToString(filePath) {
76
+ return new Promise((resolve, reject) => {
77
+ fs.readFile(filePath, "utf-8", (err, data) => {
78
+ if (err)
79
+ reject(err);
80
+ else
81
+ resolve(data);
82
+ });
83
+ });
84
+ }
85
+ readUtf8FileToStringSync(filePath) {
86
+ return fs.readFileSync(filePath, "utf-8");
87
+ }
88
+ async fileExists(filePath) {
89
+ return new Promise((resolve) => {
90
+ fs.access(filePath, fs.constants.F_OK, (err) => {
91
+ resolve(err ? false : true);
92
+ });
93
+ });
94
+ }
95
+ fileExistsSync(filePath) {
96
+ return fs.existsSync(filePath);
97
+ }
98
+ /**
99
+ * Adds more search paths used by this locator to find the
100
+ * Schema files.
101
+ * @param schemaPaths An array of search paths to add
102
+ */
103
+ addSchemaSearchPaths(schemaPaths) {
104
+ // If the path is not in the schemaPaths array, add it
105
+ for (const schemaPath of schemaPaths)
106
+ this.addSchemaSearchPath(schemaPath);
107
+ }
108
+ /**
109
+ * Add one search path used by this locator to find the
110
+ * Schema files.
111
+ * @param schemaPath A search path to add
112
+ */
113
+ addSchemaSearchPath(schemaPath) {
114
+ // If the path is not in the schemaPaths array, add it
115
+ if (!this.searchPaths.find((entry) => entry === schemaPath))
116
+ this.searchPaths.push(schemaPath);
117
+ }
118
+ /**
119
+ * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey. This method
120
+ * only attempts to find schema files that have no version in the file name.
121
+ * @param foundFiles The collection of SchemaKeys found in the given directory.
122
+ * @param schemaPath The directory in which to search for the Schemas.
123
+ * @param schemaName The short name of the Schema (without version).
124
+ * @param desiredKey The SchemaKey used to find matching Schema files.
125
+ * @param matchType The SchemaMatchType to use when comparing the desiredKey and the keys found during the search.
126
+ * @param format The type of file that the schema key refers to. json or xml
127
+ */
128
+ addCandidateNoExtSchemaKey(foundFiles, schemaPath, schemaName, desiredKey, matchType, format) {
129
+ const fullPath = path.join(schemaPath, `${schemaName}.ecschema.${format}`);
130
+ // If the file does not exist, end
131
+ if (!fs.existsSync(fullPath))
132
+ return;
133
+ // Read the file
134
+ const file = fs.readFileSync(fullPath);
135
+ if (!file)
136
+ return;
137
+ // Get the schema key
138
+ const key = this.getSchemaKey(file.toString());
139
+ // If the key matches, put it in foundFiles
140
+ if (key.matches(desiredKey, matchType))
141
+ foundFiles.push(new FileSchemaKey(key, fullPath, file.toString()));
142
+ }
143
+ /**
144
+ * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey
145
+ * @param foundFiles The collection of SchemaKeys found in the given directory
146
+ * @param schemaPath The directory in which to search for the Schemas
147
+ * @param fileFilter The file filter, potentially with wildcards, used to locate the Schema files.
148
+ * @param desiredKey The schemaKey used to find matching Schema files
149
+ * @param matchType The SchemaMatchType to use when comparing the desired Key and the keys found during the search.
150
+ * @param format The type of file that the schema key refers to. json or xml
151
+ */
152
+ addCandidateSchemaKeys(foundFiles, schemaPath, fileFilter, desiredKey, matchType, format) {
153
+ const fullPath = path.join(schemaPath, fileFilter);
154
+ const result = new glob.GlobSync(fullPath, { sync: true });
155
+ for (const match of result.found) {
156
+ let fileName = path.basename(match, (`.ecschema.${format}`));
157
+ // TODO: should this be moved or handled elsewhere?
158
+ // Handles two version file names - SchemaKey.parseString supports only 3 version names.
159
+ if (/[^\d]\.\d?\d\.\d?\d$/.test(fileName)) {
160
+ const parts = fileName.split(".");
161
+ parts.splice(2, 0, "00");
162
+ fileName = parts.join(".");
163
+ }
164
+ const file = fs.readFileSync(match);
165
+ if (!file)
166
+ continue;
167
+ const schemaKey = ecschema_metadata_1.SchemaKey.parseString(fileName);
168
+ if (schemaKey.matches(desiredKey, matchType))
169
+ foundFiles.push(new FileSchemaKey(schemaKey, match, file.toString()));
170
+ }
171
+ }
172
+ /**
173
+ * Attempts to find all Schema files in the configurable search paths that match
174
+ * the desired SchemaKey.
175
+ * @param desiredKey The SchemaKey to match.
176
+ * @param matchType The SchemaMatchType.
177
+ * @param format The type of file that the schema key refers to. json or xml
178
+ */
179
+ findEligibleSchemaKeys(desiredKey, matchType, format) {
180
+ const foundFiles = new Array();
181
+ let twoVersionSuffix;
182
+ let threeVersionSuffix;
183
+ const readVersion = desiredKey.readVersion.toString();
184
+ const writeVersion = desiredKey.writeVersion.toString();
185
+ const minorVersion = desiredKey.minorVersion.toString();
186
+ if (matchType === ecschema_metadata_1.SchemaMatchType.Latest) {
187
+ twoVersionSuffix = (`.*.*.ecschema.${format}`);
188
+ threeVersionSuffix = (`.*.*.*.ecschema.${format}`);
189
+ }
190
+ else if (matchType === ecschema_metadata_1.SchemaMatchType.LatestWriteCompatible) {
191
+ twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"));
192
+ threeVersionSuffix = formatString(`.{0}.{1}.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"), padStartEx(writeVersion, 2, "0"));
193
+ }
194
+ else if (matchType === ecschema_metadata_1.SchemaMatchType.LatestReadCompatible) {
195
+ twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"));
196
+ threeVersionSuffix = formatString(`.{0}.*.*.ecschema.${format}`, padStartEx(readVersion, 2, "0"));
197
+ }
198
+ else {
199
+ twoVersionSuffix = formatString(`.{0}.{1}.ecschema.${format}`, padStartEx(readVersion, 2, "0"), padStartEx(writeVersion, 2, "0"));
200
+ threeVersionSuffix = formatString(`.{0}.{1}.{2}.ecschema.${format}`, padStartEx(readVersion, 2, "0"), padStartEx(writeVersion, 2, "0"), padStartEx(minorVersion, 2, "0"));
201
+ }
202
+ const twoVersionExpression = desiredKey.name + twoVersionSuffix;
203
+ const threeVersionExpression = desiredKey.name + threeVersionSuffix;
204
+ for (const searchPath of this.searchPaths) {
205
+ this.addCandidateNoExtSchemaKey(foundFiles, searchPath, desiredKey.name, desiredKey, matchType, format);
206
+ this.addCandidateSchemaKeys(foundFiles, searchPath, twoVersionExpression, desiredKey, matchType, format);
207
+ this.addCandidateSchemaKeys(foundFiles, searchPath, threeVersionExpression, desiredKey, matchType, format);
208
+ }
209
+ return foundFiles;
210
+ }
211
+ }
212
+ exports.SchemaFileLocater = SchemaFileLocater;
213
213
  //# sourceMappingURL=SchemaFileLocater.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaFileLocater.js","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,gEAA6F;AAE7F;;GAEG;AAEH,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,IAAc,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE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AAC,CAAC;SAC3K;QAED,MAAM,oBAAoB,GAAG,UAAU,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAChE,MAAM,sBAAsB,GAAG,UAAU,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAEpE,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE;YACzC,IAAI,CAAC,0BAA0B,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YACxG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YACzG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;SAC5G;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CAaF;AA9KD,8CA8KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as fs from \"fs\";\r\nimport * as glob from \"glob\";\r\nimport * as path from \"path\";\r\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\n\r\n/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nconst formatString = (format: string, ...args: string[]) => {\r\n return format.replace(/{(\\d+)}/g, (match, theNumber) => {\r\n return typeof args[theNumber] !== \"undefined\"\r\n ? args[theNumber]\r\n : match;\r\n });\r\n};\r\n\r\nconst padStartEx = (str: string, targetLength: number, padString: string) => {\r\n targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;\r\n padString = String((typeof padString !== \"undefined\" ? padString : \" \"));\r\n if (str.length > targetLength) {\r\n return String(str);\r\n } else {\r\n targetLength = targetLength - str.length;\r\n if (targetLength > padString.length) {\r\n padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed\r\n }\r\n return padString.slice(0, targetLength) + str;\r\n }\r\n};\r\n\r\n/**\r\n * A SchemaKey implementation that aids in identifying Schema files via the\r\n * addition of two properties: fileName and schemaText. The fileName contains the\r\n * full path to the file on disk and schemaText is the full string representation\r\n * of the Schema.\r\n * @beta\r\n */\r\nexport class FileSchemaKey extends SchemaKey {\r\n // The schema file associated with the SchemaKey\r\n public fileName: string;\r\n // The JSON text for the schema loaded\r\n public schemaText?: string;\r\n\r\n /**\r\n * Initializes a new FileSchemaKey object.\r\n * @param key The EC SchemaKey identifying the Schema.\r\n * @param fileName The full path to the Schema file.\r\n * @param schemaText The string representation of the Schema\r\n * loaded from disk. Optional.\r\n */\r\n constructor(key: SchemaKey, fileName: string, schemaJson?: string) {\r\n super(key.name, key.version);\r\n this.fileName = fileName;\r\n this.schemaText = schemaJson;\r\n }\r\n}\r\n\r\n/**\r\n * Abstract class to hold common/overlapping functionality between SchemaJsonFileLocater and SchemaXmlFileLocater\r\n * @beta - Needs further testing and possibly moved to a separate package.\r\n */\r\nexport abstract class SchemaFileLocater {\r\n public searchPaths: string[];\r\n\r\n constructor() {\r\n this.searchPaths = [];\r\n }\r\n\r\n public async readUtf8FileToString(filePath: string): Promise<string | undefined> {\r\n return new Promise<string | undefined>((resolve, reject) => {\r\n fs.readFile(filePath, \"utf-8\", (err, data) => {\r\n if (err)\r\n reject(err);\r\n else\r\n resolve(data);\r\n });\r\n });\r\n }\r\n\r\n public readUtf8FileToStringSync(filePath: string): string | undefined {\r\n return fs.readFileSync(filePath, \"utf-8\");\r\n }\r\n\r\n public async fileExists(filePath: string): Promise<boolean | undefined> {\r\n return new Promise<boolean | undefined>((resolve) => {\r\n fs.access(filePath, fs.constants.F_OK, (err) => {\r\n resolve(err ? false : true);\r\n });\r\n });\r\n }\r\n\r\n public fileExistsSync(filePath: string): boolean | undefined {\r\n return fs.existsSync(filePath);\r\n }\r\n\r\n /**\r\n * Adds more search paths used by this locator to find the\r\n * Schema files.\r\n * @param schemaPaths An array of search paths to add\r\n */\r\n public addSchemaSearchPaths(schemaPaths: string[]) {\r\n // If the path is not in the schemaPaths array, add it\r\n for (const schemaPath of schemaPaths)\r\n this.addSchemaSearchPath(schemaPath);\r\n }\r\n\r\n /**\r\n * Add one search path used by this locator to find the\r\n * Schema files.\r\n * @param schemaPath A search path to add\r\n */\r\n public addSchemaSearchPath(schemaPath: string) {\r\n // If the path is not in the schemaPaths array, add it\r\n if (!this.searchPaths.find((entry) => entry === schemaPath))\r\n this.searchPaths.push(schemaPath);\r\n }\r\n\r\n protected abstract getSchemaKey(data: string): SchemaKey;\r\n\r\n /**\r\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey. This method\r\n * only attempts to find schema files that have no version in the file name.\r\n * @param foundFiles The collection of SchemaKeys found in the given directory.\r\n * @param schemaPath The directory in which to search for the Schemas.\r\n * @param schemaName The short name of the Schema (without version).\r\n * @param desiredKey The SchemaKey used to find matching Schema files.\r\n * @param matchType The SchemaMatchType to use when comparing the desiredKey and the keys found during the search.\r\n * @param format The type of file that the schema key refers to. json or xml\r\n */\r\n private addCandidateNoExtSchemaKey(foundFiles: FileSchemaKey[], schemaPath: string, schemaName: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\r\n const fullPath = path.join(schemaPath, `${schemaName}.ecschema.${format}`);\r\n\r\n // If the file does not exist, end\r\n if (!fs.existsSync(fullPath))\r\n return;\r\n\r\n // Read the file\r\n const file = fs.readFileSync(fullPath);\r\n if (!file)\r\n return;\r\n\r\n // Get the schema key\r\n const key = this.getSchemaKey(file.toString());\r\n\r\n // If the key matches, put it in foundFiles\r\n if (key.matches(desiredKey, matchType))\r\n foundFiles.push(new FileSchemaKey(key, fullPath, file.toString()));\r\n }\r\n\r\n /**\r\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey\r\n * @param foundFiles The collection of SchemaKeys found in the given directory\r\n * @param schemaPath The directory in which to search for the Schemas\r\n * @param fileFilter The file filter, potentially with wildcards, used to locate the Schema files.\r\n * @param desiredKey The schemaKey used to find matching Schema files\r\n * @param matchType The SchemaMatchType to use when comparing the desired Key and the keys found during the search.\r\n * @param format The type of file that the schema key refers to. json or xml\r\n */\r\n private addCandidateSchemaKeys(foundFiles: FileSchemaKey[], schemaPath: string, fileFilter: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\r\n const fullPath = path.join(schemaPath, fileFilter);\r\n\r\n const result = new glob.GlobSync(fullPath, { sync: true });\r\n for (const match of result.found) {\r\n let fileName = path.basename(match, (`.ecschema.${format}`));\r\n // TODO: should this be moved or handled elsewhere?\r\n // Handles two version file names - SchemaKey.parseString supports only 3 version names.\r\n if (/[^\\d]\\.\\d?\\d\\.\\d?\\d$/.test(fileName)) {\r\n const parts = fileName.split(\".\");\r\n parts.splice(2, 0, \"00\");\r\n fileName = parts.join(\".\");\r\n }\r\n\r\n const file = fs.readFileSync(match);\r\n if (!file)\r\n continue;\r\n\r\n const schemaKey = SchemaKey.parseString(fileName);\r\n if (schemaKey.matches(desiredKey, matchType))\r\n foundFiles.push(new FileSchemaKey(schemaKey, match, file.toString()));\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to find all Schema files in the configurable search paths that match\r\n * the desired SchemaKey.\r\n * @param desiredKey The SchemaKey to match.\r\n * @param matchType The SchemaMatchType.\r\n * @param format The type of file that the schema key refers to. json or xml\r\n */\r\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType, format: string): FileSchemaKey[] {\r\n const foundFiles = new Array<FileSchemaKey>();\r\n\r\n let twoVersionSuffix: string;\r\n let threeVersionSuffix: string;\r\n const readVersion = desiredKey.readVersion.toString();\r\n const writeVersion = desiredKey.writeVersion.toString();\r\n const minorVersion = desiredKey.minorVersion.toString();\r\n\r\n if (matchType === SchemaMatchType.Latest) {\r\n twoVersionSuffix = (`.*.*.ecschema.${format}`);\r\n threeVersionSuffix = (`.*.*.*.ecschema.${format}`);\r\n } else if (matchType === SchemaMatchType.LatestWriteCompatible) {\r\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\r\n threeVersionSuffix = formatString(`.{0}.{1}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\r\n } else if (matchType === SchemaMatchType.LatestReadCompatible) {\r\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\r\n threeVersionSuffix = formatString(`.{0}.*.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\r\n } else {\r\n twoVersionSuffix = formatString(`.{0}.{1}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\r\n threeVersionSuffix = formatString(`.{0}.{1}.{2}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"), padStartEx(minorVersion, 2, \"0\"));\r\n }\r\n\r\n const twoVersionExpression = desiredKey.name + twoVersionSuffix;\r\n const threeVersionExpression = desiredKey.name + threeVersionSuffix;\r\n\r\n for (const searchPath of this.searchPaths) {\r\n this.addCandidateNoExtSchemaKey(foundFiles, searchPath, desiredKey.name, desiredKey, matchType, format);\r\n this.addCandidateSchemaKeys(foundFiles, searchPath, twoVersionExpression, desiredKey, matchType, format);\r\n this.addCandidateSchemaKeys(foundFiles, searchPath, threeVersionExpression, desiredKey, matchType, format);\r\n }\r\n\r\n return foundFiles;\r\n }\r\n\r\n public abstract getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;\r\n\r\n /**\r\n * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the\r\n * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.\r\n * @param lhs The 'left-hand' FileSchemaKey.\r\n * @param rhs The 'right-hand' FileSchemaKey.\r\n */\r\n public compareSchemaKeyByVersion = (lhs: FileSchemaKey, rhs: FileSchemaKey): number => {\r\n return lhs.compareByVersion(rhs);\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaFileLocater.js","sourceRoot":"","sources":["../../src/SchemaFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,gEAA6F;AAE7F;;GAEG;AAEH,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,IAAc,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACrD,OAAO,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,WAAW;YAC3C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,YAAoB,EAAE,SAAiB,EAAE,EAAE;IAC1E,YAAY,GAAG,YAAY,IAAI,CAAC,CAAC,CAAC,iDAAiD;IACnF,SAAS,GAAG,MAAM,CAAC,CAAC,OAAO,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzE,IAAI,GAAG,CAAC,MAAM,GAAG,YAAY,EAAE;QAC7B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;SAAM;QACL,YAAY,GAAG,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC;QACzC,IAAI,YAAY,GAAG,SAAS,CAAC,MAAM,EAAE;YACnC,SAAS,IAAI,SAAS,CAAC,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,yDAAyD;SAC1H;QACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG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AAM;YACL,gBAAgB,GAAG,YAAY,CAAC,qBAAqB,MAAM,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAClI,kBAAkB,GAAG,YAAY,CAAC,yBAAyB,MAAM,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;SAC3K;QAED,MAAM,oBAAoB,GAAG,UAAU,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAChE,MAAM,sBAAsB,GAAG,UAAU,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAEpE,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE;YACzC,IAAI,CAAC,0BAA0B,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YACxG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YACzG,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;SAC5G;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CAaF;AA9KD,8CA8KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as fs from \"fs\";\nimport * as glob from \"glob\";\nimport * as path from \"path\";\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\n\n/** @packageDocumentation\n * @module Locaters\n */\n\nconst formatString = (format: string, ...args: string[]) => {\n return format.replace(/{(\\d+)}/g, (match, theNumber) => {\n return typeof args[theNumber] !== \"undefined\"\n ? args[theNumber]\n : match;\n });\n};\n\nconst padStartEx = (str: string, targetLength: number, padString: string) => {\n targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;\n padString = String((typeof padString !== \"undefined\" ? padString : \" \"));\n if (str.length > targetLength) {\n return String(str);\n } else {\n targetLength = targetLength - str.length;\n if (targetLength > padString.length) {\n padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed\n }\n return padString.slice(0, targetLength) + str;\n }\n};\n\n/**\n * A SchemaKey implementation that aids in identifying Schema files via the\n * addition of two properties: fileName and schemaText. The fileName contains the\n * full path to the file on disk and schemaText is the full string representation\n * of the Schema.\n * @beta\n */\nexport class FileSchemaKey extends SchemaKey {\n // The schema file associated with the SchemaKey\n public fileName: string;\n // The JSON text for the schema loaded\n public schemaText?: string;\n\n /**\n * Initializes a new FileSchemaKey object.\n * @param key The EC SchemaKey identifying the Schema.\n * @param fileName The full path to the Schema file.\n * @param schemaText The string representation of the Schema\n * loaded from disk. Optional.\n */\n constructor(key: SchemaKey, fileName: string, schemaJson?: string) {\n super(key.name, key.version);\n this.fileName = fileName;\n this.schemaText = schemaJson;\n }\n}\n\n/**\n * Abstract class to hold common/overlapping functionality between SchemaJsonFileLocater and SchemaXmlFileLocater\n * @beta - Needs further testing and possibly moved to a separate package.\n */\nexport abstract class SchemaFileLocater {\n public searchPaths: string[];\n\n constructor() {\n this.searchPaths = [];\n }\n\n public async readUtf8FileToString(filePath: string): Promise<string | undefined> {\n return new Promise<string | undefined>((resolve, reject) => {\n fs.readFile(filePath, \"utf-8\", (err, data) => {\n if (err)\n reject(err);\n else\n resolve(data);\n });\n });\n }\n\n public readUtf8FileToStringSync(filePath: string): string | undefined {\n return fs.readFileSync(filePath, \"utf-8\");\n }\n\n public async fileExists(filePath: string): Promise<boolean | undefined> {\n return new Promise<boolean | undefined>((resolve) => {\n fs.access(filePath, fs.constants.F_OK, (err) => {\n resolve(err ? false : true);\n });\n });\n }\n\n public fileExistsSync(filePath: string): boolean | undefined {\n return fs.existsSync(filePath);\n }\n\n /**\n * Adds more search paths used by this locator to find the\n * Schema files.\n * @param schemaPaths An array of search paths to add\n */\n public addSchemaSearchPaths(schemaPaths: string[]) {\n // If the path is not in the schemaPaths array, add it\n for (const schemaPath of schemaPaths)\n this.addSchemaSearchPath(schemaPath);\n }\n\n /**\n * Add one search path used by this locator to find the\n * Schema files.\n * @param schemaPath A search path to add\n */\n public addSchemaSearchPath(schemaPath: string) {\n // If the path is not in the schemaPaths array, add it\n if (!this.searchPaths.find((entry) => entry === schemaPath))\n this.searchPaths.push(schemaPath);\n }\n\n protected abstract getSchemaKey(data: string): SchemaKey;\n\n /**\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey. This method\n * only attempts to find schema files that have no version in the file name.\n * @param foundFiles The collection of SchemaKeys found in the given directory.\n * @param schemaPath The directory in which to search for the Schemas.\n * @param schemaName The short name of the Schema (without version).\n * @param desiredKey The SchemaKey used to find matching Schema files.\n * @param matchType The SchemaMatchType to use when comparing the desiredKey and the keys found during the search.\n * @param format The type of file that the schema key refers to. json or xml\n */\n private addCandidateNoExtSchemaKey(foundFiles: FileSchemaKey[], schemaPath: string, schemaName: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\n const fullPath = path.join(schemaPath, `${schemaName}.ecschema.${format}`);\n\n // If the file does not exist, end\n if (!fs.existsSync(fullPath))\n return;\n\n // Read the file\n const file = fs.readFileSync(fullPath);\n if (!file)\n return;\n\n // Get the schema key\n const key = this.getSchemaKey(file.toString());\n\n // If the key matches, put it in foundFiles\n if (key.matches(desiredKey, matchType))\n foundFiles.push(new FileSchemaKey(key, fullPath, file.toString()));\n }\n\n /**\n * Adds SchemaKeys to the provided foundFiles collection that match the desired SchemaKey\n * @param foundFiles The collection of SchemaKeys found in the given directory\n * @param schemaPath The directory in which to search for the Schemas\n * @param fileFilter The file filter, potentially with wildcards, used to locate the Schema files.\n * @param desiredKey The schemaKey used to find matching Schema files\n * @param matchType The SchemaMatchType to use when comparing the desired Key and the keys found during the search.\n * @param format The type of file that the schema key refers to. json or xml\n */\n private addCandidateSchemaKeys(foundFiles: FileSchemaKey[], schemaPath: string, fileFilter: string, desiredKey: SchemaKey, matchType: SchemaMatchType, format: string) {\n const fullPath = path.join(schemaPath, fileFilter);\n\n const result = new glob.GlobSync(fullPath, { sync: true });\n for (const match of result.found) {\n let fileName = path.basename(match, (`.ecschema.${format}`));\n // TODO: should this be moved or handled elsewhere?\n // Handles two version file names - SchemaKey.parseString supports only 3 version names.\n if (/[^\\d]\\.\\d?\\d\\.\\d?\\d$/.test(fileName)) {\n const parts = fileName.split(\".\");\n parts.splice(2, 0, \"00\");\n fileName = parts.join(\".\");\n }\n\n const file = fs.readFileSync(match);\n if (!file)\n continue;\n\n const schemaKey = SchemaKey.parseString(fileName);\n if (schemaKey.matches(desiredKey, matchType))\n foundFiles.push(new FileSchemaKey(schemaKey, match, file.toString()));\n }\n }\n\n /**\n * Attempts to find all Schema files in the configurable search paths that match\n * the desired SchemaKey.\n * @param desiredKey The SchemaKey to match.\n * @param matchType The SchemaMatchType.\n * @param format The type of file that the schema key refers to. json or xml\n */\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType, format: string): FileSchemaKey[] {\n const foundFiles = new Array<FileSchemaKey>();\n\n let twoVersionSuffix: string;\n let threeVersionSuffix: string;\n const readVersion = desiredKey.readVersion.toString();\n const writeVersion = desiredKey.writeVersion.toString();\n const minorVersion = desiredKey.minorVersion.toString();\n\n if (matchType === SchemaMatchType.Latest) {\n twoVersionSuffix = (`.*.*.ecschema.${format}`);\n threeVersionSuffix = (`.*.*.*.ecschema.${format}`);\n } else if (matchType === SchemaMatchType.LatestWriteCompatible) {\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\n threeVersionSuffix = formatString(`.{0}.{1}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\n } else if (matchType === SchemaMatchType.LatestReadCompatible) {\n twoVersionSuffix = formatString(`.{0}.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\n threeVersionSuffix = formatString(`.{0}.*.*.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"));\n } else {\n twoVersionSuffix = formatString(`.{0}.{1}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"));\n threeVersionSuffix = formatString(`.{0}.{1}.{2}.ecschema.${format}`, padStartEx(readVersion, 2, \"0\"), padStartEx(writeVersion, 2, \"0\"), padStartEx(minorVersion, 2, \"0\"));\n }\n\n const twoVersionExpression = desiredKey.name + twoVersionSuffix;\n const threeVersionExpression = desiredKey.name + threeVersionSuffix;\n\n for (const searchPath of this.searchPaths) {\n this.addCandidateNoExtSchemaKey(foundFiles, searchPath, desiredKey.name, desiredKey, matchType, format);\n this.addCandidateSchemaKeys(foundFiles, searchPath, twoVersionExpression, desiredKey, matchType, format);\n this.addCandidateSchemaKeys(foundFiles, searchPath, threeVersionExpression, desiredKey, matchType, format);\n }\n\n return foundFiles;\n }\n\n public abstract getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;\n\n /**\n * Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the\n * left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.\n * @param lhs The 'left-hand' FileSchemaKey.\n * @param rhs The 'right-hand' FileSchemaKey.\n */\n public compareSchemaKeyByVersion = (lhs: FileSchemaKey, rhs: FileSchemaKey): number => {\n return lhs.compareByVersion(rhs);\n };\n}\n"]}
@@ -1,18 +1,18 @@
1
- import { Schema } from "@itwin/ecschema-metadata";
2
- /** @packageDocumentation
3
- * @module Utils
4
- */
5
- /**
6
- * Utility class to assist in creating serialized EC Schemas on the file system.
7
- * @beta
8
- */
9
- export declare class SchemaFileUtility {
10
- /**
11
- * Writes a Schema to an xml file to the specified output path.
12
- * @param schema The Schema to serialize.
13
- * @param outputPath The directory in which to create the file.
14
- */
15
- static writeSchemaXmlFile(schema: Schema, outputPath: string): Promise<void>;
16
- private static getSchemaPath;
17
- }
1
+ import { Schema } from "@itwin/ecschema-metadata";
2
+ /** @packageDocumentation
3
+ * @module Utils
4
+ */
5
+ /**
6
+ * Utility class to assist in creating serialized EC Schemas on the file system.
7
+ * @beta
8
+ */
9
+ export declare class SchemaFileUtility {
10
+ /**
11
+ * Writes a Schema to an xml file to the specified output path.
12
+ * @param schema The Schema to serialize.
13
+ * @param outputPath The directory in which to create the file.
14
+ */
15
+ static writeSchemaXmlFile(schema: Schema, outputPath: string): Promise<void>;
16
+ private static getSchemaPath;
17
+ }
18
18
  //# sourceMappingURL=SchemaFileUtility.d.ts.map
@@ -1,49 +1,49 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchemaFileUtility = void 0;
4
- /*---------------------------------------------------------------------------------------------
5
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
- * See LICENSE.md in the project root for license terms and full copyright notice.
7
- *--------------------------------------------------------------------------------------------*/
8
- const fs = require("fs-extra");
9
- const path = require("path");
10
- const xmldom_1 = require("@xmldom/xmldom");
11
- /** @packageDocumentation
12
- * @module Utils
13
- */
14
- /**
15
- * Utility class to assist in creating serialized EC Schemas on the file system.
16
- * @beta
17
- */
18
- class SchemaFileUtility {
19
- /**
20
- * Writes a Schema to an xml file to the specified output path.
21
- * @param schema The Schema to serialize.
22
- * @param outputPath The directory in which to create the file.
23
- */
24
- static async writeSchemaXmlFile(schema, outputPath) {
25
- let xmlDoc = new xmldom_1.DOMParser().parseFromString(`<?xml version="1.0" encoding="UTF-8"?>`, "application/xml");
26
- const baseFile = this.getSchemaPath(schema, outputPath);
27
- xmlDoc = await schema.toXml(xmlDoc);
28
- const serializer = new xmldom_1.XMLSerializer();
29
- const xml = serializer.serializeToString(xmlDoc);
30
- try {
31
- await fs.writeFile(baseFile, xml);
32
- }
33
- catch (err) {
34
- const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;
35
- throw new Error(msg);
36
- }
37
- }
38
- static getSchemaPath(schema, outputPath) {
39
- const realDir = path.normalize(outputPath);
40
- const test = fs.pathExistsSync(realDir);
41
- if (!test) {
42
- const msg = `The output directory '${realDir}' does not exist.`;
43
- throw new Error(msg);
44
- }
45
- return path.resolve(realDir, `${schema.name}.ecschema.xml`);
46
- }
47
- }
48
- exports.SchemaFileUtility = SchemaFileUtility;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaFileUtility = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const fs = require("fs-extra");
9
+ const path = require("path");
10
+ const xmldom_1 = require("@xmldom/xmldom");
11
+ /** @packageDocumentation
12
+ * @module Utils
13
+ */
14
+ /**
15
+ * Utility class to assist in creating serialized EC Schemas on the file system.
16
+ * @beta
17
+ */
18
+ class SchemaFileUtility {
19
+ /**
20
+ * Writes a Schema to an xml file to the specified output path.
21
+ * @param schema The Schema to serialize.
22
+ * @param outputPath The directory in which to create the file.
23
+ */
24
+ static async writeSchemaXmlFile(schema, outputPath) {
25
+ let xmlDoc = new xmldom_1.DOMParser().parseFromString(`<?xml version="1.0" encoding="UTF-8"?>`, "application/xml");
26
+ const baseFile = this.getSchemaPath(schema, outputPath);
27
+ xmlDoc = await schema.toXml(xmlDoc);
28
+ const serializer = new xmldom_1.XMLSerializer();
29
+ const xml = serializer.serializeToString(xmlDoc);
30
+ try {
31
+ await fs.writeFile(baseFile, xml);
32
+ }
33
+ catch (err) {
34
+ const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;
35
+ throw new Error(msg);
36
+ }
37
+ }
38
+ static getSchemaPath(schema, outputPath) {
39
+ const realDir = path.normalize(outputPath);
40
+ const test = fs.pathExistsSync(realDir);
41
+ if (!test) {
42
+ const msg = `The output directory '${realDir}' does not exist.`;
43
+ throw new Error(msg);
44
+ }
45
+ return path.resolve(realDir, `${schema.name}.ecschema.xml`);
46
+ }
47
+ }
48
+ exports.SchemaFileUtility = SchemaFileUtility;
49
49
  //# sourceMappingURL=SchemaFileUtility.js.map