@itwin/ecschema-locaters 3.4.0-dev.9 → 3.5.0-dev.4

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 (38) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/lib/cjs/SchemaFileLocater.d.ts +82 -82
  3. package/lib/cjs/SchemaFileLocater.d.ts.map +1 -1
  4. package/lib/cjs/SchemaFileLocater.js +212 -209
  5. package/lib/cjs/SchemaFileLocater.js.map +1 -1
  6. package/lib/cjs/SchemaFileUtility.d.ts +17 -14
  7. package/lib/cjs/SchemaFileUtility.d.ts.map +1 -1
  8. package/lib/cjs/SchemaFileUtility.js +48 -45
  9. package/lib/cjs/SchemaFileUtility.js.map +1 -1
  10. package/lib/cjs/SchemaJsonFileLocater.d.ts +33 -30
  11. package/lib/cjs/SchemaJsonFileLocater.d.ts.map +1 -1
  12. package/lib/cjs/SchemaJsonFileLocater.js +90 -87
  13. package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
  14. package/lib/cjs/SchemaXmlFileLocater.d.ts +33 -30
  15. package/lib/cjs/SchemaXmlFileLocater.d.ts.map +1 -1
  16. package/lib/cjs/SchemaXmlFileLocater.js +93 -90
  17. package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
  18. package/lib/cjs/StubSchemaXmlFileLocater.d.ts +69 -69
  19. package/lib/cjs/StubSchemaXmlFileLocater.d.ts.map +1 -1
  20. package/lib/cjs/StubSchemaXmlFileLocater.js +177 -174
  21. package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
  22. package/lib/cjs/ecschema-locaters.d.ts +17 -4
  23. package/lib/cjs/ecschema-locaters.d.ts.map +1 -1
  24. package/lib/cjs/ecschema-locaters.js +33 -20
  25. package/lib/cjs/ecschema-locaters.js.map +1 -1
  26. package/lib/cjs/test/SchemaFileUtility.test.d.ts +1 -1
  27. package/lib/cjs/test/SchemaFileUtility.test.js +56 -56
  28. package/lib/cjs/test/SchemaFileUtility.test.js.map +1 -1
  29. package/lib/cjs/test/SchemaJsonFileLocator.test.d.ts +1 -1
  30. package/lib/cjs/test/SchemaJsonFileLocator.test.js +119 -119
  31. package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
  32. package/lib/cjs/test/SchemaXmlFileLocator.test.d.ts +1 -1
  33. package/lib/cjs/test/SchemaXmlFileLocator.test.js +180 -180
  34. package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
  35. package/lib/cjs/test/StubSchemaXmlFileLocater.test.d.ts +1 -1
  36. package/lib/cjs/test/StubSchemaXmlFileLocater.test.js +170 -170
  37. package/lib/cjs/test/StubSchemaXmlFileLocater.test.js.map +1 -1
  38. package/package.json +6 -6
@@ -1,46 +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
- /**
12
- * Utility class to assist in creating serialized EC Schemas on the file system.
13
- * @beta
14
- */
15
- class SchemaFileUtility {
16
- /**
17
- * Writes a Schema to an xml file to the specified output path.
18
- * @param schema The Schema to serialize.
19
- * @param outputPath The directory in which to create the file.
20
- */
21
- static async writeSchemaXmlFile(schema, outputPath) {
22
- let xmlDoc = new xmldom_1.DOMParser().parseFromString(`<?xml version="1.0" encoding="UTF-8"?>`, "application/xml");
23
- const baseFile = this.getSchemaPath(schema, outputPath);
24
- xmlDoc = await schema.toXml(xmlDoc);
25
- const serializer = new xmldom_1.XMLSerializer();
26
- const xml = serializer.serializeToString(xmlDoc);
27
- try {
28
- await fs.writeFile(baseFile, xml);
29
- }
30
- catch (err) {
31
- const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;
32
- throw new Error(msg);
33
- }
34
- }
35
- static getSchemaPath(schema, outputPath) {
36
- const realDir = path.normalize(outputPath);
37
- const test = fs.pathExistsSync(realDir);
38
- if (!test) {
39
- const msg = `The output directory '${realDir}' does not exist.`;
40
- throw new Error(msg);
41
- }
42
- return path.resolve(realDir, `${schema.name}.ecschema.xml`);
43
- }
44
- }
45
- 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;
46
49
  //# sourceMappingURL=SchemaFileUtility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaFileUtility.js","sourceRoot":"","sources":["../../src/SchemaFileUtility.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,+BAA+B;AAC/B,6BAA6B;AAC7B,2CAA0D;AAG1D;;;GAGG;AACH,MAAa,iBAAiB;IAE5B;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,UAAkB;QACvE,IAAI,MAAM,GAAG,IAAI,kBAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAC1G,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAExD,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,sBAAa,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAEjD,IAAI;YACF,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;SACnC;QAAC,OAAO,GAAQ,EAAE;YACjB,MAAM,GAAG,GAAG,sCAAsC,QAAQ,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;IACH,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,MAAc,EAAE,UAAkB;QAC7D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,GAAG,GAAG,yBAAyB,OAAO,mBAAmB,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;SACtB;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;CACF;AAjCD,8CAiCC","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\nimport * as fs from \"fs-extra\";\r\nimport * as path from \"path\";\r\nimport { DOMParser, XMLSerializer } from \"@xmldom/xmldom\";\r\nimport { Schema } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * Utility class to assist in creating serialized EC Schemas on the file system.\r\n * @beta\r\n */\r\nexport class SchemaFileUtility {\r\n\r\n /**\r\n * Writes a Schema to an xml file to the specified output path.\r\n * @param schema The Schema to serialize.\r\n * @param outputPath The directory in which to create the file.\r\n */\r\n public static async writeSchemaXmlFile(schema: Schema, outputPath: string) {\r\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\r\n const baseFile = this.getSchemaPath(schema, outputPath);\r\n\r\n xmlDoc = await schema.toXml(xmlDoc);\r\n const serializer = new XMLSerializer();\r\n const xml = serializer.serializeToString(xmlDoc);\r\n\r\n try {\r\n await fs.writeFile(baseFile, xml);\r\n } catch (err: any) {\r\n const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;\r\n throw new Error(msg);\r\n }\r\n }\r\n\r\n private static getSchemaPath(schema: Schema, outputPath: string): string {\r\n const realDir = path.normalize(outputPath);\r\n const test = fs.pathExistsSync(realDir);\r\n if (!test) {\r\n const msg = `The output directory '${realDir}' does not exist.`;\r\n throw new Error(msg);\r\n }\r\n\r\n return path.resolve(realDir, `${schema.name}.ecschema.xml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;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;CACF;AAjCD,8CAiCC","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*--------------------------------------------------------------------------------------------*/\nimport * as fs from \"fs-extra\";\nimport * as path from \"path\";\nimport { DOMParser, XMLSerializer } from \"@xmldom/xmldom\";\nimport { Schema } from \"@itwin/ecschema-metadata\";\n\n/** @packageDocumentation\n * @module Utils\n */\n\n/**\n * Utility class to assist in creating serialized EC Schemas on the file system.\n * @beta\n */\nexport class SchemaFileUtility {\n\n /**\n * Writes a Schema to an xml file to the specified output path.\n * @param schema The Schema to serialize.\n * @param outputPath The directory in which to create the file.\n */\n public static async writeSchemaXmlFile(schema: Schema, outputPath: string) {\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\n const baseFile = this.getSchemaPath(schema, outputPath);\n\n xmlDoc = await schema.toXml(xmlDoc);\n const serializer = new XMLSerializer();\n const xml = serializer.serializeToString(xmlDoc);\n\n try {\n await fs.writeFile(baseFile, xml);\n } catch (err: any) {\n const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;\n throw new Error(msg);\n }\n }\n\n private static getSchemaPath(schema: Schema, outputPath: string): string {\n const realDir = path.normalize(outputPath);\n const test = fs.pathExistsSync(realDir);\n if (!test) {\n const msg = `The output directory '${realDir}' does not exist.`;\n throw new Error(msg);\n }\n\n return path.resolve(realDir, `${schema.name}.ecschema.xml`);\n }\n}\n"]}
@@ -1,31 +1,34 @@
1
- import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
- import { SchemaFileLocater } from "./SchemaFileLocater";
3
- /**
4
- * A SchemaLocator implementation for locating JSON Schema files
5
- * from the file system using configurable search paths.
6
- * @beta
7
- */
8
- export declare class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {
9
- /**
10
- * Constructs a SchemaKey based on the information in the Schema JSON
11
- * @param data The Schema JSON as a string
12
- */
13
- protected getSchemaKey(data: string): SchemaKey;
14
- /**
15
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
16
- * search paths to locate the JSON schema file from the file system.
17
- * @param key The SchemaKey of the Schema to retrieve.
18
- * @param matchType The SchemaMatchType.
19
- * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
20
- */
21
- getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
22
- /**
23
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
24
- * search paths to locate the JSON schema file from the file system.
25
- * @param key The SchemaKey of the Schema to retrieve.
26
- * @param matchType The SchemaMatchType
27
- * @param context The SchemaContext that will control the lifetime of the schema.
28
- */
29
- getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
30
- }
1
+ import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
+ import { SchemaFileLocater } from "./SchemaFileLocater";
3
+ /** @packageDocumentation
4
+ * @module Locaters
5
+ */
6
+ /**
7
+ * A SchemaLocator implementation for locating JSON Schema files
8
+ * from the file system using configurable search paths.
9
+ * @beta
10
+ */
11
+ export declare class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {
12
+ /**
13
+ * Constructs a SchemaKey based on the information in the Schema JSON
14
+ * @param data The Schema JSON as a string
15
+ */
16
+ protected getSchemaKey(data: string): SchemaKey;
17
+ /**
18
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
19
+ * search paths to locate the JSON schema file from the file system.
20
+ * @param key The SchemaKey of the Schema to retrieve.
21
+ * @param matchType The SchemaMatchType.
22
+ * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
23
+ */
24
+ getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
25
+ /**
26
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
27
+ * search paths to locate the JSON schema file from the file system.
28
+ * @param key The SchemaKey of the Schema to retrieve.
29
+ * @param matchType The SchemaMatchType
30
+ * @param context The SchemaContext that will control the lifetime of the schema.
31
+ */
32
+ getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
33
+ }
31
34
  //# sourceMappingURL=SchemaJsonFileLocater.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaJsonFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAOA,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAC9G,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,iBAAkB,YAAW,cAAc;IAEpF;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAmB/C;;;;;;OAMG;IACU,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAwB1I;;;;;;OAMG;IACI,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,CAAC,GAAG,SAAS;CAuBhI"}
1
+ {"version":3,"file":"SchemaJsonFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAOA,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAC9G,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;GAEG;AAEH;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,iBAAkB,YAAW,cAAc;IAEpF;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAmB/C;;;;;;OAMG;IACU,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAwB1I;;;;;;OAMG;IACI,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,CAAC,GAAG,SAAS;CAuBhI"}
@@ -1,88 +1,91 @@
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.SchemaJsonFileLocater = void 0;
8
- const fs = require("fs");
9
- const path = require("path");
10
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
11
- const SchemaFileLocater_1 = require("./SchemaFileLocater");
12
- /**
13
- * A SchemaLocator implementation for locating JSON Schema files
14
- * from the file system using configurable search paths.
15
- * @beta
16
- */
17
- class SchemaJsonFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
18
- /**
19
- * Constructs a SchemaKey based on the information in the Schema JSON
20
- * @param data The Schema JSON as a string
21
- */
22
- getSchemaKey(data) {
23
- const dataJson = JSON.parse(data);
24
- // Check if the name is present
25
- if (!(dataJson.name))
26
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);
27
- // Check if versions is present
28
- if (!(dataJson.version))
29
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);
30
- // Get the name and version from the JSON
31
- const schemaName = dataJson.name;
32
- const schemaVersion = dataJson.version;
33
- const key = new ecschema_metadata_1.SchemaKey(schemaName.toString(), ecschema_metadata_1.ECVersion.fromString(schemaVersion.toString()));
34
- return key;
35
- }
36
- /**
37
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
38
- * search paths to locate the JSON schema file from the file system.
39
- * @param key The SchemaKey of the Schema to retrieve.
40
- * @param matchType The SchemaMatchType.
41
- * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
42
- */
43
- async getSchema(schemaKey, matchType, context) {
44
- // Grab all schema files that match the schema key
45
- const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
46
- if (!candidates || candidates.length === 0)
47
- return undefined;
48
- // eslint-disable-next-line @typescript-eslint/unbound-method
49
- const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
50
- const schemaPath = maxCandidate.fileName;
51
- // Load the file
52
- if (!await this.fileExists(schemaPath))
53
- return undefined;
54
- const schemaText = await this.readUtf8FileToString(schemaPath);
55
- if (!schemaText)
56
- return undefined;
57
- this.addSchemaSearchPaths([path.dirname(schemaPath)]);
58
- const schema = await ecschema_metadata_1.Schema.fromJson(schemaText, context);
59
- return schema;
60
- }
61
- /**
62
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured
63
- * search paths to locate the JSON schema file from the file system.
64
- * @param key The SchemaKey of the Schema to retrieve.
65
- * @param matchType The SchemaMatchType
66
- * @param context The SchemaContext that will control the lifetime of the schema.
67
- */
68
- getSchemaSync(schemaKey, matchType, context) {
69
- // Grab all schema files that match the schema key
70
- const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
71
- if (!candidates || candidates.length === 0)
72
- return undefined;
73
- // eslint-disable-next-line @typescript-eslint/unbound-method
74
- const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
75
- const schemaPath = maxCandidate.fileName;
76
- // Load the file
77
- if (!fs.existsSync(schemaPath))
78
- return undefined;
79
- const schemaText = fs.readFileSync(schemaPath, "utf-8");
80
- if (!schemaText)
81
- return undefined;
82
- this.addSchemaSearchPaths([path.dirname(schemaPath)]);
83
- const schema = ecschema_metadata_1.Schema.fromJsonSync(schemaText, context);
84
- return schema;
85
- }
86
- }
87
- exports.SchemaJsonFileLocater = SchemaJsonFileLocater;
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.SchemaJsonFileLocater = void 0;
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
11
+ const SchemaFileLocater_1 = require("./SchemaFileLocater");
12
+ /** @packageDocumentation
13
+ * @module Locaters
14
+ */
15
+ /**
16
+ * A SchemaLocator implementation for locating JSON Schema files
17
+ * from the file system using configurable search paths.
18
+ * @beta
19
+ */
20
+ class SchemaJsonFileLocater extends SchemaFileLocater_1.SchemaFileLocater {
21
+ /**
22
+ * Constructs a SchemaKey based on the information in the Schema JSON
23
+ * @param data The Schema JSON as a string
24
+ */
25
+ getSchemaKey(data) {
26
+ const dataJson = JSON.parse(data);
27
+ // Check if the name is present
28
+ if (!(dataJson.name))
29
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);
30
+ // Check if versions is present
31
+ if (!(dataJson.version))
32
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);
33
+ // Get the name and version from the JSON
34
+ const schemaName = dataJson.name;
35
+ const schemaVersion = dataJson.version;
36
+ const key = new ecschema_metadata_1.SchemaKey(schemaName.toString(), ecschema_metadata_1.ECVersion.fromString(schemaVersion.toString()));
37
+ return key;
38
+ }
39
+ /**
40
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
41
+ * search paths to locate the JSON schema file from the file system.
42
+ * @param key The SchemaKey of the Schema to retrieve.
43
+ * @param matchType The SchemaMatchType.
44
+ * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
45
+ */
46
+ async getSchema(schemaKey, matchType, context) {
47
+ // Grab all schema files that match the schema key
48
+ const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
49
+ if (!candidates || candidates.length === 0)
50
+ return undefined;
51
+ // eslint-disable-next-line @typescript-eslint/unbound-method
52
+ const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
53
+ const schemaPath = maxCandidate.fileName;
54
+ // Load the file
55
+ if (!await this.fileExists(schemaPath))
56
+ return undefined;
57
+ const schemaText = await this.readUtf8FileToString(schemaPath);
58
+ if (!schemaText)
59
+ return undefined;
60
+ this.addSchemaSearchPaths([path.dirname(schemaPath)]);
61
+ const schema = await ecschema_metadata_1.Schema.fromJson(schemaText, context);
62
+ return schema;
63
+ }
64
+ /**
65
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured
66
+ * search paths to locate the JSON schema file from the file system.
67
+ * @param key The SchemaKey of the Schema to retrieve.
68
+ * @param matchType The SchemaMatchType
69
+ * @param context The SchemaContext that will control the lifetime of the schema.
70
+ */
71
+ getSchemaSync(schemaKey, matchType, context) {
72
+ // Grab all schema files that match the schema key
73
+ const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
74
+ if (!candidates || candidates.length === 0)
75
+ return undefined;
76
+ // eslint-disable-next-line @typescript-eslint/unbound-method
77
+ const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
78
+ const schemaPath = maxCandidate.fileName;
79
+ // Load the file
80
+ if (!fs.existsSync(schemaPath))
81
+ return undefined;
82
+ const schemaText = fs.readFileSync(schemaPath, "utf-8");
83
+ if (!schemaText)
84
+ return undefined;
85
+ this.addSchemaSearchPaths([path.dirname(schemaPath)]);
86
+ const schema = ecschema_metadata_1.Schema.fromJsonSync(schemaText, context);
87
+ return schema;
88
+ }
89
+ }
90
+ exports.SchemaJsonFileLocater = SchemaJsonFileLocater;
88
91
  //# sourceMappingURL=SchemaJsonFileLocater.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,gEAEkC;AAClC,2DAAuE;AAEvE;;;;GAIG;AACH,MAAa,qBAAsB,SAAQ,qCAAiB;IAE1D;;;OAGG;IACO,YAAY,CAAC,IAAY;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAElC,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAErH,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACrB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAErH,yCAAyC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC;QACjC,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC;QAEvC,MAAM,GAAG,GAAG,IAAI,6BAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,6BAAS,CAAC,UAAU,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YACxC,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,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC5B,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,0BAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAtFD,sDAsFC","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 path from \"path\";\r\nimport {\r\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\r\n\r\n/**\r\n * A SchemaLocator implementation for locating JSON Schema files\r\n * from the file system using configurable search paths.\r\n * @beta\r\n */\r\nexport class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {\r\n\r\n /**\r\n * Constructs a SchemaKey based on the information in the Schema JSON\r\n * @param data The Schema JSON as a string\r\n */\r\n protected getSchemaKey(data: string): SchemaKey {\r\n const dataJson = JSON.parse(data);\r\n\r\n // Check if the name is present\r\n if (!(dataJson.name))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);\r\n\r\n // Check if versions is present\r\n if (!(dataJson.version))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);\r\n\r\n // Get the name and version from the JSON\r\n const schemaName = dataJson.name;\r\n const schemaVersion = dataJson.version;\r\n\r\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\r\n return key;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\r\n * search paths to locate the JSON schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType.\r\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\r\n */\r\n public async getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\r\n // Grab all schema files that match the schema key\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n // eslint-disable-next-line @typescript-eslint/unbound-method\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaPath = maxCandidate.fileName;\r\n\r\n // Load the file\r\n if (!await this.fileExists(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = await this.readUtf8FileToString(schemaPath);\r\n if (!schemaText)\r\n return undefined;\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n\r\n const schema = await Schema.fromJson(schemaText, context);\r\n return schema as T;\r\n }\r\n\r\n /**\r\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\r\n * search paths to locate the JSON schema file from the file system.\r\n * @param key The SchemaKey of the Schema to retrieve.\r\n * @param matchType The SchemaMatchType\r\n * @param context The SchemaContext that will control the lifetime of the schema.\r\n */\r\n public getSchemaSync<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\r\n // Grab all schema files that match the schema key\r\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\r\n if (!candidates || candidates.length === 0)\r\n return undefined;\r\n\r\n // eslint-disable-next-line @typescript-eslint/unbound-method\r\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\r\n const schemaPath = maxCandidate.fileName;\r\n\r\n // Load the file\r\n if (!fs.existsSync(schemaPath))\r\n return undefined;\r\n\r\n const schemaText = fs.readFileSync(schemaPath, \"utf-8\");\r\n if (!schemaText)\r\n return undefined;\r\n\r\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\r\n\r\n const schema = Schema.fromJsonSync(schemaText, context);\r\n return schema as T;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,6BAA6B;AAC7B,gEAEkC;AAClC,2DAAuE;AAEvE;;GAEG;AAEH;;;;GAIG;AACH,MAAa,qBAAsB,SAAQ,qCAAiB;IAE1D;;;OAGG;IACO,YAAY,CAAC,IAAY;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAElC,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAErH,+BAA+B;QAC/B,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACrB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,yDAAyD,CAAC,CAAC;QAErH,yCAAyC;QACzC,MAAM,UAA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OAAsB;QAC7G,kDAAkD;QAClD,MAAM,UAAU,GAAoB,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9F,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YACxC,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,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC5B,OAAO,SAAS,CAAC;QAEnB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU;YACb,OAAO,SAAS,CAAC;QAEnB,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,MAAM,GAAG,0BAAM,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAtFD,sDAsFC","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 path from \"path\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\n/** @packageDocumentation\n * @module Locaters\n */\n\n/**\n * A SchemaLocator implementation for locating JSON Schema files\n * from the file system using configurable search paths.\n * @beta\n */\nexport class SchemaJsonFileLocater extends SchemaFileLocater implements ISchemaLocater {\n\n /**\n * Constructs a SchemaKey based on the information in the Schema JSON\n * @param data The Schema JSON as a string\n */\n protected getSchemaKey(data: string): SchemaKey {\n const dataJson = JSON.parse(data);\n\n // Check if the name is present\n if (!(dataJson.name))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Could not retrieve the ECSchema name in the given file.`);\n\n // Check if versions is present\n if (!(dataJson.version))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Could not parse the ECSchema version in the given file.`);\n\n // Get the name and version from the JSON\n const schemaName = dataJson.name;\n const schemaVersion = dataJson.version;\n\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\n return key;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\n * search paths to locate the JSON 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 and holds the schema's references, if they exist.\n */\n public async getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined> {\n // Grab all schema files that match the schema key\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\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 (!await this.fileExists(schemaPath))\n return undefined;\n\n const schemaText = await this.readUtf8FileToString(schemaPath);\n if (!schemaText)\n return undefined;\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n\n const schema = await Schema.fromJson(schemaText, context);\n return schema as T;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured\n * search paths to locate the JSON 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>(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined {\n // Grab all schema files that match the schema key\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"json\");\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 (!fs.existsSync(schemaPath))\n return undefined;\n\n const schemaText = fs.readFileSync(schemaPath, \"utf-8\");\n if (!schemaText)\n return undefined;\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n\n const schema = Schema.fromJsonSync(schemaText, context);\n return schema as T;\n }\n}\n"]}
@@ -1,31 +1,34 @@
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.
6
- * @beta This is a workaround the current lack of a full xml parser.
7
- */
8
- export declare class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
9
- /**
10
- * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
11
- * to locate the XML Schema file from the file system.
12
- * @param key The SchemaKey of the Schema to retrieve.
13
- * @param matchType The SchemaMatchType.
14
- * @param context The SchemaContext that will control the lifetime of the schema.
15
- */
16
- getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
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.
20
- * @param key The SchemaKey of the Schema to retrieve.
21
- * @param matchType The SchemaMatchType.
22
- * @param context The SchemaContext that will control the lifetime of the schema.
23
- */
24
- getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
25
- /**
26
- * Constructs a SchemaKey based on the information in the Schema XML.
27
- * @param data The Schema XML as a string.
28
- */
29
- getSchemaKey(data: string): SchemaKey;
30
- }
1
+ import { ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
2
+ import { SchemaFileLocater } from "./SchemaFileLocater";
3
+ /** @packageDocumentation
4
+ * @module Locaters
5
+ */
6
+ /**
7
+ * A SchemaLocater implementation for locating XML Schema files
8
+ * from the file system using configurable search paths.
9
+ * @beta This is a workaround the current lack of a full xml parser.
10
+ */
11
+ export declare class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
12
+ /**
13
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
14
+ * to locate the XML Schema file from the file system.
15
+ * @param key The SchemaKey of the Schema to retrieve.
16
+ * @param matchType The SchemaMatchType.
17
+ * @param context The SchemaContext that will control the lifetime of the schema.
18
+ */
19
+ getSchema<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<T | undefined>;
20
+ /**
21
+ * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
22
+ * to locate the XML Schema file from the file system.
23
+ * @param key The SchemaKey of the Schema to retrieve.
24
+ * @param matchType The SchemaMatchType.
25
+ * @param context The SchemaContext that will control the lifetime of the schema.
26
+ */
27
+ getSchemaSync<T extends Schema>(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): T | undefined;
28
+ /**
29
+ * Constructs a SchemaKey based on the information in the Schema XML.
30
+ * @param data The Schema XML as a string.
31
+ */
32
+ getSchemaKey(data: string): SchemaKey;
33
+ }
31
34
  //# sourceMappingURL=SchemaXmlFileLocater.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaXmlFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":"AAOA,OAAO,EACuC,cAAc,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