@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,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":["/*---------------------------------------------------------------------------------------------\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 Utils\n */\n\nimport * as fs from \"fs-extra\";\nimport * as path from \"path\";\nimport { DOMParser, XMLSerializer } from \"@xmldom/xmldom\";\nimport { Schema } from \"@itwin/ecschema-metadata\";\n\n/**\n * Utility class to assist in creating serialized EC Schemas on the file system.\n * @beta\n */\nexport namespace SchemaXml {\n\n /**\n * Writes a Schema to an xml file to the specified output path.\n * @param schema The Schema to serialize.\n * @param outputPath The directory in which to create the file.\n */\n export async function writeFile(schema: Schema, outputPath: string) {\n const xml = await writeString(schema);\n\n const baseFile = getSchemaPath(schema, outputPath);\n try {\n await fs.writeFile(baseFile, xml);\n } catch (err: any) {\n const msg = `An error occurred writing to file '${baseFile}': ${err.message}`;\n throw new Error(msg);\n }\n }\n\n /**\n * Writes a Schema to an xml string.\n * @param schema The Schema to serialize.\n */\n export async function writeString(schema: Schema): Promise<string> {\n let xmlDoc = new DOMParser().parseFromString(`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`, \"application/xml\");\n\n xmlDoc = await schema.toXml(xmlDoc);\n const serializer = new XMLSerializer();\n return serializer.serializeToString(xmlDoc);\n }\n\n function getSchemaPath(schema: Schema, outputPath: string): string {\n const realDir = path.normalize(outputPath);\n const test = fs.pathExistsSync(realDir);\n if (!test) {\n const msg = `The output directory '${realDir}' does not exist.`;\n throw new Error(msg);\n }\n\n return path.resolve(realDir, `${schema.name}.ecschema.xml`);\n }\n}\n"]}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlFileLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlFileLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,cAAc,EAAE,eAAe,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,EAAmB,gBAAgB,EAAE,SAAS,GACvJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IACzD;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CAAC,GAAc,EAAE,SAA0B,EAAE,OAAsB;QACvF,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,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D,OAAO,CAAC,0CAA0C;IACpD,CAAC;IAED;;;;OAIG;IACa,oBAAoB,CAAC,YAAsB;QACzD,OAAO,CAAC,0CAA0C;IACpD,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 * as fs from \"fs\";\nimport { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { FileSchemaKey, SchemaFileLocater } from \"./SchemaFileLocater\";\nimport { globSync } from \"glob\";\n\n/**\n * A SchemaLocater implementation for locating XML Schema files\n * from the file system using configurable search paths.\n * @beta This is a workaround the current lack of a full xml parser.\n */\nexport class SchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {\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.\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 await this.getSchemaInfo(key, matchType, context);\n\n const schema = await context.getCachedSchema(key, matchType);\n return schema;\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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n const candidates: FileSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType, \"xml\");\n\n if (0 === candidates.length)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (undefined === await this.fileExists(schemaPath))\n return undefined;\n\n const schemaText = await this.readUtf8FileToString(schemaPath);\n if (undefined === schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\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.\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 schemaPath = maxCandidate.fileName;\n\n // Load the file\n if (!this.fileExistsSync(schemaPath))\n return undefined;\n\n const schemaText = this.readUtf8FileToStringSync(schemaPath);\n if (!schemaText)\n return undefined;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n this.addSchemaSearchPaths([path.dirname(schemaPath)]);\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema;\n }\n\n /**\n * Constructs a SchemaKey based on the information in the Schema XML.\n * @param data The Schema XML as a string.\n */\n public getSchemaKey(data: string): SchemaKey {\n const matches = data.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 const key = new SchemaKey(name[1], ECVersion.fromString(version[1]));\n return key;\n }\n}\n\n/**\n * This locater is responsible for locating standard schema files that are released by the core-backend package.\n * The locater needs an argument to the known backend assets directory where the core-backend package is installed.\n * This can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.\n *\n * @note This locater is read-only and does not allow adding new schema search paths.\n * @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.\n * @beta This is a workaround due to the current lack of a full xml parser.\n */\nexport class PublishedSchemaXmlFileLocater extends SchemaXmlFileLocater implements ISchemaLocater {\n /**\n * Constructs a new PublishedSchemaXmlFileLocater\n * @param knownBackendAssetsDir The assets directory where the core-backend package is installed. Can be accessed by the KnownLocations.nativeAssetsDir getter provided by core-backend.\n */\n public constructor(knownBackendAssetsDir: string) {\n super();\n\n const ecSchemaDir = path.join(knownBackendAssetsDir, \"ECSchemas\");\n if (!fs.existsSync(ecSchemaDir))\n throw new Error(`The directory ${ecSchemaDir} containing standard schemas does not exist.`);\n\n // Pre-defined set of standard schema search paths\n this.searchPaths.push(...globSync(path.join(ecSchemaDir, \"*/\"), { windowsPathsNoEscape: true }).filter(fs.existsSync));\n }\n\n /**\n * Overrides the addSchemaSearchPath method to prevent adding new schema search paths.\n *\n * @param _schemaPath - The schema path to add (ignored).\n */\n public override addSchemaSearchPath(_schemaPath: string): void {\n return; // Do nothing, this is a read-only locator\n }\n\n /**\n * Overrides the addSchemaSearchPaths method to prevent adding new schema search paths.\n *\n * @param _schemaPaths - The schema paths to add (ignored).\n */\n public override addSchemaSearchPaths(_schemaPaths: string[]): void {\n return; // Do nothing, this is a read-only locator\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Locaters
|
|
3
|
+
*/
|
|
4
|
+
import { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
5
|
+
import { SchemaStringLocater } from "./SchemaStringLocater";
|
|
6
|
+
/**
|
|
7
|
+
* A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings
|
|
8
|
+
* loaded in memory.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export declare class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
14
|
+
* @param schemaXml The Schema XML as a string.
|
|
15
|
+
*/
|
|
16
|
+
getSchemaKey(schemaXml: string): SchemaKey;
|
|
17
|
+
/**
|
|
18
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
19
|
+
* Schema strings.
|
|
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 searching the configured
|
|
35
|
+
* Schema strings.
|
|
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 and holds the schema's references, if they exist.
|
|
39
|
+
*/
|
|
40
|
+
getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
43
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
44
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
45
|
+
*/
|
|
46
|
+
private fromECv2String;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=SchemaXmlStringLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.d.ts","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EACuC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAC1H,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAE7E;;;;GAIG;AACH,qBAAa,sBAAuB,SAAQ,mBAAoB,YAAW,cAAc;IAEvF;;;OAGG;IACI,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IAejD;;;;;;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;IAkBrI;;;;;;OAMG;IACI,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;IAmBlH;;;;OAIG;IACH,OAAO,CAAC,cAAc;CAYvB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { DOMParser } from "@xmldom/xmldom";
|
|
9
|
+
import { ECObjectsError, ECObjectsStatus, ECVersion, Schema, SchemaKey, SchemaReadHelper, XmlParser, } from "@itwin/ecschema-metadata";
|
|
10
|
+
import { SchemaStringLocater } from "./SchemaStringLocater";
|
|
11
|
+
/**
|
|
12
|
+
* A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings
|
|
13
|
+
* loaded in memory.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export class SchemaXmlStringLocater extends SchemaStringLocater {
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
19
|
+
* @param schemaXml The Schema XML as a string.
|
|
20
|
+
*/
|
|
21
|
+
getSchemaKey(schemaXml) {
|
|
22
|
+
const matches = schemaXml.match(/<ECSchema ([^]+?)>/g);
|
|
23
|
+
if (!matches || matches.length !== 1)
|
|
24
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find '<ECSchema>' tag in the given string`);
|
|
25
|
+
const name = matches[0].match(/schemaName="(.+?)"/);
|
|
26
|
+
const version = matches[0].match(/version="(.+?)"/);
|
|
27
|
+
if (!name || name.length !== 2 || !version || version.length !== 2)
|
|
28
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Could not find the ECSchema 'schemaName' or 'version' tag in the given string`);
|
|
29
|
+
const ecVersion = ECVersion.fromString(version[1]);
|
|
30
|
+
const key = new SchemaKey(name[1], ecVersion);
|
|
31
|
+
return key;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
35
|
+
* Schema strings.
|
|
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 and holds the schema's references, if they exist.
|
|
39
|
+
*/
|
|
40
|
+
async getSchema(schemaKey, matchType, context) {
|
|
41
|
+
await this.getSchemaInfo(schemaKey, matchType, context);
|
|
42
|
+
const schema = await context.getCachedSchema(schemaKey, matchType);
|
|
43
|
+
return schema;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
47
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
48
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
49
|
+
* @param matchType The match type to use when locating the schema
|
|
50
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
51
|
+
*/
|
|
52
|
+
async getSchemaInfo(schemaKey, matchType, context) {
|
|
53
|
+
// Grab all schema strings that match the schema key
|
|
54
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
55
|
+
if (!candidates || candidates.length === 0)
|
|
56
|
+
return undefined;
|
|
57
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
58
|
+
const schemaText = maxCandidate.schemaText;
|
|
59
|
+
const parser = new DOMParser();
|
|
60
|
+
const document = parser.parseFromString(schemaText);
|
|
61
|
+
const reader = new SchemaReadHelper(XmlParser, context);
|
|
62
|
+
const schema = new Schema(context);
|
|
63
|
+
return reader.readSchemaInfo(schema, document);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Attempts to retrieve a Schema with the given SchemaKey by searching the configured
|
|
67
|
+
* Schema strings.
|
|
68
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
69
|
+
* @param matchType The SchemaMatchType.
|
|
70
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
71
|
+
*/
|
|
72
|
+
getSchemaSync(schemaKey, matchType, context) {
|
|
73
|
+
// Grab all schema strings that match the schema key
|
|
74
|
+
const candidates = this.findEligibleSchemaKeys(schemaKey, matchType);
|
|
75
|
+
if (!candidates || candidates.length === 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];
|
|
78
|
+
const schemaText = maxCandidate.schemaText;
|
|
79
|
+
const parser = new DOMParser();
|
|
80
|
+
const document = parser.parseFromString(schemaText);
|
|
81
|
+
const reader = new SchemaReadHelper(XmlParser, context);
|
|
82
|
+
let schema = new Schema(context);
|
|
83
|
+
schema = reader.readSchemaSync(schema, document);
|
|
84
|
+
return schema;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
88
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
89
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
90
|
+
*/
|
|
91
|
+
fromECv2String(versionString) {
|
|
92
|
+
const [read, minor] = versionString.split(".");
|
|
93
|
+
if (!read)
|
|
94
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The read version is missing from version string, ${versionString}`);
|
|
95
|
+
if (!minor)
|
|
96
|
+
throw new ECObjectsError(ECObjectsStatus.InvalidECVersion, `The minor version is missing from version string, ${versionString}`);
|
|
97
|
+
return new ECVersion(+read, 0, +minor);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=SchemaXmlStringLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaXmlStringLocater.js","sourceRoot":"","sources":["../../src/SchemaXmlStringLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,cAAc,EAAE,eAAe,EAAE,SAAS,EAAkB,MAAM,EAA6B,SAAS,EAAmB,gBAAgB,EAAE,SAAS,GACvJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,uBAAuB,CAAC;AAE7E;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IAE7D;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAClC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,gBAAgB,EAAE,qDAAqD,CAAC,CAAC;QAEpH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAChE,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,gBAAgB,EAAE,+EAA+E,CAAC,CAAC;QAE9I,MAAM,SA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C,CAAC;IACzC,CAAC;CAEF","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 { DOMParser } from \"@xmldom/xmldom\";\nimport {\n ECObjectsError, ECObjectsStatus, ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaReadHelper, XmlParser,\n} from \"@itwin/ecschema-metadata\";\nimport { SchemaStringLocater, StringSchemaKey } from \"./SchemaStringLocater\";\n\n/**\n * A SchemaLocator implementation for locating and deserializing EC Schemas from XML strings\n * loaded in memory.\n * @beta\n */\nexport class SchemaXmlStringLocater extends SchemaStringLocater implements ISchemaLocater {\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 string`);\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 string`);\n\n const ecVersion = ECVersion.fromString(version[1]);\n const key = new SchemaKey(name[1], ecVersion);\n return key;\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public async getSchema(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined> {\n await this.getSchemaInfo(schemaKey, matchType, context);\n\n const schema = await context.getCachedSchema(schemaKey, matchType);\n return schema as Schema;\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(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n const schema = new Schema(context);\n\n return reader.readSchemaInfo(schema, document);\n }\n\n /**\n * Attempts to retrieve a Schema with the given SchemaKey by searching the configured\n * Schema strings.\n * @param key The SchemaKey of the Schema to retrieve.\n * @param matchType The SchemaMatchType.\n * @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n */\n public getSchemaSync(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined {\n // Grab all schema strings that match the schema key\n const candidates: StringSchemaKey[] = this.findEligibleSchemaKeys(schemaKey, matchType);\n if (!candidates || candidates.length === 0)\n return undefined;\n\n const maxCandidate = candidates.sort(this.compareSchemaKeyByVersion)[candidates.length - 1];\n const schemaText = maxCandidate.schemaText;\n\n const parser = new DOMParser();\n const document = parser.parseFromString(schemaText);\n\n const reader = new SchemaReadHelper(XmlParser, context);\n let schema: Schema = new Schema(context);\n schema = reader.readSchemaSync(schema, document);\n\n return schema;\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}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
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. Returns only
|
|
9
|
+
* Schemas from XML files with their keys populated.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class StubSchemaXmlFileLocater extends SchemaFileLocater implements ISchemaLocater {
|
|
13
|
+
/**
|
|
14
|
+
* Loads a Schema from an XML file on the file system.
|
|
15
|
+
* @param schemaPath The path to the Schema file.
|
|
16
|
+
* @param schemaText Optionally pass in the schema text read from the schema file. If undefined,
|
|
17
|
+
* the schema will be read from the provided schemaPath.
|
|
18
|
+
*/
|
|
19
|
+
loadSchema(schemaPath: string, schemaText?: string): Schema;
|
|
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. Returns only Schemas from XML files with
|
|
23
|
+
* their keys populated.
|
|
24
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
25
|
+
* @param matchType The SchemaMatchType.
|
|
26
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
27
|
+
*/
|
|
28
|
+
getSchema(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<Schema | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
|
|
31
|
+
* The fully loaded schema can be gotten later from the context using the getCachedSchema method.
|
|
32
|
+
* @param schemaKey The SchemaKey describing the schema to get from the cache.
|
|
33
|
+
* @param matchType The match type to use when locating the schema
|
|
34
|
+
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
35
|
+
*/
|
|
36
|
+
getSchemaInfo(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Attempts to retrieve a Schema with the given SchemaKey by using the configured search paths
|
|
39
|
+
* to locate the XML Schema file from the file system. Returns only Schemas from XML files with
|
|
40
|
+
* their keys populated.
|
|
41
|
+
* @param key The SchemaKey of the Schema to retrieve.
|
|
42
|
+
* @param matchType The SchemaMatchType.
|
|
43
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
44
|
+
*/
|
|
45
|
+
getSchemaSync(key: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Schema | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Constructs a SchemaKey based on the information in the Schema XML.
|
|
48
|
+
* @param schemaXml The Schema XML as a string.
|
|
49
|
+
*/
|
|
50
|
+
getSchemaKey(schemaXml: string): SchemaKey;
|
|
51
|
+
/**
|
|
52
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
53
|
+
* @param xmlSchemaKey The SchemaKey of the parent Schema containing the references.
|
|
54
|
+
*/
|
|
55
|
+
private getSchemaReferenceKeys;
|
|
56
|
+
/**
|
|
57
|
+
* Adds schemas to the references collection for the given Schema by locating
|
|
58
|
+
* the referenced schemas.
|
|
59
|
+
* @param schema The schema for which to add the references.
|
|
60
|
+
* @param context The SchemaContext that will control the lifetime of the schema.
|
|
61
|
+
* @param refMatchType The SchemaMatchType to use when locating schema references.
|
|
62
|
+
*/
|
|
63
|
+
private addSchemaReferences;
|
|
64
|
+
/**
|
|
65
|
+
* Gets an array of SchemaKeys of the Schemas referenced by the given Schema.
|
|
66
|
+
* @param data The Schema XML string.
|
|
67
|
+
*/
|
|
68
|
+
private _getSchemaReferenceKeys;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the Schema alias from the Schema XML.
|
|
71
|
+
* @param data The Schema XML as a string.
|
|
72
|
+
*/
|
|
73
|
+
private getSchemaAlias;
|
|
74
|
+
/**
|
|
75
|
+
* Parses a valid EC 2.0 version string and returns an ECVersion object. The second digit becomes the minor version,
|
|
76
|
+
* and a zero is inserted as the 'write' digit. Example: "1.1" -> "1.0.1".
|
|
77
|
+
* @param versionString A valid EC 2.0 version string of the format, 'RR.mm'.
|
|
78
|
+
*/
|
|
79
|
+
private fromECv2String;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=StubSchemaXmlFileLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StubSchemaXmlFileLocater.d.ts","sourceRoot":"","sources":["../../src/StubSchemaXmlFileLocater.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,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;AAMvE;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,iBAAkB,YAAW,cAAc;IACvF;;;;;OAKG;IACI,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAiBlE;;;;;;;OAOG;IACU,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIvH;;;;;;QAMI;IACS,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAI/H;;;;;;;OAOG;IACI,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;IAe5G;;;OAGG;IACI,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IAoBjD;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAI9B;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAkC/B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAgBtB;;;;OAIG;IACH,OAAO,CAAC,cAAc;CAWvB"}
|