@itwin/ecschema-rpcinterface-common 5.1.0-dev.59 → 5.1.0-dev.60
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/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/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 +17 -11
|
@@ -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":"RpcIncrementalS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,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":[],"mappings":";;AACA;;;+FAG+F;AAC/F,gEAA4G;AAC5G,gFAA6E;AAC7E,oDAA+G;AAC/G,kEAA+D;AAC/D,+BAA8B;AAC9B,+BAA+B;AAE/B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------------------------------------------------------------------------\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}"]}
|
|
@@ -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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AAC,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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AAE,EAAE,CAAC,CAAC,CAAC;QAE3F,MAAM,OAAO,GAAG,IAAI,2BAA2B,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC5E,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,aAAa,EAAE,CAAC,CAAC;QAE/F,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACH,KAAK,UAAU,aAAa,CAAC,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.1.0-dev.
|
|
3
|
+
"version": "5.1.0-dev.60",
|
|
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.1.0-dev.
|
|
26
|
-
"@itwin/core-
|
|
27
|
-
"@itwin/core-
|
|
28
|
-
"@itwin/ecschema-metadata": "5.1.0-dev.
|
|
25
|
+
"@itwin/core-bentley": "5.1.0-dev.60",
|
|
26
|
+
"@itwin/core-geometry": "5.1.0-dev.60",
|
|
27
|
+
"@itwin/core-common": "5.1.0-dev.60",
|
|
28
|
+
"@itwin/ecschema-metadata": "5.1.0-dev.60"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
32
|
+
"@types/chai": "4.3.1",
|
|
33
|
+
"@types/mocha": "^10.0.6",
|
|
34
|
+
"@types/sinon": "^17.0.2",
|
|
35
|
+
"chai": "^4.3.10",
|
|
32
36
|
"eslint": "^9.13.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.1.0-dev.
|
|
36
|
-
"@itwin/core-
|
|
37
|
-
"@itwin/core-bentley": "5.1.0-dev.
|
|
38
|
-
"@itwin/
|
|
39
|
-
"@itwin/
|
|
41
|
+
"@itwin/build-tools": "5.1.0-dev.60",
|
|
42
|
+
"@itwin/core-geometry": "5.1.0-dev.60",
|
|
43
|
+
"@itwin/core-bentley": "5.1.0-dev.60",
|
|
44
|
+
"@itwin/core-common": "5.1.0-dev.60",
|
|
45
|
+
"@itwin/ecschema-metadata": "5.1.0-dev.60"
|
|
40
46
|
},
|
|
41
47
|
"scripts": {
|
|
42
48
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|
|
@@ -47,6 +53,6 @@
|
|
|
47
53
|
"docs": "",
|
|
48
54
|
"extract-api": "betools extract-api --entry=ecschema-rpc-interface",
|
|
49
55
|
"lint": "eslint \"./src/**/*.ts\" 1>&2",
|
|
50
|
-
"test": ""
|
|
56
|
+
"test": "mocha"
|
|
51
57
|
}
|
|
52
58
|
}
|