@delta-base/core 0.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,129 +2,1188 @@ import * as hono_hono_base from 'hono/hono-base';
2
2
  import * as hono_utils_http_status from 'hono/utils/http-status';
3
3
  import * as hono_types from 'hono/types';
4
4
  import * as hono from 'hono';
5
+ import { z, OpenAPIHono } from '@hono/zod-openapi';
5
6
  import { DurableObject } from 'cloudflare:workers';
6
- import { OpenAPIHono } from '@hono/zod-openapi';
7
7
 
8
- type Flavour<K, T> = K & {
9
- readonly __brand?: T;
10
- };
11
- type DefaultRecord = Record<string, unknown>;
12
- type Event<EventType extends string = string, EventData extends DefaultRecord = DefaultRecord, EventMetaData extends DefaultRecord = DefaultRecord> = Flavour<Readonly<{
13
- type: EventType;
14
- data: EventData;
15
- metadata?: EventMetaData;
16
- }>, 'Event'>;
17
- type EventTypeOf<T extends Event> = T['type'];
18
- type EventDataOf<T extends Event> = T['data'];
19
- type EventMetaDataOf<T extends Event> = T['metadata'];
20
- type CreateEventType<EventType extends string, EventData extends DefaultRecord, EventMetaData extends DefaultRecord | undefined> = Readonly<{
21
- type: EventType;
22
- data: EventData;
23
- metadata?: EventMetaData;
24
- }>;
25
- type ReadEvent<EventType extends Event = Event, EventMetaDataType extends EventMetaDataOf<EventType> & ReadEventMetadata = EventMetaDataOf<EventType> & ReadEventMetadata> = CreateEventType<EventTypeOf<EventType>, EventDataOf<EventType>, EventMetaDataType> & EventType & {
26
- metadata: EventMetaDataType;
27
- };
28
- type ReadEventMetadata = Readonly<{
29
- eventId: string;
30
- streamPosition: number;
31
- streamName: string;
32
- }>;
33
- type ReadEventMetadataWithGlobalPosition = ReadEventMetadata & {
34
- globalPosition: number;
35
- };
36
- type ExpectedStreamVersion<VersionType = DefaultStreamVersionType> = ExpectedStreamVersionWithValue<VersionType> | ExpectedStreamVersionGeneral;
37
- type ExpectedStreamVersionWithValue<VersionType = DefaultStreamVersionType> = Flavour<VersionType, 'StreamVersion'>;
38
- type ExpectedStreamVersionGeneral = Flavour<'STREAM_EXISTS' | 'STREAM_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK', 'StreamVersion'>;
39
- interface EventStore<StreamVersion = DefaultStreamVersionType, ReadEventMetadataType extends ReadEventMetadata = ReadEventMetadata> {
40
- aggregateStream<State, EventType extends Event>(streamName: string, options: AggregateStreamOptions<State, EventType, StreamVersion, ReadEventMetadataType>): Promise<AggregateStreamResult<State, StreamVersion> | null>;
41
- readStream<EventType extends Event>(streamName: string, options?: ReadStreamOptions<StreamVersion>): Promise<ReadStreamResult<EventType, StreamVersion, ReadEventMetadataType>>;
42
- appendToStream<EventType extends Event>(streamName: string, events: EventType[], options?: AppendToStreamOptions<StreamVersion>): Promise<AppendToStreamResult<StreamVersion>>;
8
+ declare namespace ManagementAPI {
9
+ const EventStoreSchema: z.ZodObject<{
10
+ eventStoreID: z.ZodString;
11
+ eventStoreName: z.ZodString;
12
+ eventStoreDurableObjectID: z.ZodString;
13
+ eventBusDurableObjectID: z.ZodString;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ settings: z.ZodOptional<z.ZodObject<{
16
+ retentionPeriodDays: z.ZodOptional<z.ZodNumber>;
17
+ maxStreamSizeBytes: z.ZodOptional<z.ZodNumber>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ retentionPeriodDays?: number | undefined;
20
+ maxStreamSizeBytes?: number | undefined;
21
+ }, {
22
+ retentionPeriodDays?: number | undefined;
23
+ maxStreamSizeBytes?: number | undefined;
24
+ }>>;
25
+ created: z.ZodString;
26
+ }, "strip", z.ZodTypeAny, {
27
+ created: string;
28
+ eventStoreID: string;
29
+ eventStoreName: string;
30
+ eventStoreDurableObjectID: string;
31
+ eventBusDurableObjectID: string;
32
+ description?: string | undefined;
33
+ settings?: {
34
+ retentionPeriodDays?: number | undefined;
35
+ maxStreamSizeBytes?: number | undefined;
36
+ } | undefined;
37
+ }, {
38
+ created: string;
39
+ eventStoreID: string;
40
+ eventStoreName: string;
41
+ eventStoreDurableObjectID: string;
42
+ eventBusDurableObjectID: string;
43
+ description?: string | undefined;
44
+ settings?: {
45
+ retentionPeriodDays?: number | undefined;
46
+ maxStreamSizeBytes?: number | undefined;
47
+ } | undefined;
48
+ }>;
49
+ const CreateEventStoreRequestSchema: z.ZodObject<{
50
+ name: z.ZodString;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ settings: z.ZodOptional<z.ZodObject<{
53
+ retentionPeriodDays: z.ZodOptional<z.ZodNumber>;
54
+ maxStreamSizeBytes: z.ZodOptional<z.ZodNumber>;
55
+ }, "strip", z.ZodTypeAny, {
56
+ retentionPeriodDays?: number | undefined;
57
+ maxStreamSizeBytes?: number | undefined;
58
+ }, {
59
+ retentionPeriodDays?: number | undefined;
60
+ maxStreamSizeBytes?: number | undefined;
61
+ }>>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ name: string;
64
+ description?: string | undefined;
65
+ settings?: {
66
+ retentionPeriodDays?: number | undefined;
67
+ maxStreamSizeBytes?: number | undefined;
68
+ } | undefined;
69
+ }, {
70
+ name: string;
71
+ description?: string | undefined;
72
+ settings?: {
73
+ retentionPeriodDays?: number | undefined;
74
+ maxStreamSizeBytes?: number | undefined;
75
+ } | undefined;
76
+ }>;
77
+ const EventStoreListResponseSchema: z.ZodObject<{
78
+ eventStores: z.ZodArray<z.ZodObject<{
79
+ eventStoreID: z.ZodString;
80
+ eventStoreName: z.ZodString;
81
+ eventStoreDurableObjectID: z.ZodString;
82
+ eventBusDurableObjectID: z.ZodString;
83
+ description: z.ZodOptional<z.ZodString>;
84
+ settings: z.ZodOptional<z.ZodObject<{
85
+ retentionPeriodDays: z.ZodOptional<z.ZodNumber>;
86
+ maxStreamSizeBytes: z.ZodOptional<z.ZodNumber>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ retentionPeriodDays?: number | undefined;
89
+ maxStreamSizeBytes?: number | undefined;
90
+ }, {
91
+ retentionPeriodDays?: number | undefined;
92
+ maxStreamSizeBytes?: number | undefined;
93
+ }>>;
94
+ created: z.ZodString;
95
+ }, "strip", z.ZodTypeAny, {
96
+ created: string;
97
+ eventStoreID: string;
98
+ eventStoreName: string;
99
+ eventStoreDurableObjectID: string;
100
+ eventBusDurableObjectID: string;
101
+ description?: string | undefined;
102
+ settings?: {
103
+ retentionPeriodDays?: number | undefined;
104
+ maxStreamSizeBytes?: number | undefined;
105
+ } | undefined;
106
+ }, {
107
+ created: string;
108
+ eventStoreID: string;
109
+ eventStoreName: string;
110
+ eventStoreDurableObjectID: string;
111
+ eventBusDurableObjectID: string;
112
+ description?: string | undefined;
113
+ settings?: {
114
+ retentionPeriodDays?: number | undefined;
115
+ maxStreamSizeBytes?: number | undefined;
116
+ } | undefined;
117
+ }>, "many">;
118
+ totalCount: z.ZodNumber;
119
+ }, "strip", z.ZodTypeAny, {
120
+ totalCount: number;
121
+ eventStores: {
122
+ created: string;
123
+ eventStoreID: string;
124
+ eventStoreName: string;
125
+ eventStoreDurableObjectID: string;
126
+ eventBusDurableObjectID: string;
127
+ description?: string | undefined;
128
+ settings?: {
129
+ retentionPeriodDays?: number | undefined;
130
+ maxStreamSizeBytes?: number | undefined;
131
+ } | undefined;
132
+ }[];
133
+ }, {
134
+ totalCount: number;
135
+ eventStores: {
136
+ created: string;
137
+ eventStoreID: string;
138
+ eventStoreName: string;
139
+ eventStoreDurableObjectID: string;
140
+ eventBusDurableObjectID: string;
141
+ description?: string | undefined;
142
+ settings?: {
143
+ retentionPeriodDays?: number | undefined;
144
+ maxStreamSizeBytes?: number | undefined;
145
+ } | undefined;
146
+ }[];
147
+ }>;
148
+ const EventStoreDatabaseSizesSchema: z.ZodObject<{
149
+ eventStoreDatabaseSize: z.ZodNumber;
150
+ eventBusDatabaseSize: z.ZodNumber;
151
+ totalSize: z.ZodNumber;
152
+ }, "strip", z.ZodTypeAny, {
153
+ eventStoreDatabaseSize: number;
154
+ eventBusDatabaseSize: number;
155
+ totalSize: number;
156
+ }, {
157
+ eventStoreDatabaseSize: number;
158
+ eventBusDatabaseSize: number;
159
+ totalSize: number;
160
+ }>;
161
+ const EventStoreDetailsResponseSchema: z.ZodObject<z.objectUtil.extendShape<{
162
+ eventStoreID: z.ZodString;
163
+ eventStoreName: z.ZodString;
164
+ eventStoreDurableObjectID: z.ZodString;
165
+ eventBusDurableObjectID: z.ZodString;
166
+ description: z.ZodOptional<z.ZodString>;
167
+ settings: z.ZodOptional<z.ZodObject<{
168
+ retentionPeriodDays: z.ZodOptional<z.ZodNumber>;
169
+ maxStreamSizeBytes: z.ZodOptional<z.ZodNumber>;
170
+ }, "strip", z.ZodTypeAny, {
171
+ retentionPeriodDays?: number | undefined;
172
+ maxStreamSizeBytes?: number | undefined;
173
+ }, {
174
+ retentionPeriodDays?: number | undefined;
175
+ maxStreamSizeBytes?: number | undefined;
176
+ }>>;
177
+ created: z.ZodString;
178
+ }, {
179
+ streams: z.ZodOptional<z.ZodObject<{
180
+ count: z.ZodNumber;
181
+ totalEvents: z.ZodNumber;
182
+ }, "strip", z.ZodTypeAny, {
183
+ count: number;
184
+ totalEvents: number;
185
+ }, {
186
+ count: number;
187
+ totalEvents: number;
188
+ }>>;
189
+ databaseSizes: z.ZodOptional<z.ZodObject<{
190
+ eventStoreDatabaseSize: z.ZodNumber;
191
+ eventBusDatabaseSize: z.ZodNumber;
192
+ totalSize: z.ZodNumber;
193
+ }, "strip", z.ZodTypeAny, {
194
+ eventStoreDatabaseSize: number;
195
+ eventBusDatabaseSize: number;
196
+ totalSize: number;
197
+ }, {
198
+ eventStoreDatabaseSize: number;
199
+ eventBusDatabaseSize: number;
200
+ totalSize: number;
201
+ }>>;
202
+ }>, "strip", z.ZodTypeAny, {
203
+ created: string;
204
+ eventStoreID: string;
205
+ eventStoreName: string;
206
+ eventStoreDurableObjectID: string;
207
+ eventBusDurableObjectID: string;
208
+ description?: string | undefined;
209
+ settings?: {
210
+ retentionPeriodDays?: number | undefined;
211
+ maxStreamSizeBytes?: number | undefined;
212
+ } | undefined;
213
+ streams?: {
214
+ count: number;
215
+ totalEvents: number;
216
+ } | undefined;
217
+ databaseSizes?: {
218
+ eventStoreDatabaseSize: number;
219
+ eventBusDatabaseSize: number;
220
+ totalSize: number;
221
+ } | undefined;
222
+ }, {
223
+ created: string;
224
+ eventStoreID: string;
225
+ eventStoreName: string;
226
+ eventStoreDurableObjectID: string;
227
+ eventBusDurableObjectID: string;
228
+ description?: string | undefined;
229
+ settings?: {
230
+ retentionPeriodDays?: number | undefined;
231
+ maxStreamSizeBytes?: number | undefined;
232
+ } | undefined;
233
+ streams?: {
234
+ count: number;
235
+ totalEvents: number;
236
+ } | undefined;
237
+ databaseSizes?: {
238
+ eventStoreDatabaseSize: number;
239
+ eventBusDatabaseSize: number;
240
+ totalSize: number;
241
+ } | undefined;
242
+ }>;
243
+ const ErrorResponseSchema: z.ZodObject<{
244
+ error: z.ZodString;
245
+ message: z.ZodString;
246
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
247
+ }, "strip", z.ZodTypeAny, {
248
+ error: string;
249
+ message: string;
250
+ details?: Record<string, any> | undefined;
251
+ }, {
252
+ error: string;
253
+ message: string;
254
+ details?: Record<string, any> | undefined;
255
+ }>;
256
+ const routes: OpenAPIHono<{
257
+ Bindings: Env;
258
+ }, {}, "/">;
43
259
  }
44
- type DefaultStreamVersionType = number;
45
- type ReadStreamOptions<StreamVersion = DefaultStreamVersionType> = ({
46
- from: StreamVersion;
47
- } | {
48
- to: StreamVersion;
49
- } | {
50
- from: StreamVersion;
51
- maxCount?: DefaultStreamVersionType;
52
- } | {
53
- expectedStreamVersion: ExpectedStreamVersion<StreamVersion>;
54
- }) & {
55
- expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;
56
- };
57
- type ReadStreamResult<EventType extends Event, StreamVersion = DefaultStreamVersionType, ReadEventMetadataType extends ReadEventMetadata = ReadEventMetadata> = {
58
- currentStreamVersion: StreamVersion;
59
- events: ReadEvent<EventType, ReadEventMetadataType>[];
60
- } | null;
61
- type Evolve<State, EventType extends Event, ReadEventMetadataType extends ReadEventMetadata = ReadEventMetadata> = ((currentState: State, event: EventType) => State) | ((currentState: State, event: ReadEvent<EventType, ReadEventMetadataType>) => State) | ((currentState: State, event: ReadEvent<EventType>) => State);
62
- type AggregateStreamOptions<State, EventType extends Event, StreamVersion = DefaultStreamVersionType, ReadEventMetadataType extends ReadEventMetadata = ReadEventMetadata> = {
63
- evolve: Evolve<State, EventType, ReadEventMetadataType>;
64
- initialState: () => State;
65
- read?: ReadStreamOptions<StreamVersion>;
66
- };
67
- type AggregateStreamResult<State, StreamVersion = DefaultStreamVersionType> = {
68
- currentStreamVersion: StreamVersion;
69
- state: State;
70
- };
71
- type AppendToStreamOptions<StreamVersion = DefaultStreamVersionType> = {
72
- expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;
73
- };
74
- type AppendToStreamResult<StreamVersion = DefaultStreamVersionType> = {
75
- nextExpectedStreamVersion: StreamVersion;
76
- };
77
260
 
78
- type EventStoreOutboxEvent = {
79
- stream_position: number;
80
- global_position: number;
81
- event_id: string;
82
- event_type: string;
83
- event_data: string;
84
- event_metadata: string;
85
- event_schema_version: string;
86
- transaction_id: string;
87
- stream_id: string;
88
- phase: number;
89
- created: string;
90
- processing_started_at: string;
91
- processed_at: string;
92
- };
93
- declare class EventStoreDurableObject extends DurableObject<Env> {
94
- sql: SqlStorage;
95
- constructor(ctx: DurableObjectState, env: Env);
96
- private initializeTables;
97
- initialize(eventStoreId: string): void;
98
- getEventStoreId(): string;
99
- appendToStream(streamId: string, events: Event[], options?: AppendToStreamOptions<number>): Promise<AppendToStreamResult<number>>;
100
- private getStreamVersion;
101
- private getGlobalPosition;
102
- private scheduleAsyncWork;
103
- private storeEventsToStream;
104
- alarm(_alarmInfo: AlarmInvocationInfo): Promise<void>;
105
- queryEvents(options: {
106
- afterPosition?: number;
107
- limit?: number;
108
- streamId?: string;
109
- eventType?: string;
110
- }): Promise<{
111
- events: EventStoreOutboxEvent[];
112
- hasMore: boolean;
113
- nextPosition: number;
261
+ declare namespace EventStoreAPI {
262
+ const AppendEventsRequestSchema: z.ZodObject<{
263
+ events: z.ZodArray<z.ZodObject<{
264
+ type: z.ZodString;
265
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
266
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
267
+ }, "strip", z.ZodTypeAny, {
268
+ type: string;
269
+ data: Record<string, any>;
270
+ metadata?: Record<string, any> | undefined;
271
+ }, {
272
+ type: string;
273
+ data: Record<string, any>;
274
+ metadata?: Record<string, any> | undefined;
275
+ }>, "many">;
276
+ options: z.ZodOptional<z.ZodObject<{
277
+ expectedStreamVersion: z.ZodOptional<z.ZodNumber>;
278
+ }, "strip", z.ZodTypeAny, {
279
+ expectedStreamVersion?: number | undefined;
280
+ }, {
281
+ expectedStreamVersion?: number | undefined;
282
+ }>>;
283
+ }, "strip", z.ZodTypeAny, {
284
+ events: {
285
+ type: string;
286
+ data: Record<string, any>;
287
+ metadata?: Record<string, any> | undefined;
288
+ }[];
289
+ options?: {
290
+ expectedStreamVersion?: number | undefined;
291
+ } | undefined;
292
+ }, {
293
+ events: {
294
+ type: string;
295
+ data: Record<string, any>;
296
+ metadata?: Record<string, any> | undefined;
297
+ }[];
298
+ options?: {
299
+ expectedStreamVersion?: number | undefined;
300
+ } | undefined;
114
301
  }>;
115
- getDatabaseSize(): number;
116
- readStream<EventType extends Event>(streamId: string, options?: ReadStreamOptions & {
117
- consistencyLevel?: 'eventual' | 'strong';
118
- }): Promise<ReadStreamResult<EventType, DefaultStreamVersionType, ReadEventMetadataWithGlobalPosition> & {
119
- consistency: 'eventual' | 'strong';
302
+ const AppendEventsResponseSchema: z.ZodObject<{
303
+ success: z.ZodBoolean;
304
+ nextExpectedStreamVersion: z.ZodNumber;
305
+ eventsWritten: z.ZodNumber;
306
+ }, "strip", z.ZodTypeAny, {
307
+ success: boolean;
308
+ nextExpectedStreamVersion: number;
309
+ eventsWritten: number;
310
+ }, {
311
+ success: boolean;
312
+ nextExpectedStreamVersion: number;
313
+ eventsWritten: number;
314
+ }>;
315
+ const VersionConflictErrorSchema: z.ZodObject<{
316
+ error: z.ZodLiteral<"Version conflict">;
317
+ details: z.ZodString;
318
+ currentVersion: z.ZodNumber;
319
+ expectedVersion: z.ZodNumber;
320
+ }, "strip", z.ZodTypeAny, {
321
+ error: "Version conflict";
322
+ details: string;
323
+ currentVersion: number;
324
+ expectedVersion: number;
325
+ }, {
326
+ error: "Version conflict";
327
+ details: string;
328
+ currentVersion: number;
329
+ expectedVersion: number;
330
+ }>;
331
+ const ValidationErrorSchema: z.ZodObject<{
332
+ error: z.ZodLiteral<"Invalid request body">;
333
+ details: z.ZodArray<z.ZodObject<{
334
+ code: z.ZodString;
335
+ message: z.ZodString;
336
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
337
+ }, "strip", z.ZodTypeAny, {
338
+ message: string;
339
+ code: string;
340
+ path: (string | number)[];
341
+ }, {
342
+ message: string;
343
+ code: string;
344
+ path: (string | number)[];
345
+ }>, "many">;
346
+ }, "strip", z.ZodTypeAny, {
347
+ error: "Invalid request body";
348
+ details: {
349
+ message: string;
350
+ code: string;
351
+ path: (string | number)[];
352
+ }[];
353
+ }, {
354
+ error: "Invalid request body";
355
+ details: {
356
+ message: string;
357
+ code: string;
358
+ path: (string | number)[];
359
+ }[];
360
+ }>;
361
+ const AppendEventsErrorSchema: z.ZodDiscriminatedUnion<"error", [z.ZodObject<{
362
+ error: z.ZodLiteral<"Version conflict">;
363
+ details: z.ZodString;
364
+ currentVersion: z.ZodNumber;
365
+ expectedVersion: z.ZodNumber;
366
+ }, "strip", z.ZodTypeAny, {
367
+ error: "Version conflict";
368
+ details: string;
369
+ currentVersion: number;
370
+ expectedVersion: number;
371
+ }, {
372
+ error: "Version conflict";
373
+ details: string;
374
+ currentVersion: number;
375
+ expectedVersion: number;
376
+ }>, z.ZodObject<{
377
+ error: z.ZodLiteral<"Invalid request body">;
378
+ details: z.ZodArray<z.ZodObject<{
379
+ code: z.ZodString;
380
+ message: z.ZodString;
381
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
382
+ }, "strip", z.ZodTypeAny, {
383
+ message: string;
384
+ code: string;
385
+ path: (string | number)[];
386
+ }, {
387
+ message: string;
388
+ code: string;
389
+ path: (string | number)[];
390
+ }>, "many">;
391
+ }, "strip", z.ZodTypeAny, {
392
+ error: "Invalid request body";
393
+ details: {
394
+ message: string;
395
+ code: string;
396
+ path: (string | number)[];
397
+ }[];
398
+ }, {
399
+ error: "Invalid request body";
400
+ details: {
401
+ message: string;
402
+ code: string;
403
+ path: (string | number)[];
404
+ }[];
405
+ }>]>;
406
+ const ReadStreamOptionsSchema: z.ZodObject<{
407
+ consistencyLevel: z.ZodOptional<z.ZodEnum<["eventual", "strong"]>>;
408
+ expectedStreamVersion: z.ZodOptional<z.ZodNumber>;
409
+ }, "strip", z.ZodTypeAny, {
410
+ expectedStreamVersion?: number | undefined;
411
+ consistencyLevel?: "eventual" | "strong" | undefined;
412
+ }, {
413
+ expectedStreamVersion?: number | undefined;
414
+ consistencyLevel?: "eventual" | "strong" | undefined;
415
+ }>;
416
+ const EventWithMetadataSchema: z.ZodObject<z.objectUtil.extendShape<{
417
+ type: z.ZodString;
418
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
419
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
420
+ }, {
421
+ metadata: z.ZodOptional<z.ZodObject<{
422
+ eventId: z.ZodString;
423
+ streamPosition: z.ZodNumber;
424
+ streamName: z.ZodString;
425
+ globalPosition: z.ZodNumber;
426
+ schemaVersion: z.ZodString;
427
+ }, "strip", z.ZodTypeAny, {
428
+ eventId: string;
429
+ streamPosition: number;
430
+ streamName: string;
431
+ globalPosition: number;
432
+ schemaVersion: string;
433
+ }, {
434
+ eventId: string;
435
+ streamPosition: number;
436
+ streamName: string;
437
+ globalPosition: number;
438
+ schemaVersion: string;
439
+ }>>;
440
+ }>, "strip", z.ZodTypeAny, {
441
+ type: string;
442
+ data: Record<string, any>;
443
+ metadata?: {
444
+ eventId: string;
445
+ streamPosition: number;
446
+ streamName: string;
447
+ globalPosition: number;
448
+ schemaVersion: string;
449
+ } | undefined;
450
+ }, {
451
+ type: string;
452
+ data: Record<string, any>;
453
+ metadata?: {
454
+ eventId: string;
455
+ streamPosition: number;
456
+ streamName: string;
457
+ globalPosition: number;
458
+ schemaVersion: string;
459
+ } | undefined;
460
+ }>;
461
+ const ReadStreamResponseSchema: z.ZodObject<{
462
+ events: z.ZodArray<z.ZodObject<z.objectUtil.extendShape<{
463
+ type: z.ZodString;
464
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
465
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
466
+ }, {
467
+ metadata: z.ZodOptional<z.ZodObject<{
468
+ eventId: z.ZodString;
469
+ streamPosition: z.ZodNumber;
470
+ streamName: z.ZodString;
471
+ globalPosition: z.ZodNumber;
472
+ schemaVersion: z.ZodString;
473
+ }, "strip", z.ZodTypeAny, {
474
+ eventId: string;
475
+ streamPosition: number;
476
+ streamName: string;
477
+ globalPosition: number;
478
+ schemaVersion: string;
479
+ }, {
480
+ eventId: string;
481
+ streamPosition: number;
482
+ streamName: string;
483
+ globalPosition: number;
484
+ schemaVersion: string;
485
+ }>>;
486
+ }>, "strip", z.ZodTypeAny, {
487
+ type: string;
488
+ data: Record<string, any>;
489
+ metadata?: {
490
+ eventId: string;
491
+ streamPosition: number;
492
+ streamName: string;
493
+ globalPosition: number;
494
+ schemaVersion: string;
495
+ } | undefined;
496
+ }, {
497
+ type: string;
498
+ data: Record<string, any>;
499
+ metadata?: {
500
+ eventId: string;
501
+ streamPosition: number;
502
+ streamName: string;
503
+ globalPosition: number;
504
+ schemaVersion: string;
505
+ } | undefined;
506
+ }>, "many">;
507
+ currentStreamVersion: z.ZodNumber;
508
+ }, "strip", z.ZodTypeAny, {
509
+ events: {
510
+ type: string;
511
+ data: Record<string, any>;
512
+ metadata?: {
513
+ eventId: string;
514
+ streamPosition: number;
515
+ streamName: string;
516
+ globalPosition: number;
517
+ schemaVersion: string;
518
+ } | undefined;
519
+ }[];
520
+ currentStreamVersion: number;
521
+ }, {
522
+ events: {
523
+ type: string;
524
+ data: Record<string, any>;
525
+ metadata?: {
526
+ eventId: string;
527
+ streamPosition: number;
528
+ streamName: string;
529
+ globalPosition: number;
530
+ schemaVersion: string;
531
+ } | undefined;
532
+ }[];
533
+ currentStreamVersion: number;
534
+ }>;
535
+ const routes: OpenAPIHono<{
536
+ Bindings: Env;
537
+ }, {}, "/">;
538
+ }
539
+
540
+ declare namespace EventBusAPI {
541
+ const routes: OpenAPIHono<{
542
+ Bindings: Env;
543
+ }, {}, "/">;
544
+ const SubscriberTypeEnum: z.ZodEnum<["durable_object", "webhook", "queue", "cloudflare_workflow", "websocket"]>;
545
+ const SubscriptionStatusEnum: z.ZodEnum<["ACTIVE", "SUSPENDED", "ERROR", "INITIALIZING", "DELETED"]>;
546
+ const SubscriptionRequestSchema: z.ZodObject<{
547
+ eventFilter: z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"*">, z.ZodString, z.ZodString, z.ZodString]>, z.ZodArray<z.ZodUnion<[z.ZodLiteral<"*">, z.ZodString, z.ZodString, z.ZodString]>, "many">]>;
548
+ subscriberId: z.ZodOptional<z.ZodString>;
549
+ subscriber: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
550
+ type: z.ZodLiteral<"durable_object">;
551
+ config: z.ZodObject<z.objectUtil.extendShape<{
552
+ retryPolicy: z.ZodOptional<z.ZodObject<{
553
+ maxAttempts: z.ZodNumber;
554
+ backoffMinutes: z.ZodNumber;
555
+ }, "strip", z.ZodTypeAny, {
556
+ maxAttempts: number;
557
+ backoffMinutes: number;
558
+ }, {
559
+ maxAttempts: number;
560
+ backoffMinutes: number;
561
+ }>>;
562
+ }, {
563
+ namespace: z.ZodString;
564
+ id: z.ZodString;
565
+ }>, "strip", z.ZodTypeAny, {
566
+ namespace: string;
567
+ id: string;
568
+ retryPolicy?: {
569
+ maxAttempts: number;
570
+ backoffMinutes: number;
571
+ } | undefined;
572
+ }, {
573
+ namespace: string;
574
+ id: string;
575
+ retryPolicy?: {
576
+ maxAttempts: number;
577
+ backoffMinutes: number;
578
+ } | undefined;
579
+ }>;
580
+ }, "strip", z.ZodTypeAny, {
581
+ type: "durable_object";
582
+ config: {
583
+ namespace: string;
584
+ id: string;
585
+ retryPolicy?: {
586
+ maxAttempts: number;
587
+ backoffMinutes: number;
588
+ } | undefined;
589
+ };
590
+ }, {
591
+ type: "durable_object";
592
+ config: {
593
+ namespace: string;
594
+ id: string;
595
+ retryPolicy?: {
596
+ maxAttempts: number;
597
+ backoffMinutes: number;
598
+ } | undefined;
599
+ };
600
+ }>, z.ZodObject<{
601
+ type: z.ZodLiteral<"webhook">;
602
+ config: z.ZodObject<z.objectUtil.extendShape<{
603
+ retryPolicy: z.ZodOptional<z.ZodObject<{
604
+ maxAttempts: z.ZodNumber;
605
+ backoffMinutes: z.ZodNumber;
606
+ }, "strip", z.ZodTypeAny, {
607
+ maxAttempts: number;
608
+ backoffMinutes: number;
609
+ }, {
610
+ maxAttempts: number;
611
+ backoffMinutes: number;
612
+ }>>;
613
+ }, {
614
+ url: z.ZodString;
615
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
616
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
617
+ }>, "strip", z.ZodTypeAny, {
618
+ url: string;
619
+ headers?: Record<string, string> | undefined;
620
+ retryPolicy?: {
621
+ maxAttempts: number;
622
+ backoffMinutes: number;
623
+ } | undefined;
624
+ timeoutMs?: number | undefined;
625
+ }, {
626
+ url: string;
627
+ headers?: Record<string, string> | undefined;
628
+ retryPolicy?: {
629
+ maxAttempts: number;
630
+ backoffMinutes: number;
631
+ } | undefined;
632
+ timeoutMs?: number | undefined;
633
+ }>;
634
+ }, "strip", z.ZodTypeAny, {
635
+ type: "webhook";
636
+ config: {
637
+ url: string;
638
+ headers?: Record<string, string> | undefined;
639
+ retryPolicy?: {
640
+ maxAttempts: number;
641
+ backoffMinutes: number;
642
+ } | undefined;
643
+ timeoutMs?: number | undefined;
644
+ };
645
+ }, {
646
+ type: "webhook";
647
+ config: {
648
+ url: string;
649
+ headers?: Record<string, string> | undefined;
650
+ retryPolicy?: {
651
+ maxAttempts: number;
652
+ backoffMinutes: number;
653
+ } | undefined;
654
+ timeoutMs?: number | undefined;
655
+ };
656
+ }>, z.ZodObject<{
657
+ type: z.ZodLiteral<"queue">;
658
+ config: z.ZodObject<z.objectUtil.extendShape<{
659
+ retryPolicy: z.ZodOptional<z.ZodObject<{
660
+ maxAttempts: z.ZodNumber;
661
+ backoffMinutes: z.ZodNumber;
662
+ }, "strip", z.ZodTypeAny, {
663
+ maxAttempts: number;
664
+ backoffMinutes: number;
665
+ }, {
666
+ maxAttempts: number;
667
+ backoffMinutes: number;
668
+ }>>;
669
+ }, {
670
+ queueName: z.ZodString;
671
+ region: z.ZodOptional<z.ZodString>;
672
+ batchSize: z.ZodOptional<z.ZodNumber>;
673
+ }>, "strip", z.ZodTypeAny, {
674
+ queueName: string;
675
+ retryPolicy?: {
676
+ maxAttempts: number;
677
+ backoffMinutes: number;
678
+ } | undefined;
679
+ region?: string | undefined;
680
+ batchSize?: number | undefined;
681
+ }, {
682
+ queueName: string;
683
+ retryPolicy?: {
684
+ maxAttempts: number;
685
+ backoffMinutes: number;
686
+ } | undefined;
687
+ region?: string | undefined;
688
+ batchSize?: number | undefined;
689
+ }>;
690
+ }, "strip", z.ZodTypeAny, {
691
+ type: "queue";
692
+ config: {
693
+ queueName: string;
694
+ retryPolicy?: {
695
+ maxAttempts: number;
696
+ backoffMinutes: number;
697
+ } | undefined;
698
+ region?: string | undefined;
699
+ batchSize?: number | undefined;
700
+ };
701
+ }, {
702
+ type: "queue";
703
+ config: {
704
+ queueName: string;
705
+ retryPolicy?: {
706
+ maxAttempts: number;
707
+ backoffMinutes: number;
708
+ } | undefined;
709
+ region?: string | undefined;
710
+ batchSize?: number | undefined;
711
+ };
712
+ }>, z.ZodObject<{
713
+ type: z.ZodLiteral<"cloudflare_workflow">;
714
+ config: z.ZodObject<z.objectUtil.extendShape<{
715
+ retryPolicy: z.ZodOptional<z.ZodObject<{
716
+ maxAttempts: z.ZodNumber;
717
+ backoffMinutes: z.ZodNumber;
718
+ }, "strip", z.ZodTypeAny, {
719
+ maxAttempts: number;
720
+ backoffMinutes: number;
721
+ }, {
722
+ maxAttempts: number;
723
+ backoffMinutes: number;
724
+ }>>;
725
+ }, {
726
+ bindingName: z.ZodString;
727
+ }>, "strip", z.ZodTypeAny, {
728
+ bindingName: string;
729
+ retryPolicy?: {
730
+ maxAttempts: number;
731
+ backoffMinutes: number;
732
+ } | undefined;
733
+ }, {
734
+ bindingName: string;
735
+ retryPolicy?: {
736
+ maxAttempts: number;
737
+ backoffMinutes: number;
738
+ } | undefined;
739
+ }>;
740
+ }, "strip", z.ZodTypeAny, {
741
+ type: "cloudflare_workflow";
742
+ config: {
743
+ bindingName: string;
744
+ retryPolicy?: {
745
+ maxAttempts: number;
746
+ backoffMinutes: number;
747
+ } | undefined;
748
+ };
749
+ }, {
750
+ type: "cloudflare_workflow";
751
+ config: {
752
+ bindingName: string;
753
+ retryPolicy?: {
754
+ maxAttempts: number;
755
+ backoffMinutes: number;
756
+ } | undefined;
757
+ };
758
+ }>, z.ZodObject<{
759
+ type: z.ZodLiteral<"websocket">;
760
+ config: z.ZodObject<z.objectUtil.extendShape<{
761
+ retryPolicy: z.ZodOptional<z.ZodObject<{
762
+ maxAttempts: z.ZodNumber;
763
+ backoffMinutes: z.ZodNumber;
764
+ }, "strip", z.ZodTypeAny, {
765
+ maxAttempts: number;
766
+ backoffMinutes: number;
767
+ }, {
768
+ maxAttempts: number;
769
+ backoffMinutes: number;
770
+ }>>;
771
+ }, {
772
+ managerId: z.ZodString;
773
+ }>, "strip", z.ZodTypeAny, {
774
+ managerId: string;
775
+ retryPolicy?: {
776
+ maxAttempts: number;
777
+ backoffMinutes: number;
778
+ } | undefined;
779
+ }, {
780
+ managerId: string;
781
+ retryPolicy?: {
782
+ maxAttempts: number;
783
+ backoffMinutes: number;
784
+ } | undefined;
785
+ }>;
786
+ }, "strip", z.ZodTypeAny, {
787
+ type: "websocket";
788
+ config: {
789
+ managerId: string;
790
+ retryPolicy?: {
791
+ maxAttempts: number;
792
+ backoffMinutes: number;
793
+ } | undefined;
794
+ };
795
+ }, {
796
+ type: "websocket";
797
+ config: {
798
+ managerId: string;
799
+ retryPolicy?: {
800
+ maxAttempts: number;
801
+ backoffMinutes: number;
802
+ } | undefined;
803
+ };
804
+ }>]>;
805
+ initialPosition: z.ZodDefault<z.ZodOptional<z.ZodEnum<["latest", "earliest"]>>>;
806
+ }, "strip", z.ZodTypeAny, {
807
+ eventFilter: string | string[];
808
+ subscriber: {
809
+ type: "durable_object";
810
+ config: {
811
+ namespace: string;
812
+ id: string;
813
+ retryPolicy?: {
814
+ maxAttempts: number;
815
+ backoffMinutes: number;
816
+ } | undefined;
817
+ };
818
+ } | {
819
+ type: "webhook";
820
+ config: {
821
+ url: string;
822
+ headers?: Record<string, string> | undefined;
823
+ retryPolicy?: {
824
+ maxAttempts: number;
825
+ backoffMinutes: number;
826
+ } | undefined;
827
+ timeoutMs?: number | undefined;
828
+ };
829
+ } | {
830
+ type: "queue";
831
+ config: {
832
+ queueName: string;
833
+ retryPolicy?: {
834
+ maxAttempts: number;
835
+ backoffMinutes: number;
836
+ } | undefined;
837
+ region?: string | undefined;
838
+ batchSize?: number | undefined;
839
+ };
840
+ } | {
841
+ type: "cloudflare_workflow";
842
+ config: {
843
+ bindingName: string;
844
+ retryPolicy?: {
845
+ maxAttempts: number;
846
+ backoffMinutes: number;
847
+ } | undefined;
848
+ };
849
+ } | {
850
+ type: "websocket";
851
+ config: {
852
+ managerId: string;
853
+ retryPolicy?: {
854
+ maxAttempts: number;
855
+ backoffMinutes: number;
856
+ } | undefined;
857
+ };
858
+ };
859
+ initialPosition: "latest" | "earliest";
860
+ subscriberId?: string | undefined;
861
+ }, {
862
+ eventFilter: string | string[];
863
+ subscriber: {
864
+ type: "durable_object";
865
+ config: {
866
+ namespace: string;
867
+ id: string;
868
+ retryPolicy?: {
869
+ maxAttempts: number;
870
+ backoffMinutes: number;
871
+ } | undefined;
872
+ };
873
+ } | {
874
+ type: "webhook";
875
+ config: {
876
+ url: string;
877
+ headers?: Record<string, string> | undefined;
878
+ retryPolicy?: {
879
+ maxAttempts: number;
880
+ backoffMinutes: number;
881
+ } | undefined;
882
+ timeoutMs?: number | undefined;
883
+ };
884
+ } | {
885
+ type: "queue";
886
+ config: {
887
+ queueName: string;
888
+ retryPolicy?: {
889
+ maxAttempts: number;
890
+ backoffMinutes: number;
891
+ } | undefined;
892
+ region?: string | undefined;
893
+ batchSize?: number | undefined;
894
+ };
895
+ } | {
896
+ type: "cloudflare_workflow";
897
+ config: {
898
+ bindingName: string;
899
+ retryPolicy?: {
900
+ maxAttempts: number;
901
+ backoffMinutes: number;
902
+ } | undefined;
903
+ };
904
+ } | {
905
+ type: "websocket";
906
+ config: {
907
+ managerId: string;
908
+ retryPolicy?: {
909
+ maxAttempts: number;
910
+ backoffMinutes: number;
911
+ } | undefined;
912
+ };
913
+ };
914
+ subscriberId?: string | undefined;
915
+ initialPosition?: "latest" | "earliest" | undefined;
916
+ }>;
917
+ const SubscriptionResponseSchema: z.ZodObject<{
918
+ subscriptionId: z.ZodString;
919
+ status: z.ZodEnum<["ACTIVE", "SUSPENDED", "ERROR", "INITIALIZING", "DELETED"]>;
920
+ statusDetails: z.ZodOptional<z.ZodObject<{
921
+ lastError: z.ZodOptional<z.ZodString>;
922
+ lastErrorAt: z.ZodOptional<z.ZodString>;
923
+ retryCount: z.ZodOptional<z.ZodNumber>;
924
+ nextRetryAt: z.ZodOptional<z.ZodString>;
925
+ }, "strip", z.ZodTypeAny, {
926
+ lastError?: string | undefined;
927
+ retryCount?: number | undefined;
928
+ lastErrorAt?: string | undefined;
929
+ nextRetryAt?: string | undefined;
930
+ }, {
931
+ lastError?: string | undefined;
932
+ retryCount?: number | undefined;
933
+ lastErrorAt?: string | undefined;
934
+ nextRetryAt?: string | undefined;
935
+ }>>;
936
+ eventStoreId: z.ZodString;
937
+ eventFilter: z.ZodString;
938
+ subscriberId: z.ZodString;
939
+ subscriberType: z.ZodEnum<["durable_object", "webhook", "queue", "cloudflare_workflow", "websocket"]>;
940
+ createdAt: z.ZodString;
941
+ updatedAt: z.ZodString;
942
+ lastProcessedEventGlobalPosition: z.ZodOptional<z.ZodNumber>;
943
+ }, "strip", z.ZodTypeAny, {
944
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
945
+ eventStoreId: string;
946
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
947
+ eventFilter: string;
948
+ subscriberId: string;
949
+ createdAt: string;
950
+ updatedAt: string;
951
+ subscriptionId: string;
952
+ statusDetails?: {
953
+ lastError?: string | undefined;
954
+ retryCount?: number | undefined;
955
+ lastErrorAt?: string | undefined;
956
+ nextRetryAt?: string | undefined;
957
+ } | undefined;
958
+ lastProcessedEventGlobalPosition?: number | undefined;
959
+ }, {
960
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
961
+ eventStoreId: string;
962
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
963
+ eventFilter: string;
964
+ subscriberId: string;
965
+ createdAt: string;
966
+ updatedAt: string;
967
+ subscriptionId: string;
968
+ statusDetails?: {
969
+ lastError?: string | undefined;
970
+ retryCount?: number | undefined;
971
+ lastErrorAt?: string | undefined;
972
+ nextRetryAt?: string | undefined;
973
+ } | undefined;
974
+ lastProcessedEventGlobalPosition?: number | undefined;
975
+ }>;
976
+ const SubscriptionListResponseSchema: z.ZodObject<{
977
+ subscriptions: z.ZodArray<z.ZodObject<{
978
+ subscriptionId: z.ZodString;
979
+ status: z.ZodEnum<["ACTIVE", "SUSPENDED", "ERROR", "INITIALIZING", "DELETED"]>;
980
+ statusDetails: z.ZodOptional<z.ZodObject<{
981
+ lastError: z.ZodOptional<z.ZodString>;
982
+ lastErrorAt: z.ZodOptional<z.ZodString>;
983
+ retryCount: z.ZodOptional<z.ZodNumber>;
984
+ nextRetryAt: z.ZodOptional<z.ZodString>;
985
+ }, "strip", z.ZodTypeAny, {
986
+ lastError?: string | undefined;
987
+ retryCount?: number | undefined;
988
+ lastErrorAt?: string | undefined;
989
+ nextRetryAt?: string | undefined;
990
+ }, {
991
+ lastError?: string | undefined;
992
+ retryCount?: number | undefined;
993
+ lastErrorAt?: string | undefined;
994
+ nextRetryAt?: string | undefined;
995
+ }>>;
996
+ eventStoreId: z.ZodString;
997
+ eventFilter: z.ZodString;
998
+ subscriberId: z.ZodString;
999
+ subscriberType: z.ZodEnum<["durable_object", "webhook", "queue", "cloudflare_workflow", "websocket"]>;
1000
+ createdAt: z.ZodString;
1001
+ updatedAt: z.ZodString;
1002
+ lastProcessedEventGlobalPosition: z.ZodOptional<z.ZodNumber>;
1003
+ }, "strip", z.ZodTypeAny, {
1004
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1005
+ eventStoreId: string;
1006
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1007
+ eventFilter: string;
1008
+ subscriberId: string;
1009
+ createdAt: string;
1010
+ updatedAt: string;
1011
+ subscriptionId: string;
1012
+ statusDetails?: {
1013
+ lastError?: string | undefined;
1014
+ retryCount?: number | undefined;
1015
+ lastErrorAt?: string | undefined;
1016
+ nextRetryAt?: string | undefined;
1017
+ } | undefined;
1018
+ lastProcessedEventGlobalPosition?: number | undefined;
1019
+ }, {
1020
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1021
+ eventStoreId: string;
1022
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1023
+ eventFilter: string;
1024
+ subscriberId: string;
1025
+ createdAt: string;
1026
+ updatedAt: string;
1027
+ subscriptionId: string;
1028
+ statusDetails?: {
1029
+ lastError?: string | undefined;
1030
+ retryCount?: number | undefined;
1031
+ lastErrorAt?: string | undefined;
1032
+ nextRetryAt?: string | undefined;
1033
+ } | undefined;
1034
+ lastProcessedEventGlobalPosition?: number | undefined;
1035
+ }>, "many">;
1036
+ totalCount: z.ZodNumber;
1037
+ }, "strip", z.ZodTypeAny, {
1038
+ totalCount: number;
1039
+ subscriptions: {
1040
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1041
+ eventStoreId: string;
1042
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1043
+ eventFilter: string;
1044
+ subscriberId: string;
1045
+ createdAt: string;
1046
+ updatedAt: string;
1047
+ subscriptionId: string;
1048
+ statusDetails?: {
1049
+ lastError?: string | undefined;
1050
+ retryCount?: number | undefined;
1051
+ lastErrorAt?: string | undefined;
1052
+ nextRetryAt?: string | undefined;
1053
+ } | undefined;
1054
+ lastProcessedEventGlobalPosition?: number | undefined;
1055
+ }[];
1056
+ }, {
1057
+ totalCount: number;
1058
+ subscriptions: {
1059
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1060
+ eventStoreId: string;
1061
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1062
+ eventFilter: string;
1063
+ subscriberId: string;
1064
+ createdAt: string;
1065
+ updatedAt: string;
1066
+ subscriptionId: string;
1067
+ statusDetails?: {
1068
+ lastError?: string | undefined;
1069
+ retryCount?: number | undefined;
1070
+ lastErrorAt?: string | undefined;
1071
+ nextRetryAt?: string | undefined;
1072
+ } | undefined;
1073
+ lastProcessedEventGlobalPosition?: number | undefined;
1074
+ }[];
1075
+ }>;
1076
+ const SubscriptionErrorSchema: z.ZodObject<{
1077
+ error: z.ZodString;
1078
+ message: z.ZodString;
1079
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1080
+ }, "strip", z.ZodTypeAny, {
1081
+ error: string;
1082
+ message: string;
1083
+ details?: Record<string, any> | undefined;
1084
+ }, {
1085
+ error: string;
1086
+ message: string;
1087
+ details?: Record<string, any> | undefined;
1088
+ }>;
1089
+ }
1090
+
1091
+ declare namespace WebSocketsAPI {
1092
+ const WebSocketConnectionSchema: z.ZodObject<{
1093
+ connectionId: z.ZodString;
1094
+ clientId: z.ZodString;
1095
+ connectedAt: z.ZodString;
1096
+ ipAddress: z.ZodOptional<z.ZodString>;
1097
+ userAgent: z.ZodOptional<z.ZodString>;
1098
+ filter: z.ZodOptional<z.ZodString>;
1099
+ }, "strip", z.ZodTypeAny, {
1100
+ clientId: string;
1101
+ connectionId: string;
1102
+ connectedAt: string;
1103
+ filter?: string | undefined;
1104
+ ipAddress?: string | undefined;
1105
+ userAgent?: string | undefined;
1106
+ }, {
1107
+ clientId: string;
1108
+ connectionId: string;
1109
+ connectedAt: string;
1110
+ filter?: string | undefined;
1111
+ ipAddress?: string | undefined;
1112
+ userAgent?: string | undefined;
1113
+ }>;
1114
+ const WebSocketConnectionListResponseSchema: z.ZodObject<{
1115
+ connections: z.ZodArray<z.ZodObject<{
1116
+ connectionId: z.ZodString;
1117
+ clientId: z.ZodString;
1118
+ connectedAt: z.ZodString;
1119
+ ipAddress: z.ZodOptional<z.ZodString>;
1120
+ userAgent: z.ZodOptional<z.ZodString>;
1121
+ filter: z.ZodOptional<z.ZodString>;
1122
+ }, "strip", z.ZodTypeAny, {
1123
+ clientId: string;
1124
+ connectionId: string;
1125
+ connectedAt: string;
1126
+ filter?: string | undefined;
1127
+ ipAddress?: string | undefined;
1128
+ userAgent?: string | undefined;
1129
+ }, {
1130
+ clientId: string;
1131
+ connectionId: string;
1132
+ connectedAt: string;
1133
+ filter?: string | undefined;
1134
+ ipAddress?: string | undefined;
1135
+ userAgent?: string | undefined;
1136
+ }>, "many">;
1137
+ totalCount: z.ZodNumber;
1138
+ eventStoreId: z.ZodString;
1139
+ }, "strip", z.ZodTypeAny, {
1140
+ connections: {
1141
+ clientId: string;
1142
+ connectionId: string;
1143
+ connectedAt: string;
1144
+ filter?: string | undefined;
1145
+ ipAddress?: string | undefined;
1146
+ userAgent?: string | undefined;
1147
+ }[];
1148
+ totalCount: number;
1149
+ eventStoreId: string;
1150
+ }, {
1151
+ connections: {
1152
+ clientId: string;
1153
+ connectionId: string;
1154
+ connectedAt: string;
1155
+ filter?: string | undefined;
1156
+ ipAddress?: string | undefined;
1157
+ userAgent?: string | undefined;
1158
+ }[];
1159
+ totalCount: number;
1160
+ eventStoreId: string;
1161
+ }>;
1162
+ const ErrorResponseSchema: z.ZodObject<{
1163
+ error: z.ZodString;
1164
+ message: z.ZodString;
1165
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1166
+ }, "strip", z.ZodTypeAny, {
1167
+ error: string;
1168
+ message: string;
1169
+ details?: Record<string, any> | undefined;
1170
+ }, {
1171
+ error: string;
1172
+ message: string;
1173
+ details?: Record<string, any> | undefined;
120
1174
  }>;
121
- private waitForStreamVersion;
122
- private mergeAndDeduplicateEvents;
1175
+ const routes: OpenAPIHono<{
1176
+ Bindings: Env;
1177
+ }, {}, "/">;
123
1178
  }
124
1179
 
125
1180
  type WildcardPattern = '*' | `${string}.*` | `*.${string}` | `${string}.*${string}`;
126
1181
  type EventType = string;
127
1182
  type EventFilter = EventType | EventType[] | WildcardPattern;
1183
+ declare enum InitialPosition {
1184
+ LATEST = "latest",
1185
+ EARLIEST = "earliest"
1186
+ }
128
1187
  interface BaseSubscriberConfig {
129
1188
  retryPolicy?: {
130
1189
  maxAttempts: number;
@@ -189,24 +1248,64 @@ interface EventMessage {
189
1248
  transaction_id: string;
190
1249
  created: string;
191
1250
  }
1251
+ interface SubscriptionListOptions {
1252
+ subscriberType?: SubscriberType;
1253
+ eventFilter?: string;
1254
+ limit?: number;
1255
+ offset?: number;
1256
+ }
1257
+ declare enum SubscriptionStatus {
1258
+ ACTIVE = "ACTIVE",
1259
+ SUSPENDED = "SUSPENDED",
1260
+ ERROR = "ERROR",
1261
+ INITIALIZING = "INITIALIZING",
1262
+ DELETED = "DELETED"
1263
+ }
1264
+ interface StatusDetails {
1265
+ lastError?: string;
1266
+ lastErrorAt?: string;
1267
+ retryCount?: number;
1268
+ nextRetryAt?: string;
1269
+ reason?: string;
1270
+ }
1271
+ interface Subscription {
1272
+ id: string;
1273
+ eventFilter: string;
1274
+ subscriberId: string;
1275
+ subscriberType: SubscriberType;
1276
+ subscriberConfig: string;
1277
+ status: SubscriptionStatus;
1278
+ statusDetails?: StatusDetails;
1279
+ lastProcessedEventGlobalPosition: number;
1280
+ createdAt: string;
1281
+ updatedAt: string;
1282
+ }
192
1283
  declare class EventBusDurableObject extends DurableObject<Env$1> {
193
1284
  private readonly BATCH_SIZE;
194
1285
  private readonly RETRY_DELAY_HOURS;
195
1286
  sql: SqlStorage;
196
1287
  constructor(state: DurableObjectState, env: Env$1);
197
1288
  private initializeTables;
198
- subscribe(eventFilter: EventFilter, subscriberId: string, subscription: SubscriberTypeConfig): Promise<void>;
199
- unsubscribe(eventFilter: EventFilter, subscriberId: string): Promise<void>;
200
- getSubscriptions(): Promise<{
201
- id: string;
202
- eventFilter: string;
203
- subscriberId: string;
204
- subscriberType: SubscriberType;
205
- subscriberConfig: string;
206
- lastProcessedEventGlobalPosition: number;
207
- createdAt: string;
208
- }[]>;
209
- publish(events: EventStoreOutboxEvent[]): Promise<void>;
1289
+ initialize(eventStoreID: string): void;
1290
+ subscribe(eventFilter: EventFilter, subscriberId: string, subscription: SubscriberTypeConfig, initialPosition?: InitialPosition): Promise<void>;
1291
+ private validateSubscriberConfig;
1292
+ private updateSubscriptionStatus;
1293
+ unsubscribe(subscriberId: string): Promise<void>;
1294
+ getSubscriptions(options?: SubscriptionListOptions): Promise<Subscription[]>;
1295
+ getSubscriptionsCount(options?: Omit<SubscriptionListOptions, 'limit' | 'offset'>): Promise<number>;
1296
+ getSubscription(id: string): Promise<Subscription | null>;
1297
+ publish(events: {
1298
+ event_id: string;
1299
+ event_type: string;
1300
+ event_data: Record<string, unknown>;
1301
+ event_metadata: Record<string, unknown>;
1302
+ stream_id: string;
1303
+ stream_position: number;
1304
+ global_position: number;
1305
+ event_schema_version: string;
1306
+ transaction_id: string;
1307
+ created: string;
1308
+ }[]): Promise<void>;
210
1309
  private getMatchingSubscriptions;
211
1310
  private scheduleDelivery;
212
1311
  private processOutboxBatch;
@@ -215,6 +1314,7 @@ declare class EventBusDurableObject extends DurableObject<Env$1> {
215
1314
  private parseSubscription;
216
1315
  private markMessageAsProcessed;
217
1316
  private markMessageAsFailed;
1317
+ private markDeliveryAttempt;
218
1318
  private deliverEvent;
219
1319
  private logProcessingMetrics;
220
1320
  alarm(alarmInfo: AlarmInvocationInfo): Promise<void>;
@@ -222,165 +1322,434 @@ declare class EventBusDurableObject extends DurableObject<Env$1> {
222
1322
  private validateEventFilter;
223
1323
  }
224
1324
 
225
- declare class WebSocketManagerDurableObject extends DurableObject<Env> {
226
- fetch(request: Request): Promise<Response>;
227
- private findWebSocketsByClientId;
228
- deliverEventToClient(clientId: string, event: EventMessage): Promise<void>;
229
- broadcastEvent(event: EventMessage): Promise<void>;
230
- closeConnection(clientId: string): Promise<void>;
231
- webSocketClose(ws: WebSocket, _code: number, reason: string, _wasClean: boolean): Promise<void>;
232
- }
233
-
234
- declare class EventStreamDurableObject extends DurableObject<Env> {
235
- sql: SqlStorage;
236
- private isProcessing;
237
- private static ALARM_DELAY;
238
- constructor(ctx: DurableObjectState, env: Env);
239
- private initializeTables;
240
- initializeStream(streamId: string, eventStoreId: string): void;
241
- private getStreamId;
242
- private getEventStoreId;
243
- appendToStream(events: EventStoreOutboxEvent[]): Promise<void>;
244
- getStreamEvents<EventType extends Event>(streamId: string, options?: ReadStreamOptions<number>): ReadStreamResult<EventType, number, ReadEventMetadataWithGlobalPosition>;
245
- getEventsByEventIds(eventIds: string[]): Promise<ReadEvent[]>;
246
- private checkUnprocessedEvents;
247
- private scheduleAsyncWork;
248
- private publishEventsToEventBus;
249
- private storeEventsToGlobalIndex;
250
- alarm(_alarmInfo: AlarmInvocationInfo): Promise<void>;
251
- }
1325
+ type Flavour<K, T> = K & {
1326
+ readonly __brand?: T;
1327
+ };
1328
+ type DefaultRecord = Record<string, unknown>;
1329
+ type Event<EventType extends string = string, EventData extends DefaultRecord = DefaultRecord, EventMetaData extends DefaultRecord = DefaultRecord> = Flavour<Readonly<{
1330
+ type: EventType;
1331
+ data: EventData;
1332
+ metadata?: EventMetaData;
1333
+ }>, 'Event'>;
1334
+ type EventTypeOf<T extends Event> = T['type'];
1335
+ type EventDataOf<T extends Event> = T['data'];
1336
+ type EventMetaDataOf<T extends Event> = T['metadata'];
1337
+ type CreateEventType<EventType extends string, EventData extends DefaultRecord, EventMetaData extends DefaultRecord | undefined> = Readonly<{
1338
+ type: EventType;
1339
+ data: EventData;
1340
+ metadata?: EventMetaData;
1341
+ }>;
1342
+ type ReadEvent<EventType extends Event = Event, EventMetaDataType extends EventMetaDataOf<EventType> & ReadEventMetadata = EventMetaDataOf<EventType> & ReadEventMetadata> = CreateEventType<EventTypeOf<EventType>, EventDataOf<EventType>, EventMetaDataType> & EventType & {
1343
+ metadata: EventMetaDataType;
1344
+ };
1345
+ type ReadEventMetadata = Readonly<{
1346
+ eventId: string;
1347
+ streamPosition: number;
1348
+ streamName: string;
1349
+ }>;
1350
+ type ExpectedStreamVersion<VersionType = DefaultStreamVersionType> = ExpectedStreamVersionWithValue<VersionType> | ExpectedStreamVersionGeneral;
1351
+ type ExpectedStreamVersionWithValue<VersionType = DefaultStreamVersionType> = Flavour<VersionType, 'StreamVersion'>;
1352
+ type ExpectedStreamVersionGeneral = Flavour<'STREAM_EXISTS' | 'STREAM_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK', 'StreamVersion'>;
1353
+ type DefaultStreamVersionType = number;
1354
+ type ReadStreamOptions<StreamVersion = DefaultStreamVersionType> = ({
1355
+ from: StreamVersion;
1356
+ } | {
1357
+ to: StreamVersion;
1358
+ } | {
1359
+ from: StreamVersion;
1360
+ maxCount?: DefaultStreamVersionType;
1361
+ } | {
1362
+ expectedStreamVersion: ExpectedStreamVersion<StreamVersion>;
1363
+ }) & {
1364
+ expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;
1365
+ };
1366
+ type AppendToStreamOptions<StreamVersion = DefaultStreamVersionType> = {
1367
+ expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;
1368
+ };
252
1369
 
253
- declare class EventGlobalIndexDurableObject extends DurableObject<Env> {
1370
+ /**
1371
+ * A durable object implementation of an event store.
1372
+ * Handles event persistence, archiving, and event bus integration.
1373
+ */
1374
+ declare class EventStoreDurableObject extends DurableObject<Env> {
254
1375
  sql: SqlStorage;
1376
+ /** Soft limit for database size (90% of 10GB) */
1377
+ private readonly SIZE_SOFT_LIMIT_MB;
1378
+ /** Hard limit for database size (95% of 10GB) */
1379
+ private readonly SIZE_HARD_LIMIT_MB;
1380
+ /** Emergency limit for database size (95% of 10GB) */
1381
+ private readonly SIZE_EMERGENCY_MB;
1382
+ /** Conversion factor from MB to bytes */
1383
+ private readonly MB_TO_BYTES;
1384
+ /** Number of events to store in each archive chunk */
1385
+ private readonly EVENTS_PER_ARCHIVE_CHUNK;
1386
+ /** Maximum batch size for emergency operations */
1387
+ private readonly MAX_EMERGENCY_BATCH_SIZE;
1388
+ /**
1389
+ * Creates a new instance of the EventStoreDurableObject
1390
+ * @param ctx - The durable object state
1391
+ * @param env - Environment variables and bindings
1392
+ */
255
1393
  constructor(ctx: DurableObjectState, env: Env);
1394
+ /**
1395
+ * Initializes the database tables required for the event store
1396
+ * @private
1397
+ */
256
1398
  private initializeTables;
257
- appendToIndex(events: EventStoreOutboxEvent[]): Promise<void>;
258
- getEventsByType(eventType: string, options?: {
259
- fromPosition?: number;
260
- limit?: number;
261
- streamId?: string;
262
- }): Promise<Record<string, SqlStorageValue>[]>;
263
- getEventsPaginated(options: {
264
- afterPosition?: number;
265
- limit?: number;
266
- streamId?: string;
267
- eventType?: string;
268
- }): Promise<{
269
- events: Record<string, SqlStorageValue>[];
270
- hasMore: boolean;
271
- nextPosition: SqlStorageValue | undefined;
1399
+ /**
1400
+ * Initializes the event store with a name
1401
+ * @param eventStoreID - The ID to assign to this event store
1402
+ */
1403
+ initialize(eventStoreID: string): void;
1404
+ /**
1405
+ * Appends events to a stream with optimistic concurrency control
1406
+ * @param streamId - The unique identifier for the stream
1407
+ * @param events - Array of events to append
1408
+ * @param options - Optional parameters for append operation
1409
+ * @returns Promise resolving to the next expected version and last global position
1410
+ * @throws Error if stream id is missing or events array is empty
1411
+ */
1412
+ appendToStream(streamId: string, events: Event[], options?: AppendToStreamOptions<number>): Promise<{
1413
+ nextExpectedStreamVersion: number;
1414
+ lastGlobalPosition: number;
272
1415
  }>;
273
- getEventsByTransactionId(transactionId: string): Promise<Record<string, SqlStorageValue>[]>;
274
- getEventCounts(): Promise<Record<string, SqlStorageValue>[]>;
275
- getEventTypeDistribution(streamId?: string): Promise<Record<string, SqlStorageValue>[]>;
276
- getEventsInTimeAndPositionRange(options: {
277
- startTime?: Date;
278
- endTime?: Date;
279
- minPosition?: number;
280
- maxPosition?: number;
281
- streamId?: string;
282
- limit?: number;
283
- }): Promise<Record<string, SqlStorageValue>[]>;
284
- getEventStatistics(windowStart: Date, windowEnd: Date): Promise<Record<string, SqlStorageValue>>;
285
- getEventsAfterPosition(position: number, limit?: number): Promise<Record<string, SqlStorageValue>[]>;
286
- getStreamEvents(streamId: string, options?: {
287
- fromPosition?: number;
288
- toPosition?: number;
289
- limit?: number;
290
- }): Promise<Record<string, SqlStorageValue>[]>;
291
- getEventsByTimeRange(startTime: Date, endTime: Date, limit?: number): Promise<Record<string, SqlStorageValue>[]>;
292
- getLatestEvents(limit?: number): Promise<Record<string, SqlStorageValue>[]>;
293
- getStreamPositionRange(streamId: string): Promise<Record<string, SqlStorageValue>>;
294
- getDatabaseSize(): number;
1416
+ /**
1417
+ * Reads events from a stream
1418
+ * @param streamId - The unique identifier for the stream
1419
+ * @param options - Optional parameters for read operation
1420
+ * @returns Promise resolving to the stream's events and metadata
1421
+ * @throws Error if stream id is missing
1422
+ */
1423
+ readStream(streamId: string, options?: ReadStreamOptions): Promise<{
1424
+ currentStreamVersion: number;
1425
+ events: ReadEvent[];
1426
+ streamExists: boolean;
1427
+ }>;
1428
+ /**
1429
+ * Gets the id of this event store instance
1430
+ * @returns The configured id of the event store
1431
+ */
1432
+ getEventStoreId(): string;
1433
+ /**
1434
+ * Maps a database row to an event object
1435
+ * @param row - The database row containing event data
1436
+ * @returns A properly formatted event object
1437
+ * @private
1438
+ */
1439
+ private mapRowToEvent;
1440
+ /**
1441
+ * Gets the current version of a stream
1442
+ * @param streamId - The stream to get the version for
1443
+ * @returns The current version number of the stream
1444
+ * @private
1445
+ */
1446
+ private getStreamVersion;
1447
+ /**
1448
+ * Gets information about a stream
1449
+ * @param streamId - The stream to get information for
1450
+ * @returns Stream metadata and state information
1451
+ * @private
1452
+ */
1453
+ private getStreamInfo;
1454
+ /**
1455
+ * Gets the type of a stream from its ID or metadata
1456
+ * @param streamId - The stream to get the type for
1457
+ * @returns The determined stream type
1458
+ * @private
1459
+ */
1460
+ private getStreamType;
1461
+ /**
1462
+ * Creates an event record for storage
1463
+ * @param event - The event to create a record for
1464
+ * @param streamId - The stream the event belongs to
1465
+ * @param position - The position in the stream
1466
+ * @returns A formatted event record
1467
+ * @private
1468
+ */
1469
+ private createEventRecord;
1470
+ /**
1471
+ * Inserts events into the database
1472
+ * @param events - The events to insert
1473
+ * @returns The last global position after insertion
1474
+ * @private
1475
+ */
1476
+ private insertEvents;
1477
+ /**
1478
+ * Reads archived events from R2 storage
1479
+ * @param streamId - The stream to read archived events from
1480
+ * @param fromPosition - Starting position to read from
1481
+ * @param toPosition - Ending position to read to
1482
+ * @returns Array of archived events
1483
+ * @private
1484
+ */
1485
+ private readArchivedEvents;
1486
+ /**
1487
+ * Queues events for processing by the event bus
1488
+ * @param streamId - The stream the events belong to
1489
+ * @param events - The events to queue
1490
+ * @private
1491
+ */
1492
+ private queueEventsForEventBus;
1493
+ /**
1494
+ * Processes events that are pending publication to the event bus
1495
+ * @private
1496
+ */
1497
+ private processPendingEventBusMessages;
1498
+ private getDatabaseSizeInMB;
1499
+ private getStoragePressureLevel;
1500
+ private checkDatabaseSize;
1501
+ private getNextCheckDelay;
1502
+ private checkStreamsForArchiving;
1503
+ /**
1504
+ * Gets archiving parameters based on storage pressure level
1505
+ * @param pressureLevel - Current storage pressure level
1506
+ * @returns Parameters for archiving operations
1507
+ * @private
1508
+ */
1509
+ private getArchivingParameters;
1510
+ /**
1511
+ * Calculates the batch size for archiving based on pressure level
1512
+ * @param availableEvents - Number of events available for archiving
1513
+ * @param pressureLevel - Current storage pressure level
1514
+ * @returns Number of events to archive in this batch
1515
+ * @private
1516
+ */
1517
+ private calculateBatchSize;
1518
+ /**
1519
+ * Archives a stream from fromPosition to toPosition
1520
+ * @param streamId - The stream to archive
1521
+ * @param fromPosition - Starting position to archive from
1522
+ * @param toPosition - Ending position to archive to
1523
+ * @private
1524
+ */
1525
+ private archiveStream;
1526
+ /**
1527
+ * Reads events for archiving from the database
1528
+ * @param streamId - The stream to read events from
1529
+ * @param fromPosition - Starting position to read from
1530
+ * @param toPosition - Ending position to read to
1531
+ * @param limit - Maximum number of events to read
1532
+ * @returns Array of events to archive
1533
+ * @private
1534
+ */
1535
+ private readEventsForArchiving;
1536
+ /**
1537
+ * Updates stream metadata with archive information
1538
+ * @param streamId - The stream being archived
1539
+ * @param fromPosition - Starting position of the archive
1540
+ * @param toPosition - Ending position of the archive
1541
+ * @param archiveKey - Key where the archive is stored
1542
+ * @private
1543
+ */
1544
+ private updateStreamArchiveMetadata;
1545
+ /**
1546
+ * Prunes archived events that have been safely stored in R2
1547
+ * @param isEmergency - Whether this is an emergency pruning operation
1548
+ * @private
1549
+ */
1550
+ private pruneArchivedEvents;
1551
+ /**
1552
+ * Emergency pruning of oldest events regardless of archive status
1553
+ * @private
1554
+ */
1555
+ private emergencyPruneOldestEvents;
1556
+ /**
1557
+ * Emergency archive method - simplified for speed
1558
+ * @param streamId - The stream to archive
1559
+ * @param fromPosition - Starting position to archive from
1560
+ * @param toPosition - Ending position to archive to
1561
+ * @private
1562
+ */
1563
+ private emergencyArchiveEvents;
1564
+ /**
1565
+ * Notifies subscribers when a stream is archived
1566
+ * @param streamId - The archived stream
1567
+ * @param fromPosition - Starting position of the archive
1568
+ * @param toPosition - Ending position of the archive
1569
+ * @param archiveKey - Key where the archive is stored
1570
+ * @private
1571
+ */
1572
+ private notifyStreamArchived;
1573
+ /**
1574
+ * Gets current metrics for this event store
1575
+ * @returns Current metrics including size, pressure, and event counts
1576
+ */
1577
+ getMetrics(): Promise<{
1578
+ database_size_mb: number;
1579
+ pressure_level: string;
1580
+ total_streams: number;
1581
+ total_events: number;
1582
+ archived_events: number;
1583
+ pending_events: number;
1584
+ }>;
1585
+ /**
1586
+ * Enhanced alarm handler for processing async work
1587
+ */
1588
+ alarm(): Promise<void>;
1589
+ /**
1590
+ * Schedules asynchronous work based on current system state
1591
+ * @private
1592
+ */
1593
+ private scheduleAsyncWork;
1594
+ /**
1595
+ * Checks if there is any non-event-bus related work to be done
1596
+ * @returns Whether there is other work pending
1597
+ * @private
1598
+ */
1599
+ private hasOtherWorkToDo;
295
1600
  }
296
1601
 
297
1602
  declare class EventStoreManagerDurableObject extends DurableObject<Env> {
298
1603
  sql: SqlStorage;
299
1604
  constructor(ctx: DurableObjectState, env: Env);
1605
+ private scheduleMetricsCollection;
300
1606
  private initializeTables;
301
- createEventStore(eventStoreName: string): Promise<{
1607
+ createEventStore(eventStoreName: string, description?: string, settings?: {
1608
+ retentionPeriodDays?: number;
1609
+ maxStreamSizeBytes?: number;
1610
+ }): Promise<{
302
1611
  eventStoreID: string;
303
1612
  eventStoreName: string;
304
1613
  eventStoreDurableObjectID: string;
305
1614
  eventBusDurableObjectID: string;
306
- eventGlobalIndexDurableObjectID: string;
1615
+ description?: string;
1616
+ settings?: {
1617
+ retentionPeriodDays?: number;
1618
+ maxStreamSizeBytes?: number;
1619
+ };
1620
+ created: string;
307
1621
  }>;
308
- getEventStoreInfo(eventStoreName: string): {
1622
+ getEventStoreInfo(eventStoreId: string, options?: {
1623
+ includeDeleted?: boolean;
1624
+ }): {
309
1625
  eventStoreID: string;
310
1626
  eventStoreName: string;
311
1627
  eventStoreDurableObjectID: string;
312
1628
  eventBusDurableObjectID: string;
313
- eventGlobalIndexDurableObjectID: string;
314
- };
315
- getEventStoreDatabaseSizes(eventStoreName: string): Promise<{
1629
+ description?: string;
1630
+ settings?: {
1631
+ retentionPeriodDays?: number;
1632
+ maxStreamSizeBytes?: number;
1633
+ };
1634
+ created: string;
1635
+ } | null;
1636
+ listEventStores(options: {
1637
+ limit?: number;
1638
+ offset?: number;
1639
+ namePrefix?: string;
1640
+ }): Promise<{
1641
+ eventStores: Array<{
1642
+ eventStoreID: string;
1643
+ eventStoreName: string;
1644
+ eventStoreDurableObjectID: string;
1645
+ eventBusDurableObjectID: string;
1646
+ description?: string;
1647
+ settings?: {
1648
+ retentionPeriodDays?: number;
1649
+ maxStreamSizeBytes?: number;
1650
+ };
1651
+ created: string;
1652
+ }>;
1653
+ totalCount: number;
1654
+ }>;
1655
+ getStreamStats(eventStoreId: string): Promise<{
1656
+ count: number;
1657
+ totalEvents: number;
1658
+ }>;
1659
+ getDatabaseSizes(eventStoreId: string): Promise<{
316
1660
  eventStoreDatabaseSize: number;
317
1661
  eventBusDatabaseSize: number;
318
- eventGlobalIndexDatabaseSize: number;
1662
+ totalSize: number;
319
1663
  }>;
320
- }
321
-
322
- // Generated by Wrangler by running `wrangler types`
323
-
324
- interface Env {
325
- EVENT_STORE_MANAGER_DO: DurableObjectNamespace<
326
- EventStoreManagerDurableObject
327
- >;
328
- EVENT_STORE_DO: DurableObjectNamespace<
329
- EventStoreDurableObject
330
- >;
331
- EVENT_BUS_DO: DurableObjectNamespace<
332
- EventBusDurableObject
333
- >;
334
- EVENT_GLOBAL_INDEX_DO: DurableObjectNamespace<
335
- EventGlobalIndexDurableObject
336
- >;
337
- EVENT_STREAM_DO: DurableObjectNamespace<
338
- EventStreamDurableObject
339
- >;
340
- WS_MANAGER_DO: DurableObjectNamespace<
341
- WebSocketManagerDurableObject
342
- >;
343
- }
344
-
345
- declare const getDOEventStoreManagement: (environmentName: string, env: Env) => {
346
- createEventStore: (eventStoreName: string) => Promise<{
347
- eventStoreID: string;
348
- eventStoreName: string;
349
- eventStoreDurableObjectID: string;
350
- eventBusDurableObjectID: string;
351
- eventGlobalIndexDurableObjectID: string;
352
- } & Disposable>;
353
- getEventStoreInfo: (eventStoreName: string) => Promise<{
1664
+ fetch(request: Request): Promise<Response>;
1665
+ private handleArchiveCandidates;
1666
+ private handleStorageStats;
1667
+ private handleRunArchive;
1668
+ private handleArchiveStatus;
1669
+ /**
1670
+ * Helper method to get or create event store stats table
1671
+ */
1672
+ private initEventStoreStats;
1673
+ /**
1674
+ * Update stats for a specific event store
1675
+ */
1676
+ updateEventStoreStats(eventStoreName: string, stats: {
1677
+ databaseSizeMB: number;
1678
+ totalEvents: number;
1679
+ archivedEvents: number;
1680
+ lastEventTimestamp?: string;
1681
+ }): Promise<void>;
1682
+ /**
1683
+ * Record an archive operation
1684
+ */
1685
+ recordArchiveOperation(eventStoreName: string, operation: {
1686
+ archivedCount: number;
1687
+ fromPosition: number;
1688
+ toPosition: number;
1689
+ isEmergency: boolean;
1690
+ }): Promise<void>;
1691
+ /**
1692
+ * Periodic alarm handler that collects metrics from all event stores
1693
+ */
1694
+ alarm(): Promise<void>;
1695
+ softDeleteEventStore(eventStoreId: string): Promise<void>;
1696
+ updateEventStoreSettings(eventStoreId: string, updates: {
1697
+ description?: string;
1698
+ settings?: {
1699
+ retentionPeriodDays?: number;
1700
+ maxStreamSizeBytes?: number;
1701
+ };
1702
+ }): Promise<{
354
1703
  eventStoreID: string;
355
1704
  eventStoreName: string;
356
1705
  eventStoreDurableObjectID: string;
357
1706
  eventBusDurableObjectID: string;
358
- eventGlobalIndexDurableObjectID: string;
359
- } & Disposable>;
360
- getEventStoreDatabaseSizes: (eventStoreName: string) => Promise<{
361
- eventStoreDatabaseSize: number;
362
- eventBusDatabaseSize: number;
363
- eventGlobalIndexDatabaseSize: number;
364
- } & Disposable>;
365
- };
366
-
367
- declare const getDOEventStore: (eventStoreId: string, env: Env) => EventStore;
368
-
369
- declare const getDOEventBus: (eventBusId: string, env: Env) => {
370
- subscribe: (eventFilter: EventFilter, subscriberId: string, subscription: SubscriberTypeConfig) => Promise<void>;
371
- unsubscribe: (eventFilter: EventFilter, subscriberId: string) => Promise<void>;
372
- };
1707
+ description?: string;
1708
+ settings?: {
1709
+ retentionPeriodDays?: number;
1710
+ maxStreamSizeBytes?: number;
1711
+ };
1712
+ created: string;
1713
+ }>;
1714
+ }
373
1715
 
374
- interface EventStoreWebSocketRouteConfig {
375
- managerId: string;
376
- path?: string;
1716
+ interface ConnectionListOptions {
1717
+ limit?: number;
1718
+ offset?: number;
1719
+ clientId?: string;
1720
+ }
1721
+ interface ConnectionListResult {
1722
+ connections: Array<{
1723
+ connectionId: string;
1724
+ clientId: string;
1725
+ connectedAt: string;
1726
+ ipAddress?: string;
1727
+ userAgent?: string;
1728
+ filter?: string;
1729
+ }>;
1730
+ totalCount: number;
1731
+ eventStoreId: string;
1732
+ }
1733
+ interface CloseConnectionResult {
1734
+ success: boolean;
1735
+ message: string;
1736
+ connectionsClosedCount: number;
1737
+ }
1738
+ declare class WebSocketManagerDurableObject extends DurableObject<Env> {
1739
+ sql: SqlStorage;
1740
+ constructor(ctx: DurableObjectState, env: Env);
1741
+ private initializeTables;
1742
+ initialize(eventStoreID: string): Promise<void>;
1743
+ private subscribeToEventStore;
1744
+ fetch(request: Request): Promise<Response>;
1745
+ private findWebSocketsByClientId;
1746
+ listConnections(options?: ConnectionListOptions): Promise<ConnectionListResult>;
1747
+ closeClientConnections(clientId: string, reason?: string): Promise<CloseConnectionResult>;
1748
+ private matchEventWithFilter;
1749
+ deliverEventToClient(clientId: string, event: EventMessage): Promise<void>;
1750
+ broadcastEvent(event: EventMessage): Promise<void>;
1751
+ webSocketClose(ws: WebSocket, _code: number, reason: string, _wasClean: boolean): Promise<void>;
377
1752
  }
378
- declare function createEventStoreWebSocketRoute(config: EventStoreWebSocketRouteConfig): {
379
- app: OpenAPIHono<{
380
- Bindings: Env;
381
- }, {}, "/">;
382
- getManagerId: () => string;
383
- };
384
1753
 
385
1754
  declare const routes: hono_hono_base.HonoBase<hono.Env, hono_types.MergeSchemaPath<{}, "/api"> & {
386
1755
  docs: {
@@ -405,8 +1774,21 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, hono_types.MergeSchemaPa
405
1774
  status: hono_utils_http_status.StatusCode;
406
1775
  };
407
1776
  };
1777
+ } & {
1778
+ "/api/webhook-test": {
1779
+ $post: {
1780
+ input: {};
1781
+ output: {
1782
+ status: string;
1783
+ received_at: string;
1784
+ event: any;
1785
+ };
1786
+ outputFormat: "json";
1787
+ status: hono_utils_http_status.ContentfulStatusCode;
1788
+ };
1789
+ };
408
1790
  }, "/api">;
409
1791
 
410
1792
  type AppType = typeof routes;
411
1793
 
412
- export { type AppType, type BaseSubscriberConfig, type CloudflareWorkflowConfig, type DurableObjectConfig, EventBusDurableObject, type EventFilter, EventGlobalIndexDurableObject, EventStoreDurableObject, type Env as EventStoreEnv, EventStoreManagerDurableObject, EventStreamDurableObject, type EventType, type QueueConfig, SubscriberType, WebSocketManagerDurableObject, type WebhookConfig, type WildcardPattern, createEventStoreWebSocketRoute, routes as default, getDOEventBus, getDOEventStore, getDOEventStoreManagement };
1794
+ export { type AppType, type BaseSubscriberConfig, type CloudflareWorkflowConfig, type DurableObjectConfig, EventBusAPI, EventBusDurableObject, type EventFilter, EventStoreAPI, EventStoreDurableObject, EventStoreManagerDurableObject, type EventType, ManagementAPI, type QueueConfig, SubscriberType, WebSocketManagerDurableObject, WebSocketsAPI, type WebhookConfig, type WildcardPattern, routes as default };