@schemeless/event-store-types 5.0.0 → 6.0.0-rc.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 +7 -41
- package/dist/Errors.js +14 -65
- package/dist/EventStore.types.d.ts +6 -153
- package/dist/EventStore.types.js +0 -19
- package/dist/Repo.types.d.ts +22 -75
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +2 -2
- package/readme.md +22 -80
- package/dist/Revert.types.d.ts +0 -38
- package/dist/Revert.types.js +0 -2
package/dist/Errors.d.ts
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
export declare class ConcurrencyError extends Error {
|
|
2
|
-
readonly streamKey: string;
|
|
3
|
-
readonly expectedSequence: number;
|
|
4
|
-
readonly actualSequence: number;
|
|
5
|
-
constructor(streamKey: string, expectedSequence: number, actualSequence: number);
|
|
6
|
-
}
|
|
7
1
|
export declare class EventStoreError extends Error {
|
|
8
2
|
constructor(message: string);
|
|
9
3
|
}
|
|
10
|
-
export declare class
|
|
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 {
|
|
4
|
+
export declare class StreamConcurrencyError extends EventStoreError {
|
|
23
5
|
readonly domain: string;
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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');
|
|
6
|
+
readonly identifier: string;
|
|
7
|
+
readonly expectedVersion: number;
|
|
8
|
+
readonly actualVersion: number;
|
|
9
|
+
constructor(domain: string, identifier: string, expectedVersion: number, actualVersion: number);
|
|
37
10
|
}
|
|
38
|
-
export declare class
|
|
39
|
-
|
|
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);
|
|
11
|
+
export declare class SnapshotError extends EventStoreError {
|
|
12
|
+
constructor(message: string);
|
|
47
13
|
}
|
package/dist/Errors.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class ConcurrencyError extends Error {
|
|
5
|
-
constructor(streamKey, expectedSequence, actualSequence) {
|
|
6
|
-
super(`Concurrency conflict on stream "${streamKey}": expected sequence ${expectedSequence}, but found ${actualSequence}`);
|
|
7
|
-
this.streamKey = streamKey;
|
|
8
|
-
this.expectedSequence = expectedSequence;
|
|
9
|
-
this.actualSequence = actualSequence;
|
|
10
|
-
this.name = 'ConcurrencyError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.ConcurrencyError = ConcurrencyError;
|
|
3
|
+
exports.SnapshotError = exports.StreamConcurrencyError = exports.EventStoreError = void 0;
|
|
14
4
|
class EventStoreError extends Error {
|
|
15
5
|
constructor(message) {
|
|
16
6
|
super(message);
|
|
@@ -18,62 +8,21 @@ class EventStoreError extends Error {
|
|
|
18
8
|
}
|
|
19
9
|
}
|
|
20
10
|
exports.EventStoreError = EventStoreError;
|
|
21
|
-
class
|
|
22
|
-
constructor(
|
|
23
|
-
super(`
|
|
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.`);
|
|
11
|
+
class StreamConcurrencyError extends EventStoreError {
|
|
12
|
+
constructor(domain, identifier, expectedVersion, actualVersion) {
|
|
13
|
+
super(`Concurrency conflict on stream "${domain}/${identifier}": expected version ${expectedVersion}, but found ${actualVersion}`);
|
|
35
14
|
this.domain = domain;
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
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';
|
|
15
|
+
this.identifier = identifier;
|
|
16
|
+
this.expectedVersion = expectedVersion;
|
|
17
|
+
this.actualVersion = actualVersion;
|
|
18
|
+
this.name = 'StreamConcurrencyError';
|
|
61
19
|
}
|
|
62
20
|
}
|
|
63
|
-
exports.
|
|
64
|
-
class
|
|
65
|
-
constructor(
|
|
66
|
-
|
|
67
|
-
|
|
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';
|
|
21
|
+
exports.StreamConcurrencyError = StreamConcurrencyError;
|
|
22
|
+
class SnapshotError extends EventStoreError {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'SnapshotError';
|
|
77
26
|
}
|
|
78
27
|
}
|
|
79
|
-
exports.
|
|
28
|
+
exports.SnapshotError = SnapshotError;
|
|
@@ -1,172 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base metadata for all events.
|
|
3
|
-
* Framework automatically populates schemaVersion.
|
|
4
|
-
* User code can extend this interface for custom metadata.
|
|
5
|
-
*/
|
|
6
1
|
export interface EventMeta {
|
|
7
|
-
/** Schema version of the event payload */
|
|
8
2
|
schemaVersion?: number;
|
|
9
|
-
/** Flag indicating this is a compensating event */
|
|
10
|
-
isCompensating?: boolean;
|
|
11
|
-
/** ID of the event being compensated */
|
|
12
|
-
compensatesEventId?: string;
|
|
13
|
-
/** Allow arbitrary extensions */
|
|
14
3
|
[key: string]: any;
|
|
15
4
|
}
|
|
16
|
-
export interface BaseEventInput<Payload, META extends EventMeta = EventMeta> {
|
|
5
|
+
export interface BaseEventInput<Payload = any, META extends EventMeta = EventMeta> {
|
|
17
6
|
payload: Payload;
|
|
18
7
|
meta?: META;
|
|
19
8
|
identifier?: string;
|
|
20
9
|
correlationId?: string;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Will be removed in v3.0.
|
|
23
|
-
* causationId is now managed exclusively by the framework.
|
|
24
|
-
* Do not set this field manually.
|
|
25
|
-
*/
|
|
26
10
|
causationId?: string;
|
|
27
11
|
created?: Date;
|
|
28
12
|
}
|
|
29
|
-
export interface BaseEvent<Payload, META extends EventMeta = EventMeta> extends BaseEventInput<Payload, META> {
|
|
13
|
+
export interface BaseEvent<Payload = any, META extends EventMeta = EventMeta> extends BaseEventInput<Payload, META> {
|
|
30
14
|
id?: string;
|
|
31
15
|
domain: string;
|
|
32
16
|
type: string;
|
|
33
|
-
payload: Payload;
|
|
34
|
-
identifier?: string;
|
|
35
|
-
correlationId?: string;
|
|
36
|
-
causationId?: string;
|
|
37
|
-
created?: Date;
|
|
38
17
|
}
|
|
39
|
-
export interface CreatedEvent<Payload, META extends EventMeta = EventMeta> extends BaseEvent<Payload, META> {
|
|
18
|
+
export interface CreatedEvent<Payload = any, META extends EventMeta = EventMeta> extends BaseEvent<Payload, META> {
|
|
40
19
|
id: string;
|
|
41
|
-
|
|
20
|
+
created: Date;
|
|
42
21
|
}
|
|
43
|
-
export interface StoredEvent<Payload, META extends EventMeta = EventMeta> extends CreatedEvent<Payload, META> {
|
|
22
|
+
export interface StoredEvent<Payload = any, META extends EventMeta = EventMeta> extends CreatedEvent<Payload, META> {
|
|
23
|
+
sequence?: number;
|
|
44
24
|
}
|
|
45
25
|
export type Event<Payload, META extends EventMeta = EventMeta> = StoredEvent<Payload, META>;
|
|
46
|
-
export interface EventFlow<PartialPayload = any, Payload extends PartialPayload = PartialPayload, META extends EventMeta = EventMeta> {
|
|
47
|
-
readonly kind?: 'simple';
|
|
48
|
-
readonly domain: string;
|
|
49
|
-
readonly type: string;
|
|
50
|
-
readonly description?: string;
|
|
51
|
-
readonly meta?: {
|
|
52
|
-
readonly sideEffectFailedRetryAllowed?: number;
|
|
53
|
-
};
|
|
54
|
-
readonly eventType?: CreatedEvent<Payload, META>;
|
|
55
|
-
readonly payloadType?: PartialPayload | Payload;
|
|
56
|
-
readonly samplePayload?: PartialPayload | Payload;
|
|
57
|
-
/**
|
|
58
|
-
* Current schema version for this event type.
|
|
59
|
-
* Stored in event.meta.schemaVersion when event is created.
|
|
60
|
-
* @default 1
|
|
61
|
-
*/
|
|
62
|
-
readonly schemaVersion?: number;
|
|
63
|
-
/**
|
|
64
|
-
* Upgrades event payload from older versions to the current schemaVersion.
|
|
65
|
-
* Called automatically during event processing and replay.
|
|
66
|
-
*
|
|
67
|
-
* @param event - The event with potentially outdated payload
|
|
68
|
-
* @param fromVersion - The version stored in event.meta.schemaVersion (defaults to 1)
|
|
69
|
-
* @returns Updated event with migrated payload, or void to use the original
|
|
70
|
-
*/
|
|
71
|
-
readonly upcast?: (event: CreatedEvent<any, META>, fromVersion: number) => CreatedEvent<Payload, META> | Promise<CreatedEvent<Payload, META>> | void;
|
|
72
|
-
/**
|
|
73
|
-
* Extract the shard key for event routing.
|
|
74
|
-
* Events with the same shard key will be processed sequentially in the same partition.
|
|
75
|
-
* Events with different shard keys can be processed in parallel.
|
|
76
|
-
*
|
|
77
|
-
* @param event - The event to extract the shard key from
|
|
78
|
-
* @returns The shard key string, or undefined to use fallback (identifier)
|
|
79
|
-
* @example
|
|
80
|
-
* getShardKey: (event) => event.payload.userId
|
|
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
|
-
*/
|
|
88
|
-
readonly receive: (eventStore: {
|
|
89
|
-
receive: (eventFlow: EventFlow<PartialPayload, Payload, META>) => (eventInput: BaseEventInput<PartialPayload, META>) => Promise<[CreatedEvent<Payload, META>, ...Array<CreatedEvent<any>>]>;
|
|
90
|
-
}) => (eventInputArgs: BaseEventInput<PartialPayload, META>) => Promise<[CreatedEvent<Payload, META>, ...Array<CreatedEvent<any>>]>;
|
|
91
|
-
readonly validate?: (event: CreatedEvent<Payload, META>) => Promise<Error | void> | Error | void;
|
|
92
|
-
readonly preApply?: (event: CreatedEvent<PartialPayload, META>) => Promise<CreatedEvent<Payload, META> | void> | CreatedEvent<Payload, META> | void;
|
|
93
|
-
readonly apply?: (event: CreatedEvent<Payload, META>) => Promise<void> | void;
|
|
94
|
-
readonly sideEffect?: (event: CreatedEvent<Payload, META>) => Promise<void | BaseEvent<any>[]> | void | BaseEvent<any>[];
|
|
95
|
-
readonly cancelApply?: (event: CreatedEvent<Payload, META>) => Promise<void> | void;
|
|
96
|
-
readonly createConsequentEvents?: (causalEvent: CreatedEvent<Payload, META>) => Promise<BaseEvent<any>[]> | BaseEvent<any>[];
|
|
97
|
-
/**
|
|
98
|
-
* Generates compensating event(s) to reverse this event's effects.
|
|
99
|
-
* Called by the framework during revert operations.
|
|
100
|
-
*
|
|
101
|
-
* If this hook is not defined, the event cannot be reverted.
|
|
102
|
-
* If any event in a causal chain lacks this hook, the entire chain
|
|
103
|
-
* cannot be reverted.
|
|
104
|
-
*
|
|
105
|
-
* @param originalEvent - The event being reverted
|
|
106
|
-
* @returns Compensating event(s) to persist
|
|
107
|
-
*/
|
|
108
|
-
readonly compensate?: (originalEvent: CreatedEvent<Payload, META>) => BaseEvent<any> | BaseEvent<any>[];
|
|
109
|
-
}
|
|
110
|
-
export interface AggregateConfig<State> {
|
|
111
|
-
readonly reducer: (state: State, event: CreatedEvent<any>) => State;
|
|
112
|
-
readonly initialState: State;
|
|
113
|
-
readonly getIdentifier?: (event: BaseEvent<any>) => string | undefined;
|
|
114
|
-
}
|
|
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';
|
|
117
|
-
readonly aggregate: AggregateConfig<State>;
|
|
118
|
-
readonly validate?: (event: CreatedEvent<Payload, META>, state: State) => Promise<Error | void> | Error | void;
|
|
119
|
-
readonly apply?: (event: CreatedEvent<Payload, META>, state: State) => State | Promise<State>;
|
|
120
|
-
}
|
|
121
|
-
export interface AggregateEventObserver<Payload = any, State = any> extends Omit<SuccessEventObserver<Payload>, 'apply'> {
|
|
122
|
-
readonly aggregate: true;
|
|
123
|
-
readonly apply?: (event: CreatedEvent<Payload>, state: State) => Promise<void> | void;
|
|
124
|
-
}
|
|
125
|
-
export type EventTaskAndError = {
|
|
126
|
-
task: CreatedEvent<any>;
|
|
127
|
-
error: Error;
|
|
128
|
-
};
|
|
129
|
-
export interface EventFlowMap {
|
|
130
|
-
[key: string]: EventFlow;
|
|
131
|
-
}
|
|
132
|
-
interface EventObserverStaticFilter {
|
|
133
|
-
domain: string;
|
|
134
|
-
type: string;
|
|
135
|
-
}
|
|
136
|
-
type EventObserverFilter = EventObserverStaticFilter;
|
|
137
|
-
export interface SuccessEventObserver<Payload = any> {
|
|
138
|
-
filters: EventObserverFilter[];
|
|
139
|
-
priority: number;
|
|
140
|
-
/**
|
|
141
|
-
* If true, the observer will be executed asynchronously without blocking.
|
|
142
|
-
* The main flow will not wait for this observer to complete.
|
|
143
|
-
* @default false
|
|
144
|
-
*/
|
|
145
|
-
fireAndForget?: boolean;
|
|
146
|
-
readonly apply?: (event: CreatedEvent<Payload>) => Promise<void> | void;
|
|
147
|
-
}
|
|
148
|
-
export declare enum SideEffectsState {
|
|
149
|
-
done = "SideEffects:done",
|
|
150
|
-
retry = "SideEffects:retry",
|
|
151
|
-
fail = "SideEffects:fail"
|
|
152
|
-
}
|
|
153
|
-
export declare enum EventOutputState {
|
|
154
|
-
success = "Event:success",
|
|
155
|
-
invalid = "Event:invalid",
|
|
156
|
-
canceled = "Event:canceled",
|
|
157
|
-
reverted = "Event:reverted",
|
|
158
|
-
revertFailed = "Event:revertFailed"
|
|
159
|
-
}
|
|
160
|
-
export declare enum EventObserverState {
|
|
161
|
-
success = "Observer:success"
|
|
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
|
-
});
|
|
172
|
-
export {};
|
package/dist/EventStore.types.js
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventObserverState = exports.EventOutputState = exports.SideEffectsState = void 0;
|
|
4
|
-
var SideEffectsState;
|
|
5
|
-
(function (SideEffectsState) {
|
|
6
|
-
SideEffectsState["done"] = "SideEffects:done";
|
|
7
|
-
SideEffectsState["retry"] = "SideEffects:retry";
|
|
8
|
-
SideEffectsState["fail"] = "SideEffects:fail";
|
|
9
|
-
})(SideEffectsState = exports.SideEffectsState || (exports.SideEffectsState = {}));
|
|
10
|
-
var EventOutputState;
|
|
11
|
-
(function (EventOutputState) {
|
|
12
|
-
EventOutputState["success"] = "Event:success";
|
|
13
|
-
EventOutputState["invalid"] = "Event:invalid";
|
|
14
|
-
EventOutputState["canceled"] = "Event:canceled";
|
|
15
|
-
EventOutputState["reverted"] = "Event:reverted";
|
|
16
|
-
EventOutputState["revertFailed"] = "Event:revertFailed";
|
|
17
|
-
})(EventOutputState = exports.EventOutputState || (exports.EventOutputState = {}));
|
|
18
|
-
var EventObserverState;
|
|
19
|
-
(function (EventObserverState) {
|
|
20
|
-
EventObserverState["success"] = "Observer:success";
|
|
21
|
-
})(EventObserverState = exports.EventObserverState || (exports.EventObserverState = {}));
|
package/dist/Repo.types.d.ts
CHANGED
|
@@ -1,84 +1,31 @@
|
|
|
1
|
-
import type { CreatedEvent } from './EventStore.types';
|
|
2
|
-
export interface
|
|
3
|
-
id: string;
|
|
4
|
-
domain: string;
|
|
5
|
-
type: string;
|
|
6
|
-
meta?: META;
|
|
7
|
-
payload: PAYLOAD;
|
|
8
|
-
identifier?: string;
|
|
9
|
-
correlationId?: string;
|
|
10
|
-
causationId?: string;
|
|
1
|
+
import type { CreatedEvent, EventMeta } from './EventStore.types';
|
|
2
|
+
export interface PersistedEvent<Payload = any, META extends EventMeta = EventMeta> extends CreatedEvent<Payload, META> {
|
|
11
3
|
sequence?: number;
|
|
12
|
-
readonly created: Date;
|
|
13
|
-
}
|
|
14
|
-
export interface StoreEventsOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Expected sequence number for the stream (domain + identifier).
|
|
17
|
-
* If provided, the store will verify the current sequence matches
|
|
18
|
-
* before writing. Throws ConcurrencyError on mismatch.
|
|
19
|
-
*/
|
|
20
|
-
expectedSequence?: number;
|
|
21
4
|
}
|
|
22
|
-
export interface
|
|
5
|
+
export interface Snapshot<State = any> {
|
|
23
6
|
domain: string;
|
|
24
7
|
identifier: string;
|
|
25
|
-
state:
|
|
8
|
+
state: State;
|
|
26
9
|
sequence: number;
|
|
27
10
|
created: Date;
|
|
28
11
|
}
|
|
29
|
-
export interface
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
export interface EventStoreAdapter {
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
close?(): Promise<void>;
|
|
15
|
+
append(events: PersistedEvent[]): Promise<void>;
|
|
16
|
+
getAllEvents(pageSize?: number, startFromId?: string): Promise<AsyncIterableIterator<Array<PersistedEvent>>>;
|
|
17
|
+
reset?(): Promise<void>;
|
|
35
18
|
}
|
|
36
|
-
export interface
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* Get events for a specific stream (domain + identifier).
|
|
49
|
-
* MUST use efficient index-based query (e.g., DynamoDB Query, SQL WHERE).
|
|
50
|
-
* Required for getAggregate to work.
|
|
51
|
-
*
|
|
52
|
-
* @param domain - Event domain
|
|
53
|
-
* @param identifier - Stream identifier
|
|
54
|
-
* @param fromSequence - Start from this sequence (exclusive), 0 = from beginning
|
|
55
|
-
* @returns Events ordered by sequence ascending
|
|
56
|
-
*/
|
|
57
|
-
getStreamEvents?: (domain: string, identifier: string, fromSequence?: number) => Promise<IEventStoreEntity<PAYLOAD, META>[]>;
|
|
58
|
-
getSnapshot?: <STATE>(domain: string, identifier: string) => Promise<ISnapshotEntity<STATE> | null>;
|
|
59
|
-
saveSnapshot?: <STATE>(snapshot: ISnapshotEntity<STATE>) => Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Get the current sequence number for a stream.
|
|
62
|
-
* Returns 0 if no events exist for this stream.
|
|
63
|
-
*/
|
|
64
|
-
getStreamSequence?: (domain: string, identifier: string) => Promise<number>;
|
|
65
|
-
/**
|
|
66
|
-
* Retrieves a single event by its ID.
|
|
67
|
-
* Required for revert operations.
|
|
68
|
-
*/
|
|
69
|
-
getEventById?: (id: string) => Promise<IEventStoreEntity<PAYLOAD, META> | null>;
|
|
70
|
-
/**
|
|
71
|
-
* Finds all events directly caused by the specified event.
|
|
72
|
-
* Returns events where causationId equals the given eventId.
|
|
73
|
-
* Required for revert operations to traverse the event tree.
|
|
74
|
-
*
|
|
75
|
-
* Note for DynamoDB: Consider adding a GSI on causationId for better
|
|
76
|
-
* performance. Without a GSI, this will result in a table scan.
|
|
77
|
-
*/
|
|
78
|
-
findByCausationId?: (causationId: string) => Promise<IEventStoreEntity<PAYLOAD, META>[]>;
|
|
79
|
-
/**
|
|
80
|
-
* Closes the database connection and releases resources.
|
|
81
|
-
* Called during graceful shutdown.
|
|
82
|
-
*/
|
|
83
|
-
close?: () => Promise<void>;
|
|
19
|
+
export interface StreamEventStoreAdapter extends EventStoreAdapter {
|
|
20
|
+
getStreamEvents(domain: string, identifier: string, fromSequence?: number): Promise<PersistedEvent[]>;
|
|
21
|
+
appendToStream(events: PersistedEvent[], expectedVersion: number): Promise<{
|
|
22
|
+
nextVersion: number;
|
|
23
|
+
}>;
|
|
24
|
+
getSnapshot?<State>(domain: string, identifier: string): Promise<Snapshot<State> | null>;
|
|
25
|
+
saveSnapshot?<State>(snapshot: Snapshot<State>): Promise<void>;
|
|
26
|
+
capabilities: {
|
|
27
|
+
streamQuery: true;
|
|
28
|
+
optimisticConcurrency: true;
|
|
29
|
+
snapshot?: boolean;
|
|
30
|
+
};
|
|
84
31
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,5 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./EventStore.types"), exports);
|
|
18
18
|
__exportStar(require("./Repo.types"), exports);
|
|
19
|
-
__exportStar(require("./Revert.types"), exports);
|
|
20
19
|
__exportStar(require("./Errors"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemeless/event-store-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-rc.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": "0d1e175bf8294c9f33be8c875aad9ae8249ca1d6"
|
|
38
38
|
}
|
package/readme.md
CHANGED
|
@@ -1,95 +1,37 @@
|
|
|
1
1
|
# @schemeless/event-store-types
|
|
2
2
|
|
|
3
|
-
Shared TypeScript
|
|
3
|
+
Shared TypeScript contracts for the V6 architecture.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
yarn add @schemeless/event-store-types
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Event primitives
|
|
12
|
-
|
|
13
|
-
The package defines the shape of event inputs, created events, and the lifecycle metadata that flows through the runtime.
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import { BaseEventInput, CreatedEvent, EventFlow } from '@schemeless/event-store-types';
|
|
17
|
-
|
|
18
|
-
const draft: BaseEventInput<{ id: string }> = {
|
|
19
|
-
payload: { id: '123' },
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const eventFlow: EventFlow = {
|
|
23
|
-
domain: 'user',
|
|
24
|
-
type: 'registered',
|
|
25
|
-
receive: (eventStore) => eventStore.receive(eventFlow),
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
`CreatedEvent` extends the base shape with generated identifiers and timestamps, while `SideEffectsState`, `EventOutputState`, and `EventObserverState` describe the possible outcomes emitted by the runtime.
|
|
30
|
-
|
|
31
|
-
### Traceability IDs
|
|
32
|
-
|
|
33
|
-
The event store uses several ID fields to track causation and correlation across event chains:
|
|
5
|
+
Primary consumers:
|
|
34
6
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
- **`trackingId`** – Developer-provided external reference for cross-system tracing.
|
|
7
|
+
- `@schemeless/event-store-core`
|
|
8
|
+
- `@schemeless/event-store-aggregate`
|
|
9
|
+
- adapter packages
|
|
39
10
|
|
|
40
|
-
|
|
11
|
+
This package is the canonical home for:
|
|
41
12
|
|
|
42
|
-
|
|
13
|
+
- persisted event types
|
|
14
|
+
- snapshot types
|
|
15
|
+
- adapter capability contracts
|
|
16
|
+
- concurrency and snapshot errors
|
|
43
17
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
import { IEventStoreRepo } from '@schemeless/event-store-types';
|
|
18
|
+
## Installation
|
|
48
19
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
async getAllEvents(pageSize: number) {
|
|
52
|
-
// return an async iterator of stored events
|
|
53
|
-
}
|
|
54
|
-
createEventEntity(event) {
|
|
55
|
-
return event;
|
|
56
|
-
}
|
|
57
|
-
async storeEvents(events) {}
|
|
58
|
-
async resetStore() {}
|
|
59
|
-
}
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @schemeless/event-store-types
|
|
60
22
|
```
|
|
61
23
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Revert support
|
|
65
|
-
|
|
66
|
-
To enable revert operations, adapters should also implement two additional optional methods:
|
|
24
|
+
## Main contracts
|
|
67
25
|
|
|
68
26
|
```ts
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
async findByCausationId(causationId: string) {
|
|
77
|
-
// Return all events where causationId equals the given value
|
|
78
|
-
// Used to traverse the event tree during reverts
|
|
79
|
-
}
|
|
80
|
-
}
|
|
27
|
+
import type {
|
|
28
|
+
PersistedEvent,
|
|
29
|
+
Snapshot,
|
|
30
|
+
EventStoreAdapter,
|
|
31
|
+
StreamEventStoreAdapter,
|
|
32
|
+
} from '@schemeless/event-store-types';
|
|
81
33
|
```
|
|
82
34
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
## Revert types
|
|
86
|
-
|
|
87
|
-
The package exports types for the revert API:
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
import { CanRevertResult, PreviewRevertResult, RevertResult } from '@schemeless/event-store-types';
|
|
91
|
-
```
|
|
35
|
+
## Design note
|
|
92
36
|
|
|
93
|
-
|
|
94
|
-
- `PreviewRevertResult` – Shows which events would be affected by a revert
|
|
95
|
-
- `RevertResult` – Contains the outcome of a revert operation, including generated compensating events
|
|
37
|
+
New code should target the V6 split architecture. This package only carries shared contracts and storage-facing types.
|
package/dist/Revert.types.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { CreatedEvent } from './EventStore.types';
|
|
2
|
-
/**
|
|
3
|
-
* Result of canRevert() check
|
|
4
|
-
*/
|
|
5
|
-
export interface CanRevertResult {
|
|
6
|
-
/** Whether the event can be reverted */
|
|
7
|
-
canRevert: boolean;
|
|
8
|
-
/** Reason why revert is not possible (if canRevert is false) */
|
|
9
|
-
reason?: string;
|
|
10
|
-
/** Events missing the 'compensate' hook */
|
|
11
|
-
missingCompensateEvents?: Array<{
|
|
12
|
-
id: string;
|
|
13
|
-
domain: string;
|
|
14
|
-
type: string;
|
|
15
|
-
}>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Result of previewRevert() - shows what would be affected
|
|
19
|
-
*/
|
|
20
|
-
export interface PreviewRevertResult {
|
|
21
|
-
/** The root event that would be reverted */
|
|
22
|
-
rootEvent: CreatedEvent<any>;
|
|
23
|
-
/** All descendant events that would be reverted */
|
|
24
|
-
descendantEvents: CreatedEvent<any>[];
|
|
25
|
-
/** Total count of events affected */
|
|
26
|
-
totalEventCount: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Result of a successful revert() operation
|
|
30
|
-
*/
|
|
31
|
-
export interface RevertResult {
|
|
32
|
-
/** ID of the event that was reverted */
|
|
33
|
-
revertedEventId: string;
|
|
34
|
-
/** Compensating events generated for this event */
|
|
35
|
-
compensatingEvents: CreatedEvent<any>[];
|
|
36
|
-
/** Revert results for child events */
|
|
37
|
-
childResults: RevertResult[];
|
|
38
|
-
}
|
package/dist/Revert.types.js
DELETED