@itwin/presentation-core-interop 0.1.1 → 0.2.0

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/cjs/core-interop/QueryExecutor.d.ts.map +1 -1
  3. package/lib/cjs/core-interop/QueryExecutor.js +5 -1
  4. package/lib/cjs/core-interop/QueryExecutor.js.map +1 -1
  5. package/lib/esm/core-interop/QueryExecutor.d.ts.map +1 -1
  6. package/lib/esm/core-interop/QueryExecutor.js +5 -1
  7. package/lib/esm/core-interop/QueryExecutor.js.map +1 -1
  8. package/package.json +12 -12
  9. package/.mocharc.json +0 -8
  10. package/.nycrc +0 -14
  11. package/api/presentation-core-interop.api.md +0 -38
  12. package/api/presentation-core-interop.exports.csv +0 -7
  13. package/eslint.config.js +0 -14
  14. package/lib/cjs/test/Formatting.test.d.ts +0 -2
  15. package/lib/cjs/test/Formatting.test.d.ts.map +0 -1
  16. package/lib/cjs/test/Formatting.test.js +0 -282
  17. package/lib/cjs/test/Formatting.test.js.map +0 -1
  18. package/lib/cjs/test/Logging.test.d.ts +0 -2
  19. package/lib/cjs/test/Logging.test.d.ts.map +0 -1
  20. package/lib/cjs/test/Logging.test.js +0 -57
  21. package/lib/cjs/test/Logging.test.js.map +0 -1
  22. package/lib/cjs/test/Metadata.test.d.ts +0 -2
  23. package/lib/cjs/test/Metadata.test.d.ts.map +0 -1
  24. package/lib/cjs/test/Metadata.test.js +0 -684
  25. package/lib/cjs/test/Metadata.test.js.map +0 -1
  26. package/lib/cjs/test/QueryExecutor.test.d.ts +0 -2
  27. package/lib/cjs/test/QueryExecutor.test.d.ts.map +0 -1
  28. package/lib/cjs/test/QueryExecutor.test.js +0 -178
  29. package/lib/cjs/test/QueryExecutor.test.js.map +0 -1
  30. package/lib/cjs/test/Transactions.test.d.ts +0 -2
  31. package/lib/cjs/test/Transactions.test.d.ts.map +0 -1
  32. package/lib/cjs/test/Transactions.test.js +0 -73
  33. package/lib/cjs/test/Transactions.test.js.map +0 -1
  34. package/lib/cjs/test/index.d.ts +0 -2
  35. package/lib/cjs/test/index.d.ts.map +0 -1
  36. package/lib/cjs/test/index.js +0 -43
  37. package/lib/cjs/test/index.js.map +0 -1
  38. package/lib/esm/test/Formatting.test.d.ts +0 -2
  39. package/lib/esm/test/Formatting.test.d.ts.map +0 -1
  40. package/lib/esm/test/Formatting.test.js +0 -277
  41. package/lib/esm/test/Formatting.test.js.map +0 -1
  42. package/lib/esm/test/Logging.test.d.ts +0 -2
  43. package/lib/esm/test/Logging.test.d.ts.map +0 -1
  44. package/lib/esm/test/Logging.test.js +0 -52
  45. package/lib/esm/test/Logging.test.js.map +0 -1
  46. package/lib/esm/test/Metadata.test.d.ts +0 -2
  47. package/lib/esm/test/Metadata.test.d.ts.map +0 -1
  48. package/lib/esm/test/Metadata.test.js +0 -679
  49. package/lib/esm/test/Metadata.test.js.map +0 -1
  50. package/lib/esm/test/QueryExecutor.test.d.ts +0 -2
  51. package/lib/esm/test/QueryExecutor.test.d.ts.map +0 -1
  52. package/lib/esm/test/QueryExecutor.test.js +0 -173
  53. package/lib/esm/test/QueryExecutor.test.js.map +0 -1
  54. package/lib/esm/test/Transactions.test.d.ts +0 -2
  55. package/lib/esm/test/Transactions.test.d.ts.map +0 -1
  56. package/lib/esm/test/Transactions.test.js +0 -68
  57. package/lib/esm/test/Transactions.test.js.map +0 -1
  58. package/lib/esm/test/index.d.ts +0 -2
  59. package/lib/esm/test/index.d.ts.map +0 -1
  60. package/lib/esm/test/index.js +0 -15
  61. package/lib/esm/test/index.js.map +0 -1
  62. package/src/core-interop/Formatting.ts +0 -194
  63. package/src/core-interop/Logging.ts +0 -58
  64. package/src/core-interop/Metadata.ts +0 -62
  65. package/src/core-interop/MetadataInternal.ts +0 -413
  66. package/src/core-interop/QueryExecutor.ts +0 -122
  67. package/src/core-interop/Transactions.ts +0 -92
  68. package/src/presentation-core-interop.ts +0 -10
  69. package/src/test/Formatting.test.ts +0 -358
  70. package/src/test/Logging.test.ts +0 -59
  71. package/src/test/Metadata.test.ts +0 -786
  72. package/src/test/QueryExecutor.test.ts +0 -217
  73. package/src/test/Transactions.test.ts +0 -74
  74. package/src/test/index.ts +0 -17
  75. package/tsconfig.cjs.json +0 -7
  76. package/tsconfig.esm.json +0 -7
  77. package/tsconfig.json +0 -14
@@ -1,217 +0,0 @@
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
-
6
- import { expect } from "chai";
7
- import sinon from "sinon";
8
- import { QueryBinder, QueryOptions, QueryRowFormat } from "@itwin/core-common";
9
- import { Point2d, Point3d } from "@itwin/core-geometry";
10
- import { ECSqlBinding } from "@itwin/presentation-shared";
11
- import { createECSqlQueryExecutor } from "../core-interop/QueryExecutor";
12
-
13
- describe("createECSqlQueryExecutor", () => {
14
- describe("createQueryReader", () => {
15
- it("calls IModel's `createQueryReader` with default params", async () => {
16
- const imodel = {
17
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub([{}, {}])),
18
- };
19
-
20
- const executor = createECSqlQueryExecutor(imodel);
21
- const reader = executor.createQueryReader({ ecsql: "ecsql" });
22
- for await (const _ of reader) {
23
- }
24
-
25
- // eslint-disable-next-line @typescript-eslint/unbound-method
26
- expect(imodel.createQueryReader).to.be.calledOnceWithExactly(
27
- "ecsql",
28
- sinon.match((binder: QueryBinder) => Object.keys(binder.serialize()).length === 0),
29
- sinon.match((options: QueryOptions) => Object.keys(options).length === 0),
30
- );
31
- });
32
-
33
- it("calls IModel's `createQueryReader` with CTEs", async () => {
34
- const imodel = {
35
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub([{}, {}])),
36
- };
37
-
38
- const executor = createECSqlQueryExecutor(imodel);
39
- const reader = executor.createQueryReader({ ctes: ["cte1", "cte2"], ecsql: "ecsql" });
40
- for await (const _ of reader) {
41
- }
42
-
43
- // eslint-disable-next-line @typescript-eslint/unbound-method
44
- expect(imodel.createQueryReader).to.be.calledOnceWith("WITH RECURSIVE cte1, cte2 ecsql");
45
- });
46
-
47
- it("calls IModel's `createQueryReader` with `ECSqlPropertyNames` row format", async () => {
48
- const imodel = {
49
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub([])),
50
- };
51
-
52
- const executor = createECSqlQueryExecutor(imodel);
53
- const reader = executor.createQueryReader({ ecsql: "ecsql" }, { rowFormat: "ECSqlPropertyNames" });
54
- for await (const _ of reader) {
55
- }
56
-
57
- // eslint-disable-next-line @typescript-eslint/unbound-method
58
- expect(imodel.createQueryReader).to.be.calledOnceWithExactly(
59
- "ecsql",
60
- sinon.match((binder: QueryBinder) => Object.keys(binder.serialize()).length === 0),
61
- sinon.match((options: QueryOptions) => options.rowFormat === QueryRowFormat.UseECSqlPropertyNames),
62
- );
63
- });
64
-
65
- it("calls IModel's `createQueryReader` with `Indexes` row format", async () => {
66
- const imodel = {
67
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub([])),
68
- };
69
-
70
- const executor = createECSqlQueryExecutor(imodel);
71
- const reader = executor.createQueryReader({ ecsql: "ecsql" }, { rowFormat: "Indexes" });
72
- for await (const _ of reader) {
73
- }
74
-
75
- // eslint-disable-next-line @typescript-eslint/unbound-method
76
- expect(imodel.createQueryReader).to.be.calledOnceWithExactly(
77
- "ecsql",
78
- sinon.match((binder: QueryBinder) => Object.keys(binder.serialize()).length === 0),
79
- sinon.match((options: QueryOptions) => options.rowFormat === QueryRowFormat.UseECSqlPropertyIndexes),
80
- );
81
- });
82
-
83
- it("calls IModel's `createQueryReader` with different bindings", async () => {
84
- const imodel = {
85
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub([])),
86
- };
87
-
88
- const bindings: ECSqlBinding[] = [
89
- {
90
- type: "boolean",
91
- value: true,
92
- },
93
- {
94
- type: "double",
95
- value: 1.23,
96
- },
97
- {
98
- type: "id",
99
- value: "0x123",
100
- },
101
- {
102
- type: "idset",
103
- value: ["0x123", "0x456"],
104
- },
105
- {
106
- type: "int",
107
- value: 123,
108
- },
109
- { type: "long", value: 456 },
110
- {
111
- type: "point2d",
112
- value: { x: 1.23, y: 4.56 },
113
- },
114
- {
115
- type: "point3d",
116
- value: { x: 1.23, y: 4.56, z: 7.89 },
117
- },
118
- {
119
- type: "string",
120
- value: "xxx",
121
- },
122
- {
123
- type: "string",
124
- value: undefined,
125
- },
126
- ];
127
-
128
- const expectedBinder = new QueryBinder();
129
- expectedBinder.bindBoolean(1, true);
130
- expectedBinder.bindDouble(2, 1.23);
131
- expectedBinder.bindId(3, "0x123");
132
- expectedBinder.bindIdSet(4, ["0x123", "0x456"]);
133
- expectedBinder.bindInt(5, 123);
134
- expectedBinder.bindLong(6, 456);
135
- expectedBinder.bindPoint2d(7, Point2d.create(1.23, 4.56));
136
- expectedBinder.bindPoint3d(8, Point3d.create(1.23, 4.56, 7.89));
137
- expectedBinder.bindString(9, "xxx");
138
- expectedBinder.bindNull(10);
139
-
140
- const executor = createECSqlQueryExecutor(imodel);
141
- const reader = executor.createQueryReader({ ecsql: "ecsql", bindings }, undefined);
142
- for await (const _ of reader) {
143
- }
144
-
145
- // eslint-disable-next-line @typescript-eslint/unbound-method
146
- expect(imodel.createQueryReader).to.be.calledOnceWithExactly(
147
- "ecsql",
148
- sinon.match((binder: QueryBinder) => JSON.stringify(expectedBinder.serialize()) === JSON.stringify(binder.serialize())),
149
- sinon.match((options: QueryOptions) => Object.keys(options).length === 0),
150
- );
151
- });
152
-
153
- it("creates iterable reader for rows as objects", async () => {
154
- const rows = [{ x: 1 }, { y: 2 }];
155
- const imodel = {
156
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub(rows)),
157
- };
158
-
159
- const executor = createECSqlQueryExecutor(imodel);
160
- const reader = executor.createQueryReader({ ecsql: "ecsql" }, { rowFormat: "ECSqlPropertyNames" });
161
-
162
- const resultRows = new Array<any>();
163
- for await (const row of reader) {
164
- resultRows.push(row);
165
- }
166
-
167
- expect(resultRows).to.deep.eq(rows);
168
- });
169
-
170
- it("creates iterable reader for rows as arrays", async () => {
171
- const rows = [
172
- [1, 2],
173
- [3, 4],
174
- ];
175
- const imodel = {
176
- createQueryReader: sinon.stub().returns(createCoreECSqlReaderStub(rows)),
177
- };
178
-
179
- const executor = createECSqlQueryExecutor(imodel);
180
- const reader = executor.createQueryReader({ ecsql: "ecsql" }, { rowFormat: "Indexes" });
181
-
182
- const resultRows = new Array<any>();
183
- for await (const row of reader) {
184
- resultRows.push(row);
185
- }
186
-
187
- expect(resultRows).to.deep.eq(rows);
188
- });
189
- });
190
- });
191
-
192
- function createCoreECSqlReaderStub(rows: object[]) {
193
- let curr = -1;
194
- const reader = {
195
- next: sinon.fake(async () => {
196
- ++curr;
197
- if (curr < rows.length) {
198
- return { done: false, value: createQueryRowProxy(rows[curr]) };
199
- }
200
- return { done: true, value: undefined };
201
- }),
202
- };
203
- return {
204
- ...reader,
205
- async *[Symbol.asyncIterator]() {
206
- return reader;
207
- },
208
- };
209
- }
210
-
211
- function createQueryRowProxy(data: object) {
212
- return {
213
- ...data,
214
- toArray: () => data,
215
- toRow: () => data,
216
- };
217
- }
@@ -1,74 +0,0 @@
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
-
6
- import { expect } from "chai";
7
- import sinon from "sinon";
8
- import { registerTxnListeners } from "../core-interop/Transactions";
9
-
10
- describe("registerTxnListeners", () => {
11
- it("calls provided callback on `onAppliedChanges` event", async () => {
12
- const txns = createCoreTxnManager();
13
- const callback = sinon.stub();
14
- registerTxnListeners(txns, callback);
15
- expect(txns.onChangesApplied.addListener).to.be.calledOnce;
16
- txns.onChangesApplied.addListener.firstCall.callArg(0);
17
- expect(callback).to.be.calledOnce;
18
- });
19
-
20
- it("calls provided callback on `onCommit` and `onCommitted` event", async () => {
21
- const txns = createCoreTxnManager();
22
- const callback = sinon.stub();
23
- registerTxnListeners(txns, callback);
24
- expect(txns.onCommit.addListener).to.be.calledOnce;
25
- expect(txns.onCommitted.addListener).to.be.calledOnce;
26
- txns.onCommit.addListener.firstCall.callArg(0);
27
- txns.onCommitted.addListener.firstCall.callArg(0);
28
- expect(callback).to.be.calledOnce;
29
- });
30
-
31
- it("doesn't call provided callback on `onCommitted` event if there was no `onCommit` event", async () => {
32
- const txns = createCoreTxnManager();
33
- const callback = sinon.stub();
34
- registerTxnListeners(txns, callback);
35
- expect(txns.onCommit.addListener).to.be.calledOnce;
36
- expect(txns.onCommitted.addListener).to.be.calledOnce;
37
- txns.onCommitted.addListener.firstCall.callArg(0);
38
- expect(callback).to.not.be.called;
39
- });
40
-
41
- it("unregisters from events when returned function is called", async () => {
42
- const txns = createCoreTxnManager();
43
- const unregister = registerTxnListeners(txns, sinon.stub());
44
- expect(txns.onCommit.hasListeners()).to.be.true;
45
- expect(txns.onCommitted.hasListeners()).to.be.true;
46
- expect(txns.onChangesApplied.hasListeners()).to.be.true;
47
- unregister();
48
- expect(txns.onCommit.hasListeners()).to.be.false;
49
- expect(txns.onCommitted.hasListeners()).to.be.false;
50
- expect(txns.onChangesApplied.hasListeners()).to.be.false;
51
- });
52
-
53
- function createCoreTxnManager() {
54
- return {
55
- onCommit: createEventStub(),
56
- onCommitted: createEventStub(),
57
- onChangesApplied: createEventStub(),
58
- };
59
- }
60
-
61
- function createEventStub() {
62
- let hasListeners = false;
63
- return {
64
- hasListeners: () => hasListeners,
65
- addListener: sinon.fake(() => {
66
- hasListeners = true;
67
- return () => {
68
- hasListeners = false;
69
- };
70
- }),
71
- removeListener: sinon.stub(),
72
- };
73
- }
74
- });
package/src/test/index.ts DELETED
@@ -1,17 +0,0 @@
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
-
6
- import * as chai from "chai";
7
- import chaiAsPromised from "chai-as-promised";
8
- import sinon from "sinon";
9
- import sinonChai from "sinon-chai";
10
-
11
- // setup chai
12
- chai.use(chaiAsPromised);
13
- chai.use(sinonChai);
14
-
15
- beforeEach(function () {
16
- sinon.restore();
17
- });
package/tsconfig.cjs.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "CommonJS",
5
- "outDir": "lib/cjs"
6
- }
7
- }
package/tsconfig.esm.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "ES2020",
5
- "outDir": "lib/esm"
6
- }
7
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "sourceMap": true,
5
- "esModuleInterop": true,
6
- "inlineSources": true,
7
- "declaration": true,
8
- "declarationMap": true,
9
- "allowSyntheticDefaultImports": true,
10
- "resolveJsonModule": true,
11
- "lib": ["ES2022"]
12
- },
13
- "include": ["src"]
14
- }