@quadnix/octo 0.0.21 → 0.0.23
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/dist/app.type.d.ts +124 -27
- package/dist/app.type.js +77 -7
- package/dist/app.type.js.map +1 -1
- package/dist/decorators/action.decorator.d.ts +7 -8
- package/dist/decorators/action.decorator.js +45 -44
- package/dist/decorators/action.decorator.js.map +1 -1
- package/dist/decorators/anchor.decorator.d.ts +2 -2
- package/dist/decorators/anchor.decorator.js +16 -11
- package/dist/decorators/anchor.decorator.js.map +1 -1
- package/dist/decorators/enable-hook.decorator.js +2 -2
- package/dist/decorators/enable-hook.decorator.js.map +1 -1
- package/dist/decorators/event-source.decorator.d.ts +1 -1
- package/dist/decorators/event-source.decorator.js +7 -2
- package/dist/decorators/event-source.decorator.js.map +1 -1
- package/dist/decorators/factory.decorator.d.ts +32 -1
- package/dist/decorators/factory.decorator.js +35 -3
- package/dist/decorators/factory.decorator.js.map +1 -1
- package/dist/decorators/model.decorator.d.ts +3 -2
- package/dist/decorators/model.decorator.js +24 -11
- package/dist/decorators/model.decorator.js.map +1 -1
- package/dist/decorators/module.decorator.d.ts +4 -71
- package/dist/decorators/module.decorator.js +18 -58
- package/dist/decorators/module.decorator.js.map +1 -1
- package/dist/decorators/on-event.decorator.d.ts +1 -1
- package/dist/decorators/on-event.decorator.js +7 -2
- package/dist/decorators/on-event.decorator.js.map +1 -1
- package/dist/decorators/overlay.decorator.d.ts +3 -2
- package/dist/decorators/overlay.decorator.js +23 -11
- package/dist/decorators/overlay.decorator.js.map +1 -1
- package/dist/decorators/resource.decorator.d.ts +3 -2
- package/dist/decorators/resource.decorator.js +23 -11
- package/dist/decorators/resource.decorator.js.map +1 -1
- package/dist/decorators/validate.decorator.d.ts +4 -4
- package/dist/decorators/validate.decorator.js +16 -2
- package/dist/decorators/validate.decorator.js.map +1 -1
- package/dist/errors/container.error.d.ts +11 -0
- package/dist/errors/container.error.js +20 -0
- package/dist/errors/container.error.js.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.js +7 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/input.error.d.ts +11 -0
- package/dist/errors/input.error.js +21 -0
- package/dist/errors/input.error.js.map +1 -0
- package/dist/errors/module.error.d.ts +4 -0
- package/dist/errors/module.error.js +8 -0
- package/dist/errors/module.error.js.map +1 -0
- package/dist/errors/node.error.d.ts +36 -0
- package/dist/errors/node.error.js +60 -0
- package/dist/errors/node.error.js.map +1 -0
- package/dist/errors/schema.error.d.ts +4 -0
- package/dist/errors/schema.error.js +8 -0
- package/dist/errors/schema.error.js.map +1 -0
- package/dist/errors/transaction.error.d.ts +35 -0
- package/dist/errors/transaction.error.js +58 -0
- package/dist/errors/transaction.error.js.map +1 -0
- package/dist/events/action.event.d.ts +13 -0
- package/dist/events/action.event.js +11 -0
- package/dist/events/action.event.js.map +1 -0
- package/dist/events/event.model.d.ts +6 -12
- package/dist/events/event.model.js +5 -11
- package/dist/events/event.model.js.map +1 -1
- package/dist/events/hook/commit.hook.event.d.ts +25 -0
- package/dist/events/hook/commit.hook.event.js +26 -0
- package/dist/events/hook/commit.hook.event.js.map +1 -0
- package/dist/events/hook/hook.event.d.ts +9 -0
- package/dist/events/hook/hook.event.js +10 -0
- package/dist/events/hook/hook.event.js.map +1 -0
- package/dist/events/hook/index.d.ts +4 -0
- package/dist/events/hook/index.js +5 -0
- package/dist/events/hook/index.js.map +1 -0
- package/dist/events/hook/model.hook.event.d.ts +25 -0
- package/dist/events/hook/model.hook.event.js +26 -0
- package/dist/events/hook/model.hook.event.js.map +1 -0
- package/dist/events/hook/resource.hook.event.d.ts +25 -0
- package/dist/events/hook/resource.hook.event.js +26 -0
- package/dist/events/hook/resource.hook.event.js.map +1 -0
- package/dist/events/index.d.ts +7 -0
- package/dist/events/index.js +8 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/module.event.d.ts +1 -6
- package/dist/events/module.event.js +0 -5
- package/dist/events/module.event.js.map +1 -1
- package/dist/events/registration.event.d.ts +9 -51
- package/dist/events/registration.event.js +16 -64
- package/dist/events/registration.event.js.map +1 -1
- package/dist/events/serialization.event.d.ts +24 -37
- package/dist/events/serialization.event.js +49 -33
- package/dist/events/serialization.event.js.map +1 -1
- package/dist/events/transaction.event.d.ts +45 -26
- package/dist/events/transaction.event.js +43 -25
- package/dist/events/transaction.event.js.map +1 -1
- package/dist/{decorators → functions/container}/container.d.ts +45 -31
- package/dist/{decorators → functions/container}/container.js +90 -58
- package/dist/functions/container/container.js.map +1 -0
- package/dist/{decorators → functions/container}/test-container.d.ts +5 -13
- package/dist/{decorators → functions/container}/test-container.js +31 -43
- package/dist/functions/container/test-container.js.map +1 -0
- package/dist/functions/dependency/dependency.d.ts +6 -6
- package/dist/functions/dependency/dependency.js +4 -3
- package/dist/functions/dependency/dependency.js.map +1 -1
- package/dist/functions/diff/diff-metadata.d.ts +4 -6
- package/dist/functions/diff/diff-metadata.js +4 -3
- package/dist/functions/diff/diff-metadata.js.map +1 -1
- package/dist/functions/diff/diff.d.ts +12 -7
- package/dist/functions/diff/diff.js +9 -12
- package/dist/functions/diff/diff.js.map +1 -1
- package/dist/functions/diff/diff.utility.d.ts +24 -24
- package/dist/functions/diff/diff.utility.js +46 -25
- package/dist/functions/diff/diff.utility.js.map +1 -1
- package/dist/functions/hook/commit.hook.d.ts +14 -3
- package/dist/functions/hook/commit.hook.js +16 -16
- package/dist/functions/hook/commit.hook.js.map +1 -1
- package/dist/functions/hook/hook.interface.d.ts +7 -6
- package/dist/functions/hook/model-action.hook.d.ts +17 -5
- package/dist/functions/hook/model-action.hook.js +20 -39
- package/dist/functions/hook/model-action.hook.js.map +1 -1
- package/dist/functions/hook/resource-action.hook.d.ts +17 -5
- package/dist/functions/hook/resource-action.hook.js +18 -18
- package/dist/functions/hook/resource-action.hook.js.map +1 -1
- package/dist/functions/node/node-action.abstract.d.ts +7 -0
- package/dist/functions/node/node-action.abstract.js +20 -0
- package/dist/functions/node/node-action.abstract.js.map +1 -0
- package/dist/functions/node/node.abstract.d.ts +93 -0
- package/dist/functions/node/node.abstract.js +342 -0
- package/dist/functions/node/node.abstract.js.map +1 -0
- package/dist/functions/node/node.interface.d.ts +176 -0
- package/dist/functions/node/node.interface.js +2 -0
- package/dist/functions/node/node.interface.js.map +1 -0
- package/dist/functions/schema/schema.d.ts +4 -0
- package/dist/functions/schema/schema.js +38 -0
- package/dist/functions/schema/schema.js.map +1 -0
- package/dist/index.d.ts +31 -33
- package/dist/index.js +32 -16
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +34 -22
- package/dist/main.js +92 -53
- package/dist/main.js.map +1 -1
- package/dist/models/account/account.model.d.ts +23 -0
- package/dist/models/account/account.model.js +67 -0
- package/dist/models/account/account.model.js.map +1 -0
- package/dist/models/account/account.schema.d.ts +7 -0
- package/dist/models/account/account.schema.js +12 -0
- package/dist/models/account/account.schema.js.map +1 -0
- package/dist/models/app/app.model.d.ts +6 -15
- package/dist/models/app/app.model.js +26 -31
- package/dist/models/app/app.model.js.map +1 -1
- package/dist/models/app/app.schema.d.ts +3 -0
- package/dist/models/app/app.schema.js +21 -0
- package/dist/models/app/app.schema.js.map +1 -0
- package/dist/models/deployment/deployment.model.d.ts +6 -13
- package/dist/models/deployment/deployment.model.js +11 -16
- package/dist/models/deployment/deployment.model.js.map +1 -1
- package/dist/models/deployment/deployment.schema.d.ts +7 -0
- package/dist/models/deployment/deployment.schema.js +25 -0
- package/dist/models/deployment/deployment.schema.js.map +1 -0
- package/dist/models/environment/environment.model.d.ts +5 -15
- package/dist/models/environment/environment.model.js +10 -28
- package/dist/models/environment/environment.model.js.map +1 -1
- package/dist/models/environment/environment.schema.d.ts +13 -0
- package/dist/models/environment/environment.schema.js +38 -0
- package/dist/models/environment/environment.schema.js.map +1 -0
- package/dist/models/execution/execution.model.d.ts +6 -14
- package/dist/models/execution/execution.model.js +15 -28
- package/dist/models/execution/execution.model.js.map +1 -1
- package/dist/models/execution/execution.schema.d.ts +14 -0
- package/dist/models/execution/execution.schema.js +34 -0
- package/dist/models/execution/execution.schema.js.map +1 -0
- package/dist/models/filesystem/filesystem.model.d.ts +10 -0
- package/dist/models/filesystem/filesystem.model.js +43 -0
- package/dist/models/filesystem/filesystem.model.js.map +1 -0
- package/dist/models/filesystem/filesystem.schema.d.ts +3 -0
- package/dist/models/filesystem/filesystem.schema.js +21 -0
- package/dist/models/filesystem/filesystem.schema.js.map +1 -0
- package/dist/models/image/image.model.d.ts +7 -41
- package/dist/models/image/image.model.js +17 -32
- package/dist/models/image/image.model.js.map +1 -1
- package/dist/models/image/image.schema.d.ts +9 -0
- package/dist/models/image/image.schema.js +31 -0
- package/dist/models/image/image.schema.js.map +1 -0
- package/dist/models/model-action.interface.d.ts +5 -19
- package/dist/models/model.abstract.d.ts +28 -316
- package/dist/models/model.abstract.js +180 -557
- package/dist/models/model.abstract.js.map +1 -1
- package/dist/models/model.interface.d.ts +42 -21
- package/dist/models/pipeline/pipeline.model.d.ts +5 -8
- package/dist/models/pipeline/pipeline.model.js +10 -16
- package/dist/models/pipeline/pipeline.model.js.map +1 -1
- package/dist/models/pipeline/pipeline.schema.d.ts +4 -0
- package/dist/models/pipeline/pipeline.schema.js +22 -0
- package/dist/models/pipeline/pipeline.schema.js.map +1 -0
- package/dist/models/region/region.model.d.ts +8 -9
- package/dist/models/region/region.model.js +25 -17
- package/dist/models/region/region.model.js.map +1 -1
- package/dist/models/region/region.schema.d.ts +3 -0
- package/dist/models/region/region.schema.js +21 -0
- package/dist/models/region/region.schema.js.map +1 -0
- package/dist/models/server/server.model.d.ts +5 -11
- package/dist/models/server/server.model.js +13 -16
- package/dist/models/server/server.model.js.map +1 -1
- package/dist/models/server/server.schema.d.ts +6 -0
- package/dist/models/server/server.schema.js +24 -0
- package/dist/models/server/server.schema.js.map +1 -0
- package/dist/models/service/service.model.d.ts +4 -10
- package/dist/models/service/service.model.js +12 -16
- package/dist/models/service/service.model.js.map +1 -1
- package/dist/models/service/service.schema.d.ts +6 -0
- package/dist/models/service/service.schema.js +24 -0
- package/dist/models/service/service.schema.js.map +1 -0
- package/dist/models/subnet/subnet.model.d.ts +10 -35
- package/dist/models/subnet/subnet.model.js +16 -47
- package/dist/models/subnet/subnet.model.js.map +1 -1
- package/dist/models/subnet/subnet.schema.d.ts +33 -0
- package/dist/models/subnet/subnet.schema.js +48 -0
- package/dist/models/subnet/subnet.schema.js.map +1 -0
- package/dist/modules/module.abstract.d.ts +21 -0
- package/dist/modules/module.abstract.js +14 -0
- package/dist/modules/module.abstract.js.map +1 -0
- package/dist/modules/module.container.d.ts +32 -18
- package/dist/modules/module.container.js +134 -81
- package/dist/modules/module.container.js.map +1 -1
- package/dist/modules/module.interface.d.ts +15 -2
- package/dist/modules/test-module.container.d.ts +33 -15
- package/dist/modules/test-module.container.js +264 -35
- package/dist/modules/test-module.container.js.map +1 -1
- package/dist/overlays/anchor.abstract.d.ts +13 -8
- package/dist/overlays/anchor.abstract.js.map +1 -1
- package/dist/overlays/anchor.interface.d.ts +5 -8
- package/dist/overlays/anchor.schema.d.ts +8 -0
- package/dist/overlays/anchor.schema.js +9 -0
- package/dist/overlays/anchor.schema.js.map +1 -0
- package/dist/overlays/overlay-data.repository.d.ts +3 -6
- package/dist/overlays/overlay-data.repository.js +17 -38
- package/dist/overlays/overlay-data.repository.js.map +1 -1
- package/dist/overlays/overlay.abstract.d.ts +15 -17
- package/dist/overlays/overlay.abstract.js +30 -44
- package/dist/overlays/overlay.abstract.js.map +1 -1
- package/dist/overlays/overlay.interface.d.ts +3 -7
- package/dist/overlays/overlay.schema.d.ts +8 -0
- package/dist/overlays/overlay.schema.js +9 -0
- package/dist/overlays/overlay.schema.js.map +1 -0
- package/dist/resources/resource-action.interface.d.ts +4 -3
- package/dist/resources/resource-data.repository.d.ts +16 -7
- package/dist/resources/resource-data.repository.js +118 -42
- package/dist/resources/resource-data.repository.js.map +1 -1
- package/dist/resources/resource.abstract.d.ts +56 -16
- package/dist/resources/resource.abstract.js +326 -19
- package/dist/resources/resource.abstract.js.map +1 -1
- package/dist/resources/resource.interface.d.ts +39 -8
- package/dist/resources/resource.schema.d.ts +14 -0
- package/dist/resources/resource.schema.js +11 -0
- package/dist/resources/resource.schema.js.map +1 -0
- package/dist/services/capture/capture.service.d.ts +6 -7
- package/dist/services/capture/capture.service.js +8 -5
- package/dist/services/capture/capture.service.js.map +1 -1
- package/dist/services/event/event.service.d.ts +3 -4
- package/dist/services/event/event.service.js +7 -9
- package/dist/services/event/event.service.js.map +1 -1
- package/dist/services/input/input.service.d.ts +62 -6
- package/dist/services/input/input.service.js +290 -14
- package/dist/services/input/input.service.js.map +1 -1
- package/dist/services/schema-translation/schema-translation.service.d.ts +13 -0
- package/dist/services/schema-translation/schema-translation.service.js +42 -0
- package/dist/services/schema-translation/schema-translation.service.js.map +1 -0
- package/dist/services/serialization/model/model-serialization.service.d.ts +1 -4
- package/dist/services/serialization/model/model-serialization.service.js +37 -33
- package/dist/services/serialization/model/model-serialization.service.js.map +1 -1
- package/dist/services/serialization/resource/resource-serialization.service.d.ts +5 -5
- package/dist/services/serialization/resource/resource-serialization.service.js +71 -96
- package/dist/services/serialization/resource/resource-serialization.service.js.map +1 -1
- package/dist/services/state-management/local.state-provider.d.ts +0 -1
- package/dist/services/state-management/local.state-provider.js +5 -7
- package/dist/services/state-management/local.state-provider.js.map +1 -1
- package/dist/services/state-management/state-management.service.d.ts +2 -3
- package/dist/services/state-management/state-management.service.js +19 -9
- package/dist/services/state-management/state-management.service.js.map +1 -1
- package/dist/services/state-management/state-provider.interface.d.ts +0 -1
- package/dist/services/state-management/test.state-provider.d.ts +0 -1
- package/dist/services/state-management/test.state-provider.js +2 -1
- package/dist/services/state-management/test.state-provider.js.map +1 -1
- package/dist/services/transaction/transaction.service.d.ts +18 -14
- package/dist/services/transaction/transaction.service.js +261 -132
- package/dist/services/transaction/transaction.service.js.map +1 -1
- package/dist/services/validation/validation.service.d.ts +2 -3
- package/dist/services/validation/validation.service.js +27 -12
- package/dist/services/validation/validation.service.js.map +1 -1
- package/dist/utilities/node/node.utility.d.ts +4 -0
- package/dist/utilities/node/node.utility.js +22 -0
- package/dist/utilities/node/node.utility.js.map +1 -0
- package/dist/utilities/object/object.utility.d.ts +3 -0
- package/dist/utilities/object/object.utility.js +33 -0
- package/dist/utilities/object/object.utility.js.map +1 -1
- package/dist/utilities/test-helpers/test-classes.d.ts +57 -0
- package/dist/utilities/test-helpers/test-classes.js +76 -0
- package/dist/utilities/test-helpers/test-classes.js.map +1 -0
- package/dist/utilities/test-helpers/test-models.d.ts +41 -0
- package/dist/utilities/test-helpers/test-models.js +224 -0
- package/dist/utilities/test-helpers/test-models.js.map +1 -0
- package/dist/utilities/test-helpers/test-overlays.d.ts +10 -0
- package/dist/utilities/test-helpers/test-overlays.js +53 -0
- package/dist/utilities/test-helpers/test-overlays.js.map +1 -0
- package/dist/utilities/test-helpers/test-resources.d.ts +22 -0
- package/dist/utilities/test-helpers/test-resources.js +162 -0
- package/dist/utilities/test-helpers/test-resources.js.map +1 -0
- package/dist/utilities/validation/validation.utility.d.ts +31 -3
- package/dist/utilities/validation/validation.utility.js +121 -2
- package/dist/utilities/validation/validation.utility.js.map +1 -1
- package/package.json +6 -6
- package/dist/decorators/container.js.map +0 -1
- package/dist/decorators/test-container.js.map +0 -1
- package/dist/events/error.event.d.ts +0 -35
- package/dist/events/error.event.js +0 -36
- package/dist/events/error.event.js.map +0 -1
- package/dist/events/hook.event.d.ts +0 -194
- package/dist/events/hook.event.js +0 -195
- package/dist/events/hook.event.js.map +0 -1
- package/dist/models/app/app.interface.d.ts +0 -9
- package/dist/models/app/app.interface.js +0 -2
- package/dist/models/app/app.interface.js.map +0 -1
- package/dist/models/deployment/deployment.interface.d.ts +0 -9
- package/dist/models/deployment/deployment.interface.js +0 -2
- package/dist/models/deployment/deployment.interface.js.map +0 -1
- package/dist/models/environment/environment.interface.d.ts +0 -12
- package/dist/models/environment/environment.interface.js +0 -2
- package/dist/models/environment/environment.interface.js.map +0 -1
- package/dist/models/execution/execution.interface.d.ts +0 -14
- package/dist/models/execution/execution.interface.js +0 -2
- package/dist/models/execution/execution.interface.js.map +0 -1
- package/dist/models/image/image.interface.d.ts +0 -12
- package/dist/models/image/image.interface.js +0 -2
- package/dist/models/image/image.interface.js.map +0 -1
- package/dist/models/pipeline/pipeline.interface.d.ts +0 -10
- package/dist/models/pipeline/pipeline.interface.js +0 -2
- package/dist/models/pipeline/pipeline.interface.js.map +0 -1
- package/dist/models/region/region.interface.d.ts +0 -9
- package/dist/models/region/region.interface.js +0 -2
- package/dist/models/region/region.interface.js.map +0 -1
- package/dist/models/server/server.interface.d.ts +0 -9
- package/dist/models/server/server.interface.js +0 -2
- package/dist/models/server/server.interface.js.map +0 -1
- package/dist/models/service/service.interface.d.ts +0 -9
- package/dist/models/service/service.interface.js +0 -2
- package/dist/models/service/service.interface.js.map +0 -1
- package/dist/models/subnet/subnet.interface.d.ts +0 -13
- package/dist/models/subnet/subnet.interface.js +0 -2
- package/dist/models/subnet/subnet.interface.js.map +0 -1
- package/dist/overlays/overlay.service.d.ts +0 -18
- package/dist/overlays/overlay.service.js +0 -45
- package/dist/overlays/overlay.service.js.map +0 -1
- package/dist/resources/shared-resource.abstract.d.ts +0 -13
- package/dist/resources/shared-resource.abstract.js +0 -47
- package/dist/resources/shared-resource.abstract.js.map +0 -1
|
@@ -1,619 +1,242 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MatchingAnchor, MatchingModel, MatchingResource, NodeType, } from '../app.type.js';
|
|
2
|
+
import { NodeError, SchemaError, ValidationTransactionError } from '../errors/index.js';
|
|
3
|
+
import { Container } from '../functions/container/container.js';
|
|
3
4
|
import { Diff, DiffAction } from '../functions/diff/diff.js';
|
|
4
5
|
import { DiffUtility } from '../functions/diff/diff.utility.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Nodes can have children, and siblings, but only if connected via an edge, called {@link Dependency} here.
|
|
11
|
-
*
|
|
12
|
-
* From this base class, three more base classes are derived,
|
|
13
|
-
* - [Models](/docs/fundamentals/models)
|
|
14
|
-
* - [Resources](/docs/fundamentals/resources)
|
|
15
|
-
* - [Overlays](/docs/fundamentals/overlay-and-anchor)
|
|
16
|
-
*
|
|
17
|
-
* Each of these derived base classes, using the base methods of this class,
|
|
18
|
-
* define their own specific rules on how their graphs should be constructed.
|
|
19
|
-
*/
|
|
20
|
-
export class AModel {
|
|
6
|
+
import { ANode } from '../functions/node/node.abstract.js';
|
|
7
|
+
import { getSchemaInstance } from '../functions/schema/schema.js';
|
|
8
|
+
import { InputService } from '../services/input/input.service.js';
|
|
9
|
+
import { SchemaTranslationService } from '../services/schema-translation/schema-translation.service.js';
|
|
10
|
+
export class AModel extends ANode {
|
|
21
11
|
constructor() {
|
|
22
|
-
|
|
23
|
-
this._deleteMarker = false;
|
|
12
|
+
super(...arguments);
|
|
24
13
|
this.anchors = [];
|
|
25
|
-
this.dependencies = [];
|
|
26
14
|
}
|
|
27
|
-
/**
|
|
28
|
-
* To add an {@link Anchor}.
|
|
29
|
-
*
|
|
30
|
-
* Each node can store multiple anchors for reference.
|
|
31
|
-
* These anchors don't necessarily need to be parented by self, but must be unique,
|
|
32
|
-
* i.e. an anchor, identified by it's parent, cannot be added twice to self's list of anchors.
|
|
33
|
-
*/
|
|
34
15
|
addAnchor(anchor) {
|
|
35
|
-
const existingAnchor =
|
|
36
|
-
|
|
37
|
-
this.
|
|
16
|
+
const existingAnchor = anchor instanceof MatchingAnchor
|
|
17
|
+
? this.getAnchor(anchor.getActual().anchorId, anchor.getActual().getParent())
|
|
18
|
+
: this.getAnchor(anchor.anchorId, anchor.getParent());
|
|
19
|
+
if (existingAnchor) {
|
|
20
|
+
throw new NodeError('Anchor already exists!', this);
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* To add another node as a child of self.
|
|
42
|
-
*
|
|
43
|
-
* Every node must have a unique ID against other nodes of the same {@link MODEL_NAME}.
|
|
44
|
-
* This ID is how Octo differentiates similar nodes, and keeps track of them.
|
|
45
|
-
* But because each node is free to define their own fields,
|
|
46
|
-
* the fields containing the ID are a necessary input to this method.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const region = new Region('region');
|
|
51
|
-
* const environment = new Environment('qa');
|
|
52
|
-
* region.addChild('regionId', environment, 'environmentName');
|
|
53
|
-
* ```
|
|
54
|
-
* @param onField The field in self which contains the unique ID.
|
|
55
|
-
* @param child The child node.
|
|
56
|
-
* @param toField The field in child which contains the unique ID.
|
|
57
|
-
* @returns
|
|
58
|
-
* - childToParentDependency: The dependency edge from child to self.
|
|
59
|
-
* - parentToChildDependency: The dependency edge from self to child.
|
|
60
|
-
*/
|
|
61
|
-
addChild(onField, child, toField) {
|
|
62
|
-
const cIndex = child.dependencies.findIndex((d) => Object.is(d.to, this));
|
|
63
|
-
const pIndex = this.dependencies.findIndex((d) => Object.is(d.to, child));
|
|
64
|
-
if (cIndex !== -1 || pIndex !== -1) {
|
|
65
|
-
throw new Error('Dependency relationship already exists!');
|
|
22
|
+
else {
|
|
23
|
+
this.anchors.push(anchor);
|
|
66
24
|
}
|
|
67
|
-
const childToParentDependency = new Dependency(child, this);
|
|
68
|
-
childToParentDependency.addBehavior(toField, DiffAction.ADD, onField, DiffAction.ADD);
|
|
69
|
-
childToParentDependency.addBehavior(toField, DiffAction.ADD, onField, DiffAction.UPDATE);
|
|
70
|
-
childToParentDependency.addChildRelationship(toField, onField);
|
|
71
|
-
child.dependencies.push(childToParentDependency);
|
|
72
|
-
const parentToChildDependency = new Dependency(this, child);
|
|
73
|
-
parentToChildDependency.addBehavior(onField, DiffAction.DELETE, toField, DiffAction.DELETE);
|
|
74
|
-
parentToChildDependency.addParentRelationship(onField, toField);
|
|
75
|
-
this.dependencies.push(parentToChildDependency);
|
|
76
|
-
return { childToParentDependency, parentToChildDependency };
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* To add another node as a sibling of self.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* const region1 = new Region('region-1');
|
|
84
|
-
* const region2 = new Region('region-2');
|
|
85
|
-
* region1.addSibling(region2);
|
|
86
|
-
* ```
|
|
87
|
-
* @param to The sibling node.
|
|
88
|
-
* @returns
|
|
89
|
-
* - thatToThisDependency: The dependency edge from sibling to self.
|
|
90
|
-
* - thisToThatDependency: The dependency edge from self to sibling.
|
|
91
|
-
*/
|
|
92
|
-
addRelationship(to) {
|
|
93
|
-
const thisToThatDependency = new Dependency(this, to);
|
|
94
|
-
this.dependencies.push(thisToThatDependency);
|
|
95
|
-
const thatToThisDependency = new Dependency(to, this);
|
|
96
|
-
to.dependencies.push(thatToThisDependency);
|
|
97
|
-
return { thatToThisDependency, thisToThatDependency };
|
|
98
25
|
}
|
|
99
|
-
/**
|
|
100
|
-
* To derive the name of the field in self which contains the ID.
|
|
101
|
-
*
|
|
102
|
-
* @remarks This method does a best attempt search of the field name by traversing all dependencies of self.
|
|
103
|
-
* But if the dependencies lack, or have not been added yet, this method might return `undefined`.
|
|
104
|
-
* That does not mean that such a field does not exist,
|
|
105
|
-
* but rather that it wasn't possible to derive the name at that point.
|
|
106
|
-
* @returns The name of the field in self which contains the ID, or `undefined` if not found.
|
|
107
|
-
*/
|
|
108
26
|
deriveDependencyField() {
|
|
109
|
-
|
|
27
|
+
if (this.getDependencies().length === 0 && this.constructor.NODE_NAME === 'app') {
|
|
28
|
+
return 'name';
|
|
29
|
+
}
|
|
30
|
+
else if (this.constructor.NODE_TYPE === NodeType.OVERLAY) {
|
|
31
|
+
return 'overlayId';
|
|
32
|
+
}
|
|
33
|
+
return this.getDependencies()
|
|
34
|
+
.find((d) => d.getRelationship() !== undefined)
|
|
35
|
+
?.getRelationship().onField;
|
|
110
36
|
}
|
|
111
|
-
|
|
112
|
-
* Compares and calculates the difference between the current version of self node, and the previous version.
|
|
113
|
-
* - Recursively compares self children too.
|
|
114
|
-
*
|
|
115
|
-
* @param previous The previous version of self.
|
|
116
|
-
*/
|
|
117
|
-
async diff(previous) {
|
|
37
|
+
async diff() {
|
|
118
38
|
const diffs = [];
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (const modelName of Object.keys(previousChildrenByModels)) {
|
|
123
|
-
const previousChildren = previousChildrenByModels[modelName].map((d) => d.to);
|
|
124
|
-
const currentChildren = currentChildrenByModels[modelName]?.map((d) => d.to) || [];
|
|
125
|
-
const field = previousChildrenByModels[modelName][0].getRelationship().toField;
|
|
126
|
-
const childrenDiffs = await DiffUtility.diffModels(previousChildren, currentChildren, field);
|
|
127
|
-
diffs.push(...childrenDiffs);
|
|
39
|
+
const field = this.deriveDependencyField();
|
|
40
|
+
if (!field) {
|
|
41
|
+
throw new NodeError('Cannot derive dependency field!', this);
|
|
128
42
|
}
|
|
129
|
-
|
|
43
|
+
const currentChildrenByModels = this.getChildren();
|
|
130
44
|
for (const modelName of Object.keys(currentChildrenByModels)) {
|
|
131
|
-
if (previousChildrenByModels.hasOwnProperty(modelName)) {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
45
|
const previousChildren = [];
|
|
135
46
|
const currentChildren = currentChildrenByModels[modelName].map((d) => d.to);
|
|
136
47
|
const field = currentChildrenByModels[modelName][0].getRelationship().toField;
|
|
137
|
-
const childrenDiffs = await DiffUtility.
|
|
48
|
+
const childrenDiffs = await DiffUtility.diffNodes(previousChildren, currentChildren, field);
|
|
138
49
|
diffs.push(...childrenDiffs);
|
|
139
50
|
}
|
|
140
|
-
const previousSiblingsByModels = previous?.getSiblings() ?? {};
|
|
141
51
|
const currentSiblingsByModels = this.getSiblings();
|
|
142
|
-
// Compare previous siblings with current siblings.
|
|
143
|
-
for (const modelName of Object.keys(previousSiblingsByModels)) {
|
|
144
|
-
const previousSiblings = previousSiblingsByModels[modelName];
|
|
145
|
-
const currentSiblings = currentSiblingsByModels[modelName] || [];
|
|
146
|
-
for (const pd of previousSiblings) {
|
|
147
|
-
// Skip OVERLAY sibling, since overlays are diffed separately.
|
|
148
|
-
if (pd.to.MODEL_TYPE === ModelType.OVERLAY) {
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (!currentSiblings.find((cd) => cd.to.getContext() === pd.to.getContext())) {
|
|
152
|
-
diffs.push(new Diff(this, DiffAction.DELETE, 'sibling', pd.to));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
for (const cd of currentSiblings) {
|
|
156
|
-
// Skip OVERLAY sibling, since overlays are diffed separately.
|
|
157
|
-
if (cd.to.MODEL_TYPE === ModelType.OVERLAY) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (!previousSiblings.find((pd) => pd.to.getContext() === cd.to.getContext())) {
|
|
161
|
-
diffs.push(new Diff(this, DiffAction.ADD, 'sibling', cd.to));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Add new siblings not in previous.
|
|
166
52
|
for (const modelName of Object.keys(currentSiblingsByModels)) {
|
|
167
|
-
if (previousSiblingsByModels.hasOwnProperty(modelName)) {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
53
|
const currentSiblings = currentSiblingsByModels[modelName];
|
|
171
54
|
for (const cd of currentSiblings) {
|
|
172
55
|
// Skip OVERLAY sibling, since overlays are diffed separately.
|
|
173
|
-
if (cd.to.
|
|
56
|
+
if (cd.to.constructor.NODE_TYPE === NodeType.OVERLAY) {
|
|
174
57
|
continue;
|
|
175
58
|
}
|
|
176
59
|
diffs.push(new Diff(this, DiffAction.ADD, 'sibling', cd.to));
|
|
177
60
|
}
|
|
178
61
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
else if (!previous) {
|
|
185
|
-
diffs.push(new Diff(this, DiffAction.ADD, field, fieldValue));
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
const pDiffs = await this.diffProperties(previous);
|
|
189
|
-
diffs.push(...pDiffs);
|
|
190
|
-
}
|
|
62
|
+
// Add model.
|
|
63
|
+
diffs.push(new Diff(this, DiffAction.ADD, field, this[field]));
|
|
64
|
+
// Diff model properties.
|
|
65
|
+
const propertyDiffs = await this.diffProperties();
|
|
66
|
+
diffs.push(...propertyDiffs);
|
|
191
67
|
return diffs;
|
|
192
68
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
* - Includes parent nodes.
|
|
196
|
-
* - Might include sibling nodes, if they are necessary for self node to exist.
|
|
197
|
-
*/
|
|
198
|
-
getAncestors() {
|
|
199
|
-
const members = [this];
|
|
200
|
-
const membersProcessed = [];
|
|
201
|
-
while (members.length > 0) {
|
|
202
|
-
const member = members.pop();
|
|
203
|
-
// Skip processing an already processed member.
|
|
204
|
-
if (membersProcessed.some((m) => m.getContext() === member.getContext())) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
for (const d of member.dependencies) {
|
|
208
|
-
// If in dependency I am not declared a parent, then d.to is either my parent or has a relationship to me.
|
|
209
|
-
// The behavior of that relationship should be that it must exist for me to exist.
|
|
210
|
-
if (!d.isParentRelationship() &&
|
|
211
|
-
d.hasMatchingBehavior(undefined, DiffAction.ADD, undefined, DiffAction.ADD) &&
|
|
212
|
-
!membersProcessed.some((m) => m.getContext() === d.to.getContext())) {
|
|
213
|
-
members.push(d.to);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
membersProcessed.push(member);
|
|
217
|
-
}
|
|
218
|
-
return membersProcessed;
|
|
69
|
+
async diffProperties() {
|
|
70
|
+
return [];
|
|
219
71
|
}
|
|
220
|
-
/**
|
|
221
|
-
* To get an anchor with a given ID and parent.
|
|
222
|
-
*
|
|
223
|
-
* @param anchorId The ID of the anchor.
|
|
224
|
-
* @param parent The parent of the anchor.
|
|
225
|
-
* - If parent is not given, then self is considered the parent of this anchor.
|
|
226
|
-
*/
|
|
227
72
|
getAnchor(anchorId, parent) {
|
|
228
73
|
const index = this.getAnchorIndex(anchorId, parent);
|
|
229
|
-
|
|
74
|
+
if (index === -1) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const anchor = this.anchors[index];
|
|
78
|
+
if (anchor instanceof MatchingAnchor) {
|
|
79
|
+
return anchor.getActual();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return anchor;
|
|
83
|
+
}
|
|
230
84
|
}
|
|
231
|
-
/**
|
|
232
|
-
* To get the index of an anchor with a given ID and parent.
|
|
233
|
-
*
|
|
234
|
-
* @param anchorId The ID of the anchor.
|
|
235
|
-
* @param parent The parent of the anchor.
|
|
236
|
-
* - If parent is not given, then self is considered the parent of this anchor.
|
|
237
|
-
*/
|
|
238
85
|
getAnchorIndex(anchorId, parent) {
|
|
239
|
-
return this.anchors.findIndex((a) =>
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
86
|
+
return this.anchors.findIndex((a) => {
|
|
87
|
+
if (a instanceof MatchingAnchor) {
|
|
88
|
+
return (a.getActual().anchorId === anchorId &&
|
|
89
|
+
a.getActual().getParent().getContext() === (parent || this).getContext());
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return a.anchorId === anchorId && a.getParent().getContext() === (parent || this).getContext();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
248
95
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
96
|
+
getAnchors(filters = [], types = []) {
|
|
97
|
+
return this.anchors
|
|
98
|
+
.filter((a) => !types.length || types.some((t) => a instanceof t))
|
|
99
|
+
.filter((a) => filters.every((c) => {
|
|
100
|
+
if (a instanceof MatchingAnchor) {
|
|
101
|
+
return a.getSchemaInstance().properties[c.key] === c.value;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return a.properties[c.key] === c.value;
|
|
105
|
+
}
|
|
106
|
+
}))
|
|
107
|
+
.map((a) => (a instanceof MatchingAnchor ? a.getActual() : a));
|
|
108
|
+
}
|
|
109
|
+
async getAnchorsMatchingSchema(from, propertyFilters = [], { searchBoundaryMembers = true } = {}) {
|
|
110
|
+
const matches = [];
|
|
111
|
+
const container = Container.getInstance();
|
|
112
|
+
const schemaTranslationService = await container.get(SchemaTranslationService);
|
|
113
|
+
const translatedSchema = schemaTranslationService.getTranslatedSchema(from);
|
|
114
|
+
if (translatedSchema) {
|
|
115
|
+
from = translatedSchema.schema;
|
|
116
|
+
}
|
|
117
|
+
const boundaryMembers = searchBoundaryMembers ? this.getBoundaryMembers() : [this];
|
|
118
|
+
const anchors = boundaryMembers.map((m) => m.getAnchors()).flat();
|
|
119
|
+
while (anchors.length > 0) {
|
|
120
|
+
const anchor = anchors.shift();
|
|
121
|
+
try {
|
|
122
|
+
const schemaInstance = getSchemaInstance(from, anchor.synth());
|
|
123
|
+
const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : anchor.synth());
|
|
124
|
+
if (propertyFilters.every((f) => matchingSchemaInstance.properties[f.key] === f.value)) {
|
|
125
|
+
matches.push([anchor, translatedSchema ? translatedSchema.translator : undefined]);
|
|
263
126
|
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const ancestors = model.getAncestors();
|
|
269
|
-
for (const ancestor of ancestors) {
|
|
270
|
-
// Skip processing an already processed ancestor.
|
|
271
|
-
if (members.some((m) => m.getContext() === ancestor.getContext())) {
|
|
272
|
-
continue;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
|
|
130
|
+
throw error;
|
|
273
131
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const context = toProcess.pop();
|
|
295
|
-
if (seen[context]) {
|
|
296
|
-
throw new Error('Found circular dependencies!');
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
seen[context] = true;
|
|
300
|
-
}
|
|
301
|
-
toProcess.push(...(parentOf[context] || []));
|
|
302
|
-
}
|
|
303
|
-
if (!parentOf[childContext]) {
|
|
304
|
-
parentOf[childContext] = [];
|
|
305
|
-
parentOf[childContext].push(parentContext);
|
|
306
|
-
}
|
|
307
|
-
else if (!parentOf[childContext].some((p) => p === parentContext)) {
|
|
308
|
-
parentOf[childContext].push(parentContext);
|
|
309
|
-
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return matches.map((m) => new MatchingAnchor(m[0], m[1]));
|
|
135
|
+
}
|
|
136
|
+
async getModelsMatchingSchema(schema, filters = [], { searchBoundaryMembers = true } = {}) {
|
|
137
|
+
const matches = [];
|
|
138
|
+
const container = Container.getInstance();
|
|
139
|
+
const schemaTranslationService = await container.get(SchemaTranslationService);
|
|
140
|
+
const translatedSchema = schemaTranslationService.getTranslatedSchema(schema);
|
|
141
|
+
if (translatedSchema) {
|
|
142
|
+
schema = translatedSchema.schema;
|
|
143
|
+
}
|
|
144
|
+
const models = searchBoundaryMembers ? this.getBoundaryMembers() : [this];
|
|
145
|
+
while (models.length > 0) {
|
|
146
|
+
const model = models.shift();
|
|
147
|
+
try {
|
|
148
|
+
const schemaInstance = getSchemaInstance(schema, model.synth());
|
|
149
|
+
const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : model.synth());
|
|
150
|
+
if (filters.every((f) => matchingSchemaInstance[f.key] === f.value)) {
|
|
151
|
+
matches.push([model, translatedSchema ? translatedSchema.translator : undefined]);
|
|
310
152
|
}
|
|
311
153
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
315
158
|
}
|
|
316
|
-
const dependents = model.dependencies
|
|
317
|
-
.filter((d) => !d.isParentRelationship() && !d.isChildRelationship())
|
|
318
|
-
.map((d) => d.to);
|
|
319
|
-
pushToExtenders(dependents);
|
|
320
159
|
}
|
|
321
|
-
return
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
* const environments = children['environment'].map((d) => d.to);
|
|
348
|
-
* ```
|
|
349
|
-
* @param modelName The {@link MODEL_NAME} of the children.
|
|
350
|
-
* @returns All children as an object with the {@link MODEL_NAME} as the key,
|
|
351
|
-
* and self's dependency to the child as the value.
|
|
352
|
-
*/
|
|
353
|
-
getChildren(modelName) {
|
|
354
|
-
return this.dependencies
|
|
355
|
-
.filter((d) => d.isParentRelationship() && (modelName ? d.to.MODEL_NAME === modelName : true))
|
|
356
|
-
.reduce((accumulator, currentValue) => {
|
|
357
|
-
if (!(currentValue.to.MODEL_NAME in accumulator)) {
|
|
358
|
-
accumulator[currentValue.to.MODEL_NAME] = [];
|
|
160
|
+
return matches.map((m) => new MatchingModel(m[0], m[1]));
|
|
161
|
+
}
|
|
162
|
+
async getOverlaysMatchingSchema(schema, propertyFilters = [], { searchBoundaryMembers = true } = {}) {
|
|
163
|
+
const matches = [];
|
|
164
|
+
const container = Container.getInstance();
|
|
165
|
+
const schemaTranslationService = await container.get(SchemaTranslationService);
|
|
166
|
+
const translatedSchema = schemaTranslationService.getTranslatedSchema(schema);
|
|
167
|
+
if (translatedSchema) {
|
|
168
|
+
schema = translatedSchema.schema;
|
|
169
|
+
}
|
|
170
|
+
const overlays = searchBoundaryMembers
|
|
171
|
+
? this.getBoundaryMembers().filter((m) => m.constructor.NODE_TYPE === NodeType.OVERLAY)
|
|
172
|
+
: [this];
|
|
173
|
+
while (overlays.length > 0) {
|
|
174
|
+
const overlay = overlays.shift();
|
|
175
|
+
try {
|
|
176
|
+
const schemaInstance = getSchemaInstance(schema, overlay.synth());
|
|
177
|
+
const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : overlay.synth());
|
|
178
|
+
if (propertyFilters.every((f) => matchingSchemaInstance.properties[f.key] === f.value)) {
|
|
179
|
+
matches.push([overlay, translatedSchema ? translatedSchema.translator : undefined]);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
359
186
|
}
|
|
360
|
-
accumulator[currentValue.to.MODEL_NAME].push(currentValue);
|
|
361
|
-
return accumulator;
|
|
362
|
-
}, {});
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* To get the context of self.
|
|
366
|
-
* A context is a string representation of self that uniquely identifies self in the graph.
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* ```ts
|
|
370
|
-
* const app = new App('my-app');
|
|
371
|
-
* const region = new Region('my-region');
|
|
372
|
-
* app.addRegion(region);
|
|
373
|
-
* const context = region.getContext(); // "region=my-region,app=my-app"
|
|
374
|
-
* ```
|
|
375
|
-
*/
|
|
376
|
-
getContext() {
|
|
377
|
-
if (!this.context) {
|
|
378
|
-
this.context = this.setContext();
|
|
379
|
-
}
|
|
380
|
-
return this.context;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* To get all dependencies of self.
|
|
384
|
-
* - Can be filtered to just dependencies with a single node.
|
|
385
|
-
*
|
|
386
|
-
* @param to The other node. If present, will only return dependencies of self with this node.
|
|
387
|
-
*/
|
|
388
|
-
getDependencies(to) {
|
|
389
|
-
const filters = [];
|
|
390
|
-
if (to) {
|
|
391
|
-
filters.push({ key: 'to', value: to.getContext() });
|
|
392
187
|
}
|
|
393
|
-
return
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
188
|
+
return matches.map((m) => new MatchingModel(m[0], m[1]));
|
|
189
|
+
}
|
|
190
|
+
async getResourcesMatchingSchema(schema, propertyFilters = [], responseFilters = [], { searchBoundaryMembers = true } = {}) {
|
|
191
|
+
const matches = [];
|
|
192
|
+
const container = Container.getInstance();
|
|
193
|
+
const [inputService, schemaTranslationService] = await Promise.all([
|
|
194
|
+
container.get(InputService),
|
|
195
|
+
container.get(SchemaTranslationService),
|
|
196
|
+
]);
|
|
197
|
+
const translatedSchema = schemaTranslationService.getTranslatedSchema(schema);
|
|
198
|
+
if (translatedSchema) {
|
|
199
|
+
schema = translatedSchema.schema;
|
|
200
|
+
}
|
|
201
|
+
const models = searchBoundaryMembers ? this.getBoundaryMembers() : [this];
|
|
202
|
+
while (models.length > 0) {
|
|
203
|
+
const model = models.shift();
|
|
204
|
+
const moduleId = model.constructor.NODE_TYPE === NodeType.OVERLAY
|
|
205
|
+
? inputService.getModuleIdFromOverlay(model)
|
|
206
|
+
: inputService.getModuleIdFromModel(model);
|
|
207
|
+
const moduleResources = inputService.getModuleResources(moduleId);
|
|
208
|
+
for (const r of moduleResources) {
|
|
209
|
+
try {
|
|
210
|
+
const schemaInstance = getSchemaInstance(schema, r.synth());
|
|
211
|
+
const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : r.synth());
|
|
212
|
+
if (propertyFilters.every((f) => matchingSchemaInstance.properties[f.key] === f.value) &&
|
|
213
|
+
responseFilters.every((f) => matchingSchemaInstance.response[f.key] === f.value)) {
|
|
214
|
+
matches.push([r, translatedSchema ? translatedSchema.translator : undefined]);
|
|
215
|
+
}
|
|
397
216
|
}
|
|
398
|
-
|
|
399
|
-
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
400
221
|
}
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* To get a dependency of self with another node.
|
|
406
|
-
*
|
|
407
|
-
* @param to The other node.
|
|
408
|
-
* @param relationship The relationship between self and the other node.
|
|
409
|
-
* @returns The dependency with the other node having the given relationship, or `undefined` if not found.
|
|
410
|
-
*/
|
|
411
|
-
getDependency(to, relationship) {
|
|
412
|
-
const index = this.getDependencyIndex(to, relationship);
|
|
413
|
-
return index > -1 ? this.dependencies[index] : undefined;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* To get the index of a dependency of self with another node.
|
|
417
|
-
*
|
|
418
|
-
* @param to The other node.
|
|
419
|
-
* @param relationship The relationship between self and the other node.
|
|
420
|
-
* @returns The index of the dependency with the other node having the given relationship, or `-1` if not found.
|
|
421
|
-
*/
|
|
422
|
-
getDependencyIndex(to, relationship) {
|
|
423
|
-
return this.dependencies.findIndex((d) => d.from.getContext() === this.getContext() &&
|
|
424
|
-
d.to.getContext() === to.getContext() &&
|
|
425
|
-
d.getRelationship() !== undefined &&
|
|
426
|
-
d.getRelationship().type === relationship);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* To get all parent of self.
|
|
430
|
-
*
|
|
431
|
-
* @example
|
|
432
|
-
* ```ts
|
|
433
|
-
* const parents = environment.getParents('region');
|
|
434
|
-
* const regions = parents['region'].map((d) => d.to);
|
|
435
|
-
* ```
|
|
436
|
-
* @param modelName The {@link MODEL_NAME} of the parent.
|
|
437
|
-
* @returns All parents as an object with the {@link MODEL_NAME} as the key,
|
|
438
|
-
* and self's dependency to the parent as the value.
|
|
439
|
-
*/
|
|
440
|
-
getParents(modelName) {
|
|
441
|
-
return this.dependencies
|
|
442
|
-
.filter((d) => d.isChildRelationship() && (modelName ? d.to.MODEL_NAME === modelName : true))
|
|
443
|
-
.reduce((accumulator, currentValue) => {
|
|
444
|
-
if (!(currentValue.to.MODEL_NAME in accumulator)) {
|
|
445
|
-
accumulator[currentValue.to.MODEL_NAME] = [];
|
|
446
222
|
}
|
|
447
|
-
accumulator[currentValue.to.MODEL_NAME].push(currentValue);
|
|
448
|
-
return accumulator;
|
|
449
|
-
}, {});
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* To get all siblings of self.
|
|
453
|
-
*
|
|
454
|
-
* :::note Note
|
|
455
|
-
* Two environments, or two regions, etc. are not automatically considered siblings,
|
|
456
|
-
* unless they have a dependency between them.
|
|
457
|
-
*
|
|
458
|
-
* ```ts
|
|
459
|
-
* const environment1 = new Environment('qa');
|
|
460
|
-
* const environment2 = new Environment('prod');
|
|
461
|
-
* const region = new Region('region');
|
|
462
|
-
* region.addEnvironment(environment1);
|
|
463
|
-
* region.addEnvironment(environment2);
|
|
464
|
-
* environment1.getSiblings('environment'); // This won't return a dependency to environment2.
|
|
465
|
-
* ```
|
|
466
|
-
* :::
|
|
467
|
-
*
|
|
468
|
-
* @example
|
|
469
|
-
* ```ts
|
|
470
|
-
* const siblings = environment.getSiblings('image');
|
|
471
|
-
* const images = siblings['image'].map((d) => d.to);
|
|
472
|
-
* ```
|
|
473
|
-
* @param modelName The {@link MODEL_NAME} of the sibling.
|
|
474
|
-
* @returns All siblings as an object with the {@link MODEL_NAME} as the key,
|
|
475
|
-
* and self's dependency to the sibling as the value.
|
|
476
|
-
*/
|
|
477
|
-
getSiblings(modelName) {
|
|
478
|
-
return this.dependencies
|
|
479
|
-
.filter((d) => !d.isChildRelationship() && !d.isParentRelationship() && (modelName ? d.to.MODEL_NAME === modelName : true))
|
|
480
|
-
.reduce((accumulator, currentValue) => {
|
|
481
|
-
if (!(currentValue.to.MODEL_NAME in accumulator)) {
|
|
482
|
-
accumulator[currentValue.to.MODEL_NAME] = [];
|
|
483
|
-
}
|
|
484
|
-
accumulator[currentValue.to.MODEL_NAME].push(currentValue);
|
|
485
|
-
return accumulator;
|
|
486
|
-
}, {});
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* To check if given node is an ancestor of self.
|
|
490
|
-
*
|
|
491
|
-
* @param model The other node.
|
|
492
|
-
*/
|
|
493
|
-
hasAncestor(model) {
|
|
494
|
-
const modelParts = model
|
|
495
|
-
.getContext()
|
|
496
|
-
.split(',')
|
|
497
|
-
.map((p) => p.split('='));
|
|
498
|
-
const ancestors = this.getAncestors();
|
|
499
|
-
return ancestors.some((a) => {
|
|
500
|
-
const ancestorParts = a
|
|
501
|
-
.getContext()
|
|
502
|
-
.split(',')
|
|
503
|
-
.reduce((map, p) => {
|
|
504
|
-
const parts = p.split('=');
|
|
505
|
-
map[parts[0]] = parts[1];
|
|
506
|
-
return map;
|
|
507
|
-
}, {});
|
|
508
|
-
return modelParts.every((p) => ancestorParts[p[0]] === p[1]);
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* To check if self is marked as deleted.
|
|
513
|
-
* A deleted node will be removed from the graph after the transaction.
|
|
514
|
-
*/
|
|
515
|
-
isMarkedDeleted() {
|
|
516
|
-
return this._deleteMarker;
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* To mark self as deleted.
|
|
520
|
-
* A deleted node will be removed from the graph after the transaction.
|
|
521
|
-
* - A node cannot be deleted if it has dependencies.
|
|
522
|
-
* - Unless the dependency is a sibling dependency and `ignoreDirectRelationships` is `true`.
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* ```ts
|
|
526
|
-
* const region1 = new Region('region-1');
|
|
527
|
-
* const environment = new Environment('environment');
|
|
528
|
-
* region1.addEnvironment(environment);
|
|
529
|
-
* const region2 = new Region('region-2');
|
|
530
|
-
* region1.addSibling(region2);
|
|
531
|
-
*
|
|
532
|
-
* // Cannot remove region1 because it has dependencies.
|
|
533
|
-
* region1.remove(); // throws.
|
|
534
|
-
*
|
|
535
|
-
* // Still can't remove region1 because it has a sibling dependency.
|
|
536
|
-
* environment.remove(); // ok.
|
|
537
|
-
* region1.remove(); // throws.
|
|
538
|
-
*
|
|
539
|
-
* // But can remove region1 when sibling relationships are ignored.
|
|
540
|
-
* region1.remove(true); // ok.
|
|
541
|
-
* ```
|
|
542
|
-
* @param ignoreDirectRelationships Whether to ignore sibling relationships.
|
|
543
|
-
* @throws {@link Error} If node contains dependencies to other nodes.
|
|
544
|
-
*/
|
|
545
|
-
remove(ignoreDirectRelationships = false) {
|
|
546
|
-
// Verify model can be removed.
|
|
547
|
-
for (const dependency of this.dependencies) {
|
|
548
|
-
// When direct relationship is not ignored, this model can't be a parent or have direct relationships.
|
|
549
|
-
// When direct relationship is ignored, this model can't be a parent.
|
|
550
|
-
if ((!ignoreDirectRelationships && !dependency.isChildRelationship()) ||
|
|
551
|
-
(ignoreDirectRelationships && dependency.isParentRelationship())) {
|
|
552
|
-
throw new Error('Cannot remove model until dependent models exist!');
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
// Removing all dependencies that points to this.
|
|
556
|
-
for (const dependency of this.dependencies) {
|
|
557
|
-
const index = dependency.to.dependencies.findIndex((d) => d.to.getContext() === this.getContext());
|
|
558
|
-
dependency.to.dependencies.splice(index, 1);
|
|
559
223
|
}
|
|
560
|
-
|
|
224
|
+
return matches.map((m) => new MatchingResource(m[0], m[1]));
|
|
561
225
|
}
|
|
562
|
-
/**
|
|
563
|
-
* To remove all anchors from self.
|
|
564
|
-
*/
|
|
565
226
|
removeAllAnchors() {
|
|
566
|
-
|
|
227
|
+
const anchors = this.getAnchors();
|
|
567
228
|
while (anchors.length > 0) {
|
|
568
|
-
this.removeAnchor(anchors
|
|
569
|
-
anchors = this.getAnchors();
|
|
229
|
+
this.removeAnchor(anchors.shift());
|
|
570
230
|
}
|
|
571
231
|
}
|
|
572
|
-
/**
|
|
573
|
-
* To remove an anchor from self.
|
|
574
|
-
*
|
|
575
|
-
* @param anchor The anchor to remove.
|
|
576
|
-
*/
|
|
577
232
|
removeAnchor(anchor) {
|
|
578
|
-
const existingAnchorIndex =
|
|
233
|
+
const existingAnchorIndex = anchor instanceof MatchingAnchor
|
|
234
|
+
? this.getAnchorIndex(anchor.getActual().anchorId, anchor.getActual().getParent())
|
|
235
|
+
: this.getAnchorIndex(anchor.anchorId, anchor.getParent());
|
|
579
236
|
if (existingAnchorIndex !== -1) {
|
|
580
237
|
this.anchors.splice(existingAnchorIndex, 1);
|
|
581
238
|
}
|
|
582
239
|
}
|
|
583
|
-
/**
|
|
584
|
-
* To remove a dependency from self.
|
|
585
|
-
*
|
|
586
|
-
* @param dependencyIndex The index of the dependency to remove.
|
|
587
|
-
*/
|
|
588
|
-
removeDependency(dependencyIndex) {
|
|
589
|
-
if (dependencyIndex > -1 && dependencyIndex < this.dependencies.length) {
|
|
590
|
-
this.dependencies.splice(dependencyIndex, 1);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* To remove ALL dependencies from self for the given node.
|
|
595
|
-
*
|
|
596
|
-
* @param model The other node.
|
|
597
|
-
*/
|
|
598
|
-
removeRelationship(model) {
|
|
599
|
-
for (let i = this.dependencies.length - 1; i >= 0; i--) {
|
|
600
|
-
const dependency = this.dependencies[i];
|
|
601
|
-
if (dependency.to.getContext() === model.getContext()) {
|
|
602
|
-
this.dependencies.splice(i, 1);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
for (let i = model.dependencies.length - 1; i >= 0; i--) {
|
|
606
|
-
const dependency = model.dependencies[i];
|
|
607
|
-
if (dependency.to.getContext() === this.getContext()) {
|
|
608
|
-
model.dependencies.splice(i, 1);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* To create self given its serialized representation.
|
|
614
|
-
* - First argument is the serialized representation.
|
|
615
|
-
* - Second argument is the `deReferenceContext()` function to resolve other nodes self depends on.
|
|
616
|
-
*/
|
|
617
240
|
static async unSynth(...args) {
|
|
618
241
|
if (args.length > 4) {
|
|
619
242
|
throw new Error('Too many args in unSynth()');
|