@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,305 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { DataDomain, DomainPropertyKind, DomainProperty } from '../../../src/index.js'
|
|
3
|
+
|
|
4
|
+
test.group('DomainEntity.addProperty()', () => {
|
|
5
|
+
test('adds a property to the entity', ({ assert }) => {
|
|
6
|
+
const dataDomain = new DataDomain()
|
|
7
|
+
const model = dataDomain.addModel()
|
|
8
|
+
const entity = model.addEntity()
|
|
9
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
10
|
+
assert.instanceOf(property, DomainProperty)
|
|
11
|
+
assert.equal(property.kind, DomainPropertyKind)
|
|
12
|
+
assert.equal(property.key, 'test-property')
|
|
13
|
+
assert.deepInclude(property.info, { name: 'New property' })
|
|
14
|
+
assert.isTrue(dataDomain.graph.hasNode(property.key))
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('adds a property with default values', ({ assert }) => {
|
|
18
|
+
const dataDomain = new DataDomain()
|
|
19
|
+
const model = dataDomain.addModel({ key: 'test-model' })
|
|
20
|
+
const entity = model.addEntity({ key: 'test-entity' })
|
|
21
|
+
const property = entity.addProperty()
|
|
22
|
+
assert.instanceOf(property, DomainProperty)
|
|
23
|
+
assert.equal(property.kind, DomainPropertyKind)
|
|
24
|
+
assert.typeOf(property.key, 'string')
|
|
25
|
+
assert.isNotEmpty(property.key)
|
|
26
|
+
assert.deepInclude(property.info, { name: 'New property' })
|
|
27
|
+
assert.isTrue(dataDomain.graph.hasNode(property.key))
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('throws an error if a property with the same key already exists', ({ assert }) => {
|
|
31
|
+
const dataDomain = new DataDomain()
|
|
32
|
+
const model = dataDomain.addModel()
|
|
33
|
+
const entity = model.addEntity()
|
|
34
|
+
const p1 = entity.addProperty()
|
|
35
|
+
assert.throws(() => {
|
|
36
|
+
entity.addProperty({ key: p1.key, type: 'string' })
|
|
37
|
+
}, `Trying to add a property ${p1.key}, but it already exists`)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('notifies change', async ({ assert }) => {
|
|
41
|
+
const dataDomain = new DataDomain()
|
|
42
|
+
const model = dataDomain.addModel({ key: 'test-model' })
|
|
43
|
+
const entity = model.addEntity({ key: 'test-entity' })
|
|
44
|
+
entity.addProperty({ key: 'test-property', type: 'string' })
|
|
45
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('adds a property to the fields array', ({ assert }) => {
|
|
49
|
+
const dataDomain = new DataDomain()
|
|
50
|
+
const model = dataDomain.addModel({ key: 'test-model' })
|
|
51
|
+
const entity = model.addEntity({ key: 'test-entity' })
|
|
52
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
53
|
+
assert.deepEqual(entity.fields, [{ key: property.key, type: 'property' }])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('adds a property to the root graph', ({ assert }) => {
|
|
57
|
+
const dataDomain = new DataDomain()
|
|
58
|
+
const model = dataDomain.addModel({ key: 'test-model' })
|
|
59
|
+
const entity = model.addEntity({ key: 'test-entity' })
|
|
60
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
61
|
+
assert.isTrue(dataDomain.graph.hasNode(property.key))
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('creates a graph edge', ({ assert }) => {
|
|
65
|
+
const dataDomain = new DataDomain()
|
|
66
|
+
const model = dataDomain.addModel({ key: 'test-model' })
|
|
67
|
+
const entity = model.addEntity({ key: 'test-entity' })
|
|
68
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
69
|
+
assert.isTrue(dataDomain.graph.hasEdge(entity.key, property.key))
|
|
70
|
+
assert.deepEqual(dataDomain.graph.edge(entity.key, property.key), { type: 'property' })
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test.group('DomainEntity.removeProperty()', () => {
|
|
75
|
+
test('removes a property from the entity', ({ assert }) => {
|
|
76
|
+
const dataDomain = new DataDomain()
|
|
77
|
+
const model = dataDomain.addModel()
|
|
78
|
+
const entity = model.addEntity()
|
|
79
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
80
|
+
entity.removeProperty(property.key)
|
|
81
|
+
assert.isFalse(dataDomain.graph.hasNode(property.key))
|
|
82
|
+
assert.deepEqual(entity.fields, [])
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('throws an error if the property does not exist', ({ assert }) => {
|
|
86
|
+
const dataDomain = new DataDomain()
|
|
87
|
+
const model = dataDomain.addModel()
|
|
88
|
+
const entity = model.addEntity()
|
|
89
|
+
assert.throws(() => {
|
|
90
|
+
entity.removeProperty('non-existent-property')
|
|
91
|
+
}, "Trying to remove the non-existent-property property, but it doesn't exist")
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('throws an error when the property belongs to another entity', ({ assert }) => {
|
|
95
|
+
const dataDomain = new DataDomain()
|
|
96
|
+
const m1 = dataDomain.addModel()
|
|
97
|
+
const e1 = m1.addEntity()
|
|
98
|
+
const e2 = m1.addEntity()
|
|
99
|
+
const p1 = e1.addProperty()
|
|
100
|
+
assert.throws(() => {
|
|
101
|
+
e2.removeProperty(p1.key)
|
|
102
|
+
}, `Trying to remove the ${p1.key} property, but it doesn't belong to this entity`)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('notifies change', async ({ assert }) => {
|
|
106
|
+
const dataDomain = new DataDomain()
|
|
107
|
+
const model = dataDomain.addModel()
|
|
108
|
+
const entity = model.addEntity()
|
|
109
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
110
|
+
entity.removeProperty(property.key)
|
|
111
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('removes the property from the fields array', ({ assert }) => {
|
|
115
|
+
const dataDomain = new DataDomain()
|
|
116
|
+
const model = dataDomain.addModel()
|
|
117
|
+
const entity = model.addEntity()
|
|
118
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
119
|
+
entity.removeProperty(property.key)
|
|
120
|
+
assert.deepEqual(entity.fields, [])
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('removes the property from the root graph', ({ assert }) => {
|
|
124
|
+
const dataDomain = new DataDomain()
|
|
125
|
+
const model = dataDomain.addModel()
|
|
126
|
+
const entity = model.addEntity()
|
|
127
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
128
|
+
entity.removeProperty(property.key)
|
|
129
|
+
assert.isFalse(dataDomain.graph.hasNode(property.key))
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('removes the graph edge', ({ assert }) => {
|
|
133
|
+
const dataDomain = new DataDomain()
|
|
134
|
+
const model = dataDomain.addModel()
|
|
135
|
+
const entity = model.addEntity()
|
|
136
|
+
const property = entity.addProperty({ key: 'test-property', type: 'string' })
|
|
137
|
+
entity.removeProperty(property.key)
|
|
138
|
+
assert.isFalse(dataDomain.graph.hasEdge(entity.key, property.key))
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('removes only the specified property', ({ assert }) => {
|
|
142
|
+
const dataDomain = new DataDomain()
|
|
143
|
+
const model = dataDomain.addModel()
|
|
144
|
+
const entity = model.addEntity()
|
|
145
|
+
const property1 = entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
146
|
+
const property2 = entity.addProperty({ key: 'test-property2', type: 'string' })
|
|
147
|
+
entity.removeProperty(property1.key)
|
|
148
|
+
assert.isFalse(dataDomain.graph.hasNode(property1.key))
|
|
149
|
+
assert.isTrue(dataDomain.graph.hasNode(property2.key))
|
|
150
|
+
assert.deepEqual(entity.fields, [{ key: property2.key, type: 'property' }])
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('does not remove other entities or models', ({ assert }) => {
|
|
154
|
+
const dataDomain = new DataDomain()
|
|
155
|
+
const model = dataDomain.addModel()
|
|
156
|
+
const entity1 = model.addEntity()
|
|
157
|
+
const entity2 = model.addEntity()
|
|
158
|
+
const property = entity1.addProperty({ key: 'test-property', type: 'string' })
|
|
159
|
+
entity1.removeProperty(property.key)
|
|
160
|
+
assert.isTrue(dataDomain.graph.hasNode(entity2.key))
|
|
161
|
+
assert.isTrue(dataDomain.graph.hasNode(model.key))
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('does not remove other properties', ({ assert }) => {
|
|
165
|
+
const dataDomain = new DataDomain()
|
|
166
|
+
const model = dataDomain.addModel()
|
|
167
|
+
const entity = model.addEntity()
|
|
168
|
+
const property1 = entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
169
|
+
const property2 = entity.addProperty({ key: 'test-property2', type: 'string' })
|
|
170
|
+
entity.removeProperty(property1.key)
|
|
171
|
+
assert.isFalse(dataDomain.graph.hasNode(property1.key))
|
|
172
|
+
assert.isTrue(dataDomain.graph.hasNode(property2.key))
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
test.group('DomainEntity.listProperties()', () => {
|
|
177
|
+
test('lists all properties in the entity', ({ assert }) => {
|
|
178
|
+
const dataDomain = new DataDomain()
|
|
179
|
+
const model = dataDomain.addModel()
|
|
180
|
+
const entity = model.addEntity()
|
|
181
|
+
const property1 = entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
182
|
+
const property2 = entity.addProperty({ key: 'test-property2', type: 'number' })
|
|
183
|
+
const properties = [...entity.listProperties()]
|
|
184
|
+
assert.lengthOf(properties, 2)
|
|
185
|
+
assert.deepInclude(properties, property1)
|
|
186
|
+
assert.deepInclude(properties, property2)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('returns an empty array if there are no properties', ({ assert }) => {
|
|
190
|
+
const dataDomain = new DataDomain()
|
|
191
|
+
const model = dataDomain.addModel()
|
|
192
|
+
const entity = model.addEntity()
|
|
193
|
+
const properties = [...entity.listProperties()]
|
|
194
|
+
assert.lengthOf(properties, 0)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('returns only properties', ({ assert }) => {
|
|
198
|
+
const dataDomain = new DataDomain()
|
|
199
|
+
const model = dataDomain.addModel()
|
|
200
|
+
const entity = model.addEntity()
|
|
201
|
+
const property1 = entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
202
|
+
entity.addAssociation()
|
|
203
|
+
const properties = [...entity.listProperties()]
|
|
204
|
+
assert.lengthOf(properties, 1)
|
|
205
|
+
assert.deepInclude(properties, property1)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
test('properties in the list are of type DomainProperty', ({ assert }) => {
|
|
209
|
+
const dataDomain = new DataDomain()
|
|
210
|
+
const model = dataDomain.addModel()
|
|
211
|
+
const entity = model.addEntity()
|
|
212
|
+
entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
213
|
+
const properties = [...entity.listProperties()]
|
|
214
|
+
assert.instanceOf(properties[0], DomainProperty)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test('lists properties in the order they were added', ({ assert }) => {
|
|
218
|
+
const dataDomain = new DataDomain()
|
|
219
|
+
const model = dataDomain.addModel()
|
|
220
|
+
const entity = model.addEntity()
|
|
221
|
+
const property1 = entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
222
|
+
const property2 = entity.addProperty({ key: 'test-property2', type: 'number' })
|
|
223
|
+
const properties = [...entity.listProperties()]
|
|
224
|
+
assert.deepEqual(properties, [property1, property2])
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test('lists properties when there are no properties', ({ assert }) => {
|
|
228
|
+
const dataDomain = new DataDomain()
|
|
229
|
+
const model = dataDomain.addModel()
|
|
230
|
+
const entity = model.addEntity()
|
|
231
|
+
const properties = [...entity.listProperties()]
|
|
232
|
+
assert.deepEqual(properties, [])
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('lists properties when there are other domain elements', ({ assert }) => {
|
|
236
|
+
const dataDomain = new DataDomain()
|
|
237
|
+
const model = dataDomain.addModel()
|
|
238
|
+
const entity = model.addEntity()
|
|
239
|
+
const property1 = entity.addProperty({ key: 'test-property1', type: 'string' })
|
|
240
|
+
entity.addAssociation()
|
|
241
|
+
const properties = [...entity.listProperties()]
|
|
242
|
+
assert.deepEqual(properties, [property1])
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
test('lists properties when fields array is empty', ({ assert }) => {
|
|
246
|
+
const dataDomain = new DataDomain()
|
|
247
|
+
const model = dataDomain.addModel()
|
|
248
|
+
const entity = model.addEntity()
|
|
249
|
+
entity.fields = []
|
|
250
|
+
const properties = [...entity.listProperties()]
|
|
251
|
+
assert.deepEqual(properties, [])
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
test('lists properties when fields array contains only associations', ({ assert }) => {
|
|
255
|
+
const dataDomain = new DataDomain()
|
|
256
|
+
const model = dataDomain.addModel()
|
|
257
|
+
const entity = model.addEntity()
|
|
258
|
+
const association = entity.addAssociation()
|
|
259
|
+
entity.fields = [{ key: association.key, type: 'association' }]
|
|
260
|
+
const properties = [...entity.listProperties()]
|
|
261
|
+
assert.deepEqual(properties, [])
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
test.group('DomainEntity.hasProperties()', () => {
|
|
266
|
+
test('returns true if there are child properties', ({ assert }) => {
|
|
267
|
+
const dataDomain = new DataDomain()
|
|
268
|
+
const model = dataDomain.addModel()
|
|
269
|
+
const entity = model.addEntity()
|
|
270
|
+
entity.addProperty({ key: 'test-property', type: 'string' })
|
|
271
|
+
assert.isTrue(entity.hasProperties())
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
test('returns false if there are no child properties', ({ assert }) => {
|
|
275
|
+
const dataDomain = new DataDomain()
|
|
276
|
+
const model = dataDomain.addModel()
|
|
277
|
+
const entity = model.addEntity()
|
|
278
|
+
assert.isFalse(entity.hasProperties())
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
test('returns false if there are only other domain elements', ({ assert }) => {
|
|
282
|
+
const dataDomain = new DataDomain()
|
|
283
|
+
const model = dataDomain.addModel()
|
|
284
|
+
const entity = model.addEntity()
|
|
285
|
+
entity.addAssociation()
|
|
286
|
+
assert.isFalse(entity.hasProperties())
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
test('returns true if there are both properties and other domain elements', ({ assert }) => {
|
|
290
|
+
const dataDomain = new DataDomain()
|
|
291
|
+
const model = dataDomain.addModel()
|
|
292
|
+
const entity = model.addEntity()
|
|
293
|
+
entity.addProperty({ key: 'test-property', type: 'string' })
|
|
294
|
+
entity.addAssociation()
|
|
295
|
+
assert.isTrue(entity.hasProperties())
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
test('returns false if the entity has no fields', ({ assert }) => {
|
|
299
|
+
const dataDomain = new DataDomain()
|
|
300
|
+
const model = dataDomain.addModel()
|
|
301
|
+
const entity = model.addEntity()
|
|
302
|
+
entity.fields = []
|
|
303
|
+
assert.isFalse(entity.hasProperties())
|
|
304
|
+
})
|
|
305
|
+
})
|
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
|
-
import {
|
|
2
|
+
import { DomainFile, IDomainFile, ThingKind, DomainFileKind, DataDomain } from '../../../src/index.js'
|
|
3
3
|
|
|
4
4
|
const organization = 'test-organization'
|
|
5
5
|
|
|
6
|
-
test.group('
|
|
6
|
+
test.group('DomainFile.fromDataDomain()', () => {
|
|
7
7
|
test('sets the kind', ({ assert }) => {
|
|
8
|
-
const p1 =
|
|
9
|
-
const result =
|
|
10
|
-
assert.equal(result.kind,
|
|
8
|
+
const p1 = new DataDomain({ info: { name: 'p1' } })
|
|
9
|
+
const result = DomainFile.fromDataDomain(p1, organization)
|
|
10
|
+
assert.equal(result.kind, DomainFileKind)
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
test('sets the organization', ({ assert }) => {
|
|
14
|
-
const p1 =
|
|
15
|
-
const result =
|
|
14
|
+
const p1 = new DataDomain({ info: { name: 'p1' } })
|
|
15
|
+
const result = DomainFile.fromDataDomain(p1, organization)
|
|
16
16
|
assert.equal(result.organization, organization)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
test('sets the name', ({ assert }) => {
|
|
20
|
-
const p1 =
|
|
21
|
-
const result =
|
|
20
|
+
const p1 = new DataDomain({ info: { name: 'p1' } })
|
|
21
|
+
const result = DomainFile.fromDataDomain(p1, organization)
|
|
22
22
|
assert.equal(result.info.name, 'p1')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
test('sets the key', ({ assert }) => {
|
|
26
|
-
const p1 =
|
|
27
|
-
const result =
|
|
26
|
+
const p1 = new DataDomain({ info: { name: 'p1' } })
|
|
27
|
+
const result = DomainFile.fromDataDomain(p1, organization)
|
|
28
28
|
assert.equal(result.key, p1.key)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
test('sets the configured owner', ({ assert }) => {
|
|
32
|
-
const p1 =
|
|
33
|
-
const result =
|
|
32
|
+
const p1 = new DataDomain({ info: { name: 'p1' } })
|
|
33
|
+
const result = DomainFile.fromDataDomain(p1, organization, 'other')
|
|
34
34
|
assert.equal(result.owner, 'other')
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
test('respects schema instead of instance', ({ assert }) => {
|
|
38
|
-
const p1 =
|
|
39
|
-
const result =
|
|
38
|
+
const p1 = new DataDomain({ info: { name: 'p1' } })
|
|
39
|
+
const result = DomainFile.fromDataDomain(p1.toJSON(), organization)
|
|
40
40
|
assert.equal(result.info.name, 'p1')
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
test.group('constructor()', () => {
|
|
45
45
|
test('creates a default data file', ({ assert }) => {
|
|
46
|
-
const result = new
|
|
47
|
-
assert.equal(result.kind,
|
|
46
|
+
const result = new DomainFile()
|
|
47
|
+
assert.equal(result.kind, DomainFileKind)
|
|
48
48
|
assert.isUndefined(result.owner)
|
|
49
49
|
assert.typeOf(result.key, 'string')
|
|
50
50
|
assert.typeOf(result.lastModified, 'object')
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
test('creates a data file from the schema values', ({ assert }) => {
|
|
54
|
-
const schema:
|
|
55
|
-
kind:
|
|
54
|
+
const schema: IDomainFile = {
|
|
55
|
+
kind: DomainFileKind,
|
|
56
56
|
organization,
|
|
57
57
|
info: {
|
|
58
58
|
kind: ThingKind,
|
|
@@ -77,8 +77,8 @@ test.group('constructor()', () => {
|
|
|
77
77
|
lastModified: { byMe: false, time: 0, user: 'id', name: 'test' },
|
|
78
78
|
labels: ['l1'],
|
|
79
79
|
}
|
|
80
|
-
const result = new
|
|
81
|
-
assert.equal(result.kind,
|
|
80
|
+
const result = new DomainFile(schema)
|
|
81
|
+
assert.equal(result.kind, DomainFileKind)
|
|
82
82
|
assert.equal(result.organization, organization)
|
|
83
83
|
assert.equal(result.info.name, 'hello')
|
|
84
84
|
assert.equal(result.owner, 'me')
|
|
@@ -91,8 +91,8 @@ test.group('constructor()', () => {
|
|
|
91
91
|
})
|
|
92
92
|
|
|
93
93
|
test('creates a data file from the JSON schema string', ({ assert }) => {
|
|
94
|
-
const schema:
|
|
95
|
-
kind:
|
|
94
|
+
const schema: IDomainFile = {
|
|
95
|
+
kind: DomainFileKind,
|
|
96
96
|
organization,
|
|
97
97
|
info: {
|
|
98
98
|
kind: ThingKind,
|
|
@@ -116,8 +116,8 @@ test.group('constructor()', () => {
|
|
|
116
116
|
],
|
|
117
117
|
lastModified: { byMe: false, time: 0, user: 'id', name: 'test' },
|
|
118
118
|
}
|
|
119
|
-
const result = new
|
|
120
|
-
assert.equal(result.kind,
|
|
119
|
+
const result = new DomainFile(JSON.stringify(schema))
|
|
120
|
+
assert.equal(result.kind, DomainFileKind)
|
|
121
121
|
assert.equal(result.organization, organization)
|
|
122
122
|
assert.equal(result.info.name, 'hello')
|
|
123
123
|
assert.equal(result.owner, 'me')
|
|
@@ -127,7 +127,7 @@ test.group('constructor()', () => {
|
|
|
127
127
|
|
|
128
128
|
test('throws when invalid schema', ({ assert }) => {
|
|
129
129
|
assert.throws(() => {
|
|
130
|
-
new
|
|
130
|
+
new DomainFile(
|
|
131
131
|
JSON.stringify({
|
|
132
132
|
name: 'a name',
|
|
133
133
|
})
|
|
@@ -138,72 +138,16 @@ test.group('constructor()', () => {
|
|
|
138
138
|
|
|
139
139
|
test.group('toJSON()', () => {
|
|
140
140
|
test('serializes the kind', ({ assert }) => {
|
|
141
|
-
const file = new
|
|
141
|
+
const file = new DomainFile()
|
|
142
142
|
const result = file.toJSON()
|
|
143
|
-
assert.equal(result.kind,
|
|
143
|
+
assert.equal(result.kind, DomainFileKind)
|
|
144
144
|
})
|
|
145
145
|
|
|
146
146
|
test('serializes the key', ({ assert }) => {
|
|
147
|
-
const file = new
|
|
147
|
+
const file = new DomainFile()
|
|
148
148
|
const result = file.toJSON()
|
|
149
149
|
assert.equal(result.key, file.key)
|
|
150
150
|
})
|
|
151
151
|
|
|
152
152
|
// the "key" test tests whether the parent toJSON() is called.
|
|
153
153
|
})
|
|
154
|
-
|
|
155
|
-
test.group('DataFile.fromName()', () => {
|
|
156
|
-
test('sets the kind', ({ assert }) => {
|
|
157
|
-
const result = DataFile.fromName('name', organization)
|
|
158
|
-
assert.equal(result.kind, DataFileKind)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test('sets the organization', ({ assert }) => {
|
|
162
|
-
const result = DataFile.fromName('name', organization)
|
|
163
|
-
assert.equal(result.organization, organization)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
test('sets the name', ({ assert }) => {
|
|
167
|
-
const result = DataFile.fromName('name', organization)
|
|
168
|
-
assert.equal(result.info.name, 'name')
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
test('sets the key', ({ assert }) => {
|
|
172
|
-
const result = DataFile.fromName('name', organization)
|
|
173
|
-
assert.typeOf(result.key, 'string')
|
|
174
|
-
assert.notEqual(result.key, '')
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
test('sets the owner', ({ assert }) => {
|
|
178
|
-
const result = DataFile.fromName('name', organization, 'other')
|
|
179
|
-
assert.equal(result.owner, 'other')
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
test.group('DataFile.fromName()', () => {
|
|
184
|
-
test('sets the kind', ({ assert }) => {
|
|
185
|
-
const result = DataFile.fromName('name', organization)
|
|
186
|
-
assert.equal(result.kind, DataFileKind)
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
test('sets the organization', ({ assert }) => {
|
|
190
|
-
const result = DataFile.fromName('name', organization)
|
|
191
|
-
assert.equal(result.organization, organization)
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
test('sets the name', ({ assert }) => {
|
|
195
|
-
const result = DataFile.fromName('name', organization)
|
|
196
|
-
assert.equal(result.info.name, 'name')
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
test('sets the key', ({ assert }) => {
|
|
200
|
-
const result = DataFile.fromName('name', organization)
|
|
201
|
-
assert.typeOf(result.key, 'string')
|
|
202
|
-
assert.notEqual(result.key, '')
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
test('sets the owner', ({ assert }) => {
|
|
206
|
-
const result = DataFile.fromName('name', organization, 'other')
|
|
207
|
-
assert.equal(result.owner, 'other')
|
|
208
|
-
})
|
|
209
|
-
})
|