@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
@@ -0,0 +1,25 @@
1
+ import { UserEnvelope } from '../envelope';
2
+ export interface DecodedToken {
3
+ header: {
4
+ kid: string;
5
+ [key: string]: any;
6
+ };
7
+ payload: {
8
+ sub: string;
9
+ email?: string;
10
+ phone_number?: string;
11
+ [key: string]: any;
12
+ };
13
+ }
14
+ export interface TokenVerifier {
15
+ /**
16
+ * Verify asd deserialize a stringified token with this token verifier.
17
+ * @param token The token to verify
18
+ */
19
+ verify(token: string): Promise<DecodedToken>;
20
+ /**
21
+ * Build a valid `UserEnvelope` from a decoded token.
22
+ * @param decodedToken The decoded token
23
+ */
24
+ toUserEnvelope(decodedToken: DecodedToken): UserEnvelope;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `UUID` type to work globally as a identifier for Entities,
3
+ * Commands, Events or any other magek artifact.
4
+ * New unique identifiers can be created using the
5
+ * `UUID.generate` method.
6
+ */
7
+ export declare class UUID extends String {
8
+ static generate(): UUID;
9
+ }
10
+ /** Time-based unique identifier. It's a string in the form <timestamp>-<random UUID>. */
11
+ export declare class TimeKey extends String {
12
+ /**
13
+ * Time-based unique identifier generator
14
+ * @param moment Number of milliseconds since epoch for the moment in which the identifier should be generated. It defaults to the current time.
15
+ * @returns A unique identifier in the form "<moment>-<random UUID>"
16
+ */
17
+ static generate(moment?: number): TimeKey;
18
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeKey = exports.UUID = void 0;
4
+ const uuid_1 = require("uuid");
5
+ /**
6
+ * `UUID` type to work globally as a identifier for Entities,
7
+ * Commands, Events or any other magek artifact.
8
+ * New unique identifiers can be created using the
9
+ * `UUID.generate` method.
10
+ */
11
+ class UUID extends String {
12
+ static generate() {
13
+ return (0, uuid_1.v4)();
14
+ }
15
+ }
16
+ exports.UUID = UUID;
17
+ /** Time-based unique identifier. It's a string in the form <timestamp>-<random UUID>. */
18
+ class TimeKey extends String {
19
+ /**
20
+ * Time-based unique identifier generator
21
+ * @param moment Number of milliseconds since epoch for the moment in which the identifier should be generated. It defaults to the current time.
22
+ * @returns A unique identifier in the form "<moment>-<random UUID>"
23
+ */
24
+ static generate(moment = Date.now()) {
25
+ return `${moment}-${(0, uuid_1.v4)()}`;
26
+ }
27
+ }
28
+ exports.TimeKey = TimeKey;
@@ -0,0 +1,122 @@
1
+ import { CommandMetadata, DataMigrationMetadata, EntityInterface, EntityMetadata, EventHandlerInterface, EventMetadata, EventStreamConfiguration, GlobalErrorHandlerMetadata, NotificationMetadata, ProjectionMetadata, QueryMetadata, ReadModelInterface, ReadModelMetadata, ReducerMetadata, RoleMetadata, ScheduledCommandMetadata, SchemaMigrationMetadata, TokenVerifier } from './concepts';
2
+ import { ProviderLibrary } from './provider';
3
+ import { EventStoreAdapter } from './event-store-adapter';
4
+ import { ReadModelStoreAdapter } from './read-model-store-adapter';
5
+ import { SessionStoreAdapter } from './session-store-adapter';
6
+ import { Level } from './logger';
7
+ import { HealthIndicatorMetadata, Logger, SensorConfiguration } from '.';
8
+ import { TraceConfiguration } from './instrumentation/trace-types';
9
+ /**
10
+ * Class used by external packages that needs to get a representation of
11
+ * the Magek config. Used mainly for vendor-specific deployment packages
12
+ */
13
+ export declare class MagekConfig {
14
+ readonly environmentName: string;
15
+ logLevel: Level;
16
+ logPrefix?: string;
17
+ logger?: Logger;
18
+ private _provider?;
19
+ eventStoreAdapter?: EventStoreAdapter;
20
+ readModelStoreAdapter?: ReadModelStoreAdapter;
21
+ sessionStoreAdapter?: SessionStoreAdapter;
22
+ appName: string;
23
+ assets?: Array<string>;
24
+ defaultResponseHeaders: Record<string, string>;
25
+ injectable?: unknown;
26
+ readonly subscriptions: {
27
+ maxConnectionDurationInSeconds: number;
28
+ maxDurationInSeconds: number;
29
+ };
30
+ enableGraphQLIntrospection: boolean;
31
+ private _userProjectRootPath?;
32
+ readonly codeRelativePath: string;
33
+ readonly eventDispatcherHandler: string;
34
+ readonly eventStreamConsumer: string;
35
+ readonly eventStreamProducer: string;
36
+ readonly serveGraphQLHandler: string;
37
+ readonly sensorHealthHandler: string;
38
+ readonly scheduledTaskHandler: string;
39
+ readonly notifySubscribersHandler: string;
40
+ readonly functionRelativePath: string;
41
+ readonly events: Record<EventName, EventMetadata>;
42
+ readonly notifications: Record<EventName, NotificationMetadata>;
43
+ readonly partitionKeys: Record<EventName, string>;
44
+ readonly topicToEvent: Record<string, EventName>;
45
+ readonly eventToTopic: Record<EventName, string>;
46
+ readonly entities: Record<EntityName, EntityMetadata>;
47
+ readonly reducers: Record<EventName, ReducerMetadata>;
48
+ readonly commandHandlers: Record<CommandName, CommandMetadata>;
49
+ readonly queryHandlers: Record<QueryName, QueryMetadata>;
50
+ readonly eventHandlers: Record<EventName, Array<EventHandlerInterface>>;
51
+ readonly readModels: Record<ReadModelName, ReadModelMetadata>;
52
+ readonly projections: Record<EntityName, Array<ProjectionMetadata<EntityInterface, ReadModelInterface>>>;
53
+ readonly unProjections: Record<EntityName, Array<ProjectionMetadata<EntityInterface, ReadModelInterface>>>;
54
+ readonly readModelSequenceKeys: Record<EntityName, string>;
55
+ readonly roles: Record<RoleName, RoleMetadata>;
56
+ readonly schemaMigrations: Record<ConceptName, Map<Version, SchemaMigrationMetadata>>;
57
+ readonly scheduledCommandHandlers: Record<ScheduledCommandName, ScheduledCommandMetadata>;
58
+ readonly dataMigrationHandlers: Record<DataMigrationName, DataMigrationMetadata>;
59
+ userHealthIndicators: Record<string, HealthIndicatorMetadata>;
60
+ readonly sensorConfiguration: SensorConfiguration;
61
+ globalErrorsHandler: GlobalErrorHandlerMetadata | undefined;
62
+ enableSubscriptions: boolean;
63
+ readonly nonExposedGraphQLMetadataKey: Record<string, Array<string>>;
64
+ dispatchedEventsTtl: number;
65
+ traceConfiguration: TraceConfiguration;
66
+ eventStreamConfiguration: EventStreamConfiguration;
67
+ /** Environment variables to set when running the application */
68
+ readonly env: Record<string, string>;
69
+ /**
70
+ * Add `TokenVerifier` implementations to this array to enable token verification.
71
+ * When a bearer token arrives in a request 'Authorization' header, it will be checked
72
+ * against all the verifiers registered here.
73
+ */
74
+ tokenVerifiers: Array<TokenVerifier>;
75
+ constructor(environmentName: string);
76
+ get resourceNames(): ResourceNames;
77
+ /**
78
+ * Returns the name of the ReadModel from the name of its resouce (normally, a table)
79
+ * @param resourceName
80
+ */
81
+ readModelNameFromResourceName(resourceName: string): string;
82
+ /**
83
+ * This is a convenience property to easily check if the application has defined any roles.
84
+ * Only in that case we will create a user pool and an authorization API.
85
+ * If there are no roles defined, it means that all app endpoints are public and users
86
+ * won't be registered (they are all anonymous)
87
+ */
88
+ get thereAreRoles(): boolean;
89
+ currentVersionFor(className: string): number;
90
+ validate(): void;
91
+ get provider(): ProviderLibrary;
92
+ set provider(provider: ProviderLibrary);
93
+ get userProjectRootPath(): string;
94
+ set userProjectRootPath(path: string);
95
+ get eventStore(): EventStoreAdapter;
96
+ get readModelStore(): ReadModelStoreAdapter;
97
+ get sessionStore(): SessionStoreAdapter;
98
+ mustGetEnvironmentVar(varName: string): string;
99
+ private validateAllMigrations;
100
+ private validateConceptSchemaMigrations;
101
+ }
102
+ interface ResourceNames {
103
+ applicationStack: string;
104
+ eventsStore: string;
105
+ dispatchedEventsStore: string;
106
+ eventsDedup: string;
107
+ subscriptionsStore: string;
108
+ connectionsStore: string;
109
+ streamTopic: string;
110
+ forReadModel(entityName: string): string;
111
+ }
112
+ type EntityName = string;
113
+ type EventName = string;
114
+ type CommandName = string;
115
+ type QueryName = string;
116
+ type ReadModelName = string;
117
+ type RoleName = string;
118
+ type ConceptName = string;
119
+ type Version = number;
120
+ type ScheduledCommandName = string;
121
+ type DataMigrationName = string;
122
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekConfig = void 0;
4
+ const logger_1 = require("./logger");
5
+ const path = require("path");
6
+ const _1 = require(".");
7
+ /**
8
+ * Class used by external packages that needs to get a representation of
9
+ * the Magek config. Used mainly for vendor-specific deployment packages
10
+ */
11
+ class MagekConfig {
12
+ constructor(environmentName) {
13
+ this.environmentName = environmentName;
14
+ this.logLevel = logger_1.Level.debug;
15
+ this.appName = 'new-magek-app';
16
+ this.defaultResponseHeaders = {};
17
+ this.subscriptions = {
18
+ maxConnectionDurationInSeconds: 7 * 24 * 60 * 60, // 7 days
19
+ maxDurationInSeconds: 2 * 24 * 60 * 60, // 2 days
20
+ };
21
+ this.enableGraphQLIntrospection = true;
22
+ this.codeRelativePath = 'dist';
23
+ this.eventDispatcherHandler = path.join(this.codeRelativePath, 'index.eventDispatcher');
24
+ this.eventStreamConsumer = path.join(this.codeRelativePath, 'index.consumeEventStream');
25
+ this.eventStreamProducer = path.join(this.codeRelativePath, 'index.produceEventStream');
26
+ this.serveGraphQLHandler = path.join(this.codeRelativePath, 'index.graphQLDispatcher');
27
+ this.sensorHealthHandler = path.join(this.codeRelativePath, 'index.health');
28
+ this.scheduledTaskHandler = path.join(this.codeRelativePath, 'index.triggerScheduledCommands');
29
+ this.notifySubscribersHandler = path.join(this.codeRelativePath, 'index.notifySubscribers');
30
+ this.functionRelativePath = path.join('..', this.codeRelativePath, 'index.js');
31
+ this.events = {};
32
+ this.notifications = {};
33
+ this.partitionKeys = {};
34
+ this.topicToEvent = {};
35
+ this.eventToTopic = {};
36
+ this.entities = {};
37
+ this.reducers = {};
38
+ this.commandHandlers = {};
39
+ this.queryHandlers = {};
40
+ this.eventHandlers = {};
41
+ this.readModels = {};
42
+ this.projections = {};
43
+ this.unProjections = {};
44
+ this.readModelSequenceKeys = {};
45
+ this.roles = {};
46
+ this.schemaMigrations = {};
47
+ this.scheduledCommandHandlers = {};
48
+ this.dataMigrationHandlers = {};
49
+ this.userHealthIndicators = {};
50
+ this.sensorConfiguration = {
51
+ health: {
52
+ globalAuthorizer: {
53
+ authorize: 'all',
54
+ },
55
+ magek: _1.DEFAULT_SENSOR_HEALTH_CONFIGURATIONS,
56
+ },
57
+ };
58
+ this.enableSubscriptions = true;
59
+ this.nonExposedGraphQLMetadataKey = {};
60
+ // TTL for events stored in dispatched events table. Default to 5 minutes (i.e., 300 seconds).
61
+ this.dispatchedEventsTtl = 300;
62
+ this.traceConfiguration = {
63
+ enableTraceNotification: false,
64
+ includeInternal: false,
65
+ onStart: async () => { },
66
+ onEnd: async () => { },
67
+ };
68
+ this.eventStreamConfiguration = { enabled: false };
69
+ /** Environment variables to set when running the application */
70
+ this.env = {};
71
+ /**
72
+ * Add `TokenVerifier` implementations to this array to enable token verification.
73
+ * When a bearer token arrives in a request 'Authorization' header, it will be checked
74
+ * against all the verifiers registered here.
75
+ */
76
+ this.tokenVerifiers = [];
77
+ }
78
+ get resourceNames() {
79
+ var _a, _b;
80
+ if (this.appName.length === 0)
81
+ throw new Error('Application name cannot be empty');
82
+ const applicationStackName = this.appName + '-app';
83
+ return {
84
+ applicationStack: applicationStackName,
85
+ eventsStore: applicationStackName + '-events-store',
86
+ dispatchedEventsStore: applicationStackName + '-dispatched-events',
87
+ eventsDedup: applicationStackName + '-events-dedup',
88
+ subscriptionsStore: applicationStackName + '-subscriptions-store',
89
+ connectionsStore: applicationStackName + '-connections-store',
90
+ streamTopic: (_b = (_a = this.eventStreamConfiguration.parameters) === null || _a === void 0 ? void 0 : _a.streamTopic) !== null && _b !== void 0 ? _b : 'magek_events',
91
+ forReadModel(readModelName) {
92
+ return applicationStackName + '-' + readModelName;
93
+ },
94
+ };
95
+ }
96
+ /**
97
+ * Returns the name of the ReadModel from the name of its resouce (normally, a table)
98
+ * @param resourceName
99
+ */
100
+ readModelNameFromResourceName(resourceName) {
101
+ const resourceNamePrefixRegex = new RegExp(`^${this.resourceNames.applicationStack}-`);
102
+ return resourceName.replace(resourceNamePrefixRegex, '');
103
+ }
104
+ /**
105
+ * This is a convenience property to easily check if the application has defined any roles.
106
+ * Only in that case we will create a user pool and an authorization API.
107
+ * If there are no roles defined, it means that all app endpoints are public and users
108
+ * won't be registered (they are all anonymous)
109
+ */
110
+ get thereAreRoles() {
111
+ return Object.entries(this.roles).length > 0;
112
+ }
113
+ currentVersionFor(className) {
114
+ const migrations = this.schemaMigrations[className];
115
+ if (!migrations) {
116
+ return 1;
117
+ }
118
+ return Math.max(...migrations.keys());
119
+ }
120
+ validate() {
121
+ this.validateAllMigrations();
122
+ }
123
+ get provider() {
124
+ if (!this._provider)
125
+ throw new Error('It is required to set a valid provider runtime in your configuration files');
126
+ return this._provider;
127
+ }
128
+ set provider(provider) {
129
+ this._provider = provider;
130
+ }
131
+ get userProjectRootPath() {
132
+ if (!this._userProjectRootPath)
133
+ throw new Error('Property "userProjectRootPath" is not set. Ensure you have called "Magek.start"');
134
+ return this._userProjectRootPath;
135
+ }
136
+ set userProjectRootPath(path) {
137
+ this._userProjectRootPath = path;
138
+ }
139
+ get eventStore() {
140
+ if (!this.eventStoreAdapter) {
141
+ throw new Error('EventStoreAdapter is not configured. Please set config.eventStoreAdapter.');
142
+ }
143
+ return this.eventStoreAdapter;
144
+ }
145
+ get readModelStore() {
146
+ if (!this.readModelStoreAdapter) {
147
+ throw new Error('ReadModelStoreAdapter is not configured. Please set config.readModelStoreAdapter.');
148
+ }
149
+ return this.readModelStoreAdapter;
150
+ }
151
+ get sessionStore() {
152
+ if (this.enableSubscriptions && !this.sessionStoreAdapter) {
153
+ throw new Error('SessionStoreAdapter is not configured. Please set config.sessionStoreAdapter.');
154
+ }
155
+ return this.sessionStoreAdapter;
156
+ }
157
+ mustGetEnvironmentVar(varName) {
158
+ const value = process.env[varName];
159
+ if (value == undefined) {
160
+ throw new Error(`Missing environment variable '${varName}'`);
161
+ }
162
+ return value;
163
+ }
164
+ validateAllMigrations() {
165
+ for (const conceptName in this.schemaMigrations) {
166
+ this.validateConceptSchemaMigrations(conceptName, this.schemaMigrations[conceptName]);
167
+ }
168
+ }
169
+ validateConceptSchemaMigrations(conceptName, migrations) {
170
+ // Check that migrations are defined consecutively. In other words, there are no gaps between the version numbers
171
+ const currentVersion = this.currentVersionFor(conceptName);
172
+ for (let toVersion = 2; toVersion <= currentVersion; toVersion++) {
173
+ if (!migrations.has(toVersion)) {
174
+ throw new Error(`Schema Migrations for '${conceptName}' are invalid: they are missing a migration with toVersion=${toVersion}. ` +
175
+ `There must be a migration for '${conceptName}' for every version in the range [2..${currentVersion}]`);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ exports.MagekConfig = MagekConfig;
@@ -0,0 +1,3 @@
1
+ export interface DataMigrationParameters {
2
+ readonly order: number;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,188 @@
1
+ import { CommandInput, EntityInterface, EventInterface, NotificationInterface, ReadModelInterface, SequenceKey, UUID } from './concepts';
2
+ import { GraphQLClientMessage } from './graphql-websocket-messages';
3
+ import { FilterFor, ProjectionFor, SortFor } from './searcher';
4
+ import { Class } from './typelevel';
5
+ /**
6
+ * An `Envelope` carries a command/event body together with the name
7
+ * of its class. This is important information for the `Distributor` to
8
+ * work. Each provider has to implement their own `Envelope`.
9
+ */
10
+ export interface Envelope {
11
+ currentUser?: UserEnvelope;
12
+ requestID: UUID;
13
+ context?: ContextEnvelope;
14
+ }
15
+ export interface TypedEnvelope extends Envelope {
16
+ typeName: string;
17
+ version: number;
18
+ }
19
+ export interface CommandEnvelope extends TypedEnvelope {
20
+ value: CommandInput;
21
+ }
22
+ export type QueryEnvelope = CommandEnvelope;
23
+ export interface HealthEnvelope extends Envelope {
24
+ componentPath: string;
25
+ token?: string;
26
+ }
27
+ export interface ScheduledCommandEnvelope extends Envelope {
28
+ typeName: string;
29
+ }
30
+ export type SuperKindType = 'domain' | 'notification' | 'magek';
31
+ export interface EventStoreEntryEnvelope extends TypedEnvelope {
32
+ superKind: SuperKindType;
33
+ entityID: UUID;
34
+ entityTypeName: string;
35
+ value: EventInterface | EntityInterface | NotificationInterface;
36
+ }
37
+ export interface NonPersistedEventEnvelope extends EventStoreEntryEnvelope {
38
+ kind: 'event';
39
+ }
40
+ export interface EventEnvelope extends NonPersistedEventEnvelope {
41
+ id?: string;
42
+ createdAt: string;
43
+ deletedAt?: string;
44
+ }
45
+ export interface NonPersistedEntitySnapshotEnvelope extends EventStoreEntryEnvelope {
46
+ kind: 'snapshot';
47
+ snapshottedEventCreatedAt: string;
48
+ }
49
+ export interface EntitySnapshotEnvelope extends NonPersistedEntitySnapshotEnvelope {
50
+ /** Logic creation date of the snapshot, it always matches the creation date of the latest event included in it. */
51
+ createdAt: string;
52
+ /** Time when this snapshot was actually persisted in the database. */
53
+ persistedAt: string;
54
+ }
55
+ export interface EventSearchRequest extends Envelope {
56
+ parameters: EventSearchParameters;
57
+ }
58
+ export type EventSearchParameters = EventParametersFilterByEntity | EventParametersFilterByType;
59
+ export interface EventLimitParameter {
60
+ limit?: number;
61
+ }
62
+ export interface EventTimeParameterFilter extends EventLimitParameter {
63
+ from?: string;
64
+ to?: string;
65
+ }
66
+ export interface EventParametersFilterByEntity extends EventTimeParameterFilter {
67
+ entity: string;
68
+ entityID?: string;
69
+ }
70
+ export interface EventParametersFilterByType extends EventTimeParameterFilter {
71
+ type: string;
72
+ }
73
+ export interface EventSearchResponse {
74
+ type: string;
75
+ entity: string;
76
+ entityID: UUID;
77
+ requestID: UUID;
78
+ user?: UserEnvelope;
79
+ createdAt: string;
80
+ value: EventInterface | NotificationInterface;
81
+ deletedAt?: string;
82
+ }
83
+ export interface ReadModelEnvelope {
84
+ typeName: string;
85
+ value: ReadModelInterface;
86
+ }
87
+ export interface PaginatedEntityIdResult {
88
+ entityID: UUID;
89
+ }
90
+ export interface PaginatedEntitiesIdsResult {
91
+ items: Array<PaginatedEntityIdResult>;
92
+ count?: number;
93
+ cursor?: Record<string, string>;
94
+ }
95
+ export interface ReadModelListResult<TReadModel> {
96
+ items: Array<TReadModel>;
97
+ count?: number;
98
+ cursor?: Record<string, string>;
99
+ }
100
+ export interface ReadModelRequestEnvelope<TReadModel extends ReadModelInterface> extends Envelope {
101
+ key?: {
102
+ id: UUID;
103
+ sequenceKey?: SequenceKey;
104
+ };
105
+ class: Class<TReadModel>;
106
+ className: string;
107
+ version: number;
108
+ filters: ReadModelRequestProperties<TReadModel>;
109
+ sortBy?: ReadModelSortProperties<TReadModel>;
110
+ limit?: number;
111
+ afterCursor?: unknown;
112
+ paginatedVersion?: boolean;
113
+ select?: ProjectionFor<TReadModel>;
114
+ }
115
+ export interface ReadModelRequestArgs<TReadModel extends ReadModelInterface> {
116
+ filter?: ReadModelRequestProperties<TReadModel>;
117
+ sortBy?: ReadModelSortProperties<TReadModel>;
118
+ limit?: number;
119
+ afterCursor?: unknown;
120
+ }
121
+ export interface ReadModelByIdRequestArgs {
122
+ id: string;
123
+ [sequenceKey: string]: string | undefined;
124
+ }
125
+ export type ReadModelRequestProperties<TReadModel> = Record<string, FilterFor<TReadModel>>;
126
+ export type ReadModelSortProperties<TReadModel> = Record<string, SortFor<TReadModel>>;
127
+ export type EventType = 'CONNECT' | 'MESSAGE' | 'DISCONNECT';
128
+ export interface GraphQLRequestEnvelope extends Envelope {
129
+ eventType: EventType;
130
+ connectionID?: string;
131
+ value?: GraphQLOperation | GraphQLClientMessage;
132
+ token?: string;
133
+ }
134
+ export type GraphQLRequestEnvelopeError = Pick<GraphQLRequestEnvelope, 'eventType' | 'connectionID' | 'requestID'> & {
135
+ error: Error;
136
+ };
137
+ export interface SubscriptionEnvelope extends ReadModelRequestEnvelope<ReadModelInterface> {
138
+ expirationTime: number;
139
+ connectionID: string;
140
+ operation: GraphQLOperation;
141
+ }
142
+ export interface GraphQLOperation {
143
+ query: string;
144
+ id?: string;
145
+ operationName?: string;
146
+ variables?: Record<string, any>;
147
+ }
148
+ export interface ConnectionDataEnvelope {
149
+ expirationTime: number;
150
+ user?: UserEnvelope;
151
+ }
152
+ export interface UserEnvelope {
153
+ /** An optional identifier of the user */
154
+ id?: string;
155
+ /** The unique username of the current user */
156
+ username: string;
157
+ /** The list of role names assigned to this user */
158
+ roles: Array<string>;
159
+ /** An object containing the claims included in the body of the JWT token */
160
+ claims: Record<string, unknown>;
161
+ /** An object containing the headers of the JWT token for further verification */
162
+ header?: Record<string, unknown>;
163
+ }
164
+ export interface ContextEnvelope {
165
+ /** Decoded request header and body */
166
+ request: {
167
+ headers: unknown;
168
+ body: unknown;
169
+ };
170
+ /** Provider-dependent raw request context object */
171
+ rawContext: unknown;
172
+ }
173
+ export type EventEnvelopeFromDatabase = EventEnvelope & {
174
+ id: string;
175
+ };
176
+ export type EntitySnapshotEnvelopeFromDatabase = EntitySnapshotEnvelope & {
177
+ id: string;
178
+ };
179
+ export interface EventDeleteParameters {
180
+ entityTypeName: string;
181
+ entityID: string;
182
+ createdAt: string;
183
+ }
184
+ export interface SnapshotDeleteParameters {
185
+ entityID: UUID;
186
+ entityTypeName: string;
187
+ createdAt: string;
188
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { CommandEnvelope } from '../envelope';
3
+ import { CommandMetadata } from '../concepts';
4
+ export declare class CommandHandlerGlobalError extends GlobalErrorContainer {
5
+ readonly commandEnvelope: CommandEnvelope;
6
+ readonly commandMetadata: CommandMetadata;
7
+ constructor(commandEnvelope: CommandEnvelope, commandMetadata: CommandMetadata, originalError: Error);
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandHandlerGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class CommandHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(commandEnvelope, commandMetadata, originalError) {
7
+ super(originalError);
8
+ this.commandEnvelope = commandEnvelope;
9
+ this.commandMetadata = commandMetadata;
10
+ }
11
+ }
12
+ exports.CommandHandlerGlobalError = CommandHandlerGlobalError;
@@ -0,0 +1,6 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { EventEnvelope } from '../envelope';
3
+ export declare class EventGlobalError extends GlobalErrorContainer {
4
+ readonly eventEnvelope: EventEnvelope;
5
+ constructor(eventEnvelope: EventEnvelope, originalError: Error);
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class EventGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(eventEnvelope, originalError) {
7
+ super(originalError);
8
+ this.eventEnvelope = eventEnvelope;
9
+ }
10
+ }
11
+ exports.EventGlobalError = EventGlobalError;
@@ -0,0 +1,9 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { EventInterface, NotificationInterface } from '../concepts';
3
+ import { EventEnvelope } from '../envelope';
4
+ export declare class EventHandlerGlobalError extends GlobalErrorContainer {
5
+ readonly eventEnvelope: EventEnvelope | NotificationInterface;
6
+ readonly eventInstance: EventInterface;
7
+ readonly eventHandlerMetadata: unknown;
8
+ constructor(eventEnvelope: EventEnvelope | NotificationInterface, eventInstance: EventInterface, eventHandlerMetadata: unknown, originalError: Error);
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventHandlerGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class EventHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(eventEnvelope, eventInstance, eventHandlerMetadata, originalError) {
7
+ super(originalError);
8
+ this.eventEnvelope = eventEnvelope;
9
+ this.eventInstance = eventInstance;
10
+ this.eventHandlerMetadata = eventHandlerMetadata;
11
+ }
12
+ }
13
+ exports.EventHandlerGlobalError = EventHandlerGlobalError;
@@ -0,0 +1,4 @@
1
+ export declare class GlobalErrorContainer {
2
+ readonly originalError: Error;
3
+ constructor(originalError: Error);
4
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlobalErrorContainer = void 0;
4
+ class GlobalErrorContainer {
5
+ constructor(originalError) {
6
+ this.originalError = originalError;
7
+ }
8
+ }
9
+ exports.GlobalErrorContainer = GlobalErrorContainer;