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