@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,277 +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
- import { expect } from "chai";
6
- import sinon from "sinon";
7
- import { FormatterSpec, Format as QuantityFormat } from "@itwin/core-quantity";
8
- import { OverrideFormat, SchemaItemType, SchemaUnitProvider, } from "@itwin/ecschema-metadata";
9
- import { createValueFormatter } from "../core-interop/Formatting";
10
- describe("createValueFormatter", () => {
11
- const schemaContext = {
12
- getSchema: sinon.stub(),
13
- };
14
- const defaultFormatter = sinon.fake(async () => Promise.resolve("DEFAULT"));
15
- let formatter;
16
- function initFormatter(unitSystem) {
17
- formatter = createValueFormatter({
18
- schemaContext: schemaContext,
19
- unitSystem,
20
- baseFormatter: defaultFormatter,
21
- });
22
- }
23
- beforeEach(() => {
24
- defaultFormatter.resetHistory();
25
- initFormatter();
26
- });
27
- it("returns default formatter result when property doesn't have a KoQ", async () => {
28
- const prop = {
29
- type: "Double",
30
- value: 1.23,
31
- };
32
- expect(await formatter(prop)).to.eq("DEFAULT");
33
- expect(defaultFormatter).to.be.calledOnceWith(prop);
34
- });
35
- it("throws when property references non-existing schema in KoQ", async () => {
36
- schemaContext.getSchema.resolves(undefined);
37
- const prop = {
38
- type: "Double",
39
- value: 1.23,
40
- koqName: "X.Y",
41
- };
42
- await expect(formatter(prop)).to.eventually.be.rejectedWith("Invalid schema");
43
- });
44
- it("throws when property references non-existing KoQ", async () => {
45
- schemaContext.getSchema.resolves({
46
- name: "X",
47
- getItem: async () => undefined,
48
- });
49
- const prop = {
50
- type: "Double",
51
- value: 1.23,
52
- koqName: "X.Y",
53
- };
54
- await expect(formatter(prop)).to.eventually.be.rejectedWith("Invalid kind of quantity");
55
- });
56
- it("returns default formatter result when KoQ doesn't specify persistence unit", async () => {
57
- schemaContext.getSchema.resolves({
58
- name: "X",
59
- getItem: async (name) => {
60
- if (name === "Y") {
61
- return {
62
- persistenceUnit: Promise.resolve(undefined),
63
- };
64
- }
65
- return undefined;
66
- },
67
- });
68
- const prop = {
69
- type: "Double",
70
- value: 1.23,
71
- koqName: "X.Y",
72
- };
73
- expect(await formatter(prop)).to.eq("DEFAULT");
74
- expect(defaultFormatter).to.be.calledOnceWith(prop);
75
- });
76
- it("returns default formatter result when KoQ doesn't specify presentation format", async () => {
77
- schemaContext.getSchema.resolves({
78
- name: "X",
79
- getItem: async (name) => {
80
- if (name === "Y") {
81
- return {
82
- persistenceUnit: Promise.resolve({
83
- unitSystem: Promise.resolve({
84
- name: "metric",
85
- }),
86
- }),
87
- presentationFormats: [],
88
- defaultPresentationFormat: undefined,
89
- };
90
- }
91
- return undefined;
92
- },
93
- });
94
- const prop = {
95
- type: "Double",
96
- value: 1.23,
97
- koqName: "X.Y",
98
- };
99
- expect(await formatter(prop)).to.eq("DEFAULT");
100
- expect(defaultFormatter).to.be.calledOnceWith(prop);
101
- });
102
- it("returns koq formatter result when presentation format is found in koq formats list", async () => {
103
- initFormatter("metric");
104
- const persistenceUnit = createUnit("schema.persistence_unit", "metric");
105
- const presentationUnit = createUnit("schema.presentation_unit", "metric");
106
- const presentationFormatProps = {};
107
- schemaContext.getSchema.resolves({
108
- name: "schema",
109
- getItem: async (name) => {
110
- if (name === "koq") {
111
- return {
112
- schemaItemType: SchemaItemType.KindOfQuantity,
113
- persistenceUnit: Promise.resolve(persistenceUnit),
114
- presentationFormats: [
115
- {
116
- units: [[presentationUnit, "presentation unit"]],
117
- toJSON: () => presentationFormatProps,
118
- },
119
- ],
120
- defaultPresentationFormat: undefined,
121
- };
122
- }
123
- if (name === "persistence_unit") {
124
- return persistenceUnit;
125
- }
126
- if (name === "presentation_unit") {
127
- return presentationUnit;
128
- }
129
- return undefined;
130
- },
131
- });
132
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
133
- const quantityFormat = {};
134
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
135
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
136
- applyFormatting: koqFormatterStub,
137
- });
138
- expect(await formatter({
139
- type: "Double",
140
- value: 1.23,
141
- koqName: "schema.koq",
142
- })).to.eq("KOQ FORMAT");
143
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), presentationFormatProps);
144
- expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
145
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
146
- });
147
- it("returns koq formatter result when persistence unit system matches requested unit system", async () => {
148
- initFormatter("imperial");
149
- const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
150
- schemaContext.getSchema.resolves({
151
- name: "schema",
152
- getItem: async (name) => {
153
- if (name === "koq") {
154
- return {
155
- schemaItemType: SchemaItemType.KindOfQuantity,
156
- persistenceUnit: Promise.resolve(persistenceUnit),
157
- presentationFormats: [],
158
- defaultPresentationFormat: undefined,
159
- };
160
- }
161
- if (name === "persistence_unit") {
162
- return persistenceUnit;
163
- }
164
- return undefined;
165
- },
166
- });
167
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
168
- const quantityFormat = {};
169
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
170
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
171
- applyFormatting: koqFormatterStub,
172
- });
173
- expect(await formatter({
174
- type: "Double",
175
- value: 1.23,
176
- koqName: "schema.koq",
177
- })).to.eq("KOQ FORMAT");
178
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.composite.units[0].name === persistenceUnit.fullName));
179
- expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
180
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
181
- });
182
- it("returns koq formatter result when default presentation unit is of requested unit system", async () => {
183
- initFormatter("usCustomary");
184
- const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
185
- const defaultPresentationUnit = createUnit("schema.presentation_unit", "usCustomary");
186
- const defaultPresentationFormatProps = {};
187
- schemaContext.getSchema.resolves({
188
- name: "schema",
189
- getItem: async (name) => {
190
- if (name === "koq") {
191
- return {
192
- schemaItemType: SchemaItemType.KindOfQuantity,
193
- persistenceUnit: Promise.resolve(persistenceUnit),
194
- presentationFormats: [],
195
- defaultPresentationFormat: {
196
- units: [[defaultPresentationUnit, "presentation unit"]],
197
- toJSON: () => defaultPresentationFormatProps,
198
- },
199
- };
200
- }
201
- if (name === "persistence_unit") {
202
- return persistenceUnit;
203
- }
204
- if (name === "presentation_unit") {
205
- return defaultPresentationUnit;
206
- }
207
- return undefined;
208
- },
209
- });
210
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
211
- const quantityFormat = {};
212
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
213
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
214
- applyFormatting: koqFormatterStub,
215
- });
216
- expect(await formatter({
217
- type: "Double",
218
- value: 1.23,
219
- koqName: "schema.koq",
220
- })).to.eq("KOQ FORMAT");
221
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), defaultPresentationFormatProps);
222
- expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
223
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
224
- });
225
- it("returns koq formatter result when koq uses override format", async () => {
226
- initFormatter("usSurvey");
227
- const persistenceUnit = createUnit("schema.persistence_unit", "metric");
228
- const presentationUnit = createUnit("schema.presentation_unit", "usSurvey");
229
- const overrideFormat = new OverrideFormat({ fullName: "schema.base_format", toJSON: () => ({}) }, undefined, [
230
- [presentationUnit, "presentation unit"],
231
- ]);
232
- schemaContext.getSchema.resolves({
233
- name: "schema",
234
- getItem: async (name) => {
235
- if (name === "koq") {
236
- return {
237
- schemaItemType: SchemaItemType.KindOfQuantity,
238
- persistenceUnit: Promise.resolve(persistenceUnit),
239
- presentationFormats: [],
240
- defaultPresentationFormat: overrideFormat,
241
- };
242
- }
243
- if (name === "persistence_unit") {
244
- return persistenceUnit;
245
- }
246
- if (name === "presentation_unit") {
247
- return presentationUnit;
248
- }
249
- return undefined;
250
- },
251
- });
252
- const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
253
- const quantityFormat = {};
254
- const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
255
- const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
256
- applyFormatting: koqFormatterStub,
257
- });
258
- expect(await formatter({
259
- type: "Double",
260
- value: 1.23,
261
- koqName: "schema.koq",
262
- })).to.eq("KOQ FORMAT");
263
- expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.composite?.units[0].name === presentationUnit.fullName));
264
- expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
265
- expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
266
- });
267
- });
268
- function createUnit(fullName, unitSystem) {
269
- return {
270
- schemaItemType: SchemaItemType.Unit,
271
- fullName,
272
- unitSystem: Promise.resolve({
273
- name: unitSystem,
274
- }),
275
- };
276
- }
277
- //# sourceMappingURL=Formatting.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Formatting.test.js","sourceRoot":"","sources":["../../../src/test/Formatting.test.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,aAAa,EAAE,MAAM,IAAI,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EAGL,cAAc,EAId,cAAc,EAEd,kBAAkB,GAGnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,MAAM,aAAa,GAAG;QACpB,SAAS,EAAE,KAAK,CAAC,IAAI,EAAuB;KAC7C,CAAC;IACF,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5E,IAAI,SAAmC,CAAC;IAExC,SAAS,aAAa,CAAC,UAA0B;QAC/C,SAAS,GAAG,oBAAoB,CAAC;YAC/B,aAAa,EAAE,aAAyC;YACxD,UAAU;YACV,aAAa,EAAE,gBAAgB;SAChC,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,GAAG,EAAE;QACd,gBAAgB,CAAC,YAAY,EAAE,CAAC;QAChC,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACjF,MAAM,IAAI,GAAwB;YAChC,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IA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AAEH,SAAS,UAAU,CAAC,QAAgB,EAAE,UAAyB;IAC7D,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,IAAI;QACnC,QAAQ;QACR,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC;YAC1B,IAAI,EAAE,UAAU;SACH,CAAC;KACE,CAAC;AACvB,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 *--------------------------------------------------------------------------------------------*/\n\nimport { expect } from \"chai\";\nimport sinon from \"sinon\";\nimport { FormatProps, FormatterSpec, Format as QuantityFormat, UnitSystemKey } from \"@itwin/core-quantity\";\nimport {\n Format,\n KindOfQuantity,\n OverrideFormat,\n Schema,\n SchemaContext,\n SchemaItemFormatProps,\n SchemaItemType,\n SchemaKey,\n SchemaUnitProvider,\n Unit,\n UnitSystem,\n} from \"@itwin/ecschema-metadata\";\nimport { IPrimitiveValueFormatter, TypedPrimitiveValue } from \"@itwin/presentation-shared\";\nimport { createValueFormatter } from \"../core-interop/Formatting\";\n\ndescribe(\"createValueFormatter\", () => {\n const schemaContext = {\n getSchema: sinon.stub<[SchemaKey], Schema>(),\n };\n const defaultFormatter = sinon.fake(async () => Promise.resolve(\"DEFAULT\"));\n let formatter: IPrimitiveValueFormatter;\n\n function initFormatter(unitSystem?: UnitSystemKey) {\n formatter = createValueFormatter({\n schemaContext: schemaContext as unknown as SchemaContext,\n unitSystem,\n baseFormatter: defaultFormatter,\n });\n }\n\n beforeEach(() => {\n defaultFormatter.resetHistory();\n initFormatter();\n });\n\n it(\"returns default formatter result when property doesn't have a KoQ\", async () => {\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n };\n expect(await formatter(prop)).to.eq(\"DEFAULT\");\n expect(defaultFormatter).to.be.calledOnceWith(prop);\n });\n\n it(\"throws when property references non-existing schema in KoQ\", async () => {\n schemaContext.getSchema.resolves(undefined);\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n await expect(formatter(prop)).to.eventually.be.rejectedWith(\"Invalid schema\");\n });\n\n it(\"throws when property references non-existing KoQ\", async () => {\n schemaContext.getSchema.resolves({\n name: \"X\",\n getItem: async () => undefined,\n });\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n await expect(formatter(prop)).to.eventually.be.rejectedWith(\"Invalid kind of quantity\");\n });\n\n it(\"returns default formatter result when KoQ doesn't specify persistence unit\", async () => {\n schemaContext.getSchema.resolves({\n name: \"X\",\n getItem: async (name: string) => {\n if (name === \"Y\") {\n return {\n persistenceUnit: Promise.resolve(undefined),\n } as unknown as KindOfQuantity;\n }\n return undefined;\n },\n });\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n expect(await formatter(prop)).to.eq(\"DEFAULT\");\n expect(defaultFormatter).to.be.calledOnceWith(prop);\n });\n\n it(\"returns default formatter result when KoQ doesn't specify presentation format\", async () => {\n schemaContext.getSchema.resolves({\n name: \"X\",\n getItem: async (name: string) => {\n if (name === \"Y\") {\n return {\n persistenceUnit: Promise.resolve({\n unitSystem: Promise.resolve({\n name: \"metric\",\n } as UnitSystem),\n } as Unit),\n presentationFormats: [],\n defaultPresentationFormat: undefined,\n } as unknown as KindOfQuantity;\n }\n return undefined;\n },\n });\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n expect(await formatter(prop)).to.eq(\"DEFAULT\");\n expect(defaultFormatter).to.be.calledOnceWith(prop);\n });\n\n it(\"returns koq formatter result when presentation format is found in koq formats list\", async () => {\n initFormatter(\"metric\");\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"metric\");\n const presentationUnit = createUnit(\"schema.presentation_unit\", \"metric\");\n const presentationFormatProps = {} as SchemaItemFormatProps;\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [\n {\n units: [[presentationUnit, \"presentation unit\"]],\n toJSON: () => presentationFormatProps,\n } as unknown as Format,\n ],\n defaultPresentationFormat: undefined,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n if (name === \"presentation_unit\") {\n return presentationUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n presentationFormatProps,\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n\n it(\"returns koq formatter result when persistence unit system matches requested unit system\", async () => {\n initFormatter(\"imperial\");\n\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"imperial\");\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [],\n defaultPresentationFormat: undefined,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg: SchemaItemFormatProps) => arg.composite!.units[0].name === persistenceUnit.fullName),\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n\n it(\"returns koq formatter result when default presentation unit is of requested unit system\", async () => {\n initFormatter(\"usCustomary\");\n\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"imperial\");\n const defaultPresentationUnit = createUnit(\"schema.presentation_unit\", \"usCustomary\");\n const defaultPresentationFormatProps = {} as SchemaItemFormatProps;\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [],\n defaultPresentationFormat: {\n units: [[defaultPresentationUnit, \"presentation unit\"]],\n toJSON: () => defaultPresentationFormatProps,\n } as unknown as Format,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n if (name === \"presentation_unit\") {\n return defaultPresentationUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n defaultPresentationFormatProps,\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n\n it(\"returns koq formatter result when koq uses override format\", async () => {\n initFormatter(\"usSurvey\");\n\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"metric\");\n const presentationUnit = createUnit(\"schema.presentation_unit\", \"usSurvey\");\n const overrideFormat = new OverrideFormat({ fullName: \"schema.base_format\", toJSON: () => ({}) } as Format, undefined, [\n [presentationUnit, \"presentation unit\"],\n ]);\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [],\n defaultPresentationFormat: overrideFormat,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n if (name === \"presentation_unit\") {\n return presentationUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg: FormatProps) => arg.composite?.units[0].name === presentationUnit.fullName),\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n});\n\nfunction createUnit(fullName: string, unitSystem: UnitSystemKey) {\n return {\n schemaItemType: SchemaItemType.Unit,\n fullName,\n unitSystem: Promise.resolve({\n name: unitSystem,\n } as UnitSystem),\n } as unknown as Unit;\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Logging.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logging.test.d.ts","sourceRoot":"","sources":["../../../src/test/Logging.test.ts"],"names":[],"mappings":""}
@@ -1,52 +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
- import { expect } from "chai";
6
- import sinon from "sinon";
7
- import { Logger, LogLevel } from "@itwin/core-bentley";
8
- import { createLogger } from "../core-interop/Logging";
9
- describe("createLogger", () => {
10
- it("checks error severity using core `Logger`", async () => {
11
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
12
- const logger = createLogger(Logger);
13
- expect(logger.isEnabled("test category", "error")).to.be.true;
14
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Error);
15
- });
16
- it("checks warning severity using core `Logger`", async () => {
17
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
18
- const logger = createLogger(Logger);
19
- expect(logger.isEnabled("test category", "warning")).to.be.true;
20
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Warning);
21
- });
22
- it("checks info severity using core `Logger`", async () => {
23
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
24
- const logger = createLogger(Logger);
25
- expect(logger.isEnabled("test category", "info")).to.be.true;
26
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Info);
27
- });
28
- it("checks trace severity using core `Logger`", async () => {
29
- const spy = sinon.stub(Logger, "isEnabled").returns(true);
30
- const logger = createLogger(Logger);
31
- expect(logger.isEnabled("test category", "trace")).to.be.true;
32
- expect(spy).to.be.calledOnceWith("test category", LogLevel.Trace);
33
- });
34
- it("logs messages using core `Logger`", async () => {
35
- const spies = {
36
- error: sinon.spy(Logger, "logError"),
37
- warn: sinon.spy(Logger, "logWarning"),
38
- info: sinon.spy(Logger, "logInfo"),
39
- trace: sinon.spy(Logger, "logTrace"),
40
- };
41
- const logger = createLogger(Logger);
42
- logger.logError("c1", "m1");
43
- logger.logWarning("c2", "m2");
44
- logger.logInfo("c3", "m3");
45
- logger.logTrace("c4", "m4");
46
- expect(spies.error).to.be.calledOnceWithExactly("c1", "m1");
47
- expect(spies.warn).to.be.calledOnceWithExactly("c2", "m2");
48
- expect(spies.info).to.be.calledOnceWithExactly("c3", "m3");
49
- expect(spies.trace).to.be.calledOnceWithExactly("c4", "m4");
50
- });
51
- });
52
- //# sourceMappingURL=Logging.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logging.test.js","sourceRoot":"","sources":["../../../src/test/Logging.test.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB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,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE5B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,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 *--------------------------------------------------------------------------------------------*/\n\nimport { expect } from \"chai\";\nimport sinon from \"sinon\";\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { createLogger } from \"../core-interop/Logging\";\n\ndescribe(\"createLogger\", () => {\n it(\"checks error severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"error\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Error);\n });\n\n it(\"checks warning severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"warning\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Warning);\n });\n\n it(\"checks info severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"info\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Info);\n });\n\n it(\"checks trace severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"trace\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Trace);\n });\n\n it(\"logs messages using core `Logger`\", async () => {\n const spies = {\n error: sinon.spy(Logger, \"logError\"),\n warn: sinon.spy(Logger, \"logWarning\"),\n info: sinon.spy(Logger, \"logInfo\"),\n trace: sinon.spy(Logger, \"logTrace\"),\n };\n const logger = createLogger(Logger);\n\n logger.logError(\"c1\", \"m1\");\n logger.logWarning(\"c2\", \"m2\");\n logger.logInfo(\"c3\", \"m3\");\n logger.logTrace(\"c4\", \"m4\");\n\n expect(spies.error).to.be.calledOnceWithExactly(\"c1\", \"m1\");\n expect(spies.warn).to.be.calledOnceWithExactly(\"c2\", \"m2\");\n expect(spies.info).to.be.calledOnceWithExactly(\"c3\", \"m3\");\n expect(spies.trace).to.be.calledOnceWithExactly(\"c4\", \"m4\");\n });\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Metadata.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Metadata.test.d.ts","sourceRoot":"","sources":["../../../src/test/Metadata.test.ts"],"names":[],"mappings":""}