@delta-base/core 0.0.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,129 +2,1176 @@ 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
+ }, "strip", z.ZodTypeAny, {
427
+ eventId: string;
428
+ streamPosition: number;
429
+ streamName: string;
430
+ globalPosition: number;
431
+ }, {
432
+ eventId: string;
433
+ streamPosition: number;
434
+ streamName: string;
435
+ globalPosition: number;
436
+ }>>;
437
+ }>, "strip", z.ZodTypeAny, {
438
+ type: string;
439
+ data: Record<string, any>;
440
+ metadata?: {
441
+ eventId: string;
442
+ streamPosition: number;
443
+ streamName: string;
444
+ globalPosition: number;
445
+ } | undefined;
446
+ }, {
447
+ type: string;
448
+ data: Record<string, any>;
449
+ metadata?: {
450
+ eventId: string;
451
+ streamPosition: number;
452
+ streamName: string;
453
+ globalPosition: number;
454
+ } | undefined;
455
+ }>;
456
+ const ReadStreamResponseSchema: z.ZodObject<{
457
+ events: z.ZodArray<z.ZodObject<z.objectUtil.extendShape<{
458
+ type: z.ZodString;
459
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
460
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
461
+ }, {
462
+ metadata: z.ZodOptional<z.ZodObject<{
463
+ eventId: z.ZodString;
464
+ streamPosition: z.ZodNumber;
465
+ streamName: z.ZodString;
466
+ globalPosition: z.ZodNumber;
467
+ }, "strip", z.ZodTypeAny, {
468
+ eventId: string;
469
+ streamPosition: number;
470
+ streamName: string;
471
+ globalPosition: number;
472
+ }, {
473
+ eventId: string;
474
+ streamPosition: number;
475
+ streamName: string;
476
+ globalPosition: number;
477
+ }>>;
478
+ }>, "strip", z.ZodTypeAny, {
479
+ type: string;
480
+ data: Record<string, any>;
481
+ metadata?: {
482
+ eventId: string;
483
+ streamPosition: number;
484
+ streamName: string;
485
+ globalPosition: number;
486
+ } | undefined;
487
+ }, {
488
+ type: string;
489
+ data: Record<string, any>;
490
+ metadata?: {
491
+ eventId: string;
492
+ streamPosition: number;
493
+ streamName: string;
494
+ globalPosition: number;
495
+ } | undefined;
496
+ }>, "many">;
497
+ currentStreamVersion: z.ZodNumber;
498
+ }, "strip", z.ZodTypeAny, {
499
+ events: {
500
+ type: string;
501
+ data: Record<string, any>;
502
+ metadata?: {
503
+ eventId: string;
504
+ streamPosition: number;
505
+ streamName: string;
506
+ globalPosition: number;
507
+ } | undefined;
508
+ }[];
509
+ currentStreamVersion: number;
510
+ }, {
511
+ events: {
512
+ type: string;
513
+ data: Record<string, any>;
514
+ metadata?: {
515
+ eventId: string;
516
+ streamPosition: number;
517
+ streamName: string;
518
+ globalPosition: number;
519
+ } | undefined;
520
+ }[];
521
+ currentStreamVersion: number;
522
+ }>;
523
+ const routes: OpenAPIHono<{
524
+ Bindings: Env;
525
+ }, {}, "/">;
526
+ }
527
+
528
+ declare namespace EventBusAPI {
529
+ const routes: OpenAPIHono<{
530
+ Bindings: Env;
531
+ }, {}, "/">;
532
+ const SubscriberTypeEnum: z.ZodEnum<["durable_object", "webhook", "queue", "cloudflare_workflow", "websocket"]>;
533
+ const SubscriptionStatusEnum: z.ZodEnum<["ACTIVE", "SUSPENDED", "ERROR", "INITIALIZING", "DELETED"]>;
534
+ const SubscriptionRequestSchema: z.ZodObject<{
535
+ 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">]>;
536
+ subscriberId: z.ZodOptional<z.ZodString>;
537
+ subscriber: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
538
+ type: z.ZodLiteral<"durable_object">;
539
+ config: z.ZodObject<z.objectUtil.extendShape<{
540
+ retryPolicy: z.ZodOptional<z.ZodObject<{
541
+ maxAttempts: z.ZodNumber;
542
+ backoffMinutes: z.ZodNumber;
543
+ }, "strip", z.ZodTypeAny, {
544
+ maxAttempts: number;
545
+ backoffMinutes: number;
546
+ }, {
547
+ maxAttempts: number;
548
+ backoffMinutes: number;
549
+ }>>;
550
+ }, {
551
+ namespace: z.ZodString;
552
+ id: z.ZodString;
553
+ }>, "strip", z.ZodTypeAny, {
554
+ namespace: string;
555
+ id: string;
556
+ retryPolicy?: {
557
+ maxAttempts: number;
558
+ backoffMinutes: number;
559
+ } | undefined;
560
+ }, {
561
+ namespace: string;
562
+ id: string;
563
+ retryPolicy?: {
564
+ maxAttempts: number;
565
+ backoffMinutes: number;
566
+ } | undefined;
567
+ }>;
568
+ }, "strip", z.ZodTypeAny, {
569
+ type: "durable_object";
570
+ config: {
571
+ namespace: string;
572
+ id: string;
573
+ retryPolicy?: {
574
+ maxAttempts: number;
575
+ backoffMinutes: number;
576
+ } | undefined;
577
+ };
578
+ }, {
579
+ type: "durable_object";
580
+ config: {
581
+ namespace: string;
582
+ id: string;
583
+ retryPolicy?: {
584
+ maxAttempts: number;
585
+ backoffMinutes: number;
586
+ } | undefined;
587
+ };
588
+ }>, z.ZodObject<{
589
+ type: z.ZodLiteral<"webhook">;
590
+ config: z.ZodObject<z.objectUtil.extendShape<{
591
+ retryPolicy: z.ZodOptional<z.ZodObject<{
592
+ maxAttempts: z.ZodNumber;
593
+ backoffMinutes: z.ZodNumber;
594
+ }, "strip", z.ZodTypeAny, {
595
+ maxAttempts: number;
596
+ backoffMinutes: number;
597
+ }, {
598
+ maxAttempts: number;
599
+ backoffMinutes: number;
600
+ }>>;
601
+ }, {
602
+ url: z.ZodString;
603
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
604
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
605
+ }>, "strip", z.ZodTypeAny, {
606
+ url: string;
607
+ headers?: Record<string, string> | undefined;
608
+ retryPolicy?: {
609
+ maxAttempts: number;
610
+ backoffMinutes: number;
611
+ } | undefined;
612
+ timeoutMs?: number | undefined;
613
+ }, {
614
+ url: string;
615
+ headers?: Record<string, string> | undefined;
616
+ retryPolicy?: {
617
+ maxAttempts: number;
618
+ backoffMinutes: number;
619
+ } | undefined;
620
+ timeoutMs?: number | undefined;
621
+ }>;
622
+ }, "strip", z.ZodTypeAny, {
623
+ type: "webhook";
624
+ config: {
625
+ url: string;
626
+ headers?: Record<string, string> | undefined;
627
+ retryPolicy?: {
628
+ maxAttempts: number;
629
+ backoffMinutes: number;
630
+ } | undefined;
631
+ timeoutMs?: number | undefined;
632
+ };
633
+ }, {
634
+ type: "webhook";
635
+ config: {
636
+ url: string;
637
+ headers?: Record<string, string> | undefined;
638
+ retryPolicy?: {
639
+ maxAttempts: number;
640
+ backoffMinutes: number;
641
+ } | undefined;
642
+ timeoutMs?: number | undefined;
643
+ };
644
+ }>, z.ZodObject<{
645
+ type: z.ZodLiteral<"queue">;
646
+ config: z.ZodObject<z.objectUtil.extendShape<{
647
+ retryPolicy: z.ZodOptional<z.ZodObject<{
648
+ maxAttempts: z.ZodNumber;
649
+ backoffMinutes: z.ZodNumber;
650
+ }, "strip", z.ZodTypeAny, {
651
+ maxAttempts: number;
652
+ backoffMinutes: number;
653
+ }, {
654
+ maxAttempts: number;
655
+ backoffMinutes: number;
656
+ }>>;
657
+ }, {
658
+ queueName: z.ZodString;
659
+ region: z.ZodOptional<z.ZodString>;
660
+ batchSize: z.ZodOptional<z.ZodNumber>;
661
+ }>, "strip", z.ZodTypeAny, {
662
+ queueName: string;
663
+ retryPolicy?: {
664
+ maxAttempts: number;
665
+ backoffMinutes: number;
666
+ } | undefined;
667
+ region?: string | undefined;
668
+ batchSize?: number | undefined;
669
+ }, {
670
+ queueName: string;
671
+ retryPolicy?: {
672
+ maxAttempts: number;
673
+ backoffMinutes: number;
674
+ } | undefined;
675
+ region?: string | undefined;
676
+ batchSize?: number | undefined;
677
+ }>;
678
+ }, "strip", z.ZodTypeAny, {
679
+ type: "queue";
680
+ config: {
681
+ queueName: string;
682
+ retryPolicy?: {
683
+ maxAttempts: number;
684
+ backoffMinutes: number;
685
+ } | undefined;
686
+ region?: string | undefined;
687
+ batchSize?: number | undefined;
688
+ };
689
+ }, {
690
+ type: "queue";
691
+ config: {
692
+ queueName: string;
693
+ retryPolicy?: {
694
+ maxAttempts: number;
695
+ backoffMinutes: number;
696
+ } | undefined;
697
+ region?: string | undefined;
698
+ batchSize?: number | undefined;
699
+ };
700
+ }>, z.ZodObject<{
701
+ type: z.ZodLiteral<"cloudflare_workflow">;
702
+ config: z.ZodObject<z.objectUtil.extendShape<{
703
+ retryPolicy: z.ZodOptional<z.ZodObject<{
704
+ maxAttempts: z.ZodNumber;
705
+ backoffMinutes: z.ZodNumber;
706
+ }, "strip", z.ZodTypeAny, {
707
+ maxAttempts: number;
708
+ backoffMinutes: number;
709
+ }, {
710
+ maxAttempts: number;
711
+ backoffMinutes: number;
712
+ }>>;
713
+ }, {
714
+ bindingName: z.ZodString;
715
+ }>, "strip", z.ZodTypeAny, {
716
+ bindingName: string;
717
+ retryPolicy?: {
718
+ maxAttempts: number;
719
+ backoffMinutes: number;
720
+ } | undefined;
721
+ }, {
722
+ bindingName: string;
723
+ retryPolicy?: {
724
+ maxAttempts: number;
725
+ backoffMinutes: number;
726
+ } | undefined;
727
+ }>;
728
+ }, "strip", z.ZodTypeAny, {
729
+ type: "cloudflare_workflow";
730
+ config: {
731
+ bindingName: string;
732
+ retryPolicy?: {
733
+ maxAttempts: number;
734
+ backoffMinutes: number;
735
+ } | undefined;
736
+ };
737
+ }, {
738
+ type: "cloudflare_workflow";
739
+ config: {
740
+ bindingName: string;
741
+ retryPolicy?: {
742
+ maxAttempts: number;
743
+ backoffMinutes: number;
744
+ } | undefined;
745
+ };
746
+ }>, z.ZodObject<{
747
+ type: z.ZodLiteral<"websocket">;
748
+ config: z.ZodObject<z.objectUtil.extendShape<{
749
+ retryPolicy: z.ZodOptional<z.ZodObject<{
750
+ maxAttempts: z.ZodNumber;
751
+ backoffMinutes: z.ZodNumber;
752
+ }, "strip", z.ZodTypeAny, {
753
+ maxAttempts: number;
754
+ backoffMinutes: number;
755
+ }, {
756
+ maxAttempts: number;
757
+ backoffMinutes: number;
758
+ }>>;
759
+ }, {
760
+ managerId: z.ZodString;
761
+ }>, "strip", z.ZodTypeAny, {
762
+ managerId: string;
763
+ retryPolicy?: {
764
+ maxAttempts: number;
765
+ backoffMinutes: number;
766
+ } | undefined;
767
+ }, {
768
+ managerId: string;
769
+ retryPolicy?: {
770
+ maxAttempts: number;
771
+ backoffMinutes: number;
772
+ } | undefined;
773
+ }>;
774
+ }, "strip", z.ZodTypeAny, {
775
+ type: "websocket";
776
+ config: {
777
+ managerId: string;
778
+ retryPolicy?: {
779
+ maxAttempts: number;
780
+ backoffMinutes: number;
781
+ } | undefined;
782
+ };
783
+ }, {
784
+ type: "websocket";
785
+ config: {
786
+ managerId: string;
787
+ retryPolicy?: {
788
+ maxAttempts: number;
789
+ backoffMinutes: number;
790
+ } | undefined;
791
+ };
792
+ }>]>;
793
+ initialPosition: z.ZodDefault<z.ZodOptional<z.ZodEnum<["latest", "earliest"]>>>;
794
+ }, "strip", z.ZodTypeAny, {
795
+ eventFilter: string | string[];
796
+ subscriber: {
797
+ type: "durable_object";
798
+ config: {
799
+ namespace: string;
800
+ id: string;
801
+ retryPolicy?: {
802
+ maxAttempts: number;
803
+ backoffMinutes: number;
804
+ } | undefined;
805
+ };
806
+ } | {
807
+ type: "webhook";
808
+ config: {
809
+ url: string;
810
+ headers?: Record<string, string> | undefined;
811
+ retryPolicy?: {
812
+ maxAttempts: number;
813
+ backoffMinutes: number;
814
+ } | undefined;
815
+ timeoutMs?: number | undefined;
816
+ };
817
+ } | {
818
+ type: "queue";
819
+ config: {
820
+ queueName: string;
821
+ retryPolicy?: {
822
+ maxAttempts: number;
823
+ backoffMinutes: number;
824
+ } | undefined;
825
+ region?: string | undefined;
826
+ batchSize?: number | undefined;
827
+ };
828
+ } | {
829
+ type: "cloudflare_workflow";
830
+ config: {
831
+ bindingName: string;
832
+ retryPolicy?: {
833
+ maxAttempts: number;
834
+ backoffMinutes: number;
835
+ } | undefined;
836
+ };
837
+ } | {
838
+ type: "websocket";
839
+ config: {
840
+ managerId: string;
841
+ retryPolicy?: {
842
+ maxAttempts: number;
843
+ backoffMinutes: number;
844
+ } | undefined;
845
+ };
846
+ };
847
+ initialPosition: "latest" | "earliest";
848
+ subscriberId?: string | undefined;
849
+ }, {
850
+ eventFilter: string | string[];
851
+ subscriber: {
852
+ type: "durable_object";
853
+ config: {
854
+ namespace: string;
855
+ id: string;
856
+ retryPolicy?: {
857
+ maxAttempts: number;
858
+ backoffMinutes: number;
859
+ } | undefined;
860
+ };
861
+ } | {
862
+ type: "webhook";
863
+ config: {
864
+ url: string;
865
+ headers?: Record<string, string> | undefined;
866
+ retryPolicy?: {
867
+ maxAttempts: number;
868
+ backoffMinutes: number;
869
+ } | undefined;
870
+ timeoutMs?: number | undefined;
871
+ };
872
+ } | {
873
+ type: "queue";
874
+ config: {
875
+ queueName: string;
876
+ retryPolicy?: {
877
+ maxAttempts: number;
878
+ backoffMinutes: number;
879
+ } | undefined;
880
+ region?: string | undefined;
881
+ batchSize?: number | undefined;
882
+ };
883
+ } | {
884
+ type: "cloudflare_workflow";
885
+ config: {
886
+ bindingName: string;
887
+ retryPolicy?: {
888
+ maxAttempts: number;
889
+ backoffMinutes: number;
890
+ } | undefined;
891
+ };
892
+ } | {
893
+ type: "websocket";
894
+ config: {
895
+ managerId: string;
896
+ retryPolicy?: {
897
+ maxAttempts: number;
898
+ backoffMinutes: number;
899
+ } | undefined;
900
+ };
901
+ };
902
+ subscriberId?: string | undefined;
903
+ initialPosition?: "latest" | "earliest" | undefined;
904
+ }>;
905
+ const SubscriptionResponseSchema: z.ZodObject<{
906
+ subscriptionId: z.ZodString;
907
+ status: z.ZodEnum<["ACTIVE", "SUSPENDED", "ERROR", "INITIALIZING", "DELETED"]>;
908
+ statusDetails: z.ZodOptional<z.ZodObject<{
909
+ lastError: z.ZodOptional<z.ZodString>;
910
+ lastErrorAt: z.ZodOptional<z.ZodString>;
911
+ retryCount: z.ZodOptional<z.ZodNumber>;
912
+ nextRetryAt: z.ZodOptional<z.ZodString>;
913
+ }, "strip", z.ZodTypeAny, {
914
+ lastError?: string | undefined;
915
+ retryCount?: number | undefined;
916
+ lastErrorAt?: string | undefined;
917
+ nextRetryAt?: string | undefined;
918
+ }, {
919
+ lastError?: string | undefined;
920
+ retryCount?: number | undefined;
921
+ lastErrorAt?: string | undefined;
922
+ nextRetryAt?: string | undefined;
923
+ }>>;
924
+ eventStoreId: z.ZodString;
925
+ eventFilter: z.ZodString;
926
+ subscriberId: z.ZodString;
927
+ subscriberType: z.ZodEnum<["durable_object", "webhook", "queue", "cloudflare_workflow", "websocket"]>;
928
+ createdAt: z.ZodString;
929
+ updatedAt: z.ZodString;
930
+ lastProcessedEventGlobalPosition: z.ZodOptional<z.ZodNumber>;
931
+ }, "strip", z.ZodTypeAny, {
932
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
933
+ eventStoreId: string;
934
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
935
+ eventFilter: string;
936
+ subscriberId: string;
937
+ createdAt: string;
938
+ updatedAt: string;
939
+ subscriptionId: string;
940
+ statusDetails?: {
941
+ lastError?: string | undefined;
942
+ retryCount?: number | undefined;
943
+ lastErrorAt?: string | undefined;
944
+ nextRetryAt?: string | undefined;
945
+ } | undefined;
946
+ lastProcessedEventGlobalPosition?: number | undefined;
947
+ }, {
948
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
949
+ eventStoreId: string;
950
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
951
+ eventFilter: string;
952
+ subscriberId: string;
953
+ createdAt: string;
954
+ updatedAt: string;
955
+ subscriptionId: string;
956
+ statusDetails?: {
957
+ lastError?: string | undefined;
958
+ retryCount?: number | undefined;
959
+ lastErrorAt?: string | undefined;
960
+ nextRetryAt?: string | undefined;
961
+ } | undefined;
962
+ lastProcessedEventGlobalPosition?: number | undefined;
963
+ }>;
964
+ const SubscriptionListResponseSchema: z.ZodObject<{
965
+ subscriptions: z.ZodArray<z.ZodObject<{
966
+ subscriptionId: z.ZodString;
967
+ status: z.ZodEnum<["ACTIVE", "SUSPENDED", "ERROR", "INITIALIZING", "DELETED"]>;
968
+ statusDetails: z.ZodOptional<z.ZodObject<{
969
+ lastError: z.ZodOptional<z.ZodString>;
970
+ lastErrorAt: z.ZodOptional<z.ZodString>;
971
+ retryCount: z.ZodOptional<z.ZodNumber>;
972
+ nextRetryAt: z.ZodOptional<z.ZodString>;
973
+ }, "strip", z.ZodTypeAny, {
974
+ lastError?: string | undefined;
975
+ retryCount?: number | undefined;
976
+ lastErrorAt?: string | undefined;
977
+ nextRetryAt?: string | undefined;
978
+ }, {
979
+ lastError?: string | undefined;
980
+ retryCount?: number | undefined;
981
+ lastErrorAt?: string | undefined;
982
+ nextRetryAt?: string | undefined;
983
+ }>>;
984
+ eventStoreId: z.ZodString;
985
+ eventFilter: z.ZodString;
986
+ subscriberId: z.ZodString;
987
+ subscriberType: z.ZodEnum<["durable_object", "webhook", "queue", "cloudflare_workflow", "websocket"]>;
988
+ createdAt: z.ZodString;
989
+ updatedAt: z.ZodString;
990
+ lastProcessedEventGlobalPosition: z.ZodOptional<z.ZodNumber>;
991
+ }, "strip", z.ZodTypeAny, {
992
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
993
+ eventStoreId: string;
994
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
995
+ eventFilter: string;
996
+ subscriberId: string;
997
+ createdAt: string;
998
+ updatedAt: string;
999
+ subscriptionId: string;
1000
+ statusDetails?: {
1001
+ lastError?: string | undefined;
1002
+ retryCount?: number | undefined;
1003
+ lastErrorAt?: string | undefined;
1004
+ nextRetryAt?: string | undefined;
1005
+ } | undefined;
1006
+ lastProcessedEventGlobalPosition?: number | undefined;
1007
+ }, {
1008
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1009
+ eventStoreId: string;
1010
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1011
+ eventFilter: string;
1012
+ subscriberId: string;
1013
+ createdAt: string;
1014
+ updatedAt: string;
1015
+ subscriptionId: string;
1016
+ statusDetails?: {
1017
+ lastError?: string | undefined;
1018
+ retryCount?: number | undefined;
1019
+ lastErrorAt?: string | undefined;
1020
+ nextRetryAt?: string | undefined;
1021
+ } | undefined;
1022
+ lastProcessedEventGlobalPosition?: number | undefined;
1023
+ }>, "many">;
1024
+ totalCount: z.ZodNumber;
1025
+ }, "strip", z.ZodTypeAny, {
1026
+ totalCount: number;
1027
+ subscriptions: {
1028
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1029
+ eventStoreId: string;
1030
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1031
+ eventFilter: string;
1032
+ subscriberId: string;
1033
+ createdAt: string;
1034
+ updatedAt: string;
1035
+ subscriptionId: string;
1036
+ statusDetails?: {
1037
+ lastError?: string | undefined;
1038
+ retryCount?: number | undefined;
1039
+ lastErrorAt?: string | undefined;
1040
+ nextRetryAt?: string | undefined;
1041
+ } | undefined;
1042
+ lastProcessedEventGlobalPosition?: number | undefined;
1043
+ }[];
1044
+ }, {
1045
+ totalCount: number;
1046
+ subscriptions: {
1047
+ status: "ACTIVE" | "SUSPENDED" | "ERROR" | "INITIALIZING" | "DELETED";
1048
+ eventStoreId: string;
1049
+ subscriberType: "websocket" | "durable_object" | "webhook" | "queue" | "cloudflare_workflow";
1050
+ eventFilter: string;
1051
+ subscriberId: string;
1052
+ createdAt: string;
1053
+ updatedAt: string;
1054
+ subscriptionId: string;
1055
+ statusDetails?: {
1056
+ lastError?: string | undefined;
1057
+ retryCount?: number | undefined;
1058
+ lastErrorAt?: string | undefined;
1059
+ nextRetryAt?: string | undefined;
1060
+ } | undefined;
1061
+ lastProcessedEventGlobalPosition?: number | undefined;
1062
+ }[];
1063
+ }>;
1064
+ const SubscriptionErrorSchema: z.ZodObject<{
1065
+ error: z.ZodString;
1066
+ message: z.ZodString;
1067
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1068
+ }, "strip", z.ZodTypeAny, {
1069
+ error: string;
1070
+ message: string;
1071
+ details?: Record<string, any> | undefined;
1072
+ }, {
1073
+ error: string;
1074
+ message: string;
1075
+ details?: Record<string, any> | undefined;
1076
+ }>;
1077
+ }
1078
+
1079
+ declare namespace WebSocketsAPI {
1080
+ const WebSocketConnectionSchema: z.ZodObject<{
1081
+ connectionId: z.ZodString;
1082
+ clientId: z.ZodString;
1083
+ connectedAt: z.ZodString;
1084
+ ipAddress: z.ZodOptional<z.ZodString>;
1085
+ userAgent: z.ZodOptional<z.ZodString>;
1086
+ filter: z.ZodOptional<z.ZodString>;
1087
+ }, "strip", z.ZodTypeAny, {
1088
+ clientId: string;
1089
+ connectionId: string;
1090
+ connectedAt: string;
1091
+ filter?: string | undefined;
1092
+ ipAddress?: string | undefined;
1093
+ userAgent?: string | undefined;
1094
+ }, {
1095
+ clientId: string;
1096
+ connectionId: string;
1097
+ connectedAt: string;
1098
+ filter?: string | undefined;
1099
+ ipAddress?: string | undefined;
1100
+ userAgent?: string | undefined;
1101
+ }>;
1102
+ const WebSocketConnectionListResponseSchema: z.ZodObject<{
1103
+ connections: z.ZodArray<z.ZodObject<{
1104
+ connectionId: z.ZodString;
1105
+ clientId: z.ZodString;
1106
+ connectedAt: z.ZodString;
1107
+ ipAddress: z.ZodOptional<z.ZodString>;
1108
+ userAgent: z.ZodOptional<z.ZodString>;
1109
+ filter: z.ZodOptional<z.ZodString>;
1110
+ }, "strip", z.ZodTypeAny, {
1111
+ clientId: string;
1112
+ connectionId: string;
1113
+ connectedAt: string;
1114
+ filter?: string | undefined;
1115
+ ipAddress?: string | undefined;
1116
+ userAgent?: string | undefined;
1117
+ }, {
1118
+ clientId: string;
1119
+ connectionId: string;
1120
+ connectedAt: string;
1121
+ filter?: string | undefined;
1122
+ ipAddress?: string | undefined;
1123
+ userAgent?: string | undefined;
1124
+ }>, "many">;
1125
+ totalCount: z.ZodNumber;
1126
+ eventStoreId: z.ZodString;
1127
+ }, "strip", z.ZodTypeAny, {
1128
+ connections: {
1129
+ clientId: string;
1130
+ connectionId: string;
1131
+ connectedAt: string;
1132
+ filter?: string | undefined;
1133
+ ipAddress?: string | undefined;
1134
+ userAgent?: string | undefined;
1135
+ }[];
1136
+ totalCount: number;
1137
+ eventStoreId: string;
1138
+ }, {
1139
+ connections: {
1140
+ clientId: string;
1141
+ connectionId: string;
1142
+ connectedAt: string;
1143
+ filter?: string | undefined;
1144
+ ipAddress?: string | undefined;
1145
+ userAgent?: string | undefined;
1146
+ }[];
1147
+ totalCount: number;
1148
+ eventStoreId: string;
1149
+ }>;
1150
+ const ErrorResponseSchema: z.ZodObject<{
1151
+ error: z.ZodString;
1152
+ message: z.ZodString;
1153
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1154
+ }, "strip", z.ZodTypeAny, {
1155
+ error: string;
1156
+ message: string;
1157
+ details?: Record<string, any> | undefined;
1158
+ }, {
1159
+ error: string;
1160
+ message: string;
1161
+ details?: Record<string, any> | undefined;
120
1162
  }>;
121
- private waitForStreamVersion;
122
- private mergeAndDeduplicateEvents;
1163
+ const routes: OpenAPIHono<{
1164
+ Bindings: Env;
1165
+ }, {}, "/">;
123
1166
  }
124
1167
 
125
1168
  type WildcardPattern = '*' | `${string}.*` | `*.${string}` | `${string}.*${string}`;
126
1169
  type EventType = string;
127
1170
  type EventFilter = EventType | EventType[] | WildcardPattern;
1171
+ declare enum InitialPosition {
1172
+ LATEST = "latest",
1173
+ EARLIEST = "earliest"
1174
+ }
128
1175
  interface BaseSubscriberConfig {
129
1176
  retryPolicy?: {
130
1177
  maxAttempts: number;
@@ -189,24 +1236,64 @@ interface EventMessage {
189
1236
  transaction_id: string;
190
1237
  created: string;
191
1238
  }
1239
+ interface SubscriptionListOptions {
1240
+ subscriberType?: SubscriberType;
1241
+ eventFilter?: string;
1242
+ limit?: number;
1243
+ offset?: number;
1244
+ }
1245
+ declare enum SubscriptionStatus {
1246
+ ACTIVE = "ACTIVE",
1247
+ SUSPENDED = "SUSPENDED",
1248
+ ERROR = "ERROR",
1249
+ INITIALIZING = "INITIALIZING",
1250
+ DELETED = "DELETED"
1251
+ }
1252
+ interface StatusDetails {
1253
+ lastError?: string;
1254
+ lastErrorAt?: string;
1255
+ retryCount?: number;
1256
+ nextRetryAt?: string;
1257
+ reason?: string;
1258
+ }
1259
+ interface Subscription {
1260
+ id: string;
1261
+ eventFilter: string;
1262
+ subscriberId: string;
1263
+ subscriberType: SubscriberType;
1264
+ subscriberConfig: string;
1265
+ status: SubscriptionStatus;
1266
+ statusDetails?: StatusDetails;
1267
+ lastProcessedEventGlobalPosition: number;
1268
+ createdAt: string;
1269
+ updatedAt: string;
1270
+ }
192
1271
  declare class EventBusDurableObject extends DurableObject<Env$1> {
193
1272
  private readonly BATCH_SIZE;
194
1273
  private readonly RETRY_DELAY_HOURS;
195
1274
  sql: SqlStorage;
196
1275
  constructor(state: DurableObjectState, env: Env$1);
197
1276
  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>;
1277
+ initialize(eventStoreID: string): void;
1278
+ subscribe(eventFilter: EventFilter, subscriberId: string, subscription: SubscriberTypeConfig, initialPosition?: InitialPosition): Promise<void>;
1279
+ private validateSubscriberConfig;
1280
+ private updateSubscriptionStatus;
1281
+ unsubscribe(subscriberId: string): Promise<void>;
1282
+ getSubscriptions(options?: SubscriptionListOptions): Promise<Subscription[]>;
1283
+ getSubscriptionsCount(options?: Omit<SubscriptionListOptions, 'limit' | 'offset'>): Promise<number>;
1284
+ getSubscription(id: string): Promise<Subscription | null>;
1285
+ publish(events: {
1286
+ event_id: string;
1287
+ event_type: string;
1288
+ event_data: Record<string, unknown>;
1289
+ event_metadata: Record<string, unknown>;
1290
+ stream_id: string;
1291
+ stream_position: number;
1292
+ global_position: number;
1293
+ event_schema_version: string;
1294
+ transaction_id: string;
1295
+ created: string;
1296
+ }[]): Promise<void>;
210
1297
  private getMatchingSubscriptions;
211
1298
  private scheduleDelivery;
212
1299
  private processOutboxBatch;
@@ -215,6 +1302,7 @@ declare class EventBusDurableObject extends DurableObject<Env$1> {
215
1302
  private parseSubscription;
216
1303
  private markMessageAsProcessed;
217
1304
  private markMessageAsFailed;
1305
+ private markDeliveryAttempt;
218
1306
  private deliverEvent;
219
1307
  private logProcessingMetrics;
220
1308
  alarm(alarmInfo: AlarmInvocationInfo): Promise<void>;
@@ -222,165 +1310,434 @@ declare class EventBusDurableObject extends DurableObject<Env$1> {
222
1310
  private validateEventFilter;
223
1311
  }
224
1312
 
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
- }
1313
+ type Flavour<K, T> = K & {
1314
+ readonly __brand?: T;
1315
+ };
1316
+ type DefaultRecord = Record<string, unknown>;
1317
+ type Event<EventType extends string = string, EventData extends DefaultRecord = DefaultRecord, EventMetaData extends DefaultRecord = DefaultRecord> = Flavour<Readonly<{
1318
+ type: EventType;
1319
+ data: EventData;
1320
+ metadata?: EventMetaData;
1321
+ }>, 'Event'>;
1322
+ type EventTypeOf<T extends Event> = T['type'];
1323
+ type EventDataOf<T extends Event> = T['data'];
1324
+ type EventMetaDataOf<T extends Event> = T['metadata'];
1325
+ type CreateEventType<EventType extends string, EventData extends DefaultRecord, EventMetaData extends DefaultRecord | undefined> = Readonly<{
1326
+ type: EventType;
1327
+ data: EventData;
1328
+ metadata?: EventMetaData;
1329
+ }>;
1330
+ type ReadEvent<EventType extends Event = Event, EventMetaDataType extends EventMetaDataOf<EventType> & ReadEventMetadata = EventMetaDataOf<EventType> & ReadEventMetadata> = CreateEventType<EventTypeOf<EventType>, EventDataOf<EventType>, EventMetaDataType> & EventType & {
1331
+ metadata: EventMetaDataType;
1332
+ };
1333
+ type ReadEventMetadata = Readonly<{
1334
+ eventId: string;
1335
+ streamPosition: number;
1336
+ streamName: string;
1337
+ }>;
1338
+ type ExpectedStreamVersion<VersionType = DefaultStreamVersionType> = ExpectedStreamVersionWithValue<VersionType> | ExpectedStreamVersionGeneral;
1339
+ type ExpectedStreamVersionWithValue<VersionType = DefaultStreamVersionType> = Flavour<VersionType, 'StreamVersion'>;
1340
+ type ExpectedStreamVersionGeneral = Flavour<'STREAM_EXISTS' | 'STREAM_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK', 'StreamVersion'>;
1341
+ type DefaultStreamVersionType = number;
1342
+ type ReadStreamOptions<StreamVersion = DefaultStreamVersionType> = ({
1343
+ from: StreamVersion;
1344
+ } | {
1345
+ to: StreamVersion;
1346
+ } | {
1347
+ from: StreamVersion;
1348
+ maxCount?: DefaultStreamVersionType;
1349
+ } | {
1350
+ expectedStreamVersion: ExpectedStreamVersion<StreamVersion>;
1351
+ }) & {
1352
+ expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;
1353
+ };
1354
+ type AppendToStreamOptions<StreamVersion = DefaultStreamVersionType> = {
1355
+ expectedStreamVersion?: ExpectedStreamVersion<StreamVersion>;
1356
+ };
252
1357
 
253
- declare class EventGlobalIndexDurableObject extends DurableObject<Env> {
1358
+ /**
1359
+ * A durable object implementation of an event store.
1360
+ * Handles event persistence, archiving, and event bus integration.
1361
+ */
1362
+ declare class EventStoreDurableObject extends DurableObject<Env> {
254
1363
  sql: SqlStorage;
1364
+ /** Soft limit for database size (90% of 10GB) */
1365
+ private readonly SIZE_SOFT_LIMIT_MB;
1366
+ /** Hard limit for database size (95% of 10GB) */
1367
+ private readonly SIZE_HARD_LIMIT_MB;
1368
+ /** Emergency limit for database size (95% of 10GB) */
1369
+ private readonly SIZE_EMERGENCY_MB;
1370
+ /** Conversion factor from MB to bytes */
1371
+ private readonly MB_TO_BYTES;
1372
+ /** Number of events to store in each archive chunk */
1373
+ private readonly EVENTS_PER_ARCHIVE_CHUNK;
1374
+ /** Maximum batch size for emergency operations */
1375
+ private readonly MAX_EMERGENCY_BATCH_SIZE;
1376
+ /**
1377
+ * Creates a new instance of the EventStoreDurableObject
1378
+ * @param ctx - The durable object state
1379
+ * @param env - Environment variables and bindings
1380
+ */
255
1381
  constructor(ctx: DurableObjectState, env: Env);
1382
+ /**
1383
+ * Initializes the database tables required for the event store
1384
+ * @private
1385
+ */
256
1386
  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;
1387
+ /**
1388
+ * Initializes the event store with a name
1389
+ * @param eventStoreID - The ID to assign to this event store
1390
+ */
1391
+ initialize(eventStoreID: string): void;
1392
+ /**
1393
+ * Appends events to a stream with optimistic concurrency control
1394
+ * @param streamId - The unique identifier for the stream
1395
+ * @param events - Array of events to append
1396
+ * @param options - Optional parameters for append operation
1397
+ * @returns Promise resolving to the next expected version and last global position
1398
+ * @throws Error if stream id is missing or events array is empty
1399
+ */
1400
+ appendToStream(streamId: string, events: Event[], options?: AppendToStreamOptions<number>): Promise<{
1401
+ nextExpectedStreamVersion: number;
1402
+ lastGlobalPosition: number;
272
1403
  }>;
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;
1404
+ /**
1405
+ * Reads events from a stream
1406
+ * @param streamId - The unique identifier for the stream
1407
+ * @param options - Optional parameters for read operation
1408
+ * @returns Promise resolving to the stream's events and metadata
1409
+ * @throws Error if stream id is missing
1410
+ */
1411
+ readStream(streamId: string, options?: ReadStreamOptions): Promise<{
1412
+ currentStreamVersion: number;
1413
+ events: ReadEvent[];
1414
+ streamExists: boolean;
1415
+ }>;
1416
+ /**
1417
+ * Gets the id of this event store instance
1418
+ * @returns The configured id of the event store
1419
+ */
1420
+ getEventStoreId(): string;
1421
+ /**
1422
+ * Maps a database row to an event object
1423
+ * @param row - The database row containing event data
1424
+ * @returns A properly formatted event object
1425
+ * @private
1426
+ */
1427
+ private mapRowToEvent;
1428
+ /**
1429
+ * Gets the current version of a stream
1430
+ * @param streamId - The stream to get the version for
1431
+ * @returns The current version number of the stream
1432
+ * @private
1433
+ */
1434
+ private getStreamVersion;
1435
+ /**
1436
+ * Gets information about a stream
1437
+ * @param streamId - The stream to get information for
1438
+ * @returns Stream metadata and state information
1439
+ * @private
1440
+ */
1441
+ private getStreamInfo;
1442
+ /**
1443
+ * Gets the type of a stream from its ID or metadata
1444
+ * @param streamId - The stream to get the type for
1445
+ * @returns The determined stream type
1446
+ * @private
1447
+ */
1448
+ private getStreamType;
1449
+ /**
1450
+ * Creates an event record for storage
1451
+ * @param event - The event to create a record for
1452
+ * @param streamId - The stream the event belongs to
1453
+ * @param position - The position in the stream
1454
+ * @returns A formatted event record
1455
+ * @private
1456
+ */
1457
+ private createEventRecord;
1458
+ /**
1459
+ * Inserts events into the database
1460
+ * @param events - The events to insert
1461
+ * @returns The last global position after insertion
1462
+ * @private
1463
+ */
1464
+ private insertEvents;
1465
+ /**
1466
+ * Reads archived events from R2 storage
1467
+ * @param streamId - The stream to read archived events from
1468
+ * @param fromPosition - Starting position to read from
1469
+ * @param toPosition - Ending position to read to
1470
+ * @returns Array of archived events
1471
+ * @private
1472
+ */
1473
+ private readArchivedEvents;
1474
+ /**
1475
+ * Queues events for processing by the event bus
1476
+ * @param streamId - The stream the events belong to
1477
+ * @param events - The events to queue
1478
+ * @private
1479
+ */
1480
+ private queueEventsForEventBus;
1481
+ /**
1482
+ * Processes events that are pending publication to the event bus
1483
+ * @private
1484
+ */
1485
+ private processPendingEventBusMessages;
1486
+ private getDatabaseSizeInMB;
1487
+ private getStoragePressureLevel;
1488
+ private checkDatabaseSize;
1489
+ private getNextCheckDelay;
1490
+ private checkStreamsForArchiving;
1491
+ /**
1492
+ * Gets archiving parameters based on storage pressure level
1493
+ * @param pressureLevel - Current storage pressure level
1494
+ * @returns Parameters for archiving operations
1495
+ * @private
1496
+ */
1497
+ private getArchivingParameters;
1498
+ /**
1499
+ * Calculates the batch size for archiving based on pressure level
1500
+ * @param availableEvents - Number of events available for archiving
1501
+ * @param pressureLevel - Current storage pressure level
1502
+ * @returns Number of events to archive in this batch
1503
+ * @private
1504
+ */
1505
+ private calculateBatchSize;
1506
+ /**
1507
+ * Archives a stream from fromPosition to toPosition
1508
+ * @param streamId - The stream to archive
1509
+ * @param fromPosition - Starting position to archive from
1510
+ * @param toPosition - Ending position to archive to
1511
+ * @private
1512
+ */
1513
+ private archiveStream;
1514
+ /**
1515
+ * Reads events for archiving from the database
1516
+ * @param streamId - The stream to read events from
1517
+ * @param fromPosition - Starting position to read from
1518
+ * @param toPosition - Ending position to read to
1519
+ * @param limit - Maximum number of events to read
1520
+ * @returns Array of events to archive
1521
+ * @private
1522
+ */
1523
+ private readEventsForArchiving;
1524
+ /**
1525
+ * Updates stream metadata with archive information
1526
+ * @param streamId - The stream being archived
1527
+ * @param fromPosition - Starting position of the archive
1528
+ * @param toPosition - Ending position of the archive
1529
+ * @param archiveKey - Key where the archive is stored
1530
+ * @private
1531
+ */
1532
+ private updateStreamArchiveMetadata;
1533
+ /**
1534
+ * Prunes archived events that have been safely stored in R2
1535
+ * @param isEmergency - Whether this is an emergency pruning operation
1536
+ * @private
1537
+ */
1538
+ private pruneArchivedEvents;
1539
+ /**
1540
+ * Emergency pruning of oldest events regardless of archive status
1541
+ * @private
1542
+ */
1543
+ private emergencyPruneOldestEvents;
1544
+ /**
1545
+ * Emergency archive method - simplified for speed
1546
+ * @param streamId - The stream to archive
1547
+ * @param fromPosition - Starting position to archive from
1548
+ * @param toPosition - Ending position to archive to
1549
+ * @private
1550
+ */
1551
+ private emergencyArchiveEvents;
1552
+ /**
1553
+ * Notifies subscribers when a stream is archived
1554
+ * @param streamId - The archived stream
1555
+ * @param fromPosition - Starting position of the archive
1556
+ * @param toPosition - Ending position of the archive
1557
+ * @param archiveKey - Key where the archive is stored
1558
+ * @private
1559
+ */
1560
+ private notifyStreamArchived;
1561
+ /**
1562
+ * Gets current metrics for this event store
1563
+ * @returns Current metrics including size, pressure, and event counts
1564
+ */
1565
+ getMetrics(): Promise<{
1566
+ database_size_mb: number;
1567
+ pressure_level: string;
1568
+ total_streams: number;
1569
+ total_events: number;
1570
+ archived_events: number;
1571
+ pending_events: number;
1572
+ }>;
1573
+ /**
1574
+ * Enhanced alarm handler for processing async work
1575
+ */
1576
+ alarm(): Promise<void>;
1577
+ /**
1578
+ * Schedules asynchronous work based on current system state
1579
+ * @private
1580
+ */
1581
+ private scheduleAsyncWork;
1582
+ /**
1583
+ * Checks if there is any non-event-bus related work to be done
1584
+ * @returns Whether there is other work pending
1585
+ * @private
1586
+ */
1587
+ private hasOtherWorkToDo;
295
1588
  }
296
1589
 
297
1590
  declare class EventStoreManagerDurableObject extends DurableObject<Env> {
298
1591
  sql: SqlStorage;
299
1592
  constructor(ctx: DurableObjectState, env: Env);
1593
+ private scheduleMetricsCollection;
300
1594
  private initializeTables;
301
- createEventStore(eventStoreName: string): Promise<{
1595
+ createEventStore(eventStoreName: string, description?: string, settings?: {
1596
+ retentionPeriodDays?: number;
1597
+ maxStreamSizeBytes?: number;
1598
+ }): Promise<{
302
1599
  eventStoreID: string;
303
1600
  eventStoreName: string;
304
1601
  eventStoreDurableObjectID: string;
305
1602
  eventBusDurableObjectID: string;
306
- eventGlobalIndexDurableObjectID: string;
1603
+ description?: string;
1604
+ settings?: {
1605
+ retentionPeriodDays?: number;
1606
+ maxStreamSizeBytes?: number;
1607
+ };
1608
+ created: string;
307
1609
  }>;
308
- getEventStoreInfo(eventStoreName: string): {
1610
+ getEventStoreInfo(eventStoreId: string, options?: {
1611
+ includeDeleted?: boolean;
1612
+ }): {
309
1613
  eventStoreID: string;
310
1614
  eventStoreName: string;
311
1615
  eventStoreDurableObjectID: string;
312
1616
  eventBusDurableObjectID: string;
313
- eventGlobalIndexDurableObjectID: string;
314
- };
315
- getEventStoreDatabaseSizes(eventStoreName: string): Promise<{
1617
+ description?: string;
1618
+ settings?: {
1619
+ retentionPeriodDays?: number;
1620
+ maxStreamSizeBytes?: number;
1621
+ };
1622
+ created: string;
1623
+ } | null;
1624
+ listEventStores(options: {
1625
+ limit?: number;
1626
+ offset?: number;
1627
+ namePrefix?: string;
1628
+ }): Promise<{
1629
+ eventStores: Array<{
1630
+ eventStoreID: string;
1631
+ eventStoreName: string;
1632
+ eventStoreDurableObjectID: string;
1633
+ eventBusDurableObjectID: string;
1634
+ description?: string;
1635
+ settings?: {
1636
+ retentionPeriodDays?: number;
1637
+ maxStreamSizeBytes?: number;
1638
+ };
1639
+ created: string;
1640
+ }>;
1641
+ totalCount: number;
1642
+ }>;
1643
+ getStreamStats(eventStoreId: string): Promise<{
1644
+ count: number;
1645
+ totalEvents: number;
1646
+ }>;
1647
+ getDatabaseSizes(eventStoreId: string): Promise<{
316
1648
  eventStoreDatabaseSize: number;
317
1649
  eventBusDatabaseSize: number;
318
- eventGlobalIndexDatabaseSize: number;
1650
+ totalSize: number;
319
1651
  }>;
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<{
1652
+ fetch(request: Request): Promise<Response>;
1653
+ private handleArchiveCandidates;
1654
+ private handleStorageStats;
1655
+ private handleRunArchive;
1656
+ private handleArchiveStatus;
1657
+ /**
1658
+ * Helper method to get or create event store stats table
1659
+ */
1660
+ private initEventStoreStats;
1661
+ /**
1662
+ * Update stats for a specific event store
1663
+ */
1664
+ updateEventStoreStats(eventStoreName: string, stats: {
1665
+ databaseSizeMB: number;
1666
+ totalEvents: number;
1667
+ archivedEvents: number;
1668
+ lastEventTimestamp?: string;
1669
+ }): Promise<void>;
1670
+ /**
1671
+ * Record an archive operation
1672
+ */
1673
+ recordArchiveOperation(eventStoreName: string, operation: {
1674
+ archivedCount: number;
1675
+ fromPosition: number;
1676
+ toPosition: number;
1677
+ isEmergency: boolean;
1678
+ }): Promise<void>;
1679
+ /**
1680
+ * Periodic alarm handler that collects metrics from all event stores
1681
+ */
1682
+ alarm(): Promise<void>;
1683
+ softDeleteEventStore(eventStoreId: string): Promise<void>;
1684
+ updateEventStoreSettings(eventStoreId: string, updates: {
1685
+ description?: string;
1686
+ settings?: {
1687
+ retentionPeriodDays?: number;
1688
+ maxStreamSizeBytes?: number;
1689
+ };
1690
+ }): Promise<{
354
1691
  eventStoreID: string;
355
1692
  eventStoreName: string;
356
1693
  eventStoreDurableObjectID: string;
357
1694
  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
- };
1695
+ description?: string;
1696
+ settings?: {
1697
+ retentionPeriodDays?: number;
1698
+ maxStreamSizeBytes?: number;
1699
+ };
1700
+ created: string;
1701
+ }>;
1702
+ }
373
1703
 
374
- interface EventStoreWebSocketRouteConfig {
375
- managerId: string;
376
- path?: string;
1704
+ interface ConnectionListOptions {
1705
+ limit?: number;
1706
+ offset?: number;
1707
+ clientId?: string;
1708
+ }
1709
+ interface ConnectionListResult {
1710
+ connections: Array<{
1711
+ connectionId: string;
1712
+ clientId: string;
1713
+ connectedAt: string;
1714
+ ipAddress?: string;
1715
+ userAgent?: string;
1716
+ filter?: string;
1717
+ }>;
1718
+ totalCount: number;
1719
+ eventStoreId: string;
1720
+ }
1721
+ interface CloseConnectionResult {
1722
+ success: boolean;
1723
+ message: string;
1724
+ connectionsClosedCount: number;
1725
+ }
1726
+ declare class WebSocketManagerDurableObject extends DurableObject<Env> {
1727
+ sql: SqlStorage;
1728
+ constructor(ctx: DurableObjectState, env: Env);
1729
+ private initializeTables;
1730
+ initialize(eventStoreID: string): Promise<void>;
1731
+ private subscribeToEventStore;
1732
+ fetch(request: Request): Promise<Response>;
1733
+ private findWebSocketsByClientId;
1734
+ listConnections(options?: ConnectionListOptions): Promise<ConnectionListResult>;
1735
+ closeClientConnections(clientId: string, reason?: string): Promise<CloseConnectionResult>;
1736
+ private matchEventWithFilter;
1737
+ deliverEventToClient(clientId: string, event: EventMessage): Promise<void>;
1738
+ broadcastEvent(event: EventMessage): Promise<void>;
1739
+ webSocketClose(ws: WebSocket, _code: number, reason: string, _wasClean: boolean): Promise<void>;
377
1740
  }
378
- declare function createEventStoreWebSocketRoute(config: EventStoreWebSocketRouteConfig): {
379
- app: OpenAPIHono<{
380
- Bindings: Env;
381
- }, {}, "/">;
382
- getManagerId: () => string;
383
- };
384
1741
 
385
1742
  declare const routes: hono_hono_base.HonoBase<hono.Env, hono_types.MergeSchemaPath<{}, "/api"> & {
386
1743
  docs: {
@@ -405,8 +1762,21 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, hono_types.MergeSchemaPa
405
1762
  status: hono_utils_http_status.StatusCode;
406
1763
  };
407
1764
  };
1765
+ } & {
1766
+ "/api/webhook-test": {
1767
+ $post: {
1768
+ input: {};
1769
+ output: {
1770
+ status: string;
1771
+ received_at: string;
1772
+ event: any;
1773
+ };
1774
+ outputFormat: "json";
1775
+ status: hono_utils_http_status.ContentfulStatusCode;
1776
+ };
1777
+ };
408
1778
  }, "/api">;
409
1779
 
410
1780
  type AppType = typeof routes;
411
1781
 
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 };
1782
+ 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 };