@quadnix/octo 0.0.29 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +25 -3
- package/dist/app.type.d.ts +143 -4
- package/dist/app.type.js +80 -9
- package/dist/app.type.js.map +1 -1
- package/dist/decorators/action.decorator.d.ts +10 -6
- package/dist/decorators/action.decorator.js +19 -6
- package/dist/decorators/action.decorator.js.map +1 -1
- package/dist/decorators/anchor.decorator.d.ts +12 -5
- package/dist/decorators/anchor.decorator.js +12 -5
- package/dist/decorators/anchor.decorator.js.map +1 -1
- package/dist/decorators/enable-hook.decorator.d.ts +1 -1
- package/dist/decorators/enable-hook.decorator.js +1 -1
- package/dist/decorators/factory.decorator.d.ts +18 -34
- package/dist/decorators/factory.decorator.js +18 -34
- package/dist/decorators/factory.decorator.js.map +1 -1
- package/dist/decorators/model.decorator.d.ts +1 -1
- package/dist/decorators/model.decorator.js +1 -1
- package/dist/decorators/module.decorator.d.ts +16 -10
- package/dist/decorators/module.decorator.js +16 -10
- package/dist/decorators/module.decorator.js.map +1 -1
- package/dist/decorators/on-event.decorator.d.ts +5 -0
- package/dist/decorators/on-event.decorator.js +5 -0
- package/dist/decorators/on-event.decorator.js.map +1 -1
- package/dist/decorators/validate.decorator.d.ts +15 -1
- package/dist/decorators/validate.decorator.js +15 -1
- package/dist/decorators/validate.decorator.js.map +1 -1
- package/dist/errors/container.error.d.ts +18 -0
- package/dist/errors/container.error.js +18 -0
- package/dist/errors/container.error.js.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/module.error.d.ts +6 -0
- package/dist/errors/module.error.js +6 -0
- package/dist/errors/module.error.js.map +1 -1
- package/dist/errors/node.error.d.ts +56 -0
- package/dist/errors/node.error.js +56 -0
- package/dist/errors/node.error.js.map +1 -1
- package/dist/errors/schema.error.d.ts +6 -0
- package/dist/errors/schema.error.js +6 -0
- package/dist/errors/schema.error.js.map +1 -1
- package/dist/errors/terraform.error.d.ts +19 -0
- package/dist/errors/terraform.error.js +23 -0
- package/dist/errors/terraform.error.js.map +1 -0
- package/dist/errors/transaction.error.d.ts +77 -0
- package/dist/errors/transaction.error.js +83 -0
- package/dist/errors/transaction.error.js.map +1 -1
- package/dist/events/action.event.d.ts +0 -2
- package/dist/events/action.event.js +0 -2
- package/dist/events/action.event.js.map +1 -1
- package/dist/events/event.model.d.ts +21 -5
- package/dist/events/event.model.js +11 -5
- package/dist/events/event.model.js.map +1 -1
- package/dist/events/hook/commit.hook.event.d.ts +0 -6
- package/dist/events/hook/commit.hook.event.js +0 -6
- package/dist/events/hook/commit.hook.event.js.map +1 -1
- package/dist/events/hook/hook.event.d.ts +0 -2
- package/dist/events/hook/hook.event.js +0 -2
- package/dist/events/hook/hook.event.js.map +1 -1
- package/dist/events/hook/model.hook.event.d.ts +0 -6
- package/dist/events/hook/model.hook.event.js +0 -6
- package/dist/events/hook/model.hook.event.js.map +1 -1
- package/dist/events/hook/resource.hook.event.d.ts +0 -6
- package/dist/events/hook/resource.hook.event.js +0 -6
- package/dist/events/hook/resource.hook.event.js.map +1 -1
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -1
- package/dist/events/mode-result.event.d.ts +57 -0
- package/dist/events/mode-result.event.js +24 -0
- package/dist/events/mode-result.event.js.map +1 -0
- package/dist/events/mode.event.d.ts +57 -0
- package/dist/events/mode.event.js +32 -0
- package/dist/events/mode.event.js.map +1 -0
- package/dist/events/module.event.d.ts +0 -2
- package/dist/events/module.event.js +0 -2
- package/dist/events/module.event.js.map +1 -1
- package/dist/events/registration.event.d.ts +18 -14
- package/dist/events/registration.event.js +18 -14
- package/dist/events/registration.event.js.map +1 -1
- package/dist/events/serialization.event.d.ts +15 -12
- package/dist/events/serialization.event.js +15 -12
- package/dist/events/serialization.event.js.map +1 -1
- package/dist/events/terraform.event.d.ts +42 -0
- package/dist/events/terraform.event.js +31 -0
- package/dist/events/terraform.event.js.map +1 -0
- package/dist/events/transaction.event.d.ts +0 -37
- package/dist/events/transaction.event.js +0 -28
- package/dist/events/transaction.event.js.map +1 -1
- package/dist/functions/container/container.d.ts +54 -13
- package/dist/functions/container/container.js +63 -18
- package/dist/functions/container/container.js.map +1 -1
- package/dist/functions/container/test-container.d.ts +43 -29
- package/dist/functions/container/test-container.js +71 -43
- package/dist/functions/container/test-container.js.map +1 -1
- package/dist/functions/dependency/dependency.d.ts +82 -8
- package/dist/functions/dependency/dependency.js +80 -14
- package/dist/functions/dependency/dependency.js.map +1 -1
- package/dist/functions/diff/aggregate-resource-actions.d.ts +19 -0
- package/dist/functions/diff/aggregate-resource-actions.js +41 -0
- package/dist/functions/diff/aggregate-resource-actions.js.map +1 -0
- package/dist/functions/diff/diff-metadata.d.ts +21 -3
- package/dist/functions/diff/diff-metadata.js +18 -0
- package/dist/functions/diff/diff-metadata.js.map +1 -1
- package/dist/functions/diff/diff.d.ts +55 -1
- package/dist/functions/diff/diff.js +44 -3
- package/dist/functions/diff/diff.js.map +1 -1
- package/dist/functions/diff/diff.utility.d.ts +17 -2
- package/dist/functions/diff/diff.utility.js +53 -38
- package/dist/functions/diff/diff.utility.js.map +1 -1
- package/dist/functions/hook/commit.hook.d.ts +16 -1
- package/dist/functions/hook/commit.hook.js +21 -6
- package/dist/functions/hook/commit.hook.js.map +1 -1
- package/dist/functions/hook/model-action.hook.d.ts +16 -1
- package/dist/functions/hook/model-action.hook.js +21 -6
- package/dist/functions/hook/model-action.hook.js.map +1 -1
- package/dist/functions/hook/resource-action.hook.d.ts +16 -1
- package/dist/functions/hook/resource-action.hook.js +21 -6
- package/dist/functions/hook/resource-action.hook.js.map +1 -1
- package/dist/functions/node/node-action.abstract.d.ts +23 -0
- package/dist/functions/node/node-action.abstract.js +20 -0
- package/dist/functions/node/node-action.abstract.js.map +1 -1
- package/dist/functions/node/node.abstract.d.ts +56 -5
- package/dist/functions/node/node.abstract.js +85 -12
- package/dist/functions/node/node.abstract.js.map +1 -1
- package/dist/functions/node/node.interface.d.ts +1 -0
- package/dist/functions/schema/schema.d.ts +7 -0
- package/dist/functions/schema/schema.js +9 -0
- package/dist/functions/schema/schema.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +244 -14
- package/dist/main.js +361 -72
- package/dist/main.js.map +1 -1
- package/dist/models/account/account.model.d.ts +37 -7
- package/dist/models/account/account.model.js +40 -8
- package/dist/models/account/account.model.js.map +1 -1
- package/dist/models/account/account.schema.d.ts +13 -1
- package/dist/models/account/account.schema.js +12 -0
- package/dist/models/account/account.schema.js.map +1 -1
- package/dist/models/app/app.model.d.ts +16 -1
- package/dist/models/app/app.model.js +19 -4
- package/dist/models/app/app.model.js.map +1 -1
- package/dist/models/app/app.schema.d.ts +6 -0
- package/dist/models/app/app.schema.js +6 -0
- package/dist/models/app/app.schema.js.map +1 -1
- package/dist/models/deployment/deployment.model.d.ts +13 -1
- package/dist/models/deployment/deployment.model.js +16 -4
- package/dist/models/deployment/deployment.model.js.map +1 -1
- package/dist/models/deployment/deployment.schema.d.ts +2 -0
- package/dist/models/deployment/deployment.schema.js +2 -0
- package/dist/models/deployment/deployment.schema.js.map +1 -1
- package/dist/models/environment/environment.model.d.ts +13 -1
- package/dist/models/environment/environment.model.js +20 -8
- package/dist/models/environment/environment.model.js.map +1 -1
- package/dist/models/environment/environment.schema.d.ts +2 -0
- package/dist/models/environment/environment.schema.js +2 -0
- package/dist/models/environment/environment.schema.js.map +1 -1
- package/dist/models/execution/execution.model.d.ts +20 -2
- package/dist/models/execution/execution.model.js +46 -28
- package/dist/models/execution/execution.model.js.map +1 -1
- package/dist/models/execution/execution.schema.d.ts +11 -0
- package/dist/models/execution/execution.schema.js +11 -0
- package/dist/models/execution/execution.schema.js.map +1 -1
- package/dist/models/filesystem/filesystem.model.d.ts +27 -1
- package/dist/models/filesystem/filesystem.model.js +30 -4
- package/dist/models/filesystem/filesystem.model.js.map +1 -1
- package/dist/models/filesystem/filesystem.schema.d.ts +5 -0
- package/dist/models/filesystem/filesystem.schema.js +5 -0
- package/dist/models/filesystem/filesystem.schema.js.map +1 -1
- package/dist/models/image/image.model.d.ts +17 -4
- package/dist/models/image/image.model.js +20 -7
- package/dist/models/image/image.model.js.map +1 -1
- package/dist/models/image/image.schema.d.ts +8 -0
- package/dist/models/image/image.schema.js +8 -0
- package/dist/models/image/image.schema.js.map +1 -1
- package/dist/models/model-action.interface.d.ts +17 -4
- package/dist/models/model.abstract.d.ts +96 -1
- package/dist/models/model.abstract.js +106 -7
- package/dist/models/model.abstract.js.map +1 -1
- package/dist/models/model.interface.d.ts +3 -0
- package/dist/models/pipeline/pipeline.model.d.ts +13 -1
- package/dist/models/pipeline/pipeline.model.js +18 -6
- package/dist/models/pipeline/pipeline.model.js.map +1 -1
- package/dist/models/pipeline/pipeline.schema.d.ts +8 -0
- package/dist/models/pipeline/pipeline.schema.js +8 -0
- package/dist/models/pipeline/pipeline.schema.js.map +1 -1
- package/dist/models/region/region.model.d.ts +16 -1
- package/dist/models/region/region.model.js +19 -4
- package/dist/models/region/region.model.js.map +1 -1
- package/dist/models/region/region.schema.d.ts +6 -0
- package/dist/models/region/region.schema.js +6 -0
- package/dist/models/region/region.schema.js.map +1 -1
- package/dist/models/server/server.model.d.ts +13 -1
- package/dist/models/server/server.model.js +16 -4
- package/dist/models/server/server.model.js.map +1 -1
- package/dist/models/server/server.schema.d.ts +3 -1
- package/dist/models/server/server.schema.js +3 -1
- package/dist/models/server/server.schema.js.map +1 -1
- package/dist/models/service/service.model.d.ts +15 -1
- package/dist/models/service/service.model.js +15 -1
- package/dist/models/service/service.model.js.map +1 -1
- package/dist/models/service/service.schema.d.ts +4 -1
- package/dist/models/service/service.schema.js +4 -1
- package/dist/models/service/service.schema.js.map +1 -1
- package/dist/models/subnet/subnet.model.d.ts +27 -3
- package/dist/models/subnet/subnet.model.js +40 -16
- package/dist/models/subnet/subnet.model.js.map +1 -1
- package/dist/models/subnet/subnet.schema.d.ts +9 -0
- package/dist/models/subnet/subnet.schema.js +9 -0
- package/dist/models/subnet/subnet.schema.js.map +1 -1
- package/dist/modes/apply-transaction.d.ts +23 -0
- package/dist/modes/apply-transaction.js +25 -0
- package/dist/modes/apply-transaction.js.map +1 -0
- package/dist/modes/commit.mode.d.ts +54 -0
- package/dist/modes/commit.mode.js +235 -0
- package/dist/modes/commit.mode.js.map +1 -0
- package/dist/modes/generate.mode.d.ts +29 -0
- package/dist/modes/generate.mode.js +49 -0
- package/dist/modes/generate.mode.js.map +1 -0
- package/dist/modes/run-action.mode.d.ts +30 -0
- package/dist/modes/run-action.mode.js +140 -0
- package/dist/modes/run-action.mode.js.map +1 -0
- package/dist/modes/validate.mode.d.ts +162 -0
- package/dist/modes/validate.mode.js +480 -0
- package/dist/modes/validate.mode.js.map +1 -0
- package/dist/modules/module.abstract.d.ts +51 -0
- package/dist/modules/module.abstract.js +36 -0
- package/dist/modules/module.abstract.js.map +1 -1
- package/dist/modules/module.container.d.ts +36 -0
- package/dist/modules/module.container.js +36 -0
- package/dist/modules/module.container.js.map +1 -1
- package/dist/modules/test-module.container.d.ts +139 -24
- package/dist/modules/test-module.container.js +410 -163
- package/dist/modules/test-module.container.js.map +1 -1
- package/dist/overlays/anchor.abstract.d.ts +32 -1
- package/dist/overlays/anchor.abstract.js +42 -11
- package/dist/overlays/anchor.abstract.js.map +1 -1
- package/dist/overlays/anchor.schema.d.ts +21 -0
- package/dist/overlays/anchor.schema.js +21 -0
- package/dist/overlays/anchor.schema.js.map +1 -1
- package/dist/overlays/overlay-data.repository.d.ts +18 -0
- package/dist/overlays/overlay-data.repository.js +18 -0
- package/dist/overlays/overlay-data.repository.js.map +1 -1
- package/dist/overlays/overlay.abstract.d.ts +56 -1
- package/dist/overlays/overlay.abstract.js +79 -20
- package/dist/overlays/overlay.abstract.js.map +1 -1
- package/dist/overlays/overlay.schema.d.ts +20 -0
- package/dist/overlays/overlay.schema.js +20 -0
- package/dist/overlays/overlay.schema.js.map +1 -1
- package/dist/resources/resource-action.interface.d.ts +26 -2
- package/dist/resources/resource-data.repository.d.ts +63 -1
- package/dist/resources/resource-data.repository.js +94 -4
- package/dist/resources/resource-data.repository.js.map +1 -1
- package/dist/resources/resource.abstract.d.ts +118 -3
- package/dist/resources/resource.abstract.js +166 -33
- package/dist/resources/resource.abstract.js.map +1 -1
- package/dist/resources/resource.schema.d.ts +29 -1
- package/dist/resources/resource.schema.js +28 -0
- package/dist/resources/resource.schema.js.map +1 -1
- package/dist/resources/terraform-resource.abstract.d.ts +44 -0
- package/dist/resources/terraform-resource.abstract.js +45 -0
- package/dist/resources/terraform-resource.abstract.js.map +1 -0
- package/dist/services/event/event.service.d.ts +30 -3
- package/dist/services/event/event.service.js +58 -16
- package/dist/services/event/event.service.js.map +1 -1
- package/dist/services/input/input.service.d.ts +52 -3
- package/dist/services/input/input.service.js +72 -8
- package/dist/services/input/input.service.js.map +1 -1
- package/dist/services/schema-translation/schema-translation.service.d.ts +9 -0
- package/dist/services/schema-translation/schema-translation.service.js +9 -0
- package/dist/services/schema-translation/schema-translation.service.js.map +1 -1
- package/dist/services/serialization/model/model-serialization.service.d.ts +26 -2
- package/dist/services/serialization/model/model-serialization.service.js +110 -62
- package/dist/services/serialization/model/model-serialization.service.js.map +1 -1
- package/dist/services/serialization/resource/resource-serialization.service.d.ts +33 -4
- package/dist/services/serialization/resource/resource-serialization.service.js +64 -28
- package/dist/services/serialization/resource/resource-serialization.service.js.map +1 -1
- package/dist/services/state-management/file-app-lock.utility.d.ts +43 -0
- package/dist/services/state-management/file-app-lock.utility.js +124 -0
- package/dist/services/state-management/file-app-lock.utility.js.map +1 -0
- package/dist/services/state-management/local-encryption.state-provider.d.ts +53 -2
- package/dist/services/state-management/local-encryption.state-provider.js +75 -49
- package/dist/services/state-management/local-encryption.state-provider.js.map +1 -1
- package/dist/services/state-management/local.state-provider.d.ts +49 -2
- package/dist/services/state-management/local.state-provider.js +70 -49
- package/dist/services/state-management/local.state-provider.js.map +1 -1
- package/dist/services/state-management/state-management.service.d.ts +141 -6
- package/dist/services/state-management/state-management.service.js +149 -4
- package/dist/services/state-management/state-management.service.js.map +1 -1
- package/dist/services/state-management/state-provider.interface.d.ts +55 -1
- package/dist/services/state-management/terraform-state.service.d.ts +76 -0
- package/dist/services/state-management/terraform-state.service.js +154 -0
- package/dist/services/state-management/terraform-state.service.js.map +1 -0
- package/dist/services/state-management/test.state-provider.d.ts +38 -1
- package/dist/services/state-management/test.state-provider.js +52 -21
- package/dist/services/state-management/test.state-provider.js.map +1 -1
- package/dist/services/terraform/terraform.service.d.ts +426 -0
- package/dist/services/terraform/terraform.service.js +995 -0
- package/dist/services/terraform/terraform.service.js.map +1 -0
- package/dist/services/terraform/terraform.type.d.ts +387 -0
- package/dist/services/terraform/terraform.type.js +579 -0
- package/dist/services/terraform/terraform.type.js.map +1 -0
- package/dist/services/transaction/transaction.service.d.ts +86 -10
- package/dist/services/transaction/transaction.service.js +387 -232
- package/dist/services/transaction/transaction.service.js.map +1 -1
- package/dist/services/validation/validation.service.d.ts +13 -1
- package/dist/services/validation/validation.service.js +12 -0
- package/dist/services/validation/validation.service.js.map +1 -1
- package/dist/utilities/array/array.utility.d.ts +3 -0
- package/dist/utilities/array/array.utility.js +3 -0
- package/dist/utilities/array/array.utility.js.map +1 -1
- package/dist/utilities/file/file.utility.d.ts +15 -0
- package/dist/utilities/file/file.utility.js +18 -1
- package/dist/utilities/file/file.utility.js.map +1 -1
- package/dist/utilities/hcl/hcl.utility.d.ts +61 -0
- package/dist/utilities/hcl/hcl.utility.js +229 -0
- package/dist/utilities/hcl/hcl.utility.js.map +1 -0
- package/dist/utilities/node/node.utility.d.ts +3 -0
- package/dist/utilities/node/node.utility.js +3 -0
- package/dist/utilities/node/node.utility.js.map +1 -1
- package/dist/utilities/object/object.utility.d.ts +12 -0
- package/dist/utilities/object/object.utility.js +12 -0
- package/dist/utilities/object/object.utility.js.map +1 -1
- package/dist/utilities/project/project.utility.d.ts +28 -0
- package/dist/utilities/project/project.utility.js +35 -0
- package/dist/utilities/project/project.utility.js.map +1 -0
- package/dist/utilities/string/string.utility.d.ts +21 -0
- package/dist/utilities/string/string.utility.js +39 -0
- package/dist/utilities/string/string.utility.js.map +1 -0
- package/dist/utilities/terraform/terraform.utility.d.ts +227 -0
- package/dist/utilities/terraform/terraform.utility.js +434 -0
- package/dist/utilities/terraform/terraform.utility.js.map +1 -0
- package/dist/utilities/test-helpers/test-classes.d.ts +18 -31
- package/dist/utilities/test-helpers/test-classes.js +18 -41
- package/dist/utilities/test-helpers/test-classes.js.map +1 -1
- package/dist/utilities/test-helpers/test-models.js +12 -0
- package/dist/utilities/test-helpers/test-models.js.map +1 -1
- package/dist/utilities/test-helpers/test-modes.d.ts +315 -0
- package/dist/utilities/test-helpers/test-modes.js +463 -0
- package/dist/utilities/test-helpers/test-modes.js.map +1 -0
- package/dist/utilities/test-helpers/test-modules.d.ts +41 -0
- package/dist/utilities/test-helpers/test-modules.js +79 -0
- package/dist/utilities/test-helpers/test-modules.js.map +1 -0
- package/dist/utilities/test-helpers/test-overlays.d.ts +17 -1
- package/dist/utilities/test-helpers/test-overlays.js +49 -5
- package/dist/utilities/test-helpers/test-overlays.js.map +1 -1
- package/dist/utilities/test-helpers/test-resources.d.ts +19 -1
- package/dist/utilities/test-helpers/test-resources.js +61 -3
- package/dist/utilities/test-helpers/test-resources.js.map +1 -1
- package/dist/utilities/validation/validation.utility.d.ts +24 -0
- package/dist/utilities/validation/validation.utility.js +24 -0
- package/dist/utilities/validation/validation.utility.js.map +1 -1
- package/package.json +6 -5
- package/dist/services/capture/capture.service.d.ts +0 -19
- package/dist/services/capture/capture.service.js +0 -43
- package/dist/services/capture/capture.service.js.map +0 -1
- package/dist/utilities/cidr/cidr.utility.d.ts +0 -10
- package/dist/utilities/cidr/cidr.utility.js +0 -51
- package/dist/utilities/cidr/cidr.utility.js.map +0 -1
|
@@ -12,11 +12,26 @@ import { DiffUtility } from '../diff/diff.utility.js';
|
|
|
12
12
|
* @group Functions/Container
|
|
13
13
|
*/
|
|
14
14
|
export class Container {
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
15
18
|
constructor() {
|
|
16
|
-
this.FACTORY_TIMEOUT_IN_MS = 3000;
|
|
17
19
|
this.factories = {};
|
|
20
|
+
this.FACTORY_TIMEOUT_IN_MS = 3000;
|
|
18
21
|
this.startupUnhandledPromises = [];
|
|
19
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The Container is a singleton - this is how you reach it.
|
|
25
|
+
*/
|
|
26
|
+
static getInstance() {
|
|
27
|
+
if (!this.instance) {
|
|
28
|
+
this.instance = new Container();
|
|
29
|
+
}
|
|
30
|
+
return this.instance;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
20
35
|
copyFactories() {
|
|
21
36
|
const newFactoriesCopy = {};
|
|
22
37
|
for (const [type, factoryContainers] of Object.entries(this.factories)) {
|
|
@@ -31,8 +46,9 @@ export class Container {
|
|
|
31
46
|
return newFactoriesCopy;
|
|
32
47
|
}
|
|
33
48
|
/**
|
|
34
|
-
*
|
|
35
|
-
* If the factory is not yet
|
|
49
|
+
* To get an instance of a class from its factory.
|
|
50
|
+
* If the factory is not registered yet, this waits for it, and times out - see
|
|
51
|
+
* {@link Container.setFactoryTimeout}.
|
|
36
52
|
*
|
|
37
53
|
* @param type The type or name of the class to get.
|
|
38
54
|
* @param options Allows selection of a specific factory to use to get the instance.
|
|
@@ -76,12 +92,9 @@ export class Container {
|
|
|
76
92
|
}
|
|
77
93
|
return factory.create(...args);
|
|
78
94
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
return this.instance;
|
|
84
|
-
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether a factory is registered for the class.
|
|
97
|
+
*/
|
|
85
98
|
has(type, options) {
|
|
86
99
|
const metadata = options?.metadata || {};
|
|
87
100
|
const name = typeof type === 'string' ? type : type.name;
|
|
@@ -91,7 +104,8 @@ export class Container {
|
|
|
91
104
|
return this.factories[name].some((f) => DiffUtility.isObjectDeepEquals(f.metadata, metadata));
|
|
92
105
|
}
|
|
93
106
|
/**
|
|
94
|
-
*
|
|
107
|
+
* To register a factory for a class. Prefer the {@link Factory} decorator; call this directly only
|
|
108
|
+
* when the factory is built at runtime.
|
|
95
109
|
*
|
|
96
110
|
* @param type The type or name of the class for which the factory is registered.
|
|
97
111
|
* @param factory The factory class being registered.
|
|
@@ -118,18 +132,41 @@ export class Container {
|
|
|
118
132
|
}
|
|
119
133
|
this.factories[name].push({ factory, metadata });
|
|
120
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
registerStartupUnhandledPromise(promise) {
|
|
139
|
+
this.startupUnhandledPromises.push(promise);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* To register a ready-made instance, instead of a factory that builds one.
|
|
143
|
+
*/
|
|
121
144
|
registerValue(type, value, options) {
|
|
122
145
|
this.registerFactory(type, class {
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
123
149
|
static async create() {
|
|
124
150
|
return value;
|
|
125
151
|
}
|
|
126
152
|
}, options);
|
|
127
153
|
}
|
|
128
|
-
|
|
129
|
-
|
|
154
|
+
/**
|
|
155
|
+
* To register a ready-made instance over whatever is already registered under the same type and
|
|
156
|
+
* metadata, rather than refusing as {@link Container.registerValue} does.
|
|
157
|
+
*
|
|
158
|
+
* Registering once is the right default - two factories for one type is usually a mistake. This is
|
|
159
|
+
* for the callers that legitimately register the same thing more than once: a module whose
|
|
160
|
+
* `onInit` runs on every `compose()`, and a test replacing a factory with a mock.
|
|
161
|
+
*/
|
|
162
|
+
replaceValue(type, value, options) {
|
|
163
|
+
if (this.has(type, options)) {
|
|
164
|
+
this.unRegisterFactory(type, options);
|
|
165
|
+
}
|
|
166
|
+
this.registerValue(type, value, options);
|
|
130
167
|
}
|
|
131
168
|
/**
|
|
132
|
-
*
|
|
169
|
+
* To clear every registered factory and empty the container. Mostly used in testing.
|
|
133
170
|
*/
|
|
134
171
|
reset() {
|
|
135
172
|
this.FACTORY_TIMEOUT_IN_MS = 3000;
|
|
@@ -138,6 +175,9 @@ export class Container {
|
|
|
138
175
|
}
|
|
139
176
|
this.startupUnhandledPromises.splice(0, this.startupUnhandledPromises.length);
|
|
140
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* @internal
|
|
180
|
+
*/
|
|
141
181
|
setFactories(factories) {
|
|
142
182
|
for (const [type, factoryContainers] of Object.entries(factories)) {
|
|
143
183
|
this.factories[type] = [];
|
|
@@ -150,19 +190,21 @@ export class Container {
|
|
|
150
190
|
}
|
|
151
191
|
}
|
|
152
192
|
/**
|
|
153
|
-
*
|
|
154
|
-
* This method allows to change that timeout.
|
|
193
|
+
* To change how long `get()` waits for a factory to be registered.
|
|
155
194
|
*
|
|
195
|
+
* @defaultValue `3000`
|
|
156
196
|
* @param timeoutInMs The timeout in milliseconds.
|
|
197
|
+
*
|
|
157
198
|
*/
|
|
158
199
|
setFactoryTimeout(timeoutInMs) {
|
|
159
200
|
this.FACTORY_TIMEOUT_IN_MS = timeoutInMs;
|
|
160
201
|
}
|
|
161
202
|
/**
|
|
162
|
-
*
|
|
203
|
+
* To unregister a class's factories, so that your own can take their place.
|
|
163
204
|
*
|
|
164
|
-
* @param type The type or name of the class
|
|
165
|
-
* @param options
|
|
205
|
+
* @param type The type or name of the class whose factories are unregistered.
|
|
206
|
+
* @param options Pass `metadata` to unregister one specific factory. Without it, all of the
|
|
207
|
+
* class's factories are unregistered.
|
|
166
208
|
*/
|
|
167
209
|
unRegisterFactory(type, options) {
|
|
168
210
|
const name = typeof type === 'string' ? type : type.name;
|
|
@@ -176,6 +218,9 @@ export class Container {
|
|
|
176
218
|
this.factories[name].splice(index, 1);
|
|
177
219
|
}
|
|
178
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
179
224
|
async waitToResolveAllFactories() {
|
|
180
225
|
const promiseToResolveAllFactories = [];
|
|
181
226
|
for (const name of Object.keys(this.factories)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/functions/container/container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMtD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IASpB;
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/functions/container/container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMtD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IASpB;;OAEG;IACH;QATiB,cAAS,GAAmD,EAAE,CAAC;QAExE,0BAAqB,GAAG,IAAI,CAAC;QAEpB,6BAAwB,GAAuB,EAAE,CAAC;IAK5C,CAAC;IAExB;;OAEG;IACH,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;QAClC,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,aAAa;QACX,MAAM,gBAAgB,GAAmD,EAAE,CAAC;QAE5E,KAAK,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACvE,gBAAgB,C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,gBAAgB,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpD,IAAI,gBAAgB,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;oBACzE,4BAA4B,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,4BAA4B,EAAE,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC;IACzF,CAAC;CACF"}
|
|
@@ -12,40 +12,46 @@ type TestContainerSubjects = {
|
|
|
12
12
|
};
|
|
13
13
|
type TestContainerOptions = {
|
|
14
14
|
factoryTimeoutInMs?: number;
|
|
15
|
+
force?: boolean;
|
|
15
16
|
};
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
+
* An isolated {@link Container} for tests.
|
|
19
|
+
*
|
|
20
|
+
* The Container is a process-wide singleton, which makes it awkward to mock. TestContainer solves
|
|
21
|
+
* that: create one in `beforeEach()` and it takes over the Container for that test, letting you
|
|
22
|
+
* replace any factory with a stub. `reset()` in `afterEach()` puts it back.
|
|
18
23
|
*
|
|
19
24
|
* :::info Info
|
|
20
|
-
* A test framework like Jest
|
|
21
|
-
*
|
|
25
|
+
* A test framework like Jest runs test *files* in parallel across cores, and the `it()` blocks
|
|
26
|
+
* within a file serially. So a TestContainer never leaks into a test running in parallel.
|
|
22
27
|
* :::
|
|
23
28
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* beforeEach(async () => {
|
|
32
|
+
* container = await TestContainer.create({ mocks: [] }, { factoryTimeoutInMs: 500 });
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* afterEach(async () => {
|
|
36
|
+
* await TestContainer.reset();
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
29
39
|
*
|
|
30
40
|
* @group Functions/Container
|
|
31
41
|
*/
|
|
32
42
|
export declare class TestContainer {
|
|
33
43
|
private static originalFactories;
|
|
34
|
-
private static bootstrap;
|
|
35
44
|
/**
|
|
36
|
-
*
|
|
45
|
+
* To take over the Container for one test, replacing the factories you name.
|
|
37
46
|
*
|
|
38
47
|
* @example
|
|
39
48
|
* ```ts
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* }, { factoryTimeoutInMs: 500 });
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
+
* await TestContainer.create({
|
|
50
|
+
* mocks: [
|
|
51
|
+
* { type: MyClass, value: jest.fn() },
|
|
52
|
+
* { metadata: { key: 'value' }, type: AnotherClass, value: new AnotherClass() },
|
|
53
|
+
* ],
|
|
54
|
+
* }, { factoryTimeoutInMs: 500 });
|
|
49
55
|
* ```
|
|
50
56
|
* @param subjects The subjects being mocked.
|
|
51
57
|
* - `mocks` is an array of objects, to override the default factories.
|
|
@@ -54,20 +60,28 @@ export declare class TestContainer {
|
|
|
54
60
|
* - Use `value: T` to provide the mocked value.
|
|
55
61
|
* @param options Options to configure TestContainer.
|
|
56
62
|
* - `factoryTimeoutInMs?: number` is to override the default container timeout.
|
|
63
|
+
* - `force?: boolean` performs a complete container reset.
|
|
57
64
|
*/
|
|
58
65
|
static create(subjects: TestContainerSubjects, options?: TestContainerOptions): Promise<Container>;
|
|
59
66
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* afterAll(async () => {
|
|
67
|
-
* await TestContainer.reset();
|
|
68
|
-
* });
|
|
69
|
-
* ```
|
|
67
|
+
* To destroy every factory in the Container. Because it destroys the whole Container and not only
|
|
68
|
+
* the mocks, it must always be called in your teardown block - otherwise the next test starts
|
|
69
|
+
* against a Container this test left behind.
|
|
70
70
|
*/
|
|
71
71
|
static reset(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Bootstrap the Container with the necessary factories internal to Octo.
|
|
74
|
+
* Between test runs, when the container is reset, many of Octo's internal classes must be reset as well.
|
|
75
|
+
* Since these classes are not exposed outside of Octo, we must bootstrap them.
|
|
76
|
+
*
|
|
77
|
+
* Some factories defined in Octo using `@Factory` must be placed here,
|
|
78
|
+
* the exact criteria being any factory that needs to reset its state.
|
|
79
|
+
*
|
|
80
|
+
* Exceptions:
|
|
81
|
+
* - {@link ModelSerializationService}: We do not want to loose class mapping already instantiated via decorators.
|
|
82
|
+
* - {@link ResourceSerializationService}: We do not want to loose class mapping already instantiated via decorators.
|
|
83
|
+
* - {@link TransactionService}: We do not want to loose action mapping already instantiated via decorators.
|
|
84
|
+
*/
|
|
85
|
+
private static bootstrap;
|
|
72
86
|
}
|
|
73
87
|
export {};
|
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
import { ModuleContainer } from '../../modules/module.container.js';
|
|
2
2
|
import { OverlayDataRepository } from '../../overlays/overlay-data.repository.js';
|
|
3
3
|
import { ResourceDataRepository, } from '../../resources/resource-data.repository.js';
|
|
4
|
-
import {
|
|
4
|
+
import { EventService } from '../../services/event/event.service.js';
|
|
5
5
|
import { InputService } from '../../services/input/input.service.js';
|
|
6
|
+
import { ModelSerializationService } from '../../services/serialization/model/model-serialization.service.js';
|
|
7
|
+
import { ResourceSerializationService } from '../../services/serialization/resource/resource-serialization.service.js';
|
|
8
|
+
import { TerraformService } from '../../services/terraform/terraform.service.js';
|
|
9
|
+
import { TransactionService } from '../../services/transaction/transaction.service.js';
|
|
6
10
|
import { Container } from './container.js';
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* An isolated {@link Container} for tests.
|
|
13
|
+
*
|
|
14
|
+
* The Container is a process-wide singleton, which makes it awkward to mock. TestContainer solves
|
|
15
|
+
* that: create one in `beforeEach()` and it takes over the Container for that test, letting you
|
|
16
|
+
* replace any factory with a stub. `reset()` in `afterEach()` puts it back.
|
|
9
17
|
*
|
|
10
18
|
* :::info Info
|
|
11
|
-
* A test framework like Jest
|
|
12
|
-
*
|
|
19
|
+
* A test framework like Jest runs test *files* in parallel across cores, and the `it()` blocks
|
|
20
|
+
* within a file serially. So a TestContainer never leaks into a test running in parallel.
|
|
13
21
|
* :::
|
|
14
22
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* beforeEach(async () => {
|
|
26
|
+
* container = await TestContainer.create({ mocks: [] }, { factoryTimeoutInMs: 500 });
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* afterEach(async () => {
|
|
30
|
+
* await TestContainer.reset();
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
20
33
|
*
|
|
21
34
|
* @group Functions/Container
|
|
22
35
|
*/
|
|
23
36
|
export class TestContainer {
|
|
24
|
-
static async bootstrap(container) {
|
|
25
|
-
await container.get(OverlayDataRepository, {
|
|
26
|
-
args: [true, []],
|
|
27
|
-
});
|
|
28
|
-
await container.get(ResourceDataRepository, {
|
|
29
|
-
args: [true, [], [], []],
|
|
30
|
-
});
|
|
31
|
-
await container.get(CaptureService, { args: [true] });
|
|
32
|
-
await container.get(InputService, { args: [true] });
|
|
33
|
-
await container.get(ModuleContainer, { args: [true] });
|
|
34
|
-
}
|
|
35
37
|
/**
|
|
36
|
-
*
|
|
38
|
+
* To take over the Container for one test, replacing the factories you name.
|
|
37
39
|
*
|
|
38
40
|
* @example
|
|
39
41
|
* ```ts
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* }, { factoryTimeoutInMs: 500 });
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
42
|
+
* await TestContainer.create({
|
|
43
|
+
* mocks: [
|
|
44
|
+
* { type: MyClass, value: jest.fn() },
|
|
45
|
+
* { metadata: { key: 'value' }, type: AnotherClass, value: new AnotherClass() },
|
|
46
|
+
* ],
|
|
47
|
+
* }, { factoryTimeoutInMs: 500 });
|
|
49
48
|
* ```
|
|
50
49
|
* @param subjects The subjects being mocked.
|
|
51
50
|
* - `mocks` is an array of objects, to override the default factories.
|
|
@@ -54,6 +53,7 @@ export class TestContainer {
|
|
|
54
53
|
* - Use `value: T` to provide the mocked value.
|
|
55
54
|
* @param options Options to configure TestContainer.
|
|
56
55
|
* - `factoryTimeoutInMs?: number` is to override the default container timeout.
|
|
56
|
+
* - `force?: boolean` performs a complete container reset.
|
|
57
57
|
*/
|
|
58
58
|
static async create(subjects, options) {
|
|
59
59
|
if (!TestContainer.originalFactories) {
|
|
@@ -64,31 +64,59 @@ export class TestContainer {
|
|
|
64
64
|
container.setFactories(this.originalFactories);
|
|
65
65
|
// Reset state of eligible factories.
|
|
66
66
|
// A factory is eligible if it has an internal structure and should be reset on every test.
|
|
67
|
-
await this.bootstrap(container);
|
|
67
|
+
await this.bootstrap(container, options?.force ?? false);
|
|
68
68
|
if (options?.factoryTimeoutInMs) {
|
|
69
69
|
container.setFactoryTimeout(options.factoryTimeoutInMs);
|
|
70
70
|
}
|
|
71
71
|
// Override new container with mock factories as instructed.
|
|
72
72
|
for (const mock of subjects.mocks || []) {
|
|
73
|
-
container.
|
|
74
|
-
container.registerValue(mock.type, mock.value, { metadata: mock.metadata });
|
|
73
|
+
container.replaceValue(mock.type, mock.value, { metadata: mock.metadata });
|
|
75
74
|
}
|
|
76
75
|
return container;
|
|
77
76
|
}
|
|
78
77
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* afterAll(async () => {
|
|
86
|
-
* await TestContainer.reset();
|
|
87
|
-
* });
|
|
88
|
-
* ```
|
|
78
|
+
* To destroy every factory in the Container. Because it destroys the whole Container and not only
|
|
79
|
+
* the mocks, it must always be called in your teardown block - otherwise the next test starts
|
|
80
|
+
* against a Container this test left behind.
|
|
89
81
|
*/
|
|
90
82
|
static async reset() {
|
|
91
83
|
Container.getInstance().reset();
|
|
92
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Bootstrap the Container with the necessary factories internal to Octo.
|
|
87
|
+
* Between test runs, when the container is reset, many of Octo's internal classes must be reset as well.
|
|
88
|
+
* Since these classes are not exposed outside of Octo, we must bootstrap them.
|
|
89
|
+
*
|
|
90
|
+
* Some factories defined in Octo using `@Factory` must be placed here,
|
|
91
|
+
* the exact criteria being any factory that needs to reset its state.
|
|
92
|
+
*
|
|
93
|
+
* Exceptions:
|
|
94
|
+
* - {@link ModelSerializationService}: We do not want to loose class mapping already instantiated via decorators.
|
|
95
|
+
* - {@link ResourceSerializationService}: We do not want to loose class mapping already instantiated via decorators.
|
|
96
|
+
* - {@link TransactionService}: We do not want to loose action mapping already instantiated via decorators.
|
|
97
|
+
*/
|
|
98
|
+
static async bootstrap(container, force = false) {
|
|
99
|
+
const overlayDataRepository = await container.get(OverlayDataRepository, { args: [true, []] });
|
|
100
|
+
const resourceDataRepository = await container.get(ResourceDataRepository, { args: [true, [], [], []] });
|
|
101
|
+
const inputService = await container.get(InputService, { args: [true] });
|
|
102
|
+
const moduleContainer = await container.get(ModuleContainer, {
|
|
103
|
+
args: [true],
|
|
104
|
+
});
|
|
105
|
+
const terraformService = await container.get(TerraformService, {
|
|
106
|
+
args: [{}, true],
|
|
107
|
+
});
|
|
108
|
+
if (force) {
|
|
109
|
+
const eventService = await container.get(EventService);
|
|
110
|
+
const modelSerializationService = new ModelSerializationService(inputService);
|
|
111
|
+
container.unRegisterFactory(ModelSerializationService);
|
|
112
|
+
container.registerValue(ModelSerializationService, modelSerializationService);
|
|
113
|
+
const resourceSerializationService = new ResourceSerializationService(resourceDataRepository, inputService);
|
|
114
|
+
container.unRegisterFactory(ResourceSerializationService);
|
|
115
|
+
container.registerValue(ResourceSerializationService, resourceSerializationService);
|
|
116
|
+
const transactionService = new TransactionService(eventService, inputService, moduleContainer, overlayDataRepository, resourceDataRepository, terraformService);
|
|
117
|
+
container.unRegisterFactory(TransactionService);
|
|
118
|
+
container.registerValue(TransactionService, transactionService);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
93
121
|
}
|
|
94
122
|
//# sourceMappingURL=test-container.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/functions/container/test-container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA+B,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAqC,MAAM,2CAA2C,CAAC;AACrH,OAAO,EACL,sBAAsB,GAEvB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/functions/container/test-container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA+B,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAqC,MAAM,2CAA2C,CAAC;AACrH,OAAO,EACL,sBAAsB,GAEvB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACrE,OAAO,EAAE,YAAY,EAA4B,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,mEAAmE,CAAC;AAC9G,OAAO,EAAE,4BAA4B,EAAE,MAAM,yEAAyE,CAAC;AACvH,OAAO,EAAE,gBAAgB,EAAgC,MAAM,+CAA+C,CAAC;AAC/G,OAAO,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAa3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YACF,SAAS,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;YAChD,SAAS,CAAC,aAAa,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type { UnknownNode } from '../../app.type.js';
|
|
2
2
|
import type { DiffAction } from '../diff/diff.js';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
3
6
|
declare class DependencyBehavior {
|
|
4
7
|
forAction: DiffAction;
|
|
5
8
|
onAction: DiffAction;
|
|
6
9
|
onField: string;
|
|
7
10
|
toField: string;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
8
14
|
constructor(onField: string, onAction: DiffAction, toField: string, forAction: DiffAction);
|
|
9
15
|
}
|
|
10
16
|
/**
|
|
17
|
+
* How two nodes are related. A parent exists before its child, and outlives it.
|
|
18
|
+
*
|
|
11
19
|
* @group Functions/Dependency
|
|
12
20
|
*/
|
|
13
21
|
export declare enum DependencyRelationship {
|
|
@@ -15,6 +23,8 @@ export declare enum DependencyRelationship {
|
|
|
15
23
|
PARENT = "parent"
|
|
16
24
|
}
|
|
17
25
|
/**
|
|
26
|
+
* The serialized form of a {@link Dependency}, as it is written to state.
|
|
27
|
+
*
|
|
18
28
|
* @group Functions/Dependency
|
|
19
29
|
*/
|
|
20
30
|
export interface IDependency {
|
|
@@ -33,29 +43,93 @@ export interface IDependency {
|
|
|
33
43
|
to: string;
|
|
34
44
|
}
|
|
35
45
|
/**
|
|
46
|
+
* The edge between two nodes in Octo's graph.
|
|
47
|
+
*
|
|
48
|
+
* A dependency is directed, and carries two things: an optional parent/child relationship, and a set
|
|
49
|
+
* of *behaviors*. A behavior states an ordering rule - "when this field of `from` is added, the
|
|
50
|
+
* matching action on `to` must have run first" - and it is those rules that let Octo order a
|
|
51
|
+
* transaction correctly instead of guessing.
|
|
52
|
+
*
|
|
53
|
+
* Models create dependencies through `addChild()` and `addRelationship()`; you rarely construct one.
|
|
54
|
+
*
|
|
36
55
|
* @group Functions/Dependency
|
|
56
|
+
*
|
|
57
|
+
* @see Definition of [Dependencies](/docs/fundamentals/dependencies).
|
|
37
58
|
*/
|
|
38
59
|
export declare class Dependency {
|
|
39
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The node this dependency points from.
|
|
62
|
+
*/
|
|
40
63
|
readonly from: UnknownNode;
|
|
41
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The node this dependency points to.
|
|
66
|
+
*/
|
|
42
67
|
readonly to: UnknownNode;
|
|
68
|
+
private readonly behaviors;
|
|
69
|
+
private relationship;
|
|
70
|
+
/**
|
|
71
|
+
* @param from The node this dependency points from.
|
|
72
|
+
* @param to The node this dependency points to.
|
|
73
|
+
*/
|
|
43
74
|
constructor(from: UnknownNode, to: UnknownNode);
|
|
44
|
-
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
static unSynth(from: UnknownNode, to: UnknownNode, dependency: IDependency): Dependency;
|
|
79
|
+
/**
|
|
80
|
+
* To declare an ordering rule: when `onAction` happens to `onField` of `from`, then `forAction`
|
|
81
|
+
* on `toField` of `to` must have been applied first. Adding the same behavior twice is a no-op.
|
|
82
|
+
*/
|
|
45
83
|
addBehavior(onField: string, onAction: DiffAction, toField: string, forAction: DiffAction): void;
|
|
84
|
+
/**
|
|
85
|
+
* To mark `to` as the child of `from`.
|
|
86
|
+
*
|
|
87
|
+
* @throws {@link DependencyError} If this dependency already has a relationship.
|
|
88
|
+
*/
|
|
46
89
|
addChildRelationship(onField: string, toField: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* To mark `to` as the parent of `from`.
|
|
92
|
+
*
|
|
93
|
+
* @throws {@link DependencyError} If this dependency already has a relationship.
|
|
94
|
+
*/
|
|
47
95
|
addParentRelationship(onField: string, toField: string): void;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
isParentRelationship(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* The relationship between the two nodes, if one was declared.
|
|
98
|
+
*/
|
|
52
99
|
getRelationship(): {
|
|
53
100
|
onField: string;
|
|
54
101
|
toField: string;
|
|
55
102
|
type: DependencyRelationship;
|
|
56
103
|
} | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Whether any behavior matches every argument given. Arguments left out match anything.
|
|
106
|
+
*/
|
|
107
|
+
hasMatchingBehavior(onField?: string, onAction?: DiffAction, toField?: string, forAction?: DiffAction): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Whether `to` is a child of `from`.
|
|
110
|
+
*/
|
|
111
|
+
isChildRelationship(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Whether both dependencies connect the same two nodes, in the same direction.
|
|
114
|
+
*/
|
|
115
|
+
isEqual(dependency: Dependency): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Whether `to` is a parent of `from`.
|
|
118
|
+
*/
|
|
119
|
+
isParentRelationship(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* To drop an ordering rule.
|
|
122
|
+
*
|
|
123
|
+
* @throws {@link DependencyError} If no such behavior exists.
|
|
124
|
+
*/
|
|
57
125
|
removeBehavior(onField: string, onAction: DiffAction, toField: string, forAction: DiffAction): void;
|
|
126
|
+
/**
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
58
129
|
synth(): IDependency;
|
|
59
|
-
|
|
130
|
+
/**
|
|
131
|
+
* The position of a matching behavior, or `-1`.
|
|
132
|
+
*/
|
|
133
|
+
private getBehaviorIndex;
|
|
60
134
|
}
|
|
61
135
|
export {};
|