@api-client/core 0.13.6 → 0.14.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 (174) hide show
  1. package/build/src/amf/AmfTypes.d.ts +1 -1
  2. package/build/src/amf/AmfTypes.js +1 -1
  3. package/build/src/amf/AmfTypes.js.map +1 -1
  4. package/build/src/amf/Utils.d.ts +0 -6
  5. package/build/src/amf/Utils.d.ts.map +1 -1
  6. package/build/src/amf/Utils.js +0 -14
  7. package/build/src/amf/Utils.js.map +1 -1
  8. package/build/src/browser.d.ts +1 -0
  9. package/build/src/browser.d.ts.map +1 -1
  10. package/build/src/browser.js +1 -0
  11. package/build/src/browser.js.map +1 -1
  12. package/build/src/index.d.ts +1 -0
  13. package/build/src/index.d.ts.map +1 -1
  14. package/build/src/index.js +1 -0
  15. package/build/src/index.js.map +1 -1
  16. package/build/src/legacy.d.ts +0 -8
  17. package/build/src/legacy.d.ts.map +1 -1
  18. package/build/src/legacy.js +0 -9
  19. package/build/src/legacy.js.map +1 -1
  20. package/build/src/modeling/Bindings.d.ts +1 -1
  21. package/build/src/modeling/Bindings.js.map +1 -1
  22. package/build/src/modeling/DataDomain.js +2 -2
  23. package/build/src/modeling/DataDomain.js.map +1 -1
  24. package/build/src/modeling/DataFormat.d.ts +0 -40
  25. package/build/src/modeling/DataFormat.d.ts.map +1 -1
  26. package/build/src/modeling/DataFormat.js +0 -27
  27. package/build/src/modeling/DataFormat.js.map +1 -1
  28. package/build/src/modeling/DomainAssociation.d.ts +28 -0
  29. package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
  30. package/build/src/modeling/DomainAssociation.js +73 -4
  31. package/build/src/modeling/DomainAssociation.js.map +1 -1
  32. package/build/src/modeling/DomainEntity.d.ts +25 -9
  33. package/build/src/modeling/DomainEntity.d.ts.map +1 -1
  34. package/build/src/modeling/DomainEntity.js +65 -21
  35. package/build/src/modeling/DomainEntity.js.map +1 -1
  36. package/build/src/modeling/DomainFile.d.ts +3 -4
  37. package/build/src/modeling/DomainFile.d.ts.map +1 -1
  38. package/build/src/modeling/DomainFile.js +5 -9
  39. package/build/src/modeling/DomainFile.js.map +1 -1
  40. package/build/src/modeling/DomainImpactAnalysis.d.ts +1 -1
  41. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  42. package/build/src/modeling/DomainImpactAnalysis.js +3 -3
  43. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  44. package/build/src/modeling/DomainModel.d.ts +2 -2
  45. package/build/src/modeling/DomainModel.js +2 -2
  46. package/build/src/modeling/DomainModel.js.map +1 -1
  47. package/build/src/modeling/DomainProperty.d.ts +28 -12
  48. package/build/src/modeling/DomainProperty.d.ts.map +1 -1
  49. package/build/src/modeling/DomainProperty.js +61 -26
  50. package/build/src/modeling/DomainProperty.js.map +1 -1
  51. package/build/src/modeling/Semantics.d.ts +109 -0
  52. package/build/src/modeling/Semantics.d.ts.map +1 -0
  53. package/build/src/modeling/Semantics.js +97 -0
  54. package/build/src/modeling/Semantics.js.map +1 -0
  55. package/build/src/models/CertificateFile.d.ts +2 -3
  56. package/build/src/models/CertificateFile.d.ts.map +1 -1
  57. package/build/src/models/CertificateFile.js +4 -8
  58. package/build/src/models/CertificateFile.js.map +1 -1
  59. package/build/src/models/Folder.d.ts +1 -2
  60. package/build/src/models/Folder.d.ts.map +1 -1
  61. package/build/src/models/Folder.js +2 -4
  62. package/build/src/models/Folder.js.map +1 -1
  63. package/build/src/models/Project.d.ts +2 -3
  64. package/build/src/models/Project.d.ts.map +1 -1
  65. package/build/src/models/Project.js +4 -8
  66. package/build/src/models/Project.js.map +1 -1
  67. package/build/src/models/kinds.d.ts +0 -24
  68. package/build/src/models/kinds.d.ts.map +1 -1
  69. package/build/src/models/kinds.js +0 -24
  70. package/build/src/models/kinds.js.map +1 -1
  71. package/build/src/models/store/File.d.ts +1 -21
  72. package/build/src/models/store/File.d.ts.map +1 -1
  73. package/build/src/models/store/File.js +3 -23
  74. package/build/src/models/store/File.js.map +1 -1
  75. package/build/src/models/store/data_catalog.d.ts +1 -1
  76. package/build/src/models/store/data_catalog.js.map +1 -1
  77. package/build/src/sdk/FilesSdk.js +1 -1
  78. package/build/src/sdk/FilesSdk.js.map +1 -1
  79. package/build/tsconfig.tsbuildinfo +1 -1
  80. package/data/models/example-generator-api.json +22 -22
  81. package/eslint.config.js +1 -0
  82. package/package.json +5 -5
  83. package/src/amf/AmfTypes.ts +1 -1
  84. package/src/amf/Utils.ts +0 -15
  85. package/src/modeling/Bindings.ts +1 -1
  86. package/src/modeling/DataDomain.ts +2 -2
  87. package/src/modeling/DataFormat.ts +0 -48
  88. package/src/modeling/DomainAssociation.ts +66 -3
  89. package/src/modeling/DomainEntity.ts +56 -17
  90. package/src/modeling/DomainFile.ts +5 -9
  91. package/src/modeling/DomainImpactAnalysis.ts +3 -3
  92. package/src/modeling/DomainModel.ts +2 -2
  93. package/src/modeling/DomainProperty.ts +60 -21
  94. package/src/modeling/Semantics.ts +178 -0
  95. package/src/modeling/graph.md +14 -14
  96. package/src/modeling/readme.md +29 -29
  97. package/src/models/CertificateFile.ts +4 -12
  98. package/src/models/Folder.ts +2 -4
  99. package/src/models/Project.ts +4 -8
  100. package/src/models/kinds.ts +0 -25
  101. package/src/models/store/File.ts +4 -35
  102. package/src/models/store/data_catalog.ts +1 -1
  103. package/src/sdk/FilesSdk.ts +1 -1
  104. package/tests/unit/modeling/data_domain_change_observers.spec.ts +11 -10
  105. package/tests/unit/modeling/data_domain_entities.spec.ts +129 -1
  106. package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
  107. package/tests/unit/modeling/domain_asociation.spec.ts +177 -0
  108. package/tests/unit/modeling/domain_entity.spec.ts +27 -26
  109. package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +11 -11
  110. package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +10 -10
  111. package/tests/unit/modeling/domain_file.spec.ts +4 -27
  112. package/tests/unit/modeling/{domain.property.spec.ts → domain_property.spec.ts} +139 -23
  113. package/tests/unit/models/Certificate/from_name.spec.ts +3 -15
  114. package/tests/unit/models/File/constructor.spec.ts +0 -1
  115. package/tests/unit/models/File/new.spec.ts +0 -13
  116. package/tests/unit/models/File/shortcutTo.spec.ts +1 -2
  117. package/tests/unit/models/File/toJSON.spec.ts +0 -13
  118. package/tests/unit/models/File/updateByMeMeta.spec.ts +4 -6
  119. package/tests/unit/models/Folder/create.spec.ts +2 -23
  120. package/tests/unit/models/Project/create.spec.ts +6 -32
  121. package/build/src/amf/AmfShapeGenerator.d.ts +0 -103
  122. package/build/src/amf/AmfShapeGenerator.d.ts.map +0 -1
  123. package/build/src/amf/AmfShapeGenerator.js +0 -416
  124. package/build/src/amf/AmfShapeGenerator.js.map +0 -1
  125. package/build/src/modeling/legacy/DataAssociation.d.ts +0 -284
  126. package/build/src/modeling/legacy/DataAssociation.d.ts.map +0 -1
  127. package/build/src/modeling/legacy/DataAssociation.js +0 -443
  128. package/build/src/modeling/legacy/DataAssociation.js.map +0 -1
  129. package/build/src/modeling/legacy/DataEntity.d.ts +0 -358
  130. package/build/src/modeling/legacy/DataEntity.d.ts.map +0 -1
  131. package/build/src/modeling/legacy/DataEntity.js +0 -855
  132. package/build/src/modeling/legacy/DataEntity.js.map +0 -1
  133. package/build/src/modeling/legacy/DataEntityBuilder.d.ts +0 -162
  134. package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +0 -1
  135. package/build/src/modeling/legacy/DataEntityBuilder.js +0 -221
  136. package/build/src/modeling/legacy/DataEntityBuilder.js.map +0 -1
  137. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +0 -298
  138. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +0 -1
  139. package/build/src/modeling/legacy/DataImpactAnalysis.js +0 -441
  140. package/build/src/modeling/legacy/DataImpactAnalysis.js.map +0 -1
  141. package/build/src/modeling/legacy/DataModel.d.ts +0 -99
  142. package/build/src/modeling/legacy/DataModel.d.ts.map +0 -1
  143. package/build/src/modeling/legacy/DataModel.js +0 -237
  144. package/build/src/modeling/legacy/DataModel.js.map +0 -1
  145. package/build/src/modeling/legacy/DataNamespace.d.ts +0 -340
  146. package/build/src/modeling/legacy/DataNamespace.d.ts.map +0 -1
  147. package/build/src/modeling/legacy/DataNamespace.js +0 -784
  148. package/build/src/modeling/legacy/DataNamespace.js.map +0 -1
  149. package/build/src/modeling/legacy/DataProperty.d.ts +0 -332
  150. package/build/src/modeling/legacy/DataProperty.d.ts.map +0 -1
  151. package/build/src/modeling/legacy/DataProperty.js +0 -415
  152. package/build/src/modeling/legacy/DataProperty.js.map +0 -1
  153. package/build/src/models/store/DataFile.d.ts +0 -31
  154. package/build/src/models/store/DataFile.d.ts.map +0 -1
  155. package/build/src/models/store/DataFile.js +0 -92
  156. package/build/src/models/store/DataFile.js.map +0 -1
  157. package/src/amf/AmfShapeGenerator.ts +0 -477
  158. package/src/modeling/legacy/DataAssociation.ts +0 -554
  159. package/src/modeling/legacy/DataEntity.ts +0 -1019
  160. package/src/modeling/legacy/DataEntityBuilder.ts +0 -236
  161. package/src/modeling/legacy/DataImpactAnalysis.ts +0 -530
  162. package/src/modeling/legacy/DataModel.ts +0 -276
  163. package/src/modeling/legacy/DataNamespace.ts +0 -929
  164. package/src/modeling/legacy/DataProperty.ts +0 -630
  165. package/src/models/store/DataFile.ts +0 -100
  166. package/tests/unit/modeling/legacy/amf_shape_generator.spec.ts +0 -1041
  167. package/tests/unit/modeling/legacy/data_association.spec.ts +0 -710
  168. package/tests/unit/modeling/legacy/data_entity.spec.ts +0 -2061
  169. package/tests/unit/modeling/legacy/data_entity_generator_json.spec.ts +0 -987
  170. package/tests/unit/modeling/legacy/data_entity_generator_xml.spec.ts +0 -1451
  171. package/tests/unit/modeling/legacy/data_model.spec.ts +0 -395
  172. package/tests/unit/modeling/legacy/data_namespace.spec.ts +0 -1312
  173. package/tests/unit/modeling/legacy/data_property.spec.ts +0 -887
  174. package/tests/unit/modeling/legacy/impact_analysis.spec.ts +0 -373
@@ -1,710 +0,0 @@
1
- import { test } from '@japa/runner'
2
- import { DataAssociationKind, Thing, ValidationError } from '../../../../src/index.js'
3
- import { DataNamespace, DataModel, DataAssociation, IDataAssociation, DataEntity } from '../../../../src/legacy.js'
4
-
5
- test.group('constructor() with defaults', (g) => {
6
- let root: DataNamespace
7
- g.each.setup(() => {
8
- root = new DataNamespace()
9
- })
10
-
11
- test('sets the kind', ({ assert }) => {
12
- const assoc = new DataAssociation(root)
13
- assert.equal(assoc.kind, DataAssociationKind)
14
- })
15
-
16
- test('sets the key', ({ assert }) => {
17
- const assoc = new DataAssociation(root)
18
- assert.typeOf(assoc.key, 'string')
19
- assert.isNotEmpty(assoc.key)
20
- })
21
-
22
- test('sets the default "info"', ({ assert }) => {
23
- const assoc = new DataAssociation(root)
24
- assert.typeOf(assoc.info, 'EventTarget')
25
- assert.equal(assoc.info.name, 'Unnamed association')
26
- })
27
-
28
- test('sets the default schema', ({ assert }) => {
29
- const assoc = new DataAssociation(root)
30
- assert.isUndefined(assoc.schema)
31
- })
32
-
33
- test('does not set multiple', ({ assert }) => {
34
- const assoc = new DataAssociation(root)
35
- assert.isUndefined(assoc.multiple)
36
- })
37
-
38
- test('does not set required', ({ assert }) => {
39
- const assoc = new DataAssociation(root)
40
- assert.isUndefined(assoc.required)
41
- })
42
-
43
- test('sets the default targets', ({ assert }) => {
44
- const assoc = new DataAssociation(root)
45
- assert.deepEqual(assoc.targets, [])
46
- })
47
- })
48
-
49
- test.group('constructor() from schema initialization', (g) => {
50
- let root: DataNamespace
51
- g.each.setup(() => {
52
- root = new DataNamespace()
53
- })
54
-
55
- test('sets the key', ({ assert }) => {
56
- const orig = new DataAssociation(root).toJSON()
57
- orig.key = 'test'
58
- const instance = new DataAssociation(root, orig)
59
- assert.equal(instance.key, 'test')
60
- })
61
-
62
- test('sets the info', ({ assert }) => {
63
- const orig = new DataAssociation(root).toJSON()
64
- orig.info.name = 'test'
65
- const instance = new DataAssociation(root, orig)
66
- assert.equal(instance.info.name, 'test')
67
- })
68
-
69
- test('sets the multiple', ({ assert }) => {
70
- const orig = new DataAssociation(root).toJSON()
71
- orig.multiple = true
72
- const instance = new DataAssociation(root, orig)
73
- assert.isTrue(instance.multiple)
74
- })
75
-
76
- test('sets the required', ({ assert }) => {
77
- const orig = new DataAssociation(root).toJSON()
78
- orig.required = true
79
- const instance = new DataAssociation(root, orig)
80
- assert.isTrue(instance.required)
81
- })
82
-
83
- test('sets the targets', ({ assert }) => {
84
- const orig = new DataAssociation(root).toJSON()
85
- orig.targets = [{ key: 'test' }]
86
- const instance = new DataAssociation(root, orig)
87
- assert.deepEqual(instance.targets, [{ key: 'test' }])
88
- })
89
-
90
- test('sets the schema', ({ assert }) => {
91
- const orig = new DataAssociation(root).toJSON()
92
- orig.schema = { linked: true }
93
- const instance = new DataAssociation(root, orig)
94
- assert.deepEqual(instance.schema, { linked: true })
95
- })
96
-
97
- test('initializes from JSON schema ', ({ assert }) => {
98
- const orig = new DataAssociation(root).toJSON()
99
- orig.schema = { linked: true }
100
- const instance = new DataAssociation(root, JSON.stringify(orig))
101
- assert.deepEqual(instance.schema, { linked: true })
102
- })
103
- })
104
-
105
- test.group('fromTarget()', (g) => {
106
- let root: DataNamespace
107
- g.each.setup(() => {
108
- root = new DataNamespace()
109
- })
110
-
111
- test('sets the target', ({ assert }) => {
112
- const assoc = DataAssociation.fromTarget(root, 'test')
113
- assert.deepEqual(assoc.targets, [{ key: 'test' }])
114
- })
115
- })
116
-
117
- test.group('fromName()', (g) => {
118
- let root: DataNamespace
119
- g.each.setup(() => {
120
- root = new DataNamespace()
121
- })
122
-
123
- test('sets the name', ({ assert }) => {
124
- const assoc = DataAssociation.fromName(root, 'test')
125
- assert.equal(assoc.info.name, 'test')
126
- })
127
- })
128
-
129
- test.group('new()', (g) => {
130
- let root: DataNamespace
131
- let base: IDataAssociation
132
- g.each.setup(() => {
133
- root = new DataNamespace()
134
- base = {
135
- info: Thing.fromName('test name').toJSON(),
136
- key: 'test123',
137
- kind: DataAssociationKind,
138
- }
139
- })
140
-
141
- test('sets the key', ({ assert }) => {
142
- const assoc = new DataAssociation(root)
143
- assoc.new(base)
144
- assert.equal(assoc.key, 'test123')
145
- })
146
-
147
- test('sets the info', ({ assert }) => {
148
- const assoc = new DataAssociation(root)
149
- assoc.new(base)
150
- assert.equal(assoc.info.name, 'test name')
151
- })
152
-
153
- test('sets default info', ({ assert }) => {
154
- const assoc = new DataAssociation(root)
155
- // @ts-expect-error Used in testing
156
- delete base.info
157
- assoc.new(base)
158
- assert.equal(assoc.info.name, '')
159
- })
160
-
161
- test('sets the schema', ({ assert }) => {
162
- const assoc = new DataAssociation(root)
163
- assoc.new({ ...base, schema: { linked: true } })
164
- assert.deepEqual(assoc.schema, { linked: true })
165
- })
166
-
167
- test('sets default schema', ({ assert }) => {
168
- const assoc = new DataAssociation(root)
169
- assoc.new(base)
170
- assert.isUndefined(assoc.schema)
171
- })
172
-
173
- test('sets the multiple', ({ assert }) => {
174
- const assoc = new DataAssociation(root)
175
- assoc.new({ ...base, multiple: true })
176
- assert.isTrue(assoc.multiple)
177
- })
178
-
179
- test('does not set multiple when not in the input', ({ assert }) => {
180
- const assoc = new DataAssociation(root)
181
- assoc.new(base)
182
- assert.isUndefined(assoc.multiple)
183
- })
184
-
185
- test('sets the required', ({ assert }) => {
186
- const assoc = new DataAssociation(root)
187
- assoc.new({ ...base, required: true })
188
- assert.isTrue(assoc.required)
189
- })
190
-
191
- test('does not set required when not in the input', ({ assert }) => {
192
- const assoc = new DataAssociation(root)
193
- assoc.new(base)
194
- assert.isUndefined(assoc.required)
195
- })
196
-
197
- test('sets the targets', ({ assert }) => {
198
- const assoc = new DataAssociation(root)
199
- assoc.new({ ...base, targets: [{ key: 'target-id' }] })
200
- assert.deepEqual(assoc.targets, [{ key: 'target-id' }])
201
- })
202
-
203
- test('re-sets targets when not in the input', ({ assert }) => {
204
- const assoc = new DataAssociation(root)
205
- assoc.targets = [{ key: 'target-id' }]
206
- assoc.new(base)
207
- assert.deepEqual(assoc.targets, [])
208
- })
209
-
210
- test('throws when unknown input', ({ assert }) => {
211
- const assoc = new DataAssociation(root)
212
- assert.throws(() => {
213
- // @ts-expect-error Used in testing
214
- assoc.new({})
215
- }, 'Validation failure')
216
- })
217
- })
218
-
219
- test.group('toJSON()', (g) => {
220
- let root: DataNamespace
221
- let base: DataAssociation
222
- g.each.setup(() => {
223
- root = new DataNamespace()
224
- base = new DataAssociation(root, {
225
- info: Thing.fromName('test name').toJSON(),
226
- key: 'test123',
227
- kind: DataAssociationKind,
228
- })
229
- })
230
-
231
- test('serializes the kind', ({ assert }) => {
232
- const result = base.toJSON()
233
- assert.equal(result.kind, DataAssociationKind)
234
- })
235
-
236
- test('serializes the key', ({ assert }) => {
237
- const result = base.toJSON()
238
- assert.equal(result.key, base.key)
239
- })
240
-
241
- test('serializes the info', ({ assert }) => {
242
- const result = base.toJSON()
243
- assert.equal(result.info.name, 'test name')
244
- })
245
-
246
- test('does not serialize the schema by default', ({ assert }) => {
247
- const result = base.toJSON()
248
- assert.isUndefined(result.schema)
249
- })
250
-
251
- test('does not serialize the multiple by default', ({ assert }) => {
252
- const result = base.toJSON()
253
- assert.isUndefined(result.multiple)
254
- })
255
-
256
- test('does not serialize the required by default', ({ assert }) => {
257
- const result = base.toJSON()
258
- assert.isUndefined(result.required)
259
- })
260
-
261
- test('does not serialize targets when empty', ({ assert }) => {
262
- const result = base.toJSON()
263
- assert.isUndefined(result.targets)
264
- })
265
-
266
- test('serializes the schema', ({ assert }) => {
267
- base.schema = { linked: true }
268
- const result = base.toJSON()
269
- assert.deepEqual(result.schema, { linked: true })
270
- })
271
-
272
- test('serialize the set multiple', ({ assert }) => {
273
- base.multiple = false
274
- const result = base.toJSON()
275
- assert.isFalse(result.multiple)
276
- })
277
-
278
- test('serialize the set required', ({ assert }) => {
279
- base.required = false
280
- const result = base.toJSON()
281
- assert.isFalse(result.required)
282
- })
283
-
284
- test('serializes targets as a copy', ({ assert }) => {
285
- base.targets = [{ key: 'abc' }]
286
- const result = base.toJSON()
287
- assert.deepEqual(result.targets, [{ key: 'abc' }])
288
- base.targets.push({ key: 'def' })
289
- assert.deepEqual(result.targets, [{ key: 'abc' }])
290
- })
291
- })
292
-
293
- test.group('#isSingle', (g) => {
294
- let root: DataNamespace
295
- let e1: DataEntity
296
- let e2: DataEntity
297
-
298
- g.each.setup(() => {
299
- root = new DataNamespace()
300
- const model = root.addDataModel('m1')
301
- e1 = model.addEntity('e1')
302
- e2 = model.addEntity('e2')
303
- })
304
-
305
- test('returns true when no targets', ({ assert }) => {
306
- const assoc = e1.addNamedAssociation('a1')
307
- assert.isTrue(assoc.isSingle)
308
- })
309
-
310
- test('returns true when a single target', ({ assert }) => {
311
- const assoc = e1.addTargetAssociation(e2.key)
312
- assert.isTrue(assoc.isSingle)
313
- })
314
-
315
- test('returns false when multiple targets', ({ assert }) => {
316
- const assoc = e1.addTargetAssociation(e2.key)
317
- assoc.targets.push({ key: 'other' })
318
- assert.isFalse(assoc.isSingle)
319
- })
320
- })
321
-
322
- test.group('getTargets()', (g) => {
323
- let root: DataNamespace
324
- let e1: DataEntity
325
- let e2: DataEntity
326
-
327
- g.each.setup(() => {
328
- root = new DataNamespace()
329
- const model = root.addDataModel('m1')
330
- e1 = model.addEntity('e1')
331
- e2 = model.addEntity('e2')
332
- })
333
-
334
- test('returns the entity', ({ assert }) => {
335
- const assoc = e1.addTargetAssociation(e2.key)
336
- const result = assoc.getTargets()
337
- assert.deepEqual(result, [e2])
338
- })
339
-
340
- test('returns empty array when no target', ({ assert }) => {
341
- const assoc = e1.addNamedAssociation('test')
342
- const result = assoc.getTargets()
343
- assert.deepEqual(result, [])
344
- })
345
-
346
- test('returns undefined when target has no definition', ({ assert }) => {
347
- const assoc = e1.addNamedAssociation('test')
348
- assoc.targets = [{ key: 'nothing' }]
349
- const result = assoc.getTargets()
350
- assert.deepEqual(result, [])
351
- })
352
- })
353
-
354
- test.group('remove()', (g) => {
355
- let root: DataNamespace
356
- let m1: DataModel
357
- let e1: DataEntity
358
- let e2: DataEntity
359
- let a1: DataAssociation
360
-
361
- g.each.setup(() => {
362
- root = new DataNamespace()
363
- m1 = root.addDataModel('m1')
364
- e1 = m1.addEntity('e1')
365
- e2 = m1.addEntity('e2')
366
- a1 = e1.addTargetAssociation(e2.key)
367
- })
368
-
369
- test('removes self from the parent entity', ({ assert }) => {
370
- a1.remove()
371
- assert.deepEqual(e1.associations, [])
372
- })
373
-
374
- test('removes self from the root definitions', ({ assert }) => {
375
- a1.remove()
376
- assert.deepEqual(root.definitions.associations, [])
377
- })
378
-
379
- test('does not serialize associations', ({ assert }) => {
380
- a1.remove()
381
- const schema = root.toJSON()
382
- assert.isUndefined(schema.definitions.associations)
383
- assert.isUndefined(schema.definitions.entities![0].associations)
384
- assert.isUndefined(schema.definitions.entities![1].associations)
385
- })
386
-
387
- test('removes self only', ({ assert }) => {
388
- const e3 = m1.addEntity('e2')
389
- const a2 = e1.addTargetAssociation(e3.key)
390
- a1.remove()
391
- assert.deepEqual(e1.associations, [a2])
392
- assert.deepEqual(root.definitions.associations, [a2])
393
- })
394
- })
395
-
396
- test.group('addTarget()', (g) => {
397
- let root: DataNamespace
398
- let e1: DataEntity
399
- let e2: DataEntity
400
- let a1: DataAssociation
401
- let foreign: DataNamespace
402
-
403
- g.each.setup(() => {
404
- root = new DataNamespace()
405
- foreign = new DataNamespace()
406
- root.addForeign(foreign)
407
- const model = root.addDataModel('m1')
408
- const model2 = foreign.addDataModel('m2')
409
- e1 = model.addEntity('e1')
410
- e2 = model2.addEntity('e2')
411
- a1 = e1.addNamedAssociation('a1')
412
- })
413
-
414
- test('adds the target from the key', ({ assert }) => {
415
- a1.addTarget(e1.key)
416
- assert.deepEqual(a1.targets, [{ key: e1.key }])
417
- })
418
-
419
- test('adds the target from an entity', ({ assert }) => {
420
- a1.addTarget(e1)
421
- assert.deepEqual(a1.targets, [{ key: e1.key }])
422
- })
423
-
424
- test('adds the target from an entity schema', ({ assert }) => {
425
- a1.addTarget(e1.toJSON())
426
- assert.deepEqual(a1.targets, [{ key: e1.key }])
427
- })
428
-
429
- test('adds the target with foreign namespace', ({ assert }) => {
430
- a1.addTarget(e2)
431
- assert.deepEqual(a1.targets, [{ key: e2.key, namespace: foreign.key }])
432
- })
433
-
434
- test('adds the target from an entity with foreign namespace', ({ assert }) => {
435
- a1.addTarget(e2)
436
- assert.deepEqual(a1.targets, [{ key: e2.key, namespace: foreign.key }])
437
- })
438
-
439
- test('throws an error when namespace does not exist', ({ assert }) => {
440
- assert.throws(() => a1.addTarget('some-key', 'not-exist'), 'Foreign namespace "not-exist" does not exist.')
441
- })
442
- })
443
-
444
- test.group('removeTarget()', (g) => {
445
- let root: DataNamespace
446
- let e1: DataEntity
447
- let e2: DataEntity
448
- let a1: DataAssociation
449
-
450
- g.each.setup(() => {
451
- root = new DataNamespace()
452
- const model = root.addDataModel('m1')
453
- e1 = model.addEntity('e1')
454
- e2 = model.addEntity('e2')
455
- a1 = e1.addTargetAssociation(e2.key)
456
- })
457
-
458
- test('removes the target from the key', ({ assert }) => {
459
- a1.removeTarget(e2.key)
460
- assert.deepEqual(a1.targets, [])
461
- })
462
-
463
- test('removes the target from an entity', ({ assert }) => {
464
- a1.removeTarget(e2)
465
- assert.deepEqual(a1.targets, [])
466
- })
467
-
468
- test('removes the target from an entity schema', ({ assert }) => {
469
- a1.removeTarget(e2.toJSON())
470
- assert.deepEqual(a1.targets, [])
471
- })
472
-
473
- test('does nothing when the target does not exist', ({ assert }) => {
474
- a1.removeTarget('other')
475
- assert.deepEqual(a1.targets, [{ key: e2.key }])
476
- })
477
- })
478
-
479
- test.group('toApiShape()', (g) => {
480
- let root: DataNamespace
481
- let m1: DataModel
482
- let e1: DataEntity
483
- let e2: DataEntity
484
- let a1: DataAssociation
485
-
486
- g.each.setup(() => {
487
- root = new DataNamespace()
488
- m1 = root.addDataModel('m1')
489
- e1 = m1.addEntity('e1')
490
- e2 = m1.addEntity('e2')
491
- a1 = e1.addTargetAssociation(e2.key)
492
- })
493
-
494
- // these tests only check whether the AmfShapeGenerator is called.
495
- // specific tests are performed elsewhere
496
-
497
- test('returns an object', ({ assert }) => {
498
- const result = a1.toApiShape()
499
-
500
- assert.typeOf(result, 'object')
501
- assert.typeOf(result.range, 'object')
502
- })
503
- })
504
-
505
- test.group('getParentInstance()', (g) => {
506
- let root: DataNamespace
507
- let m1: DataModel
508
- let e1: DataEntity
509
- let e2: DataEntity
510
-
511
- g.each.setup(() => {
512
- root = new DataNamespace()
513
- m1 = root.addDataModel('m1')
514
- e1 = m1.addEntity('e1')
515
- e2 = m1.addEntity('e2')
516
- })
517
-
518
- test('returns the reference to the parent entity', ({ assert }) => {
519
- const a1 = e1.addTargetAssociation(e2.key)
520
- const result = a1.getParentInstance()
521
- assert.deepEqual(result, e1)
522
- })
523
- })
524
-
525
- test.group('DataAssociation Validation', (g) => {
526
- let root: DataNamespace
527
- g.each.setup(() => {
528
- root = new DataNamespace()
529
- })
530
-
531
- test('throws when kind is missing', ({ assert }) => {
532
- const orig = new DataAssociation(root).toJSON()
533
- // @ts-expect-error Testing invalid data
534
- delete orig.kind
535
- assert.throws(
536
- () => new DataAssociation(root, orig),
537
- ValidationError as unknown as ErrorConstructor,
538
- 'Validation failure'
539
- )
540
- })
541
-
542
- test('throws when kind is wrong', ({ assert }) => {
543
- const orig = new DataAssociation(root).toJSON()
544
- // @ts-expect-error Testing invalid data
545
- orig.kind = 'wrong kind'
546
- assert.throws(
547
- () => new DataAssociation(root, orig),
548
- ValidationError as unknown as ErrorConstructor,
549
- 'Validation failure'
550
- )
551
- })
552
-
553
- test('throws when input is not an object', ({ assert }) => {
554
- assert.throws(() => new DataAssociation(root, 'not an object'), ValidationError as unknown as ErrorConstructor)
555
- })
556
-
557
- test('throws when info is invalid', ({ assert }) => {
558
- const orig = new DataAssociation(root).toJSON()
559
- // @ts-expect-error Testing invalid data
560
- orig.info = 'not an info'
561
- assert.throws(() => new DataAssociation(root, orig), ValidationError as unknown as ErrorConstructor)
562
- })
563
- })
564
-
565
- test.group('Foreign Namespace Handling', (g) => {
566
- let root: DataNamespace
567
- let foreign: DataNamespace
568
- let e1: DataEntity
569
- let e2: DataEntity
570
- g.each.setup(() => {
571
- root = new DataNamespace()
572
- foreign = new DataNamespace()
573
- root.addForeign(foreign)
574
- const model1 = root.addDataModel('m1')
575
- const model2 = foreign.addDataModel('m2')
576
- e1 = model1.addEntity('e1')
577
- e2 = model2.addEntity('e2')
578
- })
579
-
580
- test('fromTarget() with foreign namespace', ({ assert }) => {
581
- const assoc = DataAssociation.fromTarget(root, e2.key, foreign.key)
582
- assert.deepEqual(assoc.targets, [{ key: e2.key, namespace: foreign.key }])
583
- })
584
-
585
- test('addTarget() with foreign namespace', ({ assert }) => {
586
- const assoc = e1.addNamedAssociation('assoc1')
587
- assoc.addTarget(e2)
588
- assert.deepEqual(assoc.targets, [{ key: e2.key, namespace: foreign.key }])
589
- })
590
- test('addTarget() with foreign namespace - namespace does not exist', ({ assert }) => {
591
- assert.throws(() => {
592
- const assoc = e1.addNamedAssociation('assoc1')
593
- assoc.addTarget(e2.toJSON(), 'not-exist')
594
- }, 'Foreign namespace "not-exist" does not exist.')
595
- })
596
-
597
- test('getTargets() with foreign namespace', ({ assert }) => {
598
- const assoc = e1.addForeignAssociation(e2.key, foreign.key)
599
- const result = assoc.getTargets()
600
- assert.deepEqual(result, [e2])
601
- })
602
-
603
- test('getTargets() with foreign namespace - no target entity', ({ assert }) => {
604
- const assoc = e1.addNamedAssociation('assoc')
605
- assoc.targets = [{ key: 'no-target', namespace: foreign.key }]
606
- const result = assoc.getTargets()
607
- assert.deepEqual(result, [])
608
- })
609
- test('getTargets() with foreign namespace - wrong namespace', ({ assert }) => {
610
- const assoc = e1.addNamedAssociation('assoc')
611
- assoc.targets = [{ key: e2.key, namespace: 'no-namespace' }]
612
- const result = assoc.getTargets()
613
- assert.deepEqual(result, [])
614
- })
615
- })
616
-
617
- test.group('DataAssociation Multiple targets', (g) => {
618
- let root: DataNamespace
619
- let e1: DataEntity
620
- let e2: DataEntity
621
- let e3: DataEntity
622
-
623
- g.each.setup(() => {
624
- root = new DataNamespace()
625
- const model = root.addDataModel('m1')
626
- e1 = model.addEntity('e1')
627
- e2 = model.addEntity('e2')
628
- e3 = model.addEntity('e3')
629
- })
630
-
631
- test('addTarget() with multiple targets', ({ assert }) => {
632
- const a1 = e1.addNamedAssociation('assoc1')
633
- a1.addTarget(e2.key)
634
- a1.addTarget(e3.key)
635
- assert.deepEqual(a1.targets, [{ key: e2.key }, { key: e3.key }])
636
- })
637
- })
638
-
639
- test.group('DataAssociation.isChildOf()', (group) => {
640
- let root: DataNamespace
641
- let n1: DataNamespace
642
- let n2: DataNamespace
643
- let m1: DataModel
644
- let m2: DataModel
645
- let e1: DataEntity
646
- let e2: DataEntity
647
- let a1: DataAssociation
648
- let a2: DataAssociation
649
- let a3: DataAssociation
650
-
651
- group.each.setup(() => {
652
- root = new DataNamespace()
653
- n1 = root.addNamespace('n1')
654
- n2 = n1.addNamespace('n2')
655
- m1 = root.addDataModel('m1')
656
- m2 = n1.addDataModel('m2')
657
- e1 = m1.addEntity('e1')
658
- e2 = m2.addEntity('e2')
659
- a1 = e1.addNamedAssociation('a1')
660
- a2 = e2.addNamedAssociation('a2')
661
- a3 = n2.addDataModel('m3').addEntity('e3').addNamedAssociation('a3')
662
- })
663
-
664
- test('returns false when called on an association not in an entity', ({ assert }) => {
665
- const a4 = new DataAssociation(root)
666
- const result = a4.isChildOf('some-key')
667
- assert.isFalse(result)
668
- })
669
-
670
- test('returns false when called on self', ({ assert }) => {
671
- const result = a2.isChildOf(a2.key)
672
- assert.isFalse(result)
673
- })
674
-
675
- test('returns true when called on a direct parent', ({ assert }) => {
676
- const result = a2.isChildOf(e2.key)
677
- assert.isTrue(result)
678
- })
679
-
680
- test('returns true when called on a grandparent', ({ assert }) => {
681
- const result = a3.isChildOf(root.key)
682
- assert.isTrue(result)
683
- })
684
-
685
- test('returns false when called on a sibling', ({ assert }) => {
686
- const a4 = e1.addNamedAssociation('a4')
687
- const result = a1.isChildOf(a4.key)
688
- assert.isFalse(result)
689
- })
690
-
691
- test('returns false when called on a child', ({ assert }) => {
692
- const result = e2.isChildOf(a2.key)
693
- assert.isFalse(result)
694
- })
695
-
696
- test('returns false when called on a non-existent namespace', ({ assert }) => {
697
- const result = a2.isChildOf('non-existent-key')
698
- assert.isFalse(result)
699
- })
700
-
701
- test('returns true when called on a grandparent', ({ assert }) => {
702
- const result = a3.isChildOf(n1.key)
703
- assert.isTrue(result)
704
- })
705
-
706
- test('returns true when called on a data model in the same namespace', ({ assert }) => {
707
- const result = a1.isChildOf(m1.key)
708
- assert.isTrue(result)
709
- })
710
- })