@magek/common 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/app.d.ts +17 -0
  2. package/dist/app.js +2 -0
  3. package/dist/concepts/authorizers.d.ts +7 -0
  4. package/dist/concepts/authorizers.js +2 -0
  5. package/dist/concepts/command.d.ts +14 -0
  6. package/dist/concepts/command.js +2 -0
  7. package/dist/concepts/data-migration.d.ts +19 -0
  8. package/dist/concepts/data-migration.js +8 -0
  9. package/dist/concepts/entity.d.ts +12 -0
  10. package/dist/concepts/entity.js +2 -0
  11. package/dist/concepts/event-handler.d.ts +6 -0
  12. package/dist/concepts/event-handler.js +2 -0
  13. package/dist/concepts/event-stream-configuration.d.ts +14 -0
  14. package/dist/concepts/event-stream-configuration.js +2 -0
  15. package/dist/concepts/event.d.ts +12 -0
  16. package/dist/concepts/event.js +2 -0
  17. package/dist/concepts/filter-hooks.d.ts +15 -0
  18. package/dist/concepts/filter-hooks.js +2 -0
  19. package/dist/concepts/global-error-handler-metadata.d.ts +24 -0
  20. package/dist/concepts/global-error-handler-metadata.js +2 -0
  21. package/dist/concepts/index.d.ts +21 -0
  22. package/dist/concepts/index.js +24 -0
  23. package/dist/concepts/migration.d.ts +8 -0
  24. package/dist/concepts/migration.js +2 -0
  25. package/dist/concepts/notification.d.ts +12 -0
  26. package/dist/concepts/notification.js +2 -0
  27. package/dist/concepts/projection-metadata.d.ts +15 -0
  28. package/dist/concepts/projection-metadata.js +8 -0
  29. package/dist/concepts/query.d.ts +21 -0
  30. package/dist/concepts/query.js +2 -0
  31. package/dist/concepts/read-model.d.ts +33 -0
  32. package/dist/concepts/read-model.js +8 -0
  33. package/dist/concepts/reducer-metadata.d.ts +5 -0
  34. package/dist/concepts/reducer-metadata.js +2 -0
  35. package/dist/concepts/register.d.ts +91 -0
  36. package/dist/concepts/register.js +84 -0
  37. package/dist/concepts/role.d.ts +27 -0
  38. package/dist/concepts/role.js +2 -0
  39. package/dist/concepts/scheduled-command.d.ts +10 -0
  40. package/dist/concepts/scheduled-command.js +2 -0
  41. package/dist/concepts/sequence-metadata.d.ts +5 -0
  42. package/dist/concepts/sequence-metadata.js +2 -0
  43. package/dist/concepts/token-verifier.d.ts +25 -0
  44. package/dist/concepts/token-verifier.js +2 -0
  45. package/dist/concepts/uuid.d.ts +18 -0
  46. package/dist/concepts/uuid.js +28 -0
  47. package/dist/config.d.ts +122 -0
  48. package/dist/config.js +180 -0
  49. package/dist/data-migration-parameters.d.ts +3 -0
  50. package/dist/data-migration-parameters.js +2 -0
  51. package/dist/envelope.d.ts +188 -0
  52. package/dist/envelope.js +2 -0
  53. package/dist/errors/command-handler-global-error.d.ts +8 -0
  54. package/dist/errors/command-handler-global-error.js +12 -0
  55. package/dist/errors/event-global-error.d.ts +6 -0
  56. package/dist/errors/event-global-error.js +11 -0
  57. package/dist/errors/event-handler-global-error.d.ts +9 -0
  58. package/dist/errors/event-handler-global-error.js +13 -0
  59. package/dist/errors/global-error-container.d.ts +4 -0
  60. package/dist/errors/global-error-container.js +9 -0
  61. package/dist/errors/index.d.ts +9 -0
  62. package/dist/errors/index.js +12 -0
  63. package/dist/errors/projection-global-error.d.ts +10 -0
  64. package/dist/errors/projection-global-error.js +14 -0
  65. package/dist/errors/query-handler-global-error.d.ts +6 -0
  66. package/dist/errors/query-handler-global-error.js +11 -0
  67. package/dist/errors/reducer-global-error.d.ts +10 -0
  68. package/dist/errors/reducer-global-error.js +14 -0
  69. package/dist/errors/schedule-command-global-error.d.ts +8 -0
  70. package/dist/errors/schedule-command-global-error.js +12 -0
  71. package/dist/errors/snapshot-persist-handler-global-error.d.ts +16 -0
  72. package/dist/errors/snapshot-persist-handler-global-error.js +21 -0
  73. package/dist/errors.d.ts +30 -0
  74. package/dist/errors.js +60 -0
  75. package/dist/event-store-adapter.d.ts +123 -0
  76. package/dist/event-store-adapter.js +2 -0
  77. package/dist/field-decorator.d.ts +63 -0
  78. package/dist/field-decorator.js +122 -0
  79. package/dist/graphql-websocket-messages.d.ts +65 -0
  80. package/dist/graphql-websocket-messages.js +55 -0
  81. package/dist/groups.d.ts +4 -0
  82. package/dist/groups.js +9 -0
  83. package/dist/http-service.d.ts +10 -0
  84. package/dist/http-service.js +50 -0
  85. package/dist/index.d.ts +30 -0
  86. package/dist/index.js +33 -0
  87. package/dist/instances.d.ts +47 -0
  88. package/dist/instances.js +136 -0
  89. package/dist/instrumentation/trace-types.d.ts +52 -0
  90. package/dist/instrumentation/trace-types.js +34 -0
  91. package/dist/internal-info.d.ts +2 -0
  92. package/dist/internal-info.js +6 -0
  93. package/dist/logger.d.ts +14 -0
  94. package/dist/logger.js +33 -0
  95. package/dist/metadata-types.d.ts +28 -0
  96. package/dist/metadata-types.js +12 -0
  97. package/dist/promises.d.ts +25 -0
  98. package/dist/promises.js +42 -0
  99. package/dist/provider/azure-configuration.d.ts +12 -0
  100. package/dist/provider/azure-configuration.js +4 -0
  101. package/dist/provider.d.ts +83 -0
  102. package/dist/provider.js +2 -0
  103. package/dist/read-model-store-adapter.d.ts +84 -0
  104. package/dist/read-model-store-adapter.js +2 -0
  105. package/dist/retrier.d.ts +12 -0
  106. package/dist/retrier.js +36 -0
  107. package/dist/rocket-loader.d.ts +7 -0
  108. package/dist/rocket-loader.js +21 -0
  109. package/dist/rockets.d.ts +10 -0
  110. package/dist/rockets.js +4 -0
  111. package/dist/run-command.d.ts +5 -0
  112. package/dist/run-command.js +48 -0
  113. package/dist/schedule.d.ts +8 -0
  114. package/dist/schedule.js +2 -0
  115. package/dist/searcher.d.ts +98 -0
  116. package/dist/searcher.js +79 -0
  117. package/dist/sensor/health-indicator-configuration.d.ts +60 -0
  118. package/dist/sensor/health-indicator-configuration.js +31 -0
  119. package/dist/session-store-adapter.d.ts +103 -0
  120. package/dist/session-store-adapter.js +2 -0
  121. package/dist/stream-types.d.ts +1 -0
  122. package/dist/stream-types.js +2 -0
  123. package/dist/super-kind.d.ts +2 -0
  124. package/dist/super-kind.js +5 -0
  125. package/dist/typelevel.d.ts +28 -0
  126. package/dist/typelevel.js +9 -0
  127. package/dist/user-app.d.ts +18 -0
  128. package/dist/user-app.js +2 -0
  129. package/package.json +66 -0
package/dist/app.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { MagekConfig, UUID, EntityInterface, Class, ReadModelInterface, Searcher, EventSearchParameters, EventSearchResponse, PaginatedEntitiesIdsResult, EventDeleteParameters } from '.';
2
+ /**
3
+ * `MagekApp` is the interface of the user-facing functions that
4
+ * the framework provides.
5
+ */
6
+ export interface MagekApp {
7
+ start(projectPath: string): void;
8
+ config: MagekConfig;
9
+ configure(environment: string, configurator: (config: MagekConfig) => void): void;
10
+ configureCurrentEnv(configurator: (config: MagekConfig) => void): void;
11
+ entity<TEntity extends EntityInterface>(entityName: Class<TEntity>, entityID: UUID): Promise<TEntity | undefined>;
12
+ readModel<TReadModel extends ReadModelInterface>(readModelClass: Class<TReadModel>): Searcher<TReadModel>;
13
+ events(request: EventSearchParameters): Promise<Array<EventSearchResponse>>;
14
+ entitiesIDs(entityTypeName: string, limit: number, afterCursor: Record<string, string> | undefined): Promise<PaginatedEntitiesIdsResult>;
15
+ deleteEvent(parameters: EventDeleteParameters): Promise<boolean>;
16
+ configuredEnvironments: Set<string>;
17
+ }
package/dist/app.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { EventSearchRequest, ReadModelRequestEnvelope, UserEnvelope, CommandEnvelope, QueryEnvelope, HealthEnvelope } from '../envelope';
2
+ import { ReadModelInterface } from './read-model';
3
+ export type CommandAuthorizer = (currentUser?: UserEnvelope, commandEnvelope?: CommandEnvelope) => Promise<void>;
4
+ export type QueryAuthorizer = (currentUser?: UserEnvelope, queryEnvelope?: QueryEnvelope) => Promise<void>;
5
+ export type HealthAuthorizer = (currentUser?: UserEnvelope, healthEnvelope?: HealthEnvelope) => Promise<void>;
6
+ export type ReadModelAuthorizer = (currentUser?: UserEnvelope, readModelRequestEnvelope?: ReadModelRequestEnvelope<ReadModelInterface>) => Promise<void>;
7
+ export type EventStreamAuthorizer = (currentUser?: UserEnvelope, eventSearchRequest?: EventSearchRequest) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { Class } from '../typelevel';
2
+ import { PropertyMetadata } from '../metadata-types';
3
+ import { Register, CommandAuthorizer, CommandFilterHooks } from './.';
4
+ export type CommandInput = Record<string, any>;
5
+ export interface CommandInterface<TCommand = unknown, THandleResult = unknown> extends Class<TCommand> {
6
+ handle(command: TCommand, register: Register): Promise<THandleResult>;
7
+ }
8
+ export interface CommandMetadata<TCommand = unknown> {
9
+ readonly class: CommandInterface<TCommand>;
10
+ readonly properties: Array<PropertyMetadata>;
11
+ readonly methods: Array<PropertyMetadata>;
12
+ readonly authorizer: CommandAuthorizer;
13
+ readonly before: NonNullable<CommandFilterHooks['before']>;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { AnyClass } from '../typelevel';
2
+ import { Register } from './register';
3
+ import { DataMigrationParameters } from '../data-migration-parameters';
4
+ export declare enum DataMigrationStatus {
5
+ 'RUNNING' = 0,
6
+ 'FINISHED' = 1
7
+ }
8
+ export interface DataMigrationInterface extends AnyClass {
9
+ start(register: Register): Promise<void>;
10
+ }
11
+ export interface DataMigrationMetadata {
12
+ readonly class: DataMigrationInterface;
13
+ migrationOptions: DataMigrationParameters;
14
+ }
15
+ export interface MagekDataMigrationEntityDuration {
16
+ start: string;
17
+ end?: string;
18
+ elapsedMilliseconds?: number;
19
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataMigrationStatus = void 0;
4
+ var DataMigrationStatus;
5
+ (function (DataMigrationStatus) {
6
+ DataMigrationStatus[DataMigrationStatus["RUNNING"] = 0] = "RUNNING";
7
+ DataMigrationStatus[DataMigrationStatus["FINISHED"] = 1] = "FINISHED";
8
+ })(DataMigrationStatus || (exports.DataMigrationStatus = DataMigrationStatus = {}));
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Holds information about a user class annotated with `@Entity`
3
+ */
4
+ import { Class } from '../typelevel';
5
+ import { EventStreamAuthorizer, UUID } from '.';
6
+ export interface EntityInterface {
7
+ id: UUID;
8
+ }
9
+ export interface EntityMetadata {
10
+ readonly class: Class<EntityInterface>;
11
+ readonly eventStreamAuthorizer: EventStreamAuthorizer;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { Register } from './register';
2
+ import { EventInterface } from './event';
3
+ import { NotificationInterface } from './notification';
4
+ export interface EventHandlerInterface {
5
+ handle(event: EventInterface | NotificationInterface, register: Register): Promise<void>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ export type EventStreamConfiguration = {
2
+ enabled: true;
3
+ parameters: {
4
+ streamTopic: string;
5
+ partitionCount: number;
6
+ messageRetention: number;
7
+ dedupTtl?: number;
8
+ maxRetries?: number;
9
+ mode?: 'exponential' | 'fixed';
10
+ };
11
+ } | {
12
+ enabled: false;
13
+ parameters?: never;
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { UUID } from './uuid';
2
+ import { Class } from '../typelevel';
3
+ /**
4
+ * An `Event` is a fact that has happened in your system.
5
+ * All Event classes of your application must implement this interface.
6
+ */
7
+ export interface EventInterface {
8
+ entityID: () => UUID;
9
+ }
10
+ export interface EventMetadata {
11
+ readonly class: Class<EventInterface>;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import { QueryInput, ReadModelInterface } from '.';
2
+ import { UserEnvelope, ReadModelRequestEnvelope } from '../envelope';
3
+ import { CommandInput } from './command';
4
+ export interface CommandFilterHooks {
5
+ readonly before?: Array<CommandBeforeFunction>;
6
+ }
7
+ export type CommandBeforeFunction = (input: CommandInput, currentUser?: UserEnvelope) => Promise<CommandInput>;
8
+ export interface ReadModelFilterHooks<TReadModel extends ReadModelInterface = ReadModelInterface> {
9
+ readonly before?: Array<ReadModelBeforeFunction<TReadModel>>;
10
+ }
11
+ export type ReadModelBeforeFunction<TReadModel extends ReadModelInterface = ReadModelInterface> = (readModelRequestEnvelope: ReadModelRequestEnvelope<TReadModel>, currentUser?: UserEnvelope) => Promise<ReadModelRequestEnvelope<TReadModel>>;
12
+ export interface QueryFilterHooks {
13
+ readonly before?: Array<QueryBeforeFunction>;
14
+ }
15
+ export type QueryBeforeFunction = (input: QueryInput, currentUser?: UserEnvelope) => Promise<QueryInput>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ import { AnyClass } from '../typelevel';
2
+ import { CommandEnvelope, EntitySnapshotEnvelope, EventEnvelope, NonPersistedEntitySnapshotEnvelope, QueryEnvelope, ScheduledCommandEnvelope } from '../envelope';
3
+ import { EventInterface } from './event';
4
+ import { ReadModelInterface } from './read-model';
5
+ import { EntityInterface } from './entity';
6
+ import { ReducerMetadata } from './reducer-metadata';
7
+ import { ScheduledCommandMetadata } from './scheduled-command';
8
+ import { CommandMetadata } from './command';
9
+ import { ProjectionMetadata } from './projection-metadata';
10
+ import { NotificationInterface } from './notification';
11
+ export interface GlobalErrorHandlerInterface extends AnyClass {
12
+ onCommandHandlerError?(error: Error, commandEnvelope: CommandEnvelope, commandMetadata: CommandMetadata): Promise<Error | undefined>;
13
+ onQueryHandlerError?(error: Error, query: QueryEnvelope): Promise<Error | undefined>;
14
+ onScheduledCommandHandlerError?(error: Error, scheduledCommandEnvelope: ScheduledCommandEnvelope, scheduledCommandMetadata: ScheduledCommandMetadata): Promise<Error | undefined>;
15
+ onDispatchEventHandlerError?(error: Error, eventEnvelope: EventEnvelope | NotificationInterface, eventHandlerMetadata: unknown, eventInstance: EventInterface): Promise<Error | undefined>;
16
+ onReducerError?(error: Error, eventEnvelope: EventEnvelope, reducerMetadata: ReducerMetadata, eventInstance: EventInterface, snapshotInstance: EntityInterface | null): Promise<Error>;
17
+ onProjectionError?(error: Error, entityEnvelope: EntitySnapshotEnvelope, projectionMetadata: ProjectionMetadata<EntityInterface, ReadModelInterface>, entity: EntityInterface, readModel: ReadModelInterface | undefined): Promise<Error | undefined>;
18
+ onSnapshotPersistError?(error: Error, snapshot: NonPersistedEntitySnapshotEnvelope): Promise<Error | undefined>;
19
+ onEventError?(error: Error, eventEnvelope: EventEnvelope): Promise<Error | undefined>;
20
+ onError?(error: Error | undefined): Promise<Error | undefined>;
21
+ }
22
+ export interface GlobalErrorHandlerMetadata {
23
+ readonly class: GlobalErrorHandlerInterface;
24
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ export * from './authorizers';
2
+ export * from './command';
3
+ export * from './query';
4
+ export * from './data-migration';
5
+ export * from './entity';
6
+ export * from './event';
7
+ export * from './event-handler';
8
+ export * from './filter-hooks';
9
+ export * from './global-error-handler-metadata';
10
+ export * from './migration';
11
+ export * from './notification';
12
+ export * from './projection-metadata';
13
+ export * from './read-model';
14
+ export * from './reducer-metadata';
15
+ export * from './register';
16
+ export * from './role';
17
+ export * from './scheduled-command';
18
+ export * from './sequence-metadata';
19
+ export * from './token-verifier';
20
+ export * from './uuid';
21
+ export * from './event-stream-configuration';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./authorizers"), exports);
5
+ tslib_1.__exportStar(require("./command"), exports);
6
+ tslib_1.__exportStar(require("./query"), exports);
7
+ tslib_1.__exportStar(require("./data-migration"), exports);
8
+ tslib_1.__exportStar(require("./entity"), exports);
9
+ tslib_1.__exportStar(require("./event"), exports);
10
+ tslib_1.__exportStar(require("./event-handler"), exports);
11
+ tslib_1.__exportStar(require("./filter-hooks"), exports);
12
+ tslib_1.__exportStar(require("./global-error-handler-metadata"), exports);
13
+ tslib_1.__exportStar(require("./migration"), exports);
14
+ tslib_1.__exportStar(require("./notification"), exports);
15
+ tslib_1.__exportStar(require("./projection-metadata"), exports);
16
+ tslib_1.__exportStar(require("./read-model"), exports);
17
+ tslib_1.__exportStar(require("./reducer-metadata"), exports);
18
+ tslib_1.__exportStar(require("./register"), exports);
19
+ tslib_1.__exportStar(require("./role"), exports);
20
+ tslib_1.__exportStar(require("./scheduled-command"), exports);
21
+ tslib_1.__exportStar(require("./sequence-metadata"), exports);
22
+ tslib_1.__exportStar(require("./token-verifier"), exports);
23
+ tslib_1.__exportStar(require("./uuid"), exports);
24
+ tslib_1.__exportStar(require("./event-stream-configuration"), exports);
@@ -0,0 +1,8 @@
1
+ import { AnyClass } from '../typelevel';
2
+ export interface SchemaMigrationMetadata {
3
+ migrationClass: AnyClass;
4
+ methodName: string;
5
+ toVersion: number;
6
+ fromSchema: AnyClass;
7
+ toSchema: AnyClass;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { Class } from '../typelevel';
2
+ /**
3
+ * All Notification classes of your application must implement this interface.
4
+ */
5
+ export type NotificationInterface = {
6
+ partitionId?: string;
7
+ topic?: string;
8
+ [key: string]: any;
9
+ };
10
+ export interface NotificationMetadata {
11
+ readonly class: Class<NotificationInterface>;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import { AnyClass } from '../typelevel';
2
+ import { ReadModelInterface } from './read-model';
3
+ import { EntityInterface } from './entity';
4
+ import { FilterFor } from '../searcher';
5
+ export type ReadModelJoinKeyFunction<TEntity extends EntityInterface, TReadModel extends ReadModelInterface> = (entity: TEntity) => FilterFor<TReadModel> | undefined;
6
+ export interface ProjectionMetadata<TEntity extends EntityInterface, TReadModel extends ReadModelInterface> {
7
+ class: AnyClass;
8
+ methodName: string;
9
+ joinKey: keyof TEntity | ReadModelJoinKeyFunction<TEntity, TReadModel>;
10
+ }
11
+ export type ProjectionResult<TReadModel> = TReadModel | ReadModelAction;
12
+ export declare enum ReadModelAction {
13
+ Delete = 0,
14
+ Nothing = 1
15
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReadModelAction = void 0;
4
+ var ReadModelAction;
5
+ (function (ReadModelAction) {
6
+ ReadModelAction[ReadModelAction["Delete"] = 0] = "Delete";
7
+ ReadModelAction[ReadModelAction["Nothing"] = 1] = "Nothing";
8
+ })(ReadModelAction || (exports.ReadModelAction = ReadModelAction = {}));
@@ -0,0 +1,21 @@
1
+ import { Class } from '../typelevel';
2
+ import { PropertyMetadata } from '../metadata-types';
3
+ import { QueryAuthorizer, QueryFilterHooks, UUID } from './.';
4
+ import { ContextEnvelope, UserEnvelope } from '../envelope';
5
+ export type QueryInput = Record<string, any>;
6
+ export interface QueryInterface<TQuery = unknown, THandleResult = unknown> extends Class<TQuery> {
7
+ handle(query: TQuery, queryInfo?: QueryInfo): Promise<THandleResult>;
8
+ }
9
+ export interface QueryMetadata<TCommand = unknown> {
10
+ readonly class: QueryInterface<TCommand>;
11
+ readonly properties: Array<PropertyMetadata>;
12
+ readonly methods: Array<PropertyMetadata>;
13
+ readonly authorizer: QueryAuthorizer;
14
+ readonly before: NonNullable<QueryFilterHooks['before']>;
15
+ }
16
+ export interface QueryInfo {
17
+ requestID: UUID;
18
+ responseHeaders: Record<string, string>;
19
+ currentUser?: UserEnvelope;
20
+ context?: ContextEnvelope;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,33 @@
1
+ import { ReadModelAuthorizer, ReadModelFilterHooks, UUID } from '.';
2
+ import { Class } from '../typelevel';
3
+ import { PropertyMetadata } from '../metadata-types';
4
+ export interface MagekMetadata {
5
+ version: number;
6
+ schemaVersion: number;
7
+ optimisticConcurrencyValue?: string | number;
8
+ lastUpdateAt?: string;
9
+ lastProjectionInfo?: {
10
+ entityId: string;
11
+ entityName: string;
12
+ entityUpdatedAt: string;
13
+ projectionMethod: string;
14
+ };
15
+ }
16
+ export interface ReadModelInterface {
17
+ id: UUID;
18
+ magekMetadata?: MagekMetadata;
19
+ [key: string]: any;
20
+ }
21
+ export interface ReadModelMetadata<TReadModel extends ReadModelInterface = ReadModelInterface> {
22
+ readonly class: Class<ReadModelInterface>;
23
+ readonly properties: Array<PropertyMetadata>;
24
+ readonly authorizer: ReadModelAuthorizer;
25
+ readonly before: NonNullable<ReadModelFilterHooks<TReadModel>['before']>;
26
+ }
27
+ export declare enum ProjectionInfoReason {
28
+ ENTITY_PROJECTED = 0,
29
+ ENTITY_DELETED = 1
30
+ }
31
+ export interface ProjectionInfo {
32
+ reason: ProjectionInfoReason;
33
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectionInfoReason = void 0;
4
+ var ProjectionInfoReason;
5
+ (function (ProjectionInfoReason) {
6
+ ProjectionInfoReason[ProjectionInfoReason["ENTITY_PROJECTED"] = 0] = "ENTITY_PROJECTED";
7
+ ProjectionInfoReason[ProjectionInfoReason["ENTITY_DELETED"] = 1] = "ENTITY_DELETED";
8
+ })(ProjectionInfoReason || (exports.ProjectionInfoReason = ProjectionInfoReason = {}));
@@ -0,0 +1,5 @@
1
+ import { AnyClass } from '..';
2
+ export interface ReducerMetadata {
3
+ class: AnyClass;
4
+ methodName: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,91 @@
1
+ import { EventInterface } from './event';
2
+ import { UserEnvelope, ContextEnvelope } from '../envelope';
3
+ import { UUID } from './uuid';
4
+ import { NotificationInterface } from './notification';
5
+ export type FlusherFunction = (record: Register) => Promise<void>;
6
+ /**
7
+ * Object injected by Magek in all command or event handlers to interact with the execution
8
+ * context. By default, the events registered won't be stored until the handler has finished,
9
+ * but you can force the storage by calling the `register.flush()` method.
10
+ *
11
+ * Example:
12
+ * ```typescript
13
+ * public handle(register: Register): void {
14
+ * //...
15
+ * register.events(new CartItemChanged(cart, this.sku, this.quantity))
16
+ * if (this.hasPromotion()) {
17
+ * if (this.isEmpty()) {
18
+ * throw new Error("Added a promotion to an empty cart")
19
+ * } else {
20
+ * register.commands(new ApplyPromoToCart(this.promo, cart)
21
+ * }
22
+ * }
23
+ * // ...
24
+ * }
25
+ * ```
26
+ */
27
+ export declare class Register {
28
+ /** Unique request identifier. This identifier is propagated automatically by Magek
29
+ * to all the events generated during a request, as well as all subsequent events
30
+ * generated by event handlers. This identifier can be used as a correlation
31
+ * identifier to build the event tree coming from a single request. */
32
+ readonly requestID: UUID;
33
+ /** In the context of a command handler, the `responseHeaders` object contains the headers
34
+ * that will be returned to the client in the response. You can use this object to set
35
+ * custom headers or alter the default ones. */
36
+ readonly responseHeaders: Record<string, string>;
37
+ /** Private flusher function that will be called when the flush method is called. This property
38
+ * is reserved to be used internally by Magek. */
39
+ private flusher;
40
+ /** Object that references the current user. This property is initialized by Magek in a command,
41
+ * and in the same way as the `requestID` property, it is propagated to all the events generated
42
+ * afterwards. */
43
+ readonly currentUser?: UserEnvelope | undefined;
44
+ /** In the context of a command handler, the `context` object contains the context of the request. */
45
+ readonly context?: ContextEnvelope | undefined;
46
+ readonly eventList: Array<EventInterface | NotificationInterface>;
47
+ /**
48
+ * Creates a new instance of Register
49
+ *
50
+ * @param {UUID} requestID - The ID of the current request
51
+ * @param {Record<string, string>} responseHeaders - The response headers object. It can be changed by the user.
52
+ * @param {FlusherFunction} flusher - The provider-dependent function used to flush the events to the event store.
53
+ * @param {UserEnvelope} [currentUser] - The current user envelope, if available
54
+ * @param {ContextEnvelope} [context] - The current context envelope, if available
55
+ */
56
+ constructor(
57
+ /** Unique request identifier. This identifier is propagated automatically by Magek
58
+ * to all the events generated during a request, as well as all subsequent events
59
+ * generated by event handlers. This identifier can be used as a correlation
60
+ * identifier to build the event tree coming from a single request. */
61
+ requestID: UUID,
62
+ /** In the context of a command handler, the `responseHeaders` object contains the headers
63
+ * that will be returned to the client in the response. You can use this object to set
64
+ * custom headers or alter the default ones. */
65
+ responseHeaders: Record<string, string>,
66
+ /** Private flusher function that will be called when the flush method is called. This property
67
+ * is reserved to be used internally by Magek. */
68
+ flusher: FlusherFunction,
69
+ /** Object that references the current user. This property is initialized by Magek in a command,
70
+ * and in the same way as the `requestID` property, it is propagated to all the events generated
71
+ * afterwards. */
72
+ currentUser?: UserEnvelope | undefined,
73
+ /** In the context of a command handler, the `context` object contains the context of the request. */
74
+ context?: ContextEnvelope | undefined);
75
+ /**
76
+ * Register a list of events to be added to the event-store on handler completion
77
+ *
78
+ * @param {...Array<EventInterface|NotificationInterface>} events - The events to register
79
+ * @returns {Register} The current Register instance, so the calls to events and/or flush can be chained.
80
+ */
81
+ events(...events: Array<EventInterface | NotificationInterface>): Register;
82
+ /**
83
+ * Flushes the accumulated events and commands to the event store using the provider-depdent flusher function.
84
+ * This method can be called from a command or event handler to force the persistion of the events
85
+ * to the event store. After the events have been flushed, the eventList is cleared, so the same
86
+ * register instance can be used to register more events.
87
+ *
88
+ * @returns {Promise<void>} A Promise that resolves when the flush operation is complete
89
+ */
90
+ flush(): Promise<void>;
91
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Register = void 0;
4
+ /**
5
+ * Object injected by Magek in all command or event handlers to interact with the execution
6
+ * context. By default, the events registered won't be stored until the handler has finished,
7
+ * but you can force the storage by calling the `register.flush()` method.
8
+ *
9
+ * Example:
10
+ * ```typescript
11
+ * public handle(register: Register): void {
12
+ * //...
13
+ * register.events(new CartItemChanged(cart, this.sku, this.quantity))
14
+ * if (this.hasPromotion()) {
15
+ * if (this.isEmpty()) {
16
+ * throw new Error("Added a promotion to an empty cart")
17
+ * } else {
18
+ * register.commands(new ApplyPromoToCart(this.promo, cart)
19
+ * }
20
+ * }
21
+ * // ...
22
+ * }
23
+ * ```
24
+ */
25
+ class Register {
26
+ /**
27
+ * Creates a new instance of Register
28
+ *
29
+ * @param {UUID} requestID - The ID of the current request
30
+ * @param {Record<string, string>} responseHeaders - The response headers object. It can be changed by the user.
31
+ * @param {FlusherFunction} flusher - The provider-dependent function used to flush the events to the event store.
32
+ * @param {UserEnvelope} [currentUser] - The current user envelope, if available
33
+ * @param {ContextEnvelope} [context] - The current context envelope, if available
34
+ */
35
+ constructor(
36
+ /** Unique request identifier. This identifier is propagated automatically by Magek
37
+ * to all the events generated during a request, as well as all subsequent events
38
+ * generated by event handlers. This identifier can be used as a correlation
39
+ * identifier to build the event tree coming from a single request. */
40
+ requestID,
41
+ /** In the context of a command handler, the `responseHeaders` object contains the headers
42
+ * that will be returned to the client in the response. You can use this object to set
43
+ * custom headers or alter the default ones. */
44
+ responseHeaders,
45
+ /** Private flusher function that will be called when the flush method is called. This property
46
+ * is reserved to be used internally by Magek. */
47
+ flusher,
48
+ /** Object that references the current user. This property is initialized by Magek in a command,
49
+ * and in the same way as the `requestID` property, it is propagated to all the events generated
50
+ * afterwards. */
51
+ currentUser,
52
+ /** In the context of a command handler, the `context` object contains the context of the request. */
53
+ context) {
54
+ this.requestID = requestID;
55
+ this.responseHeaders = responseHeaders;
56
+ this.flusher = flusher;
57
+ this.currentUser = currentUser;
58
+ this.context = context;
59
+ this.eventList = [];
60
+ }
61
+ /**
62
+ * Register a list of events to be added to the event-store on handler completion
63
+ *
64
+ * @param {...Array<EventInterface|NotificationInterface>} events - The events to register
65
+ * @returns {Register} The current Register instance, so the calls to events and/or flush can be chained.
66
+ */
67
+ events(...events) {
68
+ this.eventList.push(...events);
69
+ return this;
70
+ }
71
+ /**
72
+ * Flushes the accumulated events and commands to the event store using the provider-depdent flusher function.
73
+ * This method can be called from a command or event handler to force the persistion of the events
74
+ * to the event store. After the events have been flushed, the eventList is cleared, so the same
75
+ * register instance can be used to register more events.
76
+ *
77
+ * @returns {Promise<void>} A Promise that resolves when the flush operation is complete
78
+ */
79
+ async flush() {
80
+ await this.flusher(this);
81
+ this.eventList.length = 0;
82
+ }
83
+ }
84
+ exports.Register = Register;
@@ -0,0 +1,27 @@
1
+ import { Class } from '../typelevel';
2
+ import { CommandAuthorizer, EventStreamAuthorizer, HealthAuthorizer, QueryAuthorizer, ReadModelAuthorizer } from './authorizers';
3
+ export interface RoleInterface {
4
+ }
5
+ export interface RoleMetadata {
6
+ readonly auth: AuthMetadata;
7
+ }
8
+ export type SignUpMethod = 'email' | 'phone';
9
+ export interface AuthMetadata {
10
+ readonly signUpMethods?: Array<SignUpMethod>;
11
+ readonly skipConfirmation?: boolean;
12
+ }
13
+ export interface CommandRoleAccess {
14
+ readonly authorize?: 'all' | Array<Class<RoleInterface>> | CommandAuthorizer;
15
+ }
16
+ export interface QueryRoleAccess {
17
+ readonly authorize?: 'all' | Array<Class<RoleInterface>> | QueryAuthorizer;
18
+ }
19
+ export interface HealthRoleAccess {
20
+ authorize?: 'all' | Array<Class<RoleInterface>> | HealthAuthorizer;
21
+ }
22
+ export interface ReadModelRoleAccess {
23
+ readonly authorize?: 'all' | Array<Class<RoleInterface>> | ReadModelAuthorizer;
24
+ }
25
+ export interface EventStreamRoleAccess {
26
+ readonly authorizeReadEvents: 'all' | Array<Class<RoleInterface>> | EventStreamAuthorizer;
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { AnyClass } from '../typelevel';
2
+ import { ScheduleInterface } from '../schedule';
3
+ import { Register } from './register';
4
+ export interface ScheduledCommandInterface extends AnyClass {
5
+ handle(register: Register): Promise<void>;
6
+ }
7
+ export interface ScheduledCommandMetadata {
8
+ readonly class: ScheduledCommandInterface;
9
+ readonly scheduledOn: ScheduleInterface;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { TimeKey } from './uuid';
2
+ export interface SequenceKey {
3
+ name: string;
4
+ value: TimeKey;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });