@api-client/core 0.11.11 → 0.12.1
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 +7 -4
- 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 +17 -16
- package/build/src/amf/DataValueGenerator.js.map +1 -1
- package/build/src/amf/models/AmfDataNode.d.ts.map +1 -1
- package/build/src/amf/models/AmfDataNode.js +2 -2
- package/build/src/amf/models/AmfDataNode.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/lib/uuid.d.ts +1 -1
- package/build/src/lib/uuid.js +1 -1
- package/build/src/lib/uuid.js.map +1 -1
- package/build/src/mocking/lib/History.js +8 -8
- package/build/src/mocking/lib/History.js.map +1 -1
- package/build/src/mocking/lib/HostRules.js +1 -1
- package/build/src/mocking/lib/HostRules.js.map +1 -1
- package/build/src/mocking/lib/User.js +2 -2
- package/build/src/mocking/lib/User.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 +1141 -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} +11 -8
- 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} +21 -20
- 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} +4 -3
- 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} +9 -8
- 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} +9 -5
- 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} +10 -7
- 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/AuthorizationData.js +3 -3
- package/build/src/models/AuthorizationData.js.map +1 -1
- package/build/src/models/CertificateFile.js +2 -2
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/ClientCertificate.js +5 -5
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/Environment.js +6 -6
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/Folder.js +2 -2
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/HostRule.js +4 -4
- package/build/src/models/HostRule.js.map +1 -1
- package/build/src/models/HttpProject.js +12 -12
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/Project.d.ts.map +1 -1
- package/build/src/models/Project.js +2 -2
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts.map +1 -1
- package/build/src/models/ProjectFolder.js +6 -6
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts.map +1 -1
- package/build/src/models/ProjectRequest.js +8 -8
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/ProjectSchema.js +6 -6
- package/build/src/models/ProjectSchema.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 +4 -2
- package/build/src/models/store/DataFile.js.map +1 -1
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +3 -3
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Organization.js +3 -3
- package/build/src/models/store/Organization.js.map +1 -1
- package/build/src/models/store/Permission.js +7 -7
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/store/UserIdentity.js +3 -3
- package/build/src/models/store/UserIdentity.js.map +1 -1
- package/build/src/models/transformers/ArcDexieTransformer.js +4 -4
- package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcLegacyTransformer.js +3 -3
- package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcPouchTransformer.js +2 -2
- package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +2 -2
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +2 -2
- package/build/src/models/transformers/PostmanV2Transformer.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/patch/PatchClient.js +2 -2
- package/build/src/patch/PatchClient.js.map +1 -1
- 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 +3 -3
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/data/models/example-generator-api.json +8 -8
- package/package.json +20 -6
- package/readme.md +1 -1
- package/src/amf/AmfShapeGenerator.ts +10 -7
- package/src/amf/AmfTypes.ts +2 -2
- package/src/amf/DataValueGenerator.ts +24 -23
- package/src/amf/models/AmfDataNode.ts +2 -2
- 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/lib/uuid.ts +1 -1
- package/src/mocking/lib/History.ts +8 -8
- package/src/mocking/lib/HostRules.ts +1 -1
- package/src/mocking/lib/User.ts +2 -2
- package/src/modeling/Bindings.ts +2 -2
- package/src/modeling/DataDomain.ts +1220 -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} +15 -10
- package/src/modeling/{DataEntity.ts → legacy/DataEntity.ts} +30 -25
- package/src/modeling/{DataEntityBuilder.ts → legacy/DataEntityBuilder.ts} +5 -4
- package/src/modeling/legacy/DataImpactAnalysis.ts +530 -0
- package/src/modeling/{DataModel.ts → legacy/DataModel.ts} +12 -10
- package/src/modeling/{DataNamespace.ts → legacy/DataNamespace.ts} +25 -7
- package/src/modeling/{DataProperty.ts → legacy/DataProperty.ts} +17 -9
- package/src/modeling/observed.ts +267 -0
- package/src/modeling/types.ts +174 -1
- package/src/models/AuthorizationData.ts +3 -3
- package/src/models/CertificateFile.ts +2 -2
- package/src/models/ClientCertificate.ts +5 -5
- package/src/models/Environment.ts +6 -6
- package/src/models/Folder.ts +2 -2
- package/src/models/HostRule.ts +4 -4
- package/src/models/HttpProject.ts +12 -12
- package/src/models/Project.ts +2 -2
- package/src/models/ProjectFolder.ts +6 -6
- package/src/models/ProjectRequest.ts +8 -8
- package/src/models/ProjectSchema.ts +6 -6
- package/src/models/Thing.ts +70 -5
- package/src/models/kinds.ts +32 -6
- package/src/models/store/DataFile.ts +5 -3
- package/src/models/store/File.ts +3 -3
- package/src/models/store/Organization.ts +3 -3
- package/src/models/store/Permission.ts +7 -7
- package/src/models/store/UserIdentity.ts +3 -3
- package/src/models/transformers/ArcDexieTransformer.ts +4 -4
- package/src/models/transformers/ArcLegacyTransformer.ts +3 -3
- package/src/models/transformers/ArcPouchTransformer.ts +2 -2
- package/src/models/transformers/PostmanV21Transformer.ts +2 -2
- package/src/models/transformers/PostmanV2Transformer.ts +2 -2
- package/src/models/types.ts +11 -0
- package/src/patch/PatchClient.ts +2 -2
- package/src/runtime/store/FilesSdk.ts +5 -5
- 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/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +8 -8
- 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,113 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { DataDomain, DomainAssociation, DomainProperty } from '../../../src/index.js'
|
|
3
|
+
|
|
4
|
+
test.group('DomainEntity.listFields()', () => {
|
|
5
|
+
test('lists all fields (properties and associations) of this entity', ({ assert }) => {
|
|
6
|
+
const dataDomain = new DataDomain()
|
|
7
|
+
const model = dataDomain.addModel()
|
|
8
|
+
const entity = model.addEntity()
|
|
9
|
+
const property1 = entity.addProperty()
|
|
10
|
+
const association1 = entity.addAssociation()
|
|
11
|
+
const fields = [...entity.listFields()]
|
|
12
|
+
assert.lengthOf(fields, 2)
|
|
13
|
+
assert.deepInclude(fields, property1)
|
|
14
|
+
assert.deepInclude(fields, association1)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('returns an empty array if there are no fields', ({ assert }) => {
|
|
18
|
+
const dataDomain = new DataDomain()
|
|
19
|
+
const model = dataDomain.addModel()
|
|
20
|
+
const entity = model.addEntity()
|
|
21
|
+
const fields = [...entity.listFields()]
|
|
22
|
+
assert.lengthOf(fields, 0)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('returns only properties and associations', ({ assert }) => {
|
|
26
|
+
const root = new DataDomain()
|
|
27
|
+
const m1 = root.addModel()
|
|
28
|
+
const e1 = m1.addEntity()
|
|
29
|
+
const e2 = m1.addEntity()
|
|
30
|
+
const p1 = e1.addProperty()
|
|
31
|
+
e1.addParent(e2.key)
|
|
32
|
+
const association1 = e1.addAssociation()
|
|
33
|
+
|
|
34
|
+
const fields = [...e1.listFields()]
|
|
35
|
+
assert.lengthOf(fields, 2)
|
|
36
|
+
assert.deepInclude(fields, p1)
|
|
37
|
+
assert.deepInclude(fields, association1)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('fields in the list are of type DomainProperty or DomainAssociation', ({ assert }) => {
|
|
41
|
+
const dataDomain = new DataDomain()
|
|
42
|
+
const model = dataDomain.addModel()
|
|
43
|
+
const entity = model.addEntity()
|
|
44
|
+
entity.addProperty()
|
|
45
|
+
entity.addAssociation()
|
|
46
|
+
const fields = [...entity.listFields()]
|
|
47
|
+
assert.instanceOf(fields[0], DomainProperty)
|
|
48
|
+
assert.instanceOf(fields[1], DomainAssociation)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('lists fields in the order they were added', ({ assert }) => {
|
|
52
|
+
const dataDomain = new DataDomain()
|
|
53
|
+
const model = dataDomain.addModel()
|
|
54
|
+
const entity = model.addEntity()
|
|
55
|
+
const property1 = entity.addProperty()
|
|
56
|
+
const association1 = entity.addAssociation()
|
|
57
|
+
const property2 = entity.addProperty({ key: 'property2' })
|
|
58
|
+
const association2 = entity.addAssociation()
|
|
59
|
+
|
|
60
|
+
const fields = [...entity.listFields()]
|
|
61
|
+
assert.deepEqual(fields, [property1, association1, property2, association2])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('lists fields when there are no fields', ({ assert }) => {
|
|
65
|
+
const dataDomain = new DataDomain()
|
|
66
|
+
const model = dataDomain.addModel()
|
|
67
|
+
const entity = model.addEntity()
|
|
68
|
+
const fields = [...entity.listFields()]
|
|
69
|
+
assert.deepEqual(fields, [])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('lists fields when fields array is empty', ({ assert }) => {
|
|
73
|
+
const dataDomain = new DataDomain()
|
|
74
|
+
const model = dataDomain.addModel()
|
|
75
|
+
const entity = model.addEntity()
|
|
76
|
+
entity.fields = []
|
|
77
|
+
const fields = [...entity.listFields()]
|
|
78
|
+
assert.deepEqual(fields, [])
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test.group('DomainEntity.hasFields()', () => {
|
|
83
|
+
test('returns true if the entity has any fields (properties or associations)', ({ assert }) => {
|
|
84
|
+
const dataDomain = new DataDomain()
|
|
85
|
+
const model = dataDomain.addModel()
|
|
86
|
+
const entity = model.addEntity()
|
|
87
|
+
entity.addProperty()
|
|
88
|
+
assert.isTrue(entity.hasFields())
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('returns true if the entity has any associations', ({ assert }) => {
|
|
92
|
+
const dataDomain = new DataDomain()
|
|
93
|
+
const model = dataDomain.addModel()
|
|
94
|
+
const entity = model.addEntity()
|
|
95
|
+
entity.addAssociation()
|
|
96
|
+
assert.isTrue(entity.hasFields())
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('returns false if the entity has no fields', ({ assert }) => {
|
|
100
|
+
const dataDomain = new DataDomain()
|
|
101
|
+
const model = dataDomain.addModel()
|
|
102
|
+
const entity = model.addEntity()
|
|
103
|
+
assert.isFalse(entity.hasFields())
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('returns false if the entity has an empty fields array', ({ assert }) => {
|
|
107
|
+
const dataDomain = new DataDomain()
|
|
108
|
+
const model = dataDomain.addModel()
|
|
109
|
+
const entity = model.addEntity()
|
|
110
|
+
entity.fields = []
|
|
111
|
+
assert.isFalse(entity.hasFields())
|
|
112
|
+
})
|
|
113
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { DataDomain } from '../../../src/index.js'
|
|
3
|
+
|
|
4
|
+
test.group('DomainEntity.toApiShape()', () => {
|
|
5
|
+
test('returns an object', ({ assert }) => {
|
|
6
|
+
const dataDomain = new DataDomain()
|
|
7
|
+
const model = dataDomain.addModel()
|
|
8
|
+
const entity = model.addEntity()
|
|
9
|
+
const result = entity.toApiShape()
|
|
10
|
+
assert.typeOf(result, 'object')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('returns an object with the correct kind', ({ assert }) => {
|
|
14
|
+
const dataDomain = new DataDomain()
|
|
15
|
+
const model = dataDomain.addModel()
|
|
16
|
+
const entity = model.addEntity()
|
|
17
|
+
const result = entity.toApiShape()
|
|
18
|
+
assert.equal(result.id, entity.key)
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { DataDomain, DomainEntity } from '../../../src/index.js'
|
|
3
|
+
|
|
4
|
+
test.group('DomainEntity.listParents()', () => {
|
|
5
|
+
test('lists all parent entities', ({ assert }) => {
|
|
6
|
+
const dataDomain = new DataDomain()
|
|
7
|
+
const model = dataDomain.addModel()
|
|
8
|
+
const entity1 = model.addEntity()
|
|
9
|
+
const entity2 = model.addEntity()
|
|
10
|
+
const entity3 = model.addEntity()
|
|
11
|
+
entity2.addParent(entity1.key)
|
|
12
|
+
entity2.addParent(entity3.key)
|
|
13
|
+
const parents = [...entity2.listParents()]
|
|
14
|
+
assert.lengthOf(parents, 2)
|
|
15
|
+
assert.deepInclude(parents, entity1)
|
|
16
|
+
assert.deepInclude(parents, entity3)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('returns an empty array if there are no parents', ({ assert }) => {
|
|
20
|
+
const dataDomain = new DataDomain()
|
|
21
|
+
const model = dataDomain.addModel()
|
|
22
|
+
const entity = model.addEntity()
|
|
23
|
+
const parents = [...entity.listParents()]
|
|
24
|
+
assert.lengthOf(parents, 0)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('returns only entities', ({ assert }) => {
|
|
28
|
+
const dataDomain = new DataDomain()
|
|
29
|
+
const model = dataDomain.addModel()
|
|
30
|
+
const entity1 = model.addEntity()
|
|
31
|
+
const entity2 = model.addEntity()
|
|
32
|
+
entity2.addParent(entity1.key)
|
|
33
|
+
entity2.addProperty({ key: 'test-property', type: 'string' })
|
|
34
|
+
const parents = [...entity2.listParents()]
|
|
35
|
+
assert.lengthOf(parents, 1)
|
|
36
|
+
assert.deepInclude(parents, entity1)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('entities in the list are of type DomainEntity', ({ assert }) => {
|
|
40
|
+
const dataDomain = new DataDomain()
|
|
41
|
+
const model = dataDomain.addModel()
|
|
42
|
+
const entity1 = model.addEntity()
|
|
43
|
+
const entity2 = model.addEntity()
|
|
44
|
+
entity2.addParent(entity1.key)
|
|
45
|
+
const parents = [...entity2.listParents()]
|
|
46
|
+
assert.instanceOf(parents[0], DomainEntity)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('lists parents when there are multiple levels of inheritance', ({ assert }) => {
|
|
50
|
+
const dataDomain = new DataDomain()
|
|
51
|
+
const model = dataDomain.addModel()
|
|
52
|
+
const entity1 = model.addEntity()
|
|
53
|
+
const entity2 = model.addEntity()
|
|
54
|
+
const entity3 = model.addEntity()
|
|
55
|
+
entity3.addParent(entity2.key)
|
|
56
|
+
entity2.addParent(entity1.key)
|
|
57
|
+
const parents = [...entity3.listParents()]
|
|
58
|
+
assert.deepEqual(parents, [entity2])
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test.group('DomainEntity.addParent()', () => {
|
|
63
|
+
test('adds a parent to the entity', ({ assert }) => {
|
|
64
|
+
const dataDomain = new DataDomain()
|
|
65
|
+
const model = dataDomain.addModel()
|
|
66
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
67
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
68
|
+
entity2.addParent(entity1.key)
|
|
69
|
+
assert.isTrue(dataDomain.graph.hasEdge(entity2.key, entity1.key))
|
|
70
|
+
assert.deepEqual([...entity2.listParents()], [entity1])
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('throws an error if the parent does not exist', ({ assert }) => {
|
|
74
|
+
const dataDomain = new DataDomain()
|
|
75
|
+
const model = dataDomain.addModel()
|
|
76
|
+
const entity = model.addEntity()
|
|
77
|
+
assert.throws(() => {
|
|
78
|
+
entity.addParent('non-existent-entity')
|
|
79
|
+
}, 'Entity with key "non-existent-entity" not found')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('throws an error if adding self as parent', ({ assert }) => {
|
|
83
|
+
const dataDomain = new DataDomain()
|
|
84
|
+
const model = dataDomain.addModel()
|
|
85
|
+
const entity = model.addEntity()
|
|
86
|
+
assert.throws(() => {
|
|
87
|
+
entity.addParent(entity.key)
|
|
88
|
+
}, 'Entity cannot be a parent of itself')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('throws an error if circular dependency is detected', ({ assert }) => {
|
|
92
|
+
const dataDomain = new DataDomain()
|
|
93
|
+
const model = dataDomain.addModel()
|
|
94
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
95
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
96
|
+
entity1.addParent(entity2.key)
|
|
97
|
+
assert.throws(() => {
|
|
98
|
+
entity2.addParent(entity1.key)
|
|
99
|
+
}, 'Circular inheritance detected. Cannot add entity1 as a parent')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('throws an error if circular dependency is detected - indirect', ({ assert }) => {
|
|
103
|
+
const dataDomain = new DataDomain()
|
|
104
|
+
const model = dataDomain.addModel()
|
|
105
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
106
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
107
|
+
const entity3 = model.addEntity({ key: 'entity3' })
|
|
108
|
+
entity1.addParent(entity2.key)
|
|
109
|
+
entity2.addParent(entity3.key)
|
|
110
|
+
assert.throws(() => {
|
|
111
|
+
entity3.addParent(entity1.key)
|
|
112
|
+
}, 'Circular inheritance detected. Cannot add entity1 as a parent')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('throws an error if parent already exists', ({ assert }) => {
|
|
116
|
+
const dataDomain = new DataDomain()
|
|
117
|
+
const model = dataDomain.addModel()
|
|
118
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
119
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
120
|
+
entity2.addParent(entity1.key)
|
|
121
|
+
assert.throws(() => {
|
|
122
|
+
entity2.addParent(entity1.key)
|
|
123
|
+
}, 'Parent entity1 already exists')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('notifies change', async ({ assert }) => {
|
|
127
|
+
const dataDomain = new DataDomain()
|
|
128
|
+
const model = dataDomain.addModel()
|
|
129
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
130
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
131
|
+
entity2.addParent(entity1.key)
|
|
132
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('creates a graph edge', ({ assert }) => {
|
|
136
|
+
const dataDomain = new DataDomain()
|
|
137
|
+
const model = dataDomain.addModel()
|
|
138
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
139
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
140
|
+
entity2.addParent(entity1.key)
|
|
141
|
+
assert.isTrue(dataDomain.graph.hasEdge(entity2.key, entity1.key))
|
|
142
|
+
assert.deepEqual(dataDomain.graph.edge(entity2.key, entity1.key), { type: 'parent' })
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test.group('DomainEntity.removeParent()', () => {
|
|
147
|
+
test('removes a parent from the entity', ({ assert }) => {
|
|
148
|
+
const dataDomain = new DataDomain()
|
|
149
|
+
const model = dataDomain.addModel()
|
|
150
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
151
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
152
|
+
entity2.addParent(entity1.key)
|
|
153
|
+
entity2.removeParent(entity1.key)
|
|
154
|
+
assert.isFalse(dataDomain.graph.hasEdge(entity2.key, entity1.key))
|
|
155
|
+
assert.deepEqual([...entity2.listParents()], [])
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('throws an error if the parent does not exist', ({ assert }) => {
|
|
159
|
+
const dataDomain = new DataDomain()
|
|
160
|
+
const model = dataDomain.addModel()
|
|
161
|
+
const entity = model.addEntity()
|
|
162
|
+
assert.throws(() => {
|
|
163
|
+
entity.removeParent('non-existent-entity')
|
|
164
|
+
}, `Trying to remove a parent non-existent-entity from ${entity.key}, but it doesn't exist`)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('notifies change', async ({ assert }) => {
|
|
168
|
+
const dataDomain = new DataDomain()
|
|
169
|
+
const model = dataDomain.addModel()
|
|
170
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
171
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
172
|
+
entity2.addParent(entity1.key)
|
|
173
|
+
entity2.removeParent(entity1.key)
|
|
174
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('removes the graph edge', ({ assert }) => {
|
|
178
|
+
const dataDomain = new DataDomain()
|
|
179
|
+
const model = dataDomain.addModel()
|
|
180
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
181
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
182
|
+
entity2.addParent(entity1.key)
|
|
183
|
+
entity2.removeParent(entity1.key)
|
|
184
|
+
assert.isFalse(dataDomain.graph.hasEdge(entity2.key, entity1.key))
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test.group('DomainEntity.hasCircularParent()', () => {
|
|
189
|
+
test('returns false when no parents', ({ assert }) => {
|
|
190
|
+
const dataDomain = new DataDomain()
|
|
191
|
+
const model = dataDomain.addModel()
|
|
192
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
193
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
194
|
+
assert.isFalse(entity1.hasCircularParent(entity2.key))
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('returns true when direct circular dependency', ({ assert }) => {
|
|
198
|
+
const dataDomain = new DataDomain()
|
|
199
|
+
const model = dataDomain.addModel()
|
|
200
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
201
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
202
|
+
entity1.addParent(entity2.key)
|
|
203
|
+
assert.isTrue(entity2.hasCircularParent(entity1.key))
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
test('returns true when indirect circular dependency', ({ assert }) => {
|
|
207
|
+
const dataDomain = new DataDomain()
|
|
208
|
+
const model = dataDomain.addModel()
|
|
209
|
+
const entity1 = model.addEntity()
|
|
210
|
+
const entity2 = model.addEntity()
|
|
211
|
+
const entity3 = model.addEntity()
|
|
212
|
+
entity1.addParent(entity2.key)
|
|
213
|
+
entity2.addParent(entity3.key)
|
|
214
|
+
assert.isTrue(entity3.hasCircularParent(entity1.key))
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test('returns true when indirect circular dependency - longer chain', ({ assert }) => {
|
|
218
|
+
const dataDomain = new DataDomain()
|
|
219
|
+
const model = dataDomain.addModel()
|
|
220
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
221
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
222
|
+
const entity3 = model.addEntity({ key: 'entity3' })
|
|
223
|
+
const entity4 = model.addEntity({ key: 'entity4' })
|
|
224
|
+
entity1.addParent(entity2.key)
|
|
225
|
+
entity2.addParent(entity3.key)
|
|
226
|
+
entity3.addParent(entity4.key)
|
|
227
|
+
assert.isTrue(entity4.hasCircularParent(entity1.key))
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('returns true when adding one of children as parent', ({ assert }) => {
|
|
231
|
+
const dataDomain = new DataDomain()
|
|
232
|
+
const model = dataDomain.addModel()
|
|
233
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
234
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
235
|
+
const entity3 = model.addEntity({ key: 'entity3' })
|
|
236
|
+
entity1.addParent(entity2.key)
|
|
237
|
+
entity2.addParent(entity3.key)
|
|
238
|
+
assert.isTrue(entity2.hasCircularParent(entity1.key))
|
|
239
|
+
assert.isTrue(entity3.hasCircularParent(entity1.key))
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('returns true when indirect circular dependency - multiple parents', ({ assert }) => {
|
|
243
|
+
const dataDomain = new DataDomain()
|
|
244
|
+
const model = dataDomain.addModel()
|
|
245
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
246
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
247
|
+
const entity3 = model.addEntity({ key: 'entity3' })
|
|
248
|
+
const entity4 = model.addEntity({ key: 'entity4' })
|
|
249
|
+
entity1.addParent(entity2.key)
|
|
250
|
+
entity1.addParent(entity3.key)
|
|
251
|
+
entity2.addParent(entity4.key)
|
|
252
|
+
assert.isTrue(entity4.hasCircularParent(entity1.key))
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
test('returns false when there is a parent, but not in the chain', ({ assert }) => {
|
|
256
|
+
const dataDomain = new DataDomain()
|
|
257
|
+
const model = dataDomain.addModel()
|
|
258
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
259
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
260
|
+
const entity3 = model.addEntity({ key: 'entity3' })
|
|
261
|
+
entity3.addParent(entity2.key)
|
|
262
|
+
assert.isFalse(entity1.hasCircularParent(entity3.key))
|
|
263
|
+
})
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test.group('DomainEntity.hasParents()', () => {
|
|
267
|
+
test('returns true if the entity has parents', ({ assert }) => {
|
|
268
|
+
const dataDomain = new DataDomain()
|
|
269
|
+
const model = dataDomain.addModel()
|
|
270
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
271
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
272
|
+
entity2.addParent(entity1.key)
|
|
273
|
+
assert.isTrue(entity2.hasParents())
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
test('returns false if the entity has no parents', ({ assert }) => {
|
|
277
|
+
const dataDomain = new DataDomain()
|
|
278
|
+
const model = dataDomain.addModel()
|
|
279
|
+
const entity = model.addEntity()
|
|
280
|
+
assert.isFalse(entity.hasParents())
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
test('returns false if the entity has other edges but not parent', ({ assert }) => {
|
|
284
|
+
const dataDomain = new DataDomain()
|
|
285
|
+
const model = dataDomain.addModel()
|
|
286
|
+
const entity1 = model.addEntity({ key: 'entity1' })
|
|
287
|
+
const entity2 = model.addEntity({ key: 'entity2' })
|
|
288
|
+
dataDomain.graph.setEdge(entity2.key, entity1.key, { type: 'association' })
|
|
289
|
+
assert.isFalse(entity2.hasParents())
|
|
290
|
+
})
|
|
291
|
+
})
|