@schemeless/event-store-types 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Errors.d.ts +41 -0
- package/dist/Errors.js +67 -1
- package/dist/EventStore.types.d.ts +17 -1
- package/package.json +2 -2
package/dist/Errors.d.ts
CHANGED
|
@@ -4,3 +4,44 @@ export declare class ConcurrencyError extends Error {
|
|
|
4
4
|
readonly actualSequence: number;
|
|
5
5
|
constructor(streamKey: string, expectedSequence: number, actualSequence: number);
|
|
6
6
|
}
|
|
7
|
+
export declare class EventStoreError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class ValidationError extends EventStoreError {
|
|
11
|
+
readonly flow: {
|
|
12
|
+
domain: string;
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
readonly eventId: string;
|
|
16
|
+
readonly cause: Error;
|
|
17
|
+
constructor(flow: {
|
|
18
|
+
domain: string;
|
|
19
|
+
type: string;
|
|
20
|
+
}, eventId: string, cause: Error);
|
|
21
|
+
}
|
|
22
|
+
export declare class FlowNotFoundError extends EventStoreError {
|
|
23
|
+
readonly domain: string;
|
|
24
|
+
readonly type: string;
|
|
25
|
+
constructor(domain: string, type: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class AggregateError extends EventStoreError {
|
|
28
|
+
readonly flow: {
|
|
29
|
+
domain: string;
|
|
30
|
+
type: string;
|
|
31
|
+
};
|
|
32
|
+
readonly reason: 'no_loader' | 'no_identifier' | 'apply_must_return_state' | 'capability_missing';
|
|
33
|
+
constructor(flow: {
|
|
34
|
+
domain: string;
|
|
35
|
+
type: string;
|
|
36
|
+
}, reason: 'no_loader' | 'no_identifier' | 'apply_must_return_state' | 'capability_missing');
|
|
37
|
+
}
|
|
38
|
+
export declare class ShutdownTimeoutError extends EventStoreError {
|
|
39
|
+
readonly timeoutMs: number;
|
|
40
|
+
constructor(timeoutMs: number);
|
|
41
|
+
}
|
|
42
|
+
export declare class RevertError extends EventStoreError {
|
|
43
|
+
readonly eventId: string;
|
|
44
|
+
readonly reason: 'not_found' | 'not_root' | 'missing_compensate' | 'repo_not_supported';
|
|
45
|
+
readonly details?: string;
|
|
46
|
+
constructor(eventId: string, reason: 'not_found' | 'not_root' | 'missing_compensate' | 'repo_not_supported', details?: string);
|
|
47
|
+
}
|
package/dist/Errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConcurrencyError = void 0;
|
|
3
|
+
exports.RevertError = exports.ShutdownTimeoutError = exports.AggregateError = exports.FlowNotFoundError = exports.ValidationError = exports.EventStoreError = exports.ConcurrencyError = void 0;
|
|
4
4
|
class ConcurrencyError extends Error {
|
|
5
5
|
constructor(streamKey, expectedSequence, actualSequence) {
|
|
6
6
|
super(`Concurrency conflict on stream "${streamKey}": expected sequence ${expectedSequence}, but found ${actualSequence}`);
|
|
@@ -11,3 +11,69 @@ class ConcurrencyError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ConcurrencyError = ConcurrencyError;
|
|
14
|
+
class EventStoreError extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'EventStoreError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.EventStoreError = EventStoreError;
|
|
21
|
+
class ValidationError extends EventStoreError {
|
|
22
|
+
constructor(flow, eventId, cause) {
|
|
23
|
+
super(`Validation failed for ${flow.domain}/${flow.type} (event ${eventId}): ${cause.message}`);
|
|
24
|
+
this.flow = flow;
|
|
25
|
+
this.eventId = eventId;
|
|
26
|
+
this.cause = cause;
|
|
27
|
+
this.name = 'ValidationError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ValidationError = ValidationError;
|
|
31
|
+
class FlowNotFoundError extends EventStoreError {
|
|
32
|
+
constructor(domain, type) {
|
|
33
|
+
super(`No EventFlow registered for "${domain}/${type}". ` +
|
|
34
|
+
`Make sure the EventFlow is included in the eventFlows array passed to makeEventStore.`);
|
|
35
|
+
this.domain = domain;
|
|
36
|
+
this.type = type;
|
|
37
|
+
this.name = 'FlowNotFoundError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.FlowNotFoundError = FlowNotFoundError;
|
|
41
|
+
class AggregateError extends EventStoreError {
|
|
42
|
+
constructor(flow, reason) {
|
|
43
|
+
const messages = {
|
|
44
|
+
no_loader: 'requires getAggregate() support to load state',
|
|
45
|
+
no_identifier: 'requires an identifier (set event.identifier or aggregate.getIdentifier)',
|
|
46
|
+
apply_must_return_state: 'apply() must return the new state object',
|
|
47
|
+
capability_missing: 'requires adapter with getStreamEvents() support',
|
|
48
|
+
};
|
|
49
|
+
super(`AggregateEventFlow ${flow.domain}/${flow.type}: ${messages[reason]}`);
|
|
50
|
+
this.flow = flow;
|
|
51
|
+
this.reason = reason;
|
|
52
|
+
this.name = 'AggregateError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.AggregateError = AggregateError;
|
|
56
|
+
class ShutdownTimeoutError extends EventStoreError {
|
|
57
|
+
constructor(timeoutMs) {
|
|
58
|
+
super(`EventStore shutdown timed out after ${timeoutMs}ms`);
|
|
59
|
+
this.timeoutMs = timeoutMs;
|
|
60
|
+
this.name = 'ShutdownTimeoutError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ShutdownTimeoutError = ShutdownTimeoutError;
|
|
64
|
+
class RevertError extends EventStoreError {
|
|
65
|
+
constructor(eventId, reason, details) {
|
|
66
|
+
const messages = {
|
|
67
|
+
not_found: `Event not found: ${eventId}`,
|
|
68
|
+
not_root: `Event ${eventId} is not a root event. Revert the root event instead.`,
|
|
69
|
+
missing_compensate: `Some events in the tree lack a 'compensate' hook`,
|
|
70
|
+
repo_not_supported: 'Repository must implement getEventById and findByCausationId',
|
|
71
|
+
};
|
|
72
|
+
super(messages[reason] + (details ? `. ${details}` : ''));
|
|
73
|
+
this.eventId = eventId;
|
|
74
|
+
this.reason = reason;
|
|
75
|
+
this.details = details;
|
|
76
|
+
this.name = 'RevertError';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.RevertError = RevertError;
|
|
@@ -44,6 +44,7 @@ export interface StoredEvent<Payload, META extends EventMeta = EventMeta> extend
|
|
|
44
44
|
}
|
|
45
45
|
export type Event<Payload, META extends EventMeta = EventMeta> = StoredEvent<Payload, META>;
|
|
46
46
|
export interface EventFlow<PartialPayload = any, Payload extends PartialPayload = PartialPayload, META extends EventMeta = EventMeta> {
|
|
47
|
+
readonly kind?: 'simple';
|
|
47
48
|
readonly domain: string;
|
|
48
49
|
readonly type: string;
|
|
49
50
|
readonly description?: string;
|
|
@@ -79,6 +80,11 @@ export interface EventFlow<PartialPayload = any, Payload extends PartialPayload
|
|
|
79
80
|
* getShardKey: (event) => event.payload.userId
|
|
80
81
|
*/
|
|
81
82
|
readonly getShardKey?: (event: BaseEvent<Payload, META>) => string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated The `receive` pattern will be replaced in v5.
|
|
85
|
+
* Instead of `const send = MyEvent.receive(eventStore); await send(input);`
|
|
86
|
+
* use `await eventStore.submit(MyEvent, input);` directly.
|
|
87
|
+
*/
|
|
82
88
|
readonly receive: (eventStore: {
|
|
83
89
|
receive: (eventFlow: EventFlow<PartialPayload, Payload, META>) => (eventInput: BaseEventInput<PartialPayload, META>) => Promise<[CreatedEvent<Payload, META>, ...Array<CreatedEvent<any>>]>;
|
|
84
90
|
}) => (eventInputArgs: BaseEventInput<PartialPayload, META>) => Promise<[CreatedEvent<Payload, META>, ...Array<CreatedEvent<any>>]>;
|
|
@@ -106,7 +112,8 @@ export interface AggregateConfig<State> {
|
|
|
106
112
|
readonly initialState: State;
|
|
107
113
|
readonly getIdentifier?: (event: BaseEvent<any>) => string | undefined;
|
|
108
114
|
}
|
|
109
|
-
export interface AggregateEventFlow<PartialPayload = any, Payload extends PartialPayload = PartialPayload, State = any, META extends EventMeta = EventMeta> extends Omit<EventFlow<PartialPayload, Payload, META>, 'validate' | 'apply'> {
|
|
115
|
+
export interface AggregateEventFlow<PartialPayload = any, Payload extends PartialPayload = PartialPayload, State = any, META extends EventMeta = EventMeta> extends Omit<EventFlow<PartialPayload, Payload, META>, 'validate' | 'apply' | 'kind'> {
|
|
116
|
+
readonly kind?: 'aggregate';
|
|
110
117
|
readonly aggregate: AggregateConfig<State>;
|
|
111
118
|
readonly validate?: (event: CreatedEvent<Payload, META>, state: State) => Promise<Error | void> | Error | void;
|
|
112
119
|
readonly apply?: (event: CreatedEvent<Payload, META>, state: State) => State | Promise<State>;
|
|
@@ -153,4 +160,13 @@ export declare enum EventOutputState {
|
|
|
153
160
|
export declare enum EventObserverState {
|
|
154
161
|
success = "Observer:success"
|
|
155
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Use this type when defining new EventFlows.
|
|
165
|
+
* The `kind` field enables TypeScript to narrow the type automatically.
|
|
166
|
+
*/
|
|
167
|
+
export type TypedEventFlow<P = any, S = any> = (EventFlow<P, P> & {
|
|
168
|
+
readonly kind: 'simple';
|
|
169
|
+
}) | (AggregateEventFlow<P, P, S> & {
|
|
170
|
+
readonly kind: 'aggregate';
|
|
171
|
+
});
|
|
156
172
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemeless/event-store-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"typescript:main": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "067b860ae72ec74b66ea4cdc179b6a0975a3f2d4"
|
|
38
38
|
}
|