@itwin/presentation-core-interop 0.1.2 → 0.2.1

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 (83) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/lib/cjs/core-interop/Metadata.d.ts.map +1 -1
  3. package/lib/cjs/core-interop/Metadata.js +7 -1
  4. package/lib/cjs/core-interop/Metadata.js.map +1 -1
  5. package/lib/cjs/core-interop/QueryExecutor.d.ts.map +1 -1
  6. package/lib/cjs/core-interop/QueryExecutor.js +5 -1
  7. package/lib/cjs/core-interop/QueryExecutor.js.map +1 -1
  8. package/lib/esm/core-interop/Metadata.d.ts.map +1 -1
  9. package/lib/esm/core-interop/Metadata.js +7 -1
  10. package/lib/esm/core-interop/Metadata.js.map +1 -1
  11. package/lib/esm/core-interop/QueryExecutor.d.ts.map +1 -1
  12. package/lib/esm/core-interop/QueryExecutor.js +5 -1
  13. package/lib/esm/core-interop/QueryExecutor.js.map +1 -1
  14. package/package.json +12 -12
  15. package/.mocharc.json +0 -8
  16. package/.nycrc +0 -14
  17. package/api/presentation-core-interop.api.md +0 -38
  18. package/api/presentation-core-interop.exports.csv +0 -7
  19. package/eslint.config.js +0 -14
  20. package/lib/cjs/test/Formatting.test.d.ts +0 -2
  21. package/lib/cjs/test/Formatting.test.d.ts.map +0 -1
  22. package/lib/cjs/test/Formatting.test.js +0 -282
  23. package/lib/cjs/test/Formatting.test.js.map +0 -1
  24. package/lib/cjs/test/Logging.test.d.ts +0 -2
  25. package/lib/cjs/test/Logging.test.d.ts.map +0 -1
  26. package/lib/cjs/test/Logging.test.js +0 -57
  27. package/lib/cjs/test/Logging.test.js.map +0 -1
  28. package/lib/cjs/test/Metadata.test.d.ts +0 -2
  29. package/lib/cjs/test/Metadata.test.d.ts.map +0 -1
  30. package/lib/cjs/test/Metadata.test.js +0 -684
  31. package/lib/cjs/test/Metadata.test.js.map +0 -1
  32. package/lib/cjs/test/QueryExecutor.test.d.ts +0 -2
  33. package/lib/cjs/test/QueryExecutor.test.d.ts.map +0 -1
  34. package/lib/cjs/test/QueryExecutor.test.js +0 -178
  35. package/lib/cjs/test/QueryExecutor.test.js.map +0 -1
  36. package/lib/cjs/test/Transactions.test.d.ts +0 -2
  37. package/lib/cjs/test/Transactions.test.d.ts.map +0 -1
  38. package/lib/cjs/test/Transactions.test.js +0 -73
  39. package/lib/cjs/test/Transactions.test.js.map +0 -1
  40. package/lib/cjs/test/index.d.ts +0 -2
  41. package/lib/cjs/test/index.d.ts.map +0 -1
  42. package/lib/cjs/test/index.js +0 -43
  43. package/lib/cjs/test/index.js.map +0 -1
  44. package/lib/esm/test/Formatting.test.d.ts +0 -2
  45. package/lib/esm/test/Formatting.test.d.ts.map +0 -1
  46. package/lib/esm/test/Formatting.test.js +0 -277
  47. package/lib/esm/test/Formatting.test.js.map +0 -1
  48. package/lib/esm/test/Logging.test.d.ts +0 -2
  49. package/lib/esm/test/Logging.test.d.ts.map +0 -1
  50. package/lib/esm/test/Logging.test.js +0 -52
  51. package/lib/esm/test/Logging.test.js.map +0 -1
  52. package/lib/esm/test/Metadata.test.d.ts +0 -2
  53. package/lib/esm/test/Metadata.test.d.ts.map +0 -1
  54. package/lib/esm/test/Metadata.test.js +0 -679
  55. package/lib/esm/test/Metadata.test.js.map +0 -1
  56. package/lib/esm/test/QueryExecutor.test.d.ts +0 -2
  57. package/lib/esm/test/QueryExecutor.test.d.ts.map +0 -1
  58. package/lib/esm/test/QueryExecutor.test.js +0 -173
  59. package/lib/esm/test/QueryExecutor.test.js.map +0 -1
  60. package/lib/esm/test/Transactions.test.d.ts +0 -2
  61. package/lib/esm/test/Transactions.test.d.ts.map +0 -1
  62. package/lib/esm/test/Transactions.test.js +0 -68
  63. package/lib/esm/test/Transactions.test.js.map +0 -1
  64. package/lib/esm/test/index.d.ts +0 -2
  65. package/lib/esm/test/index.d.ts.map +0 -1
  66. package/lib/esm/test/index.js +0 -15
  67. package/lib/esm/test/index.js.map +0 -1
  68. package/src/core-interop/Formatting.ts +0 -194
  69. package/src/core-interop/Logging.ts +0 -58
  70. package/src/core-interop/Metadata.ts +0 -62
  71. package/src/core-interop/MetadataInternal.ts +0 -413
  72. package/src/core-interop/QueryExecutor.ts +0 -122
  73. package/src/core-interop/Transactions.ts +0 -92
  74. package/src/presentation-core-interop.ts +0 -10
  75. package/src/test/Formatting.test.ts +0 -358
  76. package/src/test/Logging.test.ts +0 -59
  77. package/src/test/Metadata.test.ts +0 -786
  78. package/src/test/QueryExecutor.test.ts +0 -217
  79. package/src/test/Transactions.test.ts +0 -74
  80. package/src/test/index.ts +0 -17
  81. package/tsconfig.cjs.json +0 -7
  82. package/tsconfig.esm.json +0 -7
  83. package/tsconfig.json +0 -14
@@ -1,358 +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 { FormatProps, FormatterSpec, Format as QuantityFormat, UnitSystemKey } from "@itwin/core-quantity";
9
- import {
10
- Format,
11
- KindOfQuantity,
12
- OverrideFormat,
13
- Schema,
14
- SchemaContext,
15
- SchemaItemFormatProps,
16
- SchemaItemType,
17
- SchemaKey,
18
- SchemaUnitProvider,
19
- Unit,
20
- UnitSystem,
21
- } from "@itwin/ecschema-metadata";
22
- import { IPrimitiveValueFormatter, TypedPrimitiveValue } from "@itwin/presentation-shared";
23
- import { createValueFormatter } from "../core-interop/Formatting";
24
-
25
- describe("createValueFormatter", () => {
26
- const schemaContext = {
27
- getSchema: sinon.stub<[SchemaKey], Schema>(),
28
- };
29
- const defaultFormatter = sinon.fake(async () => Promise.resolve("DEFAULT"));
30
- let formatter: IPrimitiveValueFormatter;
31
-
32
- function initFormatter(unitSystem?: UnitSystemKey) {
33
- formatter = createValueFormatter({
34
- schemaContext: schemaContext as unknown as SchemaContext,
35
- unitSystem,
36
- baseFormatter: defaultFormatter,
37
- });
38
- }
39
-
40
- beforeEach(() => {
41
- defaultFormatter.resetHistory();
42
- initFormatter();
43
- });
44
-
45
- it("returns default formatter result when property doesn't have a KoQ", async () => {
46
- const prop: TypedPrimitiveValue = {
47
- type: "Double",
48
- value: 1.23,
49
- };
50
- expect(await formatter(prop)).to.eq("DEFAULT");
51
- expect(defaultFormatter).to.be.calledOnceWith(prop);
52
- });
53
-
54
- it("throws when property references non-existing schema in KoQ", async () => {
55
- schemaContext.getSchema.resolves(undefined);
56
- const prop: TypedPrimitiveValue = {
57
- type: "Double",
58
- value: 1.23,
59
- koqName: "X.Y",
60
- };
61
- await expect(formatter(prop)).to.eventually.be.rejectedWith("Invalid schema");
62
- });
63
-
64
- it("throws when property references non-existing KoQ", async () => {
65
- schemaContext.getSchema.resolves({
66
- name: "X",
67
- getItem: async () => undefined,
68
- });
69
- const prop: TypedPrimitiveValue = {
70
- type: "Double",
71
- value: 1.23,
72
- koqName: "X.Y",
73
- };
74
- await expect(formatter(prop)).to.eventually.be.rejectedWith("Invalid kind of quantity");
75
- });
76
-
77
- it("returns default formatter result when KoQ doesn't specify persistence unit", async () => {
78
- schemaContext.getSchema.resolves({
79
- name: "X",
80
- getItem: async (name: string) => {
81
- if (name === "Y") {
82
- return {
83
- persistenceUnit: Promise.resolve(undefined),
84
- } as unknown as KindOfQuantity;
85
- }
86
- return undefined;
87
- },
88
- });
89
- const prop: TypedPrimitiveValue = {
90
- type: "Double",
91
- value: 1.23,
92
- koqName: "X.Y",
93
- };
94
- expect(await formatter(prop)).to.eq("DEFAULT");
95
- expect(defaultFormatter).to.be.calledOnceWith(prop);
96
- });
97
-
98
- it("returns default formatter result when KoQ doesn't specify presentation format", async () => {
99
- schemaContext.getSchema.resolves({
100
- name: "X",
101
- getItem: async (name: string) => {
102
- if (name === "Y") {
103
- return {
104
- persistenceUnit: Promise.resolve({
105
- unitSystem: Promise.resolve({
106
- name: "metric",
107
- } as UnitSystem),
108
- } as Unit),
109
- presentationFormats: [],
110
- defaultPresentationFormat: undefined,
111
- } as unknown as KindOfQuantity;
112
- }
113
- return undefined;
114
- },
115
- });
116
- const prop: TypedPrimitiveValue = {
117
- type: "Double",
118
- value: 1.23,
119
- koqName: "X.Y",
120
- };
121
- expect(await formatter(prop)).to.eq("DEFAULT");
122
- expect(defaultFormatter).to.be.calledOnceWith(prop);
123
- });
124
-
125
- it("returns koq formatter result when presentation format is found in koq formats list", async () => {
126
- initFormatter("metric");
127
- const persistenceUnit = createUnit("schema.persistence_unit", "metric");
128
- const presentationUnit = createUnit("schema.presentation_unit", "metric");
129
- const presentationFormatProps = {} as SchemaItemFormatProps;
130
- schemaContext.getSchema.resolves({
131
- name: "schema",
132
- getItem: async (name: string) => {
133
- if (name === "koq") {
134
- return {
135
- schemaItemType: SchemaItemType.KindOfQuantity,
136
- persistenceUnit: Promise.resolve(persistenceUnit),
137
- presentationFormats: [
138
- {
139
- units: [[presentationUnit, "presentation unit"]],
140
- toJSON: () => presentationFormatProps,
141
- } as unknown as Format,
142
- ],
143
- defaultPresentationFormat: undefined,
144
- } as unknown as KindOfQuantity;
145
- }
146
- if (name === "persistence_unit") {
147
- return persistenceUnit;
148
- }
149
- if (name === "presentation_unit") {
150
- return presentationUnit;
151
- }
152
- return undefined;
153
- },
154
- });
155
-
156
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
157
- const quantityFormat = {} as unknown as QuantityFormat;
158
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
159
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
160
- applyFormatting: koqFormatterStub,
161
- } as unknown as FormatterSpec);
162
-
163
- expect(
164
- await formatter({
165
- type: "Double",
166
- value: 1.23,
167
- koqName: "schema.koq",
168
- }),
169
- ).to.eq("KOQ FORMAT");
170
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly(
171
- "",
172
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
173
- presentationFormatProps,
174
- );
175
- expect(createFormatSpecStub).to.be.calledOnceWithExactly(
176
- "",
177
- quantityFormat,
178
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
179
- sinon.match((arg) => arg.name === persistenceUnit.fullName),
180
- );
181
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
182
- });
183
-
184
- it("returns koq formatter result when persistence unit system matches requested unit system", async () => {
185
- initFormatter("imperial");
186
-
187
- const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
188
- schemaContext.getSchema.resolves({
189
- name: "schema",
190
- getItem: async (name: string) => {
191
- if (name === "koq") {
192
- return {
193
- schemaItemType: SchemaItemType.KindOfQuantity,
194
- persistenceUnit: Promise.resolve(persistenceUnit),
195
- presentationFormats: [],
196
- defaultPresentationFormat: undefined,
197
- } as unknown as KindOfQuantity;
198
- }
199
- if (name === "persistence_unit") {
200
- return persistenceUnit;
201
- }
202
- return undefined;
203
- },
204
- });
205
-
206
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
207
- const quantityFormat = {} as unknown as QuantityFormat;
208
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
209
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
210
- applyFormatting: koqFormatterStub,
211
- } as unknown as FormatterSpec);
212
-
213
- expect(
214
- await formatter({
215
- type: "Double",
216
- value: 1.23,
217
- koqName: "schema.koq",
218
- }),
219
- ).to.eq("KOQ FORMAT");
220
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly(
221
- "",
222
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
223
- sinon.match((arg: SchemaItemFormatProps) => arg.composite!.units[0].name === persistenceUnit.fullName),
224
- );
225
- expect(createFormatSpecStub).to.be.calledOnceWithExactly(
226
- "",
227
- quantityFormat,
228
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
229
- sinon.match((arg) => arg.name === persistenceUnit.fullName),
230
- );
231
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
232
- });
233
-
234
- it("returns koq formatter result when default presentation unit is of requested unit system", async () => {
235
- initFormatter("usCustomary");
236
-
237
- const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
238
- const defaultPresentationUnit = createUnit("schema.presentation_unit", "usCustomary");
239
- const defaultPresentationFormatProps = {} as SchemaItemFormatProps;
240
- schemaContext.getSchema.resolves({
241
- name: "schema",
242
- getItem: async (name: string) => {
243
- if (name === "koq") {
244
- return {
245
- schemaItemType: SchemaItemType.KindOfQuantity,
246
- persistenceUnit: Promise.resolve(persistenceUnit),
247
- presentationFormats: [],
248
- defaultPresentationFormat: {
249
- units: [[defaultPresentationUnit, "presentation unit"]],
250
- toJSON: () => defaultPresentationFormatProps,
251
- } as unknown as Format,
252
- } as unknown as KindOfQuantity;
253
- }
254
- if (name === "persistence_unit") {
255
- return persistenceUnit;
256
- }
257
- if (name === "presentation_unit") {
258
- return defaultPresentationUnit;
259
- }
260
- return undefined;
261
- },
262
- });
263
-
264
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
265
- const quantityFormat = {} as unknown as QuantityFormat;
266
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
267
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
268
- applyFormatting: koqFormatterStub,
269
- } as unknown as FormatterSpec);
270
-
271
- expect(
272
- await formatter({
273
- type: "Double",
274
- value: 1.23,
275
- koqName: "schema.koq",
276
- }),
277
- ).to.eq("KOQ FORMAT");
278
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly(
279
- "",
280
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
281
- defaultPresentationFormatProps,
282
- );
283
- expect(createFormatSpecStub).to.be.calledOnceWithExactly(
284
- "",
285
- quantityFormat,
286
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
287
- sinon.match((arg) => arg.name === persistenceUnit.fullName),
288
- );
289
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
290
- });
291
-
292
- it("returns koq formatter result when koq uses override format", async () => {
293
- initFormatter("usSurvey");
294
-
295
- const persistenceUnit = createUnit("schema.persistence_unit", "metric");
296
- const presentationUnit = createUnit("schema.presentation_unit", "usSurvey");
297
- const overrideFormat = new OverrideFormat({ fullName: "schema.base_format", toJSON: () => ({}) } as Format, undefined, [
298
- [presentationUnit, "presentation unit"],
299
- ]);
300
- schemaContext.getSchema.resolves({
301
- name: "schema",
302
- getItem: async (name: string) => {
303
- if (name === "koq") {
304
- return {
305
- schemaItemType: SchemaItemType.KindOfQuantity,
306
- persistenceUnit: Promise.resolve(persistenceUnit),
307
- presentationFormats: [],
308
- defaultPresentationFormat: overrideFormat,
309
- } as unknown as KindOfQuantity;
310
- }
311
- if (name === "persistence_unit") {
312
- return persistenceUnit;
313
- }
314
- if (name === "presentation_unit") {
315
- return presentationUnit;
316
- }
317
- return undefined;
318
- },
319
- });
320
-
321
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
322
- const quantityFormat = {} as unknown as QuantityFormat;
323
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
324
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
325
- applyFormatting: koqFormatterStub,
326
- } as unknown as FormatterSpec);
327
-
328
- expect(
329
- await formatter({
330
- type: "Double",
331
- value: 1.23,
332
- koqName: "schema.koq",
333
- }),
334
- ).to.eq("KOQ FORMAT");
335
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly(
336
- "",
337
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
338
- sinon.match((arg: FormatProps) => arg.composite?.units[0].name === presentationUnit.fullName),
339
- );
340
- expect(createFormatSpecStub).to.be.calledOnceWithExactly(
341
- "",
342
- quantityFormat,
343
- sinon.match((arg) => arg instanceof SchemaUnitProvider),
344
- sinon.match((arg) => arg.name === persistenceUnit.fullName),
345
- );
346
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
347
- });
348
- });
349
-
350
- function createUnit(fullName: string, unitSystem: UnitSystemKey) {
351
- return {
352
- schemaItemType: SchemaItemType.Unit,
353
- fullName,
354
- unitSystem: Promise.resolve({
355
- name: unitSystem,
356
- } as UnitSystem),
357
- } as unknown as Unit;
358
- }
@@ -1,59 +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 { Logger, LogLevel } from "@itwin/core-bentley";
9
- import { createLogger } from "../core-interop/Logging";
10
-
11
- describe("createLogger", () => {
12
- it("checks error severity using core `Logger`", async () => {
13
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
14
- const logger = createLogger(Logger);
15
- expect(logger.isEnabled("test category", "error")).to.be.true;
16
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Error);
17
- });
18
-
19
- it("checks warning severity using core `Logger`", async () => {
20
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
21
- const logger = createLogger(Logger);
22
- expect(logger.isEnabled("test category", "warning")).to.be.true;
23
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Warning);
24
- });
25
-
26
- it("checks info severity using core `Logger`", async () => {
27
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
28
- const logger = createLogger(Logger);
29
- expect(logger.isEnabled("test category", "info")).to.be.true;
30
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Info);
31
- });
32
-
33
- it("checks trace severity using core `Logger`", async () => {
34
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
35
- const logger = createLogger(Logger);
36
- expect(logger.isEnabled("test category", "trace")).to.be.true;
37
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Trace);
38
- });
39
-
40
- it("logs messages using core `Logger`", async () => {
41
- const spies = {
42
- error: sinon.spy(Logger, "logError"),
43
- warn: sinon.spy(Logger, "logWarning"),
44
- info: sinon.spy(Logger, "logInfo"),
45
- trace: sinon.spy(Logger, "logTrace"),
46
- };
47
- const logger = createLogger(Logger);
48
-
49
- logger.logError("c1", "m1");
50
- logger.logWarning("c2", "m2");
51
- logger.logInfo("c3", "m3");
52
- logger.logTrace("c4", "m4");
53
-
54
- expect(spies.error).to.be.calledOnceWithExactly("c1", "m1");
55
- expect(spies.warn).to.be.calledOnceWithExactly("c2", "m2");
56
- expect(spies.info).to.be.calledOnceWithExactly("c3", "m3");
57
- expect(spies.trace).to.be.calledOnceWithExactly("c4", "m4");
58
- });
59
- });