@itwin/ecschema-rpcinterface-common 5.1.0-dev.9 → 5.2.0-dev.2
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 +61 -1
- package/lib/cjs/ECSchemaRpcLocater.d.ts +1 -1
- package/lib/cjs/ECSchemaRpcLocater.d.ts.map +1 -1
- package/lib/cjs/ECSchemaRpcLocater.js +10 -2
- package/lib/cjs/ECSchemaRpcLocater.js.map +1 -1
- package/lib/cjs/RpcIncrementalSchemaLocater.d.ts +27 -0
- package/lib/cjs/RpcIncrementalSchemaLocater.d.ts.map +1 -0
- package/lib/cjs/RpcIncrementalSchemaLocater.js +55 -0
- package/lib/cjs/RpcIncrementalSchemaLocater.js.map +1 -0
- package/lib/cjs/ecschema-rpc-interface.d.ts +1 -0
- package/lib/cjs/ecschema-rpc-interface.d.ts.map +1 -1
- package/lib/cjs/ecschema-rpc-interface.js +1 -0
- package/lib/cjs/ecschema-rpc-interface.js.map +1 -1
- package/lib/cjs/test/RpcIncrementalSchemaLocater.test.d.ts +2 -0
- package/lib/cjs/test/RpcIncrementalSchemaLocater.test.d.ts.map +1 -0
- package/lib/cjs/test/RpcIncrementalSchemaLocater.test.js +130 -0
- package/lib/cjs/test/RpcIncrementalSchemaLocater.test.js.map +1 -0
- package/lib/esm/ECSchemaRpcLocater.d.ts +1 -1
- package/lib/esm/ECSchemaRpcLocater.d.ts.map +1 -1
- package/lib/esm/ECSchemaRpcLocater.js +10 -2
- package/lib/esm/ECSchemaRpcLocater.js.map +1 -1
- package/lib/esm/RpcIncrementalSchemaLocater.d.ts +27 -0
- package/lib/esm/RpcIncrementalSchemaLocater.d.ts.map +1 -0
- package/lib/esm/RpcIncrementalSchemaLocater.js +51 -0
- package/lib/esm/RpcIncrementalSchemaLocater.js.map +1 -0
- package/lib/esm/ecschema-rpc-interface.d.ts +1 -0
- package/lib/esm/ecschema-rpc-interface.d.ts.map +1 -1
- package/lib/esm/ecschema-rpc-interface.js +1 -0
- package/lib/esm/ecschema-rpc-interface.js.map +1 -1
- package/lib/esm/test/RpcIncrementalSchemaLocater.test.d.ts +2 -0
- package/lib/esm/test/RpcIncrementalSchemaLocater.test.d.ts.map +1 -0
- package/lib/esm/test/RpcIncrementalSchemaLocater.test.js +128 -0
- package/lib/esm/test/RpcIncrementalSchemaLocater.test.js.map +1 -0
- package/package.json +20 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
# Change Log - @itwin/ecschema-rpcinterface-common
|
|
2
2
|
|
|
3
|
-
This log was last generated on Wed,
|
|
3
|
+
This log was last generated on Wed, 06 Aug 2025 15:37:23 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.0.5
|
|
6
|
+
Wed, 06 Aug 2025 15:34:15 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 5.0.4
|
|
11
|
+
Wed, 16 Jul 2025 14:59:59 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 5.0.3
|
|
16
|
+
Fri, 11 Jul 2025 00:56:56 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 5.0.2
|
|
21
|
+
Thu, 26 Jun 2025 22:16:01 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 5.0.1
|
|
26
|
+
Tue, 17 Jun 2025 18:33:52 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 5.0.0
|
|
31
|
+
Fri, 13 Jun 2025 20:25:38 GMT
|
|
32
|
+
|
|
33
|
+
### Updates
|
|
34
|
+
|
|
35
|
+
- Deprecated `getSchemaSync` method from ECSchemaRpcLocater.
|
|
36
|
+
- Add ESM build
|
|
37
|
+
- Upgrade compile target to ES2023 and module to ES2022
|
|
38
|
+
- applied changes in ecschema-metadatas SchemaLocater interface
|
|
39
|
+
|
|
40
|
+
## 4.11.6
|
|
41
|
+
Mon, 16 Jun 2025 15:00:15 GMT
|
|
42
|
+
|
|
43
|
+
_Version update only_
|
|
44
|
+
|
|
45
|
+
## 4.11.5
|
|
46
|
+
Fri, 06 Jun 2025 13:41:18 GMT
|
|
47
|
+
|
|
48
|
+
_Version update only_
|
|
49
|
+
|
|
50
|
+
## 4.11.4
|
|
51
|
+
Tue, 03 Jun 2025 16:15:19 GMT
|
|
52
|
+
|
|
53
|
+
_Version update only_
|
|
54
|
+
|
|
55
|
+
## 4.11.3
|
|
56
|
+
Wed, 28 May 2025 13:56:23 GMT
|
|
57
|
+
|
|
58
|
+
_Version update only_
|
|
59
|
+
|
|
60
|
+
## 4.11.2
|
|
61
|
+
Tue, 20 May 2025 20:14:46 GMT
|
|
62
|
+
|
|
63
|
+
_Version update only_
|
|
4
64
|
|
|
5
65
|
## 4.11.1
|
|
6
66
|
Wed, 30 Apr 2025 13:13:21 GMT
|
|
@@ -29,7 +29,7 @@ export declare class ECSchemaRpcLocater implements ISchemaLocater {
|
|
|
29
29
|
* @param _matchType How to match key against candidate schemas
|
|
30
30
|
* @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
31
31
|
* @throws Error Always throws an error indicating this method is not supported.
|
|
32
|
-
* @deprecated in 5.0 Use the asynchronous `getSchema` method for schema retrieval.
|
|
32
|
+
* @deprecated in 5.0. Use the asynchronous `getSchema` method for schema retrieval.
|
|
33
33
|
*/
|
|
34
34
|
getSchemaSync(_schemaKey: SchemaKey, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECSchemaRpcLocater.d.ts","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"ECSchemaRpcLocater.d.ts","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAe,MAAM,0BAA0B,CAAC;AACtI,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,gBAAgB;IAChB,SAAgB,KAAK,EAAE,cAAc,CAAC;gBAE1B,KAAK,EAAE,cAAc;IAEjC;;;;;MAKE;IACW,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAO7H;;;;;QAKI;IACS,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAiBrI;;;;;;;;MAQE;IACK,aAAa,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;CAGtH"}
|
|
@@ -33,7 +33,15 @@ class ECSchemaRpcLocater {
|
|
|
33
33
|
* @param matchType The match type to use when locating the schema
|
|
34
34
|
*/
|
|
35
35
|
async getSchemaInfo(schemaKey, matchType, context) {
|
|
36
|
-
|
|
36
|
+
let schemaJson;
|
|
37
|
+
try {
|
|
38
|
+
schemaJson = await ECSchemaRpcInterface_1.ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (e.message && e.message === "schema not found")
|
|
42
|
+
return undefined;
|
|
43
|
+
throw (e);
|
|
44
|
+
}
|
|
37
45
|
const schemaInfo = await ecschema_metadata_1.Schema.startLoadingFromJson(schemaJson, context || new ecschema_metadata_1.SchemaContext());
|
|
38
46
|
if (schemaInfo !== undefined && schemaInfo.schemaKey.matches(schemaKey, matchType)) {
|
|
39
47
|
return schemaInfo;
|
|
@@ -47,7 +55,7 @@ class ECSchemaRpcLocater {
|
|
|
47
55
|
* @param _matchType How to match key against candidate schemas
|
|
48
56
|
* @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
49
57
|
* @throws Error Always throws an error indicating this method is not supported.
|
|
50
|
-
* @deprecated in 5.0 Use the asynchronous `getSchema` method for schema retrieval.
|
|
58
|
+
* @deprecated in 5.0. Use the asynchronous `getSchema` method for schema retrieval.
|
|
51
59
|
*/
|
|
52
60
|
getSchemaSync(_schemaKey, _matchType, _context) {
|
|
53
61
|
throw new Error("getSchemaSync is not supported. Use the asynchronous getSchema method instead.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECSchemaRpcLocater.js","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"ECSchemaRpcLocater.js","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAsI;AAEtI,iEAA8D;AAE9D;;;GAGG;AACH,MAAa,kBAAkB;IAC7B,gBAAgB;IACA,KAAK,CAAiB;IAEtC,YAAY,KAAqB,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IAE1D;;;;;MAKE;IACK,KAAK,CAAC,SAAS,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QAC7F,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAExD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACnE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;QAKI;IACG,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QACjG,IAAI,UAAuB,CAAC;QAC5B,IAAI,CAAC;YACH,UAAU,GAAG,MAAM,2CAAoB,CAAC,SAAS,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QAChG,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,kBAAkB;gBAC/C,OAAO,SAAS,CAAC;YAEnB,MAAK,CAAC,CAAC,CAAC,CAAC;QACX,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,0BAAM,CAAC,oBAAoB,CAAC,UAAU,EAAE,OAAO,IAAI,IAAI,iCAAa,EAAE,CAAC,CAAC;QACjG,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YACnF,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;;MAQE;IACK,aAAa,CAAC,UAAqB,EAAE,UAA2B,EAAE,QAAuB;QAC9F,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACpG,CAAC;CACF;AAtDD,gDAsDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaProps } from \"@itwin/ecschema-metadata\";\nimport { IModelRpcProps } from \"@itwin/core-common\";\nimport { ECSchemaRpcInterface } from \"./ECSchemaRpcInterface\";\n\n/**\n * Defines a schema locater that retrieves schemas using an RPC interface.\n * @public @preview\n */\nexport class ECSchemaRpcLocater implements ISchemaLocater {\n /** @internal */\n public readonly token: IModelRpcProps;\n\n constructor(token: IModelRpcProps) { this.token = token; }\n\n /**\n * Attempts to get a schema from the schema rpc locater. Yields undefined if no matching schema is found.\n * @param schemaKey Key to look up\n * @param matchType How to match key against candidate schemas\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;\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 accessed via the schema 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 */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n let schemaJson: SchemaProps;\n try {\n schemaJson = await ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name);\n } catch(e: any) {\n if (e.message && e.message === \"schema not found\")\n return undefined;\n\n throw(e);\n }\n const schemaInfo = await Schema.startLoadingFromJson(schemaJson, context || new SchemaContext());\n if (schemaInfo !== undefined && schemaInfo.schemaKey.matches(schemaKey, matchType)) {\n return schemaInfo;\n }\n return undefined;\n }\n\n /**\n * This method is not supported for locating schemas over RPC/HTTP.\n * Use the asynchronous `getSchema` method instead.\n * @param _schemaKey Key to look up\n * @param _matchType How to match key against candidate schemas\n * @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n * @throws Error Always throws an error indicating this method is not supported.\n * @deprecated in 5.0. Use the asynchronous `getSchema` method for schema retrieval.\n */\n public getSchemaSync(_schemaKey: SchemaKey, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined {\n throw new Error(\"getSchemaSync is not supported. Use the asynchronous getSchema method instead.\");\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type IModelRpcProps } from "@itwin/core-common";
|
|
2
|
+
import { ECSqlQueryOptions, ECSqlSchemaLocater, ECSqlSchemaLocaterOptions, SchemaKey, SchemaProps } from "@itwin/ecschema-metadata";
|
|
3
|
+
/**
|
|
4
|
+
* A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the ECSchema RPC interfaces to load schemas incrementally.
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export declare class RpcIncrementalSchemaLocater extends ECSqlSchemaLocater {
|
|
8
|
+
private readonly _iModelProps;
|
|
9
|
+
/**
|
|
10
|
+
* Initializes a new instance of the RpcIncrementalSchemaLocater class.
|
|
11
|
+
*/
|
|
12
|
+
constructor(iModelProps: IModelRpcProps, options?: ECSqlSchemaLocaterOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Executes the given ECSql query and returns the resulting rows.
|
|
15
|
+
* @param query The ECSql query to execute.
|
|
16
|
+
* @param options Optional arguments to control the query result.
|
|
17
|
+
* @returns A promise that resolves to the resulting rows.
|
|
18
|
+
*/
|
|
19
|
+
protected executeQuery<TRow>(query: string, options?: ECSqlQueryOptions): Promise<ReadonlyArray<TRow>>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata).
|
|
22
|
+
* This is the full schema json with all elements that are defined in the schema.
|
|
23
|
+
* @param schemaKey The schema key of the schema to be resolved.
|
|
24
|
+
*/
|
|
25
|
+
protected getSchemaProps(schemaKey: SchemaKey): Promise<SchemaProps | undefined>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=RpcIncrementalSchemaLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.d.ts","sourceRoot":"","sources":["../../src/RpcIncrementalSchemaLocater.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2F,KAAK,cAAc,EAA6C,MAAM,oBAAoB,CAAC;AAC7L,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGpI;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,kBAAkB;IACjE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiB;IAE9C;;OAEG;gBACS,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAK5E;;;;;OAKG;cACsB,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAiBrH;;;;OAIG;cACa,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;CAIvF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RpcIncrementalSchemaLocater = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
const core_common_1 = require("@itwin/core-common");
|
|
9
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
10
|
+
const ECSchemaRpcInterface_1 = require("./ECSchemaRpcInterface");
|
|
11
|
+
/**
|
|
12
|
+
* A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the ECSchema RPC interfaces to load schemas incrementally.
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
class RpcIncrementalSchemaLocater extends ecschema_metadata_1.ECSqlSchemaLocater {
|
|
16
|
+
_iModelProps;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a new instance of the RpcIncrementalSchemaLocater class.
|
|
19
|
+
*/
|
|
20
|
+
constructor(iModelProps, options) {
|
|
21
|
+
super(options);
|
|
22
|
+
this._iModelProps = iModelProps;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes the given ECSql query and returns the resulting rows.
|
|
26
|
+
* @param query The ECSql query to execute.
|
|
27
|
+
* @param options Optional arguments to control the query result.
|
|
28
|
+
* @returns A promise that resolves to the resulting rows.
|
|
29
|
+
*/
|
|
30
|
+
async executeQuery(query, options) {
|
|
31
|
+
const ecSqlQueryClient = core_common_1.IModelReadRpcInterface.getClient();
|
|
32
|
+
const queryExecutor = {
|
|
33
|
+
execute: async (request) => ecSqlQueryClient.queryRows(this._iModelProps, request),
|
|
34
|
+
};
|
|
35
|
+
const queryOptions = {
|
|
36
|
+
limit: { count: options?.limit },
|
|
37
|
+
rowFormat: core_common_1.QueryRowFormat.UseECSqlPropertyNames,
|
|
38
|
+
};
|
|
39
|
+
const queryParameters = options && options.parameters ? core_common_1.QueryBinder.from(options.parameters) : undefined;
|
|
40
|
+
const queryReader = new core_common_1.ECSqlReader(queryExecutor, query, queryParameters, queryOptions);
|
|
41
|
+
return queryReader.toArray();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata).
|
|
45
|
+
* This is the full schema json with all elements that are defined in the schema.
|
|
46
|
+
* @param schemaKey The schema key of the schema to be resolved.
|
|
47
|
+
*/
|
|
48
|
+
async getSchemaProps(schemaKey) {
|
|
49
|
+
const rpcSchemaClient = ECSchemaRpcInterface_1.ECSchemaRpcInterface.getClient();
|
|
50
|
+
return rpcSchemaClient.getSchemaJSON(this._iModelProps, schemaKey.name);
|
|
51
|
+
}
|
|
52
|
+
;
|
|
53
|
+
}
|
|
54
|
+
exports.RpcIncrementalSchemaLocater = RpcIncrementalSchemaLocater;
|
|
55
|
+
//# sourceMappingURL=RpcIncrementalSchemaLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.js","sourceRoot":"","sources":["../../src/RpcIncrementalSchemaLocater.ts"],"names":[],"mappings":";;;AAAA;;;gGAGgG;AAChG,oDAA6L;AAC7L,gEAAoI;AACpI,iEAA8D;AAE9D;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,sCAAkB;IAChD,YAAY,CAAiB;IAE9C;;OAEG;IACH,YAAY,WAA2B,EAAE,OAAmC;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACgB,KAAK,CAAC,YAAY,CAAO,KAAa,EAAE,OAA2B;QACpF,MAAM,gBAAgB,GAAG,oCAAsB,CAAC,SAAS,EAAE,CAAC;QAC5D,MAAM,aAAa,GAAuD;YACxE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC;SACnF,CAAC;QAEF,MAAM,YAAY,GAAiB;YACjC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAChC,SAAS,EAAE,4BAAc,CAAC,qBAAqB;SAChD,CAAC;QAEF,MAAM,eAAe,GAAG,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAW,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzG,MAAM,WAAW,GAAG,IAAI,yBAAW,CAAC,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;QAEzF,OAAO,WAAW,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,cAAc,CAAC,SAAoB;QACjD,MAAM,eAAe,GAAG,2CAAoB,CAAC,SAAS,EAAE,CAAC;QACzD,OAAO,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;IAAA,CAAC;CACH;AA3CD,kEA2CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nimport { DbQueryRequest, DbQueryResponse, DbRequestExecutor, ECSqlReader, IModelReadRpcInterface, type IModelRpcProps, QueryBinder, QueryOptions, QueryRowFormat } from \"@itwin/core-common\";\nimport { ECSqlQueryOptions, ECSqlSchemaLocater, ECSqlSchemaLocaterOptions, SchemaKey, SchemaProps } from \"@itwin/ecschema-metadata\";\nimport { ECSchemaRpcInterface } from \"./ECSchemaRpcInterface\";\n\n/**\n * A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the ECSchema RPC interfaces to load schemas incrementally.\n * @beta\n */\nexport class RpcIncrementalSchemaLocater extends ECSqlSchemaLocater {\n private readonly _iModelProps: IModelRpcProps;\n\n /**\n * Initializes a new instance of the RpcIncrementalSchemaLocater class.\n */\n constructor(iModelProps: IModelRpcProps, options?: ECSqlSchemaLocaterOptions) {\n super(options);\n this._iModelProps = iModelProps;\n }\n\n /**\n * Executes the given ECSql query and returns the resulting rows.\n * @param query The ECSql query to execute.\n * @param options Optional arguments to control the query result.\n * @returns A promise that resolves to the resulting rows.\n */\n protected override async executeQuery<TRow>(query: string, options?: ECSqlQueryOptions): Promise<ReadonlyArray<TRow>> {\n const ecSqlQueryClient = IModelReadRpcInterface.getClient();\n const queryExecutor: DbRequestExecutor<DbQueryRequest, DbQueryResponse> = {\n execute: async (request) => ecSqlQueryClient.queryRows(this._iModelProps, request),\n };\n\n const queryOptions: QueryOptions = {\n limit: { count: options?.limit },\n rowFormat: QueryRowFormat.UseECSqlPropertyNames,\n };\n\n const queryParameters = options && options.parameters ? QueryBinder.from(options.parameters) : undefined;\n const queryReader = new ECSqlReader(queryExecutor, query, queryParameters, queryOptions);\n\n return queryReader.toArray();\n }\n\n /**\n * Gets the [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata).\n * This is the full schema json with all elements that are defined in the schema.\n * @param schemaKey The schema key of the schema to be resolved.\n */\n protected async getSchemaProps(schemaKey: SchemaKey): Promise<SchemaProps | undefined> {\n const rpcSchemaClient = ECSchemaRpcInterface.getClient();\n return rpcSchemaClient.getSchemaJSON(this._iModelProps, schemaKey.name);\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-rpc-interface.d.ts","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"ecschema-rpc-interface.d.ts","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC"}
|
|
@@ -20,4 +20,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
*--------------------------------------------------------------------------------------------*/
|
|
21
21
|
__exportStar(require("./ECSchemaRpcInterface"), exports);
|
|
22
22
|
__exportStar(require("./ECSchemaRpcLocater"), exports);
|
|
23
|
+
__exportStar(require("./RpcIncrementalSchemaLocater"), exports);
|
|
23
24
|
//# sourceMappingURL=ecschema-rpc-interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-rpc-interface.js","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,yDAAuC;AACvC,uDAAqC","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*--------------------------------------------------------------------------------------------*/\nexport * from \"./ECSchemaRpcInterface\";\nexport * from \"./ECSchemaRpcLocater\";\
|
|
1
|
+
{"version":3,"file":"ecschema-rpc-interface.js","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,yDAAuC;AACvC,uDAAqC;AACrC,gEAA8C","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*--------------------------------------------------------------------------------------------*/\nexport * from \"./ECSchemaRpcInterface\";\nexport * from \"./ECSchemaRpcLocater\";\nexport * from \"./RpcIncrementalSchemaLocater\";"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.test.d.ts","sourceRoot":"","sources":["../../../src/test/RpcIncrementalSchemaLocater.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
5
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
|
7
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
8
|
+
const RpcIncrementalSchemaLocater_1 = require("../RpcIncrementalSchemaLocater");
|
|
9
|
+
const core_common_1 = require("@itwin/core-common");
|
|
10
|
+
const ECSchemaRpcInterface_1 = require("../ECSchemaRpcInterface");
|
|
11
|
+
const chai_1 = require("chai");
|
|
12
|
+
const sinon = require("sinon");
|
|
13
|
+
// RpcIncrementalSchemaLocater derives from IncrementalSchemaLocater and ECSqlSchemaLocater, so
|
|
14
|
+
// the basic functionality is already tested in their tests. This test suite verifies the expected
|
|
15
|
+
// behaviour of the RPC specific implementation.
|
|
16
|
+
describe("RpcIncrementalSchemaLocater Tests", () => {
|
|
17
|
+
let imodelReadInterface;
|
|
18
|
+
let ecschemaRpcInterface;
|
|
19
|
+
const schemaInfoColumns = ["name", "version", "references", "alias"];
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
sinon.stub(core_common_1.IModelReadRpcInterface, "getClient").returns(imodelReadInterface = {
|
|
22
|
+
queryRows: async () => { throw new Error("Method must be implemented in the tests."); },
|
|
23
|
+
});
|
|
24
|
+
sinon.stub(ECSchemaRpcInterface_1.ECSchemaRpcInterface, "getClient").returns(ecschemaRpcInterface = {
|
|
25
|
+
getSchemaJSON: async () => { throw new Error("Method must be implemented in the tests."); },
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
sinon.restore();
|
|
30
|
+
});
|
|
31
|
+
it("get schema info, schema found", async () => {
|
|
32
|
+
const schemaKey = ecschema_metadata_1.SchemaKey.parseString("TestSchema.1.0.0");
|
|
33
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, [
|
|
34
|
+
{ name: schemaKey.name, version: schemaKey.version.toString(), references: "[]", alias: "ts" }
|
|
35
|
+
]));
|
|
36
|
+
const locater = new RpcIncrementalSchemaLocater_1.RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
37
|
+
const schemaInfo = await locater.getSchemaInfo(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest, new ecschema_metadata_1.SchemaContext());
|
|
38
|
+
(0, chai_1.expect)(schemaInfo).is.not.undefined;
|
|
39
|
+
(0, chai_1.expect)(schemaInfo).has.property("schemaKey").that.satisfies((key) => key.matches(schemaKey));
|
|
40
|
+
(0, chai_1.expect)(schemaInfo).has.property("alias").that.equals("ts");
|
|
41
|
+
(0, chai_1.expect)(schemaInfo).has.property("references").that.is.empty;
|
|
42
|
+
});
|
|
43
|
+
it("get schema info, schema not found, return undefined", async () => {
|
|
44
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, []));
|
|
45
|
+
const schemaKey = ecschema_metadata_1.SchemaKey.parseString("TestSchema.1.0.0");
|
|
46
|
+
const locater = new RpcIncrementalSchemaLocater_1.RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
47
|
+
const schemaInfo = await locater.getSchemaInfo(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest, new ecschema_metadata_1.SchemaContext());
|
|
48
|
+
(0, chai_1.expect)(schemaInfo).to.be.undefined;
|
|
49
|
+
});
|
|
50
|
+
it("get schema, incrementally", async () => {
|
|
51
|
+
const context = new ecschema_metadata_1.SchemaContext();
|
|
52
|
+
const locater = new RpcIncrementalSchemaLocater_1.RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
53
|
+
context.addLocater(locater);
|
|
54
|
+
const schemaKey = ecschema_metadata_1.SchemaKey.parseString("TestSchema.1.0.0");
|
|
55
|
+
sinon.stub(imodelReadInterface, "queryRows")
|
|
56
|
+
.onCall(0).returns(toQueryResult(schemaInfoColumns, [
|
|
57
|
+
{ name: schemaKey.name, version: schemaKey.version.toString(), references: "[]", alias: "ts" },
|
|
58
|
+
{ name: "ECDbMeta", version: "4.0.3", references: "[]", alias: "ecdb" },
|
|
59
|
+
]))
|
|
60
|
+
.onCall(1).returns(toQueryResult(["name", "version", "alias", "references", "items"], [
|
|
61
|
+
{
|
|
62
|
+
name: schemaKey.name,
|
|
63
|
+
version: schemaKey.version.toString(),
|
|
64
|
+
alias: "ts",
|
|
65
|
+
references: "[]",
|
|
66
|
+
items: "[]",
|
|
67
|
+
}
|
|
68
|
+
]))
|
|
69
|
+
.returns(toQueryResult(["schema", "items"], [
|
|
70
|
+
{
|
|
71
|
+
schema: `{
|
|
72
|
+
"name": "${schemaKey.name}",
|
|
73
|
+
"version": "${schemaKey.version.toString()}",
|
|
74
|
+
"alias": "ts",
|
|
75
|
+
"label": "Test Schema",
|
|
76
|
+
"description": "This is a test schema."
|
|
77
|
+
}`,
|
|
78
|
+
}
|
|
79
|
+
]));
|
|
80
|
+
const schema = await context.getSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest);
|
|
81
|
+
(0, chai_1.expect)(schema).is.not.undefined;
|
|
82
|
+
(0, chai_1.expect)(schema).has.property("schemaKey").that.satisfies((key) => key.matches(schemaKey));
|
|
83
|
+
(0, chai_1.expect)(schema).has.property("alias").that.equals("ts");
|
|
84
|
+
(0, chai_1.expect)(schema).has.property("loadingController").that.is.not.undefined;
|
|
85
|
+
(0, chai_1.expect)(schema).has.a.nested.property("loadingController.inProgress").that.is.true;
|
|
86
|
+
await schema.loadingController?.wait();
|
|
87
|
+
(0, chai_1.expect)(schema).has.property("label", "Test Schema");
|
|
88
|
+
(0, chai_1.expect)(schema).has.property("description", "This is a test schema.");
|
|
89
|
+
});
|
|
90
|
+
it("get schema, unsupported metaschema", async () => {
|
|
91
|
+
const schemaKey = ecschema_metadata_1.SchemaKey.parseString("TestSchema.1.0.0");
|
|
92
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, [
|
|
93
|
+
{ name: schemaKey.name, version: schemaKey.version.toString(), references: "[]", alias: "ts" },
|
|
94
|
+
{ name: "ECDbMeta", version: "4.0.1", references: "[]", alias: "ecdb" },
|
|
95
|
+
]));
|
|
96
|
+
sinon.stub(ecschemaRpcInterface, "getSchemaJSON").returns(Promise.resolve({
|
|
97
|
+
$schema: ecschema_metadata_1.ECSchemaNamespaceUris.SCHEMAURL3_2_JSON,
|
|
98
|
+
name: schemaKey.name,
|
|
99
|
+
version: schemaKey.version.toString(),
|
|
100
|
+
alias: "ts"
|
|
101
|
+
}));
|
|
102
|
+
const locater = new RpcIncrementalSchemaLocater_1.RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
103
|
+
const schema = await locater.getSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest, new ecschema_metadata_1.SchemaContext());
|
|
104
|
+
(0, chai_1.expect)(schema).is.not.undefined;
|
|
105
|
+
(0, chai_1.expect)(schema).has.property("schemaKey").that.satisfies((key) => key.matches(schemaKey));
|
|
106
|
+
(0, chai_1.expect)(schema).has.property("alias").that.equals("ts");
|
|
107
|
+
});
|
|
108
|
+
it("get schema, schema not found, return undefined", async () => {
|
|
109
|
+
const schemaKey = ecschema_metadata_1.SchemaKey.parseString("TestSchema.1.0.0");
|
|
110
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, []));
|
|
111
|
+
const locater = new RpcIncrementalSchemaLocater_1.RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
112
|
+
const schema = await locater.getSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest, new ecschema_metadata_1.SchemaContext());
|
|
113
|
+
(0, chai_1.expect)(schema).is.undefined;
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* This is a very simple helper function to translate a set of rows into a DbQueryResponse.
|
|
118
|
+
* It does not handle different row formats or property order.
|
|
119
|
+
*/
|
|
120
|
+
async function toQueryResult(columns, rows) {
|
|
121
|
+
return {
|
|
122
|
+
kind: core_common_1.DbResponseKind.ECSql,
|
|
123
|
+
status: core_common_1.DbResponseStatus.Done,
|
|
124
|
+
stats: {},
|
|
125
|
+
rowCount: rows.length,
|
|
126
|
+
meta: columns.map((column, i) => ({ name: column, jsonName: column, index: i })),
|
|
127
|
+
data: rows.map(row => columns.map(k => row[k])),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=RpcIncrementalSchemaLocater.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.test.js","sourceRoot":"","sources":["../../../src/test/RpcIncrementalSchemaLocater.test.ts"],"names":[],"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,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD,CAAC;AACJ,CAAC","sourcesContent":["\n/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { ECSchemaNamespaceUris, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { RpcIncrementalSchemaLocater } from \"../RpcIncrementalSchemaLocater\";\nimport { DbQueryResponse, DbResponseKind, DbResponseStatus, IModelReadRpcInterface } from \"@itwin/core-common\";\nimport { ECSchemaRpcInterface } from \"../ECSchemaRpcInterface\";\nimport { expect } from \"chai\";\nimport * as sinon from \"sinon\";\n\n// RpcIncrementalSchemaLocater derives from IncrementalSchemaLocater and ECSqlSchemaLocater, so\n// the basic functionality is already tested in their tests. This test suite verifies the expected\n// behaviour of the RPC specific implementation.\ndescribe(\"RpcIncrementalSchemaLocater Tests\", () => {\n\n let imodelReadInterface: IModelReadRpcInterface;\n let ecschemaRpcInterface: ECSchemaRpcInterface;\n\n const schemaInfoColumns = [\"name\", \"version\", \"references\", \"alias\"];\n\n beforeEach(() => {\n sinon.stub(IModelReadRpcInterface, \"getClient\").returns(imodelReadInterface = {\n queryRows: async () => { throw new Error(\"Method must be implemented in the tests.\"); },\n } as any);\n sinon.stub(ECSchemaRpcInterface, \"getClient\").returns(ecschemaRpcInterface = {\n getSchemaJSON: async () => { throw new Error(\"Method must be implemented in the tests.\"); },\n } as any);\n });\n\n afterEach(() => {\n sinon.restore();\n });\n\n it(\"get schema info, schema found\", async () => {\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, [\n { name: schemaKey.name, version: schemaKey.version.toString(), references: \"[]\", alias: \"ts\" }\n ]));\n\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schemaInfo = await locater.getSchemaInfo(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schemaInfo).is.not.undefined;\n expect(schemaInfo).has.property(\"schemaKey\").that.satisfies((key: SchemaKey) => key.matches(schemaKey));\n expect(schemaInfo).has.property(\"alias\").that.equals(\"ts\");\n expect(schemaInfo).has.property(\"references\").that.is.empty;\n });\n\n it(\"get schema info, schema not found, return undefined\", async () => {\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, []));\n\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schemaInfo = await locater.getSchemaInfo(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schemaInfo).to.be.undefined;\n });\n\n it(\"get schema, incrementally\", async () => {\n const context = new SchemaContext();\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n context.addLocater(locater);\n\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\")\n .onCall(0).returns(toQueryResult(schemaInfoColumns, [\n { name: schemaKey.name, version: schemaKey.version.toString(), references: \"[]\", alias: \"ts\" },\n { name: \"ECDbMeta\", version: \"4.0.3\", references: \"[]\", alias: \"ecdb\" },\n ]))\n .onCall(1).returns(toQueryResult([\"name\", \"version\", \"alias\", \"references\", \"items\"], [\n {\n name: schemaKey.name,\n version: schemaKey.version.toString(),\n alias: \"ts\",\n references: \"[]\",\n items: \"[]\",\n }\n ]))\n .returns(toQueryResult([\"schema\", \"items\"], [\n {\n schema: `{\n \"name\": \"${schemaKey.name}\",\n \"version\": \"${schemaKey.version.toString()}\",\n \"alias\": \"ts\",\n \"label\": \"Test Schema\",\n \"description\": \"This is a test schema.\"\n }`,\n }\n ]));\n\n const schema = await context.getSchema(schemaKey, SchemaMatchType.Latest);\n\n expect(schema).is.not.undefined;\n expect(schema).has.property(\"schemaKey\").that.satisfies((key: SchemaKey) => key.matches(schemaKey));\n expect(schema).has.property(\"alias\").that.equals(\"ts\");\n\n expect(schema).has.property(\"loadingController\").that.is.not.undefined;\n expect(schema).has.a.nested.property(\"loadingController.inProgress\").that.is.true;\n await schema!.loadingController?.wait();\n\n expect(schema).has.property(\"label\", \"Test Schema\");\n expect(schema).has.property(\"description\", \"This is a test schema.\");\n });\n\n it(\"get schema, unsupported metaschema\", async () => {\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, [\n { name: schemaKey.name, version: schemaKey.version.toString(), references: \"[]\", alias: \"ts\" },\n { name: \"ECDbMeta\", version: \"4.0.1\", references: \"[]\", alias: \"ecdb\" },\n ]));\n\n sinon.stub(ecschemaRpcInterface, \"getSchemaJSON\").returns(Promise.resolve({\n $schema: ECSchemaNamespaceUris.SCHEMAURL3_2_JSON,\n name: schemaKey.name,\n version: schemaKey.version.toString(),\n alias: \"ts\"\n }));\n\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schema = await locater.getSchema(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schema).is.not.undefined;\n expect(schema).has.property(\"schemaKey\").that.satisfies((key: SchemaKey) => key.matches(schemaKey));\n expect(schema).has.property(\"alias\").that.equals(\"ts\");\n });\n\n it(\"get schema, schema not found, return undefined\", async () => {\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, []));\n\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schema = await locater.getSchema(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schema).is.undefined;\n });\n});\n\n/**\n * This is a very simple helper function to translate a set of rows into a DbQueryResponse.\n * It does not handle different row formats or property order.\n */\nasync function toQueryResult(columns: Array<string>, rows: Array<{ [column: string]: any }>): Promise<DbQueryResponse> {\n return {\n kind: DbResponseKind.ECSql,\n status: DbResponseStatus.Done,\n stats: {} as any,\n rowCount: rows.length,\n meta: columns.map((column, i) => ({ name: column, jsonName: column, index: i } as any)),\n data: rows.map(row => columns.map(k => row[k])),\n };\n}"]}
|
|
@@ -29,7 +29,7 @@ export declare class ECSchemaRpcLocater implements ISchemaLocater {
|
|
|
29
29
|
* @param _matchType How to match key against candidate schemas
|
|
30
30
|
* @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
31
31
|
* @throws Error Always throws an error indicating this method is not supported.
|
|
32
|
-
* @deprecated in 5.0 Use the asynchronous `getSchema` method for schema retrieval.
|
|
32
|
+
* @deprecated in 5.0. Use the asynchronous `getSchema` method for schema retrieval.
|
|
33
33
|
*/
|
|
34
34
|
getSchemaSync(_schemaKey: SchemaKey, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECSchemaRpcLocater.d.ts","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"ECSchemaRpcLocater.d.ts","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAe,MAAM,0BAA0B,CAAC;AACtI,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,gBAAgB;IAChB,SAAgB,KAAK,EAAE,cAAc,CAAC;gBAE1B,KAAK,EAAE,cAAc;IAEjC;;;;;MAKE;IACW,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAO7H;;;;;QAKI;IACS,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAiBrI;;;;;;;;MAQE;IACK,aAAa,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS;CAGtH"}
|
|
@@ -30,7 +30,15 @@ export class ECSchemaRpcLocater {
|
|
|
30
30
|
* @param matchType The match type to use when locating the schema
|
|
31
31
|
*/
|
|
32
32
|
async getSchemaInfo(schemaKey, matchType, context) {
|
|
33
|
-
|
|
33
|
+
let schemaJson;
|
|
34
|
+
try {
|
|
35
|
+
schemaJson = await ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (e.message && e.message === "schema not found")
|
|
39
|
+
return undefined;
|
|
40
|
+
throw (e);
|
|
41
|
+
}
|
|
34
42
|
const schemaInfo = await Schema.startLoadingFromJson(schemaJson, context || new SchemaContext());
|
|
35
43
|
if (schemaInfo !== undefined && schemaInfo.schemaKey.matches(schemaKey, matchType)) {
|
|
36
44
|
return schemaInfo;
|
|
@@ -44,7 +52,7 @@ export class ECSchemaRpcLocater {
|
|
|
44
52
|
* @param _matchType How to match key against candidate schemas
|
|
45
53
|
* @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
|
|
46
54
|
* @throws Error Always throws an error indicating this method is not supported.
|
|
47
|
-
* @deprecated in 5.0 Use the asynchronous `getSchema` method for schema retrieval.
|
|
55
|
+
* @deprecated in 5.0. Use the asynchronous `getSchema` method for schema retrieval.
|
|
48
56
|
*/
|
|
49
57
|
getSchemaSync(_schemaKey, _matchType, _context) {
|
|
50
58
|
throw new Error("getSchemaSync is not supported. Use the asynchronous getSchema method instead.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ECSchemaRpcLocater.js","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAkB,MAAM,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"ECSchemaRpcLocater.js","sourceRoot":"","sources":["../../src/ECSchemaRpcLocater.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAkB,MAAM,EAAE,aAAa,EAAuD,MAAM,0BAA0B,CAAC;AAEtI,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC7B,gBAAgB;IACA,KAAK,CAAiB;IAEtC,YAAY,KAAqB,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IAE1D;;;;;MAKE;IACK,KAAK,CAAC,SAAS,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QAC7F,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAExD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACnE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;QAKI;IACG,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,SAA0B,EAAE,OAAsB;QACjG,IAAI,UAAuB,CAAC;QAC5B,IAAI,CAAC;YACH,UAAU,GAAG,MAAM,oBAAoB,CAAC,SAAS,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QAChG,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,kBAAkB;gBAC/C,OAAO,SAAS,CAAC;YAEnB,MAAK,CAAC,CAAC,CAAC,CAAC;QACX,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,UAAU,EAAE,OAAO,IAAI,IAAI,aAAa,EAAE,CAAC,CAAC;QACjG,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YACnF,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;;MAQE;IACK,aAAa,CAAC,UAAqB,EAAE,UAA2B,EAAE,QAAuB;QAC9F,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACpG,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*--------------------------------------------------------------------------------------------*/\nimport { ISchemaLocater, Schema, SchemaContext, SchemaInfo, SchemaKey, SchemaMatchType, SchemaProps } from \"@itwin/ecschema-metadata\";\nimport { IModelRpcProps } from \"@itwin/core-common\";\nimport { ECSchemaRpcInterface } from \"./ECSchemaRpcInterface\";\n\n/**\n * Defines a schema locater that retrieves schemas using an RPC interface.\n * @public @preview\n */\nexport class ECSchemaRpcLocater implements ISchemaLocater {\n /** @internal */\n public readonly token: IModelRpcProps;\n\n constructor(token: IModelRpcProps) { this.token = token; }\n\n /**\n * Attempts to get a schema from the schema rpc locater. Yields undefined if no matching schema is found.\n * @param schemaKey Key to look up\n * @param matchType How to match key against candidate schemas\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;\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 accessed via the schema 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 */\n public async getSchemaInfo(schemaKey: SchemaKey, matchType: SchemaMatchType, context: SchemaContext): Promise<SchemaInfo | undefined> {\n let schemaJson: SchemaProps;\n try {\n schemaJson = await ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name);\n } catch(e: any) {\n if (e.message && e.message === \"schema not found\")\n return undefined;\n\n throw(e);\n }\n const schemaInfo = await Schema.startLoadingFromJson(schemaJson, context || new SchemaContext());\n if (schemaInfo !== undefined && schemaInfo.schemaKey.matches(schemaKey, matchType)) {\n return schemaInfo;\n }\n return undefined;\n }\n\n /**\n * This method is not supported for locating schemas over RPC/HTTP.\n * Use the asynchronous `getSchema` method instead.\n * @param _schemaKey Key to look up\n * @param _matchType How to match key against candidate schemas\n * @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.\n * @throws Error Always throws an error indicating this method is not supported.\n * @deprecated in 5.0. Use the asynchronous `getSchema` method for schema retrieval.\n */\n public getSchemaSync(_schemaKey: SchemaKey, _matchType: SchemaMatchType, _context: SchemaContext): Schema | undefined {\n throw new Error(\"getSchemaSync is not supported. Use the asynchronous getSchema method instead.\");\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type IModelRpcProps } from "@itwin/core-common";
|
|
2
|
+
import { ECSqlQueryOptions, ECSqlSchemaLocater, ECSqlSchemaLocaterOptions, SchemaKey, SchemaProps } from "@itwin/ecschema-metadata";
|
|
3
|
+
/**
|
|
4
|
+
* A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the ECSchema RPC interfaces to load schemas incrementally.
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export declare class RpcIncrementalSchemaLocater extends ECSqlSchemaLocater {
|
|
8
|
+
private readonly _iModelProps;
|
|
9
|
+
/**
|
|
10
|
+
* Initializes a new instance of the RpcIncrementalSchemaLocater class.
|
|
11
|
+
*/
|
|
12
|
+
constructor(iModelProps: IModelRpcProps, options?: ECSqlSchemaLocaterOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Executes the given ECSql query and returns the resulting rows.
|
|
15
|
+
* @param query The ECSql query to execute.
|
|
16
|
+
* @param options Optional arguments to control the query result.
|
|
17
|
+
* @returns A promise that resolves to the resulting rows.
|
|
18
|
+
*/
|
|
19
|
+
protected executeQuery<TRow>(query: string, options?: ECSqlQueryOptions): Promise<ReadonlyArray<TRow>>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata).
|
|
22
|
+
* This is the full schema json with all elements that are defined in the schema.
|
|
23
|
+
* @param schemaKey The schema key of the schema to be resolved.
|
|
24
|
+
*/
|
|
25
|
+
protected getSchemaProps(schemaKey: SchemaKey): Promise<SchemaProps | undefined>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=RpcIncrementalSchemaLocater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.d.ts","sourceRoot":"","sources":["../../src/RpcIncrementalSchemaLocater.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2F,KAAK,cAAc,EAA6C,MAAM,oBAAoB,CAAC;AAC7L,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGpI;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,kBAAkB;IACjE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiB;IAE9C;;OAEG;gBACS,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAK5E;;;;;OAKG;cACsB,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAiBrH;;;;OAIG;cACa,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;CAIvF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { ECSqlReader, IModelReadRpcInterface, QueryBinder, QueryRowFormat } from "@itwin/core-common";
|
|
6
|
+
import { ECSqlSchemaLocater } from "@itwin/ecschema-metadata";
|
|
7
|
+
import { ECSchemaRpcInterface } from "./ECSchemaRpcInterface";
|
|
8
|
+
/**
|
|
9
|
+
* A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the ECSchema RPC interfaces to load schemas incrementally.
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export class RpcIncrementalSchemaLocater extends ECSqlSchemaLocater {
|
|
13
|
+
_iModelProps;
|
|
14
|
+
/**
|
|
15
|
+
* Initializes a new instance of the RpcIncrementalSchemaLocater class.
|
|
16
|
+
*/
|
|
17
|
+
constructor(iModelProps, options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this._iModelProps = iModelProps;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Executes the given ECSql query and returns the resulting rows.
|
|
23
|
+
* @param query The ECSql query to execute.
|
|
24
|
+
* @param options Optional arguments to control the query result.
|
|
25
|
+
* @returns A promise that resolves to the resulting rows.
|
|
26
|
+
*/
|
|
27
|
+
async executeQuery(query, options) {
|
|
28
|
+
const ecSqlQueryClient = IModelReadRpcInterface.getClient();
|
|
29
|
+
const queryExecutor = {
|
|
30
|
+
execute: async (request) => ecSqlQueryClient.queryRows(this._iModelProps, request),
|
|
31
|
+
};
|
|
32
|
+
const queryOptions = {
|
|
33
|
+
limit: { count: options?.limit },
|
|
34
|
+
rowFormat: QueryRowFormat.UseECSqlPropertyNames,
|
|
35
|
+
};
|
|
36
|
+
const queryParameters = options && options.parameters ? QueryBinder.from(options.parameters) : undefined;
|
|
37
|
+
const queryReader = new ECSqlReader(queryExecutor, query, queryParameters, queryOptions);
|
|
38
|
+
return queryReader.toArray();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets the [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata).
|
|
42
|
+
* This is the full schema json with all elements that are defined in the schema.
|
|
43
|
+
* @param schemaKey The schema key of the schema to be resolved.
|
|
44
|
+
*/
|
|
45
|
+
async getSchemaProps(schemaKey) {
|
|
46
|
+
const rpcSchemaClient = ECSchemaRpcInterface.getClient();
|
|
47
|
+
return rpcSchemaClient.getSchemaJSON(this._iModelProps, schemaKey.name);
|
|
48
|
+
}
|
|
49
|
+
;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=RpcIncrementalSchemaLocater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.js","sourceRoot":"","sources":["../../src/RpcIncrementalSchemaLocater.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG,OAAO,EAAsD,WAAW,EAAE,sBAAsB,EAAuB,WAAW,EAAgB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC7L,OAAO,EAAqB,kBAAkB,EAAqD,MAAM,0BAA0B,CAAC;AACpI,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,kBAAkB;IAChD,YAAY,CAAiB;IAE9C;;OAEG;IACH,YAAY,WAA2B,EAAE,OAAmC;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACgB,KAAK,CAAC,YAAY,CAAO,KAAa,EAAE,OAA2B;QACpF,MAAM,gBAAgB,GAAG,sBAAsB,CAAC,SAAS,EAAE,CAAC;QAC5D,MAAM,aAAa,GAAuD;YACxE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC;SACnF,CAAC;QAEF,MAAM,YAAY,GAAiB;YACjC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAChC,SAAS,EAAE,cAAc,CAAC,qBAAqB;SAChD,CAAC;QAEF,MAAM,eAAe,GAAG,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzG,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;QAEzF,OAAO,WAAW,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,cAAc,CAAC,SAAoB;QACjD,MAAM,eAAe,GAAG,oBAAoB,CAAC,SAAS,EAAE,CAAC;QACzD,OAAO,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;IAAA,CAAC;CACH","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nimport { DbQueryRequest, DbQueryResponse, DbRequestExecutor, ECSqlReader, IModelReadRpcInterface, type IModelRpcProps, QueryBinder, QueryOptions, QueryRowFormat } from \"@itwin/core-common\";\nimport { ECSqlQueryOptions, ECSqlSchemaLocater, ECSqlSchemaLocaterOptions, SchemaKey, SchemaProps } from \"@itwin/ecschema-metadata\";\nimport { ECSchemaRpcInterface } from \"./ECSchemaRpcInterface\";\n\n/**\n * A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the ECSchema RPC interfaces to load schemas incrementally.\n * @beta\n */\nexport class RpcIncrementalSchemaLocater extends ECSqlSchemaLocater {\n private readonly _iModelProps: IModelRpcProps;\n\n /**\n * Initializes a new instance of the RpcIncrementalSchemaLocater class.\n */\n constructor(iModelProps: IModelRpcProps, options?: ECSqlSchemaLocaterOptions) {\n super(options);\n this._iModelProps = iModelProps;\n }\n\n /**\n * Executes the given ECSql query and returns the resulting rows.\n * @param query The ECSql query to execute.\n * @param options Optional arguments to control the query result.\n * @returns A promise that resolves to the resulting rows.\n */\n protected override async executeQuery<TRow>(query: string, options?: ECSqlQueryOptions): Promise<ReadonlyArray<TRow>> {\n const ecSqlQueryClient = IModelReadRpcInterface.getClient();\n const queryExecutor: DbRequestExecutor<DbQueryRequest, DbQueryResponse> = {\n execute: async (request) => ecSqlQueryClient.queryRows(this._iModelProps, request),\n };\n\n const queryOptions: QueryOptions = {\n limit: { count: options?.limit },\n rowFormat: QueryRowFormat.UseECSqlPropertyNames,\n };\n\n const queryParameters = options && options.parameters ? QueryBinder.from(options.parameters) : undefined;\n const queryReader = new ECSqlReader(queryExecutor, query, queryParameters, queryOptions);\n\n return queryReader.toArray();\n }\n\n /**\n * Gets the [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata).\n * This is the full schema json with all elements that are defined in the schema.\n * @param schemaKey The schema key of the schema to be resolved.\n */\n protected async getSchemaProps(schemaKey: SchemaKey): Promise<SchemaProps | undefined> {\n const rpcSchemaClient = ECSchemaRpcInterface.getClient();\n return rpcSchemaClient.getSchemaJSON(this._iModelProps, schemaKey.name);\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-rpc-interface.d.ts","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"ecschema-rpc-interface.d.ts","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":"AAIA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC"}
|
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
export * from "./ECSchemaRpcInterface";
|
|
6
6
|
export * from "./ECSchemaRpcLocater";
|
|
7
|
+
export * from "./RpcIncrementalSchemaLocater";
|
|
7
8
|
//# sourceMappingURL=ecschema-rpc-interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-rpc-interface.js","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,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*--------------------------------------------------------------------------------------------*/\nexport * from \"./ECSchemaRpcInterface\";\nexport * from \"./ECSchemaRpcLocater\";\
|
|
1
|
+
{"version":3,"file":"ecschema-rpc-interface.js","sourceRoot":"","sources":["../../src/ecschema-rpc-interface.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,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*--------------------------------------------------------------------------------------------*/\nexport * from \"./ECSchemaRpcInterface\";\nexport * from \"./ECSchemaRpcLocater\";\nexport * from \"./RpcIncrementalSchemaLocater\";"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.test.d.ts","sourceRoot":"","sources":["../../../src/test/RpcIncrementalSchemaLocater.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { ECSchemaNamespaceUris, SchemaContext, SchemaKey, SchemaMatchType } from "@itwin/ecschema-metadata";
|
|
6
|
+
import { RpcIncrementalSchemaLocater } from "../RpcIncrementalSchemaLocater";
|
|
7
|
+
import { DbResponseKind, DbResponseStatus, IModelReadRpcInterface } from "@itwin/core-common";
|
|
8
|
+
import { ECSchemaRpcInterface } from "../ECSchemaRpcInterface";
|
|
9
|
+
import { expect } from "chai";
|
|
10
|
+
import * as sinon from "sinon";
|
|
11
|
+
// RpcIncrementalSchemaLocater derives from IncrementalSchemaLocater and ECSqlSchemaLocater, so
|
|
12
|
+
// the basic functionality is already tested in their tests. This test suite verifies the expected
|
|
13
|
+
// behaviour of the RPC specific implementation.
|
|
14
|
+
describe("RpcIncrementalSchemaLocater Tests", () => {
|
|
15
|
+
let imodelReadInterface;
|
|
16
|
+
let ecschemaRpcInterface;
|
|
17
|
+
const schemaInfoColumns = ["name", "version", "references", "alias"];
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
sinon.stub(IModelReadRpcInterface, "getClient").returns(imodelReadInterface = {
|
|
20
|
+
queryRows: async () => { throw new Error("Method must be implemented in the tests."); },
|
|
21
|
+
});
|
|
22
|
+
sinon.stub(ECSchemaRpcInterface, "getClient").returns(ecschemaRpcInterface = {
|
|
23
|
+
getSchemaJSON: async () => { throw new Error("Method must be implemented in the tests."); },
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
sinon.restore();
|
|
28
|
+
});
|
|
29
|
+
it("get schema info, schema found", async () => {
|
|
30
|
+
const schemaKey = SchemaKey.parseString("TestSchema.1.0.0");
|
|
31
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, [
|
|
32
|
+
{ name: schemaKey.name, version: schemaKey.version.toString(), references: "[]", alias: "ts" }
|
|
33
|
+
]));
|
|
34
|
+
const locater = new RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
35
|
+
const schemaInfo = await locater.getSchemaInfo(schemaKey, SchemaMatchType.Latest, new SchemaContext());
|
|
36
|
+
expect(schemaInfo).is.not.undefined;
|
|
37
|
+
expect(schemaInfo).has.property("schemaKey").that.satisfies((key) => key.matches(schemaKey));
|
|
38
|
+
expect(schemaInfo).has.property("alias").that.equals("ts");
|
|
39
|
+
expect(schemaInfo).has.property("references").that.is.empty;
|
|
40
|
+
});
|
|
41
|
+
it("get schema info, schema not found, return undefined", async () => {
|
|
42
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, []));
|
|
43
|
+
const schemaKey = SchemaKey.parseString("TestSchema.1.0.0");
|
|
44
|
+
const locater = new RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
45
|
+
const schemaInfo = await locater.getSchemaInfo(schemaKey, SchemaMatchType.Latest, new SchemaContext());
|
|
46
|
+
expect(schemaInfo).to.be.undefined;
|
|
47
|
+
});
|
|
48
|
+
it("get schema, incrementally", async () => {
|
|
49
|
+
const context = new SchemaContext();
|
|
50
|
+
const locater = new RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
51
|
+
context.addLocater(locater);
|
|
52
|
+
const schemaKey = SchemaKey.parseString("TestSchema.1.0.0");
|
|
53
|
+
sinon.stub(imodelReadInterface, "queryRows")
|
|
54
|
+
.onCall(0).returns(toQueryResult(schemaInfoColumns, [
|
|
55
|
+
{ name: schemaKey.name, version: schemaKey.version.toString(), references: "[]", alias: "ts" },
|
|
56
|
+
{ name: "ECDbMeta", version: "4.0.3", references: "[]", alias: "ecdb" },
|
|
57
|
+
]))
|
|
58
|
+
.onCall(1).returns(toQueryResult(["name", "version", "alias", "references", "items"], [
|
|
59
|
+
{
|
|
60
|
+
name: schemaKey.name,
|
|
61
|
+
version: schemaKey.version.toString(),
|
|
62
|
+
alias: "ts",
|
|
63
|
+
references: "[]",
|
|
64
|
+
items: "[]",
|
|
65
|
+
}
|
|
66
|
+
]))
|
|
67
|
+
.returns(toQueryResult(["schema", "items"], [
|
|
68
|
+
{
|
|
69
|
+
schema: `{
|
|
70
|
+
"name": "${schemaKey.name}",
|
|
71
|
+
"version": "${schemaKey.version.toString()}",
|
|
72
|
+
"alias": "ts",
|
|
73
|
+
"label": "Test Schema",
|
|
74
|
+
"description": "This is a test schema."
|
|
75
|
+
}`,
|
|
76
|
+
}
|
|
77
|
+
]));
|
|
78
|
+
const schema = await context.getSchema(schemaKey, SchemaMatchType.Latest);
|
|
79
|
+
expect(schema).is.not.undefined;
|
|
80
|
+
expect(schema).has.property("schemaKey").that.satisfies((key) => key.matches(schemaKey));
|
|
81
|
+
expect(schema).has.property("alias").that.equals("ts");
|
|
82
|
+
expect(schema).has.property("loadingController").that.is.not.undefined;
|
|
83
|
+
expect(schema).has.a.nested.property("loadingController.inProgress").that.is.true;
|
|
84
|
+
await schema.loadingController?.wait();
|
|
85
|
+
expect(schema).has.property("label", "Test Schema");
|
|
86
|
+
expect(schema).has.property("description", "This is a test schema.");
|
|
87
|
+
});
|
|
88
|
+
it("get schema, unsupported metaschema", async () => {
|
|
89
|
+
const schemaKey = SchemaKey.parseString("TestSchema.1.0.0");
|
|
90
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, [
|
|
91
|
+
{ name: schemaKey.name, version: schemaKey.version.toString(), references: "[]", alias: "ts" },
|
|
92
|
+
{ name: "ECDbMeta", version: "4.0.1", references: "[]", alias: "ecdb" },
|
|
93
|
+
]));
|
|
94
|
+
sinon.stub(ecschemaRpcInterface, "getSchemaJSON").returns(Promise.resolve({
|
|
95
|
+
$schema: ECSchemaNamespaceUris.SCHEMAURL3_2_JSON,
|
|
96
|
+
name: schemaKey.name,
|
|
97
|
+
version: schemaKey.version.toString(),
|
|
98
|
+
alias: "ts"
|
|
99
|
+
}));
|
|
100
|
+
const locater = new RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
101
|
+
const schema = await locater.getSchema(schemaKey, SchemaMatchType.Latest, new SchemaContext());
|
|
102
|
+
expect(schema).is.not.undefined;
|
|
103
|
+
expect(schema).has.property("schemaKey").that.satisfies((key) => key.matches(schemaKey));
|
|
104
|
+
expect(schema).has.property("alias").that.equals("ts");
|
|
105
|
+
});
|
|
106
|
+
it("get schema, schema not found, return undefined", async () => {
|
|
107
|
+
const schemaKey = SchemaKey.parseString("TestSchema.1.0.0");
|
|
108
|
+
sinon.stub(imodelReadInterface, "queryRows").returns(toQueryResult(schemaInfoColumns, []));
|
|
109
|
+
const locater = new RpcIncrementalSchemaLocater({ key: "rpc-test-imodel" });
|
|
110
|
+
const schema = await locater.getSchema(schemaKey, SchemaMatchType.Latest, new SchemaContext());
|
|
111
|
+
expect(schema).is.undefined;
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* This is a very simple helper function to translate a set of rows into a DbQueryResponse.
|
|
116
|
+
* It does not handle different row formats or property order.
|
|
117
|
+
*/
|
|
118
|
+
async function toQueryResult(columns, rows) {
|
|
119
|
+
return {
|
|
120
|
+
kind: DbResponseKind.ECSql,
|
|
121
|
+
status: DbResponseStatus.Done,
|
|
122
|
+
stats: {},
|
|
123
|
+
rowCount: rows.length,
|
|
124
|
+
meta: columns.map((column, i) => ({ name: column, jsonName: column, index: i })),
|
|
125
|
+
data: rows.map(row => columns.map(k => row[k])),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=RpcIncrementalSchemaLocater.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcIncrementalSchemaLocater.test.js","sourceRoot":"","sources":["../../../src/test/RpcIncrementalSchemaLocater.test.ts"],"names":[],"mappings":"AACA;;;+FAG+F;AAC/F,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC5G,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAmB,cAAc,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,+FAA+F;AAC/F,kGAAkG;AAClG,gDAAgD;AAChD,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAEjD,IAAI,mBAA2C,CAAC;IAChD,IAAI,oBAA0C,CAAC;IAE/C,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAErE,UAAU,CAAC,GAAG,EAAE;QACd,KAAK,CAAC,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC,OAAO,CAAC,mBAAmB,GAAG;YAC5E,SAAS,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC,CAAC,CAAC;SACjF,CAAC,CAAC;QACV,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC,OAAO,CAAC,oBAAoB,GAAG;YAC3E,aAAa,EAA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AC,OAAsB,EAAE,IAAsC;IACzF,OAAO;QACL,IAAI,EAAE,cAAc,CAAC,KAAK;QAC1B,MAAM,EAAE,gBAAgB,CAAC,IAAI;QAC7B,KAAK,EAAE,EAAS;QAChB,QAAQ,EAAE,IAAI,CAAC,MAAM;QACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAU,CAAA,CAAC;QACvF,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD,CAAC;AACJ,CAAC","sourcesContent":["\n/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { ECSchemaNamespaceUris, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { RpcIncrementalSchemaLocater } from \"../RpcIncrementalSchemaLocater\";\nimport { DbQueryResponse, DbResponseKind, DbResponseStatus, IModelReadRpcInterface } from \"@itwin/core-common\";\nimport { ECSchemaRpcInterface } from \"../ECSchemaRpcInterface\";\nimport { expect } from \"chai\";\nimport * as sinon from \"sinon\";\n\n// RpcIncrementalSchemaLocater derives from IncrementalSchemaLocater and ECSqlSchemaLocater, so\n// the basic functionality is already tested in their tests. This test suite verifies the expected\n// behaviour of the RPC specific implementation.\ndescribe(\"RpcIncrementalSchemaLocater Tests\", () => {\n\n let imodelReadInterface: IModelReadRpcInterface;\n let ecschemaRpcInterface: ECSchemaRpcInterface;\n\n const schemaInfoColumns = [\"name\", \"version\", \"references\", \"alias\"];\n\n beforeEach(() => {\n sinon.stub(IModelReadRpcInterface, \"getClient\").returns(imodelReadInterface = {\n queryRows: async () => { throw new Error(\"Method must be implemented in the tests.\"); },\n } as any);\n sinon.stub(ECSchemaRpcInterface, \"getClient\").returns(ecschemaRpcInterface = {\n getSchemaJSON: async () => { throw new Error(\"Method must be implemented in the tests.\"); },\n } as any);\n });\n\n afterEach(() => {\n sinon.restore();\n });\n\n it(\"get schema info, schema found\", async () => {\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, [\n { name: schemaKey.name, version: schemaKey.version.toString(), references: \"[]\", alias: \"ts\" }\n ]));\n\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schemaInfo = await locater.getSchemaInfo(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schemaInfo).is.not.undefined;\n expect(schemaInfo).has.property(\"schemaKey\").that.satisfies((key: SchemaKey) => key.matches(schemaKey));\n expect(schemaInfo).has.property(\"alias\").that.equals(\"ts\");\n expect(schemaInfo).has.property(\"references\").that.is.empty;\n });\n\n it(\"get schema info, schema not found, return undefined\", async () => {\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, []));\n\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schemaInfo = await locater.getSchemaInfo(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schemaInfo).to.be.undefined;\n });\n\n it(\"get schema, incrementally\", async () => {\n const context = new SchemaContext();\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n context.addLocater(locater);\n\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\")\n .onCall(0).returns(toQueryResult(schemaInfoColumns, [\n { name: schemaKey.name, version: schemaKey.version.toString(), references: \"[]\", alias: \"ts\" },\n { name: \"ECDbMeta\", version: \"4.0.3\", references: \"[]\", alias: \"ecdb\" },\n ]))\n .onCall(1).returns(toQueryResult([\"name\", \"version\", \"alias\", \"references\", \"items\"], [\n {\n name: schemaKey.name,\n version: schemaKey.version.toString(),\n alias: \"ts\",\n references: \"[]\",\n items: \"[]\",\n }\n ]))\n .returns(toQueryResult([\"schema\", \"items\"], [\n {\n schema: `{\n \"name\": \"${schemaKey.name}\",\n \"version\": \"${schemaKey.version.toString()}\",\n \"alias\": \"ts\",\n \"label\": \"Test Schema\",\n \"description\": \"This is a test schema.\"\n }`,\n }\n ]));\n\n const schema = await context.getSchema(schemaKey, SchemaMatchType.Latest);\n\n expect(schema).is.not.undefined;\n expect(schema).has.property(\"schemaKey\").that.satisfies((key: SchemaKey) => key.matches(schemaKey));\n expect(schema).has.property(\"alias\").that.equals(\"ts\");\n\n expect(schema).has.property(\"loadingController\").that.is.not.undefined;\n expect(schema).has.a.nested.property(\"loadingController.inProgress\").that.is.true;\n await schema!.loadingController?.wait();\n\n expect(schema).has.property(\"label\", \"Test Schema\");\n expect(schema).has.property(\"description\", \"This is a test schema.\");\n });\n\n it(\"get schema, unsupported metaschema\", async () => {\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, [\n { name: schemaKey.name, version: schemaKey.version.toString(), references: \"[]\", alias: \"ts\" },\n { name: \"ECDbMeta\", version: \"4.0.1\", references: \"[]\", alias: \"ecdb\" },\n ]));\n\n sinon.stub(ecschemaRpcInterface, \"getSchemaJSON\").returns(Promise.resolve({\n $schema: ECSchemaNamespaceUris.SCHEMAURL3_2_JSON,\n name: schemaKey.name,\n version: schemaKey.version.toString(),\n alias: \"ts\"\n }));\n\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schema = await locater.getSchema(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schema).is.not.undefined;\n expect(schema).has.property(\"schemaKey\").that.satisfies((key: SchemaKey) => key.matches(schemaKey));\n expect(schema).has.property(\"alias\").that.equals(\"ts\");\n });\n\n it(\"get schema, schema not found, return undefined\", async () => {\n const schemaKey = SchemaKey.parseString(\"TestSchema.1.0.0\");\n sinon.stub(imodelReadInterface, \"queryRows\").returns(toQueryResult(schemaInfoColumns, []));\n\n const locater = new RpcIncrementalSchemaLocater({ key: \"rpc-test-imodel\" });\n const schema = await locater.getSchema(schemaKey, SchemaMatchType.Latest, new SchemaContext());\n\n expect(schema).is.undefined;\n });\n});\n\n/**\n * This is a very simple helper function to translate a set of rows into a DbQueryResponse.\n * It does not handle different row formats or property order.\n */\nasync function toQueryResult(columns: Array<string>, rows: Array<{ [column: string]: any }>): Promise<DbQueryResponse> {\n return {\n kind: DbResponseKind.ECSql,\n status: DbResponseStatus.Done,\n stats: {} as any,\n rowCount: rows.length,\n meta: columns.map((column, i) => ({ name: column, jsonName: column, index: i } as any)),\n data: rows.map(row => columns.map(k => row[k])),\n };\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/ecschema-rpcinterface-common",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0-dev.2",
|
|
4
4
|
"description": "Schema RPC Interface common interface",
|
|
5
5
|
"main": "lib/cjs/ecschema-rpc-interface.js",
|
|
6
6
|
"module": "lib/esm/ecschema-rpc-interface.js",
|
|
@@ -22,21 +22,27 @@
|
|
|
22
22
|
"url": "http://www.bentley.com"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@itwin/core-bentley": "5.
|
|
26
|
-
"@itwin/core-
|
|
27
|
-
"@itwin/
|
|
28
|
-
"@itwin/
|
|
25
|
+
"@itwin/core-bentley": "5.2.0-dev.2",
|
|
26
|
+
"@itwin/core-common": "5.2.0-dev.2",
|
|
27
|
+
"@itwin/ecschema-metadata": "5.2.0-dev.2",
|
|
28
|
+
"@itwin/core-geometry": "5.2.0-dev.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@itwin/eslint-plugin": "5.
|
|
32
|
-
"
|
|
31
|
+
"@itwin/eslint-plugin": "5.2.2-dev.2",
|
|
32
|
+
"@types/chai": "4.3.1",
|
|
33
|
+
"@types/mocha": "^10.0.6",
|
|
34
|
+
"@types/sinon": "^17.0.2",
|
|
35
|
+
"chai": "^4.3.10",
|
|
36
|
+
"eslint": "^9.31.0",
|
|
37
|
+
"mocha": "^11.1.0",
|
|
38
|
+
"sinon": "^17.0.2",
|
|
33
39
|
"rimraf": "^6.0.1",
|
|
34
40
|
"typescript": "~5.6.2",
|
|
35
|
-
"@itwin/build-tools": "5.
|
|
36
|
-
"@itwin/core-bentley": "5.
|
|
37
|
-
"@itwin/core-
|
|
38
|
-
"@itwin/ecschema-metadata": "5.
|
|
39
|
-
"@itwin/core-
|
|
41
|
+
"@itwin/build-tools": "5.2.0-dev.2",
|
|
42
|
+
"@itwin/core-bentley": "5.2.0-dev.2",
|
|
43
|
+
"@itwin/core-geometry": "5.2.0-dev.2",
|
|
44
|
+
"@itwin/ecschema-metadata": "5.2.0-dev.2",
|
|
45
|
+
"@itwin/core-common": "5.2.0-dev.2"
|
|
40
46
|
},
|
|
41
47
|
"scripts": {
|
|
42
48
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|
|
@@ -47,6 +53,7 @@
|
|
|
47
53
|
"docs": "",
|
|
48
54
|
"extract-api": "betools extract-api --entry=ecschema-rpc-interface",
|
|
49
55
|
"lint": "eslint \"./src/**/*.ts\" 1>&2",
|
|
50
|
-
"
|
|
56
|
+
"lint-deprecation": "eslint --fix -f visualstudio --no-inline-config -c ../../../common/config/eslint/eslint.config.deprecation-policy.js \"./src/**/*.ts\"",
|
|
57
|
+
"test": "mocha"
|
|
51
58
|
}
|
|
52
59
|
}
|