@event-driven-io/emmett 0.43.0-beta.13 → 0.43.0-beta.15
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/cli.cjs +124 -179
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +12 -9
- package/dist/cli.d.ts +12 -9
- package/dist/cli.js +115 -178
- package/dist/cli.js.map +1 -1
- package/dist/index-BXN5muYb.d.cts +73 -0
- package/dist/index-C0agmFA7.d.ts +73 -0
- package/dist/index.cjs +2589 -2916
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +705 -625
- package/dist/index.d.ts +705 -625
- package/dist/index.js +2368 -2843
- package/dist/index.js.map +1 -1
- package/dist/plugins-CUbnGFPp.js +131 -0
- package/dist/plugins-CUbnGFPp.js.map +1 -0
- package/dist/plugins-DB9xe8AV.cjs +272 -0
- package/dist/plugins-DB9xe8AV.cjs.map +1 -0
- package/package.json +9 -6
- package/dist/chunk-AZDDB5SF.js +0 -161
- package/dist/chunk-AZDDB5SF.js.map +0 -1
- package/dist/chunk-WND32L6P.cjs +0 -161
- package/dist/chunk-WND32L6P.cjs.map +0 -1
- package/dist/index-D13Bsibj.d.cts +0 -69
- package/dist/index-D13Bsibj.d.ts +0 -69
package/dist/index.d.cts
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
import { a as EmmettError,
|
|
2
|
-
|
|
3
|
-
import retry from
|
|
1
|
+
import { _ as isPluginConfig, a as IllegalStateError, c as isErrorConstructor, d as EmmettCliPlugin, f as EmmettCliPluginRegistration, g as EmmettPluginType, h as EmmettPluginRegistration, i as ErrorConstructor, l as EmmettPluginsConfig, m as EmmettPluginConfig, n as ConcurrencyInMemoryDatabaseError, o as NotFoundError, p as EmmettPlugin, r as EmmettError, s as ValidationError, t as ConcurrencyError, u as EmmettCliCommand } from "./index-BXN5muYb.cjs";
|
|
2
|
+
import { ObservabilityConfig } from "@event-driven-io/almanac";
|
|
3
|
+
import retry from "async-retry";
|
|
4
4
|
|
|
5
|
+
//#region src/typing/deepReadonly.d.ts
|
|
5
6
|
type Primitive = undefined | null | boolean | string | number | bigint | symbol | Function;
|
|
6
7
|
type ImmutableTypes = Date | RegExp;
|
|
7
8
|
type DeepReadonly<T> = T extends Primitive | ImmutableTypes ? T : T extends Array<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer M> ? ReadonlySet<DeepReadonly<M>> : T extends Promise<infer U> ? Promise<DeepReadonly<U>> : T extends object ? DeepReadonlyObject<T> : Readonly<T>;
|
|
8
|
-
type DeepReadonlyObject<T> = {
|
|
9
|
-
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
10
|
-
};
|
|
9
|
+
type DeepReadonlyObject<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> };
|
|
11
10
|
type Mutable<T> = T extends Primitive ? T : T extends ReadonlyArray<infer U> ? MutableArray<U> : T extends ReadonlyMap<infer K, infer V> ? MutableMap<K, V> : T extends ReadonlySet<infer M> ? MutableSet<M> : T extends Function ? T : T extends object ? MutableObject<T> : unknown;
|
|
12
11
|
type MutableArray<T> = Array<Mutable<T>>;
|
|
13
12
|
type MutableMap<K, V> = Map<Mutable<K>, Mutable<V>>;
|
|
14
13
|
type MutableSet<T> = Set<Mutable<T>>;
|
|
15
|
-
type MutableObject<T> = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
type MutableObject<T> = { -readonly [P in keyof T]: Mutable<T[P]> };
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/typing/command.d.ts
|
|
19
17
|
type Command<CommandType extends string = string, CommandData extends DefaultRecord = DefaultRecord, CommandMetaData extends DefaultRecord | undefined = undefined> = Readonly<CommandMetaData extends undefined ? {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
type: CommandType;
|
|
19
|
+
data: Readonly<CommandData>;
|
|
20
|
+
metadata?: DefaultCommandMetadata | undefined;
|
|
23
21
|
} : {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
type: CommandType;
|
|
23
|
+
data: CommandData;
|
|
24
|
+
metadata: CommandMetaData;
|
|
27
25
|
}> & {
|
|
28
|
-
|
|
26
|
+
readonly kind?: 'Command';
|
|
29
27
|
};
|
|
30
28
|
type AnyCommand = Command<any, any, any>;
|
|
31
29
|
type CommandTypeOf<T extends Command> = T['type'];
|
|
32
30
|
type CommandDataOf<T extends Command> = T['data'];
|
|
33
31
|
type CommandMetaDataOf<T extends Command> = T extends {
|
|
34
|
-
|
|
32
|
+
metadata: infer M;
|
|
35
33
|
} ? M : undefined;
|
|
36
34
|
type CreateCommandType<CommandType extends string, CommandData extends DefaultRecord, CommandMetaData extends DefaultRecord | undefined = undefined> = Readonly<CommandMetaData extends undefined ? {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
type: CommandType;
|
|
36
|
+
data: CommandData;
|
|
37
|
+
metadata?: DefaultCommandMetadata | undefined;
|
|
40
38
|
} : {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
type: CommandType;
|
|
40
|
+
data: CommandData;
|
|
41
|
+
metadata: CommandMetaData;
|
|
44
42
|
}> & {
|
|
45
|
-
|
|
43
|
+
readonly kind?: 'Command';
|
|
46
44
|
};
|
|
47
45
|
declare const command: <CommandType extends Command<string, any, any>>(...args: CommandMetaDataOf<CommandType> extends undefined ? [type: CommandTypeOf<CommandType>, data: CommandDataOf<CommandType>, metadata?: DefaultCommandMetadata | undefined] : [type: CommandTypeOf<CommandType>, data: CommandDataOf<CommandType>, metadata: CommandMetaDataOf<CommandType>]) => CommandType;
|
|
48
46
|
type DefaultCommandMetadata = {
|
|
49
|
-
|
|
47
|
+
now: Date;
|
|
50
48
|
};
|
|
51
|
-
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/database/types.d.ts
|
|
52
51
|
/** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
|
|
53
52
|
declare type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion ? TRecordOrUnion : TRecordOrUnion extends any ? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> : never;
|
|
54
53
|
declare type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
55
|
-
|
|
54
|
+
_id: string;
|
|
56
55
|
};
|
|
57
56
|
type WithoutId<T> = Omit<T, '_id'>;
|
|
58
57
|
declare type WithVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
|
|
59
|
-
|
|
58
|
+
_version: bigint;
|
|
60
59
|
};
|
|
61
60
|
type WithoutVersion<T> = Omit<T, '_version'>;
|
|
62
61
|
type WithIdAndVersion<TSchema> = EnhancedOmit<TSchema, '_version' | '_id'> & {
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
_id: string;
|
|
63
|
+
_version: bigint;
|
|
65
64
|
};
|
|
66
65
|
type Document = Record<string, unknown>;
|
|
67
66
|
type DocumentHandler<T extends Document> = (document: T | null) => T | null;
|
|
@@ -69,204 +68,209 @@ type ExpectedDocumentVersionGeneral = 'DOCUMENT_EXISTS' | 'DOCUMENT_DOES_NOT_EXI
|
|
|
69
68
|
type ExpectedDocumentVersion = bigint | ExpectedDocumentVersionGeneral;
|
|
70
69
|
type ExpectedDocumentVersionValue = bigint;
|
|
71
70
|
type DatabaseHandleOptions = {
|
|
72
|
-
|
|
71
|
+
expectedVersion?: ExpectedDocumentVersion;
|
|
73
72
|
};
|
|
74
73
|
type OperationResult = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
acknowledged: boolean;
|
|
75
|
+
successful: boolean;
|
|
76
|
+
assertSuccessful: (errorMessage?: string) => void;
|
|
78
77
|
};
|
|
79
78
|
interface InsertOneResult extends OperationResult {
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
insertedId: string | null;
|
|
80
|
+
nextExpectedVersion: bigint;
|
|
82
81
|
}
|
|
83
82
|
interface InsertManyResult extends OperationResult {
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
insertedIds: string[];
|
|
84
|
+
insertedCount: number;
|
|
86
85
|
}
|
|
87
86
|
interface UpdateResult extends OperationResult {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
matchedCount: number;
|
|
88
|
+
modifiedCount: number;
|
|
89
|
+
nextExpectedVersion: bigint;
|
|
91
90
|
}
|
|
92
91
|
interface UpdateManyResult extends OperationResult {
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
matchedCount: number;
|
|
93
|
+
modifiedCount: number;
|
|
95
94
|
}
|
|
96
95
|
interface DeleteResult extends OperationResult {
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
matchedCount: number;
|
|
97
|
+
deletedCount: number;
|
|
99
98
|
}
|
|
100
99
|
interface DeleteManyResult extends OperationResult {
|
|
101
|
-
|
|
100
|
+
deletedCount: number;
|
|
102
101
|
}
|
|
103
102
|
type DatabaseHandleResult<T> = (InsertOneResult & {
|
|
104
|
-
|
|
103
|
+
document: WithIdAndVersion<T>;
|
|
105
104
|
}) | (UpdateResult & {
|
|
106
|
-
|
|
105
|
+
document: WithIdAndVersion<T>;
|
|
107
106
|
}) | (DeleteResult & {
|
|
108
|
-
|
|
107
|
+
document: null;
|
|
109
108
|
}) | (OperationResult & {
|
|
110
|
-
|
|
109
|
+
document: null;
|
|
111
110
|
});
|
|
112
111
|
type DatabaseHandleOptionErrors = {
|
|
113
|
-
|
|
112
|
+
throwOnOperationFailures?: boolean;
|
|
114
113
|
} | undefined;
|
|
115
114
|
declare type OptionalId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
116
|
-
|
|
115
|
+
_id?: string;
|
|
117
116
|
};
|
|
118
117
|
declare type OptionalVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
|
|
119
|
-
|
|
118
|
+
_version?: bigint;
|
|
120
119
|
};
|
|
121
120
|
declare type OptionalUnlessRequiredId<TSchema> = TSchema extends {
|
|
122
|
-
|
|
121
|
+
_id: string;
|
|
123
122
|
} ? TSchema : OptionalId<TSchema>;
|
|
124
123
|
declare type OptionalUnlessRequiredVersion<TSchema> = TSchema extends {
|
|
125
|
-
|
|
124
|
+
_version: bigint;
|
|
126
125
|
} ? TSchema : OptionalVersion<TSchema>;
|
|
127
126
|
declare type OptionalUnlessRequiredIdAndVersion<TSchema> = OptionalUnlessRequiredId<TSchema> & OptionalUnlessRequiredVersion<TSchema>;
|
|
128
127
|
type InsertOneOptions = {
|
|
129
|
-
|
|
128
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
|
|
130
129
|
};
|
|
131
130
|
type InsertManyOptions = {
|
|
132
|
-
|
|
131
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
|
|
133
132
|
};
|
|
134
133
|
type UpdateOneOptions = {
|
|
135
|
-
|
|
134
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
136
135
|
};
|
|
137
136
|
type UpdateManyOptions = {
|
|
138
|
-
|
|
137
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
139
138
|
};
|
|
140
139
|
type ReplaceOneOptions = {
|
|
141
|
-
|
|
140
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
142
141
|
};
|
|
143
142
|
type DeleteOneOptions = {
|
|
144
|
-
|
|
143
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
145
144
|
};
|
|
146
145
|
type DeleteManyOptions = {
|
|
147
|
-
|
|
146
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
148
147
|
};
|
|
149
148
|
type FullId<Collection extends string, Id extends string> = `${Collection}-${Id}`;
|
|
150
|
-
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/database/inMemoryDatabase.d.ts
|
|
151
151
|
interface InMemoryDocumentsCollection<T extends Document> {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
handle: (id: string, handle: DocumentHandler<T>, options?: DatabaseHandleOptions) => Promise<DatabaseHandleResult<T>>;
|
|
153
|
+
findOne: (predicate?: Predicate<T>) => Promise<T | null>;
|
|
154
|
+
find: (predicate?: Predicate<T>) => Promise<T[]>;
|
|
155
|
+
insertOne: (document: OptionalUnlessRequiredIdAndVersion<T>) => Promise<InsertOneResult>;
|
|
156
|
+
deleteOne: (predicate?: Predicate<T>) => Promise<DeleteResult>;
|
|
157
|
+
replaceOne: (predicate: Predicate<T>, document: WithoutId<T>, options?: ReplaceOneOptions) => Promise<UpdateResult>;
|
|
158
158
|
}
|
|
159
159
|
interface InMemoryDatabase {
|
|
160
|
-
|
|
160
|
+
collection: <T extends Document>(name: string) => InMemoryDocumentsCollection<T>;
|
|
161
161
|
}
|
|
162
162
|
type Predicate<T> = (item: T) => boolean;
|
|
163
163
|
declare const getInMemoryDatabase: () => InMemoryDatabase;
|
|
164
|
-
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/serialization/json/serializer.d.ts
|
|
165
166
|
interface Serializer<Payload, SerializeOptions extends Record<string, unknown> = Record<string, unknown>, DeserializeOptions extends Record<string, unknown> = SerializeOptions> {
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
serialize<T>(object: T, options?: SerializeOptions): Payload;
|
|
168
|
+
deserialize<T>(payload: Payload, options?: DeserializeOptions): T;
|
|
168
169
|
}
|
|
169
170
|
interface SerializationCodec<T, Payload, SerializeOptions extends Record<string, unknown> = Record<string, unknown>, DeserializeOptions extends Record<string, unknown> = SerializeOptions> {
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
encode(object: T, options?: SerializeOptions): Payload;
|
|
172
|
+
decode(payload: Payload, options?: DeserializeOptions): T;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/serialization/json/jsonSerializer.d.ts
|
|
176
|
+
interface JSONSerializer<SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> extends Serializer<string, SerializeOptions, DeserializeOptions> {
|
|
177
|
+
serialize<T>(object: T, options?: SerializeOptions): string;
|
|
178
|
+
deserialize<T>(payload: string, options?: DeserializeOptions): T;
|
|
172
179
|
}
|
|
173
|
-
|
|
174
180
|
type JSONSerializerOptions = {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
parseDates?: boolean;
|
|
182
|
+
parseBigInts?: boolean;
|
|
183
|
+
failOnBigIntSerialization?: boolean;
|
|
184
|
+
useDefaultDateSerialization?: boolean;
|
|
179
185
|
};
|
|
180
186
|
type JSONSerializeOptions = {
|
|
181
|
-
|
|
187
|
+
replacer?: JSONReplacer;
|
|
182
188
|
} & JSONSerializerOptions;
|
|
183
189
|
type JSONDeserializeOptions = {
|
|
184
|
-
|
|
190
|
+
reviver?: JSONReviver;
|
|
185
191
|
} & JSONSerializerOptions;
|
|
192
|
+
interface JSONCodec<T, SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> extends SerializationCodec<T, string, SerializeOptions, DeserializeOptions> {
|
|
193
|
+
encode(object: T, options?: SerializeOptions): string;
|
|
194
|
+
decode(payload: string, options?: DeserializeOptions): T;
|
|
195
|
+
}
|
|
186
196
|
type JSONCodecSerializationOptions<SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> = {
|
|
187
|
-
|
|
188
|
-
|
|
197
|
+
serializer?: JSONSerializer<SerializeOptions, DeserializeOptions>;
|
|
198
|
+
serializerOptions?: never;
|
|
189
199
|
} | {
|
|
190
|
-
|
|
191
|
-
|
|
200
|
+
serializer?: never;
|
|
201
|
+
serializerOptions?: JSONSerializerOptions;
|
|
192
202
|
};
|
|
193
203
|
type JSONSerializationOptions<SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> = {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
serialization?: {
|
|
205
|
+
serializer?: JSONSerializer<SerializeOptions, DeserializeOptions>;
|
|
206
|
+
options?: JSONSerializeOptions | JSONDeserializeOptions;
|
|
207
|
+
} | undefined;
|
|
198
208
|
};
|
|
199
209
|
type JSONCodecOptions<T, Payload = T, SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> = JSONCodecSerializationOptions<SerializeOptions, DeserializeOptions> & {
|
|
200
|
-
|
|
201
|
-
|
|
210
|
+
upcast?: (document: Payload) => T;
|
|
211
|
+
downcast?: (document: T) => Payload;
|
|
202
212
|
};
|
|
213
|
+
type JSONReplacer = (this: any, key: string, value: any) => any;
|
|
214
|
+
type JSONReviver = (this: any, key: string, value: any, context: JSONReviverContext) => any;
|
|
203
215
|
type JSONReviverContext = {
|
|
204
|
-
|
|
216
|
+
source: string;
|
|
205
217
|
};
|
|
206
218
|
declare const composeJSONReplacers: (...replacers: (JSONReplacer | undefined)[]) => JSONReplacer | undefined;
|
|
207
219
|
declare const composeJSONRevivers: (...revivers: (JSONReviver | undefined)[]) => JSONReviver | undefined;
|
|
208
|
-
type JSONReplacer = (this: any, key: string, value: any) => any;
|
|
209
220
|
declare const JSONReplacer: (opts?: JSONSerializeOptions) => JSONReplacer | undefined;
|
|
210
|
-
type JSONReviver = (this: any, key: string, value: any, context: JSONReviverContext) => any;
|
|
211
221
|
declare const JSONReviver: (opts?: JSONDeserializeOptions) => JSONReviver | undefined;
|
|
212
222
|
declare const JSONReplacers: {
|
|
213
|
-
|
|
214
|
-
|
|
223
|
+
bigInt: JSONReplacer;
|
|
224
|
+
date: JSONReplacer;
|
|
215
225
|
};
|
|
216
226
|
declare const JSONRevivers: {
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
bigInt: JSONReviver;
|
|
228
|
+
date: JSONReviver;
|
|
219
229
|
};
|
|
220
230
|
declare const jsonSerializer: (options?: JSONSerializerOptions & JSONDeserializeOptions & JSONSerializeOptions) => JSONSerializer;
|
|
221
|
-
interface JSONSerializer<SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> extends Serializer<string, SerializeOptions, DeserializeOptions> {
|
|
222
|
-
serialize<T>(object: T, options?: SerializeOptions): string;
|
|
223
|
-
deserialize<T>(payload: string, options?: DeserializeOptions): T;
|
|
224
|
-
}
|
|
225
231
|
declare const JSONSerializer: JSONSerializer & {
|
|
226
|
-
|
|
232
|
+
from: <SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions>(options?: JSONSerializationOptions<SerializeOptions, DeserializeOptions>) => JSONSerializer<SerializeOptions, DeserializeOptions>;
|
|
227
233
|
};
|
|
228
|
-
interface JSONCodec<T, SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions> extends SerializationCodec<T, string, SerializeOptions, DeserializeOptions> {
|
|
229
|
-
encode(object: T, options?: SerializeOptions): string;
|
|
230
|
-
decode(payload: string, options?: DeserializeOptions): T;
|
|
231
|
-
}
|
|
232
234
|
declare const JSONCodec: <T, Payload = T, SerializeOptions extends JSONSerializeOptions = JSONSerializeOptions, DeserializeOptions extends JSONDeserializeOptions = JSONDeserializeOptions>(options: JSONCodecOptions<T, Payload, SerializeOptions, DeserializeOptions>) => JSONCodec<T, SerializeOptions, DeserializeOptions>;
|
|
233
|
-
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/projections/index.d.ts
|
|
234
237
|
type ProjectionHandlingType = 'inline' | 'async';
|
|
235
238
|
type ProjectionHandler<EventType extends Event = AnyEvent, EventMetaDataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord> = BatchRecordedMessageHandlerWithContext<EventType, EventMetaDataType, ProjectionHandlerContext>;
|
|
236
239
|
type TruncateProjection<ProjectionHandlerContext extends DefaultRecord = DefaultRecord> = (context: ProjectionHandlerContext) => Promise<void>;
|
|
237
240
|
type ProjectionInitOptions<ProjectionHandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
version: number;
|
|
242
|
+
status?: 'active' | 'inactive';
|
|
243
|
+
registrationType: ProjectionHandlingType;
|
|
244
|
+
context: ProjectionHandlerContext;
|
|
242
245
|
};
|
|
243
246
|
type ProjectionDefinition<EventType extends Event = AnyEvent, EventMetaDataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord, EventPayloadType extends Event = EventType> = {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
247
|
+
name?: string;
|
|
248
|
+
version?: number;
|
|
249
|
+
kind?: string;
|
|
250
|
+
canHandle: CanHandle<EventType>;
|
|
251
|
+
handle: ProjectionHandler<EventType, EventMetaDataType, ProjectionHandlerContext>;
|
|
252
|
+
truncate?: TruncateProjection<ProjectionHandlerContext>;
|
|
253
|
+
init?: (options: ProjectionInitOptions<ProjectionHandlerContext>) => void | Promise<void>;
|
|
254
|
+
eventsOptions?: {
|
|
255
|
+
schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
|
|
256
|
+
};
|
|
254
257
|
} & JSONSerializationOptions;
|
|
255
258
|
type ProjectionRegistration<HandlingType extends ProjectionHandlingType, ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
256
|
-
|
|
257
|
-
|
|
259
|
+
type: HandlingType;
|
|
260
|
+
projection: ProjectionDefinition<AnyEvent, ReadEventMetadataType, ProjectionHandlerContext, AnyEvent>;
|
|
258
261
|
};
|
|
259
262
|
declare const filterProjections: <ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord>(type: ProjectionHandlingType, projections: ProjectionRegistration<ProjectionHandlingType, ReadEventMetadataType, ProjectionHandlerContext>[]) => ProjectionDefinition<AnyEvent, ReadEventMetadataType, ProjectionHandlerContext, AnyEvent>[];
|
|
260
263
|
declare const projection: <EventType extends Event = Event, EventMetaDataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord, EventPayloadType extends Event = EventType>(definition: ProjectionDefinition<EventType, EventMetaDataType, ProjectionHandlerContext, EventPayloadType>) => ProjectionDefinition<EventType, EventMetaDataType, ProjectionHandlerContext, EventPayloadType>;
|
|
261
264
|
declare const inlineProjections: <ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord>(definitions: ProjectionDefinition<any, ReadEventMetadataType, ProjectionHandlerContext>[]) => ProjectionRegistration<"inline", ReadEventMetadataType, ProjectionHandlerContext>[];
|
|
262
265
|
declare const asyncProjections: <ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord>(definitions: ProjectionDefinition<AnyEvent, ReadEventMetadataType, ProjectionHandlerContext>[]) => ProjectionRegistration<"inline", ReadEventMetadataType, ProjectionHandlerContext>[];
|
|
263
266
|
declare const projections: {
|
|
264
|
-
|
|
265
|
-
|
|
267
|
+
inline: <ReadEventMetadataType extends AnyReadEventMetadata = AnyRecordedMessageMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord>(definitions: ProjectionDefinition<any, ReadEventMetadataType, ProjectionHandlerContext>[]) => ProjectionRegistration<"inline", ReadEventMetadataType, ProjectionHandlerContext>[];
|
|
268
|
+
async: <ReadEventMetadataType extends AnyReadEventMetadata = AnyRecordedMessageMetadata, ProjectionHandlerContext extends DefaultRecord = DefaultRecord>(definitions: ProjectionDefinition<AnyEvent, ReadEventMetadataType, ProjectionHandlerContext>[]) => ProjectionRegistration<"inline", ReadEventMetadataType, ProjectionHandlerContext>[];
|
|
266
269
|
};
|
|
267
|
-
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/processors/processors.d.ts
|
|
268
272
|
type CurrentMessageProcessorPosition = {
|
|
269
|
-
|
|
273
|
+
lastCheckpoint: ProcessorCheckpoint;
|
|
270
274
|
} | 'BEGINNING' | 'END';
|
|
271
275
|
type GetCheckpoint<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata> = (message: RecordedMessage<MessageType, MessageMetadataType>) => ProcessorCheckpoint | null;
|
|
272
276
|
declare const getCheckpoint: <MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata>(message: RecordedMessage<MessageType, MessageMetadataType>) => ProcessorCheckpoint | null;
|
|
@@ -274,194 +278,201 @@ declare const wasMessageHandled: <MessageType extends AnyMessage = AnyMessage, M
|
|
|
274
278
|
type MessageProcessorStartFrom = CurrentMessageProcessorPosition | 'CURRENT';
|
|
275
279
|
type MessageProcessorType = 'projector' | 'reactor';
|
|
276
280
|
declare const MessageProcessorType: {
|
|
277
|
-
|
|
278
|
-
|
|
281
|
+
PROJECTOR: MessageProcessorType;
|
|
282
|
+
REACTOR: MessageProcessorType;
|
|
279
283
|
};
|
|
280
284
|
type MessageProcessor<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
285
|
+
id: string;
|
|
286
|
+
instanceId: string;
|
|
287
|
+
type: string;
|
|
288
|
+
canHandle?: string[];
|
|
289
|
+
init: (options: Partial<HandlerContext>) => Promise<void>;
|
|
290
|
+
start: (options: Partial<HandlerContext>) => Promise<CurrentMessageProcessorPosition | undefined>;
|
|
291
|
+
close: (closeOptions: Partial<HandlerContext>) => Promise<void>;
|
|
292
|
+
isActive: boolean;
|
|
293
|
+
handle: BatchRecordedMessageHandlerWithContext<MessageType, MessageMetadataType, Partial<HandlerContext>>;
|
|
290
294
|
};
|
|
291
295
|
declare const MessageProcessor: {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
296
|
+
result: {
|
|
297
|
+
skip: (options?: {
|
|
298
|
+
reason?: string;
|
|
299
|
+
}) => SingleMessageHandlerResult;
|
|
300
|
+
stop: (options?: {
|
|
301
|
+
reason?: string;
|
|
302
|
+
error?: EmmettError;
|
|
303
|
+
}) => SingleMessageHandlerResult;
|
|
304
|
+
};
|
|
301
305
|
};
|
|
302
306
|
type MessageProcessingScope<HandlerContext extends DefaultRecord | undefined = undefined> = <Result = SingleMessageHandlerResult>(handler: (context: HandlerContext) => Result | Promise<Result>, partialContext: Partial<HandlerContext>) => Result | Promise<Result>;
|
|
303
307
|
type Checkpointer<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
read: ReadProcessorCheckpoint<HandlerContext>;
|
|
309
|
+
store: StoreProcessorCheckpoint<MessageType, MessageMetadataType, HandlerContext>;
|
|
306
310
|
};
|
|
307
311
|
type ProcessorHooks<HandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
312
|
+
onInit?: OnReactorInitHook<HandlerContext>;
|
|
313
|
+
onStart?: OnReactorStartHook<HandlerContext>;
|
|
314
|
+
onClose?: OnReactorCloseHook<HandlerContext>;
|
|
311
315
|
};
|
|
312
316
|
type BaseMessageProcessorOptions<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
317
|
+
type?: string;
|
|
318
|
+
processorId: string;
|
|
319
|
+
processorInstanceId?: string;
|
|
320
|
+
version?: number;
|
|
321
|
+
partition?: string;
|
|
322
|
+
startFrom?: MessageProcessorStartFrom;
|
|
323
|
+
stopAfter?: (message: RecordedMessage<MessageType, MessageMetadataType>) => boolean;
|
|
324
|
+
processingScope?: MessageProcessingScope<HandlerContext>;
|
|
325
|
+
checkpoints?: Checkpointer<MessageType, MessageMetadataType, HandlerContext>;
|
|
326
|
+
canHandle?: CanHandle<MessageType>;
|
|
327
|
+
hooks?: ProcessorHooks<HandlerContext>;
|
|
324
328
|
} & JSONSerializationOptions;
|
|
325
329
|
type HandlerOptions<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
326
|
-
|
|
327
|
-
|
|
330
|
+
eachMessage: SingleRecordedMessageHandlerWithContext<MessageType, MessageMetadataType, HandlerContext>;
|
|
331
|
+
eachBatch?: never;
|
|
328
332
|
} | {
|
|
329
|
-
|
|
330
|
-
|
|
333
|
+
eachMessage?: never;
|
|
334
|
+
eachBatch: BatchRecordedMessageHandlerWithContext<MessageType, MessageMetadataType, HandlerContext>;
|
|
331
335
|
};
|
|
332
336
|
type OnReactorInitHook<HandlerContext extends DefaultRecord = DefaultRecord> = (context: HandlerContext) => Promise<void>;
|
|
333
337
|
type OnReactorStartHook<HandlerContext extends DefaultRecord = DefaultRecord> = (context: HandlerContext) => Promise<void>;
|
|
334
338
|
type OnReactorCloseHook<HandlerContext extends DefaultRecord = DefaultRecord> = (context: HandlerContext) => Promise<void>;
|
|
335
339
|
type ReactorOptions<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord, MessagePayloadType extends AnyMessage = MessageType> = BaseMessageProcessorOptions<MessageType, MessageMetadataType, HandlerContext> & HandlerOptions<MessageType, MessageMetadataType, HandlerContext> & {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
};
|
|
340
|
+
messageOptions?: {
|
|
341
|
+
schema?: {
|
|
342
|
+
versioning?: {
|
|
343
|
+
upcast?: (event: MessagePayloadType) => MessageType;
|
|
344
|
+
};
|
|
342
345
|
};
|
|
346
|
+
};
|
|
343
347
|
};
|
|
344
348
|
type ProjectorOptions<EventType extends AnyEvent = AnyEvent, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord, EventPayloadType extends Event = EventType> = Omit<BaseMessageProcessorOptions<EventType, MessageMetadataType, HandlerContext>, 'type' | 'processorId'> & {
|
|
345
|
-
|
|
349
|
+
processorId?: string;
|
|
346
350
|
} & {
|
|
347
|
-
|
|
348
|
-
|
|
351
|
+
truncateOnStart?: boolean;
|
|
352
|
+
projection: ProjectionDefinition<EventType, MessageMetadataType, HandlerContext, EventPayloadType>;
|
|
349
353
|
};
|
|
350
354
|
declare const defaultProcessingMessageProcessingScope: <HandlerContext = never, Result = SingleMessageHandlerResult>(handler: (context: HandlerContext) => Result | Promise<Result>, partialContext: Partial<HandlerContext>) => Result | Promise<Result>;
|
|
351
355
|
type ProcessorCheckpoint = Brand<string, 'ProcessorCheckpoint'>;
|
|
352
356
|
declare const bigIntProcessorCheckpoint: (value: bigint) => ProcessorCheckpoint;
|
|
353
357
|
declare const parseBigIntProcessorCheckpoint: (value: ProcessorCheckpoint) => bigint;
|
|
354
358
|
type ReadProcessorCheckpointResult = {
|
|
355
|
-
|
|
359
|
+
lastCheckpoint: ProcessorCheckpoint | null;
|
|
356
360
|
};
|
|
357
361
|
type ReadProcessorCheckpoint<HandlerContext extends DefaultRecord = DefaultRecord> = (options: {
|
|
358
|
-
|
|
359
|
-
|
|
362
|
+
processorId: string;
|
|
363
|
+
partition?: string;
|
|
360
364
|
}, context: HandlerContext) => Promise<ReadProcessorCheckpointResult>;
|
|
361
365
|
type StoreProcessorCheckpointResult = {
|
|
362
|
-
|
|
363
|
-
|
|
366
|
+
success: true;
|
|
367
|
+
newCheckpoint: ProcessorCheckpoint | null;
|
|
364
368
|
} | {
|
|
365
|
-
|
|
366
|
-
|
|
369
|
+
success: false;
|
|
370
|
+
reason: 'IGNORED' | 'MISMATCH' | 'CURRENT_AHEAD';
|
|
367
371
|
};
|
|
368
372
|
type StoreProcessorCheckpoint<MessageType extends Message = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (options: {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
373
|
+
message: RecordedMessage<MessageType, MessageMetadataType>;
|
|
374
|
+
processorId: string;
|
|
375
|
+
version: number | undefined;
|
|
376
|
+
lastCheckpoint: ProcessorCheckpoint | null;
|
|
377
|
+
partition?: string;
|
|
374
378
|
}, context: HandlerContext) => Promise<StoreProcessorCheckpointResult>;
|
|
375
379
|
declare const defaultProcessorVersion = 1;
|
|
376
380
|
declare const defaultProcessorPartition = "emt:default";
|
|
377
381
|
declare const getProcessorInstanceId: (processorId: string) => string;
|
|
378
382
|
declare const getProjectorId: (options: {
|
|
379
|
-
|
|
383
|
+
projectionName: string;
|
|
380
384
|
}) => string;
|
|
381
385
|
declare const reactor: <MessageType extends Message = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord, MessagePayloadType extends Message = MessageType>(options: ReactorOptions<MessageType, MessageMetadataType, HandlerContext, MessagePayloadType>) => MessageProcessor<MessageType, MessageMetadataType, HandlerContext>;
|
|
382
386
|
declare const projector: <EventType extends Event = Event, EventMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord, EventPayloadType extends Event = EventType>(options: ProjectorOptions<EventType, EventMetaDataType, HandlerContext, EventPayloadType>) => MessageProcessor<EventType, EventMetaDataType, HandlerContext>;
|
|
383
|
-
|
|
387
|
+
//#endregion
|
|
388
|
+
//#region src/processors/inMemoryProcessors.d.ts
|
|
384
389
|
type InMemoryProcessorHandlerContext = {
|
|
385
|
-
|
|
390
|
+
database: InMemoryDatabase;
|
|
386
391
|
};
|
|
387
392
|
type InMemoryProcessor<MessageType extends AnyMessage = AnyMessage> = MessageProcessor<MessageType, ReadEventMetadataWithGlobalPosition, InMemoryProcessorHandlerContext> & {
|
|
388
|
-
|
|
393
|
+
database: InMemoryDatabase;
|
|
389
394
|
};
|
|
390
395
|
type InMemoryProcessorEachMessageHandler<MessageType extends AnyMessage = AnyMessage> = SingleRecordedMessageHandlerWithContext<MessageType, ReadEventMetadataWithGlobalPosition, InMemoryProcessorHandlerContext>;
|
|
391
396
|
type InMemoryProcessorEachBatchHandler<MessageType extends AnyMessage = AnyMessage> = BatchRecordedMessageHandlerWithContext<MessageType, ReadEventMetadataWithGlobalPosition, InMemoryProcessorHandlerContext>;
|
|
392
397
|
type InMemoryProcessorConnectionOptions = {
|
|
393
|
-
|
|
398
|
+
database?: InMemoryDatabase;
|
|
394
399
|
};
|
|
395
400
|
type InMemoryCheckpointer<MessageType extends AnyMessage = AnyMessage> = Checkpointer<MessageType, ReadEventMetadataWithGlobalPosition, InMemoryProcessorHandlerContext>;
|
|
396
401
|
declare const inMemoryCheckpointer: <MessageType extends AnyMessage = AnyMessage>() => InMemoryCheckpointer<MessageType>;
|
|
397
402
|
type InMemoryConnectionOptions = {
|
|
398
|
-
|
|
403
|
+
connectionOptions?: InMemoryProcessorConnectionOptions;
|
|
399
404
|
};
|
|
400
405
|
type InMemoryReactorOptions<MessageType extends AnyMessage = AnyMessage> = ReactorOptions<MessageType, ReadEventMetadataWithGlobalPosition, InMemoryProcessorHandlerContext> & InMemoryConnectionOptions;
|
|
401
406
|
type InMemoryProjectorOptions<EventType extends AnyEvent = AnyEvent> = ProjectorOptions<EventType, ReadEventMetadataWithGlobalPosition, InMemoryProcessorHandlerContext> & InMemoryConnectionOptions;
|
|
402
407
|
type InMemoryProcessorOptions<MessageType extends AnyMessage = AnyMessage> = InMemoryReactorOptions<MessageType> | InMemoryProjectorOptions<MessageType & AnyEvent>;
|
|
403
408
|
declare const inMemoryProjector: <EventType extends AnyEvent = AnyEvent>(options: InMemoryProjectorOptions<EventType>) => InMemoryProcessor<EventType>;
|
|
404
409
|
declare const inMemoryReactor: <MessageType extends AnyMessage = AnyMessage>(options: InMemoryReactorOptions<MessageType>) => InMemoryProcessor<MessageType>;
|
|
405
|
-
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/typing/message.d.ts
|
|
406
412
|
type Message<Type extends string = string, Data extends DefaultRecord = DefaultRecord, MetaData extends DefaultRecord | undefined = undefined> = Command<Type, Data, MetaData> | Event<Type, Data, MetaData>;
|
|
407
413
|
type AnyMessage = AnyEvent | AnyCommand;
|
|
408
414
|
type MessageKindOf<T extends Message> = T['kind'];
|
|
409
415
|
type MessageTypeOf<T extends Message> = T['type'];
|
|
410
416
|
type MessageDataOf<T extends Message> = T['data'];
|
|
411
417
|
type MessageMetaDataOf<T extends Message> = T extends {
|
|
412
|
-
|
|
418
|
+
metadata: infer M;
|
|
413
419
|
} ? M : undefined;
|
|
414
420
|
type CanHandle<T extends Message> = MessageTypeOf<T>[];
|
|
415
421
|
declare const message: <MessageType extends Message<string, any, any>>(...args: MessageMetaDataOf<MessageType> extends undefined ? [kind: MessageKindOf<MessageType>, type: MessageTypeOf<MessageType>, data: MessageDataOf<MessageType>] : [kind: MessageKindOf<MessageType>, type: MessageTypeOf<MessageType>, data: MessageDataOf<MessageType>, metadata: MessageMetaDataOf<MessageType>]) => MessageType;
|
|
416
422
|
type CombinedMessageMetadata<MessageType extends Message = Message, MessageMetaDataType extends DefaultRecord = DefaultRecord> = MessageMetaDataOf<MessageType> extends undefined ? MessageMetaDataType : MessageMetaDataOf<MessageType> & MessageMetaDataType;
|
|
417
423
|
type CombineMetadata<MessageType extends Message = Message, MessageMetaDataType extends DefaultRecord = DefaultRecord> = MessageType & {
|
|
418
|
-
|
|
424
|
+
metadata: CombinedMessageMetadata<MessageType, MessageMetaDataType>;
|
|
419
425
|
};
|
|
420
426
|
type RecordedMessage<MessageType extends Message = Message, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = CombineMetadata<MessageType, MessageMetaDataType> & {
|
|
421
|
-
|
|
427
|
+
kind: NonNullable<MessageKindOf<Message>>;
|
|
422
428
|
};
|
|
423
429
|
type CommonRecordedMessageMetadata = Readonly<{
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
430
|
+
messageId: string;
|
|
431
|
+
streamPosition: StreamPosition;
|
|
432
|
+
streamName: string;
|
|
433
|
+
checkpoint?: ProcessorCheckpoint | null;
|
|
434
|
+
correlationId?: string;
|
|
435
|
+
causationId?: string;
|
|
436
|
+
traceId?: string;
|
|
437
|
+
spanId?: string;
|
|
428
438
|
}>;
|
|
429
439
|
type WithGlobalPosition = Readonly<{
|
|
430
|
-
|
|
440
|
+
globalPosition: GlobalPosition;
|
|
431
441
|
}>;
|
|
432
442
|
type RecordedMessageMetadata<HasGlobalPosition = undefined> = CommonRecordedMessageMetadata & (HasGlobalPosition extends undefined ? {} : WithGlobalPosition);
|
|
433
443
|
type AnyRecordedMessage = Message<any, any, any>;
|
|
434
444
|
type AnyRecordedMessageMetadata = RecordedMessageMetadata<any>;
|
|
435
445
|
type RecordedMessageMetadataWithGlobalPosition = RecordedMessageMetadata<true>;
|
|
436
446
|
type RecordedMessageMetadataWithoutGlobalPosition = RecordedMessageMetadata<undefined>;
|
|
437
|
-
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/typing/event.d.ts
|
|
438
449
|
type StreamPosition = bigint;
|
|
439
450
|
type GlobalPosition = bigint;
|
|
440
451
|
type Event<EventType extends string = string, EventData extends DefaultRecord = DefaultRecord, EventMetaData extends DefaultRecord | undefined = undefined> = Readonly<EventMetaData extends undefined ? {
|
|
441
|
-
|
|
442
|
-
|
|
452
|
+
type: EventType;
|
|
453
|
+
data: EventData;
|
|
443
454
|
} : {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
455
|
+
type: EventType;
|
|
456
|
+
data: EventData;
|
|
457
|
+
metadata: EventMetaData;
|
|
447
458
|
}> & {
|
|
448
|
-
|
|
459
|
+
readonly kind?: 'Event';
|
|
449
460
|
};
|
|
450
461
|
type AnyEvent = Event<any, any, any>;
|
|
451
462
|
type EventTypeOf<T extends Event> = T['type'];
|
|
452
463
|
type EventDataOf<T extends Event> = T['data'];
|
|
453
464
|
type EventMetaDataOf<T extends Event> = T extends {
|
|
454
|
-
|
|
465
|
+
metadata: infer M;
|
|
455
466
|
} ? M : undefined;
|
|
456
467
|
type CreateEventType<EventType extends string, EventData extends DefaultRecord, EventMetaData extends DefaultRecord | undefined = undefined> = Readonly<EventMetaData extends undefined ? {
|
|
457
|
-
|
|
458
|
-
|
|
468
|
+
type: EventType;
|
|
469
|
+
data: EventData;
|
|
459
470
|
} : {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
471
|
+
type: EventType;
|
|
472
|
+
data: EventData;
|
|
473
|
+
metadata: EventMetaData;
|
|
463
474
|
}> & {
|
|
464
|
-
|
|
475
|
+
readonly kind?: 'Event';
|
|
465
476
|
};
|
|
466
477
|
declare const event: <EventType extends Event<string, any, any>>(...args: EventMetaDataOf<EventType> extends undefined ? [type: EventTypeOf<EventType>, data: EventDataOf<EventType>] : [type: EventTypeOf<EventType>, data: EventDataOf<EventType>, metadata: EventMetaDataOf<EventType>]) => EventType;
|
|
467
478
|
type CombinedReadEventMetadata<EventType extends Event = Event, EventMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = CombinedMessageMetadata<EventType, EventMetaDataType>;
|
|
@@ -472,7 +483,8 @@ type ReadEventMetadata<HasGlobalPosition = undefined> = RecordedMessageMetadata<
|
|
|
472
483
|
type AnyReadEventMetadata = AnyRecordedMessageMetadata;
|
|
473
484
|
type ReadEventMetadataWithGlobalPosition = RecordedMessageMetadataWithGlobalPosition;
|
|
474
485
|
type ReadEventMetadataWithoutGlobalPosition = RecordedMessageMetadataWithoutGlobalPosition;
|
|
475
|
-
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/typing/messageHandling.d.ts
|
|
476
488
|
type SingleRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (message: MessageType) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
477
489
|
type SingleRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (message: RecordedMessage<MessageType, MessageMetaDataType>) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
478
490
|
type SingleMessageHandlerWithoutContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = never> = SingleRawMessageHandlerWithoutContext<MessageType> | SingleRecordedMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
@@ -489,39 +501,41 @@ type BatchMessageHandlerWithContext<MessageType extends AnyMessage = AnyMessage,
|
|
|
489
501
|
type BatchMessageHandler<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends DefaultRecord ? BatchMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext> : BatchMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
490
502
|
type MessageHandler<MessageType extends Message = Message, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (HandlerContext extends DefaultRecord ? SingleMessageHandler<MessageType, MessageMetaDataType, HandlerContext> : SingleMessageHandler<MessageType, MessageMetaDataType>) | (HandlerContext extends DefaultRecord ? BatchMessageHandler<MessageType, MessageMetaDataType, HandlerContext> : BatchMessageHandler<MessageType, MessageMetaDataType>);
|
|
491
503
|
type SingleMessageHandlerResult = void | {
|
|
492
|
-
|
|
504
|
+
type: 'ACK';
|
|
493
505
|
} | {
|
|
494
|
-
|
|
495
|
-
|
|
506
|
+
type: 'SKIP';
|
|
507
|
+
reason?: string;
|
|
496
508
|
} | {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
509
|
+
type: 'STOP';
|
|
510
|
+
reason?: string;
|
|
511
|
+
error?: EmmettError;
|
|
500
512
|
};
|
|
501
513
|
type BatchMessageHandlerResult = void | {
|
|
502
|
-
|
|
514
|
+
type: 'ACK';
|
|
503
515
|
} | {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
516
|
+
type: 'SKIP';
|
|
517
|
+
reason?: string;
|
|
518
|
+
lastSuccessfulMessage: AnyRecordedMessage;
|
|
507
519
|
} | {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
520
|
+
type: 'STOP';
|
|
521
|
+
reason?: string;
|
|
522
|
+
error?: EmmettError;
|
|
523
|
+
lastSuccessfulMessage?: AnyRecordedMessage;
|
|
512
524
|
};
|
|
513
|
-
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/typing/decider.d.ts
|
|
514
527
|
type Decider<State, CommandType extends Command, StreamEvent extends Event> = {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
528
|
+
decide: (command: CommandType, state: State) => StreamEvent | StreamEvent[];
|
|
529
|
+
evolve: (currentState: State, event: StreamEvent) => State;
|
|
530
|
+
initialState: () => State;
|
|
518
531
|
};
|
|
519
|
-
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/typing/index.d.ts
|
|
520
534
|
type Brand<K, T> = K & {
|
|
521
|
-
|
|
535
|
+
readonly __brand: T;
|
|
522
536
|
};
|
|
523
537
|
type Flavour<K, T> = K & {
|
|
524
|
-
|
|
538
|
+
readonly __brand?: T;
|
|
525
539
|
};
|
|
526
540
|
type DefaultRecord = Record<string, unknown>;
|
|
527
541
|
type AnyRecord = Record<string, any>;
|
|
@@ -530,7 +544,8 @@ declare const emmettPrefix = "emt";
|
|
|
530
544
|
declare const globalTag = "global";
|
|
531
545
|
declare const defaultTag = "emt:default";
|
|
532
546
|
declare const unknownTag = "emt:unknown";
|
|
533
|
-
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/eventStore/expectedVersion.d.ts
|
|
534
549
|
type ExpectedStreamVersion = ExpectedStreamVersionWithValue | ExpectedStreamVersionGeneral;
|
|
535
550
|
type ExpectedStreamVersionWithValue = Flavour<StreamPosition, 'StreamVersion'>;
|
|
536
551
|
type ExpectedStreamVersionGeneral = Flavour<'STREAM_EXISTS' | 'STREAM_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK', 'StreamVersion'>;
|
|
@@ -540,156 +555,163 @@ declare const NO_CONCURRENCY_CHECK: ExpectedStreamVersionGeneral;
|
|
|
540
555
|
declare const matchesExpectedVersion: (current: StreamPosition | undefined, expected: ExpectedStreamVersion, defaultVersion: StreamPosition) => boolean;
|
|
541
556
|
declare const assertExpectedVersionMatchesCurrent: (current: StreamPosition, expected: ExpectedStreamVersion | undefined, defaultVersion: StreamPosition) => void;
|
|
542
557
|
declare class ExpectedVersionConflictError extends ConcurrencyError {
|
|
543
|
-
|
|
558
|
+
constructor(current: StreamPosition, expected: ExpectedStreamVersion);
|
|
544
559
|
}
|
|
545
560
|
declare const isExpectedVersionConflictError: (error: unknown) => error is ExpectedVersionConflictError;
|
|
546
|
-
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/eventStore/eventStore.d.ts
|
|
547
563
|
interface EventStore<ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata> {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
564
|
+
aggregateStream<State, EventType extends Event, EventPayloadType extends Event = EventType>(streamName: string, options: AggregateStreamOptions<State, EventType, ReadEventMetadataType, EventPayloadType>): Promise<AggregateStreamResult<State>>;
|
|
565
|
+
readStream<EventType extends Event, EventPayloadType extends Event = EventType>(streamName: string, options?: ReadStreamOptions<EventType, EventPayloadType>): Promise<ReadStreamResult<EventType, ReadEventMetadataType>>;
|
|
566
|
+
appendToStream<EventType extends Event, EventPayloadType extends Event = EventType>(streamName: string, events: EventType[], options?: AppendToStreamOptions<EventType, EventPayloadType>): Promise<AppendToStreamResult>;
|
|
567
|
+
streamExists(streamName: string): Promise<StreamExistsResult>;
|
|
552
568
|
}
|
|
553
569
|
type EventStoreReadEventMetadata<Store extends EventStore> = Store extends EventStore<infer T> ? T extends CommonReadEventMetadata ? T extends WithGlobalPosition ? ReadEventMetadata<true> & T : ReadEventMetadata<undefined> & T : never : never;
|
|
554
570
|
type EventStoreSession<EventStoreType extends EventStore> = {
|
|
555
|
-
|
|
556
|
-
|
|
571
|
+
eventStore: EventStoreType;
|
|
572
|
+
close: () => Promise<void>;
|
|
557
573
|
};
|
|
558
574
|
interface EventStoreSessionFactory<EventStoreType extends EventStore> {
|
|
559
|
-
|
|
575
|
+
withSession<T = unknown>(callback: (session: EventStoreSession<EventStoreType>) => Promise<T>): Promise<T>;
|
|
560
576
|
}
|
|
561
577
|
declare const canCreateEventStoreSession: <Store extends EventStore>(eventStore: Store | EventStoreSessionFactory<Store>) => eventStore is EventStoreSessionFactory<Store>;
|
|
562
578
|
declare const nulloSessionFactory: <EventStoreType extends EventStore>(eventStore: EventStoreType) => EventStoreSessionFactory<EventStoreType>;
|
|
563
579
|
type EventStoreReadSchemaOptions<StreamEvent extends Event = Event, StoredEvent extends Event = StreamEvent> = {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
580
|
+
versioning?: {
|
|
581
|
+
upcast?: (event: StoredEvent) => StreamEvent;
|
|
582
|
+
};
|
|
567
583
|
};
|
|
568
584
|
type EventStoreAppendSchemaOptions<StreamEvent extends Event = Event, StoredEvent extends Event = StreamEvent> = {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
585
|
+
versioning?: {
|
|
586
|
+
downcast?: (event: StreamEvent) => StoredEvent;
|
|
587
|
+
};
|
|
572
588
|
};
|
|
573
589
|
type EventStoreSchemaOptions<StreamEvent extends Event = Event, StoredEvent extends Event = StreamEvent> = EventStoreReadSchemaOptions<StreamEvent, StoredEvent> & EventStoreAppendSchemaOptions<StreamEvent, StoredEvent>;
|
|
574
590
|
type ReadStreamOptions<EventType extends Event = Event, EventPayloadType extends Event = EventType> = {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
591
|
+
from?: StreamPosition;
|
|
592
|
+
to?: StreamPosition;
|
|
593
|
+
maxCount?: bigint;
|
|
594
|
+
expectedStreamVersion?: ExpectedStreamVersion;
|
|
595
|
+
schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
|
|
580
596
|
} & JSONSerializationOptions;
|
|
581
597
|
type ReadStreamResult<EventType extends Event, ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata> = {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
598
|
+
currentStreamVersion: StreamPosition;
|
|
599
|
+
events: ReadEvent<EventType, ReadEventMetadataType>[];
|
|
600
|
+
streamExists: boolean;
|
|
585
601
|
};
|
|
586
602
|
type Evolve<State, EventType extends Event, ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata> = ((currentState: State, event: EventType) => State) | ((currentState: State, event: ReadEvent<EventType, ReadEventMetadataType>) => State) | ((currentState: State, event: ReadEvent<EventType>) => State);
|
|
587
603
|
type AggregateStreamOptions<State, EventType extends Event, ReadEventMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, EventPayloadType extends Event = EventType> = {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
604
|
+
evolve: Evolve<State, EventType, ReadEventMetadataType>;
|
|
605
|
+
initialState: () => State;
|
|
606
|
+
read?: ReadStreamOptions<EventType, EventPayloadType>;
|
|
591
607
|
};
|
|
592
608
|
type AggregateStreamResult<State> = {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
609
|
+
currentStreamVersion: StreamPosition;
|
|
610
|
+
state: State;
|
|
611
|
+
streamExists: boolean;
|
|
596
612
|
};
|
|
597
613
|
type AggregateStreamResultWithGlobalPosition<State> = (AggregateStreamResult<State> & {
|
|
598
|
-
|
|
599
|
-
|
|
614
|
+
streamExists: true;
|
|
615
|
+
lastEventGlobalPosition: GlobalPosition;
|
|
600
616
|
}) | (AggregateStreamResult<State> & {
|
|
601
|
-
|
|
617
|
+
streamExists: false;
|
|
602
618
|
});
|
|
603
|
-
type AggregateStreamResultOfEventStore<Store extends EventStore> = Store['aggregateStream'] extends (...args: any[]) => Promise<infer R> ? R : never;
|
|
619
|
+
type AggregateStreamResultOfEventStore<Store extends EventStore> = Store['aggregateStream'] extends ((...args: any[]) => Promise<infer R>) ? R : never;
|
|
604
620
|
type AppendToStreamOptions<EventType extends Event = Event, EventPayloadType extends Event = EventType> = {
|
|
605
|
-
|
|
606
|
-
|
|
621
|
+
expectedStreamVersion?: ExpectedStreamVersion;
|
|
622
|
+
schema?: EventStoreAppendSchemaOptions<EventType, EventPayloadType> & JSONSerializationOptions;
|
|
623
|
+
correlationId?: string;
|
|
624
|
+
causationId?: string;
|
|
625
|
+
traceId?: string;
|
|
626
|
+
spanId?: string;
|
|
607
627
|
};
|
|
608
628
|
type AppendToStreamResult = {
|
|
609
|
-
|
|
610
|
-
|
|
629
|
+
nextExpectedStreamVersion: StreamPosition;
|
|
630
|
+
createdNewStream: boolean;
|
|
611
631
|
};
|
|
612
632
|
type AppendToStreamResultWithGlobalPosition = AppendToStreamResult & {
|
|
613
|
-
|
|
633
|
+
lastEventGlobalPosition: GlobalPosition;
|
|
614
634
|
};
|
|
615
|
-
type AppendStreamResultOfEventStore<Store extends EventStore> = Store['appendToStream'] extends (...args: any[]) => Promise<infer R> ? R : never;
|
|
635
|
+
type AppendStreamResultOfEventStore<Store extends EventStore> = Store['appendToStream'] extends ((...args: any[]) => Promise<infer R>) ? R : never;
|
|
616
636
|
type StreamExistsResult = boolean;
|
|
617
637
|
type DefaultEventStoreOptions<Store extends EventStore, HandlerContext extends DefaultRecord | undefined = undefined> = {
|
|
638
|
+
/**
|
|
639
|
+
* Pluggable set of hooks informing about the event store internal behaviour.
|
|
640
|
+
*/
|
|
641
|
+
hooks?: {
|
|
618
642
|
/**
|
|
619
|
-
*
|
|
643
|
+
* This hook will be called **AFTER** events were stored in the event store.
|
|
644
|
+
* It's designed to handle scenarios where delivery and ordering guarantees do not matter much.
|
|
645
|
+
*
|
|
646
|
+
* **WARNINGS:**
|
|
647
|
+
*
|
|
648
|
+
* 1. It will be called **EXACTLY ONCE** if append succeded.
|
|
649
|
+
* 2. If the hook fails, its append **will still silently succeed**, and no error will be thrown.
|
|
650
|
+
* 3. Wen process crashes after events were committed, but before the hook was called, delivery won't be retried.
|
|
651
|
+
* That can lead to state inconsistencies.
|
|
652
|
+
* 4. In the case of high concurrent traffic, **race conditions may cause ordering issues**.
|
|
653
|
+
* For instance, where the second hook takes longer to process than the first one, ordering won't be guaranteed.
|
|
654
|
+
*
|
|
655
|
+
* @type {AfterEventStoreCommitHandler<Store, HandlerContext>}
|
|
620
656
|
*/
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
* This hook will be called **AFTER** events were stored in the event store.
|
|
624
|
-
* It's designed to handle scenarios where delivery and ordering guarantees do not matter much.
|
|
625
|
-
*
|
|
626
|
-
* **WARNINGS:**
|
|
627
|
-
*
|
|
628
|
-
* 1. It will be called **EXACTLY ONCE** if append succeded.
|
|
629
|
-
* 2. If the hook fails, its append **will still silently succeed**, and no error will be thrown.
|
|
630
|
-
* 3. Wen process crashes after events were committed, but before the hook was called, delivery won't be retried.
|
|
631
|
-
* That can lead to state inconsistencies.
|
|
632
|
-
* 4. In the case of high concurrent traffic, **race conditions may cause ordering issues**.
|
|
633
|
-
* For instance, where the second hook takes longer to process than the first one, ordering won't be guaranteed.
|
|
634
|
-
*
|
|
635
|
-
* @type {AfterEventStoreCommitHandler<Store, HandlerContext>}
|
|
636
|
-
*/
|
|
637
|
-
onAfterCommit?: AfterEventStoreCommitHandler<Store, HandlerContext>;
|
|
638
|
-
};
|
|
657
|
+
onAfterCommit?: AfterEventStoreCommitHandler<Store, HandlerContext>;
|
|
658
|
+
};
|
|
639
659
|
};
|
|
640
|
-
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/eventStore/afterCommit/afterEventStoreCommitHandler.d.ts
|
|
641
662
|
type AfterEventStoreCommitHandler<Store extends EventStore, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends undefined ? BatchRecordedMessageHandlerWithoutContext<Event, EventStoreReadEventMetadata<Store>> : BatchRecordedMessageHandlerWithContext<Event, EventStoreReadEventMetadata<Store>, NonNullable<HandlerContext>>;
|
|
642
663
|
type BeforeEventStoreCommitHandler<Store extends EventStore, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends undefined ? BatchRecordedMessageHandlerWithoutContext<Event, EventStoreReadEventMetadata<Store>> : BatchRecordedMessageHandlerWithContext<Event, EventStoreReadEventMetadata<Store>, NonNullable<HandlerContext>>;
|
|
643
664
|
type TryPublishMessagesAfterCommitOptions<Store extends EventStore, HandlerContext extends DefaultRecord | undefined = undefined> = {
|
|
644
|
-
|
|
665
|
+
onAfterCommit?: AfterEventStoreCommitHandler<Store, HandlerContext>;
|
|
645
666
|
};
|
|
646
667
|
declare function tryPublishMessagesAfterCommit<Store extends EventStore>(messages: ReadEvent<Event, EventStoreReadEventMetadata<Store>>[], options: TryPublishMessagesAfterCommitOptions<Store, undefined> | undefined): Promise<boolean>;
|
|
647
668
|
declare function tryPublishMessagesAfterCommit<Store extends EventStore, HandlerContext extends DefaultRecord | undefined = undefined>(messages: ReadEvent<Event, EventStoreReadEventMetadata<Store>>[], options: TryPublishMessagesAfterCommitOptions<Store, HandlerContext> | undefined, context: HandlerContext): Promise<boolean>;
|
|
648
|
-
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region src/messageBus/index.d.ts
|
|
649
671
|
interface CommandSender {
|
|
650
|
-
|
|
672
|
+
send<CommandType extends Command = Command>(command: CommandType): Promise<void>;
|
|
651
673
|
}
|
|
652
674
|
interface EventsPublisher {
|
|
653
|
-
|
|
675
|
+
publish<EventType extends Event = Event>(event: EventType): Promise<void>;
|
|
654
676
|
}
|
|
655
677
|
type ScheduleOptions = {
|
|
656
|
-
|
|
678
|
+
afterInMs: number;
|
|
657
679
|
} | {
|
|
658
|
-
|
|
680
|
+
at: Date;
|
|
659
681
|
};
|
|
660
682
|
interface MessageScheduler<CommandOrEvent extends Command | Event> {
|
|
661
|
-
|
|
662
|
-
}
|
|
663
|
-
interface CommandBus extends CommandSender, MessageScheduler<Command> {
|
|
664
|
-
}
|
|
665
|
-
interface EventBus extends EventsPublisher, MessageScheduler<Event> {
|
|
683
|
+
schedule<MessageType extends CommandOrEvent>(message: MessageType, when?: ScheduleOptions): void;
|
|
666
684
|
}
|
|
685
|
+
interface CommandBus extends CommandSender, MessageScheduler<Command> {}
|
|
686
|
+
interface EventBus extends EventsPublisher, MessageScheduler<Event> {}
|
|
667
687
|
interface MessageBus extends CommandBus, EventBus {
|
|
668
|
-
|
|
688
|
+
schedule<MessageType extends Command | Event>(message: MessageType, when?: ScheduleOptions): void;
|
|
669
689
|
}
|
|
670
690
|
interface CommandProcessor {
|
|
671
|
-
|
|
691
|
+
handle<CommandType extends Command>(commandHandler: SingleMessageHandler<CommandType>, ...commandTypes: CommandTypeOf<CommandType>[]): void;
|
|
672
692
|
}
|
|
673
693
|
interface EventSubscription {
|
|
674
|
-
|
|
694
|
+
subscribe<EventType extends Event>(eventHandler: SingleMessageHandler<EventType>, ...eventTypes: EventTypeOf<EventType>[]): void;
|
|
675
695
|
}
|
|
676
696
|
type ScheduledMessage = {
|
|
677
|
-
|
|
678
|
-
|
|
697
|
+
message: Message;
|
|
698
|
+
options?: ScheduleOptions;
|
|
679
699
|
};
|
|
680
700
|
interface ScheduledMessageProcessor {
|
|
681
|
-
|
|
701
|
+
dequeue(): ScheduledMessage[];
|
|
682
702
|
}
|
|
683
703
|
type MessageSubscription = EventSubscription | CommandProcessor;
|
|
684
704
|
declare const getInMemoryMessageBus: () => MessageBus & EventSubscription & CommandProcessor & ScheduledMessageProcessor;
|
|
685
|
-
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/eventStore/afterCommit/forwardToMessageBus.d.ts
|
|
686
707
|
declare const forwardToMessageBus: <Store extends EventStore, HandlerContext extends DefaultRecord | undefined = undefined>(eventPublisher: EventsPublisher) => AfterEventStoreCommitHandler<Store, HandlerContext>;
|
|
687
|
-
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/eventStore/events/index.d.ts
|
|
688
710
|
declare const GlobalStreamCaughtUpType = "__emt:GlobalStreamCaughtUp";
|
|
689
711
|
type GlobalStreamCaughtUp = Event<'__emt:GlobalStreamCaughtUp', {
|
|
690
|
-
|
|
712
|
+
globalPosition: bigint;
|
|
691
713
|
}, {
|
|
692
|
-
|
|
714
|
+
globalPosition: bigint;
|
|
693
715
|
}>;
|
|
694
716
|
declare const isGlobalStreamCaughtUp: (event: Event) => event is GlobalStreamCaughtUp;
|
|
695
717
|
declare const caughtUpEventFrom: (position: bigint) => (event: ReadEvent<Event, ReadEventMetadataWithGlobalPosition>) => event is ReadEvent<GlobalStreamCaughtUp, ReadEventMetadataWithGlobalPosition>;
|
|
@@ -697,30 +719,32 @@ declare const globalStreamCaughtUp: (data: EventDataOf<GlobalStreamCaughtUp>) =>
|
|
|
697
719
|
declare const isSubscriptionEvent: (event: Event) => event is GlobalSubscriptionEvent;
|
|
698
720
|
declare const isNotInternalEvent: (event: Event) => boolean;
|
|
699
721
|
type GlobalSubscriptionEvent = GlobalStreamCaughtUp;
|
|
700
|
-
|
|
722
|
+
//#endregion
|
|
723
|
+
//#region src/eventStore/inMemoryEventStore.d.ts
|
|
701
724
|
declare const InMemoryEventStoreDefaultStreamVersion = 0n;
|
|
702
725
|
type InMemoryEventStore = EventStore<ReadEventMetadataWithGlobalPosition> & {
|
|
703
|
-
|
|
726
|
+
database: InMemoryDatabase;
|
|
704
727
|
};
|
|
705
728
|
type InMemoryReadEventMetadata = ReadEventMetadataWithGlobalPosition;
|
|
706
729
|
type InMemoryProjectionHandlerContext = {
|
|
707
|
-
|
|
708
|
-
|
|
730
|
+
eventStore?: InMemoryEventStore;
|
|
731
|
+
database?: InMemoryDatabase;
|
|
709
732
|
};
|
|
710
733
|
type InMemoryEventStoreOptions = DefaultEventStoreOptions<InMemoryEventStore> & {
|
|
711
|
-
|
|
712
|
-
|
|
734
|
+
projections?: ProjectionRegistration<'inline', InMemoryReadEventMetadata, InMemoryProjectionHandlerContext>[];
|
|
735
|
+
database?: InMemoryDatabase;
|
|
713
736
|
};
|
|
714
737
|
type InMemoryReadEvent<EventType extends Event = Event> = ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>;
|
|
715
738
|
declare const getInMemoryEventStore: (eventStoreOptions?: InMemoryEventStoreOptions) => InMemoryEventStore;
|
|
716
|
-
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/eventStore/projections/inMemory/inMemoryProjection.d.ts
|
|
717
741
|
declare const DATABASE_REQUIRED_ERROR_MESSAGE = "Database is required in context for InMemory projections";
|
|
718
742
|
type InMemoryProjectionDefinition<EventType extends Event> = ProjectionDefinition<EventType, InMemoryReadEventMetadata, InMemoryProjectionHandlerContext>;
|
|
719
743
|
type InMemoryProjectionHandlerOptions<EventType extends Event = Event> = {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
744
|
+
projections: InMemoryProjectionDefinition<EventType>[];
|
|
745
|
+
events: ReadEvent<EventType, InMemoryReadEventMetadata>[];
|
|
746
|
+
database: InMemoryDatabase;
|
|
747
|
+
eventStore?: InMemoryProjectionHandlerContext['eventStore'];
|
|
724
748
|
};
|
|
725
749
|
/**
|
|
726
750
|
* Handles projections for the InMemoryEventStore
|
|
@@ -731,30 +755,34 @@ type InMemoryWithNotNullDocumentEvolve<DocumentType extends Record<string, unkno
|
|
|
731
755
|
type InMemoryWithNullableDocumentEvolve<DocumentType extends Record<string, unknown>, EventType extends Event> = (document: DocumentType | null, event: ReadEvent<EventType, InMemoryReadEventMetadata>) => DocumentType | null;
|
|
732
756
|
type InMemoryDocumentEvolve<DocumentType extends Record<string, unknown>, EventType extends Event> = InMemoryWithNotNullDocumentEvolve<DocumentType, EventType> | InMemoryWithNullableDocumentEvolve<DocumentType, EventType>;
|
|
733
757
|
type InMemoryProjectionOptions<EventType extends Event> = {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
758
|
+
handle: (events: ReadEvent<EventType, InMemoryReadEventMetadata>[], context: InMemoryProjectionHandlerContext & {
|
|
759
|
+
database: InMemoryDatabase;
|
|
760
|
+
}) => Promise<void>;
|
|
761
|
+
canHandle: CanHandle<EventType>;
|
|
762
|
+
truncate?: TruncateProjection<InMemoryProjectionHandlerContext & {
|
|
763
|
+
database: InMemoryDatabase;
|
|
764
|
+
}>;
|
|
741
765
|
};
|
|
742
766
|
/**
|
|
743
767
|
* Creates an InMemory projection
|
|
744
768
|
*/
|
|
745
|
-
declare const inMemoryProjection: <EventType extends Event>({
|
|
769
|
+
declare const inMemoryProjection: <EventType extends Event>({
|
|
770
|
+
truncate,
|
|
771
|
+
handle,
|
|
772
|
+
canHandle
|
|
773
|
+
}: InMemoryProjectionOptions<EventType>) => InMemoryProjectionDefinition<EventType>;
|
|
746
774
|
/**
|
|
747
775
|
* Creates a multi-stream projection for InMemoryDatabase
|
|
748
776
|
*/
|
|
749
777
|
type InMemoryMultiStreamProjectionOptions<DocumentType extends Record<string, unknown>, EventType extends Event> = {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
778
|
+
canHandle: CanHandle<EventType>;
|
|
779
|
+
collectionName: string;
|
|
780
|
+
getDocumentId: (event: ReadEvent<EventType>) => string;
|
|
753
781
|
} & ({
|
|
754
|
-
|
|
782
|
+
evolve: InMemoryWithNullableDocumentEvolve<DocumentType, EventType>;
|
|
755
783
|
} | {
|
|
756
|
-
|
|
757
|
-
|
|
784
|
+
evolve: InMemoryWithNotNullDocumentEvolve<DocumentType, EventType>;
|
|
785
|
+
initialState: () => DocumentType;
|
|
758
786
|
});
|
|
759
787
|
/**
|
|
760
788
|
* Creates a projection that handles events across multiple streams
|
|
@@ -764,22 +792,23 @@ declare const inMemoryMultiStreamProjection: <DocumentType extends Record<string
|
|
|
764
792
|
* Creates a single-stream projection for InMemoryDatabase
|
|
765
793
|
*/
|
|
766
794
|
type InMemorySingleStreamProjectionOptions<DocumentType extends Record<string, unknown>, EventType extends Event> = {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
795
|
+
canHandle: CanHandle<EventType>;
|
|
796
|
+
getDocumentId?: (event: ReadEvent<EventType>) => string;
|
|
797
|
+
collectionName: string;
|
|
770
798
|
} & ({
|
|
771
|
-
|
|
799
|
+
evolve: InMemoryWithNullableDocumentEvolve<DocumentType, EventType>;
|
|
772
800
|
} | {
|
|
773
|
-
|
|
774
|
-
|
|
801
|
+
evolve: InMemoryWithNotNullDocumentEvolve<DocumentType, EventType>;
|
|
802
|
+
initialState: () => DocumentType;
|
|
775
803
|
});
|
|
776
804
|
/**
|
|
777
805
|
* Creates a projection that handles events from a single stream
|
|
778
806
|
*/
|
|
779
807
|
declare const inMemorySingleStreamProjection: <DocumentType extends Record<string, unknown>, EventType extends Event>(options: InMemorySingleStreamProjectionOptions<DocumentType, EventType>) => InMemoryProjectionDefinition<EventType>;
|
|
780
|
-
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/testing/assertions.d.ts
|
|
781
810
|
declare class AssertionError extends Error {
|
|
782
|
-
|
|
811
|
+
constructor(message: string);
|
|
783
812
|
}
|
|
784
813
|
declare const isSubset: (superObj: unknown, subObj: unknown) => boolean;
|
|
785
814
|
declare const assertFails: (message?: string) => never;
|
|
@@ -791,254 +820,278 @@ declare const assertMatches: (actual: unknown, expected: unknown, message?: stri
|
|
|
791
820
|
declare const assertDeepEqual: <T = unknown>(actual: T, expected: T, message?: string) => void;
|
|
792
821
|
declare const assertNotDeepEqual: <T = unknown>(actual: T, expected: T, message?: string) => void;
|
|
793
822
|
declare const assertThat: <T>(item: T) => {
|
|
794
|
-
|
|
823
|
+
isEqualTo: (other: T) => void;
|
|
795
824
|
};
|
|
796
|
-
declare
|
|
825
|
+
declare function assertDefined<T>(value: T, message?: string | Error): asserts value is NonNullable<T>;
|
|
826
|
+
declare function assertUndefined<T>(value: T | undefined, message?: string | Error): asserts value is undefined;
|
|
797
827
|
declare function assertFalse(condition: boolean, message?: string): asserts condition is false;
|
|
798
828
|
declare function assertTrue(condition: boolean, message?: string): asserts condition is true;
|
|
799
829
|
declare function assertOk<T>(obj: T | null | undefined, message?: string): asserts obj is T;
|
|
800
830
|
declare function assertEqual<T>(expected: T | null | undefined, actual: T | null | undefined, message?: string): void;
|
|
801
831
|
declare function assertNotEqual<T>(obj: T | null | undefined, other: T | null | undefined, message?: string): void;
|
|
802
|
-
declare function assertIsNotNull<T extends object | bigint>(result: T | null): asserts result is T;
|
|
803
|
-
declare function assertIsNull<T extends object>(result: T | null): asserts result is null;
|
|
832
|
+
declare function assertIsNotNull<T extends object | string | bigint | boolean | number>(result: T | null): asserts result is T;
|
|
833
|
+
declare function assertIsNull<T extends object | string | bigint | boolean | number>(result: T | null): asserts result is null;
|
|
804
834
|
type Call = {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
835
|
+
arguments: unknown[];
|
|
836
|
+
result: unknown;
|
|
837
|
+
target: unknown;
|
|
838
|
+
this: unknown;
|
|
809
839
|
};
|
|
810
840
|
type ArgumentMatcher = (arg: unknown) => boolean;
|
|
811
841
|
declare const argValue: <T>(value: T) => ArgumentMatcher;
|
|
812
842
|
declare const argMatches: <T>(matches: (arg: T) => boolean) => ArgumentMatcher;
|
|
813
843
|
type MockedFunction = Function & {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
844
|
+
mock?: {
|
|
845
|
+
calls: Call[];
|
|
846
|
+
};
|
|
817
847
|
};
|
|
818
848
|
declare function verifyThat(fn: MockedFunction): {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
849
|
+
calledTimes: (times: number) => void;
|
|
850
|
+
notCalled: () => void;
|
|
851
|
+
called: () => void;
|
|
852
|
+
calledWith: (...args: unknown[]) => void;
|
|
853
|
+
calledOnceWith: (...args: unknown[]) => void;
|
|
854
|
+
calledWithArgumentMatching: (...matches: ArgumentMatcher[]) => void;
|
|
855
|
+
notCalledWithArgumentMatching: (...matches: ArgumentMatcher[]) => void;
|
|
826
856
|
};
|
|
827
857
|
declare const assertThatArray: <T>(array: T[]) => {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
};
|
|
845
|
-
|
|
858
|
+
isEmpty: () => void;
|
|
859
|
+
isNotEmpty: () => void;
|
|
860
|
+
hasSize: (length: number) => void;
|
|
861
|
+
containsElements: (other: T[]) => void;
|
|
862
|
+
containsElementsMatching: (other: T[]) => void;
|
|
863
|
+
containsOnlyElementsMatching: (other: T[]) => void;
|
|
864
|
+
containsExactlyInAnyOrder: (other: T[]) => void;
|
|
865
|
+
containsExactlyInAnyOrderElementsOf: (other: T[]) => void;
|
|
866
|
+
containsExactlyElementsOf: (other: T[]) => void;
|
|
867
|
+
containsExactly: (elem: T) => void;
|
|
868
|
+
contains: (elem: T) => void;
|
|
869
|
+
containsOnlyOnceElementsOf: (other: T[]) => void;
|
|
870
|
+
containsAnyOf: (other: T[]) => void;
|
|
871
|
+
allMatch: (matches: (item: T) => boolean) => void;
|
|
872
|
+
anyMatches: (matches: (item: T) => boolean) => void;
|
|
873
|
+
allMatchAsync: (matches: (item: T) => Promise<boolean>) => Promise<void>;
|
|
874
|
+
};
|
|
875
|
+
//#endregion
|
|
876
|
+
//#region src/testing/deciderSpecification.d.ts
|
|
846
877
|
type ErrorCheck<ErrorType> = (error: ErrorType) => boolean;
|
|
847
878
|
type ThenThrows<ErrorType extends Error> = (() => void) | ((errorConstructor: ErrorConstructor<ErrorType>) => void) | ((errorCheck: ErrorCheck<ErrorType>) => void) | ((errorConstructor: ErrorConstructor<ErrorType>, errorCheck?: ErrorCheck<ErrorType>) => void);
|
|
848
|
-
type AsyncDeciderSpecification<Command, Event> = (givenEvents: Event | Event[]) => {
|
|
849
|
-
when: (command: Command) => {
|
|
850
|
-
then: (expectedEvents: Event | Event[]) => Promise<void>;
|
|
851
|
-
thenNothingHappened: () => Promise<void>;
|
|
852
|
-
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => Promise<void>;
|
|
853
|
-
};
|
|
854
|
-
};
|
|
855
879
|
type DeciderSpecification<Command, Event> = (givenEvents: Event | Event[]) => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
880
|
+
when: (command: Command) => {
|
|
881
|
+
then: (expectedEvents: Event | Event[]) => void;
|
|
882
|
+
thenNothingHappened: () => void;
|
|
883
|
+
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => void;
|
|
884
|
+
};
|
|
885
|
+
};
|
|
886
|
+
type AsyncDeciderSpecification<Command, Event> = (givenEvents: Event | Event[]) => {
|
|
887
|
+
when: (command: Command) => {
|
|
888
|
+
then: (expectedEvents: Event | Event[]) => Promise<void>;
|
|
889
|
+
thenNothingHappened: () => Promise<void>;
|
|
890
|
+
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => Promise<void>;
|
|
891
|
+
};
|
|
861
892
|
};
|
|
862
893
|
declare const DeciderSpecification: {
|
|
863
|
-
|
|
894
|
+
for: typeof deciderSpecificationFor;
|
|
864
895
|
};
|
|
865
896
|
declare function deciderSpecificationFor<Command, Event, State>(decider: {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
897
|
+
decide: (command: Command, state: State) => Event | Event[];
|
|
898
|
+
evolve: (state: State, event: Event) => State;
|
|
899
|
+
initialState: () => State;
|
|
869
900
|
}): DeciderSpecification<Command, Event>;
|
|
870
901
|
declare function deciderSpecificationFor<Command, Event, State>(decider: {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
902
|
+
decide: (command: Command, state: State) => Promise<Event | Event[]>;
|
|
903
|
+
evolve: (state: State, event: Event) => State;
|
|
904
|
+
initialState: () => State;
|
|
874
905
|
}): AsyncDeciderSpecification<Command, Event>;
|
|
875
|
-
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/workflows/workflow.d.ts
|
|
908
|
+
type Workflow<Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand, Name extends string = string> = {
|
|
909
|
+
name: Name;
|
|
910
|
+
decide: (command: Input, state: State) => WorkflowOutput<Output>;
|
|
911
|
+
evolve: (currentState: State, event: WorkflowEvent<Input | Output>) => State;
|
|
912
|
+
initialState: () => State;
|
|
913
|
+
};
|
|
876
914
|
type WorkflowEvent<Output extends AnyEvent | AnyCommand> = Extract<Output, {
|
|
877
|
-
|
|
915
|
+
kind?: 'Event';
|
|
878
916
|
}>;
|
|
879
917
|
type WorkflowCommand<Output extends AnyEvent | AnyCommand> = Extract<Output, {
|
|
880
|
-
|
|
918
|
+
kind?: 'Command';
|
|
881
919
|
}>;
|
|
882
920
|
type WorkflowMessageAction = 'InitiatedBy' | 'Received' | 'Sent' | 'Published' | 'Scheduled';
|
|
883
921
|
type WorkflowInputMessageMetadata = Readonly<{
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
922
|
+
originalMessageId: string | undefined;
|
|
923
|
+
input: true;
|
|
924
|
+
action?: Extract<WorkflowMessageAction, 'InitiatedBy' | 'Received'>;
|
|
887
925
|
}>;
|
|
888
926
|
type WorkflowOutputMessageMetadata = Readonly<{
|
|
889
|
-
|
|
927
|
+
action?: Extract<WorkflowMessageAction, 'Sent' | 'Published' | 'Scheduled'>;
|
|
890
928
|
}>;
|
|
891
929
|
type WorkflowOutput<Output extends AnyEvent | AnyCommand | EmmettError> = Output | Output[];
|
|
892
|
-
type Workflow<Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand, Name extends string = string> = {
|
|
893
|
-
name: Name;
|
|
894
|
-
decide: (command: Input, state: State) => WorkflowOutput<Output>;
|
|
895
|
-
evolve: (currentState: State, event: WorkflowEvent<Input | Output>) => State;
|
|
896
|
-
initialState: () => State;
|
|
897
|
-
};
|
|
898
930
|
declare const Workflow: <Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand>(workflow: Workflow<Input, State, Output>) => Workflow<Input, State, Output>;
|
|
899
|
-
|
|
931
|
+
//#endregion
|
|
932
|
+
//#region src/testing/workflowSpecification.d.ts
|
|
900
933
|
type WorkflowSpecification<Input extends AnyEvent | AnyCommand, Output extends AnyEvent | AnyCommand> = (givenEvents: WorkflowEvent<Input | Output> | WorkflowEvent<Input | Output>[]) => {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
934
|
+
when: (input: Input) => {
|
|
935
|
+
then: (expectedOutput: Output | Output[]) => void;
|
|
936
|
+
thenNothingHappened: () => void;
|
|
937
|
+
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => void;
|
|
938
|
+
};
|
|
906
939
|
};
|
|
907
940
|
declare const WorkflowSpecification: {
|
|
908
|
-
|
|
941
|
+
for: typeof workflowSpecificationFor;
|
|
909
942
|
};
|
|
910
943
|
declare function workflowSpecificationFor<Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand>(workflow: Workflow<Input, State, Output>): WorkflowSpecification<Input, Output>;
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
EventType[]
|
|
915
|
-
];
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region src/testing/wrapEventStore.d.ts
|
|
946
|
+
type TestEventStream<EventType extends Event = Event> = [string, EventType[]];
|
|
916
947
|
type EventStoreWrapper<Store extends EventStore> = Store & {
|
|
917
|
-
|
|
918
|
-
|
|
948
|
+
appendedEvents: Map<string, TestEventStream>;
|
|
949
|
+
setup<EventType extends Event>(streamName: string, events: EventType[]): Promise<AppendToStreamResult>;
|
|
919
950
|
};
|
|
920
951
|
declare const WrapEventStore: <Store extends EventStore>(eventStore: Store) => EventStoreWrapper<Store>;
|
|
921
|
-
|
|
952
|
+
//#endregion
|
|
953
|
+
//#region src/eventStore/projections/inMemory/inMemoryProjectionSpec.d.ts
|
|
922
954
|
type DocumentWithId = Document & {
|
|
923
|
-
|
|
955
|
+
_id?: string | number;
|
|
924
956
|
};
|
|
925
957
|
type InMemoryProjectionSpecEvent<EventType extends Event, EventMetaDataType extends InMemoryReadEventMetadata = InMemoryReadEventMetadata> = EventType & {
|
|
926
|
-
|
|
958
|
+
metadata?: Partial<EventMetaDataType>;
|
|
927
959
|
};
|
|
928
960
|
type InMemoryProjectionSpecWhenOptions = {
|
|
929
|
-
|
|
961
|
+
numberOfTimes: number;
|
|
962
|
+
};
|
|
963
|
+
type InMemoryProjectionSpec<EventType extends Event> = (givenEvents: InMemoryProjectionSpecEvent<EventType>[]) => {
|
|
964
|
+
when: (events: InMemoryProjectionSpecEvent<EventType>[], options?: InMemoryProjectionSpecWhenOptions) => {
|
|
965
|
+
then: (assert: InMemoryProjectionAssert, message?: string) => Promise<void>;
|
|
966
|
+
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => Promise<void>;
|
|
967
|
+
};
|
|
930
968
|
};
|
|
931
969
|
type InMemoryProjectionAssert = (options: {
|
|
932
|
-
|
|
970
|
+
database: InMemoryDatabase;
|
|
933
971
|
}) => Promise<void | boolean>;
|
|
934
972
|
type InMemoryProjectionSpecOptions<EventType extends Event> = {
|
|
935
|
-
|
|
936
|
-
};
|
|
937
|
-
type InMemoryProjectionSpec<EventType extends Event> = (givenEvents: InMemoryProjectionSpecEvent<EventType>[]) => {
|
|
938
|
-
when: (events: InMemoryProjectionSpecEvent<EventType>[], options?: InMemoryProjectionSpecWhenOptions) => {
|
|
939
|
-
then: (assert: InMemoryProjectionAssert, message?: string) => Promise<void>;
|
|
940
|
-
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => Promise<void>;
|
|
941
|
-
};
|
|
973
|
+
projection: InMemoryProjectionDefinition<EventType>;
|
|
942
974
|
};
|
|
943
975
|
declare const InMemoryProjectionSpec: {
|
|
944
|
-
|
|
976
|
+
for: <EventType extends Event>(options: InMemoryProjectionSpecOptions<EventType>) => InMemoryProjectionSpec<EventType>;
|
|
945
977
|
};
|
|
946
978
|
declare const eventInStream: <EventType extends Event = Event, EventMetaDataType extends InMemoryReadEventMetadata = InMemoryReadEventMetadata>(streamName: string, event: InMemoryProjectionSpecEvent<EventType, EventMetaDataType>) => InMemoryProjectionSpecEvent<EventType, EventMetaDataType>;
|
|
947
979
|
declare const eventsInStream: <EventType extends Event = Event, EventMetaDataType extends InMemoryReadEventMetadata = InMemoryReadEventMetadata>(streamName: string, events: InMemoryProjectionSpecEvent<EventType, EventMetaDataType>[]) => InMemoryProjectionSpecEvent<EventType, EventMetaDataType>[];
|
|
948
980
|
declare const newEventsInStream: <EventType extends Event = Event, EventMetaDataType extends InMemoryReadEventMetadata = RecordedMessageMetadataWithGlobalPosition>(streamName: string, events: InMemoryProjectionSpecEvent<EventType, EventMetaDataType>[]) => InMemoryProjectionSpecEvent<EventType, EventMetaDataType>[];
|
|
949
981
|
declare function documentExists<T extends DocumentWithId>(expected: Partial<T>, options: {
|
|
950
|
-
|
|
951
|
-
|
|
982
|
+
inCollection: string;
|
|
983
|
+
withId: string | number;
|
|
952
984
|
}): InMemoryProjectionAssert;
|
|
953
985
|
declare const expectInMemoryDocuments: {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
};
|
|
986
|
+
fromCollection: <T extends DocumentWithId>(collectionName: string) => {
|
|
987
|
+
withId: (id: string | number) => {
|
|
988
|
+
toBeEqual: (expected: Partial<T>) => InMemoryProjectionAssert;
|
|
958
989
|
};
|
|
990
|
+
};
|
|
959
991
|
};
|
|
960
|
-
|
|
992
|
+
//#endregion
|
|
993
|
+
//#region src/eventStore/versioning/downcasting.d.ts
|
|
961
994
|
type MessageDowncast<MessageType extends AnyMessage, MessagePayloadType extends AnyMessage = MessageType, RecordedMessageMetadataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = ((message: RecordedMessage<MessageType, RecordedMessageMetadataType>) => RecordedMessage<MessagePayloadType, RecordedMessageMetadataType>) | ((message: MessageType) => MessagePayloadType);
|
|
962
995
|
declare const downcastRecordedMessage: <MessageType extends AnyMessage, MessagePayloadType extends AnyMessage = MessageType, RecordedMessageMetadataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata>(recordedMessage: RecordedMessage<MessageType, RecordedMessageMetadataType> | MessageType, options?: {
|
|
963
|
-
|
|
996
|
+
downcast?: MessageDowncast<MessageType, MessagePayloadType, RecordedMessageMetadataType>;
|
|
964
997
|
}) => RecordedMessage<MessagePayloadType, RecordedMessageMetadataType>;
|
|
965
998
|
declare const downcastRecordedMessages: <MessageType extends AnyMessage, MessagePayloadType extends AnyMessage = MessageType, RecordedMessageMetadataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata>(recordedMessages: RecordedMessage<MessageType, RecordedMessageMetadataType>[] | MessageType[], options?: {
|
|
966
|
-
|
|
999
|
+
downcast?: MessageDowncast<MessageType, MessagePayloadType, RecordedMessageMetadataType>;
|
|
967
1000
|
}) => RecordedMessage<MessagePayloadType, RecordedMessageMetadataType>[];
|
|
968
|
-
|
|
1001
|
+
//#endregion
|
|
1002
|
+
//#region src/eventStore/versioning/upcasting.d.ts
|
|
969
1003
|
type MessageUpcast<MessageType extends AnyMessage, MessagePayloadType extends AnyMessage = MessageType, RecordedMessageMetadataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = ((message: MessagePayloadType) => MessageType) | ((message: RecordedMessage<MessagePayloadType, RecordedMessageMetadataType>) => RecordedMessage<MessageType, RecordedMessageMetadataType>);
|
|
970
1004
|
declare const upcastRecordedMessage: <MessageType extends AnyMessage, MessagePayloadType extends AnyMessage = MessageType, RecordedMessageMetadataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata>(recordedMessage: RecordedMessage<MessagePayloadType, RecordedMessageMetadataType> | MessagePayloadType, options?: {
|
|
971
|
-
|
|
1005
|
+
upcast?: MessageUpcast<MessageType, MessagePayloadType, RecordedMessageMetadataType>;
|
|
972
1006
|
}) => RecordedMessage<MessageType, RecordedMessageMetadataType>;
|
|
973
1007
|
declare const upcastRecordedMessages: <MessageType extends AnyMessage, MessagePayloadType extends AnyMessage = MessageType, RecordedMessageMetadataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata>(recordedMessages: RecordedMessage<MessagePayloadType, RecordedMessageMetadataType>[] | MessagePayloadType[], options?: {
|
|
974
|
-
|
|
1008
|
+
upcast?: MessageUpcast<MessageType, MessagePayloadType, RecordedMessageMetadataType>;
|
|
975
1009
|
}) => RecordedMessage<MessageType, RecordedMessageMetadataType>[];
|
|
976
|
-
|
|
1010
|
+
//#endregion
|
|
1011
|
+
//#region src/observability/options.d.ts
|
|
1012
|
+
type PollTracing = 'off' | 'active' | 'verbose';
|
|
1013
|
+
type EmmettObservabilityConfig = ObservabilityConfig<'emmett'> & {
|
|
1014
|
+
pollTracing?: PollTracing;
|
|
1015
|
+
includeMessagePayloads?: boolean;
|
|
1016
|
+
};
|
|
1017
|
+
type CommandObservabilityConfig = Pick<EmmettObservabilityConfig, 'tracer' | 'meter' | 'attributeTarget' | 'includeMessagePayloads'>;
|
|
1018
|
+
//#endregion
|
|
1019
|
+
//#region src/utils/async/mapAsync.d.ts
|
|
977
1020
|
declare function reduceAsync<T, R>(items: T[], fn: (accumulator: R, item: T, index: number) => Promise<R>, initial: R): Promise<R>;
|
|
978
|
-
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region src/utils/closeable.d.ts
|
|
979
1023
|
type Closeable = {
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
};
|
|
987
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* Gracefully cleans up managed resources
|
|
1026
|
+
*
|
|
1027
|
+
* @memberof Closeable
|
|
1028
|
+
*/
|
|
1029
|
+
close: () => Promise<void>;
|
|
1030
|
+
};
|
|
1031
|
+
//#endregion
|
|
1032
|
+
//#region src/utils/collections/merge.d.ts
|
|
988
1033
|
declare const merge: <T>(array: T[], item: T, where: (current: T) => boolean, onExisting: (current: T) => T, onNotFound?: () => T | undefined) => T[];
|
|
989
|
-
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region src/utils/collections/index.d.ts
|
|
990
1036
|
declare const arrayUtils: {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1037
|
+
merge: <T>(array: T[], item: T, where: (current: T) => boolean, onExisting: (current: T) => T, onNotFound?: () => T | undefined) => T[];
|
|
1038
|
+
hasDuplicates: <ArrayItem, Mapped>(array: ArrayItem[], predicate: (value: ArrayItem, index: number, array: ArrayItem[]) => Mapped) => boolean;
|
|
1039
|
+
getDuplicates: <ArrayItem, Mapped>(array: ArrayItem[], predicate: (value: ArrayItem, index: number, array: ArrayItem[]) => Mapped) => ArrayItem[];
|
|
994
1040
|
};
|
|
995
|
-
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/utils/deepEquals.d.ts
|
|
996
1043
|
declare const deepEquals: <T>(left: T, right: T) => boolean;
|
|
997
1044
|
type Equatable<T> = {
|
|
998
|
-
|
|
1045
|
+
equals: (right: T) => boolean;
|
|
999
1046
|
} & T;
|
|
1000
1047
|
declare const isEquatable: <T>(left: T) => left is Equatable<T>;
|
|
1001
|
-
|
|
1048
|
+
//#endregion
|
|
1049
|
+
//#region src/utils/iterators.d.ts
|
|
1002
1050
|
declare const sum: (iterator: Iterator<number, number, number> | Iterator<number>) => number;
|
|
1003
|
-
|
|
1051
|
+
//#endregion
|
|
1052
|
+
//#region src/utils/locking/index.d.ts
|
|
1004
1053
|
type LockOptions = {
|
|
1005
|
-
|
|
1054
|
+
lockId: number;
|
|
1006
1055
|
};
|
|
1007
1056
|
type AcquireLockOptions = {
|
|
1008
|
-
|
|
1057
|
+
lockId: string;
|
|
1009
1058
|
};
|
|
1010
1059
|
type ReleaseLockOptions = {
|
|
1011
|
-
|
|
1060
|
+
lockId: string;
|
|
1012
1061
|
};
|
|
1013
1062
|
type Lock = {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1063
|
+
acquire(options: AcquireLockOptions): Promise<void>;
|
|
1064
|
+
tryAcquire(options: AcquireLockOptions): Promise<boolean>;
|
|
1065
|
+
release(options: ReleaseLockOptions): Promise<boolean>;
|
|
1066
|
+
withAcquire: <Result = unknown>(handle: () => Promise<Result>, options: AcquireLockOptions) => Promise<Result>;
|
|
1018
1067
|
};
|
|
1019
1068
|
declare const InProcessLock: () => Lock;
|
|
1020
|
-
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/utils/numbers/bigint.d.ts
|
|
1021
1071
|
declare const toNormalizedString: (value: bigint) => string;
|
|
1022
1072
|
declare const bigInt: {
|
|
1023
|
-
|
|
1073
|
+
toNormalizedString: (value: bigint) => string;
|
|
1024
1074
|
};
|
|
1025
|
-
|
|
1075
|
+
//#endregion
|
|
1076
|
+
//#region src/utils/promises.d.ts
|
|
1026
1077
|
declare const delay: (ms: number) => Promise<void>;
|
|
1027
1078
|
type AsyncAwaiter<T = void> = {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1079
|
+
wait: Promise<T>;
|
|
1080
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
1081
|
+
reject: (reason?: any) => void;
|
|
1082
|
+
reset: () => void;
|
|
1032
1083
|
};
|
|
1033
1084
|
declare const asyncAwaiter: <T = void>() => AsyncAwaiter<T>;
|
|
1034
|
-
|
|
1085
|
+
//#endregion
|
|
1086
|
+
//#region src/utils/retry.d.ts
|
|
1035
1087
|
type AsyncRetryOptions<T = unknown> = retry.Options & {
|
|
1036
|
-
|
|
1037
|
-
|
|
1088
|
+
shouldRetryResult?: (result: T) => boolean;
|
|
1089
|
+
shouldRetryError?: (error?: unknown) => boolean;
|
|
1038
1090
|
};
|
|
1039
1091
|
declare const NoRetries: AsyncRetryOptions;
|
|
1040
1092
|
declare const asyncRetry: <T>(fn: () => Promise<T>, opts?: AsyncRetryOptions<T>) => Promise<T>;
|
|
1041
|
-
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region src/utils/shutdown/gracefulShutdown.d.ts
|
|
1042
1095
|
type ShutdownHandler = () => void | Promise<void>;
|
|
1043
1096
|
/**
|
|
1044
1097
|
* Registers handlers for OS signals to enable graceful shutdown.
|
|
@@ -1049,136 +1102,157 @@ type ShutdownHandler = () => void | Promise<void>;
|
|
|
1049
1102
|
* @returns Cleanup function to unregister the handlers
|
|
1050
1103
|
*/
|
|
1051
1104
|
declare const onShutdown: (handler: ShutdownHandler) => (() => void);
|
|
1052
|
-
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region src/utils/strings/hashText.d.ts
|
|
1053
1107
|
declare const hashText: (text: string) => Promise<bigint>;
|
|
1054
|
-
|
|
1108
|
+
//#endregion
|
|
1109
|
+
//#region src/commandHandling/handleCommand.d.ts
|
|
1055
1110
|
declare const CommandHandlerStreamVersionConflictRetryOptions: AsyncRetryOptions;
|
|
1056
1111
|
type CommandHandlerRetryOptions = AsyncRetryOptions | {
|
|
1057
|
-
|
|
1112
|
+
onVersionConflict: true | number | AsyncRetryOptions;
|
|
1058
1113
|
};
|
|
1059
1114
|
type CommandHandlerResult<State, StreamEvent extends Event, Store extends EventStore> = AppendStreamResultOfEventStore<Store> & {
|
|
1060
|
-
|
|
1061
|
-
|
|
1115
|
+
newState: State;
|
|
1116
|
+
newEvents: StreamEvent[];
|
|
1062
1117
|
};
|
|
1063
1118
|
type CommandHandlerOptions<State, StreamEvent extends Event, StoredEvent extends Event = StreamEvent> = {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
};
|
|
1119
|
+
evolve: (state: State, event: StreamEvent) => State;
|
|
1120
|
+
initialState: () => State;
|
|
1121
|
+
mapToStreamId?: (id: string) => string;
|
|
1122
|
+
retry?: CommandHandlerRetryOptions;
|
|
1123
|
+
schema?: {
|
|
1124
|
+
versioning?: {
|
|
1125
|
+
upcast?: (event: StoredEvent) => StreamEvent;
|
|
1126
|
+
downcast?: (event: StreamEvent) => StoredEvent;
|
|
1073
1127
|
};
|
|
1074
|
-
}
|
|
1128
|
+
};
|
|
1129
|
+
name?: string;
|
|
1130
|
+
commandType?: string | string[];
|
|
1131
|
+
} & JSONSerializationOptions & {
|
|
1132
|
+
observability?: CommandObservabilityConfig;
|
|
1133
|
+
};
|
|
1075
1134
|
type HandleOptions<Store extends EventStore> = Parameters<Store['appendToStream']>[2] & ({
|
|
1076
|
-
|
|
1135
|
+
expectedStreamVersion?: ExpectedStreamVersion;
|
|
1077
1136
|
} | {
|
|
1078
|
-
|
|
1079
|
-
})
|
|
1137
|
+
retry?: CommandHandlerRetryOptions;
|
|
1138
|
+
}) & {
|
|
1139
|
+
commandType?: string | string[];
|
|
1140
|
+
observability?: {
|
|
1141
|
+
traceId?: string;
|
|
1142
|
+
spanId?: string;
|
|
1143
|
+
correlationId?: string;
|
|
1144
|
+
causationId?: string;
|
|
1145
|
+
};
|
|
1146
|
+
};
|
|
1080
1147
|
type CommandHandlerFunction<State, StreamEvent extends Event> = (state: State) => StreamEvent | StreamEvent[] | Promise<StreamEvent | StreamEvent[]>;
|
|
1081
1148
|
declare const CommandHandler: <State, StreamEvent extends Event, EventPayloadType extends Event = StreamEvent>(options: CommandHandlerOptions<State, StreamEvent, EventPayloadType>) => <Store extends EventStore>(store: Store, id: string, handle: CommandHandlerFunction<State, StreamEvent> | CommandHandlerFunction<State, StreamEvent>[], handleOptions?: HandleOptions<Store>) => Promise<CommandHandlerResult<State, StreamEvent, Store>>;
|
|
1082
|
-
|
|
1149
|
+
//#endregion
|
|
1150
|
+
//#region src/commandHandling/handleCommandWithDecider.d.ts
|
|
1083
1151
|
type DeciderCommandHandlerOptions<State, CommandType extends Command, StreamEvent extends Event> = CommandHandlerOptions<State, StreamEvent> & Decider<State, CommandType, StreamEvent>;
|
|
1084
1152
|
declare const DeciderCommandHandler: <State, CommandType extends Command, StreamEvent extends Event>(options: DeciderCommandHandlerOptions<State, CommandType, StreamEvent>) => <Store extends EventStore>(eventStore: Store, id: string, commands: CommandType | CommandType[], handleOptions?: HandleOptions<Store>) => Promise<CommandHandlerResult<State, StreamEvent, Store>>;
|
|
1085
|
-
|
|
1153
|
+
//#endregion
|
|
1154
|
+
//#region src/consumers/consumers.d.ts
|
|
1086
1155
|
type MessageConsumerOptions<ConsumerMessageType extends Message = any> = {
|
|
1087
|
-
|
|
1088
|
-
|
|
1156
|
+
consumerId?: string;
|
|
1157
|
+
processors?: Array<MessageProcessor<ConsumerMessageType, any, any>>;
|
|
1089
1158
|
};
|
|
1090
1159
|
type MessageConsumer<ConsumerMessageType extends Message = any> = Readonly<{
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1160
|
+
consumerId: string;
|
|
1161
|
+
isRunning: boolean;
|
|
1162
|
+
whenStarted: () => Promise<void>;
|
|
1163
|
+
processors: ReadonlyArray<MessageProcessor<ConsumerMessageType, any, any>>;
|
|
1164
|
+
start: () => Promise<void>;
|
|
1165
|
+
stop: () => Promise<void>;
|
|
1166
|
+
close: () => Promise<void>;
|
|
1097
1167
|
}>;
|
|
1098
|
-
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region src/taskProcessing/executionGuards.d.ts
|
|
1099
1170
|
type ExclusiveAccessGuard = {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1171
|
+
execute: <Result>(operation: () => Promise<Result>) => Promise<Result>;
|
|
1172
|
+
waitForIdle: () => Promise<void>;
|
|
1173
|
+
stop: (options?: {
|
|
1174
|
+
force?: boolean;
|
|
1175
|
+
}) => Promise<void>;
|
|
1105
1176
|
};
|
|
1106
1177
|
declare const guardExclusiveAccess: (options?: {
|
|
1107
|
-
|
|
1178
|
+
maxQueueSize?: number;
|
|
1108
1179
|
}) => ExclusiveAccessGuard;
|
|
1109
1180
|
type BoundedAccessGuard<Resource> = {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1181
|
+
acquire: () => Promise<Resource>;
|
|
1182
|
+
release: (resource: Resource) => void;
|
|
1183
|
+
execute: <Result>(operation: (resource: Resource) => Promise<Result>) => Promise<Result>;
|
|
1184
|
+
waitForIdle: () => Promise<void>;
|
|
1185
|
+
stop: (options?: {
|
|
1186
|
+
force?: boolean;
|
|
1187
|
+
}) => Promise<void>;
|
|
1117
1188
|
};
|
|
1118
1189
|
declare const guardBoundedAccess: <Resource>(getResource: () => Resource | Promise<Resource>, options: {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1190
|
+
maxResources: number;
|
|
1191
|
+
maxQueueSize?: number;
|
|
1192
|
+
reuseResources?: boolean;
|
|
1193
|
+
closeResource?: (resource: Resource) => void | Promise<void>;
|
|
1123
1194
|
}) => BoundedAccessGuard<Resource>;
|
|
1124
1195
|
type InitializedOnceGuard<T> = {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1196
|
+
ensureInitialized: () => Promise<T>;
|
|
1197
|
+
reset: () => void;
|
|
1198
|
+
stop: (options?: {
|
|
1199
|
+
force?: boolean;
|
|
1200
|
+
}) => Promise<void>;
|
|
1130
1201
|
};
|
|
1131
1202
|
declare const guardInitializedOnce: <T>(initialize: () => Promise<T>, options?: {
|
|
1132
|
-
|
|
1133
|
-
|
|
1203
|
+
maxQueueSize?: number;
|
|
1204
|
+
maxRetries?: number;
|
|
1134
1205
|
}) => InitializedOnceGuard<T>;
|
|
1135
|
-
|
|
1206
|
+
//#endregion
|
|
1207
|
+
//#region src/taskProcessing/taskProcessor.d.ts
|
|
1136
1208
|
type TaskQueue = TaskQueueItem[];
|
|
1137
1209
|
type TaskQueueItem = {
|
|
1138
|
-
|
|
1139
|
-
|
|
1210
|
+
task: () => Promise<void>;
|
|
1211
|
+
options?: EnqueueTaskOptions | undefined;
|
|
1140
1212
|
};
|
|
1141
1213
|
type TaskProcessorOptions = {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1214
|
+
maxActiveTasks: number;
|
|
1215
|
+
maxQueueSize: number;
|
|
1216
|
+
maxTaskIdleTime?: number;
|
|
1145
1217
|
};
|
|
1146
1218
|
type Task<T> = (context: TaskContext) => Promise<T>;
|
|
1147
1219
|
type TaskContext = {
|
|
1148
|
-
|
|
1220
|
+
ack: () => void;
|
|
1149
1221
|
};
|
|
1150
1222
|
type EnqueueTaskOptions = {
|
|
1151
|
-
|
|
1223
|
+
taskGroupId?: string;
|
|
1152
1224
|
};
|
|
1153
1225
|
declare class TaskProcessor {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1226
|
+
private queue;
|
|
1227
|
+
private isProcessing;
|
|
1228
|
+
private activeTasks;
|
|
1229
|
+
private activeGroups;
|
|
1230
|
+
private options;
|
|
1231
|
+
private stopped;
|
|
1232
|
+
constructor(options: TaskProcessorOptions);
|
|
1233
|
+
enqueue<T>(task: Task<T>, options?: EnqueueTaskOptions): Promise<T>;
|
|
1234
|
+
waitForEndOfProcessing(): Promise<void>;
|
|
1235
|
+
stop(options?: {
|
|
1236
|
+
force?: boolean;
|
|
1237
|
+
}): Promise<void>;
|
|
1238
|
+
private schedule;
|
|
1239
|
+
private ensureProcessing;
|
|
1240
|
+
private processQueue;
|
|
1241
|
+
private executeItem;
|
|
1242
|
+
private takeFirstAvailableItem;
|
|
1243
|
+
private hasItemsToProcess;
|
|
1172
1244
|
}
|
|
1173
|
-
|
|
1245
|
+
//#endregion
|
|
1246
|
+
//#region src/validation/dates.d.ts
|
|
1174
1247
|
declare const formatDateToUtcYYYYMMDD: (date: Date) => string;
|
|
1175
1248
|
declare const isValidYYYYMMDD: (dateString: string) => boolean;
|
|
1176
1249
|
declare const parseDateFromUtcYYYYMMDD: (dateString: string) => Date;
|
|
1177
|
-
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/validation/index.d.ts
|
|
1178
1252
|
declare const enum ValidationErrors {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1253
|
+
NOT_A_NONEMPTY_STRING = "NOT_A_NONEMPTY_STRING",
|
|
1254
|
+
NOT_A_POSITIVE_NUMBER = "NOT_A_POSITIVE_NUMBER",
|
|
1255
|
+
NOT_AN_UNSIGNED_BIGINT = "NOT_AN_UNSIGNED_BIGINT"
|
|
1182
1256
|
}
|
|
1183
1257
|
declare const isNumber: (val: unknown) => val is number;
|
|
1184
1258
|
declare const isBigint: (val: any) => val is bigint;
|
|
@@ -1186,74 +1260,80 @@ declare const isString: (val: unknown) => val is string;
|
|
|
1186
1260
|
declare const assertNotEmptyString: (value: unknown) => string;
|
|
1187
1261
|
declare const assertPositiveNumber: (value: unknown) => number;
|
|
1188
1262
|
declare const assertUnsignedBigInt: (value: string) => bigint;
|
|
1189
|
-
|
|
1263
|
+
//#endregion
|
|
1264
|
+
//#region src/workflows/workflowProcessor.d.ts
|
|
1190
1265
|
type WorkflowOptions<Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, StoredMessage extends AnyEvent | AnyCommand = Output> = {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
};
|
|
1266
|
+
workflow: Workflow<Input, State, Output>;
|
|
1267
|
+
getWorkflowId: (input: Input | RecordedMessage<Input, MessageMetadataType>) => string | null;
|
|
1268
|
+
mapWorkflowId?: (workflowId: string) => string;
|
|
1269
|
+
separateInputInboxFromProcessing?: boolean;
|
|
1270
|
+
inputs: {
|
|
1271
|
+
commands: CanHandle<WorkflowCommand<Input>>;
|
|
1272
|
+
events: CanHandle<WorkflowEvent<Input>>;
|
|
1273
|
+
};
|
|
1274
|
+
outputs: {
|
|
1275
|
+
commands: MessageTypeOf<WorkflowCommand<Output>>[];
|
|
1276
|
+
events: MessageTypeOf<WorkflowEvent<Output>>[];
|
|
1277
|
+
};
|
|
1278
|
+
schema?: {
|
|
1279
|
+
versioning?: {
|
|
1280
|
+
upcast?: (event: StoredMessage) => Input;
|
|
1281
|
+
downcast?: (event: Output) => StoredMessage;
|
|
1208
1282
|
};
|
|
1283
|
+
};
|
|
1209
1284
|
};
|
|
1210
1285
|
type WorkflowProcessorContext = {
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1286
|
+
connection: {
|
|
1287
|
+
messageStore: EventStore;
|
|
1288
|
+
};
|
|
1214
1289
|
};
|
|
1215
1290
|
type WorkflowOutputHandlerResult<Input extends AnyEvent | AnyCommand> = Promise<Input | Input[] | EmmettError | [] | void> | Input | Input[] | EmmettError | [] | void;
|
|
1216
1291
|
type SingleWorkflowOutputHandler<Input extends AnyEvent | AnyCommand, Output extends AnyEvent | AnyCommand, MessageMetaDataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext> = (message: Output | RecordedMessage<Output, MessageMetaDataType>, context: HandlerContext) => WorkflowOutputHandlerResult<Input>;
|
|
1217
1292
|
type BatchWorkflowOutputHandler<Input extends AnyEvent | AnyCommand, Output extends AnyEvent | AnyCommand, MessageMetaDataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext> = (messages: RecordedMessage<Output, MessageMetaDataType>[], context: HandlerContext) => WorkflowOutputHandlerResult<Input>;
|
|
1218
1293
|
type WorkflowOutputHandlerOptions<Input extends AnyEvent | AnyCommand, Output extends AnyEvent | AnyCommand, MessageMetaDataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext> = {
|
|
1219
|
-
|
|
1220
|
-
|
|
1294
|
+
eachMessage: SingleWorkflowOutputHandler<Input, Output, MessageMetaDataType, HandlerContext>;
|
|
1295
|
+
eachBatch?: never;
|
|
1221
1296
|
} | {
|
|
1222
|
-
|
|
1223
|
-
|
|
1297
|
+
eachMessage?: never;
|
|
1298
|
+
eachBatch: BatchWorkflowOutputHandler<Input, Output, MessageMetaDataType, HandlerContext>;
|
|
1224
1299
|
};
|
|
1225
1300
|
type WorkflowOutputHandlerDefinition<Input extends AnyEvent | AnyCommand, Output extends AnyEvent | AnyCommand, HandledOutput extends Output = Output, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext> = {
|
|
1226
|
-
|
|
1301
|
+
canHandle: CanHandle<HandledOutput>;
|
|
1227
1302
|
} & WorkflowOutputHandlerOptions<Input, HandledOutput, MessageMetadataType, HandlerContext>;
|
|
1228
1303
|
declare const workflowOutputHandler: <Input extends AnyEvent | AnyCommand, Output extends AnyEvent | AnyCommand, HandledOutput extends Output = Output, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext>(handler: WorkflowOutputHandlerDefinition<Input, Output, HandledOutput, MessageMetadataType, HandlerContext>) => WorkflowOutputHandlerDefinition<Input, Output, HandledOutput, MessageMetadataType, HandlerContext>;
|
|
1229
1304
|
type WorkflowProcessorOptions<Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext, StoredMessage extends AnyEvent | AnyCommand = Output, HandledOutput extends Output = Output> = Omit<BaseMessageProcessorOptions<Input | Output, MessageMetadataType, HandlerContext>, 'type' | 'canHandle' | 'processorId'> & {
|
|
1230
|
-
|
|
1305
|
+
processorId?: string;
|
|
1231
1306
|
} & WorkflowOptions<Input, State, Output, MessageMetadataType, StoredMessage> & {
|
|
1232
|
-
|
|
1233
|
-
|
|
1307
|
+
retry?: WorkflowHandlerRetryOptions;
|
|
1308
|
+
outputHandler?: WorkflowOutputHandlerDefinition<Input, Output, HandledOutput, MessageMetadataType, HandlerContext>;
|
|
1234
1309
|
};
|
|
1235
1310
|
declare const getWorkflowId: (options: {
|
|
1236
|
-
|
|
1311
|
+
workflowName: string;
|
|
1237
1312
|
}) => string;
|
|
1238
1313
|
declare const workflowProcessor: <Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand, MetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends WorkflowProcessorContext = WorkflowProcessorContext, StoredMessage extends AnyEvent | AnyCommand = Output, HandledOutput extends Output = Output>(options: WorkflowProcessorOptions<Input, State, Output, MetaDataType, HandlerContext, StoredMessage, HandledOutput>) => MessageProcessor<Input, MetaDataType, HandlerContext>;
|
|
1239
|
-
|
|
1314
|
+
//#endregion
|
|
1315
|
+
//#region src/workflows/handleWorkflow.d.ts
|
|
1240
1316
|
declare const WorkflowHandlerStreamVersionConflictRetryOptions: AsyncRetryOptions;
|
|
1241
1317
|
type WorkflowHandlerRetryOptions = AsyncRetryOptions | {
|
|
1242
|
-
|
|
1318
|
+
onVersionConflict: true | number | AsyncRetryOptions;
|
|
1243
1319
|
};
|
|
1244
1320
|
type WorkflowHandlerResult<Output extends AnyEvent | AnyCommand, Store extends EventStore> = AppendStreamResultOfEventStore<Store> & {
|
|
1245
|
-
|
|
1321
|
+
newMessages: Output[];
|
|
1246
1322
|
};
|
|
1247
1323
|
type WorkflowHandleOptions<Store extends EventStore> = Parameters<Store['appendToStream']>[2] & {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
};
|
|
1251
|
-
declare const workflowStreamName: ({
|
|
1252
|
-
|
|
1253
|
-
|
|
1324
|
+
expectedStreamVersion?: ExpectedStreamVersion;
|
|
1325
|
+
retry?: WorkflowHandlerRetryOptions;
|
|
1326
|
+
};
|
|
1327
|
+
declare const workflowStreamName: ({
|
|
1328
|
+
workflowName,
|
|
1329
|
+
workflowId
|
|
1330
|
+
}: {
|
|
1331
|
+
workflowName: string;
|
|
1332
|
+
workflowId: string;
|
|
1254
1333
|
}) => string;
|
|
1255
1334
|
declare const WorkflowHandler: <Input extends AnyEvent | AnyCommand, State, Output extends AnyEvent | AnyCommand, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, StoredMessage extends AnyEvent | AnyCommand = Output>(options: WorkflowOptions<Input, State, Output, MessageMetadataType, StoredMessage> & {
|
|
1256
|
-
|
|
1335
|
+
retry?: WorkflowHandlerRetryOptions;
|
|
1257
1336
|
}) => <Store extends EventStore>(store: Store, message: Input | RecordedMessage<Input, MessageMetadataType>, handleOptions?: WorkflowHandleOptions<Store>) => Promise<WorkflowHandlerResult<Output, Store>>;
|
|
1258
|
-
|
|
1259
|
-
export {
|
|
1337
|
+
//#endregion
|
|
1338
|
+
export { AcquireLockOptions, AfterEventStoreCommitHandler, AggregateStreamOptions, AggregateStreamResult, AggregateStreamResultOfEventStore, AggregateStreamResultWithGlobalPosition, AnyCommand, AnyEvent, AnyMessage, AnyReadEvent, AnyReadEventMetadata, AnyRecord, AnyRecordedMessage, AnyRecordedMessageMetadata, AppendStreamResultOfEventStore, AppendToStreamOptions, AppendToStreamResult, AppendToStreamResultWithGlobalPosition, ArgumentMatcher, AssertionError, AsyncAwaiter, AsyncDeciderSpecification, AsyncRetryOptions, BaseMessageProcessorOptions, BatchMessageHandler, BatchMessageHandlerResult, BatchMessageHandlerWithContext, BatchMessageHandlerWithoutContext, BatchRawMessageHandlerWithContext, BatchRawMessageHandlerWithoutContext, BatchRecordedMessageHandlerWithContext, BatchRecordedMessageHandlerWithoutContext, BatchWorkflowOutputHandler, BeforeEventStoreCommitHandler, BoundedAccessGuard, Brand, CanHandle, Checkpointer, Closeable, CombineMetadata, CombinedMessageMetadata, CombinedReadEventMetadata, Command, CommandBus, CommandDataOf, CommandHandler, CommandHandlerOptions, CommandHandlerResult, CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, CommandMetaDataOf, CommandProcessor, CommandSender, CommandTypeOf, CommonReadEventMetadata, CommonRecordedMessageMetadata, ConcurrencyError, ConcurrencyInMemoryDatabaseError, CreateCommandType, CreateEventType, CurrentMessageProcessorPosition, DATABASE_REQUIRED_ERROR_MESSAGE, DatabaseHandleOptionErrors, DatabaseHandleOptions, DatabaseHandleResult, Decider, DeciderCommandHandler, DeciderCommandHandlerOptions, DeciderSpecification, DeepReadonly, DefaultCommandMetadata, DefaultEventStoreOptions, DefaultRecord, DeleteManyOptions, DeleteManyResult, DeleteOneOptions, DeleteResult, Document, DocumentHandler, EmmettCliCommand, EmmettCliPlugin, EmmettCliPluginRegistration, EmmettError, EmmettPlugin, EmmettPluginConfig, EmmettPluginRegistration, EmmettPluginType, EmmettPluginsConfig, EnhancedOmit, EnqueueTaskOptions, Equatable, ErrorConstructor, Event, EventBus, EventDataOf, EventMetaDataOf, EventStore, EventStoreAppendSchemaOptions, EventStoreReadEventMetadata, EventStoreReadSchemaOptions, EventStoreSchemaOptions, EventStoreSession, EventStoreSessionFactory, EventStoreWrapper, EventSubscription, EventTypeOf, EventsPublisher, ExclusiveAccessGuard, ExpectedDocumentVersion, ExpectedDocumentVersionGeneral, ExpectedDocumentVersionValue, ExpectedStreamVersion, ExpectedStreamVersionGeneral, ExpectedStreamVersionWithValue, ExpectedVersionConflictError, Flavour, FullId, GetCheckpoint, GlobalPosition, GlobalStreamCaughtUp, GlobalStreamCaughtUpType, GlobalSubscriptionEvent, HandleOptions, HandlerOptions, IllegalStateError, InMemoryCheckpointer, InMemoryDatabase, InMemoryDocumentEvolve, InMemoryDocumentsCollection, InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, InMemoryEventStoreOptions, InMemoryMultiStreamProjectionOptions, InMemoryProcessor, InMemoryProcessorConnectionOptions, InMemoryProcessorEachBatchHandler, InMemoryProcessorEachMessageHandler, InMemoryProcessorHandlerContext, InMemoryProcessorOptions, InMemoryProjectionAssert, InMemoryProjectionDefinition, InMemoryProjectionHandlerContext, InMemoryProjectionHandlerOptions, InMemoryProjectionOptions, InMemoryProjectionSpec, InMemoryProjectionSpecEvent, InMemoryProjectionSpecOptions, InMemoryProjectionSpecWhenOptions, InMemoryProjectorOptions, InMemoryReactorOptions, InMemoryReadEvent, InMemoryReadEventMetadata, InMemorySingleStreamProjectionOptions, InMemoryWithNotNullDocumentEvolve, InMemoryWithNullableDocumentEvolve, InProcessLock, InitializedOnceGuard, InsertManyOptions, InsertManyResult, InsertOneOptions, InsertOneResult, JSONCodec, type JSONCodecOptions, type JSONDeserializeOptions, JSONReplacer, JSONReplacers, JSONReviver, JSONReviverContext, JSONRevivers, type JSONSerializationOptions, type JSONSerializeOptions, JSONSerializer, type JSONSerializerOptions, Lock, LockOptions, Message, MessageBus, MessageConsumer, MessageConsumerOptions, MessageDataOf, MessageDowncast, MessageHandler, MessageKindOf, MessageMetaDataOf, MessageProcessingScope, MessageProcessor, MessageProcessorStartFrom, MessageProcessorType, MessageScheduler, MessageSubscription, MessageTypeOf, MessageUpcast, MockedFunction, Mutable, NO_CONCURRENCY_CHECK, NoRetries, NonNullable$1 as NonNullable, NotFoundError, OnReactorCloseHook, OnReactorInitHook, OnReactorStartHook, OperationResult, OptionalId, OptionalUnlessRequiredId, OptionalUnlessRequiredIdAndVersion, OptionalUnlessRequiredVersion, OptionalVersion, ProcessorCheckpoint, ProcessorHooks, ProjectionDefinition, ProjectionHandler, ProjectionHandlingType, ProjectionInitOptions, ProjectionRegistration, ProjectorOptions, ReactorOptions, ReadEvent, ReadEventMetadata, ReadEventMetadataWithGlobalPosition, ReadEventMetadataWithoutGlobalPosition, ReadProcessorCheckpoint, ReadProcessorCheckpointResult, ReadStreamOptions, ReadStreamResult, RecordedMessage, RecordedMessageMetadata, RecordedMessageMetadataWithGlobalPosition, RecordedMessageMetadataWithoutGlobalPosition, ReleaseLockOptions, ReplaceOneOptions, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, ScheduleOptions, ScheduledMessage, ScheduledMessageProcessor, SerializationCodec, Serializer, ShutdownHandler, SingleMessageHandler, SingleMessageHandlerResult, SingleMessageHandlerWithContext, SingleMessageHandlerWithoutContext, SingleRawMessageHandlerWithContext, SingleRawMessageHandlerWithoutContext, SingleRecordedMessageHandlerWithContext, SingleRecordedMessageHandlerWithoutContext, SingleWorkflowOutputHandler, StoreProcessorCheckpoint, StoreProcessorCheckpointResult, StreamExistsResult, StreamPosition, Task, TaskContext, TaskProcessor, TaskProcessorOptions, TaskQueue, TaskQueueItem, TestEventStream, ThenThrows, TruncateProjection, UpdateManyOptions, UpdateManyResult, UpdateOneOptions, UpdateResult, ValidationError, ValidationErrors, WithGlobalPosition, WithId, WithIdAndVersion, WithVersion, WithoutId, WithoutVersion, Workflow, WorkflowCommand, WorkflowEvent, WorkflowHandleOptions, WorkflowHandler, WorkflowHandlerResult, WorkflowHandlerRetryOptions, WorkflowHandlerStreamVersionConflictRetryOptions, WorkflowInputMessageMetadata, WorkflowMessageAction, WorkflowOptions, WorkflowOutput, WorkflowOutputHandlerDefinition, WorkflowOutputHandlerOptions, WorkflowOutputHandlerResult, WorkflowOutputMessageMetadata, WorkflowProcessorContext, WorkflowProcessorOptions, WorkflowSpecification, WrapEventStore, argMatches, argValue, arrayUtils, assertDeepEqual, assertDefined, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUndefined, assertUnsignedBigInt, asyncAwaiter, asyncProjections, asyncRetry, bigInt, bigIntProcessorCheckpoint, canCreateEventStoreSession, caughtUpEventFrom, command, composeJSONReplacers, composeJSONRevivers, deepEquals, defaultProcessingMessageProcessingScope, defaultProcessorPartition, defaultProcessorVersion, defaultTag, delay, documentExists, downcastRecordedMessage, downcastRecordedMessages, emmettPrefix, event, eventInStream, eventsInStream, expectInMemoryDocuments, filterProjections, formatDateToUtcYYYYMMDD, forwardToMessageBus, getCheckpoint, getInMemoryDatabase, getInMemoryEventStore, getInMemoryMessageBus, getProcessorInstanceId, getProjectorId, getWorkflowId, globalStreamCaughtUp, globalTag, guardBoundedAccess, guardExclusiveAccess, guardInitializedOnce, handleInMemoryProjections, hashText, inMemoryCheckpointer, inMemoryMultiStreamProjection, inMemoryProjection, inMemoryProjector, inMemoryReactor, inMemorySingleStreamProjection, inlineProjections, isBigint, isEquatable, isErrorConstructor, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isPluginConfig, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, jsonSerializer, matchesExpectedVersion, merge, message, newEventsInStream, nulloSessionFactory, onShutdown, parseBigIntProcessorCheckpoint, parseDateFromUtcYYYYMMDD, projection, projections, projector, reactor, reduceAsync, sum, toNormalizedString, tryPublishMessagesAfterCommit, unknownTag, upcastRecordedMessage, upcastRecordedMessages, verifyThat, wasMessageHandled, workflowOutputHandler, workflowProcessor, workflowStreamName };
|
|
1339
|
+
//# sourceMappingURL=index.d.cts.map
|