@quadnix/octo 0.0.19 → 0.0.21
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 +5 -0
- package/dist/app.type.js +6 -0
- package/dist/app.type.js.map +1 -1
- package/dist/decorators/action.decorator.d.ts +17 -0
- package/dist/decorators/action.decorator.js +26 -1
- package/dist/decorators/action.decorator.js.map +1 -1
- package/dist/decorators/anchor.decorator.d.ts +13 -0
- package/dist/decorators/anchor.decorator.js +16 -1
- package/dist/decorators/anchor.decorator.js.map +1 -1
- package/dist/decorators/container.d.ts +61 -0
- package/dist/decorators/container.js +68 -3
- package/dist/decorators/container.js.map +1 -1
- package/dist/decorators/enable-hook.decorator.d.ts +14 -0
- package/dist/decorators/enable-hook.decorator.js +14 -0
- package/dist/decorators/enable-hook.decorator.js.map +1 -1
- package/dist/decorators/event-source.decorator.d.ts +18 -0
- package/dist/decorators/event-source.decorator.js +22 -0
- package/dist/decorators/event-source.decorator.js.map +1 -0
- package/dist/decorators/factory.decorator.d.ts +30 -0
- package/dist/decorators/factory.decorator.js +30 -0
- package/dist/decorators/factory.decorator.js.map +1 -1
- package/dist/decorators/model.decorator.d.ts +13 -0
- package/dist/decorators/model.decorator.js +16 -1
- package/dist/decorators/model.decorator.js.map +1 -1
- package/dist/decorators/module.decorator.d.ts +52 -0
- package/dist/decorators/module.decorator.js +60 -1
- package/dist/decorators/module.decorator.js.map +1 -1
- package/dist/decorators/on-event.decorator.d.ts +20 -0
- package/dist/decorators/on-event.decorator.js +24 -0
- package/dist/decorators/on-event.decorator.js.map +1 -0
- package/dist/decorators/overlay.decorator.d.ts +13 -0
- package/dist/decorators/overlay.decorator.js +16 -1
- package/dist/decorators/overlay.decorator.js.map +1 -1
- package/dist/decorators/resource.decorator.d.ts +13 -0
- package/dist/decorators/resource.decorator.js +16 -1
- package/dist/decorators/resource.decorator.js.map +1 -1
- package/dist/decorators/test-container.d.ts +52 -0
- package/dist/decorators/test-container.js +54 -2
- package/dist/decorators/test-container.js.map +1 -1
- package/dist/decorators/validate.decorator.d.ts +9 -0
- package/dist/decorators/validate.decorator.js +23 -0
- package/dist/decorators/validate.decorator.js.map +1 -0
- package/dist/events/error.event.d.ts +35 -0
- package/dist/events/error.event.js +36 -0
- package/dist/events/error.event.js.map +1 -0
- package/dist/events/event.model.d.ts +37 -0
- package/dist/events/event.model.js +43 -0
- package/dist/events/event.model.js.map +1 -0
- package/dist/events/hook.event.d.ts +194 -0
- package/dist/events/hook.event.js +195 -0
- package/dist/events/hook.event.js.map +1 -0
- package/dist/events/module.event.d.ts +15 -0
- package/dist/events/module.event.js +16 -0
- package/dist/events/module.event.js.map +1 -0
- package/dist/events/registration.event.d.ts +112 -0
- package/dist/events/registration.event.js +170 -0
- package/dist/events/registration.event.js.map +1 -0
- package/dist/events/serialization.event.d.ts +72 -0
- package/dist/events/serialization.event.js +73 -0
- package/dist/events/serialization.event.js.map +1 -0
- package/dist/events/transaction.event.d.ts +48 -0
- package/dist/events/transaction.event.js +49 -0
- package/dist/events/transaction.event.js.map +1 -0
- package/dist/functions/dependency/dependency.js +1 -8
- package/dist/functions/dependency/dependency.js.map +1 -1
- package/dist/functions/diff/diff-metadata.d.ts +3 -0
- package/dist/functions/diff/diff-metadata.js +5 -10
- package/dist/functions/diff/diff-metadata.js.map +1 -1
- package/dist/functions/diff/diff.d.ts +3 -0
- package/dist/functions/diff/diff.js +3 -4
- package/dist/functions/diff/diff.js.map +1 -1
- package/dist/functions/diff/diff.utility.d.ts +32 -0
- package/dist/functions/diff/diff.utility.js +49 -0
- package/dist/functions/diff/diff.utility.js.map +1 -1
- package/dist/functions/hook/commit.hook.js +11 -3
- package/dist/functions/hook/commit.hook.js.map +1 -1
- package/dist/functions/hook/model-action.hook.js +11 -3
- package/dist/functions/hook/model-action.hook.js.map +1 -1
- package/dist/functions/hook/resource-action.hook.js +11 -3
- package/dist/functions/hook/resource-action.hook.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +11 -2
- package/dist/main.js +34 -16
- package/dist/main.js.map +1 -1
- package/dist/models/app/app.interface.d.ts +5 -0
- package/dist/models/app/app.model.d.ts +29 -0
- package/dist/models/app/app.model.js +40 -3
- package/dist/models/app/app.model.js.map +1 -1
- package/dist/models/deployment/deployment.interface.d.ts +5 -0
- package/dist/models/deployment/deployment.model.d.ts +15 -0
- package/dist/models/deployment/deployment.model.js +20 -3
- package/dist/models/deployment/deployment.model.js.map +1 -1
- package/dist/models/environment/environment.interface.d.ts +5 -0
- package/dist/models/environment/environment.model.d.ts +18 -0
- package/dist/models/environment/environment.model.js +33 -4
- package/dist/models/environment/environment.model.js.map +1 -1
- package/dist/models/execution/execution.interface.d.ts +5 -0
- package/dist/models/execution/execution.model.d.ts +23 -0
- package/dist/models/execution/execution.model.js +39 -2
- package/dist/models/execution/execution.model.js.map +1 -1
- package/dist/models/image/image.interface.d.ts +5 -0
- package/dist/models/image/image.model.d.ts +35 -0
- package/dist/models/image/image.model.js +25 -6
- package/dist/models/image/image.model.js.map +1 -1
- package/dist/models/model-action.interface.d.ts +21 -0
- package/dist/models/model.abstract.d.ts +265 -0
- package/dist/models/model.abstract.js +274 -5
- package/dist/models/model.abstract.js.map +1 -1
- package/dist/models/model.interface.d.ts +25 -0
- package/dist/models/pipeline/pipeline.interface.d.ts +5 -0
- package/dist/models/pipeline/pipeline.model.d.ts +15 -0
- package/dist/models/pipeline/pipeline.model.js +25 -4
- package/dist/models/pipeline/pipeline.model.js.map +1 -1
- package/dist/models/region/region.interface.d.ts +5 -0
- package/dist/models/region/region.model.d.ts +18 -0
- package/dist/models/region/region.model.js +29 -3
- package/dist/models/region/region.model.js.map +1 -1
- package/dist/models/server/server.interface.d.ts +5 -0
- package/dist/models/server/server.model.d.ts +17 -0
- package/dist/models/server/server.model.js +24 -3
- package/dist/models/server/server.model.js.map +1 -1
- package/dist/models/service/service.interface.d.ts +5 -0
- package/dist/models/service/service.model.d.ts +15 -0
- package/dist/models/service/service.model.js +19 -2
- package/dist/models/service/service.model.js.map +1 -1
- package/dist/models/subnet/subnet.interface.d.ts +5 -0
- package/dist/models/subnet/subnet.model.d.ts +48 -0
- package/dist/models/subnet/subnet.model.js +52 -7
- package/dist/models/subnet/subnet.model.js.map +1 -1
- package/dist/modules/module.container.d.ts +2 -0
- package/dist/modules/module.container.js +22 -10
- package/dist/modules/module.container.js.map +1 -1
- package/dist/modules/test-module.container.d.ts +4 -3
- package/dist/modules/test-module.container.js +13 -10
- package/dist/modules/test-module.container.js.map +1 -1
- package/dist/overlays/anchor.abstract.js +0 -3
- package/dist/overlays/anchor.abstract.js.map +1 -1
- package/dist/overlays/overlay-data.repository.js +0 -3
- package/dist/overlays/overlay-data.repository.js.map +1 -1
- package/dist/overlays/overlay.abstract.js +3 -3
- package/dist/overlays/overlay.abstract.js.map +1 -1
- package/dist/overlays/overlay.service.js +0 -2
- package/dist/overlays/overlay.service.js.map +1 -1
- package/dist/resources/resource-data.repository.js +6 -3
- package/dist/resources/resource-data.repository.js.map +1 -1
- package/dist/resources/resource.abstract.js +4 -4
- package/dist/resources/resource.abstract.js.map +1 -1
- package/dist/resources/shared-resource.abstract.js +4 -1
- package/dist/resources/shared-resource.abstract.js.map +1 -1
- package/dist/services/capture/capture.service.js +3 -2
- package/dist/services/capture/capture.service.js.map +1 -1
- package/dist/services/event/event.service.d.ts +17 -0
- package/dist/services/event/event.service.js +92 -0
- package/dist/services/event/event.service.js.map +1 -0
- package/dist/services/input/input.service.js +1 -3
- package/dist/services/input/input.service.js.map +1 -1
- package/dist/services/serialization/model/model-serialization.service.d.ts +1 -1
- package/dist/services/serialization/model/model-serialization.service.js +28 -5
- package/dist/services/serialization/model/model-serialization.service.js.map +1 -1
- package/dist/services/serialization/resource/resource-serialization.service.js +32 -4
- package/dist/services/serialization/resource/resource-serialization.service.js.map +1 -1
- package/dist/services/state-management/local.state-provider.js +0 -1
- package/dist/services/state-management/local.state-provider.js.map +1 -1
- package/dist/services/state-management/state-management.service.js +0 -2
- package/dist/services/state-management/state-management.service.js.map +1 -1
- package/dist/services/state-management/test.state-provider.js +3 -1
- package/dist/services/state-management/test.state-provider.js.map +1 -1
- package/dist/services/transaction/transaction.service.d.ts +4 -0
- package/dist/services/transaction/transaction.service.js +69 -9
- package/dist/services/transaction/transaction.service.js.map +1 -1
- package/dist/services/validation/validation.service.d.ts +19 -0
- package/dist/services/validation/validation.service.js +66 -0
- package/dist/services/validation/validation.service.js.map +1 -0
- package/dist/utilities/object/object.utility.js +1 -0
- package/dist/utilities/object/object.utility.js.map +1 -1
- package/dist/utilities/validation/validation.utility.d.ts +5 -0
- package/dist/utilities/validation/validation.utility.js +12 -0
- package/dist/utilities/validation/validation.utility.js.map +1 -0
- package/package.json +1 -1
|
@@ -3,6 +3,58 @@ import type { Octo } from '../main.js';
|
|
|
3
3
|
import type { IModelAction } from '../models/model-action.interface.js';
|
|
4
4
|
import { type IModule } from '../modules/module.interface.js';
|
|
5
5
|
import type { IResourceAction } from '../resources/resource-action.interface.js';
|
|
6
|
+
/**
|
|
7
|
+
* A `@Module` is a class decorator to be placed on top of a class that represents a module.
|
|
8
|
+
* - A Module class must implement the {@link IModule} interface.
|
|
9
|
+
* - A Module class constructor is injected with the outputs of the modules it imports.
|
|
10
|
+
* - The {@link IModule.onInit} method is called to initialize the module,
|
|
11
|
+
* and is where you will *define* your infrastructure.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* @Module({
|
|
16
|
+
* args: [{ isArg: (app: App) => app instanceof App, name: 'app' }],
|
|
17
|
+
* imports: [OtherModule],
|
|
18
|
+
* postModelActionHooks: [{ ACTION_NAME: 'SomeAction', collectInput: () => { ... }, handle: () => { ... } }],
|
|
19
|
+
* })
|
|
20
|
+
* export class MyModule implements IModule<Region> {
|
|
21
|
+
* constructor(app: App) { ... }
|
|
22
|
+
*
|
|
23
|
+
* async onInit(): Promise<Region> { ... }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
* @group Decorators
|
|
27
|
+
* @param options - Options to the module.
|
|
28
|
+
* @param options.args - (optional) An array of arg validators to verify the args passed to the module's constructor.
|
|
29
|
+
* - The `isArg` method receives an argument, and you must do your own type checking and return a boolean.
|
|
30
|
+
* - The `name` property is the name of the argument.
|
|
31
|
+
* @param options.imports - (optional) An array of modules to import.
|
|
32
|
+
* @param options.postCommitHooks - (optional) An array of post-commit hooks.
|
|
33
|
+
* - The `callback` method will be called after the transaction is committed.
|
|
34
|
+
* This method receives the same arguments as {@link Octo.commitTransaction}.
|
|
35
|
+
* @param options.postModelActionHooks - (optional) An array of post-model action hooks.
|
|
36
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
37
|
+
* - The `collectInput` method can be used to enrich the action inputs. It works the same as in {@link IModelAction}.
|
|
38
|
+
* - The `handle` method will be called after the action is executed.
|
|
39
|
+
* This method receives the same arguments as {@link IModelAction.handle}.
|
|
40
|
+
* @param options.postResourceActionHooks - (optional) An array of post-resource action hooks.
|
|
41
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
42
|
+
* - The `handle` method will be called after the action is executed.
|
|
43
|
+
* This method receives the same arguments as {@link IResourceAction.handle}.
|
|
44
|
+
* @param options.preCommitHooks - (optional) An array of pre-commit hooks.
|
|
45
|
+
* - The `callback` method will be called before the transaction is committed.
|
|
46
|
+
* This method receives the same arguments as {@link Octo.commitTransaction}.
|
|
47
|
+
* @param options.preModelActionHooks - (optional) An array of pre-model action hooks.
|
|
48
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
49
|
+
* - The `collectInput` method can be used to enrich the action inputs. It works the same as in {@link IModelAction}.
|
|
50
|
+
* - The `handle` method will be called before the action is executed.
|
|
51
|
+
* This method receives the same arguments as {@link IModelAction.handle}.
|
|
52
|
+
* @param options.preResourceActionHooks - (optional) An array of pre-resource action hooks.
|
|
53
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
54
|
+
* - The `handle` method will be called before the action is executed.
|
|
55
|
+
* @returns The decorated class.
|
|
56
|
+
* @see Definition of [Modules](/docs/fundamentals/modules).
|
|
57
|
+
*/
|
|
6
58
|
export declare function Module({ args, imports, postCommitHooks, postModelActionHooks, postResourceActionHooks, preCommitHooks, preModelActionHooks, preResourceActionHooks, }: {
|
|
7
59
|
args?: {
|
|
8
60
|
isArg: (arg: unknown) => boolean;
|
|
@@ -1,8 +1,64 @@
|
|
|
1
|
+
import { RegistrationErrorEvent } from '../events/error.event.js';
|
|
1
2
|
import { ModuleContainer } from '../modules/module.container.js';
|
|
3
|
+
import { EventService } from '../services/event/event.service.js';
|
|
2
4
|
import { Container } from './container.js';
|
|
5
|
+
/**
|
|
6
|
+
* A `@Module` is a class decorator to be placed on top of a class that represents a module.
|
|
7
|
+
* - A Module class must implement the {@link IModule} interface.
|
|
8
|
+
* - A Module class constructor is injected with the outputs of the modules it imports.
|
|
9
|
+
* - The {@link IModule.onInit} method is called to initialize the module,
|
|
10
|
+
* and is where you will *define* your infrastructure.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* @Module({
|
|
15
|
+
* args: [{ isArg: (app: App) => app instanceof App, name: 'app' }],
|
|
16
|
+
* imports: [OtherModule],
|
|
17
|
+
* postModelActionHooks: [{ ACTION_NAME: 'SomeAction', collectInput: () => { ... }, handle: () => { ... } }],
|
|
18
|
+
* })
|
|
19
|
+
* export class MyModule implements IModule<Region> {
|
|
20
|
+
* constructor(app: App) { ... }
|
|
21
|
+
*
|
|
22
|
+
* async onInit(): Promise<Region> { ... }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
* @group Decorators
|
|
26
|
+
* @param options - Options to the module.
|
|
27
|
+
* @param options.args - (optional) An array of arg validators to verify the args passed to the module's constructor.
|
|
28
|
+
* - The `isArg` method receives an argument, and you must do your own type checking and return a boolean.
|
|
29
|
+
* - The `name` property is the name of the argument.
|
|
30
|
+
* @param options.imports - (optional) An array of modules to import.
|
|
31
|
+
* @param options.postCommitHooks - (optional) An array of post-commit hooks.
|
|
32
|
+
* - The `callback` method will be called after the transaction is committed.
|
|
33
|
+
* This method receives the same arguments as {@link Octo.commitTransaction}.
|
|
34
|
+
* @param options.postModelActionHooks - (optional) An array of post-model action hooks.
|
|
35
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
36
|
+
* - The `collectInput` method can be used to enrich the action inputs. It works the same as in {@link IModelAction}.
|
|
37
|
+
* - The `handle` method will be called after the action is executed.
|
|
38
|
+
* This method receives the same arguments as {@link IModelAction.handle}.
|
|
39
|
+
* @param options.postResourceActionHooks - (optional) An array of post-resource action hooks.
|
|
40
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
41
|
+
* - The `handle` method will be called after the action is executed.
|
|
42
|
+
* This method receives the same arguments as {@link IResourceAction.handle}.
|
|
43
|
+
* @param options.preCommitHooks - (optional) An array of pre-commit hooks.
|
|
44
|
+
* - The `callback` method will be called before the transaction is committed.
|
|
45
|
+
* This method receives the same arguments as {@link Octo.commitTransaction}.
|
|
46
|
+
* @param options.preModelActionHooks - (optional) An array of pre-model action hooks.
|
|
47
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
48
|
+
* - The `collectInput` method can be used to enrich the action inputs. It works the same as in {@link IModelAction}.
|
|
49
|
+
* - The `handle` method will be called before the action is executed.
|
|
50
|
+
* This method receives the same arguments as {@link IModelAction.handle}.
|
|
51
|
+
* @param options.preResourceActionHooks - (optional) An array of pre-resource action hooks.
|
|
52
|
+
* - The `ACTION_NAME` identifies the action on which this hook is registered.
|
|
53
|
+
* - The `handle` method will be called before the action is executed.
|
|
54
|
+
* @returns The decorated class.
|
|
55
|
+
* @see Definition of [Modules](/docs/fundamentals/modules).
|
|
56
|
+
*/
|
|
3
57
|
export function Module({ args = [], imports = [], postCommitHooks = [], postModelActionHooks = [], postResourceActionHooks = [], preCommitHooks = [], preModelActionHooks = [], preResourceActionHooks = [], }) {
|
|
4
58
|
return function (constructor) {
|
|
5
|
-
Container.get(ModuleContainer)
|
|
59
|
+
Container.get(ModuleContainer)
|
|
60
|
+
.then((moduleContainer) => {
|
|
61
|
+
// Verify classes with @Module implements IModule.
|
|
6
62
|
if (!('onInit' in constructor.prototype)) {
|
|
7
63
|
throw new Error(`Class "${constructor.name}" does not implement IModule!`);
|
|
8
64
|
}
|
|
@@ -16,6 +72,9 @@ export function Module({ args = [], imports = [], postCommitHooks = [], postMode
|
|
|
16
72
|
preModelActionHooks,
|
|
17
73
|
preResourceActionHooks,
|
|
18
74
|
});
|
|
75
|
+
})
|
|
76
|
+
.catch((error) => {
|
|
77
|
+
EventService.getInstance().emit(new RegistrationErrorEvent(error));
|
|
19
78
|
});
|
|
20
79
|
};
|
|
21
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.decorator.js","sourceRoot":"","sources":["../../src/decorators/module.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module.decorator.js","sourceRoot":"","sources":["../../src/decorators/module.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGjE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,UAAU,MAAM,CAAC,EACrB,IAAI,GAAG,EAAE,EACT,OAAO,GAAG,EAAE,EACZ,eAAe,GAAG,EAAE,EACpB,oBAAoB,GAAG,EAAE,EACzB,uBAAuB,GAAG,EAAE,EAC5B,cAAc,GAAG,EAAE,EACnB,mBAAmB,GAAG,EAAE,EACxB,sBAAsB,GAAG,EAAE,GAwB5B;IACC,OAAO,UAAU,WAA4C;QAC3D,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC;aAC3B,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE;YACxB,kDAAkD;YAClD,IAAI,CAAC,CAAC,QAAQ,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;gBACzC,MAAM,IAAI,KAAK,CAAC,UAAU,WAAW,CAAC,IAAI,+BAA+B,CAAC,CAAC;YAC7E,CAAC;YAED,eAAe,CAAC,QAAQ,CAAC,WAAW,EAAE;gBACpC,IAAI;gBACJ,OAAO;gBACP,eAAe;gBACf,oBAAoB;gBACpB,uBAAuB;gBACvB,cAAc;gBACd,mBAAmB;gBACnB,sBAAsB;aACvB,CAAC,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,YAAY,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Constructable } from '../app.type.js';
|
|
2
|
+
import type { Event } from '../events/event.model.js';
|
|
3
|
+
/**
|
|
4
|
+
* An `@OnEvent` is a method decorator to listen to an event.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // Async handler.
|
|
9
|
+
* @OnEvent(MyEvent)
|
|
10
|
+
* async onEvent(event: MyEvent): Promise<void> { ... }
|
|
11
|
+
*
|
|
12
|
+
* // Sync handler.
|
|
13
|
+
* @OnEvent(MyEvent)
|
|
14
|
+
* onEvent(event: MyEvent): void { ... }
|
|
15
|
+
* ```
|
|
16
|
+
* @group Decorators
|
|
17
|
+
* @param ofType The type of event being listened to.
|
|
18
|
+
* @returns The decorated method.
|
|
19
|
+
*/
|
|
20
|
+
export declare function OnEvent(ofType: Constructable<Event<unknown>>): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventService } from '../services/event/event.service.js';
|
|
2
|
+
/**
|
|
3
|
+
* An `@OnEvent` is a method decorator to listen to an event.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // Async handler.
|
|
8
|
+
* @OnEvent(MyEvent)
|
|
9
|
+
* async onEvent(event: MyEvent): Promise<void> { ... }
|
|
10
|
+
*
|
|
11
|
+
* // Sync handler.
|
|
12
|
+
* @OnEvent(MyEvent)
|
|
13
|
+
* onEvent(event: MyEvent): void { ... }
|
|
14
|
+
* ```
|
|
15
|
+
* @group Decorators
|
|
16
|
+
* @param ofType The type of event being listened to.
|
|
17
|
+
* @returns The decorated method.
|
|
18
|
+
*/
|
|
19
|
+
export function OnEvent(ofType) {
|
|
20
|
+
return function (target, propertyKey, descriptor) {
|
|
21
|
+
EventService.getInstance().registerListeners(ofType, target, descriptor);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=on-event.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-event.decorator.js","sourceRoot":"","sources":["../../src/decorators/on-event.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CACrB,MAAqC;IAErC,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAC/E,YAAY,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An `@Overlay` is a class decorator to be placed on top of a class that represents an overlay.
|
|
3
|
+
* - An overlay must extend the {@link AOverlay} class.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* @Overlay()
|
|
8
|
+
* export class MyOverlay extends AOverlay<MyOverlay> { ... }
|
|
9
|
+
* ```
|
|
10
|
+
* @group Decorators
|
|
11
|
+
* @returns The decorated class.
|
|
12
|
+
* @see Definition of [Overlays](/docs/fundamentals/overlay-and-anchor).
|
|
13
|
+
*/
|
|
1
14
|
export declare function Overlay(): (constructor: any) => void;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { RegistrationErrorEvent } from '../events/error.event.js';
|
|
2
|
+
import { EventService } from '../services/event/event.service.js';
|
|
1
3
|
import { ModelSerializationService } from '../services/serialization/model/model-serialization.service.js';
|
|
2
4
|
import { Container } from './container.js';
|
|
5
|
+
/**
|
|
6
|
+
* An `@Overlay` is a class decorator to be placed on top of a class that represents an overlay.
|
|
7
|
+
* - An overlay must extend the {@link AOverlay} class.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* @Overlay()
|
|
12
|
+
* export class MyOverlay extends AOverlay<MyOverlay> { ... }
|
|
13
|
+
* ```
|
|
14
|
+
* @group Decorators
|
|
15
|
+
* @returns The decorated class.
|
|
16
|
+
* @see Definition of [Overlays](/docs/fundamentals/overlay-and-anchor).
|
|
17
|
+
*/
|
|
3
18
|
export function Overlay() {
|
|
4
19
|
return function (constructor) {
|
|
5
20
|
Container.get(ModelSerializationService)
|
|
@@ -7,7 +22,7 @@ export function Overlay() {
|
|
|
7
22
|
modelSerializationService.registerClass(constructor.name, constructor);
|
|
8
23
|
})
|
|
9
24
|
.catch((error) => {
|
|
10
|
-
|
|
25
|
+
EventService.getInstance().emit(new RegistrationErrorEvent(error));
|
|
11
26
|
});
|
|
12
27
|
};
|
|
13
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.decorator.js","sourceRoot":"","sources":["../../src/decorators/overlay.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,UAAU,OAAO;IACrB,OAAO,UAAU,WAAgB;QAC/B,SAAS,CAAC,GAAG,CAAC,yBAAyB,CAAC;aACrC,IAAI,CAAC,CAAC,yBAAyB,EAAE,EAAE;YAClC,yBAAyB,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QACzE,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,
|
|
1
|
+
{"version":3,"file":"overlay.decorator.js","sourceRoot":"","sources":["../../src/decorators/overlay.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,UAAU,WAAgB;QAC/B,SAAS,CAAC,GAAG,CAAC,yBAAyB,CAAC;aACrC,IAAI,CAAC,CAAC,yBAAyB,EAAE,EAAE;YAClC,yBAAyB,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QACzE,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,YAAY,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `@Resource` is a class decorator to be placed on top of a class that represents a resource.
|
|
3
|
+
* - A resource must extend the {@link AResource} class.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* @Resource()
|
|
8
|
+
* export class MyResource extends AResource<MyResource> { ... }
|
|
9
|
+
* ```
|
|
10
|
+
* @group Decorators
|
|
11
|
+
* @returns The decorated class.
|
|
12
|
+
* @see Definition of [Resources](http://localhost:3000/docs/fundamentals/resources).
|
|
13
|
+
*/
|
|
1
14
|
export declare function Resource(): (constructor: any) => void;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { RegistrationErrorEvent } from '../events/error.event.js';
|
|
2
|
+
import { EventService } from '../services/event/event.service.js';
|
|
1
3
|
import { ResourceSerializationService } from '../services/serialization/resource/resource-serialization.service.js';
|
|
2
4
|
import { Container } from './container.js';
|
|
5
|
+
/**
|
|
6
|
+
* A `@Resource` is a class decorator to be placed on top of a class that represents a resource.
|
|
7
|
+
* - A resource must extend the {@link AResource} class.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* @Resource()
|
|
12
|
+
* export class MyResource extends AResource<MyResource> { ... }
|
|
13
|
+
* ```
|
|
14
|
+
* @group Decorators
|
|
15
|
+
* @returns The decorated class.
|
|
16
|
+
* @see Definition of [Resources](http://localhost:3000/docs/fundamentals/resources).
|
|
17
|
+
*/
|
|
3
18
|
export function Resource() {
|
|
4
19
|
return function (constructor) {
|
|
5
20
|
Container.get(ResourceSerializationService)
|
|
@@ -7,7 +22,7 @@ export function Resource() {
|
|
|
7
22
|
resourceSerializationService.registerClass(constructor.name, constructor);
|
|
8
23
|
})
|
|
9
24
|
.catch((error) => {
|
|
10
|
-
|
|
25
|
+
EventService.getInstance().emit(new RegistrationErrorEvent(error));
|
|
11
26
|
});
|
|
12
27
|
};
|
|
13
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.decorator.js","sourceRoot":"","sources":["../../src/decorators/resource.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,sEAAsE,CAAC;AACpH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,UAAU,QAAQ;IACtB,OAAO,UAAU,WAAgB;QAC/B,SAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC;aACxC,IAAI,CAAC,CAAC,4BAA4B,EAAE,EAAE;YACrC,4BAA4B,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC5E,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,
|
|
1
|
+
{"version":3,"file":"resource.decorator.js","sourceRoot":"","sources":["../../src/decorators/resource.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,sEAAsE,CAAC;AACpH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,UAAU,WAAgB;QAC/B,SAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC;aACxC,IAAI,CAAC,CAAC,4BAA4B,EAAE,EAAE;YACrC,4BAA4B,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC5E,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,YAAY,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -18,10 +18,62 @@ export interface IPackageMock {
|
|
|
18
18
|
getMocks: () => FactoryMock<unknown>[];
|
|
19
19
|
init(): Promise<void>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The TestContainer class is an isolated {@link Container} for tests.
|
|
23
|
+
*
|
|
24
|
+
* :::info Info
|
|
25
|
+
* A test framework like Jest, supports parallel test executions in different cores of the machine.
|
|
26
|
+
* Each test is a single test file, whose `it()` blocks are executed serially.
|
|
27
|
+
* :::
|
|
28
|
+
*
|
|
29
|
+
* TestContainer is created with testing framework's parallel execution in mind.
|
|
30
|
+
* A TestContainer should be created in the `beforeAll()` block of your test,
|
|
31
|
+
* which modifies the Container for the duration of the test.
|
|
32
|
+
* This TestContainer does not affect other tests in parallel since they are on a separate machine core.
|
|
33
|
+
* Once tests are done executing, the `afterAll()` block cleans up the Container.
|
|
34
|
+
*/
|
|
21
35
|
export declare class TestContainer {
|
|
22
36
|
private static packageMocks;
|
|
23
37
|
private static createTestFactory;
|
|
38
|
+
/**
|
|
39
|
+
* The `TestContainer.create()` method allows you to mock factories.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* beforeAll(async () => {
|
|
44
|
+
* await TestContainer.create({
|
|
45
|
+
* importFrom: [OctoAwsCdkPackageMock],
|
|
46
|
+
* mocks: [
|
|
47
|
+
* { type: MyClass, value: jest.fn() },
|
|
48
|
+
* { metadata: { key: 'value' }, type: AnotherClass, value: new AnotherClass() },
|
|
49
|
+
* ],
|
|
50
|
+
* }, { factoryTimeoutInMs: 500 });
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
* @param subjects The subjects being mocked.
|
|
55
|
+
* - `importFrom` is an array of {@link IPackageMock} classes, to import custom mocks,
|
|
56
|
+
* such as from octo-aws-cdk package - [OctoAwsCdkPackageMock](/api/octo-aws-cdk/class/OctoAwsCdkPackageMock).
|
|
57
|
+
* - `mocks` is an array of objects, to override the default factories.
|
|
58
|
+
* - Use `metadata?: { [key: string]: string }` to identify the factory being mocked.
|
|
59
|
+
* - Use `type: Constructable<T> | string` to identify the class being mocked.
|
|
60
|
+
* - Use `value: T` to provide the mocked value.
|
|
61
|
+
* @param options Options to configure TestContainer.
|
|
62
|
+
* - `factoryTimeoutInMs?: number` is to override the default container timeout.
|
|
63
|
+
*/
|
|
24
64
|
static create(subjects: TestContainerSubjects, options?: TestContainerOptions): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* The `TestContainer.reset()` method will completely destroy all factories from the Container.
|
|
67
|
+
* Because the entire Container is destroyed, and not just the mocks,
|
|
68
|
+
* it must always be called in your `afterAll()` block.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* afterAll(async () => {
|
|
73
|
+
* await TestContainer.reset();
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
25
77
|
static reset(): Promise<void>;
|
|
26
78
|
}
|
|
27
79
|
export {};
|
|
@@ -1,15 +1,55 @@
|
|
|
1
1
|
import { DiffUtility } from '../functions/diff/diff.utility.js';
|
|
2
2
|
import { Container } from './container.js';
|
|
3
|
+
/**
|
|
4
|
+
* The TestContainer class is an isolated {@link Container} for tests.
|
|
5
|
+
*
|
|
6
|
+
* :::info Info
|
|
7
|
+
* A test framework like Jest, supports parallel test executions in different cores of the machine.
|
|
8
|
+
* Each test is a single test file, whose `it()` blocks are executed serially.
|
|
9
|
+
* :::
|
|
10
|
+
*
|
|
11
|
+
* TestContainer is created with testing framework's parallel execution in mind.
|
|
12
|
+
* A TestContainer should be created in the `beforeAll()` block of your test,
|
|
13
|
+
* which modifies the Container for the duration of the test.
|
|
14
|
+
* This TestContainer does not affect other tests in parallel since they are on a separate machine core.
|
|
15
|
+
* Once tests are done executing, the `afterAll()` block cleans up the Container.
|
|
16
|
+
*/
|
|
3
17
|
export class TestContainer {
|
|
4
|
-
static packageMocks = [];
|
|
18
|
+
static { this.packageMocks = []; }
|
|
5
19
|
static createTestFactory(mock) {
|
|
6
20
|
return class {
|
|
7
|
-
static mock = mock;
|
|
21
|
+
static { this.mock = mock; }
|
|
8
22
|
static async create() {
|
|
9
23
|
return this.mock.value;
|
|
10
24
|
}
|
|
11
25
|
};
|
|
12
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The `TestContainer.create()` method allows you to mock factories.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* beforeAll(async () => {
|
|
33
|
+
* await TestContainer.create({
|
|
34
|
+
* importFrom: [OctoAwsCdkPackageMock],
|
|
35
|
+
* mocks: [
|
|
36
|
+
* { type: MyClass, value: jest.fn() },
|
|
37
|
+
* { metadata: { key: 'value' }, type: AnotherClass, value: new AnotherClass() },
|
|
38
|
+
* ],
|
|
39
|
+
* }, { factoryTimeoutInMs: 500 });
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* ```
|
|
43
|
+
* @param subjects The subjects being mocked.
|
|
44
|
+
* - `importFrom` is an array of {@link IPackageMock} classes, to import custom mocks,
|
|
45
|
+
* such as from octo-aws-cdk package - [OctoAwsCdkPackageMock](/api/octo-aws-cdk/class/OctoAwsCdkPackageMock).
|
|
46
|
+
* - `mocks` is an array of objects, to override the default factories.
|
|
47
|
+
* - Use `metadata?: { [key: string]: string }` to identify the factory being mocked.
|
|
48
|
+
* - Use `type: Constructable<T> | string` to identify the class being mocked.
|
|
49
|
+
* - Use `value: T` to provide the mocked value.
|
|
50
|
+
* @param options Options to configure TestContainer.
|
|
51
|
+
* - `factoryTimeoutInMs?: number` is to override the default container timeout.
|
|
52
|
+
*/
|
|
13
53
|
static async create(subjects, options) {
|
|
14
54
|
const oldFactories = { ...Container['factories'] };
|
|
15
55
|
Container.reset();
|
|
@@ -42,6 +82,18 @@ export class TestContainer {
|
|
|
42
82
|
}
|
|
43
83
|
}
|
|
44
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The `TestContainer.reset()` method will completely destroy all factories from the Container.
|
|
87
|
+
* Because the entire Container is destroyed, and not just the mocks,
|
|
88
|
+
* it must always be called in your `afterAll()` block.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* afterAll(async () => {
|
|
93
|
+
* await TestContainer.reset();
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
45
97
|
static async reset() {
|
|
46
98
|
for (const mock of this.packageMocks) {
|
|
47
99
|
await mock.destroy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../src/decorators/test-container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAwB3C,MAAM,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../src/decorators/test-container.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationType } from '../app.type.js';
|
|
2
|
+
type ValidationOptions<T> = {
|
|
3
|
+
options: {
|
|
4
|
+
[key in ValidationType]?: any;
|
|
5
|
+
};
|
|
6
|
+
destruct?: (value: any) => T[];
|
|
7
|
+
};
|
|
8
|
+
export declare function Validate<T>(validators: ValidationOptions<T> | ValidationOptions<T>[]): (target: any, propertyKey: string) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ValidationService } from '../services/validation/validation.service.js';
|
|
2
|
+
export function Validate(validators) {
|
|
3
|
+
return function (target, propertyKey) {
|
|
4
|
+
const symbol = Symbol();
|
|
5
|
+
Object.defineProperty(target, propertyKey, {
|
|
6
|
+
get: function () {
|
|
7
|
+
return this[symbol];
|
|
8
|
+
},
|
|
9
|
+
set: function (newValue) {
|
|
10
|
+
if (!Array.isArray(validators)) {
|
|
11
|
+
validators = [validators];
|
|
12
|
+
}
|
|
13
|
+
for (const validator of validators) {
|
|
14
|
+
for (const [type, constraint] of Object.entries(validator.options)) {
|
|
15
|
+
ValidationService.getInstance().addSubject(type, constraint, target, propertyKey, newValue, validator.destruct);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
this[symbol] = newValue;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=validate.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.decorator.js","sourceRoot":"","sources":["../../src/decorators/validate.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAOjF,MAAM,UAAU,QAAQ,CACtB,UAAyD;IAEzD,OAAO,UAAU,MAAW,EAAE,WAAmB;QAC/C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;QAExB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YACzC,GAAG,EAAE;gBACH,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC;YACD,GAAG,EAAE,UAAU,QAAa;gBAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC/B,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC;gBAC5B,CAAC;gBAED,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;oBACnC,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;wBACnE,iBAAiB,CAAC,WAAW,EAAE,CAAC,UAAU,CACxC,IAAsB,EACtB,UAAU,EACV,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,CAAC,QAAQ,CACnB,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC;YAC1B,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Event } from './event.model.js';
|
|
2
|
+
/**
|
|
3
|
+
* The ErrorEvent class is the superclass for all events emitting an error.
|
|
4
|
+
* An error event is generated when Octo encounters an error.
|
|
5
|
+
*
|
|
6
|
+
* :::warning Warning
|
|
7
|
+
* It is not a good practice to create an event from this class directly,
|
|
8
|
+
* but should rather create one from one of the subclasses.
|
|
9
|
+
* This promotes a more accurate classification of events.
|
|
10
|
+
* :::
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const myEvent = new ErrorEvent(new Error('e'));
|
|
15
|
+
* EventService.getInstance().emit(myEvent);
|
|
16
|
+
* ```
|
|
17
|
+
* @group Events
|
|
18
|
+
* @returns The Event instance.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ErrorEvent extends Event<Error> {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This event is emitted at startup when a class fails to register.
|
|
24
|
+
* It emits the [Error](https://nodejs.org/api/errors.html) object.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const myEvent = new RegistrationErrorEvent(new Error('e'));
|
|
29
|
+
* EventService.getInstance().emit(myEvent);
|
|
30
|
+
* ```
|
|
31
|
+
* @group Events
|
|
32
|
+
* @returns The Event instance.
|
|
33
|
+
*/
|
|
34
|
+
export declare class RegistrationErrorEvent extends ErrorEvent {
|
|
35
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Event } from './event.model.js';
|
|
2
|
+
/**
|
|
3
|
+
* The ErrorEvent class is the superclass for all events emitting an error.
|
|
4
|
+
* An error event is generated when Octo encounters an error.
|
|
5
|
+
*
|
|
6
|
+
* :::warning Warning
|
|
7
|
+
* It is not a good practice to create an event from this class directly,
|
|
8
|
+
* but should rather create one from one of the subclasses.
|
|
9
|
+
* This promotes a more accurate classification of events.
|
|
10
|
+
* :::
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const myEvent = new ErrorEvent(new Error('e'));
|
|
15
|
+
* EventService.getInstance().emit(myEvent);
|
|
16
|
+
* ```
|
|
17
|
+
* @group Events
|
|
18
|
+
* @returns The Event instance.
|
|
19
|
+
*/
|
|
20
|
+
export class ErrorEvent extends Event {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This event is emitted at startup when a class fails to register.
|
|
24
|
+
* It emits the [Error](https://nodejs.org/api/errors.html) object.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const myEvent = new RegistrationErrorEvent(new Error('e'));
|
|
29
|
+
* EventService.getInstance().emit(myEvent);
|
|
30
|
+
* ```
|
|
31
|
+
* @group Events
|
|
32
|
+
* @returns The Event instance.
|
|
33
|
+
*/
|
|
34
|
+
export class RegistrationErrorEvent extends ErrorEvent {
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=error.event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.event.js","sourceRoot":"","sources":["../../src/events/error.event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAY;CAAG;AAE/C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,sBAAuB,SAAQ,UAAU;CAAG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EventService } from '../services/event/event.service.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Event class is the superclass for all events.
|
|
4
|
+
* An event is generated when something important happens in Octo.
|
|
5
|
+
* The body of the event contains a header, a payload, and an optional user data.
|
|
6
|
+
*
|
|
7
|
+
* :::warning Warning
|
|
8
|
+
* It is not a good practice to create an event from this class directly,
|
|
9
|
+
* but should rather create one from one of the subclasses.
|
|
10
|
+
* This promotes a more accurate classification of events.
|
|
11
|
+
* :::
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const myEvent = new Event<string>('my payload', { key: 'value' });
|
|
16
|
+
* EventService.getInstance().emit(myEvent);
|
|
17
|
+
* ```
|
|
18
|
+
* @group Events
|
|
19
|
+
* @returns The Event instance.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Event<T> {
|
|
22
|
+
readonly header: {
|
|
23
|
+
timestamp: number;
|
|
24
|
+
};
|
|
25
|
+
readonly payload: T;
|
|
26
|
+
readonly userData: object;
|
|
27
|
+
constructor(payload: T, userData?: object);
|
|
28
|
+
/**
|
|
29
|
+
* The `registrar()` method is explicitly called by the {@link EventSource} decorator for a method
|
|
30
|
+
* to enhance the method to auto-emit events.
|
|
31
|
+
*
|
|
32
|
+
* @param args Arguments are spread out using the array spread operator.
|
|
33
|
+
* - args[0] - Instance of {@link EventService}.
|
|
34
|
+
* - args[1] - [PropertyDescriptor](https://www.typescriptlang.org/docs/handbook/decorators.html).
|
|
35
|
+
*/
|
|
36
|
+
static registrar(...args: [EventService, PropertyDescriptor]): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Event class is the superclass for all events.
|
|
3
|
+
* An event is generated when something important happens in Octo.
|
|
4
|
+
* The body of the event contains a header, a payload, and an optional user data.
|
|
5
|
+
*
|
|
6
|
+
* :::warning Warning
|
|
7
|
+
* It is not a good practice to create an event from this class directly,
|
|
8
|
+
* but should rather create one from one of the subclasses.
|
|
9
|
+
* This promotes a more accurate classification of events.
|
|
10
|
+
* :::
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const myEvent = new Event<string>('my payload', { key: 'value' });
|
|
15
|
+
* EventService.getInstance().emit(myEvent);
|
|
16
|
+
* ```
|
|
17
|
+
* @group Events
|
|
18
|
+
* @returns The Event instance.
|
|
19
|
+
*/
|
|
20
|
+
export class Event {
|
|
21
|
+
constructor(payload, userData = {}) {
|
|
22
|
+
this.header = {
|
|
23
|
+
timestamp: Date.now(),
|
|
24
|
+
};
|
|
25
|
+
this.payload = payload;
|
|
26
|
+
this.userData = userData;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The `registrar()` method is explicitly called by the {@link EventSource} decorator for a method
|
|
30
|
+
* to enhance the method to auto-emit events.
|
|
31
|
+
*
|
|
32
|
+
* @param args Arguments are spread out using the array spread operator.
|
|
33
|
+
* - args[0] - Instance of {@link EventService}.
|
|
34
|
+
* - args[1] - [PropertyDescriptor](https://www.typescriptlang.org/docs/handbook/decorators.html).
|
|
35
|
+
*/
|
|
36
|
+
static registrar(...args) {
|
|
37
|
+
if (args.length !== 2) {
|
|
38
|
+
throw new Error('Invalid number of args in event registrar!');
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Method not implemented! Use derived class implementation');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=event.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.model.js","sourceRoot":"","sources":["../../src/events/event.model.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,KAAK;IAShB,YAAY,OAAU,EAAE,WAAmB,EAAE;QAC3C,IAAI,CAAC,MAAM,GAAG;YACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,IAAwC;QAC1D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;CACF"}
|