@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,684 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- const chai_1 = require("chai");
11
- const sinon_1 = __importDefault(require("sinon"));
12
- const core_bentley_1 = require("@itwin/core-bentley");
13
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
14
- const Metadata_1 = require("../core-interop/Metadata");
15
- const MetadataInternal_1 = require("../core-interop/MetadataInternal");
16
- describe("createECSchemaProvider", () => {
17
- describe("getSchema", () => {
18
- it("returns schema from schema context", async () => {
19
- const matchSchemaName = sinon_1.default.match((key) => key.compareByName("x"));
20
- const schemaContext = {
21
- getSchema: sinon_1.default
22
- .stub()
23
- .withArgs(matchSchemaName)
24
- .resolves({
25
- name: "y",
26
- }),
27
- };
28
- const provider = (0, Metadata_1.createECSchemaProvider)(schemaContext);
29
- const schema = await provider.getSchema("x");
30
- (0, core_bentley_1.assert)(schema !== undefined);
31
- (0, chai_1.expect)(schemaContext.getSchema).to.be.calledOnceWith(matchSchemaName);
32
- (0, chai_1.expect)(schema.name).to.eq("y");
33
- (0, chai_1.expect)(typeof schema.getClass === "function").to.be.true;
34
- });
35
- // a test for our workaround for https://github.com/iTwin/itwinjs-core/issues/6542
36
- it("handles duplicate schema in cache error", async () => {
37
- const schemaContext = {
38
- getSchema: sinon_1.default.stub(),
39
- };
40
- schemaContext.getSchema.onFirstCall().resolves({ name: "x" });
41
- schemaContext.getSchema.onSecondCall().rejects(new Error("The schema, x.01.02.03, already exists within this cache"));
42
- schemaContext.getSchema.onThirdCall().resolves({ name: "x" });
43
- const provider = (0, Metadata_1.createECSchemaProvider)(schemaContext);
44
- await Promise.all([provider.getSchema("x"), provider.getSchema("x")]);
45
- (0, chai_1.expect)(schemaContext.getSchema).to.be.calledThrice;
46
- });
47
- it(`returns undefined on "schema not found" error`, async () => {
48
- const schemaContext = {
49
- getSchema: sinon_1.default.stub(),
50
- };
51
- schemaContext.getSchema.rejects(new Error("schema not found"));
52
- const provider = (0, Metadata_1.createECSchemaProvider)(schemaContext);
53
- (0, chai_1.expect)(await provider.getSchema("x")).to.be.undefined;
54
- });
55
- it("re-throws SchemaContext errors", async () => {
56
- const schemaContext = {
57
- getSchema: sinon_1.default.stub(),
58
- };
59
- schemaContext.getSchema.rejects(new Error("Unknown error"));
60
- const provider = (0, Metadata_1.createECSchemaProvider)(schemaContext);
61
- await (0, chai_1.expect)(provider.getSchema("x")).to.eventually.be.rejected;
62
- (0, chai_1.expect)(schemaContext.getSchema).to.be.calledOnce;
63
- });
64
- it("returns undefined from schema context", async () => {
65
- const matchSchemaName = sinon_1.default.match((key) => key.compareByName("x"));
66
- const schemaContext = {
67
- getSchema: sinon_1.default.stub().resolves(undefined),
68
- };
69
- const provider = (0, Metadata_1.createECSchemaProvider)(schemaContext);
70
- const schema = await provider.getSchema("x");
71
- // eslint-disable-next-line @typescript-eslint/unbound-method
72
- (0, chai_1.expect)(schemaContext.getSchema).to.be.calledOnceWith(matchSchemaName);
73
- (0, chai_1.expect)(schema).to.be.undefined;
74
- });
75
- });
76
- });
77
- describe("createECSchema", () => {
78
- describe("getClass", () => {
79
- it("returns class from core schema", async () => {
80
- const coreSchema = {
81
- name: "s",
82
- getItem: sinon_1.default.stub().resolves({
83
- fullName: "s.c",
84
- name: "c",
85
- label: "C",
86
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
87
- }),
88
- };
89
- const schema = (0, MetadataInternal_1.createECSchema)(coreSchema);
90
- const result = await schema.getClass("c");
91
- (0, core_bentley_1.assert)(result !== undefined);
92
- // eslint-disable-next-line @typescript-eslint/unbound-method
93
- (0, chai_1.expect)(coreSchema.getItem).to.be.calledOnceWith("c");
94
- (0, chai_1.expect)(result.schema.name).to.eq("s");
95
- (0, chai_1.expect)(result.fullName).to.eq("s.c");
96
- (0, chai_1.expect)(result.name).to.eq("c");
97
- (0, chai_1.expect)(result.label).to.eq("C");
98
- (0, chai_1.expect)(typeof result.is === "function").to.be.true;
99
- });
100
- it("returns undefined from core schema", async () => {
101
- const coreSchema = {
102
- name: "s",
103
- getItem: sinon_1.default.stub().resolves(undefined),
104
- };
105
- const schema = (0, MetadataInternal_1.createECSchema)(coreSchema);
106
- const result = await schema.getClass("c");
107
- // eslint-disable-next-line @typescript-eslint/unbound-method
108
- (0, chai_1.expect)(coreSchema.getItem).to.be.calledOnceWith("c");
109
- (0, chai_1.expect)(result).to.be.undefined;
110
- });
111
- });
112
- });
113
- describe("createECClass", () => {
114
- const schema = {
115
- name: "s",
116
- async getClass() {
117
- return undefined;
118
- },
119
- };
120
- it("creates class using schema from core class", async () => {
121
- const coreClass = {
122
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
123
- fullName: "s.c",
124
- name: "c",
125
- label: "C",
126
- schema: { name: "core-schema" },
127
- };
128
- const result = (0, MetadataInternal_1.createECClass)(coreClass);
129
- (0, chai_1.expect)(result.schema.name).to.eq("core-schema");
130
- });
131
- it("creates entity class from core class", async () => {
132
- const coreClass = {
133
- fullName: "s.c",
134
- name: "c",
135
- label: "C",
136
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
137
- };
138
- const result = (0, MetadataInternal_1.createECClass)(coreClass, schema);
139
- (0, chai_1.expect)(result.isEntityClass()).to.be.true;
140
- (0, chai_1.expect)(result.isRelationshipClass()).to.be.false;
141
- (0, chai_1.expect)(result.isStructClass()).to.be.false;
142
- (0, chai_1.expect)(result.isMixin()).to.be.false;
143
- (0, chai_1.expect)(result.schema.name).to.eq("s");
144
- (0, chai_1.expect)(result.fullName).to.eq("s.c");
145
- (0, chai_1.expect)(result.name).to.eq("c");
146
- (0, chai_1.expect)(result.label).to.eq("C");
147
- (0, chai_1.expect)(typeof result.is === "function").to.be.true;
148
- });
149
- it("creates relationship class from core class", async () => {
150
- const coreClass = {
151
- fullName: "s.c",
152
- name: "c",
153
- label: "C",
154
- schemaItemType: ecschema_metadata_1.SchemaItemType.RelationshipClass,
155
- };
156
- const result = (0, MetadataInternal_1.createECClass)(coreClass, schema);
157
- (0, chai_1.expect)(result.isEntityClass()).to.be.false;
158
- (0, chai_1.expect)(result.isRelationshipClass()).to.be.true;
159
- (0, chai_1.expect)(result.isStructClass()).to.be.false;
160
- (0, chai_1.expect)(result.isMixin()).to.be.false;
161
- (0, chai_1.expect)(result.schema.name).to.eq("s");
162
- (0, chai_1.expect)(result.fullName).to.eq("s.c");
163
- (0, chai_1.expect)(result.name).to.eq("c");
164
- (0, chai_1.expect)(result.label).to.eq("C");
165
- (0, chai_1.expect)(typeof result.is === "function").to.be.true;
166
- });
167
- it("creates struct class from core class", async () => {
168
- const coreClass = {
169
- fullName: "s.c",
170
- name: "c",
171
- label: "C",
172
- schemaItemType: ecschema_metadata_1.SchemaItemType.StructClass,
173
- };
174
- const result = (0, MetadataInternal_1.createECClass)(coreClass, schema);
175
- (0, chai_1.expect)(result.isEntityClass()).to.be.false;
176
- (0, chai_1.expect)(result.isRelationshipClass()).to.be.false;
177
- (0, chai_1.expect)(result.isStructClass()).to.be.true;
178
- (0, chai_1.expect)(result.isMixin()).to.be.false;
179
- (0, chai_1.expect)(result.schema.name).to.eq("s");
180
- (0, chai_1.expect)(result.fullName).to.eq("s.c");
181
- (0, chai_1.expect)(result.name).to.eq("c");
182
- (0, chai_1.expect)(result.label).to.eq("C");
183
- (0, chai_1.expect)(typeof result.is === "function").to.be.true;
184
- });
185
- it("creates mixin from core class", async () => {
186
- const coreClass = {
187
- fullName: "s.c",
188
- name: "c",
189
- label: "C",
190
- schemaItemType: ecschema_metadata_1.SchemaItemType.Mixin,
191
- };
192
- const result = (0, MetadataInternal_1.createECClass)(coreClass, schema);
193
- (0, chai_1.expect)(result.isEntityClass()).to.be.false;
194
- (0, chai_1.expect)(result.isRelationshipClass()).to.be.false;
195
- (0, chai_1.expect)(result.isStructClass()).to.be.false;
196
- (0, chai_1.expect)(result.isMixin()).to.be.true;
197
- (0, chai_1.expect)(result.schema.name).to.eq("s");
198
- (0, chai_1.expect)(result.fullName).to.eq("s.c");
199
- (0, chai_1.expect)(result.name).to.eq("c");
200
- (0, chai_1.expect)(result.label).to.eq("C");
201
- (0, chai_1.expect)(typeof result.is === "function").to.be.true;
202
- });
203
- it("throws when creating class from non-class core schema item", async () => {
204
- const coreClass = {
205
- schemaItemType: ecschema_metadata_1.SchemaItemType.Constant,
206
- fullName: "s.c",
207
- name: "c",
208
- label: "C",
209
- };
210
- (0, chai_1.expect)(() => (0, MetadataInternal_1.createECClass)(coreClass, schema)).to.throw();
211
- });
212
- describe("is", () => {
213
- const coreClass = {
214
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
215
- fullName: "s.c",
216
- name: "c",
217
- label: "C",
218
- is: sinon_1.default.stub().resolves(true),
219
- };
220
- beforeEach(() => {
221
- coreClass.is.resetHistory();
222
- });
223
- it("handles CoreClass override", async () => {
224
- const class1 = (0, MetadataInternal_1.createECClass)(coreClass, schema);
225
- const class2 = (0, MetadataInternal_1.createECClass)({
226
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
227
- fullName: "s.c2",
228
- name: "c2",
229
- label: "C2",
230
- }, schema);
231
- const result = await class1.is(class2);
232
- // eslint-disable-next-line @typescript-eslint/unbound-method
233
- (0, chai_1.expect)(coreClass.is).to.be.calledOnceWithExactly("c2", "s");
234
- (0, chai_1.expect)(result).to.be.true;
235
- });
236
- it("handles class and schema names override", async () => {
237
- const class1 = (0, MetadataInternal_1.createECClass)(coreClass, schema);
238
- const result = await class1.is("a", "b");
239
- // eslint-disable-next-line @typescript-eslint/unbound-method
240
- (0, chai_1.expect)(coreClass.is).to.be.calledOnceWithExactly("a", "b");
241
- (0, chai_1.expect)(result).to.be.true;
242
- });
243
- });
244
- describe("getProperties", () => {
245
- it("returns properties from core class", async () => {
246
- const coreClass = {
247
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
248
- fullName: "s.c",
249
- name: "c",
250
- label: "C",
251
- getProperties: sinon_1.default.stub().resolves([
252
- {
253
- isArray: () => false,
254
- isStruct: () => false,
255
- isEnumeration: () => false,
256
- isNavigation: () => false,
257
- isPrimitive: () => true,
258
- },
259
- ]),
260
- };
261
- const ecClass = (0, MetadataInternal_1.createECClass)(coreClass, schema);
262
- const properties = await ecClass.getProperties();
263
- // eslint-disable-next-line @typescript-eslint/unbound-method
264
- (0, chai_1.expect)(coreClass.getProperties).to.be.calledOnce;
265
- (0, chai_1.expect)(properties).to.not.be.empty;
266
- });
267
- });
268
- describe("getProperty", () => {
269
- it("returns property from core class", async () => {
270
- const coreClass = {
271
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
272
- fullName: "s.c",
273
- name: "c",
274
- label: "C",
275
- getProperty: sinon_1.default.stub().resolves({
276
- isArray: () => false,
277
- isStruct: () => false,
278
- isEnumeration: () => false,
279
- isNavigation: () => false,
280
- isPrimitive: () => true,
281
- }),
282
- };
283
- const ecClass = (0, MetadataInternal_1.createECClass)(coreClass, schema);
284
- const prop = await ecClass.getProperty("p");
285
- // eslint-disable-next-line @typescript-eslint/unbound-method
286
- (0, chai_1.expect)(coreClass.getProperty).to.be.calledOnceWith("p", true);
287
- (0, chai_1.expect)(prop).to.not.be.undefined;
288
- });
289
- it("returns undefined from core class", async () => {
290
- const coreClass = {
291
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
292
- fullName: "s.c",
293
- name: "c",
294
- label: "C",
295
- getProperty: sinon_1.default.stub().resolves(undefined),
296
- };
297
- const ecClass = (0, MetadataInternal_1.createECClass)(coreClass, schema);
298
- const prop = await ecClass.getProperty("p");
299
- // eslint-disable-next-line @typescript-eslint/unbound-method
300
- (0, chai_1.expect)(coreClass.getProperty).to.be.calledOnceWith("p", true);
301
- (0, chai_1.expect)(prop).to.be.undefined;
302
- });
303
- });
304
- describe("Relationship class", () => {
305
- const coreRelationshipClass = {
306
- schemaItemType: ecschema_metadata_1.SchemaItemType.RelationshipClass,
307
- fullName: "Schema.TestRelationship",
308
- name: "TestRelationship",
309
- label: "Test relationship",
310
- };
311
- describe("direction", () => {
312
- it("returns forward direction from core relationship", async () => {
313
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, strengthDirection: ecschema_metadata_1.StrengthDirection.Forward }, schema);
314
- (0, chai_1.expect)(rel.direction).to.eq("Forward");
315
- });
316
- it("returns backward direction from core relationship", async () => {
317
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, strengthDirection: ecschema_metadata_1.StrengthDirection.Backward }, schema);
318
- (0, chai_1.expect)(rel.direction).to.eq("Backward");
319
- });
320
- });
321
- describe("source & target", () => {
322
- it("returns source constraint", () => {
323
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, source: {} }, schema);
324
- (0, chai_1.expect)(rel.source).to.not.be.undefined;
325
- });
326
- it("returns target constraint", () => {
327
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, target: {} }, schema);
328
- (0, chai_1.expect)(rel.target).to.not.be.undefined;
329
- });
330
- describe("ECRelationshipConstraint implementation", () => {
331
- it("returns undefined multiplicity from core constraint", () => {
332
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, source: { multiplicity: undefined } }, schema);
333
- (0, chai_1.expect)(rel.source.multiplicity).to.be.undefined;
334
- });
335
- it("returns multiplicity from core constraint", () => {
336
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, source: { multiplicity: new ecschema_metadata_1.RelationshipMultiplicity(123, 456) } }, schema);
337
- (0, chai_1.expect)(rel.source.multiplicity).to.deep.eq({ lowerLimit: 123, upperLimit: 456 });
338
- });
339
- it("returns polymorphic flag from core constraint", () => {
340
- [
341
- { in: undefined, expectation: false },
342
- { in: false, expectation: false },
343
- { in: true, expectation: true },
344
- ].forEach((testEntry) => {
345
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, source: { polymorphic: testEntry.in } }, schema);
346
- (0, chai_1.expect)(rel.source.polymorphic).to.eq(testEntry.expectation);
347
- });
348
- });
349
- it("returns abstract constraint from core constraint", async () => {
350
- const coreAbstractConstraint = {
351
- schemaItemType: ecschema_metadata_1.SchemaItemType.EntityClass,
352
- fullName: "Schema.TestAbstractConstraint",
353
- name: "TestAbstractConstraint",
354
- label: "Test abstract constraint",
355
- };
356
- const rel = (0, MetadataInternal_1.createECClass)({ ...coreRelationshipClass, source: { abstractConstraint: Promise.resolve(coreAbstractConstraint) } }, schema);
357
- const constraint = (await rel.source.abstractConstraint);
358
- (0, chai_1.expect)(constraint.isEntityClass()).to.be.true;
359
- (0, chai_1.expect)(constraint.fullName).to.eq(coreAbstractConstraint.fullName);
360
- });
361
- });
362
- });
363
- });
364
- });
365
- describe("createECProperty", () => {
366
- const propertyClass = {};
367
- const propertyStub = {
368
- isArray: () => false,
369
- isEnumeration: () => false,
370
- isNavigation: () => false,
371
- isPrimitive: () => false,
372
- isStruct: () => false,
373
- fullName: "",
374
- name: "",
375
- };
376
- describe("Primitive property", () => {
377
- it("creates property from core property", async () => {
378
- const coreProperty = {
379
- ...propertyStub,
380
- isPrimitive: () => true,
381
- name: "test-property",
382
- label: "Test property",
383
- extendedTypeName: "extended",
384
- };
385
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
386
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
387
- (0, chai_1.expect)(property.isArray()).to.be.false;
388
- (0, chai_1.expect)(property.isEnumeration()).to.be.false;
389
- (0, chai_1.expect)(property.isNavigation()).to.be.false;
390
- (0, chai_1.expect)(property.isPrimitive()).to.be.true;
391
- (0, chai_1.expect)(property.isStruct()).to.be.false;
392
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
393
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
394
- (0, chai_1.expect)(property.extendedTypeName).to.eq(coreProperty.extendedTypeName);
395
- });
396
- it("maps primitive types", async () => {
397
- const types = [
398
- [ecschema_metadata_1.PrimitiveType.Binary, "Binary"],
399
- [ecschema_metadata_1.PrimitiveType.Boolean, "Boolean"],
400
- [ecschema_metadata_1.PrimitiveType.DateTime, "DateTime"],
401
- [ecschema_metadata_1.PrimitiveType.Double, "Double"],
402
- [ecschema_metadata_1.PrimitiveType.IGeometry, "IGeometry"],
403
- [ecschema_metadata_1.PrimitiveType.Integer, "Integer"],
404
- [ecschema_metadata_1.PrimitiveType.Long, "Long"],
405
- [ecschema_metadata_1.PrimitiveType.Point2d, "Point2d"],
406
- [ecschema_metadata_1.PrimitiveType.Point3d, "Point3d"],
407
- [ecschema_metadata_1.PrimitiveType.String, "String"],
408
- ];
409
- types.forEach(([coreType, expectation]) => {
410
- const coreProperty = {
411
- ...propertyStub,
412
- isPrimitive: () => true,
413
- name: "test-property",
414
- primitiveType: coreType,
415
- };
416
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
417
- (0, chai_1.expect)(property.primitiveType).to.eq(expectation);
418
- });
419
- const uninitializedTypes = [undefined, ecschema_metadata_1.PrimitiveType.Uninitialized];
420
- uninitializedTypes.forEach((coreType) => {
421
- const uninitializedProperty = (0, MetadataInternal_1.createECProperty)({
422
- ...propertyStub,
423
- isPrimitive: () => true,
424
- name: "test-property",
425
- primitiveType: coreType,
426
- }, propertyClass);
427
- (0, chai_1.expect)(() => uninitializedProperty.primitiveType).to.throw();
428
- });
429
- });
430
- it("maps kind of quantity", async () => {
431
- const coreProperty = {
432
- ...propertyStub,
433
- isPrimitive: () => true,
434
- name: "test-property",
435
- kindOfQuantity: Promise.resolve({
436
- fullName: "SchemaName.TestKoq",
437
- schema: {
438
- name: "SchemaName",
439
- },
440
- }),
441
- };
442
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
443
- const koq = (await property.kindOfQuantity);
444
- (0, chai_1.expect)(koq.fullName).to.eq("SchemaName.TestKoq");
445
- (0, chai_1.expect)(await (0, MetadataInternal_1.createECProperty)({ ...coreProperty, kindOfQuantity: undefined }, propertyClass).kindOfQuantity).to.be.undefined;
446
- });
447
- });
448
- describe("Navigation property", () => {
449
- it("creates property from core property", async () => {
450
- const coreProperty = {
451
- ...propertyStub,
452
- isNavigation: () => true,
453
- name: "test-property",
454
- label: "Test property",
455
- };
456
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
457
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
458
- (0, chai_1.expect)(property.isArray()).to.be.false;
459
- (0, chai_1.expect)(property.isEnumeration()).to.be.false;
460
- (0, chai_1.expect)(property.isNavigation()).to.be.true;
461
- (0, chai_1.expect)(property.isPrimitive()).to.be.false;
462
- (0, chai_1.expect)(property.isStruct()).to.be.false;
463
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
464
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
465
- });
466
- it("maps direction", async () => {
467
- const map = [
468
- [ecschema_metadata_1.StrengthDirection.Backward, "Backward"],
469
- [ecschema_metadata_1.StrengthDirection.Forward, "Forward"],
470
- ];
471
- map.forEach(([coreDirection, expectation]) => {
472
- const coreProperty = {
473
- ...propertyStub,
474
- isNavigation: () => true,
475
- name: "test-property",
476
- direction: coreDirection,
477
- };
478
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
479
- (0, chai_1.expect)(property.direction).to.eq(expectation);
480
- });
481
- });
482
- it("returns relationship class", async () => {
483
- const coreProperty = {
484
- ...propertyStub,
485
- isNavigation: () => true,
486
- name: "test-property",
487
- relationshipClass: Promise.resolve({
488
- fullName: "SchemaName.RelationshipClass",
489
- schema: {
490
- name: "SchemaName",
491
- },
492
- }),
493
- };
494
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
495
- const relationshipClass = await property.relationshipClass;
496
- (0, chai_1.expect)(relationshipClass.fullName).to.eq("SchemaName.RelationshipClass");
497
- });
498
- });
499
- describe("Enumeration property", () => {
500
- it("creates property from core property", async () => {
501
- const coreProperty = {
502
- ...propertyStub,
503
- isEnumeration: () => true,
504
- name: "test-property",
505
- label: "Test property",
506
- extendedTypeName: "extended",
507
- };
508
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
509
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
510
- (0, chai_1.expect)(property.isArray()).to.be.false;
511
- (0, chai_1.expect)(property.isEnumeration()).to.be.true;
512
- (0, chai_1.expect)(property.isNavigation()).to.be.false;
513
- (0, chai_1.expect)(property.isPrimitive()).to.be.false;
514
- (0, chai_1.expect)(property.isStruct()).to.be.false;
515
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
516
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
517
- (0, chai_1.expect)(property.extendedTypeName).to.eq(coreProperty.extendedTypeName);
518
- });
519
- it("returns enumeration", async () => {
520
- const coreProperty = {
521
- ...propertyStub,
522
- isEnumeration: () => true,
523
- name: "test-property",
524
- enumeration: Promise.resolve({
525
- schema: {
526
- name: "SchemaName",
527
- },
528
- }),
529
- };
530
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
531
- (0, chai_1.expect)(await property.enumeration).to.not.be.undefined;
532
- });
533
- describe("ECEnumeration implementation", () => {
534
- const coreEnumeration = {
535
- schema: {
536
- name: "SchemaName",
537
- },
538
- isStrict: false,
539
- type: undefined,
540
- enumerators: new Array(),
541
- };
542
- const coreEnumerationProperty = {
543
- ...propertyStub,
544
- isEnumeration: () => true,
545
- name: "test-property",
546
- enumeration: Promise.resolve(coreEnumeration),
547
- };
548
- let property;
549
- beforeEach(async () => {
550
- property = (0, MetadataInternal_1.createECProperty)(coreEnumerationProperty, propertyClass);
551
- });
552
- it("returns `isStrict` flag", async () => {
553
- coreEnumeration.isStrict = true;
554
- const enumeration = (await property.enumeration);
555
- (0, chai_1.expect)(enumeration.isStrict).to.be.true;
556
- });
557
- it("maps enumeration type", async () => {
558
- const typesMap = [
559
- [ecschema_metadata_1.PrimitiveType.String, "String"],
560
- [ecschema_metadata_1.PrimitiveType.Integer, "Number"],
561
- [undefined, "Number"],
562
- ];
563
- const typeStub = sinon_1.default.stub(coreEnumeration, "type");
564
- for (const [coreType, expectation] of typesMap) {
565
- typeStub.reset();
566
- typeStub.get(() => coreType);
567
- const enumeration = (await property.enumeration);
568
- (0, chai_1.expect)(enumeration.type).to.eq(expectation);
569
- }
570
- });
571
- it("returns enumerators", async () => {
572
- coreEnumeration.enumerators = [
573
- { name: "1", value: 1, label: "One", description: "Test one" },
574
- { name: "2", value: 2 },
575
- ];
576
- const enumeration = (await property.enumeration);
577
- (0, chai_1.expect)(enumeration.enumerators).to.deep.eq(coreEnumeration.enumerators);
578
- });
579
- });
580
- });
581
- describe("Struct property", () => {
582
- it("creates property from core property", async () => {
583
- const coreProperty = {
584
- ...propertyStub,
585
- isStruct: () => true,
586
- name: "test-property",
587
- label: "Test property",
588
- };
589
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
590
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
591
- (0, chai_1.expect)(property.isArray()).to.be.false;
592
- (0, chai_1.expect)(property.isEnumeration()).to.be.false;
593
- (0, chai_1.expect)(property.isNavigation()).to.be.false;
594
- (0, chai_1.expect)(property.isPrimitive()).to.be.false;
595
- (0, chai_1.expect)(property.isStruct()).to.be.true;
596
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
597
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
598
- });
599
- it("returns struct class", async () => {
600
- const coreProperty = {
601
- ...propertyStub,
602
- isStruct: () => true,
603
- name: "test-property",
604
- structClass: {
605
- fullName: "SchemaName.StructClass",
606
- schema: {
607
- name: "SchemaName",
608
- },
609
- },
610
- };
611
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
612
- (0, chai_1.expect)(property.structClass.fullName).to.eq("SchemaName.StructClass");
613
- });
614
- });
615
- describe("Array property", () => {
616
- it("creates primitive array property from core property", async () => {
617
- const coreProperty = {
618
- ...propertyStub,
619
- isArray: () => true,
620
- isPrimitive: () => true,
621
- name: "test-property",
622
- label: "Test property",
623
- minOccurs: 123,
624
- maxOccurs: 456,
625
- };
626
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
627
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
628
- (0, chai_1.expect)(property.isArray()).to.be.true;
629
- (0, chai_1.expect)(property.isEnumeration()).to.be.false;
630
- (0, chai_1.expect)(property.isNavigation()).to.be.false;
631
- (0, chai_1.expect)(property.isPrimitive()).to.be.true;
632
- (0, chai_1.expect)(property.isStruct()).to.be.false;
633
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
634
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
635
- (0, chai_1.expect)(property.minOccurs).to.eq(123);
636
- (0, chai_1.expect)(property.maxOccurs).to.eq(456);
637
- });
638
- it("creates enumeration array property from core property", async () => {
639
- const coreProperty = {
640
- ...propertyStub,
641
- isArray: () => true,
642
- isEnumeration: () => true,
643
- name: "test-property",
644
- label: "Test property",
645
- minOccurs: 123,
646
- maxOccurs: 456,
647
- };
648
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
649
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
650
- (0, chai_1.expect)(property.isArray()).to.be.true;
651
- (0, chai_1.expect)(property.isEnumeration()).to.be.true;
652
- (0, chai_1.expect)(property.isNavigation()).to.be.false;
653
- (0, chai_1.expect)(property.isPrimitive()).to.be.false;
654
- (0, chai_1.expect)(property.isStruct()).to.be.false;
655
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
656
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
657
- (0, chai_1.expect)(property.minOccurs).to.eq(123);
658
- (0, chai_1.expect)(property.maxOccurs).to.eq(456);
659
- });
660
- it("creates struct array property from core property", async () => {
661
- const coreProperty = {
662
- ...propertyStub,
663
- isArray: () => true,
664
- isStruct: () => true,
665
- name: "test-property",
666
- label: "Test property",
667
- minOccurs: 123,
668
- maxOccurs: 456,
669
- };
670
- const property = (0, MetadataInternal_1.createECProperty)(coreProperty, propertyClass);
671
- (0, chai_1.expect)(property.class).to.eq(propertyClass);
672
- (0, chai_1.expect)(property.isArray()).to.be.true;
673
- (0, chai_1.expect)(property.isEnumeration()).to.be.false;
674
- (0, chai_1.expect)(property.isNavigation()).to.be.false;
675
- (0, chai_1.expect)(property.isPrimitive()).to.be.false;
676
- (0, chai_1.expect)(property.isStruct()).to.be.true;
677
- (0, chai_1.expect)(property.name).to.eq(coreProperty.name);
678
- (0, chai_1.expect)(property.label).to.eq(coreProperty.label);
679
- (0, chai_1.expect)(property.minOccurs).to.eq(123);
680
- (0, chai_1.expect)(property.maxOccurs).to.eq(456);
681
- });
682
- });
683
- });
684
- //# sourceMappingURL=Metadata.test.js.map