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