@syncular/server-hono 0.0.4-26 → 0.0.6-100
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/console/gateway.d.ts +3 -1
- package/dist/console/gateway.d.ts.map +1 -1
- package/dist/console/gateway.js +218 -41
- package/dist/console/gateway.js.map +1 -1
- package/dist/console/index.d.ts +1 -0
- package/dist/console/index.d.ts.map +1 -1
- package/dist/console/index.js +1 -0
- package/dist/console/index.js.map +1 -1
- package/dist/console/routes.d.ts +3 -97
- package/dist/console/routes.d.ts.map +1 -1
- package/dist/console/routes.js +507 -80
- package/dist/console/routes.js.map +1 -1
- package/dist/console/schemas.d.ts +29 -0
- package/dist/console/schemas.d.ts.map +1 -1
- package/dist/console/schemas.js +22 -0
- package/dist/console/schemas.js.map +1 -1
- package/dist/console/types.d.ts +175 -0
- package/dist/console/types.d.ts.map +1 -0
- package/dist/console/types.js +2 -0
- package/dist/console/types.js.map +1 -0
- package/dist/create-server.d.ts +17 -34
- package/dist/create-server.d.ts.map +1 -1
- package/dist/create-server.js +26 -26
- package/dist/create-server.js.map +1 -1
- package/dist/proxy/connection-manager.d.ts +3 -3
- package/dist/proxy/connection-manager.d.ts.map +1 -1
- package/dist/proxy/routes.d.ts +4 -4
- package/dist/proxy/routes.d.ts.map +1 -1
- package/dist/proxy/routes.js +1 -1
- package/dist/routes.d.ts +33 -9
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +153 -70
- package/dist/routes.js.map +1 -1
- package/package.json +21 -7
- package/src/__tests__/blob-routes.test.ts +424 -0
- package/src/__tests__/console-gateway-live-routes.test.ts +54 -3
- package/src/__tests__/console-routes.test.ts +161 -7
- package/src/__tests__/console-ui.test.ts +114 -0
- package/src/__tests__/create-server.test.ts +233 -10
- package/src/__tests__/pull-chunk-storage.test.ts +6 -2
- package/src/__tests__/realtime-bridge.test.ts +6 -2
- package/src/__tests__/sync-rate-limit-routing.test.ts +6 -2
- package/src/console/gateway.ts +277 -53
- package/src/console/index.ts +1 -0
- package/src/console/routes.ts +654 -198
- package/src/console/schemas.ts +29 -0
- package/src/console/types.ts +185 -0
- package/src/create-server.ts +56 -53
- package/src/proxy/connection-manager.ts +3 -3
- package/src/proxy/routes.ts +4 -4
- package/src/routes.ts +225 -96
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { ServerSyncDialect, ServerTableHandler, SqlFamily, SyncCoreDb, SyncServerAuth } from '@syncular/server';
|
|
2
|
+
import type { Context } from 'hono';
|
|
3
|
+
import type { UpgradeWebSocket } from 'hono/ws';
|
|
4
|
+
import type { Kysely } from 'kysely';
|
|
5
|
+
import type { WebSocketConnectionManager } from '../ws';
|
|
6
|
+
import type { LiveEvent } from './schemas';
|
|
7
|
+
export interface ConsoleAuthResult {
|
|
8
|
+
/** Identifier for the console user (for audit logging). */
|
|
9
|
+
consoleUserId?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Listener for console live events (SSE streaming).
|
|
13
|
+
*/
|
|
14
|
+
export type ConsoleEventListener = (event: LiveEvent) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Console event emitter for broadcasting live events.
|
|
17
|
+
*/
|
|
18
|
+
export interface ConsoleEventEmitter {
|
|
19
|
+
/** Add a listener for live events */
|
|
20
|
+
addListener(listener: ConsoleEventListener): void;
|
|
21
|
+
/** Remove a listener */
|
|
22
|
+
removeListener(listener: ConsoleEventListener): void;
|
|
23
|
+
/** Emit an event to all listeners */
|
|
24
|
+
emit(event: LiveEvent): void;
|
|
25
|
+
/**
|
|
26
|
+
* Replay recent events, optionally constrained by timestamp, partition, and max count.
|
|
27
|
+
*/
|
|
28
|
+
replay(options?: {
|
|
29
|
+
since?: string;
|
|
30
|
+
limit?: number;
|
|
31
|
+
partitionId?: string;
|
|
32
|
+
}): LiveEvent[];
|
|
33
|
+
}
|
|
34
|
+
export interface ConsoleMetricsOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Metrics query strategy for timeseries/latency endpoints.
|
|
37
|
+
* - raw: in-memory processing from raw event rows
|
|
38
|
+
* - aggregated: DB-level aggregation where supported (raw fallback for unsupported paths)
|
|
39
|
+
* - auto: use raw for small windows, aggregated for larger windows
|
|
40
|
+
*/
|
|
41
|
+
aggregationMode?: 'auto' | 'raw' | 'aggregated';
|
|
42
|
+
/** Max events for using raw mode when aggregationMode is 'auto'. */
|
|
43
|
+
rawFallbackMaxEvents?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ConsoleMaintenanceOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Minimum interval between automatic event-prune runs.
|
|
48
|
+
* Set to 0 to disable automatic pruning.
|
|
49
|
+
* Default: 5 minutes.
|
|
50
|
+
*/
|
|
51
|
+
autoPruneIntervalMs?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Max age for request events before pruning.
|
|
54
|
+
* Set to 0 to disable age-based pruning.
|
|
55
|
+
* Default: 7 days.
|
|
56
|
+
*/
|
|
57
|
+
requestEventsMaxAgeMs?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Max number of request events to retain.
|
|
60
|
+
* Set to 0 to disable count-based pruning.
|
|
61
|
+
* Default: 10000.
|
|
62
|
+
*/
|
|
63
|
+
requestEventsMaxRows?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Max age for operation audit events before pruning.
|
|
66
|
+
* Set to 0 to disable age-based pruning.
|
|
67
|
+
* Default: 30 days.
|
|
68
|
+
*/
|
|
69
|
+
operationEventsMaxAgeMs?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Max number of operation audit events to retain.
|
|
72
|
+
* Set to 0 to disable count-based pruning.
|
|
73
|
+
* Default: 5000.
|
|
74
|
+
*/
|
|
75
|
+
operationEventsMaxRows?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface ConsoleBlobObject {
|
|
78
|
+
key: string;
|
|
79
|
+
size: number;
|
|
80
|
+
uploaded: Date;
|
|
81
|
+
httpMetadata?: {
|
|
82
|
+
contentType?: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export interface ConsoleBlobGetResult {
|
|
86
|
+
body: ReadableStream;
|
|
87
|
+
size: number;
|
|
88
|
+
httpMetadata?: {
|
|
89
|
+
contentType?: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export interface ConsoleBlobHeadResult {
|
|
93
|
+
size: number;
|
|
94
|
+
httpMetadata?: {
|
|
95
|
+
contentType?: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export interface ConsoleBlobBucket {
|
|
99
|
+
list(options: {
|
|
100
|
+
prefix?: string;
|
|
101
|
+
cursor?: string;
|
|
102
|
+
limit?: number;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
objects: ConsoleBlobObject[];
|
|
105
|
+
truncated: boolean;
|
|
106
|
+
cursor?: string;
|
|
107
|
+
}>;
|
|
108
|
+
get(key: string): Promise<ConsoleBlobGetResult | null>;
|
|
109
|
+
delete(key: string | string[]): Promise<void>;
|
|
110
|
+
head(key: string): Promise<ConsoleBlobHeadResult | null>;
|
|
111
|
+
}
|
|
112
|
+
export interface ConsoleSharedOptions {
|
|
113
|
+
/**
|
|
114
|
+
* CORS origins to allow. Defaults to ['http://localhost:5173', 'https://console.sync.dev'].
|
|
115
|
+
* Set to '*' to allow all origins (not recommended for production).
|
|
116
|
+
*/
|
|
117
|
+
corsOrigins?: string[] | '*';
|
|
118
|
+
metrics?: ConsoleMetricsOptions;
|
|
119
|
+
maintenance?: ConsoleMaintenanceOptions;
|
|
120
|
+
blobBucket?: ConsoleBlobBucket;
|
|
121
|
+
}
|
|
122
|
+
export interface CreateConsoleRoutesOptions<DB extends SyncCoreDb = SyncCoreDb, Auth extends SyncServerAuth = SyncServerAuth, F extends SqlFamily = SqlFamily> extends ConsoleSharedOptions {
|
|
123
|
+
db: Kysely<DB>;
|
|
124
|
+
dialect: ServerSyncDialect<F>;
|
|
125
|
+
handlers: ServerTableHandler<DB, Auth>[];
|
|
126
|
+
/**
|
|
127
|
+
* Authentication function for console requests.
|
|
128
|
+
* Return null to reject the request.
|
|
129
|
+
*/
|
|
130
|
+
authenticate: (c: Context) => Promise<ConsoleAuthResult | null>;
|
|
131
|
+
/**
|
|
132
|
+
* Compaction options (required for /compact endpoint).
|
|
133
|
+
*/
|
|
134
|
+
compact?: {
|
|
135
|
+
fullHistoryHours?: number;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Pruning options.
|
|
139
|
+
*/
|
|
140
|
+
prune?: {
|
|
141
|
+
activeWindowMs?: number;
|
|
142
|
+
fallbackMaxAgeMs?: number;
|
|
143
|
+
keepNewestCommits?: number;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Event emitter for live console events.
|
|
147
|
+
* If provided along with websocket config, enables the /events/live WebSocket endpoint.
|
|
148
|
+
*/
|
|
149
|
+
eventEmitter?: ConsoleEventEmitter;
|
|
150
|
+
/**
|
|
151
|
+
* Shared sync WebSocket connection manager.
|
|
152
|
+
* When provided, `/clients` includes realtime connection state per client.
|
|
153
|
+
*/
|
|
154
|
+
wsConnectionManager?: WebSocketConnectionManager;
|
|
155
|
+
/**
|
|
156
|
+
* WebSocket configuration for live events streaming.
|
|
157
|
+
*/
|
|
158
|
+
websocket?: {
|
|
159
|
+
enabled?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Runtime-provided WebSocket upgrader (e.g. from `hono/bun`'s `createBunWebSocket()`).
|
|
162
|
+
*/
|
|
163
|
+
upgradeWebSocket?: UpgradeWebSocket;
|
|
164
|
+
/**
|
|
165
|
+
* Heartbeat interval in milliseconds. Default: 30000
|
|
166
|
+
*/
|
|
167
|
+
heartbeatIntervalMs?: number;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Optional console schema readiness promise.
|
|
171
|
+
* When provided, routes wait for this promise before querying console tables.
|
|
172
|
+
*/
|
|
173
|
+
consoleSchemaReady?: Promise<void>;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=types.d.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AO,CAAC;QAClB;;WAEG;QACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;QACpC;;WAEG;QACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/console/types.ts"],"names":[],"mappings":""}
|
package/dist/create-server.d.ts
CHANGED
|
@@ -2,47 +2,38 @@
|
|
|
2
2
|
* Simplified server factory for Hono
|
|
3
3
|
*
|
|
4
4
|
* Breaking changes from legacy createSyncRoutes:
|
|
5
|
-
* -
|
|
5
|
+
* - sync contract instead of top-level handlers/authenticate
|
|
6
6
|
* - Combined sync + console routes in one call
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
9
|
-
import type { Context } from 'hono';
|
|
8
|
+
import type { ScopeCacheBackend, ServerSyncConfig, ServerSyncDialect, SnapshotChunkStorage, SqlFamily, SyncCoreDb } from '@syncular/server';
|
|
10
9
|
import type { UpgradeWebSocket } from 'hono/ws';
|
|
11
10
|
import type { Kysely } from 'kysely';
|
|
12
|
-
import {
|
|
11
|
+
import { createConsoleRoutes } from './console/routes';
|
|
12
|
+
import type { ConsoleEventEmitter, ConsoleSharedOptions } from './console/types';
|
|
13
13
|
import { createSyncRoutes, type SyncAuthResult, type SyncRoutesConfigWithRateLimit } from './routes';
|
|
14
|
-
export interface SyncServerOptions<DB extends SyncCoreDb = SyncCoreDb> {
|
|
14
|
+
export interface SyncServerOptions<DB extends SyncCoreDb = SyncCoreDb, Auth extends SyncAuthResult = SyncAuthResult, F extends SqlFamily = SqlFamily> {
|
|
15
15
|
/** Kysely database instance */
|
|
16
16
|
db: Kysely<DB>;
|
|
17
17
|
/** Server sync dialect */
|
|
18
|
-
dialect: ServerSyncDialect
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
*/
|
|
22
|
-
handlers: ServerTableHandler<DB>[];
|
|
23
|
-
/** Authentication function - returns actorId or null for unauthenticated */
|
|
24
|
-
authenticate: (c: Context) => Promise<SyncAuthResult | null>;
|
|
18
|
+
dialect: ServerSyncDialect<F>;
|
|
19
|
+
/** Sync contract with auth + table handlers */
|
|
20
|
+
sync: ServerSyncConfig<DB, Auth>;
|
|
25
21
|
/** Snapshot chunk storage (external body storage, e.g. R2/S3) */
|
|
26
22
|
chunkStorage?: SnapshotChunkStorage;
|
|
23
|
+
/** Scope cache backend for resolveScopes() results */
|
|
24
|
+
scopeCache?: ScopeCacheBackend;
|
|
27
25
|
/** Sync route configuration */
|
|
28
|
-
|
|
26
|
+
routes?: SyncRoutesConfigWithRateLimit;
|
|
29
27
|
/** WebSocket upgrader for realtime */
|
|
30
28
|
upgradeWebSocket?: UpgradeWebSocket;
|
|
31
29
|
/**
|
|
32
30
|
* Console configuration for dashboard/monitoring.
|
|
33
31
|
* Omit or set to false to disable console routes.
|
|
34
32
|
*/
|
|
35
|
-
console?: false | {
|
|
33
|
+
console?: false | ({
|
|
36
34
|
/** Console bearer token for authentication (required unless SYNC_CONSOLE_TOKEN is set) */
|
|
37
35
|
token?: string;
|
|
38
|
-
|
|
39
|
-
corsOrigins?: '*' | string[];
|
|
40
|
-
/** Metrics aggregation strategy for console stats endpoints */
|
|
41
|
-
metrics?: {
|
|
42
|
-
aggregationMode?: 'auto' | 'raw' | 'aggregated';
|
|
43
|
-
rawFallbackMaxEvents?: number;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
36
|
+
} & ConsoleSharedOptions);
|
|
46
37
|
}
|
|
47
38
|
export interface SyncServerResult {
|
|
48
39
|
/** Sync routes for Hono */
|
|
@@ -57,29 +48,21 @@ export interface SyncServerResult {
|
|
|
57
48
|
*
|
|
58
49
|
* @example
|
|
59
50
|
* ```typescript
|
|
60
|
-
* // With
|
|
51
|
+
* // With sync contract
|
|
61
52
|
* const { syncRoutes } = createSyncServer({
|
|
62
53
|
* db,
|
|
63
54
|
* dialect,
|
|
64
|
-
*
|
|
65
|
-
* authenticate: async (c) => {
|
|
66
|
-
* const userId = c.req.header('x-user-id');
|
|
67
|
-
* return userId ? { actorId: userId } : null;
|
|
68
|
-
* },
|
|
55
|
+
* sync,
|
|
69
56
|
* });
|
|
70
57
|
*
|
|
71
58
|
* // With custom handlers
|
|
72
59
|
* const { syncRoutes, consoleRoutes } = createSyncServer({
|
|
73
60
|
* db,
|
|
74
61
|
* dialect,
|
|
75
|
-
*
|
|
76
|
-
* authenticate: async (c) => {
|
|
77
|
-
* const userId = c.req.header('x-user-id');
|
|
78
|
-
* return userId ? { actorId: userId } : null;
|
|
79
|
-
* },
|
|
62
|
+
* sync,
|
|
80
63
|
* console: { token: process.env.CONSOLE_TOKEN },
|
|
81
64
|
* });
|
|
82
65
|
* ```
|
|
83
66
|
*/
|
|
84
|
-
export declare function createSyncServer<DB extends SyncCoreDb = SyncCoreDb>(options: SyncServerOptions<DB>): SyncServerResult;
|
|
67
|
+
export declare function createSyncServer<DB extends SyncCoreDb = SyncCoreDb, Auth extends SyncAuthResult = SyncAuthResult, F extends SqlFamily = SqlFamily>(options: SyncServerOptions<DB, Auth, F>): SyncServerResult;
|
|
85
68
|
//# sourceMappingURL=create-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,K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;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,SAAS,UAAU,GAAG,UAAU,EAClC,IAAI,SAAS,cAAc,GAAG,cAAc,EAC5C,CAAC,SAAS,SAAS,GAAG,SAAS,EAC/B,OAAO,EAAE,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,gBAAgB,CAoG3D"}
|
package/dist/create-server.js
CHANGED
|
@@ -2,43 +2,35 @@
|
|
|
2
2
|
* Simplified server factory for Hono
|
|
3
3
|
*
|
|
4
4
|
* Breaking changes from legacy createSyncRoutes:
|
|
5
|
-
* -
|
|
5
|
+
* - sync contract instead of top-level handlers/authenticate
|
|
6
6
|
* - Combined sync + console routes in one call
|
|
7
7
|
*/
|
|
8
|
-
import { createConsoleEventEmitter, createConsoleRoutes, createTokenAuthenticator, } from './console/
|
|
8
|
+
import { createConsoleEventEmitter, createConsoleRoutes, createTokenAuthenticator, } from './console/routes.js';
|
|
9
9
|
import { createSyncRoutes, getSyncWebSocketConnectionManager, } from './routes.js';
|
|
10
10
|
/**
|
|
11
11
|
* Create a simplified sync server with sync and optional console routes.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
15
|
-
* // With
|
|
15
|
+
* // With sync contract
|
|
16
16
|
* const { syncRoutes } = createSyncServer({
|
|
17
17
|
* db,
|
|
18
18
|
* dialect,
|
|
19
|
-
*
|
|
20
|
-
* authenticate: async (c) => {
|
|
21
|
-
* const userId = c.req.header('x-user-id');
|
|
22
|
-
* return userId ? { actorId: userId } : null;
|
|
23
|
-
* },
|
|
19
|
+
* sync,
|
|
24
20
|
* });
|
|
25
21
|
*
|
|
26
22
|
* // With custom handlers
|
|
27
23
|
* const { syncRoutes, consoleRoutes } = createSyncServer({
|
|
28
24
|
* db,
|
|
29
25
|
* dialect,
|
|
30
|
-
*
|
|
31
|
-
* authenticate: async (c) => {
|
|
32
|
-
* const userId = c.req.header('x-user-id');
|
|
33
|
-
* return userId ? { actorId: userId } : null;
|
|
34
|
-
* },
|
|
26
|
+
* sync,
|
|
35
27
|
* console: { token: process.env.CONSOLE_TOKEN },
|
|
36
28
|
* });
|
|
37
29
|
* ```
|
|
38
30
|
*/
|
|
39
31
|
export function createSyncServer(options) {
|
|
40
|
-
const { db, dialect,
|
|
41
|
-
if (handlers.length === 0) {
|
|
32
|
+
const { db, dialect, sync, chunkStorage, scopeCache, routes, upgradeWebSocket, console: consoleConfig, } = options;
|
|
33
|
+
if (sync.handlers.length === 0) {
|
|
42
34
|
throw new Error('At least one handler must be provided');
|
|
43
35
|
}
|
|
44
36
|
const resolvedConsoleConfig = consoleConfig === false || consoleConfig === undefined
|
|
@@ -54,28 +46,33 @@ export function createSyncServer(options) {
|
|
|
54
46
|
const consoleEventEmitter = isConsoleEnabled
|
|
55
47
|
? createConsoleEventEmitter()
|
|
56
48
|
: undefined;
|
|
49
|
+
const consoleSchemaReady = isConsoleEnabled && dialect.ensureConsoleSchema
|
|
50
|
+
? dialect.ensureConsoleSchema(db)
|
|
51
|
+
: undefined;
|
|
57
52
|
// Create sync routes
|
|
58
53
|
const syncRoutes = createSyncRoutes({
|
|
59
54
|
db,
|
|
60
55
|
dialect,
|
|
61
|
-
handlers,
|
|
62
|
-
authenticate,
|
|
56
|
+
handlers: sync.handlers,
|
|
57
|
+
authenticate: async (context) => sync.authenticate(context.req.raw),
|
|
63
58
|
chunkStorage,
|
|
59
|
+
scopeCache,
|
|
64
60
|
consoleLiveEmitter: consoleEventEmitter,
|
|
61
|
+
consoleSchemaReady,
|
|
65
62
|
sync: {
|
|
66
|
-
...
|
|
63
|
+
...routes,
|
|
67
64
|
websocket: upgradeWebSocket
|
|
68
65
|
? {
|
|
69
66
|
enabled: true,
|
|
70
67
|
upgradeWebSocket,
|
|
71
|
-
...(
|
|
72
|
-
heartbeatIntervalMs:
|
|
68
|
+
...(routes?.websocket?.heartbeatIntervalMs !== undefined && {
|
|
69
|
+
heartbeatIntervalMs: routes.websocket.heartbeatIntervalMs,
|
|
73
70
|
}),
|
|
74
|
-
...(
|
|
75
|
-
maxConnectionsTotal:
|
|
71
|
+
...(routes?.websocket?.maxConnectionsTotal !== undefined && {
|
|
72
|
+
maxConnectionsTotal: routes.websocket.maxConnectionsTotal,
|
|
76
73
|
}),
|
|
77
|
-
...(
|
|
78
|
-
maxConnectionsPerClient:
|
|
74
|
+
...(routes?.websocket?.maxConnectionsPerClient !== undefined && {
|
|
75
|
+
maxConnectionsPerClient: routes.websocket.maxConnectionsPerClient,
|
|
79
76
|
}),
|
|
80
77
|
}
|
|
81
78
|
: { enabled: false },
|
|
@@ -88,12 +85,15 @@ export function createSyncServer(options) {
|
|
|
88
85
|
const consoleRoutes = createConsoleRoutes({
|
|
89
86
|
db,
|
|
90
87
|
dialect,
|
|
91
|
-
handlers,
|
|
88
|
+
handlers: sync.handlers,
|
|
92
89
|
authenticate: createTokenAuthenticator(consoleToken),
|
|
93
|
-
corsOrigins: resolvedConsoleConfig.corsOrigins
|
|
90
|
+
corsOrigins: resolvedConsoleConfig.corsOrigins,
|
|
94
91
|
eventEmitter: consoleEventEmitter,
|
|
92
|
+
consoleSchemaReady,
|
|
95
93
|
wsConnectionManager: getSyncWebSocketConnectionManager(syncRoutes),
|
|
96
94
|
metrics: resolvedConsoleConfig.metrics,
|
|
95
|
+
maintenance: resolvedConsoleConfig.maintenance,
|
|
96
|
+
blobBucket: resolvedConsoleConfig.blobBucket,
|
|
97
97
|
...(upgradeWebSocket && {
|
|
98
98
|
websocket: {
|
|
99
99
|
enabled: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server.js","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"create-server.js","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,kB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AE,qBAAqB,CAAC,WAAW;QAC9C,UAAU,EAAE,qBAAqB,CAAC,UAAU;QAC5C,GAAG,CAAC,gBAAgB,IAAI;YACtB,SAAS,EAAE;gBACT,OAAO,EAAE,IAAI;gBACb,gBAAgB;aACjB;SACF,CAAC;KACH,CAAC,CAAC;IAEH,OAAO;QACL,UAAU;QACV,aAAa;QACb,mBAAmB;KACpB,CAAC;AAAA,CACH"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Manages WebSocket connections for the proxy.
|
|
5
5
|
*/
|
|
6
6
|
import type { ProxyHandshake, ProxyMessage, ProxyResponse } from '@syncular/core';
|
|
7
|
-
import type {
|
|
7
|
+
import type { ProxyHandlerCollection, ServerSyncDialect, SyncCoreDb } from '@syncular/server';
|
|
8
8
|
import type { WSContext } from 'hono/ws';
|
|
9
9
|
import type { Kysely, Transaction } from 'kysely';
|
|
10
10
|
export interface ProxyConnectionManagerConfig<DB extends SyncCoreDb = SyncCoreDb> {
|
|
@@ -12,8 +12,8 @@ export interface ProxyConnectionManagerConfig<DB extends SyncCoreDb = SyncCoreDb
|
|
|
12
12
|
db: Kysely<DB>;
|
|
13
13
|
/** Server sync dialect */
|
|
14
14
|
dialect: ServerSyncDialect;
|
|
15
|
-
/** Proxy table
|
|
16
|
-
handlers:
|
|
15
|
+
/** Proxy table handlers for oplog generation */
|
|
16
|
+
handlers: ProxyHandlerCollection;
|
|
17
17
|
/** Maximum concurrent connections (default: 100) */
|
|
18
18
|
maxConnections?: number;
|
|
19
19
|
/** Idle connection timeout in ms (default: 30000) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../src/proxy/connection-manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"connection-manager.d.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AAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAS;IAE/B,YAAY,MAAM,EAAE,4BAA4B,CAAC,EAAE,CAAC,EAInD;IAED;;OAEG;IACH,SAAS,IAAI,OAAO,CAEnB;IAED;;OAEG;IACH,kBAAkB,IAAI,MAAM,CAE3B;IAED;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAc3E;IAED;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,SAAS,GAAG,oBAAoB,CAAC,EAAE,CAAC,GAAG,SAAS,CAEvD;IAED;;OAEG;IACG,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB7C;IAED;;OAEG;IACG,aAAa,CACjB,EAAE,EAAE,SAAS,EACb,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,aAAa,CAAC,CA0CxB;YAEa,WAAW;YAoCX,YAAY;YA2BZ,cAAc;YA2Bd,WAAW;IAkCzB,OAAO,CAAC,cAAc;IAkBtB;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAa9B;CACF"}
|
package/dist/proxy/routes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* WebSocket endpoint for database proxy.
|
|
5
5
|
*/
|
|
6
6
|
import type { ProxyHandshake, ProxyMessage, ProxyResponse } from '@syncular/core';
|
|
7
|
-
import type {
|
|
7
|
+
import type { ProxyHandlerCollection, ServerSyncDialect, SyncCoreDb } from '@syncular/server';
|
|
8
8
|
import type { Context } from 'hono';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
10
|
import type { UpgradeWebSocket, WSContext } from 'hono/ws';
|
|
@@ -28,8 +28,8 @@ interface CreateProxyRoutesConfig<DB extends SyncCoreDb = SyncCoreDb> {
|
|
|
28
28
|
db: Kysely<DB>;
|
|
29
29
|
/** Server sync dialect */
|
|
30
30
|
dialect: ServerSyncDialect;
|
|
31
|
-
/** Proxy table
|
|
32
|
-
handlers:
|
|
31
|
+
/** Proxy table handlers for oplog generation */
|
|
32
|
+
handlers: ProxyHandlerCollection;
|
|
33
33
|
/** Authenticate the request and return actor info */
|
|
34
34
|
authenticate: (c: Context) => Promise<ProxyAuthResult | null>;
|
|
35
35
|
/** WebSocket upgrade function from Hono */
|
|
@@ -54,7 +54,7 @@ interface CreateProxyRoutesConfig<DB extends SyncCoreDb = SyncCoreDb> {
|
|
|
54
54
|
*
|
|
55
55
|
* app.route('/proxy', createProxyRoutes({
|
|
56
56
|
* db,
|
|
57
|
-
* handlers:
|
|
57
|
+
* handlers: proxyHandlers,
|
|
58
58
|
* authenticate: async (c) => {
|
|
59
59
|
* // Verify admin auth
|
|
60
60
|
* return { actorId: 'admin:123' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/proxy/routes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EAEd,YAAY,EACZ,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/proxy/routes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EAEd,YAAY,EACZ,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EA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= new WeakMap();
|
|
|
22
22
|
*
|
|
23
23
|
* app.route('/proxy', createProxyRoutes({
|
|
24
24
|
* db,
|
|
25
|
-
* handlers:
|
|
25
|
+
* handlers: proxyHandlers,
|
|
26
26
|
* authenticate: async (c) => {
|
|
27
27
|
* // Verify admin auth
|
|
28
28
|
* return { actorId: 'admin:123' };
|
package/dist/routes.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - GET /snapshot-chunks/:chunkId (download encoded snapshot chunks)
|
|
7
7
|
* - GET /realtime (optional WebSocket "wake up" notifications)
|
|
8
8
|
*/
|
|
9
|
-
import type { ServerSyncDialect, ServerTableHandler, SnapshotChunkStorage, SyncCoreDb, SyncRealtimeBroadcaster } from '@syncular/server';
|
|
9
|
+
import type { ScopeCacheBackend, ServerSyncDialect, ServerTableHandler, SnapshotChunkStorage, SqlFamily, SyncCoreDb, SyncRealtimeBroadcaster, SyncServerAuth } from '@syncular/server';
|
|
10
10
|
import { type CompactOptions, type PruneOptions } from '@syncular/server';
|
|
11
11
|
import type { Context } from 'hono';
|
|
12
12
|
import { Hono } from 'hono';
|
|
@@ -14,9 +14,7 @@ import type { UpgradeWebSocket } from 'hono/ws';
|
|
|
14
14
|
import { type Kysely } from 'kysely';
|
|
15
15
|
import { type SyncRateLimitConfig } from './rate-limit';
|
|
16
16
|
import { WebSocketConnectionManager } from './ws';
|
|
17
|
-
export interface SyncAuthResult {
|
|
18
|
-
actorId: string;
|
|
19
|
-
partitionId?: string;
|
|
17
|
+
export interface SyncAuthResult extends SyncServerAuth {
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* WebSocket configuration for realtime sync.
|
|
@@ -67,6 +65,22 @@ export interface SyncRoutesConfigWithRateLimit {
|
|
|
67
65
|
* Default: 200
|
|
68
66
|
*/
|
|
69
67
|
maxOperationsPerPush?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Request/response payload snapshots recorded for console inspection.
|
|
70
|
+
*/
|
|
71
|
+
requestPayloadSnapshots?: {
|
|
72
|
+
/**
|
|
73
|
+
* Enable payload snapshot storage in `sync_request_payloads`.
|
|
74
|
+
* Default: true when console event recording is enabled.
|
|
75
|
+
*/
|
|
76
|
+
enabled?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Max serialized payload size in bytes per request/response snapshot.
|
|
79
|
+
* Larger payloads are truncated with metadata.
|
|
80
|
+
* Default: 128 KiB.
|
|
81
|
+
*/
|
|
82
|
+
maxBytes?: number;
|
|
83
|
+
};
|
|
70
84
|
/**
|
|
71
85
|
* Rate limiting configuration.
|
|
72
86
|
* Set to false to disable all rate limiting.
|
|
@@ -106,11 +120,11 @@ export interface SyncRoutesConfigWithRateLimit {
|
|
|
106
120
|
instanceId?: string;
|
|
107
121
|
};
|
|
108
122
|
}
|
|
109
|
-
export interface CreateSyncRoutesOptions<DB extends SyncCoreDb = SyncCoreDb> {
|
|
123
|
+
export interface CreateSyncRoutesOptions<DB extends SyncCoreDb = SyncCoreDb, Auth extends SyncAuthResult = SyncAuthResult, F extends SqlFamily = SqlFamily> {
|
|
110
124
|
db: Kysely<DB>;
|
|
111
|
-
dialect: ServerSyncDialect
|
|
112
|
-
handlers: ServerTableHandler<DB>[];
|
|
113
|
-
authenticate: (c: Context) => Promise<
|
|
125
|
+
dialect: ServerSyncDialect<F>;
|
|
126
|
+
handlers: ServerTableHandler<DB, Auth>[];
|
|
127
|
+
authenticate: (c: Context) => Promise<Auth | null>;
|
|
114
128
|
sync?: SyncRoutesConfigWithRateLimit;
|
|
115
129
|
wsConnectionManager?: WebSocketConnectionManager;
|
|
116
130
|
/**
|
|
@@ -119,6 +133,11 @@ export interface CreateSyncRoutesOptions<DB extends SyncCoreDb = SyncCoreDb> {
|
|
|
119
133
|
* (S3, R2, etc.) instead of inline in the database.
|
|
120
134
|
*/
|
|
121
135
|
chunkStorage?: SnapshotChunkStorage;
|
|
136
|
+
/**
|
|
137
|
+
* Optional scope cache backend for resolveScopes() results.
|
|
138
|
+
* Request-local memoization is always applied for every pull.
|
|
139
|
+
*/
|
|
140
|
+
scopeCache?: ScopeCacheBackend;
|
|
122
141
|
/**
|
|
123
142
|
* Optional live emitter for console websocket activity feed.
|
|
124
143
|
* When provided, sync lifecycle events are published to `/console/events/live`.
|
|
@@ -130,8 +149,13 @@ export interface CreateSyncRoutesOptions<DB extends SyncCoreDb = SyncCoreDb> {
|
|
|
130
149
|
data: Record<string, unknown>;
|
|
131
150
|
}): void;
|
|
132
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Optional console schema readiness promise.
|
|
154
|
+
* When provided, request-event recording waits for this promise before writing.
|
|
155
|
+
*/
|
|
156
|
+
consoleSchemaReady?: Promise<void>;
|
|
133
157
|
}
|
|
134
|
-
export declare function createSyncRoutes<DB extends SyncCoreDb = SyncCoreDb>(options: CreateSyncRoutesOptions<DB>): Hono;
|
|
158
|
+
export declare function createSyncRoutes<DB extends SyncCoreDb = SyncCoreDb, Auth extends SyncAuthResult = SyncAuthResult, F extends SqlFamily = SqlFamily>(options: CreateSyncRoutesOptions<DB, Auth, F>): Hono;
|
|
135
159
|
export declare function getSyncWebSocketConnectionManager(routes: Hono): WebSocketConnectionManager | undefined;
|
|
136
160
|
export declare function getSyncRealtimeUnsubscribe(routes: Hono): (() => void) | undefined;
|
|
137
161
|
//# sourceMappingURL=routes.d.ts.map
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,uBAAuB,EAEvB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL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