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