@syncular/server-hono 0.0.6-96 → 0.2.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.
Files changed (104) hide show
  1. package/README.md +5 -23
  2. package/dist/admin-page.d.ts +14 -0
  3. package/dist/admin-page.js +217 -0
  4. package/dist/admin.d.ts +39 -0
  5. package/dist/admin.js +142 -0
  6. package/dist/index.d.ts +16 -14
  7. package/dist/index.js +134 -23
  8. package/package.json +19 -53
  9. package/src/admin-page.ts +217 -0
  10. package/src/admin.ts +193 -0
  11. package/src/index.ts +175 -31
  12. package/dist/api-key-auth.d.ts +0 -49
  13. package/dist/api-key-auth.d.ts.map +0 -1
  14. package/dist/api-key-auth.js +0 -110
  15. package/dist/api-key-auth.js.map +0 -1
  16. package/dist/blobs.d.ts +0 -69
  17. package/dist/blobs.d.ts.map +0 -1
  18. package/dist/blobs.js +0 -383
  19. package/dist/blobs.js.map +0 -1
  20. package/dist/console/gateway.d.ts +0 -33
  21. package/dist/console/gateway.d.ts.map +0 -1
  22. package/dist/console/gateway.js +0 -2534
  23. package/dist/console/gateway.js.map +0 -1
  24. package/dist/console/index.d.ts +0 -11
  25. package/dist/console/index.d.ts.map +0 -1
  26. package/dist/console/index.js +0 -11
  27. package/dist/console/index.js.map +0 -1
  28. package/dist/console/routes.d.ts +0 -33
  29. package/dist/console/routes.d.ts.map +0 -1
  30. package/dist/console/routes.js +0 -3029
  31. package/dist/console/routes.js.map +0 -1
  32. package/dist/console/schemas.d.ts +0 -490
  33. package/dist/console/schemas.d.ts.map +0 -1
  34. package/dist/console/schemas.js +0 -303
  35. package/dist/console/schemas.js.map +0 -1
  36. package/dist/console/types.d.ts +0 -175
  37. package/dist/console/types.d.ts.map +0 -1
  38. package/dist/console/types.js +0 -2
  39. package/dist/console/types.js.map +0 -1
  40. package/dist/console/ui.d.ts +0 -38
  41. package/dist/console/ui.d.ts.map +0 -1
  42. package/dist/console/ui.js +0 -43
  43. package/dist/console/ui.js.map +0 -1
  44. package/dist/create-server.d.ts +0 -68
  45. package/dist/create-server.d.ts.map +0 -1
  46. package/dist/create-server.js +0 -110
  47. package/dist/create-server.js.map +0 -1
  48. package/dist/index.d.ts.map +0 -1
  49. package/dist/index.js.map +0 -1
  50. package/dist/openapi.d.ts +0 -45
  51. package/dist/openapi.d.ts.map +0 -1
  52. package/dist/openapi.js +0 -59
  53. package/dist/openapi.js.map +0 -1
  54. package/dist/proxy/connection-manager.d.ts +0 -78
  55. package/dist/proxy/connection-manager.d.ts.map +0 -1
  56. package/dist/proxy/connection-manager.js +0 -251
  57. package/dist/proxy/connection-manager.js.map +0 -1
  58. package/dist/proxy/index.d.ts +0 -8
  59. package/dist/proxy/index.d.ts.map +0 -1
  60. package/dist/proxy/index.js +0 -8
  61. package/dist/proxy/index.js.map +0 -1
  62. package/dist/proxy/routes.d.ts +0 -74
  63. package/dist/proxy/routes.d.ts.map +0 -1
  64. package/dist/proxy/routes.js +0 -147
  65. package/dist/proxy/routes.js.map +0 -1
  66. package/dist/rate-limit.d.ts +0 -101
  67. package/dist/rate-limit.d.ts.map +0 -1
  68. package/dist/rate-limit.js +0 -186
  69. package/dist/rate-limit.js.map +0 -1
  70. package/dist/routes.d.ts +0 -161
  71. package/dist/routes.d.ts.map +0 -1
  72. package/dist/routes.js +0 -1493
  73. package/dist/routes.js.map +0 -1
  74. package/dist/ws.d.ts +0 -235
  75. package/dist/ws.d.ts.map +0 -1
  76. package/dist/ws.js +0 -614
  77. package/dist/ws.js.map +0 -1
  78. package/src/__tests__/blob-routes.test.ts +0 -424
  79. package/src/__tests__/console-gateway-live-routes.test.ts +0 -297
  80. package/src/__tests__/console-gateway-routes.test.ts +0 -1364
  81. package/src/__tests__/console-routes.test.ts +0 -1626
  82. package/src/__tests__/console-ui.test.ts +0 -114
  83. package/src/__tests__/create-server.test.ts +0 -485
  84. package/src/__tests__/pull-chunk-storage.test.ts +0 -576
  85. package/src/__tests__/rate-limit.test.ts +0 -78
  86. package/src/__tests__/realtime-bridge.test.ts +0 -135
  87. package/src/__tests__/sync-rate-limit-routing.test.ts +0 -185
  88. package/src/__tests__/ws-connection-manager.test.ts +0 -176
  89. package/src/api-key-auth.ts +0 -179
  90. package/src/blobs.ts +0 -534
  91. package/src/console/gateway.ts +0 -3603
  92. package/src/console/index.ts +0 -11
  93. package/src/console/routes.ts +0 -3936
  94. package/src/console/schemas.ts +0 -434
  95. package/src/console/types.ts +0 -185
  96. package/src/console/ui.ts +0 -100
  97. package/src/create-server.ts +0 -207
  98. package/src/openapi.ts +0 -74
  99. package/src/proxy/connection-manager.ts +0 -340
  100. package/src/proxy/index.ts +0 -8
  101. package/src/proxy/routes.ts +0 -223
  102. package/src/rate-limit.ts +0 -321
  103. package/src/routes.ts +0 -2059
  104. package/src/ws.ts +0 -802
@@ -1,434 +0,0 @@
1
- /**
2
- * @syncular/server-hono - Console API Zod schemas
3
- */
4
-
5
- import { z } from 'zod';
6
-
7
- // ============================================================================
8
- // Stats Schema
9
- // ============================================================================
10
-
11
- export const SyncStatsSchema = z.object({
12
- commitCount: z.number().int(),
13
- changeCount: z.number().int(),
14
- minCommitSeq: z.number().int(),
15
- maxCommitSeq: z.number().int(),
16
- clientCount: z.number().int(),
17
- activeClientCount: z.number().int(),
18
- minActiveClientCursor: z.number().int().nullable(),
19
- maxActiveClientCursor: z.number().int().nullable(),
20
- });
21
-
22
- export type SyncStats = z.infer<typeof SyncStatsSchema>;
23
-
24
- // ============================================================================
25
- // Commit Schemas
26
- // ============================================================================
27
-
28
- export const ConsoleCommitListItemSchema = z.object({
29
- commitSeq: z.number().int(),
30
- actorId: z.string(),
31
- clientId: z.string(),
32
- clientCommitId: z.string(),
33
- createdAt: z.string(),
34
- changeCount: z.number().int(),
35
- affectedTables: z.array(z.string()),
36
- });
37
-
38
- export type ConsoleCommitListItem = z.infer<typeof ConsoleCommitListItemSchema>;
39
-
40
- export const ConsoleChangeSchema = z.object({
41
- changeId: z.number().int(),
42
- table: z.string(),
43
- rowId: z.string(),
44
- op: z.enum(['upsert', 'delete']),
45
- rowJson: z.unknown().nullable(),
46
- rowVersion: z.number().int().nullable(),
47
- scopes: z.record(z.string(), z.unknown()),
48
- });
49
-
50
- export type ConsoleChange = z.infer<typeof ConsoleChangeSchema>;
51
-
52
- export const ConsoleCommitDetailSchema = ConsoleCommitListItemSchema.extend({
53
- changes: z.array(ConsoleChangeSchema),
54
- });
55
-
56
- export type ConsoleCommitDetail = z.infer<typeof ConsoleCommitDetailSchema>;
57
-
58
- // ============================================================================
59
- // Client Schemas
60
- // ============================================================================
61
-
62
- export const ConsoleClientSchema = z.object({
63
- clientId: z.string(),
64
- actorId: z.string(),
65
- cursor: z.number().int(),
66
- lagCommitCount: z.number().int().nonnegative(),
67
- connectionPath: z.enum(['direct', 'relay']),
68
- connectionMode: z.enum(['polling', 'realtime']),
69
- realtimeConnectionCount: z.number().int().nonnegative(),
70
- isRealtimeConnected: z.boolean(),
71
- activityState: z.enum(['active', 'idle', 'stale']),
72
- lastRequestAt: z.string().nullable(),
73
- lastRequestType: z.enum(['push', 'pull']).nullable(),
74
- lastRequestOutcome: z.string().nullable(),
75
- effectiveScopes: z.record(z.string(), z.unknown()),
76
- updatedAt: z.string(),
77
- });
78
-
79
- export type ConsoleClient = z.infer<typeof ConsoleClientSchema>;
80
-
81
- // ============================================================================
82
- // Handler Schemas
83
- // ============================================================================
84
-
85
- export const ConsoleHandlerSchema = z.object({
86
- table: z.string(),
87
- dependsOn: z.array(z.string()).optional(),
88
- snapshotChunkTtlMs: z.number().int().optional(),
89
- });
90
-
91
- export type ConsoleHandler = z.infer<typeof ConsoleHandlerSchema>;
92
-
93
- // ============================================================================
94
- // Prune & Compact Schemas
95
- // ============================================================================
96
-
97
- export const ConsolePrunePreviewSchema = z.object({
98
- watermarkCommitSeq: z.number().int(),
99
- commitsToDelete: z.number().int(),
100
- });
101
-
102
- export type ConsolePrunePreview = z.infer<typeof ConsolePrunePreviewSchema>;
103
-
104
- export const ConsolePruneResultSchema = z.object({
105
- deletedCommits: z.number().int(),
106
- });
107
-
108
- export type ConsolePruneResult = z.infer<typeof ConsolePruneResultSchema>;
109
-
110
- export const ConsoleCompactResultSchema = z.object({
111
- deletedChanges: z.number().int(),
112
- });
113
-
114
- export type ConsoleCompactResult = z.infer<typeof ConsoleCompactResultSchema>;
115
-
116
- // ============================================================================
117
- // Evict Schema
118
- // ============================================================================
119
-
120
- export const ConsoleEvictResultSchema = z.object({
121
- evicted: z.boolean(),
122
- });
123
-
124
- export type ConsoleEvictResult = z.infer<typeof ConsoleEvictResultSchema>;
125
-
126
- // ============================================================================
127
- // Request Event Schemas
128
- // ============================================================================
129
-
130
- export const ConsoleRequestEventSchema = z.object({
131
- eventId: z.number().int(),
132
- partitionId: z.string(),
133
- requestId: z.string(),
134
- traceId: z.string().nullable(),
135
- spanId: z.string().nullable(),
136
- eventType: z.enum(['push', 'pull']),
137
- syncPath: z.enum(['http-combined', 'ws-push']),
138
- transportPath: z.enum(['direct', 'relay']),
139
- actorId: z.string(),
140
- clientId: z.string(),
141
- statusCode: z.number().int(),
142
- outcome: z.string(),
143
- responseStatus: z.string(),
144
- errorCode: z.string().nullable(),
145
- durationMs: z.number().int(),
146
- commitSeq: z.number().int().nullable(),
147
- operationCount: z.number().int().nullable(),
148
- rowCount: z.number().int().nullable(),
149
- subscriptionCount: z.number().int().nullable(),
150
- scopesSummary: z
151
- .record(z.string(), z.union([z.string(), z.array(z.string())]))
152
- .nullable(),
153
- tables: z.array(z.string()),
154
- errorMessage: z.string().nullable(),
155
- payloadRef: z.string().nullable(),
156
- createdAt: z.string(),
157
- });
158
-
159
- export type ConsoleRequestEvent = z.infer<typeof ConsoleRequestEventSchema>;
160
-
161
- export const ConsoleRequestPayloadSchema = z.object({
162
- payloadRef: z.string(),
163
- partitionId: z.string(),
164
- requestPayload: z.unknown(),
165
- responsePayload: z.unknown().nullable(),
166
- createdAt: z.string(),
167
- });
168
-
169
- export type ConsoleRequestPayload = z.infer<typeof ConsoleRequestPayloadSchema>;
170
-
171
- export const ConsoleTimelineItemSchema = z.object({
172
- type: z.enum(['commit', 'event']),
173
- timestamp: z.string(),
174
- commit: ConsoleCommitListItemSchema.nullable(),
175
- event: ConsoleRequestEventSchema.nullable(),
176
- });
177
-
178
- export type ConsoleTimelineItem = z.infer<typeof ConsoleTimelineItemSchema>;
179
-
180
- export const ConsoleClearEventsResultSchema = z.object({
181
- deletedCount: z.number().int(),
182
- });
183
-
184
- export type ConsoleClearEventsResult = z.infer<
185
- typeof ConsoleClearEventsResultSchema
186
- >;
187
-
188
- export const ConsolePruneEventsResultSchema = z.object({
189
- deletedCount: z.number().int(),
190
- });
191
-
192
- export type ConsolePruneEventsResult = z.infer<
193
- typeof ConsolePruneEventsResultSchema
194
- >;
195
-
196
- // ============================================================================
197
- // Operation Audit Schemas
198
- // ============================================================================
199
-
200
- export const ConsoleOperationTypeSchema = z.enum([
201
- 'prune',
202
- 'compact',
203
- 'notify_data_change',
204
- 'evict_client',
205
- ]);
206
-
207
- export type ConsoleOperationType = z.infer<typeof ConsoleOperationTypeSchema>;
208
-
209
- export const ConsoleOperationEventSchema = z.object({
210
- operationId: z.number().int(),
211
- operationType: ConsoleOperationTypeSchema,
212
- consoleUserId: z.string().nullable(),
213
- partitionId: z.string().nullable(),
214
- targetClientId: z.string().nullable(),
215
- requestPayload: z.unknown().nullable(),
216
- resultPayload: z.unknown().nullable(),
217
- createdAt: z.string(),
218
- });
219
-
220
- export type ConsoleOperationEvent = z.infer<typeof ConsoleOperationEventSchema>;
221
-
222
- // ============================================================================
223
- // API Key Schemas
224
- // ============================================================================
225
-
226
- export const ApiKeyTypeSchema = z.enum(['relay', 'proxy', 'admin']);
227
- export type ApiKeyType = z.infer<typeof ApiKeyTypeSchema>;
228
-
229
- export const ConsoleApiKeySchema = z.object({
230
- keyId: z.string(),
231
- keyPrefix: z.string(),
232
- name: z.string(),
233
- keyType: ApiKeyTypeSchema,
234
- scopeKeys: z.array(z.string()),
235
- actorId: z.string().nullable(),
236
- createdAt: z.string(),
237
- expiresAt: z.string().nullable(),
238
- lastUsedAt: z.string().nullable(),
239
- revokedAt: z.string().nullable(),
240
- });
241
-
242
- export type ConsoleApiKey = z.infer<typeof ConsoleApiKeySchema>;
243
-
244
- export const ConsoleApiKeyCreateRequestSchema = z.object({
245
- name: z.string().min(1),
246
- keyType: ApiKeyTypeSchema,
247
- scopeKeys: z.array(z.string()).optional(),
248
- actorId: z.string().optional(),
249
- expiresInDays: z.number().int().positive().optional(),
250
- });
251
-
252
- export const ConsoleApiKeyCreateResponseSchema = z.object({
253
- key: ConsoleApiKeySchema,
254
- secretKey: z.string(),
255
- });
256
-
257
- export type ConsoleApiKeyCreateResponse = z.infer<
258
- typeof ConsoleApiKeyCreateResponseSchema
259
- >;
260
-
261
- export const ConsoleApiKeyRevokeResponseSchema = z.object({
262
- revoked: z.boolean(),
263
- });
264
-
265
- export const ConsoleApiKeyBulkRevokeRequestSchema = z.object({
266
- keyIds: z.array(z.string().min(1)).min(1).max(200),
267
- });
268
-
269
- export const ConsoleApiKeyBulkRevokeResponseSchema = z.object({
270
- requestedCount: z.number().int().nonnegative(),
271
- revokedCount: z.number().int().nonnegative(),
272
- alreadyRevokedCount: z.number().int().nonnegative(),
273
- notFoundCount: z.number().int().nonnegative(),
274
- revokedKeyIds: z.array(z.string()),
275
- alreadyRevokedKeyIds: z.array(z.string()),
276
- notFoundKeyIds: z.array(z.string()),
277
- });
278
-
279
- export type ConsoleApiKeyBulkRevokeResponse = z.infer<
280
- typeof ConsoleApiKeyBulkRevokeResponseSchema
281
- >;
282
-
283
- // ============================================================================
284
- // Pagination Schemas (Console-specific)
285
- // ============================================================================
286
-
287
- export const ConsolePaginationQuerySchema = z.object({
288
- limit: z.coerce.number().int().min(1).max(100).default(50),
289
- offset: z.coerce.number().int().min(0).default(0),
290
- });
291
-
292
- export const ConsolePartitionQuerySchema = z.object({
293
- partitionId: z.string().min(1).optional(),
294
- });
295
-
296
- export const ConsolePartitionedPaginationQuerySchema =
297
- ConsolePaginationQuerySchema.extend({
298
- partitionId: z.string().min(1).optional(),
299
- });
300
-
301
- export const ConsolePaginatedResponseSchema = <T extends z.ZodTypeAny>(
302
- itemSchema: T
303
- ) =>
304
- z.object({
305
- items: z.array(itemSchema),
306
- total: z.number().int(),
307
- offset: z.number().int(),
308
- limit: z.number().int(),
309
- });
310
-
311
- export type ConsolePaginatedResponse<T> = {
312
- items: T[];
313
- total: number;
314
- offset: number;
315
- limit: number;
316
- };
317
-
318
- export const ConsoleTimelineQuerySchema =
319
- ConsolePartitionedPaginationQuerySchema.extend({
320
- view: z.enum(['all', 'commits', 'events']).default('all'),
321
- eventType: z.enum(['push', 'pull']).optional(),
322
- actorId: z.string().optional(),
323
- clientId: z.string().optional(),
324
- requestId: z.string().optional(),
325
- traceId: z.string().optional(),
326
- table: z.string().optional(),
327
- outcome: z.string().optional(),
328
- search: z.string().optional(),
329
- from: z.string().datetime().optional(),
330
- to: z.string().datetime().optional(),
331
- });
332
-
333
- export const ConsoleOperationsQuerySchema =
334
- ConsolePartitionedPaginationQuerySchema.extend({
335
- operationType: ConsoleOperationTypeSchema.optional(),
336
- });
337
-
338
- // ============================================================================
339
- // Time-Series Stats Schemas
340
- // ============================================================================
341
-
342
- const TimeseriesIntervalSchema = z.enum(['minute', 'hour', 'day']);
343
- const TimeseriesRangeSchema = z.enum(['1h', '6h', '24h', '7d', '30d']);
344
- export const TimeseriesQuerySchema = z.object({
345
- interval: TimeseriesIntervalSchema.default('hour'),
346
- range: TimeseriesRangeSchema.default('24h'),
347
- partitionId: z.string().min(1).optional(),
348
- });
349
-
350
- export const TimeseriesBucketSchema = z.object({
351
- timestamp: z.string(),
352
- pushCount: z.number().int(),
353
- pullCount: z.number().int(),
354
- errorCount: z.number().int(),
355
- avgLatencyMs: z.number(),
356
- });
357
-
358
- export type TimeseriesBucket = z.infer<typeof TimeseriesBucketSchema>;
359
-
360
- export const TimeseriesStatsResponseSchema = z.object({
361
- buckets: z.array(TimeseriesBucketSchema),
362
- interval: TimeseriesIntervalSchema,
363
- range: TimeseriesRangeSchema,
364
- });
365
-
366
- export type TimeseriesStatsResponse = z.infer<
367
- typeof TimeseriesStatsResponseSchema
368
- >;
369
-
370
- // ============================================================================
371
- // Latency Percentiles Schemas
372
- // ============================================================================
373
-
374
- export const LatencyPercentilesSchema = z.object({
375
- p50: z.number(),
376
- p90: z.number(),
377
- p99: z.number(),
378
- });
379
-
380
- export type LatencyPercentiles = z.infer<typeof LatencyPercentilesSchema>;
381
-
382
- export const LatencyStatsResponseSchema = z.object({
383
- push: LatencyPercentilesSchema,
384
- pull: LatencyPercentilesSchema,
385
- range: TimeseriesRangeSchema,
386
- });
387
-
388
- export type LatencyStatsResponse = z.infer<typeof LatencyStatsResponseSchema>;
389
-
390
- export const LatencyQuerySchema = z.object({
391
- range: TimeseriesRangeSchema.default('24h'),
392
- partitionId: z.string().min(1).optional(),
393
- });
394
-
395
- // ============================================================================
396
- // Live Events Schemas (for WebSocket)
397
- // ============================================================================
398
-
399
- export const LiveEventSchema = z.object({
400
- type: z.enum(['push', 'pull', 'commit', 'client_update']),
401
- timestamp: z.string(),
402
- data: z.record(z.string(), z.unknown()),
403
- });
404
-
405
- export type LiveEvent = z.infer<typeof LiveEventSchema>;
406
-
407
- // ---------------------------------------------------------------------------
408
- // Blob storage
409
- // ---------------------------------------------------------------------------
410
-
411
- export const ConsoleBlobSchema = z.object({
412
- key: z.string(),
413
- size: z.number().int(),
414
- uploaded: z.string(),
415
- httpMetadata: z.object({ contentType: z.string().optional() }).optional(),
416
- });
417
-
418
- export type ConsoleBlob = z.infer<typeof ConsoleBlobSchema>;
419
-
420
- export const ConsoleBlobListQuerySchema = z.object({
421
- prefix: z.string().optional(),
422
- cursor: z.string().optional(),
423
- limit: z.coerce.number().int().min(1).max(1000).default(100),
424
- });
425
-
426
- export const ConsoleBlobListResponseSchema = z.object({
427
- items: z.array(ConsoleBlobSchema),
428
- truncated: z.boolean(),
429
- cursor: z.string().nullable(),
430
- });
431
-
432
- export const ConsoleBlobDeleteResponseSchema = z.object({
433
- deleted: z.boolean(),
434
- });
@@ -1,185 +0,0 @@
1
- import type {
2
- ServerSyncDialect,
3
- ServerTableHandler,
4
- SqlFamily,
5
- SyncCoreDb,
6
- SyncServerAuth,
7
- } from '@syncular/server';
8
- import type { Context } from 'hono';
9
- import type { UpgradeWebSocket } from 'hono/ws';
10
- import type { Kysely } from 'kysely';
11
- import type { WebSocketConnectionManager } from '../ws';
12
- import type { LiveEvent } from './schemas';
13
-
14
- export interface ConsoleAuthResult {
15
- /** Identifier for the console user (for audit logging). */
16
- consoleUserId?: string;
17
- }
18
-
19
- /**
20
- * Listener for console live events (SSE streaming).
21
- */
22
- export type ConsoleEventListener = (event: LiveEvent) => void;
23
-
24
- /**
25
- * Console event emitter for broadcasting live events.
26
- */
27
- export interface ConsoleEventEmitter {
28
- /** Add a listener for live events */
29
- addListener(listener: ConsoleEventListener): void;
30
- /** Remove a listener */
31
- removeListener(listener: ConsoleEventListener): void;
32
- /** Emit an event to all listeners */
33
- emit(event: LiveEvent): void;
34
- /**
35
- * Replay recent events, optionally constrained by timestamp, partition, and max count.
36
- */
37
- replay(options?: {
38
- since?: string;
39
- limit?: number;
40
- partitionId?: string;
41
- }): LiveEvent[];
42
- }
43
-
44
- export interface ConsoleMetricsOptions {
45
- /**
46
- * Metrics query strategy for timeseries/latency endpoints.
47
- * - raw: in-memory processing from raw event rows
48
- * - aggregated: DB-level aggregation where supported (raw fallback for unsupported paths)
49
- * - auto: use raw for small windows, aggregated for larger windows
50
- */
51
- aggregationMode?: 'auto' | 'raw' | 'aggregated';
52
- /** Max events for using raw mode when aggregationMode is 'auto'. */
53
- rawFallbackMaxEvents?: number;
54
- }
55
-
56
- export interface ConsoleMaintenanceOptions {
57
- /**
58
- * Minimum interval between automatic event-prune runs.
59
- * Set to 0 to disable automatic pruning.
60
- * Default: 5 minutes.
61
- */
62
- autoPruneIntervalMs?: number;
63
- /**
64
- * Max age for request events before pruning.
65
- * Set to 0 to disable age-based pruning.
66
- * Default: 7 days.
67
- */
68
- requestEventsMaxAgeMs?: number;
69
- /**
70
- * Max number of request events to retain.
71
- * Set to 0 to disable count-based pruning.
72
- * Default: 10000.
73
- */
74
- requestEventsMaxRows?: number;
75
- /**
76
- * Max age for operation audit events before pruning.
77
- * Set to 0 to disable age-based pruning.
78
- * Default: 30 days.
79
- */
80
- operationEventsMaxAgeMs?: number;
81
- /**
82
- * Max number of operation audit events to retain.
83
- * Set to 0 to disable count-based pruning.
84
- * Default: 5000.
85
- */
86
- operationEventsMaxRows?: number;
87
- }
88
-
89
- export interface ConsoleBlobObject {
90
- key: string;
91
- size: number;
92
- uploaded: Date;
93
- httpMetadata?: { contentType?: string };
94
- }
95
-
96
- export interface ConsoleBlobGetResult {
97
- body: ReadableStream;
98
- size: number;
99
- httpMetadata?: { contentType?: string };
100
- }
101
-
102
- export interface ConsoleBlobHeadResult {
103
- size: number;
104
- httpMetadata?: { contentType?: string };
105
- }
106
-
107
- export interface ConsoleBlobBucket {
108
- list(options: { prefix?: string; cursor?: string; limit?: number }): Promise<{
109
- objects: ConsoleBlobObject[];
110
- truncated: boolean;
111
- cursor?: string;
112
- }>;
113
- get(key: string): Promise<ConsoleBlobGetResult | null>;
114
- delete(key: string | string[]): Promise<void>;
115
- head(key: string): Promise<ConsoleBlobHeadResult | null>;
116
- }
117
-
118
- export interface ConsoleSharedOptions {
119
- /**
120
- * CORS origins to allow. Defaults to ['http://localhost:5173', 'https://console.sync.dev'].
121
- * Set to '*' to allow all origins (not recommended for production).
122
- */
123
- corsOrigins?: string[] | '*';
124
- metrics?: ConsoleMetricsOptions;
125
- maintenance?: ConsoleMaintenanceOptions;
126
- blobBucket?: ConsoleBlobBucket;
127
- }
128
-
129
- export interface CreateConsoleRoutesOptions<
130
- DB extends SyncCoreDb = SyncCoreDb,
131
- Auth extends SyncServerAuth = SyncServerAuth,
132
- F extends SqlFamily = SqlFamily,
133
- > extends ConsoleSharedOptions {
134
- db: Kysely<DB>;
135
- dialect: ServerSyncDialect<F>;
136
- handlers: ServerTableHandler<DB, Auth>[];
137
- /**
138
- * Authentication function for console requests.
139
- * Return null to reject the request.
140
- */
141
- authenticate: (c: Context) => Promise<ConsoleAuthResult | null>;
142
- /**
143
- * Compaction options (required for /compact endpoint).
144
- */
145
- compact?: {
146
- fullHistoryHours?: number;
147
- };
148
- /**
149
- * Pruning options.
150
- */
151
- prune?: {
152
- activeWindowMs?: number;
153
- fallbackMaxAgeMs?: number;
154
- keepNewestCommits?: number;
155
- };
156
- /**
157
- * Event emitter for live console events.
158
- * If provided along with websocket config, enables the /events/live WebSocket endpoint.
159
- */
160
- eventEmitter?: ConsoleEventEmitter;
161
- /**
162
- * Shared sync WebSocket connection manager.
163
- * When provided, `/clients` includes realtime connection state per client.
164
- */
165
- wsConnectionManager?: WebSocketConnectionManager;
166
- /**
167
- * WebSocket configuration for live events streaming.
168
- */
169
- websocket?: {
170
- enabled?: boolean;
171
- /**
172
- * Runtime-provided WebSocket upgrader (e.g. from `hono/bun`'s `createBunWebSocket()`).
173
- */
174
- upgradeWebSocket?: UpgradeWebSocket;
175
- /**
176
- * Heartbeat interval in milliseconds. Default: 30000
177
- */
178
- heartbeatIntervalMs?: number;
179
- };
180
- /**
181
- * Optional console schema readiness promise.
182
- * When provided, routes wait for this promise before querying console tables.
183
- */
184
- consoleSchemaReady?: Promise<void>;
185
- }