@magek/common 0.0.6 → 0.0.8
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/concepts/projection-metadata.d.ts +4 -4
- package/dist/concepts/projection-metadata.js +6 -6
- package/dist/concepts/reducer-metadata.d.ts +5 -0
- package/dist/concepts/reducer-metadata.js +5 -0
- package/dist/concepts/register.js +6 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.js +78 -65
- package/dist/envelope.d.ts +9 -0
- package/dist/errors/command-handler-global-error.js +2 -0
- package/dist/errors/event-global-error.js +1 -0
- package/dist/errors/event-handler-global-error.js +3 -0
- package/dist/errors/global-error-container.js +1 -0
- package/dist/errors/projection-global-error.js +4 -0
- package/dist/errors/query-handler-global-error.js +1 -0
- package/dist/errors/reducer-global-error.js +4 -0
- package/dist/errors/schedule-command-global-error.js +2 -0
- package/dist/errors/snapshot-persist-handler-global-error.js +1 -0
- package/dist/errors.js +6 -3
- package/dist/event-store-adapter.d.ts +71 -16
- package/dist/graphql-websocket-messages.js +11 -7
- package/dist/http-service.js +2 -2
- package/dist/index.d.ts +17 -20
- package/dist/index.js +30 -20
- package/dist/instances.d.ts +20 -0
- package/dist/instances.js +10 -0
- package/dist/logger.js +5 -6
- package/dist/metadata-types.d.ts +20 -0
- package/dist/retrier.js +3 -3
- package/dist/searcher.js +10 -3
- package/dist/timestamp-generator.d.ts +38 -0
- package/dist/timestamp-generator.js +84 -0
- package/package.json +2 -2
- package/dist/field-decorator.d.ts +0 -63
- package/dist/field-decorator.js +0 -122
- package/dist/internal-info.d.ts +0 -2
- package/dist/internal-info.js +0 -6
- package/dist/promises.d.ts +0 -25
- package/dist/promises.js +0 -42
- package/dist/run-command.d.ts +0 -5
- package/dist/run-command.js +0 -48
|
@@ -8,8 +8,8 @@ export interface ProjectionMetadata<TEntity extends EntityInterface, TReadModel
|
|
|
8
8
|
methodName: string;
|
|
9
9
|
joinKey: keyof TEntity | ReadModelJoinKeyFunction<TEntity, TReadModel>;
|
|
10
10
|
}
|
|
11
|
-
export type ProjectionResult<TReadModel> = TReadModel |
|
|
12
|
-
export declare enum
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export type ProjectionResult<TReadModel> = TReadModel | ProjectionAction;
|
|
12
|
+
export declare enum ProjectionAction {
|
|
13
|
+
Skip = 0,
|
|
14
|
+
Delete = 1
|
|
15
15
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(
|
|
3
|
+
exports.ProjectionAction = void 0;
|
|
4
|
+
var ProjectionAction;
|
|
5
|
+
(function (ProjectionAction) {
|
|
6
|
+
ProjectionAction[ProjectionAction["Skip"] = 0] = "Skip";
|
|
7
|
+
ProjectionAction[ProjectionAction["Delete"] = 1] = "Delete";
|
|
8
|
+
})(ProjectionAction || (exports.ProjectionAction = ProjectionAction = {}));
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AnyClass } from '..';
|
|
2
|
+
import { EntityInterface } from './entity';
|
|
2
3
|
export interface ReducerMetadata {
|
|
3
4
|
class: AnyClass;
|
|
4
5
|
methodName: string;
|
|
5
6
|
}
|
|
7
|
+
export declare enum ReducerAction {
|
|
8
|
+
Skip = 0
|
|
9
|
+
}
|
|
10
|
+
export type ReducerResult<TEntity extends EntityInterface> = TEntity | ReducerAction;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReducerAction = void 0;
|
|
4
|
+
var ReducerAction;
|
|
5
|
+
(function (ReducerAction) {
|
|
6
|
+
ReducerAction[ReducerAction["Skip"] = 0] = "Skip";
|
|
7
|
+
})(ReducerAction || (exports.ReducerAction = ReducerAction = {}));
|
|
@@ -23,6 +23,12 @@ exports.Register = void 0;
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
class Register {
|
|
26
|
+
requestID;
|
|
27
|
+
responseHeaders;
|
|
28
|
+
flusher;
|
|
29
|
+
currentUser;
|
|
30
|
+
context;
|
|
31
|
+
eventList = [];
|
|
26
32
|
/**
|
|
27
33
|
* Creates a new instance of Register
|
|
28
34
|
*
|
|
@@ -56,7 +62,6 @@ class Register {
|
|
|
56
62
|
this.flusher = flusher;
|
|
57
63
|
this.currentUser = currentUser;
|
|
58
64
|
this.context = context;
|
|
59
|
-
this.eventList = [];
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
62
67
|
* Register a list of events to be added to the event-store on handler completion
|
package/dist/config.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ export declare class MagekConfig {
|
|
|
61
61
|
enableSubscriptions: boolean;
|
|
62
62
|
readonly nonExposedGraphQLMetadataKey: Record<string, Array<string>>;
|
|
63
63
|
dispatchedEventsTtl: number;
|
|
64
|
+
/** Interval in milliseconds between event polling cycles. Default: 1000ms */
|
|
65
|
+
eventPollingIntervalMs: number;
|
|
66
|
+
/** Number of events to process per polling cycle. Default: 100 */
|
|
67
|
+
eventProcessingBatchSize: number;
|
|
64
68
|
traceConfiguration: TraceConfiguration;
|
|
65
69
|
eventStreamConfiguration: EventStreamConfiguration;
|
|
66
70
|
/** Environment variables to set when running the application */
|
package/dist/config.js
CHANGED
|
@@ -9,74 +9,87 @@ const _1 = require(".");
|
|
|
9
9
|
* the Magek config.
|
|
10
10
|
*/
|
|
11
11
|
class MagekConfig {
|
|
12
|
+
environmentName;
|
|
13
|
+
logLevel = logger_1.Level.debug;
|
|
14
|
+
logPrefix;
|
|
15
|
+
logger;
|
|
16
|
+
_runtime;
|
|
17
|
+
eventStoreAdapter;
|
|
18
|
+
readModelStoreAdapter;
|
|
19
|
+
sessionStoreAdapter;
|
|
20
|
+
appName = 'new-magek-app';
|
|
21
|
+
assets;
|
|
22
|
+
defaultResponseHeaders = {};
|
|
23
|
+
subscriptions = {
|
|
24
|
+
maxConnectionDurationInSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
25
|
+
maxDurationInSeconds: 2 * 24 * 60 * 60, // 2 days
|
|
26
|
+
};
|
|
27
|
+
enableGraphQLIntrospection = true;
|
|
28
|
+
_userProjectRootPath;
|
|
29
|
+
codeRelativePath = 'dist';
|
|
30
|
+
eventDispatcherHandler = path.join(this.codeRelativePath, 'index.eventDispatcher');
|
|
31
|
+
eventStreamConsumer = path.join(this.codeRelativePath, 'index.consumeEventStream');
|
|
32
|
+
eventStreamProducer = path.join(this.codeRelativePath, 'index.produceEventStream');
|
|
33
|
+
serveGraphQLHandler = path.join(this.codeRelativePath, 'index.graphQLDispatcher');
|
|
34
|
+
sensorHealthHandler = path.join(this.codeRelativePath, 'index.health');
|
|
35
|
+
scheduledTaskHandler = path.join(this.codeRelativePath, 'index.triggerScheduledCommands');
|
|
36
|
+
notifySubscribersHandler = path.join(this.codeRelativePath, 'index.notifySubscribers');
|
|
37
|
+
functionRelativePath = path.join('..', this.codeRelativePath, 'index.js');
|
|
38
|
+
events = {};
|
|
39
|
+
notifications = {};
|
|
40
|
+
partitionKeys = {};
|
|
41
|
+
topicToEvent = {};
|
|
42
|
+
eventToTopic = {};
|
|
43
|
+
entities = {};
|
|
44
|
+
reducers = {};
|
|
45
|
+
commandHandlers = {};
|
|
46
|
+
queryHandlers = {};
|
|
47
|
+
eventHandlers = {};
|
|
48
|
+
readModels = {};
|
|
49
|
+
projections = {};
|
|
50
|
+
unProjections = {};
|
|
51
|
+
readModelSequenceKeys = {};
|
|
52
|
+
roles = {};
|
|
53
|
+
schemaMigrations = {};
|
|
54
|
+
scheduledCommandHandlers = {};
|
|
55
|
+
dataMigrationHandlers = {};
|
|
56
|
+
userHealthIndicators = {};
|
|
57
|
+
sensorConfiguration = {
|
|
58
|
+
health: {
|
|
59
|
+
globalAuthorizer: {
|
|
60
|
+
authorize: 'all',
|
|
61
|
+
},
|
|
62
|
+
magek: _1.DEFAULT_SENSOR_HEALTH_CONFIGURATIONS,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
globalErrorsHandler;
|
|
66
|
+
enableSubscriptions = true;
|
|
67
|
+
nonExposedGraphQLMetadataKey = {};
|
|
68
|
+
// TTL for events stored in dispatched events table. Default to 5 minutes (i.e., 300 seconds).
|
|
69
|
+
dispatchedEventsTtl = 300;
|
|
70
|
+
/** Interval in milliseconds between event polling cycles. Default: 1000ms */
|
|
71
|
+
eventPollingIntervalMs = 1000;
|
|
72
|
+
/** Number of events to process per polling cycle. Default: 100 */
|
|
73
|
+
eventProcessingBatchSize = 100;
|
|
74
|
+
traceConfiguration = {
|
|
75
|
+
enableTraceNotification: false,
|
|
76
|
+
includeInternal: false,
|
|
77
|
+
onStart: async () => { },
|
|
78
|
+
onEnd: async () => { },
|
|
79
|
+
};
|
|
80
|
+
eventStreamConfiguration = { enabled: false };
|
|
81
|
+
/** Environment variables to set when running the application */
|
|
82
|
+
env = {};
|
|
83
|
+
/**
|
|
84
|
+
* Add `TokenVerifier` implementations to this array to enable token verification.
|
|
85
|
+
* When a bearer token arrives in a request 'Authorization' header, it will be checked
|
|
86
|
+
* against all the verifiers registered here.
|
|
87
|
+
*/
|
|
88
|
+
tokenVerifiers = [];
|
|
12
89
|
constructor(environmentName) {
|
|
13
90
|
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
91
|
}
|
|
78
92
|
get resourceNames() {
|
|
79
|
-
var _a, _b;
|
|
80
93
|
if (this.appName.length === 0)
|
|
81
94
|
throw new Error('Application name cannot be empty');
|
|
82
95
|
const applicationStackName = this.appName + '-app';
|
|
@@ -87,7 +100,7 @@ class MagekConfig {
|
|
|
87
100
|
eventsDedup: applicationStackName + '-events-dedup',
|
|
88
101
|
subscriptionsStore: applicationStackName + '-subscriptions-store',
|
|
89
102
|
connectionsStore: applicationStackName + '-connections-store',
|
|
90
|
-
streamTopic:
|
|
103
|
+
streamTopic: this.eventStreamConfiguration.parameters?.streamTopic ?? 'magek_events',
|
|
91
104
|
forReadModel(readModelName) {
|
|
92
105
|
return applicationStackName + '-' + readModelName;
|
|
93
106
|
},
|
package/dist/envelope.d.ts
CHANGED
|
@@ -36,11 +36,20 @@ export interface EventStoreEntryEnvelope extends TypedEnvelope {
|
|
|
36
36
|
}
|
|
37
37
|
export interface NonPersistedEventEnvelope extends EventStoreEntryEnvelope {
|
|
38
38
|
kind: 'event';
|
|
39
|
+
createdAt: string;
|
|
39
40
|
}
|
|
40
41
|
export interface EventEnvelope extends NonPersistedEventEnvelope {
|
|
42
|
+
/** Unique identifier assigned by the event store after persistence. */
|
|
41
43
|
id?: string;
|
|
44
|
+
/** ISO timestamp when the event was created. */
|
|
42
45
|
createdAt: string;
|
|
46
|
+
/** ISO timestamp when the event was soft-deleted, if applicable. */
|
|
43
47
|
deletedAt?: string;
|
|
48
|
+
/**
|
|
49
|
+
* ISO timestamp when the event was processed by async event processing.
|
|
50
|
+
* Used for filtering unprocessed events and as an audit marker.
|
|
51
|
+
*/
|
|
52
|
+
processedAt?: string;
|
|
44
53
|
}
|
|
45
54
|
export interface NonPersistedEntitySnapshotEnvelope extends EventStoreEntryEnvelope {
|
|
46
55
|
kind: 'snapshot';
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CommandHandlerGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class CommandHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
commandEnvelope;
|
|
7
|
+
commandMetadata;
|
|
6
8
|
constructor(commandEnvelope, commandMetadata, originalError) {
|
|
7
9
|
super(originalError);
|
|
8
10
|
this.commandEnvelope = commandEnvelope;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EventGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class EventGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
eventEnvelope;
|
|
6
7
|
constructor(eventEnvelope, originalError) {
|
|
7
8
|
super(originalError);
|
|
8
9
|
this.eventEnvelope = eventEnvelope;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EventHandlerGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class EventHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
eventEnvelope;
|
|
7
|
+
eventInstance;
|
|
8
|
+
eventHandlerMetadata;
|
|
6
9
|
constructor(eventEnvelope, eventInstance, eventHandlerMetadata, originalError) {
|
|
7
10
|
super(originalError);
|
|
8
11
|
this.eventEnvelope = eventEnvelope;
|
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ProjectionGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class ProjectionGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
entityEnvelope;
|
|
7
|
+
entity;
|
|
8
|
+
readModel;
|
|
9
|
+
projectionMetadata;
|
|
6
10
|
constructor(entityEnvelope, entity, readModel, projectionMetadata, originalError) {
|
|
7
11
|
super(originalError);
|
|
8
12
|
this.entityEnvelope = entityEnvelope;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QueryHandlerGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class QueryHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
query;
|
|
6
7
|
constructor(query, originalError) {
|
|
7
8
|
super(originalError);
|
|
8
9
|
this.query = query;
|
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReducerGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class ReducerGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
eventEnvelope;
|
|
7
|
+
eventInstance;
|
|
8
|
+
snapshotInstance;
|
|
9
|
+
reducerMetadata;
|
|
6
10
|
constructor(eventEnvelope, eventInstance, snapshotInstance, reducerMetadata, originalError) {
|
|
7
11
|
super(originalError);
|
|
8
12
|
this.eventEnvelope = eventEnvelope;
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ScheduleCommandGlobalError = void 0;
|
|
4
4
|
const global_error_container_1 = require("./global-error-container");
|
|
5
5
|
class ScheduleCommandGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
6
|
+
scheduleCommandEnvelope;
|
|
7
|
+
scheduleCommandMetadata;
|
|
6
8
|
constructor(scheduleCommandEnvelope, scheduleCommandMetadata, originalError) {
|
|
7
9
|
super(originalError);
|
|
8
10
|
this.scheduleCommandEnvelope = scheduleCommandEnvelope;
|
|
@@ -13,6 +13,7 @@ const global_error_container_1 = require("./global-error-container");
|
|
|
13
13
|
* This class is kept for backwards compatibility.
|
|
14
14
|
*/
|
|
15
15
|
class SnapshotPersistHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
|
|
16
|
+
snapshot;
|
|
16
17
|
constructor(snapshot, originalError) {
|
|
17
18
|
super(originalError);
|
|
18
19
|
this.snapshot = snapshot;
|
package/dist/errors.js
CHANGED
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InvalidReducerError = exports.InvalidEventError = exports.OptimisticConcurrencyUnexpectedVersionError = exports.InvalidVersionError = exports.NotFoundError = exports.MagekTokenNotBeforeError = exports.MagekTokenExpiredError = exports.NotAuthorizedError = exports.InvalidProtocolError = exports.InvalidParameterError = exports.MagekError = void 0;
|
|
4
4
|
exports.httpStatusCodeFor = httpStatusCodeFor;
|
|
5
5
|
class MagekError extends Error {
|
|
6
|
+
data;
|
|
7
|
+
code;
|
|
6
8
|
constructor(message, code, data) {
|
|
7
9
|
super(message);
|
|
8
10
|
this.data = data;
|
|
9
|
-
this.code = code
|
|
11
|
+
this.code = code ?? this.constructor.name;
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
exports.MagekError = MagekError;
|
|
@@ -38,6 +40,8 @@ class InvalidEventError extends MagekError {
|
|
|
38
40
|
}
|
|
39
41
|
exports.InvalidEventError = InvalidEventError;
|
|
40
42
|
class InvalidReducerError extends MagekError {
|
|
43
|
+
eventInstance;
|
|
44
|
+
snapshotInstance;
|
|
41
45
|
constructor(message, eventInstance, snapshotInstance) {
|
|
42
46
|
super(message);
|
|
43
47
|
this.eventInstance = eventInstance;
|
|
@@ -46,7 +50,6 @@ class InvalidReducerError extends MagekError {
|
|
|
46
50
|
}
|
|
47
51
|
exports.InvalidReducerError = InvalidReducerError;
|
|
48
52
|
function httpStatusCodeFor(error) {
|
|
49
|
-
var _a;
|
|
50
53
|
const errorToHTTPCode = {
|
|
51
54
|
[InvalidParameterError.name]: 400,
|
|
52
55
|
[InvalidProtocolError.name]: 400,
|
|
@@ -56,5 +59,5 @@ function httpStatusCodeFor(error) {
|
|
|
56
59
|
[NotFoundError.name]: 404,
|
|
57
60
|
[InvalidVersionError.name]: 422,
|
|
58
61
|
};
|
|
59
|
-
return
|
|
62
|
+
return errorToHTTPCode[error.constructor.name] ?? 500;
|
|
60
63
|
}
|
|
@@ -10,8 +10,32 @@ export interface EventStoreAdapter {
|
|
|
10
10
|
* @returns An array of EventEnvelope objects
|
|
11
11
|
*/
|
|
12
12
|
rawToEnvelopes(rawEvents: unknown): Array<EventEnvelope>;
|
|
13
|
+
/**
|
|
14
|
+
* Converts raw stream data into an array of EventEnvelope objects.
|
|
15
|
+
*
|
|
16
|
+
* @param config - The Magek configuration object
|
|
17
|
+
* @param context - The context from the raw stream
|
|
18
|
+
* @param dedupEventStream - The deduplicated event stream
|
|
19
|
+
* @returns An array of EventEnvelope objects
|
|
20
|
+
*/
|
|
13
21
|
rawStreamToEnvelopes(config: MagekConfig, context: unknown, dedupEventStream: EventStream): Array<EventEnvelope>;
|
|
22
|
+
/**
|
|
23
|
+
* Deduplicates raw events and returns them as an EventStream.
|
|
24
|
+
*
|
|
25
|
+
* @param config - The Magek configuration object
|
|
26
|
+
* @param rawEvents - The raw events data to deduplicate
|
|
27
|
+
* @returns A promise that resolves to a deduplicated EventStream
|
|
28
|
+
*/
|
|
14
29
|
dedupEventStream(config: MagekConfig, rawEvents: unknown): Promise<EventStream>;
|
|
30
|
+
/**
|
|
31
|
+
* Produces events to an external event stream (e.g., Kafka).
|
|
32
|
+
*
|
|
33
|
+
* @param entityName - The name of the entity type
|
|
34
|
+
* @param entityID - The unique identifier of the entity
|
|
35
|
+
* @param eventEnvelopes - The array of EventEnvelope objects to produce
|
|
36
|
+
* @param config - The Magek configuration object
|
|
37
|
+
* @returns A promise that resolves when events are produced
|
|
38
|
+
*/
|
|
15
39
|
produce(entityName: string, entityID: UUID, eventEnvelopes: Array<EventEnvelope>, config: MagekConfig): Promise<void>;
|
|
16
40
|
/**
|
|
17
41
|
* Retrieves events for a specific entity since a given time
|
|
@@ -76,48 +100,79 @@ export interface EventStoreAdapter {
|
|
|
76
100
|
*/
|
|
77
101
|
storeDispatched(eventEnvelope: EventEnvelope, config: MagekConfig): Promise<boolean>;
|
|
78
102
|
/**
|
|
79
|
-
*
|
|
103
|
+
* Finds all events matching the deletion criteria.
|
|
80
104
|
*
|
|
81
|
-
* @param config
|
|
82
|
-
* @param parameters
|
|
105
|
+
* @param config - The Magek configuration object
|
|
106
|
+
* @param parameters - The parameters specifying which events to find for deletion
|
|
107
|
+
* @returns A promise that resolves to an array of EventEnvelopeFromDatabase objects
|
|
83
108
|
*/
|
|
84
109
|
findDeletableEvent(config: MagekConfig, parameters: EventDeleteParameters): Promise<Array<EventEnvelopeFromDatabase>>;
|
|
85
110
|
/**
|
|
86
|
-
*
|
|
111
|
+
* Finds all snapshots matching the deletion criteria.
|
|
87
112
|
*
|
|
88
|
-
* @param config
|
|
89
|
-
* @param parameters
|
|
113
|
+
* @param config - The Magek configuration object
|
|
114
|
+
* @param parameters - The parameters specifying which snapshots to find for deletion
|
|
115
|
+
* @returns A promise that resolves to an array of EntitySnapshotEnvelopeFromDatabase objects
|
|
90
116
|
*/
|
|
91
117
|
findDeletableSnapshot(config: MagekConfig, parameters: SnapshotDeleteParameters): Promise<Array<EntitySnapshotEnvelopeFromDatabase>>;
|
|
92
118
|
/**
|
|
93
|
-
*
|
|
119
|
+
* Soft-deletes events by marking them with a deletedAt timestamp.
|
|
94
120
|
*
|
|
95
|
-
* @param config
|
|
96
|
-
* @param events
|
|
121
|
+
* @param config - The Magek configuration object
|
|
122
|
+
* @param events - The array of events to delete
|
|
123
|
+
* @returns A promise that resolves when the events are deleted
|
|
97
124
|
*/
|
|
98
125
|
deleteEvent(config: MagekConfig, events: Array<EventEnvelopeFromDatabase>): Promise<void>;
|
|
99
126
|
/**
|
|
100
|
-
*
|
|
127
|
+
* Soft-deletes snapshots by marking them with a deletedAt timestamp.
|
|
101
128
|
*
|
|
102
|
-
* @param config
|
|
103
|
-
* @param snapshots
|
|
129
|
+
* @param config - The Magek configuration object
|
|
130
|
+
* @param snapshots - The array of snapshots to delete
|
|
131
|
+
* @returns A promise that resolves when the snapshots are deleted
|
|
104
132
|
*/
|
|
105
133
|
deleteSnapshot(config: MagekConfig, snapshots: Array<EntitySnapshotEnvelopeFromDatabase>): Promise<void>;
|
|
106
134
|
/**
|
|
107
|
-
* Health check methods for the event store
|
|
135
|
+
* Health check methods for the event store.
|
|
108
136
|
*/
|
|
109
137
|
healthCheck?: {
|
|
110
138
|
/**
|
|
111
|
-
*
|
|
139
|
+
* Checks if the event store is up and running.
|
|
140
|
+
*
|
|
141
|
+
* @param config - The Magek configuration object
|
|
142
|
+
* @returns A promise that resolves to true if the event store is healthy
|
|
112
143
|
*/
|
|
113
144
|
isUp(config: MagekConfig): Promise<boolean>;
|
|
114
145
|
/**
|
|
115
|
-
*
|
|
146
|
+
* Gets detailed health information about the event store.
|
|
147
|
+
*
|
|
148
|
+
* @param config - The Magek configuration object
|
|
149
|
+
* @returns A promise that resolves to health details
|
|
116
150
|
*/
|
|
117
151
|
details(config: MagekConfig): Promise<unknown>;
|
|
118
152
|
/**
|
|
119
|
-
*
|
|
153
|
+
* Gets the URLs/endpoints of the event store.
|
|
154
|
+
*
|
|
155
|
+
* @param config - The Magek configuration object
|
|
156
|
+
* @returns A promise that resolves to an array of URL strings
|
|
120
157
|
*/
|
|
121
158
|
urls(config: MagekConfig): Promise<Array<string>>;
|
|
122
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Fetches the next batch of unprocessed events.
|
|
162
|
+
* The adapter manages the cursor internally to track processing position.
|
|
163
|
+
* Batch size is read from config.eventProcessingBatchSize.
|
|
164
|
+
*
|
|
165
|
+
* @param config - The Magek configuration object
|
|
166
|
+
* @returns A promise that resolves to an array of EventEnvelope objects
|
|
167
|
+
*/
|
|
168
|
+
fetchUnprocessedEvents?(config: MagekConfig): Promise<Array<EventEnvelope>>;
|
|
169
|
+
/**
|
|
170
|
+
* Marks a single event as processed and advances the internal cursor.
|
|
171
|
+
* Should be called after each event has been successfully dispatched.
|
|
172
|
+
*
|
|
173
|
+
* @param config - The Magek configuration object
|
|
174
|
+
* @param eventId - The ID of the event that was processed
|
|
175
|
+
* @returns A promise that resolves when the event is marked and cursor is updated
|
|
176
|
+
*/
|
|
177
|
+
markEventProcessed?(config: MagekConfig, eventId: UUID): Promise<void>;
|
|
123
178
|
}
|
|
@@ -15,38 +15,42 @@ var MessageTypes;
|
|
|
15
15
|
MessageTypes["GQL_STOP"] = "stop";
|
|
16
16
|
})(MessageTypes || (exports.MessageTypes = MessageTypes = {}));
|
|
17
17
|
class GraphQLInitError {
|
|
18
|
+
payload;
|
|
19
|
+
type = MessageTypes.GQL_CONNECTION_ERROR;
|
|
18
20
|
constructor(payload) {
|
|
19
21
|
this.payload = payload;
|
|
20
|
-
this.type = MessageTypes.GQL_CONNECTION_ERROR;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
exports.GraphQLInitError = GraphQLInitError;
|
|
24
25
|
class GraphQLInitAck {
|
|
25
|
-
|
|
26
|
-
this.type = MessageTypes.GQL_CONNECTION_ACK;
|
|
27
|
-
}
|
|
26
|
+
type = MessageTypes.GQL_CONNECTION_ACK;
|
|
28
27
|
}
|
|
29
28
|
exports.GraphQLInitAck = GraphQLInitAck;
|
|
30
29
|
class GraphQLData {
|
|
30
|
+
id;
|
|
31
|
+
payload;
|
|
32
|
+
type = MessageTypes.GQL_DATA;
|
|
31
33
|
constructor(id, payload) {
|
|
32
34
|
this.id = id;
|
|
33
35
|
this.payload = payload;
|
|
34
|
-
this.type = MessageTypes.GQL_DATA;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
exports.GraphQLData = GraphQLData;
|
|
38
39
|
class GraphQLError {
|
|
40
|
+
id;
|
|
41
|
+
payload;
|
|
42
|
+
type = MessageTypes.GQL_ERROR;
|
|
39
43
|
constructor(id, payload) {
|
|
40
44
|
this.id = id;
|
|
41
45
|
this.payload = payload;
|
|
42
|
-
this.type = MessageTypes.GQL_ERROR;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
exports.GraphQLError = GraphQLError;
|
|
46
49
|
class GraphQLComplete {
|
|
50
|
+
id;
|
|
51
|
+
type = MessageTypes.GQL_COMPLETE;
|
|
47
52
|
constructor(id) {
|
|
48
53
|
this.id = id;
|
|
49
|
-
this.type = MessageTypes.GQL_COMPLETE;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
exports.GraphQLComplete = GraphQLComplete;
|
package/dist/http-service.js
CHANGED
|
@@ -23,7 +23,7 @@ async function request(url, method = 'GET', data = '', config = {}) {
|
|
|
23
23
|
const body = [];
|
|
24
24
|
res.on('data', (chunk) => body.push(chunk));
|
|
25
25
|
res.on('end', () => {
|
|
26
|
-
if (!
|
|
26
|
+
if (!res?.statusCode) {
|
|
27
27
|
return reject(new Error('Unknown HTTP status code'));
|
|
28
28
|
}
|
|
29
29
|
// Accept 2xx codes or any explicitly accepted status codes
|
|
@@ -32,7 +32,7 @@ async function request(url, method = 'GET', data = '', config = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
const buffer = Buffer.concat(body).toString();
|
|
34
34
|
resolve({
|
|
35
|
-
status: res
|
|
35
|
+
status: res?.statusCode,
|
|
36
36
|
body: buffer,
|
|
37
37
|
});
|
|
38
38
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
export * from './groups';
|
|
2
|
-
export * from './promises';
|
|
3
|
-
export * from './retrier';
|
|
4
|
-
export * from './instances';
|
|
5
|
-
export * from './run-command';
|
|
6
|
-
export * from './logger';
|
|
7
|
-
export * from './http-service';
|
|
8
1
|
export * from './app';
|
|
9
|
-
export * from './envelope';
|
|
10
2
|
export * from './config';
|
|
11
3
|
export * from './concepts';
|
|
12
|
-
export * from './
|
|
4
|
+
export * from './envelope';
|
|
13
5
|
export * from './errors';
|
|
14
6
|
export * from './errors/index';
|
|
15
|
-
export * from './
|
|
7
|
+
export * from './logger';
|
|
16
8
|
export * from './searcher';
|
|
17
|
-
export * from './graphql-websocket-messages';
|
|
18
|
-
export * from './schedule';
|
|
19
|
-
export * from './data-migration-parameters';
|
|
20
|
-
export * from './super-kind';
|
|
21
|
-
export * from './instrumentation/trace-types';
|
|
22
|
-
export * from './sensor/health-indicator-configuration';
|
|
23
|
-
export * from './internal-info';
|
|
24
|
-
export * from './stream-types';
|
|
25
|
-
export * from './runtime';
|
|
26
9
|
export * from './event-store-adapter';
|
|
27
10
|
export * from './read-model-store-adapter';
|
|
28
11
|
export * from './session-store-adapter';
|
|
29
|
-
export * from './
|
|
12
|
+
export * from './retrier';
|
|
13
|
+
export * from './timestamp-generator';
|
|
14
|
+
export * from './instances';
|
|
15
|
+
export * from './groups';
|
|
16
|
+
export * from './stream-types';
|
|
17
|
+
export * from './typelevel';
|
|
18
|
+
export * from './runtime';
|
|
19
|
+
export * from './user-app';
|
|
30
20
|
export * from './metadata-types';
|
|
21
|
+
export * from './super-kind';
|
|
22
|
+
export * from './schedule';
|
|
23
|
+
export * from './data-migration-parameters';
|
|
24
|
+
export * from './graphql-websocket-messages';
|
|
25
|
+
export * from './http-service';
|
|
26
|
+
export * from './instrumentation/trace-types';
|
|
27
|
+
export * from './sensor/health-indicator-configuration';
|