@api-client/core 0.11.11 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/Testing.md +1 -1
  2. package/bin/plugins/events/EventPlugin.ts +61 -0
  3. package/bin/plugins/events/assert.ts +193 -0
  4. package/bin/plugins/events/types.ts +6 -0
  5. package/bin/test.ts +8 -1
  6. package/build/src/amf/AmfShapeGenerator.d.ts +6 -3
  7. package/build/src/amf/AmfShapeGenerator.d.ts.map +1 -1
  8. package/build/src/amf/AmfShapeGenerator.js +4 -1
  9. package/build/src/amf/AmfShapeGenerator.js.map +1 -1
  10. package/build/src/amf/AmfTypes.d.ts +2 -2
  11. package/build/src/amf/AmfTypes.d.ts.map +1 -1
  12. package/build/src/amf/AmfTypes.js.map +1 -1
  13. package/build/src/amf/DataValueGenerator.d.ts +15 -15
  14. package/build/src/amf/DataValueGenerator.d.ts.map +1 -1
  15. package/build/src/amf/DataValueGenerator.js +14 -14
  16. package/build/src/amf/DataValueGenerator.js.map +1 -1
  17. package/build/src/browser.d.ts +12 -9
  18. package/build/src/browser.d.ts.map +1 -1
  19. package/build/src/browser.js +11 -8
  20. package/build/src/browser.js.map +1 -1
  21. package/build/src/exceptions/attach_exception.d.ts +11 -0
  22. package/build/src/exceptions/attach_exception.d.ts.map +1 -0
  23. package/build/src/exceptions/attach_exception.js +11 -0
  24. package/build/src/exceptions/attach_exception.js.map +1 -0
  25. package/build/src/exceptions/detach_exception.d.ts +11 -0
  26. package/build/src/exceptions/detach_exception.d.ts.map +1 -0
  27. package/build/src/exceptions/detach_exception.js +11 -0
  28. package/build/src/exceptions/detach_exception.js.map +1 -0
  29. package/build/src/exceptions/remove_model_exception.d.ts +8 -0
  30. package/build/src/exceptions/remove_model_exception.d.ts.map +1 -0
  31. package/build/src/exceptions/remove_model_exception.js +8 -0
  32. package/build/src/exceptions/remove_model_exception.js.map +1 -0
  33. package/build/src/exceptions/remove_namespace_exception.d.ts +8 -0
  34. package/build/src/exceptions/remove_namespace_exception.d.ts.map +1 -0
  35. package/build/src/exceptions/remove_namespace_exception.js +8 -0
  36. package/build/src/exceptions/remove_namespace_exception.js.map +1 -0
  37. package/build/src/index.d.ts +12 -9
  38. package/build/src/index.d.ts.map +1 -1
  39. package/build/src/index.js +11 -8
  40. package/build/src/index.js.map +1 -1
  41. package/build/src/legacy.d.ts +8 -0
  42. package/build/src/legacy.d.ts.map +1 -1
  43. package/build/src/legacy.js +9 -0
  44. package/build/src/legacy.js.map +1 -1
  45. package/build/src/modeling/Bindings.d.ts +2 -2
  46. package/build/src/modeling/Bindings.d.ts.map +1 -1
  47. package/build/src/modeling/Bindings.js.map +1 -1
  48. package/build/src/modeling/DataDomain.d.ts +601 -0
  49. package/build/src/modeling/DataDomain.d.ts.map +1 -0
  50. package/build/src/modeling/DataDomain.js +1142 -0
  51. package/build/src/modeling/DataDomain.js.map +1 -0
  52. package/build/src/modeling/DataFormat.d.ts +42 -41
  53. package/build/src/modeling/DataFormat.d.ts.map +1 -1
  54. package/build/src/modeling/DataFormat.js +30 -131
  55. package/build/src/modeling/DataFormat.js.map +1 -1
  56. package/build/src/modeling/DomainAssociation.d.ts +281 -0
  57. package/build/src/modeling/DomainAssociation.d.ts.map +1 -0
  58. package/build/src/modeling/DomainAssociation.js +440 -0
  59. package/build/src/modeling/DomainAssociation.js.map +1 -0
  60. package/build/src/modeling/DomainElement.d.ts +33 -0
  61. package/build/src/modeling/DomainElement.d.ts.map +1 -0
  62. package/build/src/modeling/DomainElement.js +32 -0
  63. package/build/src/modeling/DomainElement.js.map +1 -0
  64. package/build/src/modeling/DomainEntity.d.ts +383 -0
  65. package/build/src/modeling/DomainEntity.d.ts.map +1 -0
  66. package/build/src/modeling/DomainEntity.js +718 -0
  67. package/build/src/modeling/DomainEntity.js.map +1 -0
  68. package/build/src/modeling/DomainFile.d.ts +25 -0
  69. package/build/src/modeling/DomainFile.d.ts.map +1 -0
  70. package/build/src/modeling/DomainFile.js +86 -0
  71. package/build/src/modeling/DomainFile.js.map +1 -0
  72. package/build/src/modeling/DomainImpactAnalysis.d.ts +60 -47
  73. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  74. package/build/src/modeling/DomainImpactAnalysis.js +201 -132
  75. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  76. package/build/src/modeling/DomainModel.d.ts +226 -0
  77. package/build/src/modeling/DomainModel.d.ts.map +1 -0
  78. package/build/src/modeling/DomainModel.js +401 -0
  79. package/build/src/modeling/DomainModel.js.map +1 -0
  80. package/build/src/modeling/DomainNamespace.d.ts +268 -0
  81. package/build/src/modeling/DomainNamespace.d.ts.map +1 -0
  82. package/build/src/modeling/DomainNamespace.js +512 -0
  83. package/build/src/modeling/DomainNamespace.js.map +1 -0
  84. package/build/src/modeling/DomainProperty.d.ts +281 -0
  85. package/build/src/modeling/DomainProperty.d.ts.map +1 -0
  86. package/build/src/modeling/DomainProperty.js +560 -0
  87. package/build/src/modeling/DomainProperty.js.map +1 -0
  88. package/build/src/modeling/DomainSerialization.d.ts +40 -0
  89. package/build/src/modeling/DomainSerialization.d.ts.map +1 -0
  90. package/build/src/modeling/DomainSerialization.js +288 -0
  91. package/build/src/modeling/DomainSerialization.js.map +1 -0
  92. package/build/src/modeling/DomainVersioning.d.ts +17 -0
  93. package/build/src/modeling/DomainVersioning.d.ts.map +1 -0
  94. package/build/src/modeling/DomainVersioning.js +124 -0
  95. package/build/src/modeling/DomainVersioning.js.map +1 -0
  96. package/build/src/modeling/GraphUtils.d.ts +8 -0
  97. package/build/src/modeling/GraphUtils.d.ts.map +1 -0
  98. package/build/src/modeling/GraphUtils.js +26 -0
  99. package/build/src/modeling/GraphUtils.js.map +1 -0
  100. package/build/src/modeling/amf/ShapeGenerator.d.ts +164 -0
  101. package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -0
  102. package/build/src/modeling/amf/ShapeGenerator.js +492 -0
  103. package/build/src/modeling/amf/ShapeGenerator.js.map +1 -0
  104. package/build/src/modeling/{DataAssociation.d.ts → legacy/DataAssociation.d.ts} +10 -5
  105. package/build/src/modeling/legacy/DataAssociation.d.ts.map +1 -0
  106. package/build/src/modeling/{DataAssociation.js → legacy/DataAssociation.js} +9 -6
  107. package/build/src/modeling/legacy/DataAssociation.js.map +1 -0
  108. package/build/src/modeling/{DataEntity.d.ts → legacy/DataEntity.d.ts} +12 -7
  109. package/build/src/modeling/legacy/DataEntity.d.ts.map +1 -0
  110. package/build/src/modeling/{DataEntity.js → legacy/DataEntity.js} +19 -18
  111. package/build/src/modeling/legacy/DataEntity.js.map +1 -0
  112. package/build/src/modeling/{DataEntityBuilder.d.ts → legacy/DataEntityBuilder.d.ts} +3 -2
  113. package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +1 -0
  114. package/build/src/modeling/{DataEntityBuilder.js → legacy/DataEntityBuilder.js} +3 -2
  115. package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -0
  116. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +298 -0
  117. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +1 -0
  118. package/build/src/modeling/legacy/DataImpactAnalysis.js +441 -0
  119. package/build/src/modeling/legacy/DataImpactAnalysis.js.map +1 -0
  120. package/build/src/modeling/{DataModel.d.ts → legacy/DataModel.d.ts} +6 -4
  121. package/build/src/modeling/legacy/DataModel.d.ts.map +1 -0
  122. package/build/src/modeling/{DataModel.js → legacy/DataModel.js} +7 -6
  123. package/build/src/modeling/legacy/DataModel.js.map +1 -0
  124. package/build/src/modeling/{DataNamespace.d.ts → legacy/DataNamespace.d.ts} +22 -3
  125. package/build/src/modeling/legacy/DataNamespace.d.ts.map +1 -0
  126. package/build/src/modeling/{DataNamespace.js → legacy/DataNamespace.js} +7 -3
  127. package/build/src/modeling/legacy/DataNamespace.js.map +1 -0
  128. package/build/src/modeling/{DataProperty.d.ts → legacy/DataProperty.d.ts} +13 -5
  129. package/build/src/modeling/legacy/DataProperty.d.ts.map +1 -0
  130. package/build/src/modeling/{DataProperty.js → legacy/DataProperty.js} +8 -5
  131. package/build/src/modeling/legacy/DataProperty.js.map +1 -0
  132. package/build/src/modeling/observed.d.ts +67 -0
  133. package/build/src/modeling/observed.d.ts.map +1 -0
  134. package/build/src/modeling/observed.js +230 -0
  135. package/build/src/modeling/observed.js.map +1 -0
  136. package/build/src/modeling/types.d.ts +165 -1
  137. package/build/src/modeling/types.d.ts.map +1 -1
  138. package/build/src/modeling/types.js.map +1 -1
  139. package/build/src/models/Thing.d.ts +26 -5
  140. package/build/src/models/Thing.d.ts.map +1 -1
  141. package/build/src/models/Thing.js +193 -91
  142. package/build/src/models/Thing.js.map +1 -1
  143. package/build/src/models/kinds.d.ts +31 -6
  144. package/build/src/models/kinds.d.ts.map +1 -1
  145. package/build/src/models/kinds.js +31 -6
  146. package/build/src/models/kinds.js.map +1 -1
  147. package/build/src/models/store/DataFile.d.ts +3 -1
  148. package/build/src/models/store/DataFile.d.ts.map +1 -1
  149. package/build/src/models/store/DataFile.js +2 -0
  150. package/build/src/models/store/DataFile.js.map +1 -1
  151. package/build/src/models/types.d.ts +12 -0
  152. package/build/src/models/types.d.ts.map +1 -0
  153. package/build/src/models/types.js +2 -0
  154. package/build/src/models/types.js.map +1 -0
  155. package/build/src/runtime/store/FilesSdk.d.ts +2 -2
  156. package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
  157. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  158. package/data/models/example-generator-api.json +16 -16
  159. package/package.json +20 -6
  160. package/readme.md +1 -1
  161. package/src/amf/AmfShapeGenerator.ts +7 -4
  162. package/src/amf/AmfTypes.ts +2 -2
  163. package/src/amf/DataValueGenerator.ts +21 -21
  164. package/src/exceptions/attach_exception.ts +11 -0
  165. package/src/exceptions/detach_exception.ts +11 -0
  166. package/src/exceptions/remove_model_exception.ts +8 -0
  167. package/src/exceptions/remove_namespace_exception.ts +8 -0
  168. package/src/modeling/Bindings.ts +2 -2
  169. package/src/modeling/DataDomain.ts +1221 -0
  170. package/src/modeling/DataFormat.ts +54 -163
  171. package/src/modeling/DomainAssociation.ts +476 -0
  172. package/src/modeling/DomainElement.ts +50 -0
  173. package/src/modeling/DomainEntity.ts +769 -0
  174. package/src/modeling/DomainFile.ts +94 -0
  175. package/src/modeling/DomainImpactAnalysis.ts +218 -144
  176. package/src/modeling/DomainModel.ts +421 -0
  177. package/src/modeling/DomainNamespace.ts +537 -0
  178. package/src/modeling/DomainProperty.ts +548 -0
  179. package/src/modeling/DomainSerialization.ts +312 -0
  180. package/src/modeling/DomainVersioning.ts +144 -0
  181. package/src/modeling/GraphUtils.ts +28 -0
  182. package/src/modeling/amf/ShapeGenerator.ts +552 -0
  183. package/src/modeling/graph.md +115 -0
  184. package/src/modeling/{DataAssociation.ts → legacy/DataAssociation.ts} +13 -8
  185. package/src/modeling/{DataEntity.ts → legacy/DataEntity.ts} +28 -23
  186. package/src/modeling/{DataEntityBuilder.ts → legacy/DataEntityBuilder.ts} +4 -3
  187. package/src/modeling/legacy/DataImpactAnalysis.ts +530 -0
  188. package/src/modeling/{DataModel.ts → legacy/DataModel.ts} +10 -8
  189. package/src/modeling/{DataNamespace.ts → legacy/DataNamespace.ts} +23 -5
  190. package/src/modeling/{DataProperty.ts → legacy/DataProperty.ts} +15 -7
  191. package/src/modeling/observed.ts +267 -0
  192. package/src/modeling/types.ts +174 -1
  193. package/src/models/Thing.ts +70 -5
  194. package/src/models/kinds.ts +32 -6
  195. package/src/models/store/DataFile.ts +3 -1
  196. package/src/models/types.ts +11 -0
  197. package/src/runtime/store/FilesSdk.ts +2 -2
  198. package/tests/unit/amf/data_value_generator.spec.ts +15 -15
  199. package/tests/unit/legacy-transformers/ARC-legacy-import.spec.ts +1 -1
  200. package/tests/unit/modeling/amf/shape_generator.spec.ts +1174 -0
  201. package/tests/unit/modeling/data_domain.spec.ts +444 -0
  202. package/tests/unit/modeling/data_domain_associations.spec.ts +279 -0
  203. package/tests/unit/modeling/data_domain_change_observers.spec.ts +681 -0
  204. package/tests/unit/modeling/data_domain_entities.spec.ts +449 -0
  205. package/tests/unit/modeling/data_domain_foreign.spec.ts +355 -0
  206. package/tests/unit/modeling/data_domain_models.spec.ts +658 -0
  207. package/tests/unit/modeling/data_domain_namespaces.spec.ts +668 -0
  208. package/tests/unit/modeling/data_domain_property.spec.ts +264 -0
  209. package/tests/unit/modeling/data_domain_serialization.spec.ts +294 -0
  210. package/tests/unit/modeling/domain.property.spec.ts +822 -0
  211. package/tests/unit/modeling/domain_asociation.spec.ts +643 -0
  212. package/tests/unit/modeling/domain_asociation_targets.spec.ts +350 -0
  213. package/tests/unit/modeling/domain_entity.spec.ts +730 -0
  214. package/tests/unit/modeling/domain_entity_associations.spec.ts +330 -0
  215. package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +988 -0
  216. package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +1451 -0
  217. package/tests/unit/modeling/domain_entity_fields.spec.ts +113 -0
  218. package/tests/unit/modeling/domain_entity_generators.spec.ts +20 -0
  219. package/tests/unit/modeling/domain_entity_parents.spec.ts +291 -0
  220. package/tests/unit/modeling/domain_entity_properties.spec.ts +305 -0
  221. package/tests/unit/modeling/{data_file.spec.ts → domain_file.spec.ts} +29 -85
  222. package/tests/unit/modeling/domain_impact_analysis.spec.ts +452 -0
  223. package/tests/unit/modeling/domain_model.spec.ts +568 -0
  224. package/tests/unit/modeling/domain_model_entities.spec.ts +408 -0
  225. package/tests/unit/modeling/domain_namespace.spec.ts +514 -0
  226. package/tests/unit/modeling/domain_namespace_models.spec.ts +324 -0
  227. package/tests/unit/modeling/domain_namespace_namespaces.spec.ts +404 -0
  228. package/tests/unit/modeling/domain_versioning.spec.ts +140 -0
  229. package/tests/unit/{amf → modeling/legacy}/amf_shape_generator.spec.ts +11 -11
  230. package/tests/unit/modeling/{data_association.spec.ts → legacy/data_association.spec.ts} +3 -11
  231. package/tests/unit/modeling/{data_entity.spec.ts → legacy/data_entity.spec.ts} +10 -8
  232. package/tests/unit/modeling/{data_entity_generator_json.spec.ts → legacy/data_entity_generator_json.spec.ts} +1 -1
  233. package/tests/unit/modeling/{data_entity_generator_xml.spec.ts → legacy/data_entity_generator_xml.spec.ts} +1 -1
  234. package/tests/unit/modeling/{data_model.spec.ts → legacy/data_model.spec.ts} +3 -3
  235. package/tests/unit/modeling/{data_namespace.spec.ts → legacy/data_namespace.spec.ts} +3 -10
  236. package/tests/unit/modeling/{data_property.spec.ts → legacy/data_property.spec.ts} +3 -6
  237. package/tests/unit/modeling/{impact_analysis.spec.ts → legacy/impact_analysis.spec.ts} +9 -9
  238. package/tests/unit/models/File/new.spec.ts +1 -1
  239. package/tests/unit/models/HttpProject.spec.ts +3 -3
  240. package/tsconfig.node.json +35 -0
  241. package/build/src/modeling/DataAssociation.d.ts.map +0 -1
  242. package/build/src/modeling/DataAssociation.js.map +0 -1
  243. package/build/src/modeling/DataEntity.d.ts.map +0 -1
  244. package/build/src/modeling/DataEntity.js.map +0 -1
  245. package/build/src/modeling/DataEntityBuilder.d.ts.map +0 -1
  246. package/build/src/modeling/DataEntityBuilder.js.map +0 -1
  247. package/build/src/modeling/DataModel.d.ts.map +0 -1
  248. package/build/src/modeling/DataModel.js.map +0 -1
  249. package/build/src/modeling/DataNamespace.d.ts.map +0 -1
  250. package/build/src/modeling/DataNamespace.js.map +0 -1
  251. package/build/src/modeling/DataProperty.d.ts.map +0 -1
  252. package/build/src/modeling/DataProperty.js.map +0 -1
@@ -0,0 +1,330 @@
1
+ import { test } from '@japa/runner'
2
+ import { DataDomain, DomainAssociation } from '../../../src/index.js'
3
+
4
+ test.group('DomainEntity.addAssociation()', () => {
5
+ test('adds an association to the entity', ({ assert }) => {
6
+ const dataDomain = new DataDomain()
7
+ const model = dataDomain.addModel()
8
+ const entity = model.addEntity()
9
+ const association = entity.addAssociation()
10
+ assert.instanceOf(association, DomainAssociation)
11
+ assert.isTrue(dataDomain.graph.hasNode(association.key))
12
+ })
13
+
14
+ test('adds an association with a target entity', ({ assert }) => {
15
+ const dataDomain = new DataDomain()
16
+ const model = dataDomain.addModel()
17
+ const entity1 = model.addEntity({ key: 'entity1' })
18
+ const entity2 = model.addEntity({ key: 'entity2' })
19
+ const association = entity1.addAssociation({ key: entity2.key })
20
+ assert.instanceOf(association, DomainAssociation)
21
+ assert.isTrue(dataDomain.graph.hasNode(association.key))
22
+ assert.deepEqual(association.targets, [{ key: entity2.key }])
23
+ })
24
+
25
+ test('throws an error if the target entity does not exist', ({ assert }) => {
26
+ const dataDomain = new DataDomain()
27
+ const model = dataDomain.addModel()
28
+ const entity = model.addEntity()
29
+ assert.throws(() => {
30
+ entity.addAssociation({ key: 'non-existent-entity' })
31
+ }, 'Target entity non-existent-entity not found')
32
+ })
33
+
34
+ test('adds an association with default values', ({ assert }) => {
35
+ const dataDomain = new DataDomain()
36
+ const model = dataDomain.addModel()
37
+ const entity = model.addEntity()
38
+ const association = entity.addAssociation()
39
+ assert.instanceOf(association, DomainAssociation)
40
+ assert.isTrue(dataDomain.graph.hasNode(association.key))
41
+ assert.equal(association.info.name, 'New association')
42
+ })
43
+
44
+ test('notifies change', async ({ assert }) => {
45
+ const dataDomain = new DataDomain()
46
+ const model = dataDomain.addModel()
47
+ const entity = model.addEntity()
48
+ entity.addAssociation()
49
+ await assert.dispatches(dataDomain, 'change', { timeout: 20 })
50
+ })
51
+
52
+ test('adds an association to the fields array', ({ assert }) => {
53
+ const dataDomain = new DataDomain()
54
+ const model = dataDomain.addModel()
55
+ const entity = model.addEntity()
56
+ const association = entity.addAssociation()
57
+ assert.deepEqual(entity.fields, [{ key: association.key, type: 'association' }])
58
+ })
59
+
60
+ test('adds an association to the root graph', ({ assert }) => {
61
+ const dataDomain = new DataDomain()
62
+ const model = dataDomain.addModel()
63
+ const entity = model.addEntity()
64
+ const association = entity.addAssociation()
65
+ assert.isTrue(dataDomain.graph.hasNode(association.key))
66
+ })
67
+
68
+ test('creates a graph edge', ({ assert }) => {
69
+ const dataDomain = new DataDomain()
70
+ const model = dataDomain.addModel()
71
+ const entity = model.addEntity()
72
+ const association = entity.addAssociation()
73
+ assert.isTrue(dataDomain.graph.hasEdge(entity.key, association.key))
74
+ assert.deepEqual(dataDomain.graph.edge(entity.key, association.key), { type: 'association' })
75
+ })
76
+
77
+ test('adds association with a foreign target', ({ assert }) => {
78
+ const root1 = new DataDomain()
79
+ const root2 = new DataDomain()
80
+ const m1 = root1.addModel()
81
+ const m2 = root2.addModel()
82
+ const e1 = m1.addEntity()
83
+ const e2 = m2.addEntity()
84
+ root2.info.version = '1.0.0'
85
+ root1.registerForeignDomain(root2)
86
+
87
+ const association = e1.addAssociation({ key: e2.key, domain: root2.key })
88
+ assert.instanceOf(association, DomainAssociation)
89
+ assert.isTrue(root1.graph.hasNode(association.key))
90
+ assert.deepEqual(association.targets, [{ key: e2.key, domain: root2.key }])
91
+ })
92
+
93
+ test('throws an error if the foreign target entity does not exist', ({ assert }) => {
94
+ const root1 = new DataDomain()
95
+ const root2 = new DataDomain()
96
+ const m1 = root1.addModel()
97
+ const entity = m1.addEntity()
98
+ root2.info.version = '1.0.0'
99
+ root1.registerForeignDomain(root2)
100
+ assert.throws(() => {
101
+ entity.addAssociation({ key: 'non-existent-entity', domain: root2.key })
102
+ }, `Foreign entity ${root2.key}:non-existent-entity not found`)
103
+ })
104
+ })
105
+
106
+ test.group('DomainEntity.removeAssociation()', () => {
107
+ test('removes an association from the entity', ({ assert }) => {
108
+ const dataDomain = new DataDomain()
109
+ const model = dataDomain.addModel()
110
+ const entity = model.addEntity()
111
+ const association = entity.addAssociation()
112
+ entity.removeAssociation(association.key)
113
+ assert.isFalse(dataDomain.graph.hasNode(association.key))
114
+ assert.deepEqual(entity.fields, [])
115
+ })
116
+
117
+ test('throws an error if the association does not exist', ({ assert }) => {
118
+ const dataDomain = new DataDomain()
119
+ const model = dataDomain.addModel()
120
+ const entity = model.addEntity()
121
+ assert.throws(() => {
122
+ entity.removeAssociation('non-existent-association')
123
+ }, 'Unable to find a connection between this entity and the non-existent-association association')
124
+ })
125
+
126
+ test('throws an error if the edge exists but is not an association', ({ assert }) => {
127
+ const dataDomain = new DataDomain()
128
+ const model = dataDomain.addModel()
129
+ const entity1 = model.addEntity({ key: 'entity1' })
130
+ const entity2 = model.addEntity({ key: 'entity2' })
131
+ dataDomain.graph.setEdge(entity1.key, entity2.key, { type: 'parent' })
132
+
133
+ assert.throws(() => {
134
+ entity1.removeAssociation(entity2.key)
135
+ }, 'Association entity2 does not exist')
136
+ })
137
+
138
+ test('notifies change', async ({ assert }) => {
139
+ const dataDomain = new DataDomain()
140
+ const model = dataDomain.addModel()
141
+ const entity = model.addEntity()
142
+ const association = entity.addAssociation()
143
+ entity.removeAssociation(association.key)
144
+ await assert.dispatches(dataDomain, 'change', { timeout: 20 })
145
+ })
146
+
147
+ test('removes the association from the fields array', ({ assert }) => {
148
+ const dataDomain = new DataDomain()
149
+ const model = dataDomain.addModel()
150
+ const entity = model.addEntity()
151
+ const association = entity.addAssociation()
152
+ entity.removeAssociation(association.key)
153
+ assert.deepEqual(entity.fields, [])
154
+ })
155
+
156
+ test('removes the association from the root graph', ({ assert }) => {
157
+ const dataDomain = new DataDomain()
158
+ const model = dataDomain.addModel()
159
+ const entity = model.addEntity()
160
+ const association = entity.addAssociation()
161
+ entity.removeAssociation(association.key)
162
+ assert.isFalse(dataDomain.graph.hasNode(association.key))
163
+ })
164
+
165
+ test('removes the graph edge', ({ assert }) => {
166
+ const dataDomain = new DataDomain()
167
+ const model = dataDomain.addModel()
168
+ const entity = model.addEntity()
169
+ const association = entity.addAssociation()
170
+ entity.removeAssociation(association.key)
171
+ assert.isFalse(dataDomain.graph.hasEdge(entity.key, association.key))
172
+ })
173
+
174
+ test('removes only the specified association', ({ assert }) => {
175
+ const dataDomain = new DataDomain()
176
+ const model = dataDomain.addModel()
177
+ const entity = model.addEntity()
178
+ const association1 = entity.addAssociation()
179
+ const association2 = entity.addAssociation()
180
+ entity.removeAssociation(association1.key)
181
+ assert.isFalse(dataDomain.graph.hasNode(association1.key))
182
+ assert.isTrue(dataDomain.graph.hasNode(association2.key))
183
+ assert.deepEqual(entity.fields, [{ key: association2.key, type: 'association' }])
184
+ })
185
+
186
+ test('does not remove other entities or models', ({ assert }) => {
187
+ const dataDomain = new DataDomain()
188
+ const model = dataDomain.addModel()
189
+ const entity1 = model.addEntity()
190
+ const entity2 = model.addEntity()
191
+ const association = entity1.addAssociation()
192
+ entity1.removeAssociation(association.key)
193
+ assert.isTrue(dataDomain.graph.hasNode(entity2.key))
194
+ assert.isTrue(dataDomain.graph.hasNode(model.key))
195
+ })
196
+
197
+ test('does not remove other associations', ({ assert }) => {
198
+ const dataDomain = new DataDomain()
199
+ const model = dataDomain.addModel()
200
+ const entity = model.addEntity()
201
+ const association1 = entity.addAssociation()
202
+ const association2 = entity.addAssociation()
203
+ entity.removeAssociation(association1.key)
204
+ assert.isFalse(dataDomain.graph.hasNode(association1.key))
205
+ assert.isTrue(dataDomain.graph.hasNode(association2.key))
206
+ })
207
+ })
208
+
209
+ test.group('DomainEntity.listAssociations()', () => {
210
+ test('lists all associations in the entity', ({ assert }) => {
211
+ const dataDomain = new DataDomain()
212
+ const model = dataDomain.addModel()
213
+ const entity = model.addEntity()
214
+ const association1 = entity.addAssociation()
215
+ const association2 = entity.addAssociation()
216
+ const associations = [...entity.listAssociations()]
217
+ assert.lengthOf(associations, 2)
218
+ assert.deepInclude(associations, association1)
219
+ assert.deepInclude(associations, association2)
220
+ })
221
+
222
+ test('returns an empty array if there are no associations', ({ assert }) => {
223
+ const dataDomain = new DataDomain()
224
+ const model = dataDomain.addModel()
225
+ const entity = model.addEntity()
226
+ const associations = [...entity.listAssociations()]
227
+ assert.lengthOf(associations, 0)
228
+ })
229
+
230
+ test('returns only associations', ({ assert }) => {
231
+ const dataDomain = new DataDomain()
232
+ const model = dataDomain.addModel()
233
+ const entity = model.addEntity()
234
+ const association1 = entity.addAssociation()
235
+ entity.addProperty()
236
+ const associations = [...entity.listAssociations()]
237
+ assert.lengthOf(associations, 1)
238
+ assert.deepInclude(associations, association1)
239
+ })
240
+
241
+ test('associations in the list are of type DomainAssociation', ({ assert }) => {
242
+ const dataDomain = new DataDomain()
243
+ const model = dataDomain.addModel()
244
+ const entity = model.addEntity()
245
+ entity.addAssociation()
246
+ const associations = [...entity.listAssociations()]
247
+ assert.instanceOf(associations[0], DomainAssociation)
248
+ })
249
+
250
+ test('lists associations in the order they were added', ({ assert }) => {
251
+ const dataDomain = new DataDomain()
252
+ const model = dataDomain.addModel()
253
+ const entity = model.addEntity()
254
+ const association1 = entity.addAssociation()
255
+ const association2 = entity.addAssociation()
256
+ const associations = [...entity.listAssociations()]
257
+ assert.deepEqual(associations, [association1, association2])
258
+ })
259
+
260
+ test('lists associations when there are other domain elements', ({ assert }) => {
261
+ const dataDomain = new DataDomain()
262
+ const model = dataDomain.addModel()
263
+ const entity = model.addEntity()
264
+ const association1 = entity.addAssociation()
265
+ entity.addProperty()
266
+ const associations = [...entity.listAssociations()]
267
+ assert.deepEqual(associations, [association1])
268
+ })
269
+
270
+ test('lists associations when fields array is empty', ({ assert }) => {
271
+ const dataDomain = new DataDomain()
272
+ const model = dataDomain.addModel()
273
+ const entity = model.addEntity()
274
+ entity.fields = []
275
+ const associations = [...entity.listAssociations()]
276
+ assert.deepEqual(associations, [])
277
+ })
278
+
279
+ test('lists associations when fields array contains only properties', ({ assert }) => {
280
+ const dataDomain = new DataDomain()
281
+ const model = dataDomain.addModel()
282
+ const entity = model.addEntity()
283
+ const property = entity.addProperty()
284
+ entity.fields = [{ key: property.key, type: 'property' }]
285
+ const associations = [...entity.listAssociations()]
286
+ assert.deepEqual(associations, [])
287
+ })
288
+ })
289
+
290
+ test.group('DomainEntity.hasAssociations()', () => {
291
+ test('returns true if the entity has associations', ({ assert }) => {
292
+ const dataDomain = new DataDomain()
293
+ const model = dataDomain.addModel()
294
+ const entity = model.addEntity()
295
+ entity.addAssociation()
296
+ assert.isTrue(entity.hasAssociations())
297
+ })
298
+
299
+ test('returns false if the entity has no associations', ({ assert }) => {
300
+ const dataDomain = new DataDomain()
301
+ const model = dataDomain.addModel()
302
+ const entity = model.addEntity()
303
+ assert.isFalse(entity.hasAssociations())
304
+ })
305
+
306
+ test('returns false if the entity has other fields but not associations', ({ assert }) => {
307
+ const dataDomain = new DataDomain()
308
+ const model = dataDomain.addModel()
309
+ const entity = model.addEntity()
310
+ entity.addProperty()
311
+ assert.isFalse(entity.hasAssociations())
312
+ })
313
+
314
+ test('returns true if the entity has both properties and associations', ({ assert }) => {
315
+ const dataDomain = new DataDomain()
316
+ const model = dataDomain.addModel()
317
+ const entity = model.addEntity()
318
+ entity.addProperty()
319
+ entity.addAssociation()
320
+ assert.isTrue(entity.hasAssociations())
321
+ })
322
+
323
+ test('returns false if the entity has no fields', ({ assert }) => {
324
+ const dataDomain = new DataDomain()
325
+ const model = dataDomain.addModel()
326
+ const entity = model.addEntity()
327
+ entity.fields = []
328
+ assert.isFalse(entity.hasAssociations())
329
+ })
330
+ })