@api-client/core 0.11.10 → 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 +26 -26
  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 -6
  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,408 @@
1
+ import { test } from '@japa/runner'
2
+ import { DataDomain, DomainEntity, DomainEntityKind } from '../../../src/index.js'
3
+
4
+ test.group('DomainModel.addEntity()', () => {
5
+ test('adds an entity to the model', ({ assert }) => {
6
+ const dataDomain = new DataDomain()
7
+ const model = dataDomain.addModel({ key: 'test-model' })
8
+ const entity = model.addEntity({ key: 'test-entity' })
9
+ assert.instanceOf(entity, DomainEntity)
10
+ assert.equal(entity.kind, DomainEntityKind)
11
+ assert.equal(entity.key, 'test-entity')
12
+ assert.deepInclude(entity.info, { name: 'New entity' })
13
+ assert.isTrue(dataDomain.graph.hasNode(entity.key))
14
+ assert.equal(dataDomain.graph.parent(entity.key), model.key)
15
+ })
16
+
17
+ test('adds an entity with default values', ({ assert }) => {
18
+ const dataDomain = new DataDomain()
19
+ const model = dataDomain.addModel({ key: 'test-model' })
20
+ const entity = model.addEntity()
21
+ assert.instanceOf(entity, DomainEntity)
22
+ assert.equal(entity.kind, DomainEntityKind)
23
+ assert.typeOf(entity.key, 'string')
24
+ assert.isNotEmpty(entity.key)
25
+ assert.deepInclude(entity.info, { name: 'New entity' })
26
+ assert.isTrue(dataDomain.graph.hasNode(entity.key))
27
+ assert.equal(dataDomain.graph.parent(entity.key), model.key)
28
+ })
29
+
30
+ test('throws an error if an entity with the same key already exists', ({ assert }) => {
31
+ const dataDomain = new DataDomain()
32
+ const model = dataDomain.addModel({ key: 'test-model' })
33
+ model.addEntity({ key: 'test-entity' })
34
+ assert.throws(() => {
35
+ model.addEntity({ key: 'test-entity' })
36
+ }, 'Entity with key test-entity already exists')
37
+ })
38
+
39
+ test('notifies change', async ({ assert }) => {
40
+ const dataDomain = new DataDomain()
41
+ const model = dataDomain.addModel({ key: 'test-model' })
42
+ model.addEntity({ key: 'test-entity' })
43
+ await assert.dispatches(dataDomain, 'change', { timeout: 20 })
44
+ })
45
+
46
+ test('adds an entity to the fields array', ({ assert }) => {
47
+ const dataDomain = new DataDomain()
48
+ const model = dataDomain.addModel({ key: 'test-model' })
49
+ const entity = model.addEntity({ key: 'test-entity' })
50
+ assert.deepEqual(model.fields, [{ key: entity.key, type: 'entity' }])
51
+ })
52
+
53
+ test('adds an entity to the root graph', ({ assert }) => {
54
+ const dataDomain = new DataDomain()
55
+ const model = dataDomain.addModel({ key: 'test-model' })
56
+ const entity = model.addEntity({ key: 'test-entity' })
57
+ assert.isTrue(dataDomain.graph.hasNode(entity.key))
58
+ })
59
+
60
+ test('adds an entity with a parent relationship', ({ assert }) => {
61
+ const dataDomain = new DataDomain()
62
+ const model = dataDomain.addModel({ key: 'test-model' })
63
+ const entity = model.addEntity({ key: 'test-entity' })
64
+ assert.equal(dataDomain.graph.parent(entity.key), model.key)
65
+ })
66
+ })
67
+
68
+ test.group('DomainModel.removeEntity()', () => {
69
+ test('removes an entity from the model', ({ assert }) => {
70
+ const dataDomain = new DataDomain()
71
+ const model = dataDomain.addModel({ key: 'test-model' })
72
+ const entity = model.addEntity({ key: 'test-entity' })
73
+ model.removeEntity(entity.key)
74
+ assert.isFalse(dataDomain.graph.hasNode(entity.key))
75
+ assert.deepEqual(model.fields, [])
76
+ })
77
+
78
+ test('throws an error if the entity does not exist', ({ assert }) => {
79
+ const dataDomain = new DataDomain()
80
+ const model = dataDomain.addModel({ key: 'test-model' })
81
+ assert.throws(() => {
82
+ model.removeEntity('non-existent-entity')
83
+ }, "Trying to remove the non-existent-entity entity, but it doesn't exist")
84
+ })
85
+
86
+ test('throws an error if the key is not an entity', ({ assert }) => {
87
+ const dataDomain = new DataDomain()
88
+ const model = dataDomain.addModel({ key: 'test-model' })
89
+ assert.throws(() => {
90
+ model.removeEntity(model.key)
91
+ }, `Trying to remove the ${model.key} entity, but it is not an entity`)
92
+ })
93
+
94
+ test('throws an error if the entity belongs to another parent', ({ assert }) => {
95
+ const root = new DataDomain()
96
+ const m1 = root.addModel()
97
+ const m2 = root.addModel()
98
+ const e1 = m1.addEntity()
99
+ assert.throws(() => {
100
+ m2.removeEntity(e1.key)
101
+ }, `Trying to remove the ${e1.key} entity, but it is not a child of this model`)
102
+ })
103
+
104
+ test('notifies change', async ({ assert }) => {
105
+ const dataDomain = new DataDomain()
106
+ const model = dataDomain.addModel({ key: 'test-model' })
107
+ const entity = model.addEntity({ key: 'test-entity' })
108
+ model.removeEntity(entity.key)
109
+ await assert.dispatches(dataDomain, 'change', { timeout: 20 })
110
+ })
111
+
112
+ test('removes the entity from the fields array', ({ assert }) => {
113
+ const dataDomain = new DataDomain()
114
+ const model = dataDomain.addModel({ key: 'test-model' })
115
+ const entity = model.addEntity({ key: 'test-entity' })
116
+ model.removeEntity(entity.key)
117
+ assert.deepEqual(model.fields, [])
118
+ })
119
+
120
+ test('removes the entity from the root graph', ({ assert }) => {
121
+ const dataDomain = new DataDomain()
122
+ const model = dataDomain.addModel({ key: 'test-model' })
123
+ const entity = model.addEntity({ key: 'test-entity' })
124
+ model.removeEntity(entity.key)
125
+ assert.isFalse(dataDomain.graph.hasNode(entity.key))
126
+ })
127
+
128
+ test('removes the parent relationship', ({ assert }) => {
129
+ const dataDomain = new DataDomain()
130
+ const model = dataDomain.addModel({ key: 'test-model' })
131
+ const entity = model.addEntity({ key: 'test-entity' })
132
+ model.removeEntity(entity.key)
133
+ assert.isUndefined(dataDomain.graph.parent(entity.key))
134
+ assert.deepEqual([...dataDomain.graph.children(model.key)], [])
135
+ })
136
+
137
+ test('removes an entity with properties', ({ assert }) => {
138
+ const dataDomain = new DataDomain()
139
+ const model = dataDomain.addModel({ key: 'test-model' })
140
+ const entity = model.addEntity({ key: 'test-entity' })
141
+ entity.addProperty({ key: 'test-property', type: 'string' })
142
+ model.removeEntity(entity.key)
143
+ assert.isFalse(dataDomain.graph.hasNode(entity.key))
144
+ assert.isFalse(dataDomain.graph.hasNode('test-property'))
145
+ })
146
+
147
+ test('removes an entity with associations', ({ assert }) => {
148
+ const dataDomain = new DataDomain()
149
+ const model = dataDomain.addModel({ key: 'test-model' })
150
+ const entity = model.addEntity({ key: 'test-entity' })
151
+ const association = entity.addAssociation()
152
+ model.removeEntity(entity.key)
153
+ assert.isFalse(dataDomain.graph.hasNode(entity.key))
154
+ assert.isFalse(dataDomain.graph.hasNode(association.key))
155
+ })
156
+ })
157
+
158
+ test.group('DomainModel.attachEntity()', () => {
159
+ test('attaches an entity to the model', ({ assert }) => {
160
+ const root = new DataDomain()
161
+ const m1 = root.addModel()
162
+ const m2 = root.addModel()
163
+ const e1 = m1.addEntity()
164
+ m2.attachEntity(e1.key)
165
+ assert.isTrue(root.graph.hasNode(e1.key))
166
+ assert.equal(root.graph.parent(e1.key), m2.key)
167
+ assert.deepEqual(m2.fields, [{ key: e1.key, type: 'entity' }])
168
+ })
169
+
170
+ test('throws an error if the entity does not exist', ({ assert }) => {
171
+ const dataDomain = new DataDomain()
172
+ const model = dataDomain.addModel()
173
+ assert.throws(() => {
174
+ model.attachEntity('non-existent-entity')
175
+ }, "Trying to attach the non-existent-entity entity, but it doesn't exist")
176
+ })
177
+
178
+ test('throws an error if the key is not an entity', ({ assert }) => {
179
+ const dataDomain = new DataDomain()
180
+ const model = dataDomain.addModel({ key: 'test-model' })
181
+ assert.throws(() => {
182
+ model.attachEntity(model.key)
183
+ }, `Trying to attach the ${model.key} entity, but it is not a entity`)
184
+ })
185
+
186
+ test('throws an error if the entity is already a child of this model', ({ assert }) => {
187
+ const dataDomain = new DataDomain()
188
+ const model = dataDomain.addModel()
189
+ const entity = model.addEntity()
190
+ assert.throws(() => {
191
+ model.attachEntity(entity.key)
192
+ }, `Trying to attach the ${entity.key} entity, but it is already a child of this model`)
193
+ })
194
+
195
+ test('throws an error if the entity is not in the same domain', ({ assert }) => {
196
+ const dataDomain1 = new DataDomain()
197
+ const model1 = dataDomain1.addModel()
198
+
199
+ const dataDomain2 = new DataDomain()
200
+ const model2 = dataDomain2.addModel()
201
+ const entity = model2.addEntity()
202
+ dataDomain2.info.version = '1.0.0'
203
+ dataDomain1.registerForeignDomain(dataDomain2)
204
+
205
+ assert.throws(() => {
206
+ model1.attachEntity(`${dataDomain2.key}:${entity.key}`)
207
+ }, `Trying to attach the ${dataDomain2.key}:${entity.key} entity, but it is not in the same domain`)
208
+ })
209
+
210
+ test('attaches an entity to the fields array', ({ assert }) => {
211
+ const dataDomain = new DataDomain()
212
+ const model1 = dataDomain.addModel({ key: 'test-model1' })
213
+ const model2 = dataDomain.addModel({ key: 'test-model2' })
214
+ const entity = model1.addEntity({ key: 'test-entity' })
215
+ model2.attachEntity(entity.key)
216
+ assert.deepEqual(model2.fields, [{ key: entity.key, type: 'entity' }])
217
+ })
218
+
219
+ test('attaches an entity to the root graph', ({ assert }) => {
220
+ const dataDomain = new DataDomain()
221
+ const model1 = dataDomain.addModel({ key: 'test-model1' })
222
+ const model2 = dataDomain.addModel({ key: 'test-model2' })
223
+ const entity = model1.addEntity({ key: 'test-entity' })
224
+ model2.attachEntity(entity.key)
225
+ assert.isTrue(dataDomain.graph.hasNode(entity.key))
226
+ })
227
+
228
+ test('attaches an entity with a parent relationship', ({ assert }) => {
229
+ const dataDomain = new DataDomain()
230
+ const model1 = dataDomain.addModel({ key: 'test-model1' })
231
+ const model2 = dataDomain.addModel({ key: 'test-model2' })
232
+ const entity = model1.addEntity({ key: 'test-entity' })
233
+ model2.attachEntity(entity.key)
234
+ assert.equal(dataDomain.graph.parent(entity.key), model2.key)
235
+ })
236
+
237
+ test('attaches an entity and removes it from the previous parent', ({ assert }) => {
238
+ const dataDomain = new DataDomain()
239
+ const model1 = dataDomain.addModel()
240
+ const model2 = dataDomain.addModel()
241
+ const entity = model1.addEntity()
242
+ model2.attachEntity(entity.key)
243
+ assert.deepEqual(model1.fields, [])
244
+ })
245
+ })
246
+
247
+ test.group('DomainModel.detachEntity()', () => {
248
+ test('detaches an entity from the model', ({ assert }) => {
249
+ const dataDomain = new DataDomain()
250
+ const model = dataDomain.addModel()
251
+ const entity = model.addEntity()
252
+ model.detachEntity(entity.key)
253
+ assert.isFalse(dataDomain.graph.hasParent(entity.key, model.key))
254
+ assert.deepEqual(model.fields, [])
255
+ })
256
+
257
+ test('throws an error if the entity does not exist', ({ assert }) => {
258
+ const dataDomain = new DataDomain()
259
+ const model = dataDomain.addModel()
260
+ assert.throws(() => {
261
+ model.detachEntity('non-existent-entity')
262
+ }, "Trying to detach the non-existent-entity entity, but it doesn't exist")
263
+ })
264
+
265
+ test('throws an error if the key is not an entity', ({ assert }) => {
266
+ const dataDomain = new DataDomain()
267
+ const model = dataDomain.addModel()
268
+ model.fields.push({ key: model.key, type: 'entity' })
269
+ assert.throws(() => {
270
+ model.detachEntity(model.key)
271
+ }, `Trying to detach the ${model.key} entity, but it is not an entity`)
272
+ })
273
+
274
+ test('throws an error if the entity is not a child of this model', ({ assert }) => {
275
+ const root = new DataDomain()
276
+ const m1 = root.addModel()
277
+ const m2 = root.addModel()
278
+ const e1 = m1.addEntity()
279
+ m2.fields.push({ key: e1.key, type: 'entity' })
280
+ assert.throws(() => {
281
+ m2.detachEntity(e1.key)
282
+ }, `Trying to detach the ${e1.key} entity, but it is not a child of this model`)
283
+ })
284
+
285
+ test('detaches an entity from the fields array', ({ assert }) => {
286
+ const dataDomain = new DataDomain()
287
+ const model = dataDomain.addModel()
288
+ const entity = model.addEntity()
289
+ model.detachEntity(entity.key)
290
+ assert.deepEqual(model.fields, [])
291
+ })
292
+
293
+ test('adds an entity from the root graph', ({ assert }) => {
294
+ const dataDomain = new DataDomain()
295
+ const model = dataDomain.addModel()
296
+ const entity = model.addEntity()
297
+ model.detachEntity(entity.key)
298
+ assert.isTrue(dataDomain.graph.hasNode(entity.key))
299
+ })
300
+
301
+ test('detaches an entity and sets its parent to the root graph', ({ assert }) => {
302
+ const dataDomain = new DataDomain()
303
+ const model = dataDomain.addModel()
304
+ const entity = model.addEntity()
305
+ model.detachEntity(entity.key)
306
+ assert.equal(dataDomain.graph.parent(entity.key), undefined)
307
+ })
308
+ })
309
+
310
+ test.group('DomainModel.listEntities()', () => {
311
+ test('lists all entities in the model', ({ assert }) => {
312
+ const dataDomain = new DataDomain()
313
+ const model = dataDomain.addModel({ key: 'test-model' })
314
+ const entity1 = model.addEntity({ key: 'entity1' })
315
+ const entity2 = model.addEntity({ key: 'entity2' })
316
+ const entities = [...model.listEntities()]
317
+ assert.lengthOf(entities, 2)
318
+ assert.deepInclude(entities, entity1)
319
+ assert.deepInclude(entities, entity2)
320
+ })
321
+
322
+ test('returns an empty array if there are no entities', ({ assert }) => {
323
+ const dataDomain = new DataDomain()
324
+ const model = dataDomain.addModel({ key: 'test-model' })
325
+ const entities = [...model.listEntities()]
326
+ assert.lengthOf(entities, 0)
327
+ })
328
+
329
+ test('returns only entities', ({ assert }) => {
330
+ const dataDomain = new DataDomain()
331
+ const model = dataDomain.addModel({ key: 'test-model' })
332
+ const entity1 = model.addEntity({ key: 'entity1' })
333
+ dataDomain.addNamespace({ key: 'ns1' })
334
+ const entities = [...model.listEntities()]
335
+ assert.lengthOf(entities, 1)
336
+ assert.deepInclude(entities, entity1)
337
+ })
338
+
339
+ test('entities in the list are of type DomainEntity', ({ assert }) => {
340
+ const dataDomain = new DataDomain()
341
+ const model = dataDomain.addModel({ key: 'test-model' })
342
+ model.addEntity({ key: 'entity1' })
343
+ const entities = [...model.listEntities()]
344
+ assert.instanceOf(entities[0], DomainEntity)
345
+ })
346
+
347
+ test('lists entities in the order they were added', ({ assert }) => {
348
+ const dataDomain = new DataDomain()
349
+ const model = dataDomain.addModel({ key: 'test-model' })
350
+ const entity1 = model.addEntity({ key: 'entity1' })
351
+ const entity2 = model.addEntity({ key: 'entity2' })
352
+ const entities = [...model.listEntities()]
353
+ assert.deepEqual(entities, [entity1, entity2])
354
+ })
355
+
356
+ test('lists entities when there are no entities', ({ assert }) => {
357
+ const dataDomain = new DataDomain()
358
+ const model = dataDomain.addModel({ key: 'test-model' })
359
+ const entities = [...model.listEntities()]
360
+ assert.deepEqual(entities, [])
361
+ })
362
+
363
+ test('lists entities when there are other domain elements', ({ assert }) => {
364
+ const dataDomain = new DataDomain()
365
+ const model = dataDomain.addModel({ key: 'test-model' })
366
+ const entity1 = model.addEntity({ key: 'entity1' })
367
+ dataDomain.addNamespace({ key: 'ns1' })
368
+ const entities = [...model.listEntities()]
369
+ assert.deepEqual(entities, [entity1])
370
+ })
371
+ })
372
+
373
+ test.group('DomainModel.hasEntities()', () => {
374
+ test('returns true if there are child entities', ({ assert }) => {
375
+ const dataDomain = new DataDomain()
376
+ const model = dataDomain.addModel({ key: 'test-model' })
377
+ model.addEntity({ key: 'test-entity' })
378
+ assert.isTrue(model.hasEntities())
379
+ })
380
+
381
+ test('returns false if there are no child entities', ({ assert }) => {
382
+ const dataDomain = new DataDomain()
383
+ const model = dataDomain.addModel({ key: 'test-model' })
384
+ assert.isFalse(model.hasEntities())
385
+ })
386
+
387
+ test('returns false if there are only other domain elements', ({ assert }) => {
388
+ const dataDomain = new DataDomain()
389
+ const model = dataDomain.addModel({ key: 'test-model' })
390
+ dataDomain.addNamespace({ key: 'test-namespace' })
391
+ assert.isFalse(model.hasEntities())
392
+ })
393
+
394
+ test('returns true if there are both entities and other domain elements', ({ assert }) => {
395
+ const dataDomain = new DataDomain()
396
+ const model = dataDomain.addModel({ key: 'test-model' })
397
+ model.addEntity({ key: 'test-entity' })
398
+ dataDomain.addNamespace({ key: 'test-namespace' })
399
+ assert.isTrue(model.hasEntities())
400
+ })
401
+
402
+ test('returns false if the model has no fields', ({ assert }) => {
403
+ const dataDomain = new DataDomain()
404
+ const model = dataDomain.addModel({ key: 'test-model' })
405
+ model.fields = []
406
+ assert.isFalse(model.hasEntities())
407
+ })
408
+ })