@itwin/ecschema-locaters 5.0.0-dev.9 → 5.0.0-dev.92
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 +51 -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/SchemaXml.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/ecschema-locaters.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaJson.test.js.map +1 -1
- package/lib/cjs/test/ConcurrentGetSchemaXml.test.js.map +1 -1
- package/lib/cjs/test/SchemaJsonFileLocator.test.js.map +1 -1
- package/lib/cjs/test/SchemaXml.test.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/cjs/test/SchemaXmlStringLocater.test.js.map +1 -1
- package/lib/cjs/test/StubSchemaXmlFileLocater.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,184 @@
|
|
|
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 { ECObjectsError, ECObjectsStatus, ECVersion, Schema, SchemaContext, SchemaKey, SchemaMatchType, } from "@itwin/ecschema-metadata";
|
|
10
|
+
import { FileSchemaKey, SchemaFileLocater } from "./SchemaFileLocater";
|
|
11
|
+
function isECv2Schema(schemaText) {
|
|
12
|
+
return /<ECSchema[^>]*xmlns=".*ECXML.2.0"/.test(schemaText);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A SchemaLocater implementation for locating XML Schema files
|
|
16
|
+
* from the file system using configurable search paths. Returns only
|
|
17
|
+
* Schemas from XML files with their keys populated.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export class StubSchemaXmlFileLocater extends SchemaFileLocater {
|
|
21
|
+
/**
|
|
22
|
+
* Loads a Schema from an XML file on the file system.
|
|
23
|
+
* @param schemaPath The path to the Schema file.
|
|
24
|
+
* @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
|
|
25
|
+
* the schema will be read from the provided schemaPath.
|
|
26
|
+
*/
|
|
27
|
+
loadSchema(schemaPath, schemaText) {
|
|
28
|
+
schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);
|
|
29
|
+
if (!schemaText)
|
|
30
|
+
throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);
|
|
31
|
+
this.addSchemaSearchPaths([path.dirname(schemaPath)]);
|
|
32
|
+
const key = this.getSchemaKey(schemaText);
|
|
33
|
+
const alias = this.getSchemaAlias(schemaText);
|
|
34
|
+
const context = new SchemaContext();
|
|
35
|
+
context.addLocater(this);
|
|
36
|
+
// Load the schema and return it
|
|
37
|
+
const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);
|
|
38
|
+
this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);
|
|
39
|
+
return schema;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
43
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
44
|
+
* their keys populated.
|
|
45
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
46
|
+
* @param matchType The SchemaMatchType.
|
|
47
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
48
|
+
*/
|
|
49
|
+
async getSchema(key, matchType, context) {
|
|
50
|
+
return this.getSchemaSync(key, matchType, context);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
54
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
55
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
56
|
+
* @param matchType The match type to use when locating the schema
|
|
57
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
58
|
+
*/
|
|
59
|
+
async getSchemaInfo(key, matchType, context) {
|
|
60
|
+
return this.getSchemaSync(key, matchType, context);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
64
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
65
|
+
* their keys populated.
|
|
66
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
67
|
+
* @param matchType The SchemaMatchType.
|
|
68
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
69
|
+
*/
|
|
70
|
+
getSchemaSync(key, matchType, context) {
|
|
71
|
+
const candidates = this.findEligibleSchemaKeys(key, matchType, "xml");
|
|
72
|
+
if (!candidates || candidates.length === 0)
|
|
73
|
+
return undefined;
|
|
74
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
75
|
+
const alias = this.getSchemaAlias(maxCandidate.schemaText);
|
|
76
|
+
const schema = new Schema(context, maxCandidate, alias);
|
|
77
|
+
context.addSchemaSync(schema);
|
|
78
|
+
this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);
|
|
79
|
+
return schema;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
83
|
+
* @param schemaXml The Schema XML as a string.
|
|
84
|
+
*/
|
|
85
|
+
getSchemaKey(schemaXml) {
|
|
86
|
+
const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
|
|
87
|
+
if (!matches || matches.length !== 1)
|
|
88
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);
|
|
89
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
90
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
91
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
92
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);
|
|
93
|
+
let ecVersion;
|
|
94
|
+
if (isECv2Schema(schemaXml))
|
|
95
|
+
ecVersion = this.fromECv2String(version[1]);
|
|
96
|
+
else
|
|
97
|
+
ecVersion = ECVersion.fromString(version[1]);
|
|
98
|
+
const key = new SchemaKey(name[1], ecVersion);
|
|
99
|
+
return key;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
103
|
+
* @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
|
|
104
|
+
*/
|
|
105
|
+
getSchemaReferenceKeys(schemaKey) {
|
|
106
|
+
return this._getSchemaReferenceKeys(schemaKey);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Adds schemas to the references collection for the given Schema by locating
|
|
110
|
+
* the referenced schemas.
|
|
111
|
+
* @param schema The schema for which to add the references.
|
|
112
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
113
|
+
* @param refMatchType The SchemaMatchType to use when locating schema references.
|
|
114
|
+
*/
|
|
115
|
+
addSchemaReferences(schema, context, refMatchType) {
|
|
116
|
+
const refKeys = this.getSchemaReferenceKeys(schema.schemaKey);
|
|
117
|
+
for (const key of refKeys) {
|
|
118
|
+
const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;
|
|
119
|
+
if (!refSchema)
|
|
120
|
+
throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);
|
|
121
|
+
schema.references.push(refSchema);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
126
|
+
* @param data The Schema XML string.
|
|
127
|
+
*/
|
|
128
|
+
_getSchemaReferenceKeys(xmlSchemaKey) {
|
|
129
|
+
const file = xmlSchemaKey.schemaText;
|
|
130
|
+
if (!file)
|
|
131
|
+
throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);
|
|
132
|
+
const data = file.toString().replace(/(\s*)<!--[\s\S]*?--!?>/g, ""); // ignore any comments in the XML file when getting the array of SchemaKeys
|
|
133
|
+
const keys = [];
|
|
134
|
+
const matches = data.match(/<ECSchemaReference ([^]+?)\/>/g);
|
|
135
|
+
if (!matches)
|
|
136
|
+
return keys;
|
|
137
|
+
for (const match of matches) {
|
|
138
|
+
const name = match.match(/name="(.+?)"/);
|
|
139
|
+
const versionMatch = match.match(/version="(.+?)"/);
|
|
140
|
+
if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)
|
|
141
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);
|
|
142
|
+
// write version maybe missing, so insert "0"
|
|
143
|
+
let versionString = versionMatch[1];
|
|
144
|
+
const versionParts = versionString.split(".");
|
|
145
|
+
if (versionParts.length === 2)
|
|
146
|
+
versionParts.splice(1, 0, "0");
|
|
147
|
+
versionString = versionParts.join(".");
|
|
148
|
+
const key = new SchemaKey(name[1], ECVersion.fromString(versionString));
|
|
149
|
+
keys.push(key);
|
|
150
|
+
}
|
|
151
|
+
return keys;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the Schema alias from the Schema XML.
|
|
155
|
+
* @param data The Schema XML as a string.
|
|
156
|
+
*/
|
|
157
|
+
getSchemaAlias(schemaXml) {
|
|
158
|
+
let match;
|
|
159
|
+
if (isECv2Schema(schemaXml)) {
|
|
160
|
+
match = schemaXml.match(/<ECSchema.*nameSpacePrefix="(?<alias>\w+)"/);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
match = schemaXml.match(/<ECSchema.*alias="(?<alias>\w+)"/);
|
|
164
|
+
}
|
|
165
|
+
if (!match || !match.groups.alias) {
|
|
166
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);
|
|
167
|
+
}
|
|
168
|
+
return match.groups.alias;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
172
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
173
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
174
|
+
*/
|
|
175
|
+
fromECv2String(versionString) {
|
|
176
|
+
const [read, minor] = versionString.split(".");
|
|
177
|
+
if (!read)
|
|
178
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
|
|
179
|
+
if (!minor)
|
|
180
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
|
|
181
|
+
return new ECVersion(+read, 0, +minor);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=StubSchemaXmlFileLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StubSchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/StubSchemaXmlFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,cAAc,EAAE,eAAe,EAAE,SAAS,EAAkB,MAAM,EAAE,aAAa,EAAc,SAAS,EAAE,eAAe,GAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,SAAS,YAAY,CAAC,UAAkB;IACtC,OAAO,mCAAmC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,wBAAyB,SAAQ,iBAAiB;IAC7D;;;;;OAKG;IACI,UAAU,CAAC,UAAkB,EAAE,UAAmB;QACvD,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,CAAC,UAAU;YACb,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,oBAAoB,EAAE,uCAAuC,UAAU,EAAE,CAAC,CAAC;QAEtH,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACtD,MAAM,GAAG,GAAG,IAAI,CAAC,YA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,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAClC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,gBAAgB,EAAE,4DAA4D,CAAC,CAAC;QAC3H,CAAC;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACK,cAAc,CAAC,aAAqB;QAC1C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,gBAAgB,EAAE,oDAAoD,aAAa,EAAE,CAAC,CAAC;QAElI,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,gBAAgB,EAAE,qDAAqD,aAAa,EAAE,CAAC,CAAC;QAEnI,OAAO,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF","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/** @packageDocumentation\n * @module Locaters\n */\n\nimport * as path from \"path\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\n\nfunction isECv2Schema(schemaText: string): boolean {\n return /<ECSchema[^>]*xmlns=\".*ECXML.2.0\"/.test(schemaText);\n}\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths. Returns only\n * Schemas from XML files with their keys populated.\n * @internal\n */\nexport class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\n /**\n * Loads a Schema from an XML file on the file system.\n * @param schemaPath The path to the Schema file.\n * @param schemaText Optionally pass in the schema text read from the schema file. If undefined,\n * the schema will be read from the provided schemaPath.\n */\n public loadSchema(schemaPath: string, schemaText?: string): Schema {\n schemaText = schemaText || this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate schema XML file at ${schemaPath}`);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const key = this.getSchemaKey(schemaText);\n const alias = this.getSchemaAlias(schemaText);\n const context = new SchemaContext();\n context.addLocater(this);\n\n // Load the schema and return it\n const schema = new Schema(context, new FileSchemaKey(key, schemaPath, schemaText), alias);\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\n return schema;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema.\n */\n public async getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n return this.getSchemaSync(key, matchType, context);\n }\n\n /**\n * Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.\n * The fully loaded schema can be gotten later from the context using the getCachedSchema method.\n * @param schemaKey The SchemaKey describing the schema to get from the cache.\n * @param matchType The match type to use when locating the schema\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 getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n return this.getSchemaSync(key, matchType, context) as SchemaInfo;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths\n * to locate the XML Schema file from the file system. Returns only Schemas from XML files with\n * their keys populated.\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(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(key, matchType, \"xml\");\n\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const alias = this.getSchemaAlias(maxCandidate.schemaText!);\n const schema = new Schema(context, maxCandidate, alias);\n context.addSchemaSync(schema);\n\n this.addSchemaReferences(schema, context, SchemaMatchType.LatestWriteCompatible);\n return schema;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param schemaXml The Schema XML as a string.\n */\n public getSchemaKey(schemaXml: string): SchemaKey {\n const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);\n if (!matches || matches.length !== 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given file`);\n\n const name = matches[0].match(/schemaName=\"(.+?)\"/);\n const version = matches[0].match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !version || version.length !== 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given file`);\n\n let ecVersion: ECVersion;\n if (isECv2Schema(schemaXml))\n ecVersion = this.fromECv2String(version[1]);\n else\n ecVersion = ECVersion.fromString(version[1]);\n\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\n * @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.\n */\n private getSchemaReferenceKeys(schemaKey: FileSchemaKey): SchemaKey[] {\n return this._getSchemaReferenceKeys(schemaKey);\n }\n\n /**\n * Adds schemas to the references collection for the given Schema by locating\n * the referenced schemas.\n * @param schema The schema for which to add the references.\n * @param context The SchemaContext that will control the lifetime of the schema.\n * @param refMatchType The SchemaMatchType to use when locating schema references.\n */\n private addSchemaReferences(schema: Schema, context: SchemaContext, refMatchType: SchemaMatchType): void {\n const refKeys = this.getSchemaReferenceKeys(schema.schemaKey as FileSchemaKey);\n\n for (const key of refKeys) {\n const refSchema = context ? context.getSchemaSync(key, refMatchType) : undefined;\n if (!refSchema)\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Unable to locate referenced schema: ${key.name}.${key.readVersion}.${key.writeVersion}.${key.minorVersion}`);\n\n schema.references.push(refSchema);\n }\n }\n\n /**\n * Gets an array of SchemaKeys of the Schemas referenced by the given Schema.\n * @param data The Schema XML string.\n */\n private _getSchemaReferenceKeys(xmlSchemaKey: FileSchemaKey): SchemaKey[] {\n const file = xmlSchemaKey.schemaText;\n\n if (!file)\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema, `Could not locate the schema file, ${xmlSchemaKey.fileName}, for the schema ${xmlSchemaKey.name}`);\n\n const data = file.toString().replace(/(\\s*)<!--[\\s\\S]*?--!?>/g, \"\"); // ignore any comments in the XML file when getting the array of SchemaKeys\n\n const keys: SchemaKey[] = [];\n const matches = data.match(/<ECSchemaReference ([^]+?)\\/>/g);\n if (!matches)\n return keys;\n\n for (const match of matches) {\n const name = match.match(/name=\"(.+?)\"/);\n const versionMatch = match.match(/version=\"(.+?)\"/);\n if (!name || name.length !== 2 || !versionMatch || versionMatch.length !== 2)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Invalid ECSchemaReference xml encountered in the schema file`);\n\n // write version maybe missing, so insert \"0\"\n let versionString = versionMatch[1];\n const versionParts = versionString.split(\".\");\n if (versionParts.length === 2)\n versionParts.splice(1, 0, \"0\");\n\n versionString = versionParts.join(\".\");\n\n const key = new SchemaKey(name[1], ECVersion.fromString(versionString));\n keys.push(key);\n }\n\n return keys;\n }\n\n /**\n * Gets the Schema alias from the Schema XML.\n * @param data The Schema XML as a string.\n */\n private getSchemaAlias(schemaXml: string): string {\n let match: any;\n\n if (isECv2Schema(schemaXml)) {\n match = schemaXml.match(/<ECSchema.*nameSpacePrefix=\"(?<alias>\\w+)\"/) as any;\n } else {\n match = schemaXml.match(/<ECSchema.*alias=\"(?<alias>\\w+)\"/) as any;\n }\n\n if (!match || !match.groups.alias) {\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'alias' tag in the given file.`);\n }\n\n return match.groups.alias;\n }\n\n /**\n * Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,\n * and a zero is inserted as the 'write' digit. Example: \"1.1\" -> \"1.0.1\".\n * @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.\n */\n private fromECv2String(versionString: string): ECVersion {\n const [read, minor] = versionString.split(\".\");\n\n if (!read)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);\n\n if (!minor)\n throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);\n\n return new ECVersion(+read, 0, +minor);\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from "./SchemaFileLocater";
|
|
2
|
+
export * from "./SchemaXml";
|
|
3
|
+
export * from "./SchemaJsonFileLocater";
|
|
4
|
+
export * from "./SchemaXmlFileLocater";
|
|
5
|
+
export * from "./StubSchemaXmlFileLocater";
|
|
6
|
+
export * from "./SchemaXmlStringLocater";
|
|
7
|
+
/** @docs-package-description
|
|
8
|
+
* The ecschema-locaters package contains classes for locating ECSchemas within a given
|
|
9
|
+
* [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
|
|
10
|
+
* implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @docs-group-description Locaters
|
|
14
|
+
* ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @docs-group-description Utils
|
|
18
|
+
* A set of utility classes used throughout the package.
|
|
19
|
+
*/
|
|
20
|
+
//# sourceMappingURL=ecschema-locaters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecschema-locaters.d.ts","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":"AAKA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
export * from "./SchemaFileLocater";
|
|
6
|
+
export * from "./SchemaXml";
|
|
7
|
+
export * from "./SchemaJsonFileLocater";
|
|
8
|
+
export * from "./SchemaXmlFileLocater";
|
|
9
|
+
export * from "./StubSchemaXmlFileLocater";
|
|
10
|
+
export * from "./SchemaXmlStringLocater";
|
|
11
|
+
/** @docs-package-description
|
|
12
|
+
* The ecschema-locaters package contains classes for locating ECSchemas within a given
|
|
13
|
+
* [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater
|
|
14
|
+
* implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @docs-group-description Locaters
|
|
18
|
+
* ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @docs-group-description Utils
|
|
22
|
+
* A set of utility classes used throughout the package.
|
|
23
|
+
*/
|
|
24
|
+
//# sourceMappingURL=ecschema-locaters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecschema-locaters.js","sourceRoot":"","sources":["../../src/ecschema-locaters.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC;;;;GAIG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./SchemaFileLocater\";\nexport * from \"./SchemaXml\";\nexport * from \"./SchemaJsonFileLocater\";\nexport * from \"./SchemaXmlFileLocater\";\nexport * from \"./StubSchemaXmlFileLocater\";\nexport * from \"./SchemaXmlStringLocater\";\n\n/** @docs-package-description\n * The ecschema-locaters package contains classes for locating ECSchemas within a given\n * [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext). Each locater\n * implements the [ISchemaLocater interface](https://www.itwinjs.org/reference/ecschema-metadata/context/ischemalocater/).\n */\n/**\n * @docs-group-description Locaters\n * ISchemaLocater implementations used to locate schemas in a given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext).\n */\n/**\n * @docs-group-description Utils\n * A set of utility classes used throughout the package.\n */\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConcurrentGetSchemaJson.test.d.ts","sourceRoot":"","sources":["../../../src/test/ConcurrentGetSchemaJson.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
import { assert, expect } from "chai";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { ECVersion, SchemaContext, SchemaJsonLocater, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
9
|
+
import { SchemaJsonFileLocater } from "../SchemaJsonFileLocater";
|
|
10
|
+
describe("Concurrent schema JSON deserialization", () => {
|
|
11
|
+
const assetDir = path.join(__dirname, "assets");
|
|
12
|
+
const schemaFolder = path.join(__dirname, "assets", "json");
|
|
13
|
+
const schemaKeys = [];
|
|
14
|
+
let context;
|
|
15
|
+
let contextSync;
|
|
16
|
+
let syncSchemas = [];
|
|
17
|
+
const locater = new SchemaJsonFileLocater();
|
|
18
|
+
before(() => {
|
|
19
|
+
if (!fs.existsSync(assetDir))
|
|
20
|
+
fs.mkdirSync(assetDir);
|
|
21
|
+
if (!fs.existsSync(schemaFolder))
|
|
22
|
+
fs.mkdirSync(schemaFolder);
|
|
23
|
+
copySchemasToAssetsDir();
|
|
24
|
+
// Deserialize schemas synchronously/serially as standard to compare to
|
|
25
|
+
contextSync = new SchemaContext();
|
|
26
|
+
locater.addSchemaSearchPath(schemaFolder);
|
|
27
|
+
contextSync.addLocater(locater);
|
|
28
|
+
const schemaFiles = fs.readdirSync(schemaFolder);
|
|
29
|
+
schemaFiles.forEach((fileName) => {
|
|
30
|
+
const schemaFile = path.join(schemaFolder, fileName);
|
|
31
|
+
const schemaJson = JSON.parse(fs.readFileSync(schemaFile, "utf-8"));
|
|
32
|
+
const schemaName = schemaJson.name;
|
|
33
|
+
const schemaVersion = schemaJson.version;
|
|
34
|
+
const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));
|
|
35
|
+
schemaKeys.push(key);
|
|
36
|
+
});
|
|
37
|
+
syncSchemas = schemaKeys.map((key) => {
|
|
38
|
+
if (!key)
|
|
39
|
+
return undefined;
|
|
40
|
+
const schema = contextSync.getSchemaSync(key, SchemaMatchType.Latest);
|
|
41
|
+
return schema;
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
context = new SchemaContext();
|
|
46
|
+
context.addLocater(locater);
|
|
47
|
+
});
|
|
48
|
+
function getSchemaPathFromPackage(packageName, schemaFileName) {
|
|
49
|
+
const schemaFile = path.join(__dirname, "..", "..", "..", "node_modules", "@bentley", packageName, schemaFileName);
|
|
50
|
+
return schemaFile;
|
|
51
|
+
}
|
|
52
|
+
function copySchemasToAssetsDir() {
|
|
53
|
+
// Copy Schemas that we need for testing
|
|
54
|
+
fs.copyFileSync(getSchemaPathFromPackage("aec-units-schema", "AecUnits.ecschema.json"), path.join(schemaFolder, "AecUnits.ecschema.json"));
|
|
55
|
+
fs.copyFileSync(getSchemaPathFromPackage("architectural-physical-schema", "ArchitecturalPhysical.ecschema.json"), path.join(schemaFolder, "ArchitecturalPhysical.ecschema.json"));
|
|
56
|
+
fs.copyFileSync(getSchemaPathFromPackage("bis-core-schema", "BisCore.ecschema.json"), path.join(schemaFolder, "BisCore.ecschema.json"));
|
|
57
|
+
fs.copyFileSync(getSchemaPathFromPackage("bis-custom-attributes-schema", "BisCustomAttributes.ecschema.json"), path.join(schemaFolder, "BisCustomAttributes.ecschema.json"));
|
|
58
|
+
fs.copyFileSync(getSchemaPathFromPackage("construction-schema", "Construction.ecschema.json"), path.join(schemaFolder, "Construction.ecschema.json"));
|
|
59
|
+
fs.copyFileSync(getSchemaPathFromPackage("core-custom-attributes-schema", "CoreCustomAttributes.ecschema.json"), path.join(schemaFolder, "CoreCustomAttributes.ecschema.json"));
|
|
60
|
+
fs.copyFileSync(getSchemaPathFromPackage("ecdb-map-schema", "ECDbMap.ecschema.json"), path.join(schemaFolder, "ECDbMap.ecschema.json"));
|
|
61
|
+
fs.copyFileSync(getSchemaPathFromPackage("ecdb-schema-policies-schema", "ECDbSchemaPolicies.ecschema.json"), path.join(schemaFolder, "ECDbSchemaPolicies.ecschema.json"));
|
|
62
|
+
fs.copyFileSync(getSchemaPathFromPackage("formats-schema", "Formats.ecschema.json"), path.join(schemaFolder, "Formats.ecschema.json"));
|
|
63
|
+
fs.copyFileSync(getSchemaPathFromPackage("linear-referencing-schema", "LinearReferencing.ecschema.json"), path.join(schemaFolder, "LinearReferencing.ecschema.json"));
|
|
64
|
+
fs.copyFileSync(getSchemaPathFromPackage("physical-material-schema", "PhysicalMaterial.ecschema.json"), path.join(schemaFolder, "PhysicalMaterial.ecschema.json"));
|
|
65
|
+
fs.copyFileSync(getSchemaPathFromPackage("plant-custom-attributes-schema", "PlantCustomAttributes.ecschema.json"), path.join(schemaFolder, "PlantCustomAttributes.ecschema.json"));
|
|
66
|
+
fs.copyFileSync(getSchemaPathFromPackage("quantity-takeoffs-aspects-schema", "QuantityTakeoffsAspects.ecschema.json"), path.join(schemaFolder, "QuantityTakeoffsAspects.ecschema.json"));
|
|
67
|
+
fs.copyFileSync(getSchemaPathFromPackage("spatial-composition-schema", "SpatialComposition.ecschema.json"), path.join(schemaFolder, "SpatialComposition.ecschema.json"));
|
|
68
|
+
fs.copyFileSync(getSchemaPathFromPackage("structural-physical-schema", "StructuralPhysical.ecschema.json"), path.join(schemaFolder, "StructuralPhysical.ecschema.json"));
|
|
69
|
+
fs.copyFileSync(getSchemaPathFromPackage("units-schema", "Units.ecschema.json"), path.join(schemaFolder, "Units.ecschema.json"));
|
|
70
|
+
}
|
|
71
|
+
it("should match schemas deserialized concurrently with schemas deserialized serially", async () => {
|
|
72
|
+
const schemaPromises = schemaKeys.map(async (key) => {
|
|
73
|
+
if (!key)
|
|
74
|
+
return undefined;
|
|
75
|
+
const schema = await context.getSchema(key, SchemaMatchType.Latest);
|
|
76
|
+
return schema;
|
|
77
|
+
});
|
|
78
|
+
const asyncSchemas = await Promise.all(schemaPromises);
|
|
79
|
+
for (let i = 0; i < schemaKeys.length; i++) {
|
|
80
|
+
const syncSchema = syncSchemas[i];
|
|
81
|
+
expect(syncSchema).not.to.be.undefined;
|
|
82
|
+
const syncJSON = syncSchema.toJSON();
|
|
83
|
+
const asyncSchema = asyncSchemas[i];
|
|
84
|
+
expect(asyncSchema).not.to.be.undefined;
|
|
85
|
+
const asyncJSON = asyncSchema.toJSON();
|
|
86
|
+
expect(asyncJSON).to.deep.equal(syncJSON);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
it("should be able to mix getSchema and getSchemaSync", async () => {
|
|
90
|
+
const schemaPromises = schemaKeys.map(async (key, index) => {
|
|
91
|
+
if (index % 2 === 0) {
|
|
92
|
+
// Use getSchema() for even indices
|
|
93
|
+
if (!key)
|
|
94
|
+
return undefined;
|
|
95
|
+
const schema = await context.getSchema(key, SchemaMatchType.Latest);
|
|
96
|
+
return schema;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Use getSchemaSync() for odd indices
|
|
100
|
+
if (!key)
|
|
101
|
+
return undefined;
|
|
102
|
+
const schema = context.getSchemaSync(key, SchemaMatchType.Latest);
|
|
103
|
+
return schema;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const schemas = await Promise.all(schemaPromises);
|
|
107
|
+
for (let i = 0; i < schemaKeys.length; i++) {
|
|
108
|
+
const syncSchema = syncSchemas[i];
|
|
109
|
+
expect(syncSchema).not.to.be.undefined;
|
|
110
|
+
const syncJSON = syncSchema.toJSON();
|
|
111
|
+
const schema = schemas[i];
|
|
112
|
+
expect(schema).not.to.be.undefined;
|
|
113
|
+
const schemaJSON = schema.toJSON();
|
|
114
|
+
expect(schemaJSON).to.deep.equal(syncJSON);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
/* Run these tests below one at a time. Running them together doesn't get accurate performance likely bc of disk access caching */
|
|
118
|
+
it.skip("should measure regular deserialization performance", async () => {
|
|
119
|
+
const schemaPromises = schemaKeys.map(async (key) => {
|
|
120
|
+
if (!key)
|
|
121
|
+
return undefined;
|
|
122
|
+
const schema = await context.getSchema(key, SchemaMatchType.Latest);
|
|
123
|
+
return schema;
|
|
124
|
+
});
|
|
125
|
+
for (const promise of schemaPromises) {
|
|
126
|
+
await promise;
|
|
127
|
+
}
|
|
128
|
+
expect(schemaPromises.length).to.equal(schemaKeys.length);
|
|
129
|
+
});
|
|
130
|
+
it.skip("should measure concurrent deserialization performance", async () => {
|
|
131
|
+
const schemaPromises = schemaKeys.map(async (key) => {
|
|
132
|
+
if (!key)
|
|
133
|
+
return undefined;
|
|
134
|
+
const schema = await context.getSchema(key, SchemaMatchType.Latest);
|
|
135
|
+
return schema;
|
|
136
|
+
});
|
|
137
|
+
const asyncSchemas = await Promise.all(schemaPromises);
|
|
138
|
+
expect(asyncSchemas.length).to.equal(schemaKeys.length);
|
|
139
|
+
});
|
|
140
|
+
it("Concurrently get BisCore with SchemaJsonFileLocater", async () => {
|
|
141
|
+
const schemaContext = new SchemaContext();
|
|
142
|
+
const jsonFileLocater = new SchemaJsonFileLocater();
|
|
143
|
+
jsonFileLocater.addSchemaSearchPath(schemaFolder);
|
|
144
|
+
schemaContext.addLocater(jsonFileLocater);
|
|
145
|
+
const schemas = await Promise.all([...Array(100).keys()].map(async () => {
|
|
146
|
+
return schemaContext.getSchema(new SchemaKey("BisCore"));
|
|
147
|
+
}));
|
|
148
|
+
expect(schemas.length).to.equal(100);
|
|
149
|
+
schemas.forEach((schema) => {
|
|
150
|
+
assert(schema !== undefined);
|
|
151
|
+
expect(schema.fullName).to.equal("BisCore");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
it("Concurrently get a schema and it's referenced schema with SchemaJsonFileLocater", async () => {
|
|
155
|
+
const schemaContext = new SchemaContext();
|
|
156
|
+
const jsonFileLocater = new SchemaJsonFileLocater();
|
|
157
|
+
jsonFileLocater.addSchemaSearchPath(schemaFolder);
|
|
158
|
+
schemaContext.addLocater(jsonFileLocater);
|
|
159
|
+
let getBisCoreFirst = 0;
|
|
160
|
+
const schemas = await Promise.all([...Array(2).keys()].map(async () => {
|
|
161
|
+
if (getBisCoreFirst === 0) {
|
|
162
|
+
getBisCoreFirst = 1;
|
|
163
|
+
return schemaContext.getSchema(new SchemaKey("BisCore"));
|
|
164
|
+
}
|
|
165
|
+
return schemaContext.getSchema(new SchemaKey("CoreCustomAttributes"));
|
|
166
|
+
}));
|
|
167
|
+
expect(schemas.length).to.equal(2);
|
|
168
|
+
schemas.forEach((schema) => {
|
|
169
|
+
expect(schema).to.not.be.undefined;
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
const getSchemaProps = (schemaName) => {
|
|
173
|
+
if (schemaName === "BisCore") {
|
|
174
|
+
return {
|
|
175
|
+
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
|
|
176
|
+
alias: "bis",
|
|
177
|
+
description: "The BIS core schema contains classes that all other domain schemas extend.",
|
|
178
|
+
label: "BIS Core",
|
|
179
|
+
name: "BisCore",
|
|
180
|
+
version: "01.00.15",
|
|
181
|
+
references: [{ name: "CoreCustomAttributes", version: "01.00.04" }, { name: "ECDbMap", version: "02.00.00" }, { name: "ECDbSchemaPolicies", version: "01.00.00" }],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (schemaName === "CoreCustomAttributes") {
|
|
185
|
+
return {
|
|
186
|
+
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
|
|
187
|
+
alias: "CoreCA",
|
|
188
|
+
description: "Custom attributes to indicate core EC concepts, may include struct classes intended for use in core custom attributes.",
|
|
189
|
+
label: "Core Custom Attributes",
|
|
190
|
+
name: "CoreCustomAttributes",
|
|
191
|
+
version: "01.00.04",
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (schemaName === "ECDbMap") {
|
|
195
|
+
return {
|
|
196
|
+
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
|
|
197
|
+
alias: "ECDbMap",
|
|
198
|
+
description: "ECDbMap Desc",
|
|
199
|
+
label: "ECDbMap",
|
|
200
|
+
name: "ECDbMap",
|
|
201
|
+
version: "02.00.00",
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (schemaName === "ECDbSchemaPolicies") {
|
|
205
|
+
return {
|
|
206
|
+
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
|
|
207
|
+
alias: "ECDbSchemaPolicies",
|
|
208
|
+
description: "ECDbSchemaPolicies Desc",
|
|
209
|
+
label: "ECDbSchemaPolicies",
|
|
210
|
+
name: "ECDbSchemaPolicies",
|
|
211
|
+
version: "01.00.00",
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
};
|
|
216
|
+
it("Concurrently get BisCore with SchemaJsonLocater", async () => {
|
|
217
|
+
const schemaContext = new SchemaContext();
|
|
218
|
+
const jsonLocater = new SchemaJsonLocater(getSchemaProps);
|
|
219
|
+
schemaContext.addLocater(jsonLocater);
|
|
220
|
+
const schemaCount = 1000;
|
|
221
|
+
const schemas = await Promise.all([...Array(schemaCount).keys()].map(async () => {
|
|
222
|
+
return schemaContext.getSchema(new SchemaKey("BisCore"));
|
|
223
|
+
}));
|
|
224
|
+
expect(schemas.length).to.equal(schemaCount);
|
|
225
|
+
schemas.forEach((schema) => {
|
|
226
|
+
assert(schema !== undefined);
|
|
227
|
+
expect(schema.fullName).to.equal("BisCore");
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
it("Concurrently get a schema and it's referenced schema with SchemaJsonLocater", async () => {
|
|
231
|
+
const schemaContext = new SchemaContext();
|
|
232
|
+
const jsonLocater = new SchemaJsonLocater(getSchemaProps);
|
|
233
|
+
schemaContext.addLocater(jsonLocater);
|
|
234
|
+
let getBisCoreFirst = 0;
|
|
235
|
+
const schemaCount = 1000;
|
|
236
|
+
const schemas = await Promise.all([...Array(schemaCount).keys()].map(async () => {
|
|
237
|
+
if (getBisCoreFirst === 0) {
|
|
238
|
+
getBisCoreFirst = 1;
|
|
239
|
+
return schemaContext.getSchema(new SchemaKey("BisCore"));
|
|
240
|
+
}
|
|
241
|
+
return schemaContext.getSchema(new SchemaKey("CoreCustomAttributes"));
|
|
242
|
+
}));
|
|
243
|
+
expect(schemas.length).to.equal(schemaCount);
|
|
244
|
+
schemas.forEach((schema) => {
|
|
245
|
+
expect(schema).to.not.be.undefined;
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
//# sourceMappingURL=ConcurrentGetSchemaJson.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConcurrentGetSchemaJson.test.js","sourceRoot":"","sources":["../../../src/test/ConcurrentGetSchemaJson.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAU,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3H,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACtD,MAAM,QAAQ,GAAW,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE5D,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,IAAI,OAAsB,CAAC;IAC3B,IAAI,WAA0B,CAAC;IAC/B,IAAI,WAAW,GAA8B,EAAE,CAAC;IAEhD,MAAM,OAAO,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAE5C,MAAM,CAAC,GAAG,EAAE;QACV,IAAI,CAAC,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AC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","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 { assert, expect } from \"chai\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { ECVersion, Schema, SchemaContext, SchemaJsonLocater, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { SchemaJsonFileLocater } from \"../SchemaJsonFileLocater\";\n\ndescribe(\"Concurrent schema JSON deserialization\", () => {\n const assetDir: string = path.join(__dirname, \"assets\");\n const schemaFolder = path.join(__dirname, \"assets\", \"json\");\n\n const schemaKeys: SchemaKey[] = [];\n let context: SchemaContext;\n let contextSync: SchemaContext;\n let syncSchemas: Array<Schema | undefined> = [];\n\n const locater = new SchemaJsonFileLocater();\n\n before(() => {\n if (!fs.existsSync(assetDir))\n fs.mkdirSync(assetDir);\n if (!fs.existsSync(schemaFolder))\n fs.mkdirSync(schemaFolder);\n\n copySchemasToAssetsDir();\n\n // Deserialize schemas synchronously/serially as standard to compare to\n contextSync = new SchemaContext();\n locater.addSchemaSearchPath(schemaFolder);\n contextSync.addLocater(locater);\n\n const schemaFiles = fs.readdirSync(schemaFolder);\n schemaFiles.forEach((fileName) => {\n const schemaFile = path.join(schemaFolder, fileName);\n const schemaJson = JSON.parse(fs.readFileSync(schemaFile, \"utf-8\"));\n const schemaName = schemaJson.name;\n const schemaVersion = schemaJson.version;\n\n const key = new SchemaKey(schemaName.toString(), ECVersion.fromString(schemaVersion.toString()));\n schemaKeys.push(key);\n });\n\n syncSchemas = schemaKeys.map((key): Schema | undefined => {\n if (!key)\n return undefined;\n\n const schema = contextSync.getSchemaSync(key, SchemaMatchType.Latest);\n return schema;\n });\n });\n\n beforeEach(() => {\n context = new SchemaContext();\n context.addLocater(locater);\n });\n\n function getSchemaPathFromPackage(packageName: string, schemaFileName: string): string {\n const schemaFile = path.join(__dirname, \"..\", \"..\", \"..\", \"node_modules\", \"@bentley\", packageName, schemaFileName);\n return schemaFile;\n }\n\n function copySchemasToAssetsDir() {\n // Copy Schemas that we need for testing\n fs.copyFileSync(getSchemaPathFromPackage(\"aec-units-schema\", \"AecUnits.ecschema.json\"), path.join(schemaFolder, \"AecUnits.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"architectural-physical-schema\", \"ArchitecturalPhysical.ecschema.json\"), path.join(schemaFolder, \"ArchitecturalPhysical.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"bis-core-schema\", \"BisCore.ecschema.json\"), path.join(schemaFolder, \"BisCore.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"bis-custom-attributes-schema\", \"BisCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"BisCustomAttributes.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"construction-schema\", \"Construction.ecschema.json\"), path.join(schemaFolder, \"Construction.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"core-custom-attributes-schema\", \"CoreCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"CoreCustomAttributes.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"ecdb-map-schema\", \"ECDbMap.ecschema.json\"), path.join(schemaFolder, \"ECDbMap.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"ecdb-schema-policies-schema\", \"ECDbSchemaPolicies.ecschema.json\"), path.join(schemaFolder, \"ECDbSchemaPolicies.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"formats-schema\", \"Formats.ecschema.json\"), path.join(schemaFolder, \"Formats.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"linear-referencing-schema\", \"LinearReferencing.ecschema.json\"), path.join(schemaFolder, \"LinearReferencing.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"physical-material-schema\", \"PhysicalMaterial.ecschema.json\"), path.join(schemaFolder, \"PhysicalMaterial.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"plant-custom-attributes-schema\", \"PlantCustomAttributes.ecschema.json\"), path.join(schemaFolder, \"PlantCustomAttributes.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"quantity-takeoffs-aspects-schema\", \"QuantityTakeoffsAspects.ecschema.json\"), path.join(schemaFolder, \"QuantityTakeoffsAspects.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"spatial-composition-schema\", \"SpatialComposition.ecschema.json\"), path.join(schemaFolder, \"SpatialComposition.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"structural-physical-schema\", \"StructuralPhysical.ecschema.json\"), path.join(schemaFolder, \"StructuralPhysical.ecschema.json\"));\n fs.copyFileSync(getSchemaPathFromPackage(\"units-schema\", \"Units.ecschema.json\"), path.join(schemaFolder, \"Units.ecschema.json\"));\n }\n\n it(\"should match schemas deserialized concurrently with schemas deserialized serially\", async () => {\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n });\n const asyncSchemas = await Promise.all(schemaPromises);\n\n for (let i = 0; i < schemaKeys.length; i++) {\n const syncSchema = syncSchemas[i];\n expect(syncSchema).not.to.be.undefined;\n const syncJSON = syncSchema!.toJSON();\n\n const asyncSchema = asyncSchemas[i];\n expect(asyncSchema).not.to.be.undefined;\n const asyncJSON = asyncSchema!.toJSON();\n expect(asyncJSON).to.deep.equal(syncJSON);\n }\n });\n\n it(\"should be able to mix getSchema and getSchemaSync\", async () => {\n const schemaPromises = schemaKeys.map(async (key, index): Promise<Schema | undefined> => {\n if (index % 2 === 0) {\n // Use getSchema() for even indices\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n } else {\n // Use getSchemaSync() for odd indices\n if (!key)\n return undefined;\n\n const schema = context.getSchemaSync(key, SchemaMatchType.Latest);\n return schema;\n }\n });\n const schemas = await Promise.all(schemaPromises);\n\n for (let i = 0; i < schemaKeys.length; i++) {\n const syncSchema = syncSchemas[i];\n expect(syncSchema).not.to.be.undefined;\n const syncJSON = syncSchema!.toJSON();\n\n const schema = schemas[i];\n expect(schema).not.to.be.undefined;\n const schemaJSON = schema!.toJSON();\n expect(schemaJSON).to.deep.equal(syncJSON);\n }\n });\n\n /* Run these tests below one at a time. Running them together doesn't get accurate performance likely bc of disk access caching */\n it.skip(\"should measure regular deserialization performance\", async () => {\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n });\n\n for (const promise of schemaPromises) {\n await promise;\n }\n\n expect(schemaPromises.length).to.equal(schemaKeys.length);\n });\n\n it.skip(\"should measure concurrent deserialization performance\", async () => {\n const schemaPromises = schemaKeys.map(async (key): Promise<Schema | undefined> => {\n if (!key)\n return undefined;\n\n const schema = await context.getSchema(key, SchemaMatchType.Latest);\n return schema;\n });\n const asyncSchemas = await Promise.all(schemaPromises);\n\n expect(asyncSchemas.length).to.equal(schemaKeys.length);\n });\n\n it(\"Concurrently get BisCore with SchemaJsonFileLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonFileLocater = new SchemaJsonFileLocater();\n jsonFileLocater.addSchemaSearchPath(schemaFolder);\n schemaContext.addLocater(jsonFileLocater);\n\n const schemas = await Promise.all(\n [...Array(100).keys()].map(async () => {\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }),\n );\n expect(schemas.length).to.equal(100);\n schemas.forEach((schema) => {\n assert(schema !== undefined);\n expect(schema.fullName).to.equal(\"BisCore\");\n });\n });\n\n it(\"Concurrently get a schema and it's referenced schema with SchemaJsonFileLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonFileLocater = new SchemaJsonFileLocater();\n jsonFileLocater.addSchemaSearchPath(schemaFolder);\n schemaContext.addLocater(jsonFileLocater);\n\n let getBisCoreFirst = 0;\n const schemas = await Promise.all(\n [...Array(2).keys()].map(async () => {\n if (getBisCoreFirst === 0) {\n getBisCoreFirst = 1;\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }\n return schemaContext.getSchema(new SchemaKey(\"CoreCustomAttributes\"));\n }),\n );\n expect(schemas.length).to.equal(2);\n schemas.forEach((schema) => {\n expect(schema).to.not.be.undefined;\n });\n });\n\n const getSchemaProps = (schemaName: string) => {\n if (schemaName === \"BisCore\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"bis\",\n description: \"The BIS core schema contains classes that all other domain schemas extend.\",\n label: \"BIS Core\",\n name: \"BisCore\",\n version: \"01.00.15\",\n references:[{name:\"CoreCustomAttributes\", version:\"01.00.04\"},{name:\"ECDbMap\", version:\"02.00.00\"},{name:\"ECDbSchemaPolicies\", version:\"01.00.00\"}],\n };\n }\n if (schemaName === \"CoreCustomAttributes\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"CoreCA\",\n description: \"Custom attributes to indicate core EC concepts, may include struct classes intended for use in core custom attributes.\",\n label: \"Core Custom Attributes\",\n name: \"CoreCustomAttributes\",\n version: \"01.00.04\",\n };\n }\n if (schemaName === \"ECDbMap\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"ECDbMap\",\n description: \"ECDbMap Desc\",\n label: \"ECDbMap\",\n name: \"ECDbMap\",\n version: \"02.00.00\",\n };\n }\n if (schemaName === \"ECDbSchemaPolicies\") {\n return {\n $schema: \"https://dev.bentley.com/json_schemas/ec/32/ecschema\",\n alias: \"ECDbSchemaPolicies\",\n description: \"ECDbSchemaPolicies Desc\",\n label: \"ECDbSchemaPolicies\",\n name: \"ECDbSchemaPolicies\",\n version: \"01.00.00\",\n };\n }\n\n return undefined;\n };\n\n it(\"Concurrently get BisCore with SchemaJsonLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonLocater = new SchemaJsonLocater(getSchemaProps);\n schemaContext.addLocater(jsonLocater);\n\n const schemaCount = 1000;\n const schemas = await Promise.all(\n [...Array(schemaCount).keys()].map(async () => {\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }),\n );\n expect(schemas.length).to.equal(schemaCount);\n schemas.forEach((schema) => {\n assert(schema !== undefined);\n expect(schema.fullName).to.equal(\"BisCore\");\n });\n });\n\n it(\"Concurrently get a schema and it's referenced schema with SchemaJsonLocater\", async () => {\n const schemaContext = new SchemaContext();\n const jsonLocater = new SchemaJsonLocater(getSchemaProps);\n schemaContext.addLocater(jsonLocater);\n\n let getBisCoreFirst = 0;\n const schemaCount = 1000;\n const schemas = await Promise.all(\n [...Array(schemaCount).keys()].map(async () => {\n if (getBisCoreFirst === 0) {\n getBisCoreFirst = 1;\n return schemaContext.getSchema(new SchemaKey(\"BisCore\"));\n }\n return schemaContext.getSchema(new SchemaKey(\"CoreCustomAttributes\"));\n }),\n );\n expect(schemas.length).to.equal(schemaCount);\n schemas.forEach((schema) => {\n expect(schema).to.not.be.undefined;\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConcurrentGetSchemaXml.test.d.ts","sourceRoot":"","sources":["../../../src/test/ConcurrentGetSchemaXml.test.ts"],"names":[],"mappings":""}
|