@api-client/core 0.14.1 → 0.14.2

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 (49) hide show
  1. package/build/src/browser.d.ts +1 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js.map +1 -1
  4. package/build/src/index.d.ts +1 -1
  5. package/build/src/index.d.ts.map +1 -1
  6. package/build/src/index.js.map +1 -1
  7. package/build/src/modeling/DomainAssociation.d.ts +35 -0
  8. package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
  9. package/build/src/modeling/DomainAssociation.js +42 -5
  10. package/build/src/modeling/DomainAssociation.js.map +1 -1
  11. package/build/src/modeling/Semantics.d.ts +8 -0
  12. package/build/src/modeling/Semantics.d.ts.map +1 -1
  13. package/build/src/modeling/Semantics.js +15 -0
  14. package/build/src/modeling/Semantics.js.map +1 -1
  15. package/build/tsconfig.tsbuildinfo +1 -1
  16. package/data/models/APIC-187.json +3 -3
  17. package/data/models/APIC-188.json +3 -3
  18. package/data/models/APIC-233.json +1 -1
  19. package/data/models/APIC-391.json +2 -2
  20. package/data/models/APIC-483.json +1 -1
  21. package/data/models/APIC-487.json +1 -1
  22. package/data/models/APIC-655.json +1 -1
  23. package/data/models/APIC-689.json +1 -1
  24. package/data/models/APIC-690.json +5 -5
  25. package/data/models/SE-10469.json +1 -1
  26. package/data/models/SE-13092.json +5 -5
  27. package/data/models/SE-22063.json +12 -2
  28. package/data/models/amf-helper-api.json +154 -14
  29. package/data/models/arc-demo-api.json +95 -15
  30. package/data/models/async-api.json +1 -1
  31. package/data/models/example-generator-api.json +366 -26
  32. package/data/models/expanded-api.json +1 -1
  33. package/data/models/flattened-api.json +1 -1
  34. package/data/models/multiple-servers.json +1 -1
  35. package/data/models/oas-3-api.json +1 -1
  36. package/data/models/oas-date.json +1 -1
  37. package/data/models/oas-types.json +1 -1
  38. package/data/models/oas-unions.json +1 -1
  39. package/data/models/petstore.json +1 -1
  40. package/data/models/raml-date.json +1 -1
  41. package/data/models/recursive.json +1 -1
  42. package/data/models/schema-api.json +62 -2
  43. package/data/models/secured-api.json +16 -16
  44. package/data/models/tracked-to-linked.json +4 -4
  45. package/package.json +2 -2
  46. package/src/modeling/DomainAssociation.ts +56 -0
  47. package/src/modeling/Semantics.ts +17 -0
  48. package/tests/unit/modeling/domain_asociation.spec.ts +92 -2
  49. package/tests/unit/modeling/semantics.spec.ts +149 -0
@@ -8,6 +8,7 @@ import {
8
8
  DataDomain,
9
9
  DataFormat,
10
10
  SemanticType,
11
+ type OnDeleteRule,
11
12
  } from '../../../src/index.js'
12
13
 
13
14
  test.group('DomainAssociation.createSchema()', () => {
@@ -23,6 +24,8 @@ test.group('DomainAssociation.createSchema()', () => {
23
24
  assert.isUndefined(schema.bindings)
24
25
  assert.isUndefined(schema.targets)
25
26
  assert.deepEqual(schema.semantics, [])
27
+ assert.isUndefined(schema.onDelete)
28
+ assert.isUndefined(schema.readOnly)
26
29
  })
27
30
 
28
31
  test('creates a schema with provided key', ({ assert }) => {
@@ -43,6 +46,17 @@ test.group('DomainAssociation.createSchema()', () => {
43
46
  assert.deepEqual(schema.semantics, semantics)
44
47
  })
45
48
 
49
+ test('creates a schema with provided onDelete rule', ({ assert }) => {
50
+ const onDelete: OnDeleteRule = 'cascade'
51
+ const schema = DomainAssociation.createSchema({ onDelete })
52
+ assert.equal(schema.onDelete, onDelete)
53
+ })
54
+
55
+ test('creates a schema with provided readOnly rule', ({ assert }) => {
56
+ const schema = DomainAssociation.createSchema({ readOnly: true })
57
+ assert.isTrue(schema.readOnly)
58
+ })
59
+
46
60
  test('creates a schema with provided schema', ({ assert }) => {
47
61
  const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
48
62
  const schema = DomainAssociation.createSchema({ schema: schemaDefinition })
@@ -80,6 +94,8 @@ test.group('DomainAssociation.createSchema()', () => {
80
94
  const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
81
95
  const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
82
96
  const semantics = [{ id: SemanticType.ResourceOwnerIdentifier }]
97
+ const readOnly = true
98
+ const onDelete: OnDeleteRule = 'restrict'
83
99
 
84
100
  const schema = DomainAssociation.createSchema({
85
101
  key,
@@ -90,6 +106,8 @@ test.group('DomainAssociation.createSchema()', () => {
90
106
  bindings,
91
107
  targets,
92
108
  semantics,
109
+ onDelete,
110
+ readOnly,
93
111
  })
94
112
 
95
113
  assert.equal(schema.key, key)
@@ -100,6 +118,8 @@ test.group('DomainAssociation.createSchema()', () => {
100
118
  assert.deepEqual(schema.bindings, bindings)
101
119
  assert.deepEqual(schema.targets, targets)
102
120
  assert.deepEqual(schema.semantics, semantics)
121
+ assert.equal(schema.onDelete, onDelete)
122
+ assert.isTrue(schema.readOnly)
103
123
  })
104
124
 
105
125
  test('creates a schema with cloned bindings', ({ assert }) => {
@@ -145,6 +165,8 @@ test.group('DomainAssociation.constructor()', () => {
145
165
  assert.deepEqual(association.bindings, [])
146
166
  assert.deepEqual(association.targets, [])
147
167
  assert.deepEqual(association.semantics, [])
168
+ assert.isUndefined(association.onDelete)
169
+ assert.isUndefined(association.readOnly)
148
170
  })
149
171
 
150
172
  test('creates an instance with provided key', ({ assert }) => {
@@ -163,6 +185,22 @@ test.group('DomainAssociation.constructor()', () => {
163
185
  assert.deepEqual(association.semantics, semantics)
164
186
  })
165
187
 
188
+ test('creates an instance with provided onDelete rule', ({ assert }) => {
189
+ const dataDomain = new DataDomain()
190
+ const parentKey = 'test-parent'
191
+ const onDelete: OnDeleteRule = 'setNull'
192
+ const association = new DomainAssociation(dataDomain, parentKey, { onDelete })
193
+ assert.equal(association.onDelete, onDelete)
194
+ })
195
+
196
+ test('creates an instance with provided readOnly rule', ({ assert }) => {
197
+ const dataDomain = new DataDomain()
198
+ const parentKey = 'test-parent'
199
+ const readOnly = true
200
+ const association = new DomainAssociation(dataDomain, parentKey, { readOnly })
201
+ assert.isTrue(association.readOnly)
202
+ })
203
+
166
204
  test('creates an instance with provided info', ({ assert }) => {
167
205
  const dataDomain = new DataDomain()
168
206
  const parentKey = 'test-parent'
@@ -220,6 +258,8 @@ test.group('DomainAssociation.constructor()', () => {
220
258
  const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
221
259
  const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
222
260
  const semantics = [{ id: SemanticType.ResourceOwnerIdentifier }]
261
+ const readOnly = false
262
+ const onDelete: OnDeleteRule = 'cascade'
223
263
 
224
264
  const association = new DomainAssociation(dataDomain, parentKey, {
225
265
  key,
@@ -230,6 +270,8 @@ test.group('DomainAssociation.constructor()', () => {
230
270
  bindings,
231
271
  targets,
232
272
  semantics,
273
+ onDelete,
274
+ readOnly,
233
275
  })
234
276
 
235
277
  assert.equal(association.key, key)
@@ -240,6 +282,8 @@ test.group('DomainAssociation.constructor()', () => {
240
282
  assert.deepEqual(association.bindings, bindings)
241
283
  assert.deepEqual(association.targets, targets)
242
284
  assert.deepEqual(association.semantics, semantics)
285
+ assert.equal(association.onDelete, onDelete)
286
+ assert.isFalse(association.readOnly)
243
287
  })
244
288
 
245
289
  test('creates an instance with cloned bindings', ({ assert }) => {
@@ -294,6 +338,8 @@ test.group('DomainAssociation.toJSON()', () => {
294
338
  assert.isUndefined(json.bindings)
295
339
  assert.isUndefined(json.targets)
296
340
  assert.isUndefined(json.semantics)
341
+ assert.isUndefined(json.onDelete)
342
+ assert.isUndefined(json.readOnly)
297
343
  })
298
344
 
299
345
  test('returns a JSON representation with provided key', ({ assert }) => {
@@ -311,7 +357,25 @@ test.group('DomainAssociation.toJSON()', () => {
311
357
  const semantics = [{ id: SemanticType.ResourceOwnerIdentifier }]
312
358
  const association = new DomainAssociation(dataDomain, parentKey, { semantics })
313
359
  const json = association.toJSON()
314
- assert.deepEqual(json.semantics, semantics)
360
+ assert.deepEqual(json.semantics, semantics, 'Semantics are serialized')
361
+ })
362
+
363
+ test('returns a JSON representation with provided onDelete rule', ({ assert }) => {
364
+ const dataDomain = new DataDomain()
365
+ const parentKey = 'test-parent'
366
+ const onDelete: OnDeleteRule = 'cascade'
367
+ const association = new DomainAssociation(dataDomain, parentKey, { onDelete })
368
+ const json = association.toJSON()
369
+ assert.equal(json.onDelete, onDelete, 'onDelete is serialized')
370
+ })
371
+
372
+ test('returns a JSON representation with provided readOnly rule', ({ assert }) => {
373
+ const dataDomain = new DataDomain()
374
+ const parentKey = 'test-parent'
375
+ const readOnly = true
376
+ const association = new DomainAssociation(dataDomain, parentKey, { readOnly })
377
+ const json = association.toJSON()
378
+ assert.isTrue(json.readOnly, 'readOnly is serialized when true')
315
379
  })
316
380
 
317
381
  test('returns a JSON representation with provided info', ({ assert }) => {
@@ -380,6 +444,8 @@ test.group('DomainAssociation.toJSON()', () => {
380
444
  const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
381
445
  const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
382
446
  const semantics = [{ id: SemanticType.ResourceOwnerIdentifier }]
447
+ const readOnly = true
448
+ const onDelete: OnDeleteRule = 'restrict'
383
449
 
384
450
  const association = new DomainAssociation(dataDomain, parentKey, {
385
451
  key,
@@ -390,6 +456,8 @@ test.group('DomainAssociation.toJSON()', () => {
390
456
  bindings,
391
457
  targets,
392
458
  semantics,
459
+ onDelete,
460
+ readOnly,
393
461
  })
394
462
 
395
463
  const json = association.toJSON()
@@ -402,6 +470,8 @@ test.group('DomainAssociation.toJSON()', () => {
402
470
  assert.deepEqual(json.bindings, bindings)
403
471
  assert.deepEqual(json.targets, targets)
404
472
  assert.deepEqual(json.semantics, semantics)
473
+ assert.equal(json.onDelete, onDelete)
474
+ assert.isTrue(json.readOnly)
405
475
  })
406
476
 
407
477
  test('returns a JSON representation with cloned bindings', ({ assert }) => {
@@ -421,7 +491,27 @@ test.group('DomainAssociation.toJSON()', () => {
421
491
  const semantics = [{ id: SemanticType.ResourceOwnerIdentifier }]
422
492
  association.semantics = semantics
423
493
  const json = association.toJSON()
424
- assert.deepEqual(json.semantics, semantics)
494
+ assert.deepEqual(json.semantics, semantics, 'Semantics are serialized after creation')
495
+ })
496
+
497
+ test('returns a JSON representation with onDelete rule when it is set after creation', ({ assert }) => {
498
+ const dataDomain = new DataDomain()
499
+ const parentKey = 'test-parent'
500
+ const association = new DomainAssociation(dataDomain, parentKey)
501
+ const onDelete: OnDeleteRule = 'setNull'
502
+ association.onDelete = onDelete
503
+ const json = association.toJSON()
504
+ assert.equal(json.onDelete, onDelete, 'onDelete is serialized after creation')
505
+ })
506
+
507
+ test('returns a JSON representation with readOnly rule when it is set after creation', ({ assert }) => {
508
+ const dataDomain = new DataDomain()
509
+ const parentKey = 'test-parent'
510
+ const association = new DomainAssociation(dataDomain, parentKey)
511
+ const readOnly = true
512
+ association.readOnly = readOnly
513
+ const json = association.toJSON()
514
+ assert.isTrue(json.readOnly, 'readOnly is serialized after creation when true')
425
515
  })
426
516
 
427
517
  test('returns a JSON representation with cloned targets', ({ assert }) => {
@@ -0,0 +1,149 @@
1
+ import { test } from '@japa/runner'
2
+ import {
3
+ SemanticType,
4
+ SemanticScope,
5
+ isEntitySemantic,
6
+ isPropertySemantic,
7
+ isAssociationSemantic,
8
+ DataSemantics,
9
+ type EntitySemantic,
10
+ type PropertySemantic,
11
+ type AssociationSemantic,
12
+ type DataSemantic,
13
+ } from '../../../src/modeling/Semantics.js'
14
+
15
+ test.group('Semantics', () => {
16
+ test('SemanticType enum should have correct values', ({ assert }) => {
17
+ assert.equal(SemanticType.User, 'https://apinow.app/semantics/entities/#User')
18
+ assert.equal(SemanticType.CreatedTimestamp, 'https://apinow.app/semantics/properties/#CreatedTimestamp')
19
+ assert.equal(SemanticType.UpdatedTimestamp, 'https://apinow.app/semantics/properties/#UpdatedTimestamp')
20
+ assert.equal(SemanticType.DeletedTimestamp, 'https://apinow.app/semantics/properties/#DeletedTimestamp')
21
+ assert.equal(SemanticType.DeletedFlag, 'https://apinow.app/semantics/properties/#DeletedFlag')
22
+ assert.equal(SemanticType.PublicUniqueName, 'https://apinow.app/semantics/properties/#PublicUniqueName')
23
+ assert.equal(SemanticType.UserRole, 'https://apinow.app/semantics/entities/#UserRole')
24
+ assert.equal(
25
+ SemanticType.ResourceOwnerIdentifier,
26
+ 'https://apinow.app/semantics/associations/#ResourceOwnerIdentifier'
27
+ )
28
+ })
29
+
30
+ test('SemanticScope enum should have correct values', ({ assert }) => {
31
+ assert.equal(SemanticScope.Entity, 'Entity')
32
+ assert.equal(SemanticScope.Property, 'Property')
33
+ assert.equal(SemanticScope.Association, 'Association')
34
+ })
35
+
36
+ test('isEntitySemantic type guard', ({ assert }) => {
37
+ const entitySemantic: EntitySemantic = {
38
+ id: SemanticType.User,
39
+ displayName: 'User Entity',
40
+ description: 'Test',
41
+ scope: SemanticScope.Entity,
42
+ }
43
+ const propertySemantic: PropertySemantic = {
44
+ id: SemanticType.CreatedTimestamp,
45
+ displayName: 'Creation Timestamp',
46
+ description: 'Test',
47
+ scope: SemanticScope.Property,
48
+ }
49
+ const associationSemantic: AssociationSemantic = {
50
+ id: SemanticType.ResourceOwnerIdentifier,
51
+ displayName: 'Resource Owner Identifier',
52
+ description: 'Test',
53
+ scope: SemanticScope.Association,
54
+ }
55
+
56
+ assert.isTrue(isEntitySemantic(entitySemantic))
57
+ assert.isFalse(isEntitySemantic(propertySemantic))
58
+ assert.isFalse(isEntitySemantic(associationSemantic))
59
+ })
60
+
61
+ test('isPropertySemantic type guard', ({ assert }) => {
62
+ const entitySemantic: EntitySemantic = {
63
+ id: SemanticType.User,
64
+ displayName: 'User Entity',
65
+ description: 'Test',
66
+ scope: SemanticScope.Entity,
67
+ }
68
+ const propertySemantic: PropertySemantic = {
69
+ id: SemanticType.CreatedTimestamp,
70
+ displayName: 'Creation Timestamp',
71
+ description: 'Test',
72
+ scope: SemanticScope.Property,
73
+ }
74
+ const associationSemantic: AssociationSemantic = {
75
+ id: SemanticType.ResourceOwnerIdentifier,
76
+ displayName: 'Resource Owner Identifier',
77
+ description: 'Test',
78
+ scope: SemanticScope.Association,
79
+ }
80
+
81
+ assert.isFalse(isPropertySemantic(entitySemantic))
82
+ assert.isTrue(isPropertySemantic(propertySemantic))
83
+ assert.isFalse(isPropertySemantic(associationSemantic))
84
+ })
85
+
86
+ test('isAssociationSemantic type guard', ({ assert }) => {
87
+ const entitySemantic: EntitySemantic = {
88
+ id: SemanticType.User,
89
+ displayName: 'User Entity',
90
+ description: 'Test',
91
+ scope: SemanticScope.Entity,
92
+ }
93
+ const propertySemantic: PropertySemantic = {
94
+ id: SemanticType.CreatedTimestamp,
95
+ displayName: 'Creation Timestamp',
96
+ description: 'Test',
97
+ scope: SemanticScope.Property,
98
+ }
99
+ const associationSemantic: AssociationSemantic = {
100
+ id: SemanticType.ResourceOwnerIdentifier,
101
+ displayName: 'Resource Owner Identifier',
102
+ description: 'Test',
103
+ scope: SemanticScope.Association,
104
+ }
105
+
106
+ assert.isFalse(isAssociationSemantic(entitySemantic))
107
+ assert.isFalse(isAssociationSemantic(propertySemantic))
108
+ assert.isTrue(isAssociationSemantic(associationSemantic))
109
+ })
110
+
111
+ test('DataSemantics should contain correct definitions', ({ assert }) => {
112
+ const semanticTypes = Object.values(SemanticType)
113
+ semanticTypes.forEach((type) => {
114
+ const semantic: DataSemantic | undefined = DataSemantics[type]
115
+ assert.isDefined(semantic, `Semantic definition for ${type} should exist`)
116
+ if (!semantic) return
117
+
118
+ assert.equal(semantic.id, type, `ID for ${type} should match`)
119
+ assert.isString(semantic.displayName, `displayName for ${type} should be a string`)
120
+ assert.isNotEmpty(semantic.displayName, `displayName for ${type} should not be empty`)
121
+ assert.isString(semantic.description, `description for ${type} should be a string`)
122
+ assert.isNotEmpty(semantic.description, `description for ${type} should not be empty`)
123
+
124
+ assert.oneOf(semantic.scope, Object.values(SemanticScope), `scope for ${type} should be a valid SemanticScope`)
125
+
126
+ if (isPropertySemantic(semantic)) {
127
+ if (semantic.applicableDataTypes) {
128
+ assert.isArray(semantic.applicableDataTypes, `applicableDataTypes for ${type} should be an array if present`)
129
+ semantic.applicableDataTypes.forEach((dt) => {
130
+ assert.isString(dt, `Each applicableDataType for ${type} should be a string`)
131
+ })
132
+ }
133
+ }
134
+ })
135
+
136
+ // Specific checks for some semantics
137
+ const userSemantic = DataSemantics[SemanticType.User]
138
+ assert.equal(userSemantic.scope, SemanticScope.Entity)
139
+
140
+ const createdTimestampSemantic = DataSemantics[SemanticType.CreatedTimestamp]
141
+ assert.equal(createdTimestampSemantic.scope, SemanticScope.Property)
142
+ if (isPropertySemantic(createdTimestampSemantic)) {
143
+ assert.deepEqual(createdTimestampSemantic.applicableDataTypes, ['datetime'])
144
+ }
145
+
146
+ const resourceOwnerSemantic = DataSemantics[SemanticType.ResourceOwnerIdentifier]
147
+ assert.equal(resourceOwnerSemantic.scope, SemanticScope.Association)
148
+ })
149
+ })