@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,568 @@
1
+ import { test } from '@japa/runner'
2
+ import {
3
+ DataDomain,
4
+ DomainModel,
5
+ DomainModelKind,
6
+ Thing,
7
+ DomainNamespaceKind,
8
+ DataDomainKind,
9
+ } from '../../../src/index.js'
10
+ import type { ModelOrderedItem } from '../../../src/modeling/DomainModel.js'
11
+
12
+ test.group('DomainModel.createSchema()', () => {
13
+ test('creates a schema with default values', ({ assert }) => {
14
+ const schema = DomainModel.createSchema()
15
+ assert.equal(schema.kind, DomainModelKind)
16
+ assert.typeOf(schema.key, 'string')
17
+ assert.isNotEmpty(schema.key)
18
+ assert.deepInclude(schema.info, { name: 'New model' })
19
+ })
20
+
21
+ test('creates a schema with provided values', ({ assert }) => {
22
+ const schema = DomainModel.createSchema({
23
+ key: 'test-model',
24
+ info: { name: 'Test Model', description: 'A test model' },
25
+ deprecated: true,
26
+ })
27
+ assert.equal(schema.kind, DomainModelKind)
28
+ assert.equal(schema.key, 'test-model')
29
+ assert.deepInclude(schema.info, { name: 'Test Model', description: 'A test model' })
30
+ assert.isTrue(schema.deprecated)
31
+ })
32
+
33
+ test('creates a schema with partial info', ({ assert }) => {
34
+ const schema = DomainModel.createSchema({
35
+ info: { name: 'Test Model' },
36
+ })
37
+ assert.equal(schema.kind, DomainModelKind)
38
+ assert.typeOf(schema.key, 'string')
39
+ assert.isNotEmpty(schema.key)
40
+ assert.deepInclude(schema.info, { name: 'Test Model' })
41
+ })
42
+
43
+ test('creates a schema with empty info', ({ assert }) => {
44
+ const schema = DomainModel.createSchema({
45
+ info: {},
46
+ })
47
+ assert.equal(schema.kind, DomainModelKind)
48
+ assert.typeOf(schema.key, 'string')
49
+ assert.isNotEmpty(schema.key)
50
+ assert.deepInclude(schema.info, { name: 'New model' })
51
+ })
52
+
53
+ test('creates a schema with fields', ({ assert }) => {
54
+ const schema = DomainModel.createSchema({
55
+ fields: [{ key: 'test-entity', type: 'entity' }],
56
+ })
57
+ assert.equal(schema.kind, DomainModelKind)
58
+ assert.typeOf(schema.key, 'string')
59
+ assert.isNotEmpty(schema.key)
60
+ assert.deepInclude(schema.info, { name: 'New model' })
61
+ assert.deepEqual(schema.fields, [{ key: 'test-entity', type: 'entity' }])
62
+ })
63
+
64
+ test('creates a schema with deprecated set to true', ({ assert }) => {
65
+ const schema = DomainModel.createSchema({
66
+ deprecated: true,
67
+ })
68
+ assert.equal(schema.kind, DomainModelKind)
69
+ assert.typeOf(schema.key, 'string')
70
+ assert.isNotEmpty(schema.key)
71
+ assert.deepInclude(schema.info, { name: 'New model' })
72
+ assert.isTrue(schema.deprecated)
73
+ })
74
+
75
+ test('creates a schema with deprecated set to false', ({ assert }) => {
76
+ const schema = DomainModel.createSchema({
77
+ deprecated: false,
78
+ })
79
+ assert.equal(schema.kind, DomainModelKind)
80
+ assert.typeOf(schema.key, 'string')
81
+ assert.isNotEmpty(schema.key)
82
+ assert.deepInclude(schema.info, { name: 'New model' })
83
+ assert.isFalse(schema.deprecated)
84
+ })
85
+
86
+ test('creates a schema with a custom key', ({ assert }) => {
87
+ const customKey = 'custom-key'
88
+ const schema = DomainModel.createSchema({ key: customKey })
89
+ assert.equal(schema.key, customKey)
90
+ })
91
+
92
+ test('creates a schema with custom info', ({ assert }) => {
93
+ const customInfo = { name: 'Custom Name', description: 'Custom Description' }
94
+ const schema = DomainModel.createSchema({ info: customInfo })
95
+ assert.deepInclude(schema.info, customInfo)
96
+ })
97
+
98
+ test('creates a schema with custom fields', ({ assert }) => {
99
+ const customFields: ModelOrderedItem[] = [{ key: 'custom-entity', type: 'entity' }]
100
+ const schema = DomainModel.createSchema({ fields: customFields })
101
+ assert.deepEqual(schema.fields, customFields)
102
+ })
103
+
104
+ test('creates a schema with custom deprecated value', ({ assert }) => {
105
+ const schemaTrue = DomainModel.createSchema({ deprecated: true })
106
+ assert.isTrue(schemaTrue.deprecated)
107
+
108
+ const schemaFalse = DomainModel.createSchema({ deprecated: false })
109
+ assert.isFalse(schemaFalse.deprecated)
110
+ })
111
+ })
112
+
113
+ test.group('DomainModel.constructor()', () => {
114
+ test('creates a new DomainModel with default values', ({ assert }) => {
115
+ const dataDomain = new DataDomain()
116
+ const model = new DomainModel(dataDomain)
117
+ assert.equal(model.kind, DomainModelKind)
118
+ assert.typeOf(model.key, 'string')
119
+ assert.isNotEmpty(model.key)
120
+ assert.instanceOf(model.info, Thing)
121
+ assert.equal(model.info.name, 'New model')
122
+ assert.deepEqual(model.fields, [])
123
+ assert.isUndefined(model.deprecated)
124
+ })
125
+
126
+ test('creates a new DomainModel with provided values', ({ assert }) => {
127
+ const dataDomain = new DataDomain()
128
+ const model = new DomainModel(dataDomain, {
129
+ key: 'test-model',
130
+ info: { name: 'Test Model', description: 'A test model' },
131
+ deprecated: true,
132
+ fields: [{ key: 'test-entity', type: 'entity' }],
133
+ })
134
+ assert.equal(model.kind, DomainModelKind)
135
+ assert.equal(model.key, 'test-model')
136
+ assert.instanceOf(model.info, Thing)
137
+ assert.equal(model.info.name, 'Test Model')
138
+ assert.equal(model.info.description, 'A test model')
139
+ assert.isTrue(model.deprecated)
140
+ assert.deepEqual(model.fields, [{ key: 'test-entity', type: 'entity' }])
141
+ })
142
+
143
+ test('creates a new DomainModel with partial info', ({ assert }) => {
144
+ const dataDomain = new DataDomain()
145
+ const model = new DomainModel(dataDomain, {
146
+ info: { name: 'Test Model' },
147
+ })
148
+ assert.equal(model.kind, DomainModelKind)
149
+ assert.typeOf(model.key, 'string')
150
+ assert.isNotEmpty(model.key)
151
+ assert.instanceOf(model.info, Thing)
152
+ assert.equal(model.info.name, 'Test Model')
153
+ })
154
+
155
+ test('creates a new DomainModel with empty info', ({ assert }) => {
156
+ const dataDomain = new DataDomain()
157
+ const model = new DomainModel(dataDomain, {
158
+ info: {},
159
+ })
160
+ assert.equal(model.kind, DomainModelKind)
161
+ assert.typeOf(model.key, 'string')
162
+ assert.isNotEmpty(model.key)
163
+ assert.instanceOf(model.info, Thing)
164
+ assert.equal(model.info.name, 'New model')
165
+ })
166
+
167
+ test('creates a new DomainModel with deprecated set to true', ({ assert }) => {
168
+ const dataDomain = new DataDomain()
169
+ const model = new DomainModel(dataDomain, {
170
+ deprecated: true,
171
+ })
172
+ assert.equal(model.kind, DomainModelKind)
173
+ assert.typeOf(model.key, 'string')
174
+ assert.isNotEmpty(model.key)
175
+ assert.instanceOf(model.info, Thing)
176
+ assert.equal(model.info.name, 'New model')
177
+ assert.isTrue(model.deprecated)
178
+ })
179
+
180
+ test('creates a new DomainModel with deprecated set to false', ({ assert }) => {
181
+ const dataDomain = new DataDomain()
182
+ const model = new DomainModel(dataDomain, {
183
+ deprecated: false,
184
+ })
185
+ assert.equal(model.kind, DomainModelKind)
186
+ assert.typeOf(model.key, 'string')
187
+ assert.isNotEmpty(model.key)
188
+ assert.instanceOf(model.info, Thing)
189
+ assert.equal(model.info.name, 'New model')
190
+ assert.isFalse(model.deprecated)
191
+ })
192
+
193
+ test('creates a new DomainModel with a custom key', ({ assert }) => {
194
+ const dataDomain = new DataDomain()
195
+ const model = new DomainModel(dataDomain, { key: 'custom-key' })
196
+ assert.equal(model.key, 'custom-key')
197
+ })
198
+
199
+ test('creates a new DomainModel with custom info', ({ assert }) => {
200
+ const dataDomain = new DataDomain()
201
+ const customInfo = { name: 'Custom Name', description: 'Custom Description' }
202
+ const model = new DomainModel(dataDomain, { info: customInfo })
203
+ assert.deepInclude(model.info, customInfo)
204
+ })
205
+
206
+ test('creates a new DomainModel with custom fields', ({ assert }) => {
207
+ const dataDomain = new DataDomain()
208
+ const customFields: ModelOrderedItem[] = [{ key: 'custom-entity', type: 'entity' }]
209
+ const model = new DomainModel(dataDomain, { fields: customFields })
210
+ assert.deepEqual(model.fields, customFields)
211
+ })
212
+
213
+ test('creates a new DomainModel with custom deprecated value', ({ assert }) => {
214
+ const dataDomain = new DataDomain()
215
+ const modelTrue = new DomainModel(dataDomain, { deprecated: true })
216
+ assert.isTrue(modelTrue.deprecated)
217
+
218
+ const modelFalse = new DomainModel(dataDomain, { deprecated: false })
219
+ assert.isFalse(modelFalse.deprecated)
220
+ })
221
+
222
+ test('sets deprecated to undefined when not provided', ({ assert }) => {
223
+ const dataDomain = new DataDomain()
224
+ const model = new DomainModel(dataDomain, {})
225
+ assert.isUndefined(model.deprecated)
226
+ })
227
+
228
+ test('sets fields to empty array when not provided', ({ assert }) => {
229
+ const dataDomain = new DataDomain()
230
+ const model = new DomainModel(dataDomain, {})
231
+ assert.deepEqual(model.fields, [])
232
+ })
233
+
234
+ test('sets fields to empty array when fields is undefined', ({ assert }) => {
235
+ const dataDomain = new DataDomain()
236
+ const model = new DomainModel(dataDomain, { fields: undefined })
237
+ assert.deepEqual(model.fields, [])
238
+ })
239
+ })
240
+
241
+ test.group('DomainModel.toJSON()', () => {
242
+ test('returns a valid schema with default values', ({ assert }) => {
243
+ const dataDomain = new DataDomain()
244
+ const model = new DomainModel(dataDomain)
245
+ const json = model.toJSON()
246
+ assert.equal(json.kind, DomainModelKind)
247
+ assert.equal(json.key, model.key)
248
+ assert.deepInclude(json.info, { name: 'New model' })
249
+ assert.isUndefined(json.fields)
250
+ assert.isUndefined(json.deprecated)
251
+ })
252
+
253
+ test('returns a valid schema with provided values', ({ assert }) => {
254
+ const dataDomain = new DataDomain()
255
+ const model = new DomainModel(dataDomain, {
256
+ key: 'test-model',
257
+ info: { name: 'Test Model', description: 'A test model' },
258
+ deprecated: true,
259
+ fields: [{ key: 'test-entity', type: 'entity' }],
260
+ })
261
+ const json = model.toJSON()
262
+ assert.equal(json.kind, DomainModelKind)
263
+ assert.equal(json.key, 'test-model')
264
+ assert.deepInclude(json.info, { name: 'Test Model', description: 'A test model' })
265
+ assert.isTrue(json.deprecated)
266
+ assert.deepEqual(json.fields, [{ key: 'test-entity', type: 'entity' }])
267
+ })
268
+
269
+ test('includes child entities in the schema', ({ assert }) => {
270
+ const dataDomain = new DataDomain()
271
+ const model = dataDomain.addModel()
272
+ const entity = model.addEntity({ key: 'test-entity' })
273
+ const json = model.toJSON()
274
+ assert.isArray(json.fields)
275
+ assert.lengthOf(json.fields!, 1)
276
+ assert.deepEqual(json.fields, [{ key: entity.key, type: 'entity' }])
277
+ })
278
+
279
+ test('includes deprecated flag when true', ({ assert }) => {
280
+ const dataDomain = new DataDomain()
281
+ const model = dataDomain.addModel({ deprecated: true })
282
+ const json = model.toJSON()
283
+ assert.isTrue(json.deprecated)
284
+ })
285
+
286
+ test('includes deprecated flag when false', ({ assert }) => {
287
+ const dataDomain = new DataDomain()
288
+ const model = dataDomain.addModel({ deprecated: false })
289
+ const json = model.toJSON()
290
+ assert.isFalse(json.deprecated)
291
+ })
292
+
293
+ test('includes multiple fields in the correct order', ({ assert }) => {
294
+ const dataDomain = new DataDomain()
295
+ const model = dataDomain.addModel()
296
+ const entity1 = model.addEntity({ key: 'entity1' })
297
+ const entity2 = model.addEntity({ key: 'entity2' })
298
+ const json = model.toJSON()
299
+ assert.isArray(json.fields)
300
+ assert.lengthOf(json.fields!, 2)
301
+ assert.deepEqual(json.fields, [
302
+ { key: entity1.key, type: 'entity' },
303
+ { key: entity2.key, type: 'entity' },
304
+ ])
305
+ })
306
+
307
+ test('serializes the "info" property', ({ assert }) => {
308
+ const dataDomain = new DataDomain()
309
+ const model = dataDomain.addModel({
310
+ info: { name: 'Test Name', description: 'Test Description' },
311
+ })
312
+ const json = model.toJSON()
313
+ assert.deepInclude(json.info, { name: 'Test Name', description: 'Test Description' })
314
+ })
315
+ })
316
+
317
+ test.group('DomainModel.getParentInstance()', () => {
318
+ test('returns the data domain when the model is at the root', ({ assert }) => {
319
+ const dataDomain = new DataDomain()
320
+ const model = dataDomain.addModel()
321
+ const parent = model.getParentInstance()
322
+ assert.deepEqual(parent, dataDomain)
323
+ })
324
+
325
+ test('returns the parent namespace when the model is a child', ({ assert }) => {
326
+ const dataDomain = new DataDomain()
327
+ const parentNamespace = dataDomain.addNamespace()
328
+ const model = parentNamespace.addModel()
329
+ const parent = model.getParentInstance()
330
+ assert.deepEqual(parent, parentNamespace)
331
+ })
332
+
333
+ test('returns the correct parent when there are multiple levels of nesting', ({ assert }) => {
334
+ const dataDomain = new DataDomain()
335
+ const parentNamespace = dataDomain.addNamespace()
336
+ const model = parentNamespace.addModel()
337
+ model.addEntity()
338
+ const parent = model.getParentInstance()
339
+ assert.deepEqual(parent, parentNamespace)
340
+ })
341
+
342
+ test('returns the data domain when the model has no parent', ({ assert }) => {
343
+ const dataDomain = new DataDomain()
344
+ const model = dataDomain.addModel()
345
+ dataDomain.graph.removeParent(model.key)
346
+ const parent = model.getParentInstance()
347
+ assert.deepEqual(parent, dataDomain)
348
+ })
349
+ })
350
+
351
+ test.group('DomainModel.breadcrumbs()', () => {
352
+ test('creates breadcrumbs from model to data domain', ({ assert }) => {
353
+ const dataDomain = new DataDomain()
354
+ const model = dataDomain.addModel({ info: { name: 'Test Model' } })
355
+ const breadcrumbs = model.breadcrumbs()
356
+ assert.lengthOf(breadcrumbs, 2)
357
+ assert.deepEqual(breadcrumbs[0], {
358
+ key: dataDomain.key,
359
+ name: 'Unnamed domain',
360
+ kind: DataDomainKind,
361
+ })
362
+ assert.deepEqual(breadcrumbs[1], {
363
+ key: model.key,
364
+ name: 'Test Model',
365
+ kind: DomainModelKind,
366
+ })
367
+ })
368
+
369
+ test('creates breadcrumbs from model to data domain with custom names', ({ assert }) => {
370
+ const dataDomain = new DataDomain()
371
+ dataDomain.info.name = 'Custom Data Domain'
372
+ const model = dataDomain.addModel({ info: { name: 'Test Model' } })
373
+ const breadcrumbs = model.breadcrumbs()
374
+ assert.lengthOf(breadcrumbs, 2)
375
+ assert.deepEqual(breadcrumbs[0], {
376
+ key: dataDomain.key,
377
+ name: 'Custom Data Domain',
378
+ kind: DataDomainKind,
379
+ })
380
+ assert.deepEqual(breadcrumbs[1], {
381
+ key: model.key,
382
+ name: 'Test Model',
383
+ kind: DomainModelKind,
384
+ })
385
+ })
386
+
387
+ test('creates breadcrumbs from model to namespace to data domain', ({ assert }) => {
388
+ const dataDomain = new DataDomain()
389
+ const namespace = dataDomain.addNamespace({ info: { name: 'Test Namespace' } })
390
+ const model = namespace.addModel({ info: { name: 'Test Model' } })
391
+ const breadcrumbs = model.breadcrumbs()
392
+ assert.lengthOf(breadcrumbs, 3)
393
+ assert.deepEqual(breadcrumbs[0], {
394
+ key: dataDomain.key,
395
+ name: 'Unnamed domain',
396
+ kind: DataDomainKind,
397
+ })
398
+ assert.deepEqual(breadcrumbs[1], {
399
+ key: namespace.key,
400
+ name: 'Test Namespace',
401
+ kind: DomainNamespaceKind,
402
+ })
403
+ assert.deepEqual(breadcrumbs[2], {
404
+ key: model.key,
405
+ name: 'Test Model',
406
+ kind: DomainModelKind,
407
+ })
408
+ })
409
+
410
+ test('creates breadcrumbs from model to nested namespaces to data domain', ({ assert }) => {
411
+ const dataDomain = new DataDomain()
412
+ const namespace1 = dataDomain.addNamespace({ info: { name: 'Test Namespace 1' } })
413
+ const namespace2 = namespace1.addNamespace({ info: { name: 'Test Namespace 2' } })
414
+ const model = namespace2.addModel({ info: { name: 'Test Model' } })
415
+ const breadcrumbs = model.breadcrumbs()
416
+ assert.lengthOf(breadcrumbs, 4)
417
+ assert.deepEqual(breadcrumbs[0], {
418
+ key: dataDomain.key,
419
+ name: 'Unnamed domain',
420
+ kind: DataDomainKind,
421
+ })
422
+ assert.deepEqual(breadcrumbs[1], {
423
+ key: namespace1.key,
424
+ name: 'Test Namespace 1',
425
+ kind: DomainNamespaceKind,
426
+ })
427
+ assert.deepEqual(breadcrumbs[2], {
428
+ key: namespace2.key,
429
+ name: 'Test Namespace 2',
430
+ kind: DomainNamespaceKind,
431
+ })
432
+ assert.deepEqual(breadcrumbs[3], {
433
+ key: model.key,
434
+ name: 'Test Model',
435
+ kind: DomainModelKind,
436
+ })
437
+ })
438
+
439
+ test('creates breadcrumbs with unnamed data domain, namespaces, and model', ({ assert }) => {
440
+ const root = new DataDomain()
441
+ root.info.name = undefined
442
+ const n1 = root.addNamespace()
443
+ n1.info.name = undefined
444
+ const n2 = n1.addNamespace()
445
+ n2.info.name = undefined
446
+ const m1 = n2.addModel()
447
+ m1.info.name = undefined
448
+ const breadcrumbs = m1.breadcrumbs()
449
+ assert.lengthOf(breadcrumbs, 4)
450
+ const [b1, b2, b3, b4] = breadcrumbs
451
+ assert.deepEqual(b1, {
452
+ key: root.key,
453
+ name: 'Unnamed data domain',
454
+ kind: DataDomainKind,
455
+ })
456
+ assert.deepEqual(b2, {
457
+ key: n1.key,
458
+ name: 'Unnamed namespace',
459
+ kind: DomainNamespaceKind,
460
+ })
461
+ assert.deepEqual(b3, {
462
+ key: n2.key,
463
+ name: 'Unnamed namespace',
464
+ kind: DomainNamespaceKind,
465
+ })
466
+ assert.deepEqual(b4, {
467
+ key: m1.key,
468
+ name: 'Unnamed model',
469
+ kind: DomainModelKind,
470
+ })
471
+ })
472
+ })
473
+
474
+ test.group('DomainModel.hasFields()', () => {
475
+ test('returns true if there are child entities', ({ assert }) => {
476
+ const dataDomain = new DataDomain()
477
+ const model = dataDomain.addModel({ key: 'test-model' })
478
+ model.addEntity({ key: 'test-entity' })
479
+ assert.isTrue(model.hasFields())
480
+ })
481
+
482
+ test('returns false if there are no child entities', ({ assert }) => {
483
+ const dataDomain = new DataDomain()
484
+ const model = dataDomain.addModel({ key: 'test-model' })
485
+ assert.isFalse(model.hasFields())
486
+ })
487
+
488
+ test('returns false if there are only other domain elements', ({ assert }) => {
489
+ const dataDomain = new DataDomain()
490
+ const model = dataDomain.addModel({ key: 'test-model' })
491
+ dataDomain.addNamespace({ key: 'test-namespace' })
492
+ assert.isFalse(model.hasFields())
493
+ })
494
+
495
+ test('returns true if there are both entities and other domain elements', ({ assert }) => {
496
+ const dataDomain = new DataDomain()
497
+ const model = dataDomain.addModel({ key: 'test-model' })
498
+ model.addEntity({ key: 'test-entity' })
499
+ dataDomain.addNamespace({ key: 'test-namespace' })
500
+ assert.isTrue(model.hasFields())
501
+ })
502
+
503
+ test('returns false if the model has no fields', ({ assert }) => {
504
+ const dataDomain = new DataDomain()
505
+ const model = dataDomain.addModel({ key: 'test-model' })
506
+ model.fields = []
507
+ assert.isFalse(model.hasFields())
508
+ })
509
+ })
510
+
511
+ test.group('DomainModel.isChildOf()', () => {
512
+ test('returns false when called on non existing key', ({ assert }) => {
513
+ const dataDomain = new DataDomain()
514
+ const model = dataDomain.addModel()
515
+ const result = model.isChildOf('some-key')
516
+ assert.isFalse(result)
517
+ })
518
+
519
+ test('returns true when called on a direct parent', ({ assert }) => {
520
+ const dataDomain = new DataDomain()
521
+ const namespace = dataDomain.addNamespace()
522
+ const model = namespace.addModel()
523
+ const result = model.isChildOf(namespace.key)
524
+ assert.isTrue(result)
525
+ })
526
+
527
+ test('returns true when called on a grandparent', ({ assert }) => {
528
+ const dataDomain = new DataDomain()
529
+ const namespace1 = dataDomain.addNamespace()
530
+ const namespace2 = namespace1.addNamespace()
531
+ const model = namespace2.addModel()
532
+ const result = model.isChildOf(dataDomain.key)
533
+ assert.isTrue(result)
534
+ })
535
+
536
+ test('returns false when called on a sibling', ({ assert }) => {
537
+ const dataDomain = new DataDomain()
538
+ const namespace = dataDomain.addNamespace()
539
+ const model1 = namespace.addModel()
540
+ const model2 = namespace.addModel()
541
+ const result = model1.isChildOf(model2.key)
542
+ assert.isFalse(result)
543
+ })
544
+
545
+ test('returns false when called on self', ({ assert }) => {
546
+ const dataDomain = new DataDomain()
547
+ const model = dataDomain.addModel()
548
+ const result = model.isChildOf(model.key)
549
+ assert.isFalse(result)
550
+ })
551
+
552
+ test('returns true when the model is a child of the given namespace', ({ assert }) => {
553
+ const dataDomain = new DataDomain()
554
+ const namespace = dataDomain.addNamespace()
555
+ const model = namespace.addModel()
556
+ const result = model.isChildOf(namespace.key)
557
+ assert.isTrue(result)
558
+ })
559
+
560
+ test('returns false when the model is not a child of the given namespace', ({ assert }) => {
561
+ const dataDomain = new DataDomain()
562
+ const namespace1 = dataDomain.addNamespace()
563
+ const namespace2 = dataDomain.addNamespace()
564
+ const model = namespace1.addModel()
565
+ const result = model.isChildOf(namespace2.key)
566
+ assert.isFalse(result)
567
+ })
568
+ })