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