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