@itwin/ecschema-locaters 5.0.0-dev.10 → 5.0.0-dev.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -1
- package/lib/cjs/SchemaFileLocater.d.ts +10 -2
- package/lib/cjs/SchemaFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaFileLocater.js +14 -9
- package/lib/cjs/SchemaFileLocater.js.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.d.ts +2 -2
- package/lib/cjs/SchemaJsonFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaJsonFileLocater.js.map +1 -1
- package/lib/cjs/SchemaStringLocater.d.ts +2 -2
- package/lib/cjs/SchemaStringLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaStringLocater.js +12 -9
- package/lib/cjs/SchemaStringLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.d.ts +30 -2
- package/lib/cjs/SchemaXmlFileLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaXmlFileLocater.js +43 -1
- package/lib/cjs/SchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.d.ts +2 -2
- package/lib/cjs/SchemaXmlStringLocater.d.ts.map +1 -1
- package/lib/cjs/SchemaXmlStringLocater.js.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.d.ts +2 -2
- package/lib/cjs/StubSchemaXmlFileLocater.d.ts.map +1 -1
- package/lib/cjs/StubSchemaXmlFileLocater.js.map +1 -1
- package/lib/cjs/test/SchemaXmlFileLocator.test.js +3 -0
- package/lib/cjs/test/SchemaXmlFileLocator.test.js.map +1 -1
- package/lib/esm/SchemaFileLocater.d.ts +94 -0
- package/lib/esm/SchemaFileLocater.d.ts.map +1 -0
- package/lib/esm/SchemaFileLocater.js +213 -0
- package/lib/esm/SchemaFileLocater.js.map +1 -0
- package/lib/esm/SchemaJsonFileLocater.d.ts +42 -0
- package/lib/esm/SchemaJsonFileLocater.d.ts.map +1 -0
- package/lib/esm/SchemaJsonFileLocater.js +96 -0
- package/lib/esm/SchemaJsonFileLocater.js.map +1 -0
- package/lib/esm/SchemaStringLocater.d.ts +54 -0
- package/lib/esm/SchemaStringLocater.d.ts.map +1 -0
- package/lib/esm/SchemaStringLocater.js +83 -0
- package/lib/esm/SchemaStringLocater.js.map +1 -0
- package/lib/esm/SchemaXml.d.ts +22 -0
- package/lib/esm/SchemaXml.d.ts.map +1 -0
- package/lib/esm/SchemaXml.js +55 -0
- package/lib/esm/SchemaXml.js.map +1 -0
- package/lib/esm/SchemaXmlFileLocater.d.ts +70 -0
- package/lib/esm/SchemaXmlFileLocater.d.ts.map +1 -0
- package/lib/esm/SchemaXmlFileLocater.js +140 -0
- package/lib/esm/SchemaXmlFileLocater.js.map +1 -0
- package/lib/esm/SchemaXmlStringLocater.d.ts +48 -0
- package/lib/esm/SchemaXmlStringLocater.d.ts.map +1 -0
- package/lib/esm/SchemaXmlStringLocater.js +100 -0
- package/lib/esm/SchemaXmlStringLocater.js.map +1 -0
- package/lib/esm/StubSchemaXmlFileLocater.d.ts +81 -0
- package/lib/esm/StubSchemaXmlFileLocater.d.ts.map +1 -0
- package/lib/esm/StubSchemaXmlFileLocater.js +184 -0
- package/lib/esm/StubSchemaXmlFileLocater.js.map +1 -0
- package/lib/esm/ecschema-locaters.d.ts +20 -0
- package/lib/esm/ecschema-locaters.d.ts.map +1 -0
- package/lib/esm/ecschema-locaters.js +24 -0
- package/lib/esm/ecschema-locaters.js.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.d.ts +2 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.d.ts.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.js +249 -0
- package/lib/esm/test/ConcurrentGetSchemaJson.test.js.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.d.ts +2 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.d.ts.map +1 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.js +186 -0
- package/lib/esm/test/ConcurrentGetSchemaXml.test.js.map +1 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.d.ts +2 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.js +118 -0
- package/lib/esm/test/SchemaJsonFileLocator.test.js.map +1 -0
- package/lib/esm/test/SchemaXml.test.d.ts +2 -0
- package/lib/esm/test/SchemaXml.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaXml.test.js +55 -0
- package/lib/esm/test/SchemaXml.test.js.map +1 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.d.ts +2 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.js +182 -0
- package/lib/esm/test/SchemaXmlFileLocator.test.js.map +1 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.d.ts +2 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.d.ts.map +1 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.js +219 -0
- package/lib/esm/test/SchemaXmlStringLocater.test.js.map +1 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.d.ts +2 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.d.ts.map +1 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.js +169 -0
- package/lib/esm/test/StubSchemaXmlFileLocater.test.js.map +1 -0
- package/package.json +14 -12
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Locaters
|
|
3
|
+
*/
|
|
4
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
6
|
+
/**
|
|
7
|
+
* A 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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
27
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
28
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
29
|
+
* @param matchType The match type to use when locating the schema
|
|
30
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
31
|
+
*/
|
|
32
|
+
getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured
|
|
35
|
+
* search paths to locate the JSON schema file from the file system.
|
|
36
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
37
|
+
* @param matchType The SchemaMatchType
|
|
38
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
39
|
+
*/
|
|
40
|
+
getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=SchemaJsonFileLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaJsonFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,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,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAO7H;;;;;;QAMI;IACS,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAsBrI;;;;;;OAMG;IACI,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;CAsBnH"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Locaters
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import { ECObjectsError, ECObjectsStatus, ECVersion, Schema, SchemaKey, } from "@itwin/ecschema-metadata";
|
|
11
|
+
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
12
|
+
/**
|
|
13
|
+
* A SchemaLocator implementation for locating JSON Schema files
|
|
14
|
+
* from the file system using configurable search paths.
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
export class SchemaJsonFileLocater extends 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 ECObjectsError(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 ECObjectsError(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 SchemaKey(schemaName.toString(), 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
|
+
await this.getSchemaInfo(schemaKey, matchType, context);
|
|
45
|
+
const schema = await context.getCachedSchema(schemaKey, matchType);
|
|
46
|
+
return schema;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
50
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
51
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
52
|
+
* @param matchType The match type to use when locating the schema
|
|
53
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
54
|
+
*/
|
|
55
|
+
async getSchemaInfo(schemaKey, matchType, context) {
|
|
56
|
+
// Grab all schema files that match the schema key
|
|
57
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
|
|
58
|
+
if (!candidates || candidates.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
61
|
+
const schemaPath = maxCandidate.fileName;
|
|
62
|
+
// Load the file
|
|
63
|
+
if (!await this.fileExists(schemaPath))
|
|
64
|
+
return undefined;
|
|
65
|
+
const schemaText = await this.readUtf8FileToString(schemaPath);
|
|
66
|
+
if (!schemaText)
|
|
67
|
+
return undefined;
|
|
68
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
69
|
+
return Schema.startLoadingFromJson(schemaText, context);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured
|
|
73
|
+
* search paths to locate the JSON schema file from the file system.
|
|
74
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
75
|
+
* @param matchType The SchemaMatchType
|
|
76
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
77
|
+
*/
|
|
78
|
+
getSchemaSync(schemaKey, matchType, context) {
|
|
79
|
+
// Grab all schema files that match the schema key
|
|
80
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "json");
|
|
81
|
+
if (!candidates || candidates.length === 0)
|
|
82
|
+
return undefined;
|
|
83
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
84
|
+
const schemaPath = maxCandidate.fileName;
|
|
85
|
+
// Load the file
|
|
86
|
+
if (!fs.existsSync(schemaPath))
|
|
87
|
+
return undefined;
|
|
88
|
+
const schemaText = fs.readFileSync(schemaPath, "utf-8");
|
|
89
|
+
if (!schemaText)
|
|
90
|
+
return undefined;
|
|
91
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
92
|
+
const schema = Schema.fromJsonSync(schemaText, context);
|
|
93
|
+
return schema;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=SchemaJsonFileLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaJsonFileLocater.js","sourceRoot":"","sources":["../../src/SchemaJsonFileLocater.ts"],"names":[],"mappings":"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","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/** @packageDocumentation\r\n * @module Locaters\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, SchemaInfo, 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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\r\n await this.getSchemaInfo(schemaKey, matchType, context);\r\n\r\n const schema = await context.getCachedSchema(schemaKey, matchType);\r\n return schema;\r\n }\r\n\r\n /**\r\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\r\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\r\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\r\n * @param matchType The match type to use when locating the schema\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 getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | 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 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 return Schema.startLoadingFromJson(schemaText, context);\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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | 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 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;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Locaters
|
|
3
|
+
*/
|
|
4
|
+
import { Schema, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
5
|
+
/**
|
|
6
|
+
* A SchemaKey implementation that aids in identifying Schema strings via the
|
|
7
|
+
* addition of the schemaText property. The schemaText is the full XML string
|
|
8
|
+
* representation of the Schema.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export declare class StringSchemaKey extends SchemaKey {
|
|
12
|
+
schemaText: string;
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new StringSchemaKey object.
|
|
15
|
+
* @param key The EC SchemaKey identifying the Schema.
|
|
16
|
+
* @param schemaText The string representation of the Schema
|
|
17
|
+
*/
|
|
18
|
+
constructor(key: SchemaKey, schemaText: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class SchemaStringLocater {
|
|
25
|
+
schemaStrings: string[];
|
|
26
|
+
constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Adds schema strings used by this locator to find the
|
|
29
|
+
* Schemas.
|
|
30
|
+
* @param schemaPaths An array of Schema strings to add
|
|
31
|
+
*/
|
|
32
|
+
addSchemaStrings(schemaStrings: string[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a schema string used by this locator to locate and load Schemas.
|
|
35
|
+
* @param schemaText The text of the Schema
|
|
36
|
+
*/
|
|
37
|
+
addSchemaString(schemaString: string): void;
|
|
38
|
+
protected abstract getSchemaKey(data: string): SchemaKey;
|
|
39
|
+
/**
|
|
40
|
+
* Attempts to find all Schema strings that match the desired SchemaKey.
|
|
41
|
+
* @param desiredKey The SchemaKey to match.
|
|
42
|
+
* @param matchType The SchemaMatchType.
|
|
43
|
+
*/
|
|
44
|
+
protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType): StringSchemaKey[];
|
|
45
|
+
abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
|
|
48
|
+
* left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.
|
|
49
|
+
* @param lhs The 'left-hand' StringSchemaKey.
|
|
50
|
+
* @param rhs The 'right-hand' StringSchemaKey.
|
|
51
|
+
*/
|
|
52
|
+
compareSchemaKeyByVersion: (lhs: StringSchemaKey, rhs: StringSchemaKey) => number;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=SchemaStringLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAErC,UAAU,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;gBACS,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM;CAI/C;AAED;;;GAGG;AACH,8BAAsB,mBAAmB;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;;IAM/B;;;;OAIG;IACI,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE;IAM/C;;;OAGG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM;IAO3C,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAExD;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,GAAG,eAAe,EAAE;aAetF,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAE1H;;;;;OAKG;IACI,yBAAyB,QAAS,eAAe,OAAO,eAAe,KAAG,MAAM,CAErF;CACH"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Locaters
|
|
7
|
+
*/
|
|
8
|
+
import { SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
9
|
+
/**
|
|
10
|
+
* A SchemaKey implementation that aids in identifying Schema strings via the
|
|
11
|
+
* addition of the schemaText property. The schemaText is the full XML string
|
|
12
|
+
* representation of the Schema.
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export class StringSchemaKey extends SchemaKey {
|
|
16
|
+
// The text for the schema loaded
|
|
17
|
+
schemaText;
|
|
18
|
+
/**
|
|
19
|
+
* Initializes a new StringSchemaKey object.
|
|
20
|
+
* @param key The EC SchemaKey identifying the Schema.
|
|
21
|
+
* @param schemaText The string representation of the Schema
|
|
22
|
+
*/
|
|
23
|
+
constructor(key, schemaText) {
|
|
24
|
+
super(key.name, key.version);
|
|
25
|
+
this.schemaText = schemaText;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export class SchemaStringLocater {
|
|
33
|
+
schemaStrings;
|
|
34
|
+
constructor() {
|
|
35
|
+
this.schemaStrings = [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Adds schema strings used by this locator to find the
|
|
39
|
+
* Schemas.
|
|
40
|
+
* @param schemaPaths An array of Schema strings to add
|
|
41
|
+
*/
|
|
42
|
+
addSchemaStrings(schemaStrings) {
|
|
43
|
+
// If the path is not in the schemaPaths array, add it
|
|
44
|
+
for (const schemaString of schemaStrings)
|
|
45
|
+
this.addSchemaString(schemaString);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Adds a schema string used by this locator to locate and load Schemas.
|
|
49
|
+
* @param schemaText The text of the Schema
|
|
50
|
+
*/
|
|
51
|
+
addSchemaString(schemaString) {
|
|
52
|
+
const schemaKey = this.getSchemaKey(schemaString);
|
|
53
|
+
// If the string is not in the schemaStrings array, add it
|
|
54
|
+
if (!this.schemaStrings.find((entry) => this.getSchemaKey(entry).matches(schemaKey, SchemaMatchType.Exact)))
|
|
55
|
+
this.schemaStrings.push(schemaString);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Attempts to find all Schema strings that match the desired SchemaKey.
|
|
59
|
+
* @param desiredKey The SchemaKey to match.
|
|
60
|
+
* @param matchType The SchemaMatchType.
|
|
61
|
+
*/
|
|
62
|
+
findEligibleSchemaKeys(desiredKey, matchType) {
|
|
63
|
+
const foundStrings = new Array();
|
|
64
|
+
for (const schemaString of this.schemaStrings) {
|
|
65
|
+
// Get the schema key
|
|
66
|
+
const key = this.getSchemaKey(schemaString);
|
|
67
|
+
// If the key matches, put it in foundFiles
|
|
68
|
+
if (key.matches(desiredKey, matchType))
|
|
69
|
+
foundStrings.push(new StringSchemaKey(key, schemaString));
|
|
70
|
+
}
|
|
71
|
+
return foundStrings;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Compares two Schema versions. If the left-hand version is greater, 1 is returned. If the
|
|
75
|
+
* left-hand version is less, -1 us returned. If the versions are an exact match, 0 is returned.
|
|
76
|
+
* @param lhs The 'left-hand' StringSchemaKey.
|
|
77
|
+
* @param rhs The 'right-hand' StringSchemaKey.
|
|
78
|
+
*/
|
|
79
|
+
compareSchemaKeyByVersion = (lhs, rhs) => {
|
|
80
|
+
return lhs.compareByVersion(rhs);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=SchemaStringLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaStringLocater.js","sourceRoot":"","sources":["../../src/SchemaStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAyB,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,iCAAiC;IAC1B,UAAU,CAAS;IAE1B;;;;OAIG;IACH,YAAY,GAAc,EAAE,UAAkB;QAC5C,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,mBAAmB;IAChC,aAAa,CAAW;IAE/B;QACE,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,aAAuB;QAC7C,sDAAsD;QACtD,KAAK,MAAM,YAAY,IAAI,aAAa;YACtC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,YAAoB;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAClD,0DAA0D;QAC1D,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;YACzG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IAID;;;;OAIG;IACO,sBAAsB,CAAC,UAAqB,EAAE,SAA0B;QAChF,MAAM,YAAY,GAAG,IAAI,KAAK,EAAmB,CAAC;QAElD,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC9C,qBAAqB;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YAE5C,2CAA2C;YAC3C,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC;gBACpC,YAAY,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAID;;;;;OAKG;IACI,yBAAyB,GAAG,CAAC,GAAoB,EAAE,GAAoB,EAAU,EAAE;QACxF,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC,CAAC;CACH","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/** @packageDocumentation\r\n * @module Locaters\r\n */\r\n\r\nimport { Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * A SchemaKey implementation that aids in identifying Schema strings via the\r\n * addition of the schemaText property. The schemaText is the full XML string\r\n * representation of the Schema.\r\n * @beta\r\n */\r\nexport class StringSchemaKey extends SchemaKey {\r\n // The text for the schema loaded\r\n public schemaText: string;\r\n\r\n /**\r\n * Initializes a new StringSchemaKey object.\r\n * @param key The EC SchemaKey identifying the Schema.\r\n * @param schemaText The string representation of the Schema\r\n */\r\n constructor(key: SchemaKey, schemaText: string) {\r\n super(key.name, key.version);\r\n this.schemaText = schemaText;\r\n }\r\n}\r\n\r\n/**\r\n * Abstract class to hold common/overlapping functionality between SchemaJsonStringLocater and SchemaXmlStringLocater\r\n * @beta\r\n */\r\nexport abstract class SchemaStringLocater {\r\n public schemaStrings: string[];\r\n\r\n constructor() {\r\n this.schemaStrings = [];\r\n }\r\n\r\n /**\r\n * Adds schema strings used by this locator to find the\r\n * Schemas.\r\n * @param schemaPaths An array of Schema strings to add\r\n */\r\n public addSchemaStrings(schemaStrings: string[]) {\r\n // If the path is not in the schemaPaths array, add it\r\n for (const schemaString of schemaStrings)\r\n this.addSchemaString(schemaString);\r\n }\r\n\r\n /**\r\n * Adds a schema string used by this locator to locate and load Schemas.\r\n * @param schemaText The text of the Schema\r\n */\r\n public addSchemaString(schemaString: string) {\r\n const schemaKey = this.getSchemaKey(schemaString);\r\n // If the string is not in the schemaStrings array, add it\r\n if (!this.schemaStrings.find((entry) => this.getSchemaKey(entry).matches(schemaKey, SchemaMatchType.Exact)))\r\n this.schemaStrings.push(schemaString);\r\n }\r\n\r\n protected abstract getSchemaKey(data: string): SchemaKey;\r\n\r\n /**\r\n * Attempts to find all Schema strings that match the desired SchemaKey.\r\n * @param desiredKey The SchemaKey to match.\r\n * @param matchType The SchemaMatchType.\r\n */\r\n protected findEligibleSchemaKeys(desiredKey: SchemaKey, matchType: SchemaMatchType): StringSchemaKey[] {\r\n const foundStrings = new Array<StringSchemaKey>();\r\n\r\n for (const schemaString of this.schemaStrings) {\r\n // Get the schema key\r\n const key = this.getSchemaKey(schemaString);\r\n\r\n // If the key matches, put it in foundFiles\r\n if (key.matches(desiredKey, matchType))\r\n foundStrings.push(new StringSchemaKey(key, schemaString));\r\n }\r\n\r\n return foundStrings;\r\n }\r\n\r\n public abstract getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | 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' StringSchemaKey.\r\n * @param rhs The 'right-hand' StringSchemaKey.\r\n */\r\n public compareSchemaKeyByVersion = (lhs: StringSchemaKey, rhs: StringSchemaKey): number => {\r\n return lhs.compareByVersion(rhs);\r\n };\r\n}\r\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
import { Schema } from "@itwin/ecschema-metadata";
|
|
5
|
+
/**
|
|
6
|
+
* Utility class to assist in creating serialized EC Schemas on the file system.
|
|
7
|
+
* @beta
|
|
8
|
+
*/
|
|
9
|
+
export declare namespace SchemaXml {
|
|
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
|
+
function writeFile(schema: Schema, outputPath: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Writes a Schema to an xml string.
|
|
18
|
+
* @param schema The Schema to serialize.
|
|
19
|
+
*/
|
|
20
|
+
function writeString(schema: Schema): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=SchemaXml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXml.d.ts","sourceRoot":"","sources":["../../src/SchemaXml.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD;;;GAGG;AACH,yBAAiB,SAAS,CAAC;IAEzB;;;;OAIG;IACH,SAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,iBAUjE;IAED;;;OAGG;IACH,SAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMjE;CAYF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Utils
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from "fs-extra";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import { DOMParser, XMLSerializer } from "@xmldom/xmldom";
|
|
11
|
+
/**
|
|
12
|
+
* Utility class to assist in creating serialized EC Schemas on the file system.
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export var SchemaXml;
|
|
16
|
+
(function (SchemaXml) {
|
|
17
|
+
/**
|
|
18
|
+
* Writes a Schema to an xml file to the specified output path.
|
|
19
|
+
* @param schema The Schema to serialize.
|
|
20
|
+
* @param outputPath The directory in which to create the file.
|
|
21
|
+
*/
|
|
22
|
+
async function writeFile(schema, outputPath) {
|
|
23
|
+
const xml = await writeString(schema);
|
|
24
|
+
const baseFile = getSchemaPath(schema, outputPath);
|
|
25
|
+
try {
|
|
26
|
+
await fs.writeFile(baseFile, xml);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;
|
|
30
|
+
throw new Error(msg);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
SchemaXml.writeFile = writeFile;
|
|
34
|
+
/**
|
|
35
|
+
* Writes a Schema to an xml string.
|
|
36
|
+
* @param schema The Schema to serialize.
|
|
37
|
+
*/
|
|
38
|
+
async function writeString(schema) {
|
|
39
|
+
let xmlDoc = new DOMParser().parseFromString(`<?xml version="1.0" encoding="UTF-8"?>`, "application/xml");
|
|
40
|
+
xmlDoc = await schema.toXml(xmlDoc);
|
|
41
|
+
const serializer = new XMLSerializer();
|
|
42
|
+
return serializer.serializeToString(xmlDoc);
|
|
43
|
+
}
|
|
44
|
+
SchemaXml.writeString = writeString;
|
|
45
|
+
function getSchemaPath(schema, outputPath) {
|
|
46
|
+
const realDir = path.normalize(outputPath);
|
|
47
|
+
const test = fs.pathExistsSync(realDir);
|
|
48
|
+
if (!test) {
|
|
49
|
+
const msg = `The output directory '${realDir}' does not exist.`;
|
|
50
|
+
throw new Error(msg);
|
|
51
|
+
}
|
|
52
|
+
return path.resolve(realDir, `${schema.name}.ecschema.xml`);
|
|
53
|
+
}
|
|
54
|
+
})(SchemaXml || (SchemaXml = {}));
|
|
55
|
+
//# sourceMappingURL=SchemaXml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXml.js","sourceRoot":"","sources":["../../src/SchemaXml.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;GAGG;AACH,MAAM,KAAW,SAAS,CAyCzB;AAzCD,WAAiB,SAAS;IAExB;;;;OAIG;IACI,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,UAAkB;QAChE,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,sCAAsC,QAAQ,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAVqB,mBAAS,YAU9B,CAAA;IAED;;;OAGG;IACI,KAAK,UAAU,WAAW,CAAC,MAAc;QAC9C,IAAI,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC,eAAe,CAAC,wCAAwC,EAAE,iBAAiB,CAAC,CAAC;QAE1G,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;QACvC,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IANqB,qBAAW,cAMhC,CAAA;IAED,SAAS,aAAa,CAAC,MAAc,EAAE,UAAkB;QACvD,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,CAAC;YACV,MAAM,GAAG,GAAG,yBAAyB,OAAO,mBAAmB,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC,EAzCgB,SAAS,KAAT,SAAS,QAyCzB","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/** @packageDocumentation\r\n * @module Utils\r\n */\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 namespace SchemaXml {\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 export async function writeFile(schema: Schema, outputPath: string) {\r\n const xml = await writeString(schema);\r\n\r\n const baseFile = getSchemaPath(schema, outputPath);\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 /**\r\n * Writes a Schema to an xml string.\r\n * @param schema The Schema to serialize.\r\n */\r\n export async function writeString(schema: Schema): Promise<string> {\r\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\r\n\r\n xmlDoc = await schema.toXml(xmlDoc);\r\n const serializer = new XMLSerializer();\r\n return serializer.serializeToString(xmlDoc);\r\n }\r\n\r\n function 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`);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Locaters
|
|
3
|
+
*/
|
|
4
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
6
|
+
/**
|
|
7
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
8
|
+
* from the file system using configurable search paths.
|
|
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(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
22
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
23
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
24
|
+
* @param matchType The match type to use when locating the schema
|
|
25
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
26
|
+
*/
|
|
27
|
+
getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
30
|
+
* to locate the XML Schema file from the file system.
|
|
31
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
32
|
+
* @param matchType The SchemaMatchType.
|
|
33
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
34
|
+
*/
|
|
35
|
+
getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
38
|
+
* @param data The Schema XML as a string.
|
|
39
|
+
*/
|
|
40
|
+
getSchemaKey(data: string): SchemaKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* This locater is responsible for locating standard schema files that are released by the core-backend package.
|
|
44
|
+
* The locater needs an argument to the known backend assets directory where the core-backend package is installed.
|
|
45
|
+
* This can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.
|
|
46
|
+
*
|
|
47
|
+
* @note This locater is read-only and does not allow adding new schema search paths.
|
|
48
|
+
* @note This locater should be used as a fallback/last chance locater in the schema context as any user defined schema should have higher precedence over the standard schema.
|
|
49
|
+
* @beta This is a workaround due to the current lack of a full xml parser.
|
|
50
|
+
*/
|
|
51
|
+
export declare class PublishedSchemaXmlFileLocater extends SchemaXmlFileLocater implements ISchemaLocater {
|
|
52
|
+
/**
|
|
53
|
+
* Constructs a new PublishedSchemaXmlFileLocater
|
|
54
|
+
* @param knownBackendAssetsDir The assets directory where the core-backend package is installed. Can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.
|
|
55
|
+
*/
|
|
56
|
+
constructor(knownBackendAssetsDir: string);
|
|
57
|
+
/**
|
|
58
|
+
* Overrides the addSchemaSearchPath method to prevent adding new schema search paths.
|
|
59
|
+
*
|
|
60
|
+
* @param _schemaPath - The schema path to add (ignored).
|
|
61
|
+
*/
|
|
62
|
+
addSchemaSearchPath(_schemaPath: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Overrides the addSchemaSearchPaths method to prevent adding new schema search paths.
|
|
65
|
+
*
|
|
66
|
+
* @param _schemaPaths - The schema paths to add (ignored).
|
|
67
|
+
*/
|
|
68
|
+
addSchemaSearchPaths(_schemaPaths: string[]): void;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=SchemaXmlFileLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlFileLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGvE;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,iBAAkB,YAAW,cAAc;IACnF;;;;;;OAMG;IACU,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAOvH;;;;;;QAMI;IACS,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IA2BrI;;;;;;OAMG;IACI,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;IA4B5G;;;OAGG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;CAa7C;AAED;;;;;;;;GAQG;AACH,qBAAa,6BAA8B,SAAQ,oBAAqB,YAAW,cAAc;IAC/F;;;OAGG;gBACgB,qBAAqB,EAAE,MAAM;IAWhD;;;;OAIG;IACa,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAI9D;;;;OAIG;IACa,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI;CAGnE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Locaters
|
|
7
|
+
*/
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
11
|
+
import { ECObjectsError, ECObjectsStatus, ECVersion, Schema, SchemaKey, SchemaReadHelper, XmlParser, } from "@itwin/ecschema-metadata";
|
|
12
|
+
import { SchemaFileLocater } from "./SchemaFileLocater";
|
|
13
|
+
import { globSync } from "glob";
|
|
14
|
+
/**
|
|
15
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
16
|
+
* from the file system using configurable search paths.
|
|
17
|
+
* @beta This is a workaround the current lack of a full xml parser.
|
|
18
|
+
*/
|
|
19
|
+
export class SchemaXmlFileLocater extends SchemaFileLocater {
|
|
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
|
+
async getSchema(key, matchType, context) {
|
|
28
|
+
await this.getSchemaInfo(key, matchType, context);
|
|
29
|
+
const schema = await context.getCachedSchema(key, matchType);
|
|
30
|
+
return schema;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
34
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
35
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
36
|
+
* @param matchType The match type to use when locating the schema
|
|
37
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
38
|
+
*/
|
|
39
|
+
async getSchemaInfo(schemaKey, matchType, context) {
|
|
40
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType, "xml");
|
|
41
|
+
if (0 === candidates.length)
|
|
42
|
+
return undefined;
|
|
43
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
44
|
+
const schemaPath = maxCandidate.fileName;
|
|
45
|
+
// Load the file
|
|
46
|
+
if (undefined === await this.fileExists(schemaPath))
|
|
47
|
+
return undefined;
|
|
48
|
+
const schemaText = await this.readUtf8FileToString(schemaPath);
|
|
49
|
+
if (undefined === schemaText)
|
|
50
|
+
return undefined;
|
|
51
|
+
const parser = new DOMParser();
|
|
52
|
+
const document = parser.parseFromString(schemaText);
|
|
53
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
54
|
+
const reader = new SchemaReadHelper(XmlParser, context);
|
|
55
|
+
const schema = new Schema(context);
|
|
56
|
+
return reader.readSchemaInfo(schema, document);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
60
|
+
* to locate the XML Schema file from the file system.
|
|
61
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
62
|
+
* @param matchType The SchemaMatchType.
|
|
63
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
64
|
+
*/
|
|
65
|
+
getSchemaSync(key, matchType, context) {
|
|
66
|
+
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
67
|
+
if (!candidates || candidates.length === 0)
|
|
68
|
+
return undefined;
|
|
69
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
70
|
+
const schemaPath = maxCandidate.fileName;
|
|
71
|
+
// Load the file
|
|
72
|
+
if (!this.fileExistsSync(schemaPath))
|
|
73
|
+
return undefined;
|
|
74
|
+
const schemaText = this.readUtf8FileToStringSync(schemaPath);
|
|
75
|
+
if (!schemaText)
|
|
76
|
+
return undefined;
|
|
77
|
+
const parser = new DOMParser();
|
|
78
|
+
const document = parser.parseFromString(schemaText);
|
|
79
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
80
|
+
const reader = new SchemaReadHelper(XmlParser, context);
|
|
81
|
+
let schema = new Schema(context);
|
|
82
|
+
schema = reader.readSchemaSync(schema, document);
|
|
83
|
+
return schema;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
87
|
+
* @param data The Schema XML as a string.
|
|
88
|
+
*/
|
|
89
|
+
getSchemaKey(data) {
|
|
90
|
+
const matches = data.match(/<ECSchema ([^]+?)>/g);
|
|
91
|
+
if (!matches || matches.length !== 1)
|
|
92
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
|
|
93
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
94
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
95
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
96
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
|
|
97
|
+
const key = new SchemaKey(name[1], ECVersion.fromString(version[1]));
|
|
98
|
+
return key;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* This locater is responsible for locating standard schema files that are released by the core-backend package.
|
|
103
|
+
* The locater needs an argument to the known backend assets directory where the core-backend package is installed.
|
|
104
|
+
* This can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.
|
|
105
|
+
*
|
|
106
|
+
* @note This locater is read-only and does not allow adding new schema search paths.
|
|
107
|
+
* @note This locater should be used as a fallback/last chance locater in the schema context as any user defined schema should have higher precedence over the standard schema.
|
|
108
|
+
* @beta This is a workaround due to the current lack of a full xml parser.
|
|
109
|
+
*/
|
|
110
|
+
export class PublishedSchemaXmlFileLocater extends SchemaXmlFileLocater {
|
|
111
|
+
/**
|
|
112
|
+
* Constructs a new PublishedSchemaXmlFileLocater
|
|
113
|
+
* @param knownBackendAssetsDir The assets directory where the core-backend package is installed. Can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.
|
|
114
|
+
*/
|
|
115
|
+
constructor(knownBackendAssetsDir) {
|
|
116
|
+
super();
|
|
117
|
+
const ecSchemaDir = path.join(knownBackendAssetsDir, "ECSchemas");
|
|
118
|
+
if (!fs.existsSync(ecSchemaDir))
|
|
119
|
+
throw new Error(`The directory ${ecSchemaDir} containing standard schemas does not exist.`);
|
|
120
|
+
// Pre-defined set of standard schema search paths
|
|
121
|
+
this.searchPaths.push(...globSync(path.join(ecSchemaDir, "*/"), { windowsPathsNoEscape: true }).filter(fs.existsSync));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Overrides the addSchemaSearchPath method to prevent adding new schema search paths.
|
|
125
|
+
*
|
|
126
|
+
* @param _schemaPath - The schema path to add (ignored).
|
|
127
|
+
*/
|
|
128
|
+
addSchemaSearchPath(_schemaPath) {
|
|
129
|
+
return; // Do nothing, this is a read-only locator
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Overrides the addSchemaSearchPaths method to prevent adding new schema search paths.
|
|
133
|
+
*
|
|
134
|
+
* @param _schemaPaths - The schema paths to add (ignored).
|
|
135
|
+
*/
|
|
136
|
+
addSchemaSearchPaths(_schemaPaths) {
|
|
137
|
+
return; // Do nothing, this is a read-only locator
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=SchemaXmlFileLocater.js.map
|