@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,264 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { DataDomain } from '../../../src/modeling/DataDomain.js'
|
|
3
|
+
import { DomainProperty } from '../../../src/modeling/DomainProperty.js'
|
|
4
|
+
|
|
5
|
+
test.group('DataDomain.addProperty()', () => {
|
|
6
|
+
test('addProperty adds a property to an entity', ({ 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
|
+
const property = dataDomain.addProperty(entity.key, { key: 'test-property' })
|
|
11
|
+
assert.instanceOf(property, DomainProperty)
|
|
12
|
+
assert.isTrue(dataDomain.graph.hasNode(property.key))
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('addProperty adds a property with default values', ({ assert }) => {
|
|
16
|
+
const dataDomain = new DataDomain()
|
|
17
|
+
const model = dataDomain.addModel({ key: 'test-model' })
|
|
18
|
+
const entity = dataDomain.addEntity(model.key, { key: 'test-entity' })
|
|
19
|
+
const property = dataDomain.addProperty(entity.key)
|
|
20
|
+
assert.instanceOf(property, DomainProperty)
|
|
21
|
+
assert.isTrue(dataDomain.graph.hasNode(property.key))
|
|
22
|
+
assert.equal(property.info.name, 'New property')
|
|
23
|
+
assert.equal(property.type, 'string')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('addProperty throws an error if parent entity does not exist', ({ assert }) => {
|
|
27
|
+
const dataDomain = new DataDomain()
|
|
28
|
+
assert.throws(() => {
|
|
29
|
+
dataDomain.addProperty('non-existent-entity', { key: 'test-property' })
|
|
30
|
+
}, 'Parent entity non-existent-entity does not exist')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('addProperty throws an error if parent is not an entity', ({ assert }) => {
|
|
34
|
+
const dataDomain = new DataDomain()
|
|
35
|
+
const model = dataDomain.addModel()
|
|
36
|
+
assert.throws(() => {
|
|
37
|
+
dataDomain.addProperty(model.key)
|
|
38
|
+
}, `Parent entity ${model.key} not found`)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('addProperty notifies change', async ({ assert }) => {
|
|
42
|
+
const dataDomain = new DataDomain()
|
|
43
|
+
const model = dataDomain.addModel()
|
|
44
|
+
const entity = dataDomain.addEntity(model.key)
|
|
45
|
+
dataDomain.addProperty(entity.key)
|
|
46
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('addProperty adds a property to a parent entity - checks parent-child relationship', ({ assert }) => {
|
|
50
|
+
const dataDomain = new DataDomain()
|
|
51
|
+
const model = dataDomain.addModel()
|
|
52
|
+
const entity = dataDomain.addEntity(model.key)
|
|
53
|
+
const property = dataDomain.addProperty(entity.key)
|
|
54
|
+
assert.isTrue(dataDomain.graph.hasEdge(entity.key, property.key))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('addProperty adds a property to a parent entity - checks items list', ({ assert }) => {
|
|
58
|
+
const dataDomain = new DataDomain()
|
|
59
|
+
const model = dataDomain.addModel()
|
|
60
|
+
const entity = dataDomain.addEntity(model.key)
|
|
61
|
+
const property = dataDomain.addProperty(entity.key)
|
|
62
|
+
assert.deepInclude([...entity.listProperties()], property)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('addProperty throws an error if no parent is provided', ({ assert }) => {
|
|
66
|
+
const dataDomain = new DataDomain()
|
|
67
|
+
assert.throws(() => {
|
|
68
|
+
// @ts-expect-error For testing purposes, we are passing undefined
|
|
69
|
+
dataDomain.addProperty(undefined)
|
|
70
|
+
}, 'A property expects a DataEntity parent')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('addProperty throws when adding property to a foreign entity', ({ assert }) => {
|
|
74
|
+
const domain1 = new DataDomain()
|
|
75
|
+
const m1 = domain1.addModel({ key: 'model1' })
|
|
76
|
+
domain1.addEntity(m1.key, { key: 'entity1' })
|
|
77
|
+
|
|
78
|
+
const domain2 = new DataDomain()
|
|
79
|
+
const m2 = domain2.addModel({ key: 'model2' })
|
|
80
|
+
const e2 = domain2.addEntity(m2.key, { key: 'entity2' })
|
|
81
|
+
|
|
82
|
+
domain2.info.version = '1.0.0'
|
|
83
|
+
domain1.registerForeignDomain(domain2)
|
|
84
|
+
|
|
85
|
+
assert.throws(() => {
|
|
86
|
+
domain1.addProperty(`${domain2.key}:${e2.key}`)
|
|
87
|
+
}, 'Cannot add a property to a foreign domain')
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test.group('DataDomain.removeProperty()', () => {
|
|
92
|
+
test('removes a property from the graph', ({ assert }) => {
|
|
93
|
+
const dataDomain = new DataDomain()
|
|
94
|
+
const model = dataDomain.addModel()
|
|
95
|
+
const entity = dataDomain.addEntity(model.key)
|
|
96
|
+
const property = dataDomain.addProperty(entity.key)
|
|
97
|
+
dataDomain.removeProperty(property.key)
|
|
98
|
+
assert.isFalse(dataDomain.graph.hasNode(property.key))
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('throws an error if the property does not exist', ({ assert }) => {
|
|
102
|
+
const dataDomain = new DataDomain()
|
|
103
|
+
assert.throws(() => {
|
|
104
|
+
dataDomain.removeProperty('non-existent-property')
|
|
105
|
+
}, 'Property non-existent-property does not exist')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('removes the property from the parent entity', ({ assert }) => {
|
|
109
|
+
const dataDomain = new DataDomain()
|
|
110
|
+
const model = dataDomain.addModel()
|
|
111
|
+
const entity = dataDomain.addEntity(model.key)
|
|
112
|
+
const property = dataDomain.addProperty(entity.key)
|
|
113
|
+
dataDomain.removeProperty(property.key)
|
|
114
|
+
assert.isUndefined(entity.listProperties().next().value)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('throws an error when the parent entity is not found', ({ assert }) => {
|
|
118
|
+
const dataDomain = new DataDomain()
|
|
119
|
+
const property = new DomainProperty(dataDomain, 'non-existent-entity')
|
|
120
|
+
dataDomain.graph.setNode(property.key, property)
|
|
121
|
+
assert.throws(() => {
|
|
122
|
+
dataDomain.removeProperty(property.key)
|
|
123
|
+
}, `Parent entity not found for property ${property.key}`)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('notifies change', async ({ assert }) => {
|
|
127
|
+
const dataDomain = new DataDomain()
|
|
128
|
+
const model = dataDomain.addModel()
|
|
129
|
+
const entity = dataDomain.addEntity(model.key)
|
|
130
|
+
const property = dataDomain.addProperty(entity.key)
|
|
131
|
+
dataDomain.removeProperty(property.key)
|
|
132
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('throws an error if the property is not of type DomainProperty', ({ assert }) => {
|
|
136
|
+
const dataDomain = new DataDomain()
|
|
137
|
+
const model = dataDomain.addModel()
|
|
138
|
+
dataDomain.graph.setNode(model.key, model)
|
|
139
|
+
assert.throws(() => {
|
|
140
|
+
dataDomain.removeProperty(model.key)
|
|
141
|
+
}, `Property ${model.key} not found`)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('throws an error if trying to remove a property from a foreign domain', ({ assert }) => {
|
|
145
|
+
const domain1 = new DataDomain()
|
|
146
|
+
const m1 = domain1.addModel()
|
|
147
|
+
domain1.addEntity(m1.key)
|
|
148
|
+
|
|
149
|
+
const domain2 = new DataDomain()
|
|
150
|
+
const m2 = domain2.addModel()
|
|
151
|
+
const e2 = domain2.addEntity(m2.key)
|
|
152
|
+
const property = domain2.addProperty(e2.key)
|
|
153
|
+
|
|
154
|
+
domain2.info.version = '1.0.0'
|
|
155
|
+
domain1.registerForeignDomain(domain2)
|
|
156
|
+
assert.throws(() => {
|
|
157
|
+
domain1.removeProperty(`${domain2.key}:${property.key}`)
|
|
158
|
+
}, 'Cannot remove a property from a foreign domain')
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test('removes the property from the fields list', ({ assert }) => {
|
|
162
|
+
const dataDomain = new DataDomain()
|
|
163
|
+
const model = dataDomain.addModel()
|
|
164
|
+
const entity = dataDomain.addEntity(model.key)
|
|
165
|
+
const property = dataDomain.addProperty(entity.key)
|
|
166
|
+
dataDomain.removeProperty(property.key)
|
|
167
|
+
assert.deepEqual([...entity.listFields()], [])
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
test.group('DataDomain.findProperty()', () => {
|
|
172
|
+
test('finds a property by its key', ({ assert }) => {
|
|
173
|
+
const dataDomain = new DataDomain()
|
|
174
|
+
const model = dataDomain.addModel()
|
|
175
|
+
const entity = dataDomain.addEntity(model.key)
|
|
176
|
+
const property = dataDomain.addProperty(entity.key)
|
|
177
|
+
const foundProperty = dataDomain.findProperty(property.key)
|
|
178
|
+
assert.deepEqual(foundProperty, property)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('returns undefined if property does not exist', ({ assert }) => {
|
|
182
|
+
const dataDomain = new DataDomain()
|
|
183
|
+
const foundProperty = dataDomain.findProperty('non-existent-property')
|
|
184
|
+
assert.isUndefined(foundProperty)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('returns undefined if key is not a property', ({ assert }) => {
|
|
188
|
+
const dataDomain = new DataDomain()
|
|
189
|
+
const model = dataDomain.addModel()
|
|
190
|
+
const foundProperty = dataDomain.findProperty(model.key)
|
|
191
|
+
assert.isUndefined(foundProperty)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('returns undefined if key is undefined', ({ assert }) => {
|
|
195
|
+
const dataDomain = new DataDomain()
|
|
196
|
+
// @ts-expect-error For testing purposes
|
|
197
|
+
const foundProperty = dataDomain.findProperty(undefined)
|
|
198
|
+
assert.isUndefined(foundProperty)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test('returns undefined if key is null', ({ assert }) => {
|
|
202
|
+
const dataDomain = new DataDomain()
|
|
203
|
+
// @ts-expect-error For testing purposes
|
|
204
|
+
const foundProperty = dataDomain.findProperty(null)
|
|
205
|
+
assert.isUndefined(foundProperty)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
test('returns undefined if key is an empty string', ({ assert }) => {
|
|
209
|
+
const dataDomain = new DataDomain()
|
|
210
|
+
const foundProperty = dataDomain.findProperty('')
|
|
211
|
+
assert.isUndefined(foundProperty)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('returns undefined if key is a number', ({ assert }) => {
|
|
215
|
+
const dataDomain = new DataDomain()
|
|
216
|
+
// @ts-expect-error For testing purposes
|
|
217
|
+
const foundProperty = dataDomain.findProperty(123)
|
|
218
|
+
assert.isUndefined(foundProperty)
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test('returns undefined if key is a boolean', ({ assert }) => {
|
|
222
|
+
const dataDomain = new DataDomain()
|
|
223
|
+
// @ts-expect-error For testing purposes
|
|
224
|
+
const foundProperty = dataDomain.findProperty(true)
|
|
225
|
+
assert.isUndefined(foundProperty)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test('returns undefined if key is an object', ({ assert }) => {
|
|
229
|
+
const dataDomain = new DataDomain()
|
|
230
|
+
// @ts-expect-error For testing purposes
|
|
231
|
+
const foundProperty = dataDomain.findProperty({})
|
|
232
|
+
assert.isUndefined(foundProperty)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('returns undefined if key is an array', ({ assert }) => {
|
|
236
|
+
const dataDomain = new DataDomain()
|
|
237
|
+
// @ts-expect-error For testing purposes
|
|
238
|
+
const foundProperty = dataDomain.findProperty([])
|
|
239
|
+
assert.isUndefined(foundProperty)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('returns undefined if key is a function', ({ assert }) => {
|
|
243
|
+
const dataDomain = new DataDomain()
|
|
244
|
+
// @ts-expect-error For testing purposes
|
|
245
|
+
const foundProperty = dataDomain.findProperty(() => {})
|
|
246
|
+
assert.isUndefined(foundProperty)
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
test('finds a property in a foreign domain', ({ assert }) => {
|
|
250
|
+
const domain1 = new DataDomain()
|
|
251
|
+
const m1 = domain1.addModel({ key: 'model1' })
|
|
252
|
+
domain1.addEntity(m1.key, { key: 'entity1' })
|
|
253
|
+
|
|
254
|
+
const domain2 = new DataDomain()
|
|
255
|
+
const m2 = domain2.addModel({ key: 'model2' })
|
|
256
|
+
const e2 = domain2.addEntity(m2.key, { key: 'entity2' })
|
|
257
|
+
const property = domain2.addProperty(e2.key, { key: 'test-property' })
|
|
258
|
+
domain2.info.version = '1.0.0'
|
|
259
|
+
domain1.registerForeignDomain(domain2)
|
|
260
|
+
|
|
261
|
+
const foundProperty = domain1.findProperty(`${domain2.key}:${property.key}`)
|
|
262
|
+
assert.deepEqual(foundProperty, property)
|
|
263
|
+
})
|
|
264
|
+
})
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import {
|
|
3
|
+
DomainAssociationKind,
|
|
4
|
+
DataDomain,
|
|
5
|
+
DomainEntityKind,
|
|
6
|
+
DomainModelKind,
|
|
7
|
+
DomainNamespaceKind,
|
|
8
|
+
DomainPropertyKind,
|
|
9
|
+
} from '../../../src/index.js'
|
|
10
|
+
|
|
11
|
+
test.group('DataDomain Serialization and Deserialization', () => {
|
|
12
|
+
test('should serialize and deserialize an empty DataDomain', ({ assert }) => {
|
|
13
|
+
const domain = new DataDomain()
|
|
14
|
+
const serialized = domain.toJSON()
|
|
15
|
+
const restored = new DataDomain(serialized)
|
|
16
|
+
|
|
17
|
+
assert.equal(restored.key, domain.key)
|
|
18
|
+
assert.equal(restored.kind, domain.kind)
|
|
19
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
20
|
+
assert.equal([...restored.graph.nodes()].length, 0)
|
|
21
|
+
assert.equal([...restored.graph.edges()].length, 0)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('should serialize and deserialize a DataDomain with namespaces', ({ assert }) => {
|
|
25
|
+
const domain = new DataDomain()
|
|
26
|
+
const ns1 = domain.addNamespace()
|
|
27
|
+
const ns2 = ns1.addNamespace()
|
|
28
|
+
|
|
29
|
+
const serialized = domain.toJSON()
|
|
30
|
+
const restored = new DataDomain(serialized)
|
|
31
|
+
|
|
32
|
+
assert.equal(restored.key, domain.key)
|
|
33
|
+
assert.equal(restored.kind, domain.kind)
|
|
34
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
35
|
+
assert.equal([...restored.graph.nodes()].length, 2)
|
|
36
|
+
assert.equal([...restored.graph.edges()].length, 0)
|
|
37
|
+
|
|
38
|
+
const rn1 = restored.findNamespace(ns1.key)
|
|
39
|
+
assert.isDefined(rn1)
|
|
40
|
+
assert.equal(rn1!.key, ns1.key)
|
|
41
|
+
assert.equal(rn1!.kind, DomainNamespaceKind)
|
|
42
|
+
|
|
43
|
+
const rn2 = restored.findNamespace(ns2.key)
|
|
44
|
+
assert.isDefined(rn2)
|
|
45
|
+
assert.equal(rn2!.key, ns2.key)
|
|
46
|
+
assert.equal(rn2!.kind, DomainNamespaceKind)
|
|
47
|
+
assert.equal(restored.graph.parent(ns2.key), ns1.key)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('should serialize and deserialize a DataDomain with models', ({ assert }) => {
|
|
51
|
+
const domain = new DataDomain()
|
|
52
|
+
const m1 = domain.addModel()
|
|
53
|
+
const m2 = domain.addModel()
|
|
54
|
+
|
|
55
|
+
const serialized = domain.toJSON()
|
|
56
|
+
const restored = new DataDomain(serialized)
|
|
57
|
+
|
|
58
|
+
assert.equal(restored.key, domain.key)
|
|
59
|
+
assert.equal(restored.kind, domain.kind)
|
|
60
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
61
|
+
assert.equal([...restored.graph.nodes()].length, 2)
|
|
62
|
+
assert.equal([...restored.graph.edges()].length, 0)
|
|
63
|
+
|
|
64
|
+
const rm1 = restored.findModel(m1.key)
|
|
65
|
+
assert.isDefined(rm1)
|
|
66
|
+
assert.equal(rm1!.key, m1.key)
|
|
67
|
+
assert.equal(rm1!.kind, DomainModelKind)
|
|
68
|
+
|
|
69
|
+
const rm2 = restored.findModel(m2.key)
|
|
70
|
+
assert.isDefined(rm2)
|
|
71
|
+
assert.equal(rm2!.key, m2.key)
|
|
72
|
+
assert.equal(rm2!.kind, DomainModelKind)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('should serialize and deserialize a DataDomain with entities', ({ assert }) => {
|
|
76
|
+
const domain = new DataDomain()
|
|
77
|
+
const m1 = domain.addModel()
|
|
78
|
+
const e1 = m1.addEntity()
|
|
79
|
+
const e2 = m1.addEntity()
|
|
80
|
+
e2.addParent(e1.key)
|
|
81
|
+
|
|
82
|
+
const serialized = domain.toJSON()
|
|
83
|
+
const restored = new DataDomain(serialized)
|
|
84
|
+
|
|
85
|
+
assert.equal(restored.key, domain.key)
|
|
86
|
+
assert.equal(restored.kind, domain.kind)
|
|
87
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
88
|
+
assert.equal([...restored.graph.nodes()].length, 3)
|
|
89
|
+
assert.equal([...restored.graph.edges()].length, 1)
|
|
90
|
+
|
|
91
|
+
const re1 = restored.findEntity(e1.key)
|
|
92
|
+
assert.isDefined(re1)
|
|
93
|
+
assert.equal(re1!.key, e1.key)
|
|
94
|
+
assert.equal(re1!.kind, DomainEntityKind)
|
|
95
|
+
|
|
96
|
+
const re2 = restored.findEntity(e2.key)
|
|
97
|
+
assert.isDefined(re2)
|
|
98
|
+
assert.equal(re2!.key, e2.key)
|
|
99
|
+
assert.equal(re2!.kind, DomainEntityKind)
|
|
100
|
+
assert.equal([...re2!.listParents()][0].key, e1.key)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('should serialize and deserialize a DataDomain with properties', ({ assert }) => {
|
|
104
|
+
const domain = new DataDomain()
|
|
105
|
+
const m1 = domain.addModel()
|
|
106
|
+
const e1 = m1.addEntity()
|
|
107
|
+
const p1 = e1.addProperty({ type: 'string' })
|
|
108
|
+
const p2 = e1.addProperty({ type: 'number' })
|
|
109
|
+
|
|
110
|
+
const serialized = domain.toJSON()
|
|
111
|
+
const restored = new DataDomain(serialized)
|
|
112
|
+
|
|
113
|
+
assert.equal(restored.key, domain.key)
|
|
114
|
+
assert.equal(restored.kind, domain.kind)
|
|
115
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
116
|
+
assert.equal([...restored.graph.nodes()].length, 4)
|
|
117
|
+
assert.equal([...restored.graph.edges()].length, 2)
|
|
118
|
+
|
|
119
|
+
const rp1 = restored.findProperty(p1.key)
|
|
120
|
+
assert.isDefined(rp1)
|
|
121
|
+
assert.equal(rp1!.key, p1.key)
|
|
122
|
+
assert.equal(rp1!.kind, DomainPropertyKind)
|
|
123
|
+
|
|
124
|
+
const rp2 = restored.findProperty(p2.key)
|
|
125
|
+
assert.isDefined(rp2)
|
|
126
|
+
assert.equal(rp2!.key, p2.key)
|
|
127
|
+
assert.equal(rp2!.kind, DomainPropertyKind)
|
|
128
|
+
|
|
129
|
+
const re1 = restored.findEntity(e1.key)
|
|
130
|
+
assert.isDefined(re1)
|
|
131
|
+
const props = [...re1!.listProperties()]
|
|
132
|
+
assert.equal(props.length, 2)
|
|
133
|
+
assert.equal(props[0].key, p1.key)
|
|
134
|
+
assert.equal(props[1].key, p2.key)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('should serialize and deserialize a DataDomain with associations', ({ assert }) => {
|
|
138
|
+
const domain = new DataDomain()
|
|
139
|
+
const m1 = domain.addModel()
|
|
140
|
+
const e1 = m1.addEntity()
|
|
141
|
+
const e2 = m1.addEntity()
|
|
142
|
+
const a1 = e1.addAssociation({ key: e2.key })
|
|
143
|
+
|
|
144
|
+
const serialized = domain.toJSON()
|
|
145
|
+
const restored = new DataDomain(serialized)
|
|
146
|
+
|
|
147
|
+
assert.equal(restored.key, domain.key)
|
|
148
|
+
assert.equal(restored.kind, domain.kind)
|
|
149
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
150
|
+
assert.equal([...restored.graph.nodes()].length, 4)
|
|
151
|
+
assert.equal([...restored.graph.edges()].length, 2)
|
|
152
|
+
|
|
153
|
+
const ra1 = restored.findAssociation(a1.key)
|
|
154
|
+
assert.isDefined(ra1)
|
|
155
|
+
assert.equal(ra1!.key, a1.key)
|
|
156
|
+
assert.equal(ra1!.kind, DomainAssociationKind)
|
|
157
|
+
assert.equal([...ra1!.listTargets()][0].key, e2.key)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('should serialize and deserialize a complex DataDomain', ({ assert }) => {
|
|
161
|
+
const domain = new DataDomain()
|
|
162
|
+
const ns1 = domain.addNamespace()
|
|
163
|
+
const ns2 = ns1.addNamespace()
|
|
164
|
+
const m1 = ns1.addModel()
|
|
165
|
+
const m2 = ns2.addModel()
|
|
166
|
+
const e1 = m1.addEntity()
|
|
167
|
+
const e2 = m2.addEntity()
|
|
168
|
+
e2.addParent(e1.key)
|
|
169
|
+
const p1 = e1.addProperty({ type: 'string' })
|
|
170
|
+
const p2 = e2.addProperty({ type: 'number' })
|
|
171
|
+
const a1 = e1.addAssociation({ key: e2.key })
|
|
172
|
+
|
|
173
|
+
const serialized = domain.toJSON()
|
|
174
|
+
const restored = new DataDomain(serialized)
|
|
175
|
+
|
|
176
|
+
assert.equal(restored.key, domain.key)
|
|
177
|
+
assert.equal(restored.kind, domain.kind)
|
|
178
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
179
|
+
assert.equal([...restored.graph.nodes()].length, 9)
|
|
180
|
+
assert.equal([...restored.graph.edges()].length, 5)
|
|
181
|
+
|
|
182
|
+
const rn1 = restored.findNamespace(ns1.key)
|
|
183
|
+
assert.isDefined(rn1)
|
|
184
|
+
assert.equal(rn1!.key, ns1.key)
|
|
185
|
+
assert.equal(rn1!.kind, DomainNamespaceKind)
|
|
186
|
+
assert.equal([...rn1!.listNamespaces()][0].key, ns2.key)
|
|
187
|
+
assert.equal([...rn1!.listModels()][0].key, m1.key)
|
|
188
|
+
|
|
189
|
+
const rn2 = restored.findNamespace(ns2.key)
|
|
190
|
+
assert.isDefined(rn2)
|
|
191
|
+
assert.equal(rn2!.key, ns2.key)
|
|
192
|
+
assert.equal(rn2!.kind, DomainNamespaceKind)
|
|
193
|
+
assert.equal(restored.graph.parent(ns2.key), ns1.key)
|
|
194
|
+
assert.deepEqual([...rn2!.listNamespaces()], [])
|
|
195
|
+
assert.equal([...rn2!.listModels()][0].key, m2.key)
|
|
196
|
+
|
|
197
|
+
const rm1 = restored.findModel(m1.key)
|
|
198
|
+
assert.isDefined(rm1)
|
|
199
|
+
assert.equal(rm1!.key, m1.key)
|
|
200
|
+
assert.equal(rm1!.kind, DomainModelKind)
|
|
201
|
+
assert.equal(restored.graph.parent(m1.key), ns1.key)
|
|
202
|
+
|
|
203
|
+
const rm2 = restored.findModel(m2.key)
|
|
204
|
+
assert.isDefined(rm2)
|
|
205
|
+
assert.equal(rm2!.key, m2.key)
|
|
206
|
+
assert.equal(rm2!.kind, DomainModelKind)
|
|
207
|
+
assert.equal(restored.graph.parent(m2.key), ns2.key)
|
|
208
|
+
|
|
209
|
+
const re1 = restored.findEntity(e1.key)
|
|
210
|
+
assert.isDefined(re1)
|
|
211
|
+
assert.equal(re1!.key, e1.key)
|
|
212
|
+
assert.equal(re1!.kind, DomainEntityKind)
|
|
213
|
+
assert.equal(restored.graph.parent(e1.key), m1.key)
|
|
214
|
+
assert.equal([...re1!.listProperties()][0].key, p1.key)
|
|
215
|
+
|
|
216
|
+
const re2 = restored.findEntity(e2.key)
|
|
217
|
+
assert.isDefined(re2)
|
|
218
|
+
assert.equal(re2!.key, e2.key)
|
|
219
|
+
assert.equal(re2!.kind, DomainEntityKind)
|
|
220
|
+
assert.equal(restored.graph.parent(e2.key), m2.key)
|
|
221
|
+
assert.equal([...re2!.listParents()][0].key, e1.key)
|
|
222
|
+
assert.equal([...re2!.listProperties()][0].key, p2.key)
|
|
223
|
+
|
|
224
|
+
const rp1 = restored.findProperty(p1.key)
|
|
225
|
+
assert.isDefined(rp1)
|
|
226
|
+
assert.equal(rp1!.key, p1.key)
|
|
227
|
+
assert.equal(rp1!.kind, DomainPropertyKind)
|
|
228
|
+
|
|
229
|
+
const rp2 = restored.findProperty(p2.key)
|
|
230
|
+
assert.isDefined(rp2)
|
|
231
|
+
assert.equal(rp2!.key, p2.key)
|
|
232
|
+
assert.equal(rp2!.kind, DomainPropertyKind)
|
|
233
|
+
|
|
234
|
+
const ra1 = restored.findAssociation(a1.key)
|
|
235
|
+
assert.isDefined(ra1)
|
|
236
|
+
assert.equal(ra1!.key, a1.key)
|
|
237
|
+
assert.equal(ra1!.kind, DomainAssociationKind)
|
|
238
|
+
assert.equal([...ra1!.listTargets()][0].key, e2.key)
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test('should serialize and deserialize a DataDomain with foreign dependencies', ({ assert }) => {
|
|
242
|
+
const fd = new DataDomain()
|
|
243
|
+
const fm1 = fd.addModel({ key: 'fm1' })
|
|
244
|
+
const fe1 = fm1.addEntity({ key: 'fe1' })
|
|
245
|
+
fe1.addProperty({ type: 'string', key: 'fp1' })
|
|
246
|
+
fd.info.version = '1.0.0'
|
|
247
|
+
|
|
248
|
+
const domain = new DataDomain()
|
|
249
|
+
domain.registerForeignDomain(fd)
|
|
250
|
+
const m1 = domain.addModel({ key: 'm1' })
|
|
251
|
+
const e1 = m1.addEntity({ key: 'e1' })
|
|
252
|
+
const a1 = e1.addAssociation({ key: fe1.key, domain: fd.key }, { key: 'a1' })
|
|
253
|
+
const serialized = domain.toJSON()
|
|
254
|
+
const restored = new DataDomain(serialized, [fd])
|
|
255
|
+
|
|
256
|
+
assert.equal(restored.key, domain.key)
|
|
257
|
+
assert.equal(restored.kind, domain.kind)
|
|
258
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
259
|
+
assert.equal([...restored.graph.nodes()].length, 6)
|
|
260
|
+
assert.equal([...restored.graph.edges()].length, 3)
|
|
261
|
+
const rfe1 = restored.findForeignEntity(fe1.key, fd.key)
|
|
262
|
+
assert.isDefined(rfe1)
|
|
263
|
+
assert.equal(rfe1!.key, fe1.key)
|
|
264
|
+
assert.equal(rfe1!.kind, DomainEntityKind)
|
|
265
|
+
// Associations look like: Entity -> (edge) -> Association -> (edge) -> ForeignEntity
|
|
266
|
+
assert.isTrue(restored.graph.hasEdge(e1.key, a1.key), 'has edge from e1 to a1')
|
|
267
|
+
assert.isTrue(restored.graph.hasEdge(a1.key, `${fd.key}:${fe1.key}`), 'has edge from a1 to fe1')
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test('should serialize and deserialize a DataDomain with missing foreign dependencies', ({ assert }) => {
|
|
271
|
+
const fd = new DataDomain()
|
|
272
|
+
fd.info.version = '1.0.0'
|
|
273
|
+
const fm1 = fd.addModel()
|
|
274
|
+
const fe1 = fm1.addEntity()
|
|
275
|
+
fd.addProperty(fe1.key, { type: 'string' })
|
|
276
|
+
|
|
277
|
+
const domain = new DataDomain()
|
|
278
|
+
domain.registerForeignDomain(fd)
|
|
279
|
+
const m1 = domain.addModel()
|
|
280
|
+
const e1 = m1.addEntity()
|
|
281
|
+
const a1 = e1.addAssociation({ key: fe1.key, domain: fd.key })
|
|
282
|
+
|
|
283
|
+
const serialized = domain.toJSON()
|
|
284
|
+
const restored = new DataDomain(serialized)
|
|
285
|
+
|
|
286
|
+
assert.equal(restored.key, domain.key)
|
|
287
|
+
assert.equal(restored.kind, domain.kind)
|
|
288
|
+
assert.deepEqual(restored.info.toJSON(), domain.info.toJSON())
|
|
289
|
+
assert.equal([...restored.graph.nodes()].length, 3)
|
|
290
|
+
assert.equal([...restored.graph.edges()].length, 1)
|
|
291
|
+
assert.isTrue(restored.graph.hasEdge(e1.key, a1.key), 'has edge from e1 to a1')
|
|
292
|
+
assert.isFalse(restored.graph.hasEdge(a1.key, `${fd.key}:${fe1.key}`), 'has no edge from a1 to fe1')
|
|
293
|
+
})
|
|
294
|
+
})
|