@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,718 @@
|
|
|
1
|
+
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
|
+
import { DomainAssociationKind, DomainEntityKind, DomainPropertyKind } from '../models/kinds.js';
|
|
3
|
+
import { DomainElement } from './DomainElement.js';
|
|
4
|
+
import { nanoid } from 'nanoid';
|
|
5
|
+
import { Thing } from '../models/Thing.js';
|
|
6
|
+
import { observed, retargetChange, toRaw } from './observed.js';
|
|
7
|
+
import { DomainProperty } from './DomainProperty.js';
|
|
8
|
+
import { RemovePropertyException } from '../exceptions/remove_property_exception.js';
|
|
9
|
+
import { DomainAssociation } from './DomainAssociation.js';
|
|
10
|
+
import { ValidationError } from '../exceptions/validation_error.js';
|
|
11
|
+
import { ShapeGenerator } from './amf/ShapeGenerator.js';
|
|
12
|
+
import { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js';
|
|
13
|
+
import { removeGraphNode } from './GraphUtils.js';
|
|
14
|
+
/**
|
|
15
|
+
* Represents an entity within a data domain model.
|
|
16
|
+
*
|
|
17
|
+
* A `DomainEntity` defines a structured data type,
|
|
18
|
+
* containing properties and associations. It's a
|
|
19
|
+
* fundamental building block for modeling complex data
|
|
20
|
+
* structures.
|
|
21
|
+
*
|
|
22
|
+
* **Key Features:**
|
|
23
|
+
*
|
|
24
|
+
* - **Properties:** Defines the data elements (fields) within the entity.
|
|
25
|
+
* - **Associations:** Defines relationships to other entities.
|
|
26
|
+
* - **Inheritance:** Supports inheriting properties and associations from parent entities.
|
|
27
|
+
* - **Metadata:** Supports tags, taxonomy, and deprecation status.
|
|
28
|
+
* - **AMF Shape Generation:** Can be serialized to an AMF (API Modeling Framework) shape.
|
|
29
|
+
* - **Example Generation:** Can generate example databased on its schema.
|
|
30
|
+
*
|
|
31
|
+
* **Usage:**
|
|
32
|
+
*
|
|
33
|
+
* The preferred way to create a `DomainEntity` is through
|
|
34
|
+
* the `DomainModel.addEntity()` method.
|
|
35
|
+
*
|
|
36
|
+
* **Example:**
|
|
37
|
+
*
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const dataDomain = new DataDomain();
|
|
40
|
+
* const userModel = dataDomain.addModel({ key: 'userModel' });
|
|
41
|
+
* const userEntity = userModel.addEntity({ key: 'user' });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
let DomainEntity = (() => {
|
|
45
|
+
let _classSuper = DomainElement;
|
|
46
|
+
let _info_decorators;
|
|
47
|
+
let _info_initializers = [];
|
|
48
|
+
let _info_extraInitializers = [];
|
|
49
|
+
let _tags_decorators;
|
|
50
|
+
let _tags_initializers = [];
|
|
51
|
+
let _tags_extraInitializers = [];
|
|
52
|
+
let _taxonomy_decorators;
|
|
53
|
+
let _taxonomy_initializers = [];
|
|
54
|
+
let _taxonomy_extraInitializers = [];
|
|
55
|
+
let _deprecated_decorators;
|
|
56
|
+
let _deprecated_initializers = [];
|
|
57
|
+
let _deprecated_extraInitializers = [];
|
|
58
|
+
return class DomainEntity extends _classSuper {
|
|
59
|
+
static {
|
|
60
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
61
|
+
_info_decorators = [retargetChange()];
|
|
62
|
+
_tags_decorators = [observed({ deep: true })];
|
|
63
|
+
_taxonomy_decorators = [observed({ deep: true })];
|
|
64
|
+
_deprecated_decorators = [observed()];
|
|
65
|
+
__esDecorate(this, null, _info_decorators, { kind: "accessor", name: "info", static: false, private: false, access: { has: obj => "info" in obj, get: obj => obj.info, set: (obj, value) => { obj.info = value; } }, metadata: _metadata }, _info_initializers, _info_extraInitializers);
|
|
66
|
+
__esDecorate(this, null, _tags_decorators, { kind: "accessor", name: "tags", static: false, private: false, access: { has: obj => "tags" in obj, get: obj => obj.tags, set: (obj, value) => { obj.tags = value; } }, metadata: _metadata }, _tags_initializers, _tags_extraInitializers);
|
|
67
|
+
__esDecorate(this, null, _taxonomy_decorators, { kind: "accessor", name: "taxonomy", static: false, private: false, access: { has: obj => "taxonomy" in obj, get: obj => obj.taxonomy, set: (obj, value) => { obj.taxonomy = value; } }, metadata: _metadata }, _taxonomy_initializers, _taxonomy_extraInitializers);
|
|
68
|
+
__esDecorate(this, null, _deprecated_decorators, { kind: "accessor", name: "deprecated", static: false, private: false, access: { has: obj => "deprecated" in obj, get: obj => obj.deprecated, set: (obj, value) => { obj.deprecated = value; } }, metadata: _metadata }, _deprecated_initializers, _deprecated_extraInitializers);
|
|
69
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The kind of the domain element.
|
|
73
|
+
*/
|
|
74
|
+
kind;
|
|
75
|
+
#info_accessor_storage = __runInitializers(this, _info_initializers, void 0);
|
|
76
|
+
/**
|
|
77
|
+
* The description of the domain entity.
|
|
78
|
+
*/
|
|
79
|
+
get info() { return this.#info_accessor_storage; }
|
|
80
|
+
set info(value) { this.#info_accessor_storage = value; }
|
|
81
|
+
#tags_accessor_storage = (__runInitializers(this, _info_extraInitializers), __runInitializers(this, _tags_initializers, void 0));
|
|
82
|
+
/**
|
|
83
|
+
* Optional general purpose tags for the UI.
|
|
84
|
+
*/
|
|
85
|
+
get tags() { return this.#tags_accessor_storage; }
|
|
86
|
+
set tags(value) { this.#tags_accessor_storage = value; }
|
|
87
|
+
#taxonomy_accessor_storage = (__runInitializers(this, _tags_extraInitializers), __runInitializers(this, _taxonomy_initializers, void 0));
|
|
88
|
+
/**
|
|
89
|
+
* Reserved for future use.
|
|
90
|
+
*
|
|
91
|
+
* The keys of the taxonomy items associated with the entity.
|
|
92
|
+
*/
|
|
93
|
+
get taxonomy() { return this.#taxonomy_accessor_storage; }
|
|
94
|
+
set taxonomy(value) { this.#taxonomy_accessor_storage = value; }
|
|
95
|
+
#fields_accessor_storage = __runInitializers(this, _taxonomy_extraInitializers);
|
|
96
|
+
/**
|
|
97
|
+
* The ordered list of fields (properties and associations) in the schema.
|
|
98
|
+
* These only keep references to the properties and associations.
|
|
99
|
+
* The order of the fields is important as it defines the order of the
|
|
100
|
+
* properties in the schema.
|
|
101
|
+
*/
|
|
102
|
+
get fields() { return this.#fields_accessor_storage; }
|
|
103
|
+
set fields(value) { this.#fields_accessor_storage = value; }
|
|
104
|
+
#deprecated_accessor_storage = __runInitializers(this, _deprecated_initializers, void 0);
|
|
105
|
+
/**
|
|
106
|
+
* Whether this entity is deprecated.
|
|
107
|
+
*/
|
|
108
|
+
get deprecated() { return this.#deprecated_accessor_storage; }
|
|
109
|
+
set deprecated(value) { this.#deprecated_accessor_storage = value; }
|
|
110
|
+
/**
|
|
111
|
+
* Creates a full data entity schema with defaults.
|
|
112
|
+
*
|
|
113
|
+
* @param input The partial data entity schema.
|
|
114
|
+
* @returns The data entity schema.
|
|
115
|
+
*/
|
|
116
|
+
static createSchema(input = {}) {
|
|
117
|
+
const { key = nanoid(), tags, taxonomy, fields, deprecated } = input;
|
|
118
|
+
const info = Thing.fromJSON(input.info, { name: 'New entity' }).toJSON();
|
|
119
|
+
const result = {
|
|
120
|
+
kind: DomainEntityKind,
|
|
121
|
+
key,
|
|
122
|
+
info,
|
|
123
|
+
};
|
|
124
|
+
if (Array.isArray(tags)) {
|
|
125
|
+
result.tags = [...tags];
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(taxonomy)) {
|
|
128
|
+
result.taxonomy = [...taxonomy];
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(fields)) {
|
|
131
|
+
result.fields = [...fields];
|
|
132
|
+
}
|
|
133
|
+
if (typeof deprecated === 'boolean') {
|
|
134
|
+
result.deprecated = deprecated;
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates a new domain entity instance.
|
|
140
|
+
*
|
|
141
|
+
* You probably want to use the `DomainModel.addEntity()`
|
|
142
|
+
* method instead.
|
|
143
|
+
*
|
|
144
|
+
* @param root A reference to the root DataDomain instance.
|
|
145
|
+
* @param input The partial domain entity schema.
|
|
146
|
+
*/
|
|
147
|
+
constructor(root, input) {
|
|
148
|
+
const init = DomainEntity.createSchema(input);
|
|
149
|
+
super(root, init.key);
|
|
150
|
+
__runInitializers(this, _deprecated_extraInitializers);
|
|
151
|
+
this.kind = DomainEntityKind;
|
|
152
|
+
this.info = new Thing(init.info);
|
|
153
|
+
if (Array.isArray(init.tags)) {
|
|
154
|
+
this.tags = [...init.tags];
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this.tags = [];
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(init.taxonomy)) {
|
|
160
|
+
this.taxonomy = [...init.taxonomy];
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.taxonomy = [];
|
|
164
|
+
}
|
|
165
|
+
if (Array.isArray(init.fields)) {
|
|
166
|
+
this.fields = [...init.fields];
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.fields = [];
|
|
170
|
+
}
|
|
171
|
+
if (typeof init.deprecated === 'boolean') {
|
|
172
|
+
this.deprecated = init.deprecated;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Generates a JSON representation of the entity.
|
|
177
|
+
*
|
|
178
|
+
* @returns A plain object representation of the `DomainEntity`.
|
|
179
|
+
*/
|
|
180
|
+
toJSON() {
|
|
181
|
+
const result = {
|
|
182
|
+
kind: this.kind,
|
|
183
|
+
key: this.key,
|
|
184
|
+
info: this.info.toJSON(),
|
|
185
|
+
};
|
|
186
|
+
if (Array.isArray(this.fields) && this.fields.length) {
|
|
187
|
+
result.fields = [...this.fields];
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(this.taxonomy) && this.taxonomy.length) {
|
|
190
|
+
result.taxonomy = [...toRaw(this, this.taxonomy)];
|
|
191
|
+
}
|
|
192
|
+
if (Array.isArray(this.tags) && this.tags.length) {
|
|
193
|
+
result.tags = [...toRaw(this, this.tags)];
|
|
194
|
+
}
|
|
195
|
+
if (typeof this.deprecated === 'boolean') {
|
|
196
|
+
result.deprecated = this.deprecated;
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Returns a parent data entity where this data property
|
|
202
|
+
* exist.
|
|
203
|
+
*
|
|
204
|
+
* @returns The parent `DomainModel` or undefined if not found.
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const parent = entity.getParentInstance();
|
|
208
|
+
* if (parent) {
|
|
209
|
+
* console.log(parent.key);
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
getParentInstance() {
|
|
214
|
+
const parentKey = this.root.graph.parent(this.key);
|
|
215
|
+
if (!parentKey) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
return this.root.graph.node(parentKey);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Adds a property to this entity.
|
|
222
|
+
*
|
|
223
|
+
* @param property The partial property schema.
|
|
224
|
+
* @returns The created `DomainProperty` instance.
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const property = entity.addProperty({
|
|
228
|
+
* key: 'name',
|
|
229
|
+
* type: 'string',
|
|
230
|
+
* required: true,
|
|
231
|
+
* })
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
addProperty(property) {
|
|
235
|
+
if (property && property.key && this.root.graph.hasNode(property.key)) {
|
|
236
|
+
throw new Error(`Trying to add a property ${property.key}, but it already exists`);
|
|
237
|
+
}
|
|
238
|
+
const instance = new DomainProperty(this.root, this.key, property);
|
|
239
|
+
this.root.graph.setNode(instance.key, instance);
|
|
240
|
+
this.root.graph.setEdge(this.key, instance.key, { type: 'property' });
|
|
241
|
+
this.fields.push({
|
|
242
|
+
type: 'property',
|
|
243
|
+
key: instance.key,
|
|
244
|
+
});
|
|
245
|
+
this.root.notifyChange();
|
|
246
|
+
return instance;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Removes a property from this entity.
|
|
250
|
+
*
|
|
251
|
+
* @param key The key of the property to remove.
|
|
252
|
+
* @throws {RemovePropertyException} When the property does not exist.
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* entity.removeProperty('name')
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
removeProperty(key) {
|
|
259
|
+
if (!this.root.graph.hasNode(key)) {
|
|
260
|
+
throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't exist`);
|
|
261
|
+
}
|
|
262
|
+
const prop = this.root.graph.node(key);
|
|
263
|
+
if (prop.getParentInstance() !== this) {
|
|
264
|
+
throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't belong to this entity`);
|
|
265
|
+
}
|
|
266
|
+
removeGraphNode(this.root.graph, key);
|
|
267
|
+
this.removeField(key);
|
|
268
|
+
this.root.notifyChange();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Lists all properties of this entity.
|
|
272
|
+
*
|
|
273
|
+
* Note, it accounts for the order of the properties as
|
|
274
|
+
* defined in the `fields` array.
|
|
275
|
+
*
|
|
276
|
+
* @returns A generator that yields each `DomainProperty`.
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* for (const property of entity.listProperties()) {
|
|
280
|
+
* console.log(property.key);
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
*listProperties() {
|
|
285
|
+
for (const { key, type } of this.fields) {
|
|
286
|
+
if (type !== 'property') {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const node = this.root.graph.node(key);
|
|
290
|
+
if (!node || node.kind !== DomainPropertyKind) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
yield node;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Checks if this entity has any properties.
|
|
298
|
+
*
|
|
299
|
+
* @returns True if the entity has properties.
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* if (entity.hasProperties()) {
|
|
303
|
+
* // ...
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
hasProperties() {
|
|
308
|
+
return this.fields.some((item) => item.type === 'property');
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Lists all parent entities of this entity.
|
|
312
|
+
*
|
|
313
|
+
* @returns A generator that yields each parent `DomainEntity`.
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* for (const parent of entity.listParents()) {
|
|
317
|
+
* console.log(parent.key);
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
*listParents() {
|
|
322
|
+
for (const edge of this.root.graph.outEdges(this.key)) {
|
|
323
|
+
const value = this.root.graph.edge(edge);
|
|
324
|
+
if (!value || value.type !== 'parent') {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const parent = this.root.graph.node(edge.w);
|
|
328
|
+
if (parent) {
|
|
329
|
+
yield parent;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Adds a parent to this entity.
|
|
335
|
+
*
|
|
336
|
+
* @param key The key of the parent entity.
|
|
337
|
+
* @param domain The key of the foreign domain the parent belongs to.
|
|
338
|
+
* @returns `this` for chaining.
|
|
339
|
+
* @throws ValidationError When the parent does not exist or a circular dependency is detected.
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* entity.addParent('baseEntity');
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
addParent(key, domain) {
|
|
346
|
+
const effectiveKey = domain ? `${domain}:${key}` : key;
|
|
347
|
+
// Prevent adding self as parent
|
|
348
|
+
if (effectiveKey === this.key) {
|
|
349
|
+
const message = 'Entity cannot be a parent of itself';
|
|
350
|
+
throw new ValidationError([
|
|
351
|
+
{
|
|
352
|
+
field: 'parents',
|
|
353
|
+
message,
|
|
354
|
+
rule: 'circular',
|
|
355
|
+
},
|
|
356
|
+
], { message });
|
|
357
|
+
}
|
|
358
|
+
const { graph } = this.root;
|
|
359
|
+
if (!graph.hasNode(effectiveKey)) {
|
|
360
|
+
let message = `Entity with key "${key}" not found`;
|
|
361
|
+
if (domain) {
|
|
362
|
+
message += ` in domain "${domain}"`;
|
|
363
|
+
}
|
|
364
|
+
throw new ValidationError([
|
|
365
|
+
{
|
|
366
|
+
field: 'parents',
|
|
367
|
+
message,
|
|
368
|
+
rule: 'required',
|
|
369
|
+
},
|
|
370
|
+
], { message });
|
|
371
|
+
}
|
|
372
|
+
// Check for circular inheritance
|
|
373
|
+
if (this.hasCircularParent(effectiveKey)) {
|
|
374
|
+
const message = `Circular inheritance detected. Cannot add ${key} as a parent`;
|
|
375
|
+
throw new ValidationError([
|
|
376
|
+
{
|
|
377
|
+
field: 'parents',
|
|
378
|
+
message,
|
|
379
|
+
rule: 'circular',
|
|
380
|
+
},
|
|
381
|
+
], { message });
|
|
382
|
+
}
|
|
383
|
+
if (graph.outEdges(this.key, effectiveKey).next().value) {
|
|
384
|
+
const message = `Parent ${key} already exists`;
|
|
385
|
+
throw new ValidationError([
|
|
386
|
+
{
|
|
387
|
+
field: 'parents',
|
|
388
|
+
message,
|
|
389
|
+
rule: 'unique',
|
|
390
|
+
},
|
|
391
|
+
], { message });
|
|
392
|
+
}
|
|
393
|
+
// Parents are associated through graph edges.
|
|
394
|
+
// Otherwise it would collide with the parent model.
|
|
395
|
+
if (domain) {
|
|
396
|
+
graph.setEdge(this.key, effectiveKey, { type: 'parent', domain, foreign: true });
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
graph.setEdge(this.key, effectiveKey, { type: 'parent' });
|
|
400
|
+
}
|
|
401
|
+
this.root.notifyChange();
|
|
402
|
+
return this;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Removes a parent from this entity.
|
|
406
|
+
*
|
|
407
|
+
* @param key The key of the parent entity to remove.
|
|
408
|
+
* @returns `this` for chaining.
|
|
409
|
+
* @throws Error When the parent does not exist.
|
|
410
|
+
* @example
|
|
411
|
+
* ```typescript
|
|
412
|
+
* entity.removeParent('baseEntity');
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
removeParent(key) {
|
|
416
|
+
const { graph } = this.root;
|
|
417
|
+
if (!graph.hasEdge(this.key, key)) {
|
|
418
|
+
throw new Error(`Trying to remove a parent ${key} from ${this.key}, but it doesn't exist`);
|
|
419
|
+
}
|
|
420
|
+
graph.removeEdge(this.key, key);
|
|
421
|
+
this.root.notifyChange();
|
|
422
|
+
return this;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Checks if this entity has any parents.
|
|
426
|
+
*
|
|
427
|
+
* @returns True if the entity has parents.
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* if (entity.hasParents()) {
|
|
431
|
+
* // ...
|
|
432
|
+
* }
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
hasParents() {
|
|
436
|
+
for (const edge of this.root.graph.outEdges(this.key)) {
|
|
437
|
+
if (this.root.graph.edge(edge)?.type === 'parent') {
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Checks if the passed entity has a circular parent
|
|
445
|
+
* relationship when attempting to add a new parent.
|
|
446
|
+
*
|
|
447
|
+
* @param key The key of the parent being added.
|
|
448
|
+
* @returns True if adding this parent would create a
|
|
449
|
+
* circular relationship.
|
|
450
|
+
*/
|
|
451
|
+
hasCircularParent(key) {
|
|
452
|
+
const { graph } = this.root;
|
|
453
|
+
// Check if new parent is one of the children.
|
|
454
|
+
for (const edge of graph.outEdges(key, this.key)) {
|
|
455
|
+
if (graph.edge(edge)?.type === 'parent') {
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
// check if this entity is in parents chain.
|
|
460
|
+
let current = graph.node(key);
|
|
461
|
+
while (current) {
|
|
462
|
+
if (current.key === this.key) {
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
const parents = [...current.listParents()];
|
|
466
|
+
if (parents.length === 0) {
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
// Assuming single inheritance
|
|
470
|
+
// TODO: Update this to check for multiple parents.
|
|
471
|
+
current = parents[0];
|
|
472
|
+
}
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Creates breadcrumbs from this entity to the root
|
|
477
|
+
* namespace.
|
|
478
|
+
*
|
|
479
|
+
* @returns An array of `FileBreadcrumb` instances.
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* const breadcrumbs = entity.breadcrumbs();
|
|
483
|
+
* console.log(breadcrumbs);
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
breadcrumbs() {
|
|
487
|
+
const result = [];
|
|
488
|
+
result.push({
|
|
489
|
+
key: this.key,
|
|
490
|
+
name: this.info.getLabel('Unnamed entity'),
|
|
491
|
+
kind: DomainEntityKind,
|
|
492
|
+
});
|
|
493
|
+
const model = this.getParentInstance();
|
|
494
|
+
if (model) {
|
|
495
|
+
result.push({
|
|
496
|
+
key: model.key,
|
|
497
|
+
kind: model.kind,
|
|
498
|
+
name: model.info.getLabel('Unnamed model'),
|
|
499
|
+
});
|
|
500
|
+
let parent = model.getParentInstance();
|
|
501
|
+
while (parent && parent !== this.root) {
|
|
502
|
+
result.push({
|
|
503
|
+
key: parent.key,
|
|
504
|
+
kind: parent.kind,
|
|
505
|
+
name: parent.info.getLabel('Unnamed namespace'),
|
|
506
|
+
});
|
|
507
|
+
const typed = parent;
|
|
508
|
+
parent = typed.getParentInstance();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
result.push({
|
|
512
|
+
key: this.root.key,
|
|
513
|
+
name: this.root.info.getLabel('Unnamed data domain'),
|
|
514
|
+
kind: this.root.kind,
|
|
515
|
+
});
|
|
516
|
+
return result.reverse();
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Adds an association to this entity.
|
|
520
|
+
*
|
|
521
|
+
* @param init The association options.
|
|
522
|
+
* @param input The partial association schema.
|
|
523
|
+
* @returns The created `DomainAssociation` instance.
|
|
524
|
+
* @throws Error When the target entity does not exist.
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* const association = entity.addAssociation({
|
|
528
|
+
* key: 'address',
|
|
529
|
+
* });
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
addAssociation(init = {}, input) {
|
|
533
|
+
const { graph } = this.root;
|
|
534
|
+
if (init.domain && init.key) {
|
|
535
|
+
// target is foreign
|
|
536
|
+
const foreignKey = `${init.domain}:${init.key}`;
|
|
537
|
+
if (!graph.hasNode(foreignKey)) {
|
|
538
|
+
throw new Error(`Foreign entity ${foreignKey} not found`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else if (init.key) {
|
|
542
|
+
if (!graph.hasNode(init.key)) {
|
|
543
|
+
throw new Error(`Target entity ${init.key} not found`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
const item = new DomainAssociation(this.root, this.key, input);
|
|
547
|
+
graph.setNode(item.key, item);
|
|
548
|
+
graph.setEdge(this.key, item.key, { type: 'association' });
|
|
549
|
+
if (init.key) {
|
|
550
|
+
item.addTarget(init.key, init.domain);
|
|
551
|
+
}
|
|
552
|
+
this.fields.push({ type: 'association', key: item.key });
|
|
553
|
+
this.root.notifyChange();
|
|
554
|
+
return item;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Removes an association from this entity.
|
|
558
|
+
*
|
|
559
|
+
* @param key The key of the association to remove.
|
|
560
|
+
* @throws Error When the association does not exist.
|
|
561
|
+
* @example
|
|
562
|
+
* ```typescript
|
|
563
|
+
* entity.removeAssociation('address');
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
removeAssociation(key) {
|
|
567
|
+
if (!this.root.graph.hasEdge(this.key, key)) {
|
|
568
|
+
throw new Error(`Unable to find a connection between this entity and the ${key} association`);
|
|
569
|
+
}
|
|
570
|
+
const edge = this.root.graph.edge(this.key, key);
|
|
571
|
+
if (!edge || edge.type !== 'association') {
|
|
572
|
+
throw new Error(`Association ${key} does not exist`);
|
|
573
|
+
}
|
|
574
|
+
removeGraphNode(this.root.graph, key);
|
|
575
|
+
this.removeField(key);
|
|
576
|
+
this.root.notifyChange();
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Lists all associations of this entity.
|
|
580
|
+
*
|
|
581
|
+
* The order of the associations is defined in the `fields` array.
|
|
582
|
+
*
|
|
583
|
+
* @returns A generator that yields each
|
|
584
|
+
* `DomainAssociation`.
|
|
585
|
+
* @example
|
|
586
|
+
* ```typescript
|
|
587
|
+
* for (const association of entity.listAssociations()) {
|
|
588
|
+
* console.log(association.key);
|
|
589
|
+
* }
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
*listAssociations() {
|
|
593
|
+
for (const { key, type } of this.fields) {
|
|
594
|
+
if (type !== 'association') {
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
const node = this.root.graph.node(key);
|
|
598
|
+
if (!node || node.kind !== DomainAssociationKind) {
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
yield node;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Checks if this entity has any associations.
|
|
606
|
+
*
|
|
607
|
+
* @returns True if the entity has associations.
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* if (entity.hasAssociations()) {
|
|
611
|
+
* // ...
|
|
612
|
+
* }
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
hasAssociations() {
|
|
616
|
+
return this.fields.some((item) => item.type === 'association');
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Lists all fields (properties and associations) of this entity.
|
|
620
|
+
*
|
|
621
|
+
* @returns A generator that yields each `DomainAssociation` or `DomainProperty`.
|
|
622
|
+
* @example
|
|
623
|
+
* ```typescript
|
|
624
|
+
* for (const field of entity.listFields()) {
|
|
625
|
+
* console.log(field.key);
|
|
626
|
+
* }
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
*listFields() {
|
|
630
|
+
for (const { key } of this.fields) {
|
|
631
|
+
const node = this.root.graph.node(key);
|
|
632
|
+
if (!node) {
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
if (node.kind === DomainAssociationKind || node.kind === DomainPropertyKind) {
|
|
636
|
+
yield node;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Checks if this entity has any fields (properties or associations).
|
|
642
|
+
*
|
|
643
|
+
* @returns True if the entity has fields.
|
|
644
|
+
* @example
|
|
645
|
+
* ```typescript
|
|
646
|
+
* if (entity.hasFields()) {
|
|
647
|
+
* // ...
|
|
648
|
+
* }
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
hasFields() {
|
|
652
|
+
return this.fields.length > 0;
|
|
653
|
+
}
|
|
654
|
+
removeField(key) {
|
|
655
|
+
this.fields = this.fields.filter((item) => item.key !== key);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Creates an AMF's data Shape.
|
|
659
|
+
*
|
|
660
|
+
* The property itself is auto-generated. If the `schema` is defined then it is used
|
|
661
|
+
* as the `range` of the property. Otherwise basic shape is generated for the range.
|
|
662
|
+
*
|
|
663
|
+
* This is a preferred way of reading the AMF shape as this synchronizes changed
|
|
664
|
+
* data properties with the shape definition.
|
|
665
|
+
*
|
|
666
|
+
* @returns AMF property shape definition.
|
|
667
|
+
*/
|
|
668
|
+
toApiShape() {
|
|
669
|
+
const serializer = new ShapeGenerator();
|
|
670
|
+
return serializer.entity(this);
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Reads the schema of the Entity and generates an example for it.
|
|
674
|
+
*
|
|
675
|
+
* @param mime The mime type of the example.
|
|
676
|
+
* @param opts The example generation options.
|
|
677
|
+
* @returns The generated example.
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* const example = entity.toExample('application/json');
|
|
681
|
+
* console.log(example);
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
toExample(mime, opts = {}) {
|
|
685
|
+
const shape = this.toApiShape();
|
|
686
|
+
const generator = new ApiSchemaGenerator(mime, {
|
|
687
|
+
renderExamples: typeof opts.renderExamples === 'boolean' ? opts.renderExamples : true,
|
|
688
|
+
renderMocked: typeof opts.renderMocked === 'boolean' ? opts.renderMocked : true,
|
|
689
|
+
renderOptional: typeof opts.renderOptional === 'boolean' ? opts.renderOptional : true,
|
|
690
|
+
selectedUnions: opts.selectedUnions,
|
|
691
|
+
});
|
|
692
|
+
return generator.generate(shape);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Checks whether the entity is a child of the given namespace or data model.
|
|
696
|
+
* The relationship doesn't have to be direct, as long as the entity
|
|
697
|
+
* is in the hierarchy it will return true.
|
|
698
|
+
*
|
|
699
|
+
* @param key The key of the parent to check.
|
|
700
|
+
* @returns True if this entity is a child of the given namespace or data model.
|
|
701
|
+
*/
|
|
702
|
+
isChildOf(key) {
|
|
703
|
+
if (this.key === key) {
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
const parent = this.getParentInstance();
|
|
707
|
+
if (!parent) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
if (parent.key === key) {
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
return parent.isChildOf(key);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
})();
|
|
717
|
+
export { DomainEntity };
|
|
718
|
+
//# sourceMappingURL=DomainEntity.js.map
|