@syncular/server-hono 0.0.1-60
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/api-key-auth.d.ts +49 -0
- package/dist/api-key-auth.d.ts.map +1 -0
- package/dist/api-key-auth.js +110 -0
- package/dist/api-key-auth.js.map +1 -0
- package/dist/blobs.d.ts +69 -0
- package/dist/blobs.d.ts.map +1 -0
- package/dist/blobs.js +383 -0
- package/dist/blobs.js.map +1 -0
- package/dist/console/index.d.ts +8 -0
- package/dist/console/index.d.ts.map +1 -0
- package/dist/console/index.js +7 -0
- package/dist/console/index.js.map +1 -0
- package/dist/console/routes.d.ts +106 -0
- package/dist/console/routes.d.ts.map +1 -0
- package/dist/console/routes.js +1612 -0
- package/dist/console/routes.js.map +1 -0
- package/dist/console/schemas.d.ts +308 -0
- package/dist/console/schemas.d.ts.map +1 -0
- package/dist/console/schemas.js +201 -0
- package/dist/console/schemas.js.map +1 -0
- package/dist/create-server.d.ts +78 -0
- package/dist/create-server.d.ts.map +1 -0
- package/dist/create-server.js +99 -0
- package/dist/create-server.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +45 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +59 -0
- package/dist/openapi.js.map +1 -0
- package/dist/proxy/connection-manager.d.ts +78 -0
- package/dist/proxy/connection-manager.d.ts.map +1 -0
- package/dist/proxy/connection-manager.js +251 -0
- package/dist/proxy/connection-manager.js.map +1 -0
- package/dist/proxy/index.d.ts +8 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +8 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/proxy/routes.d.ts +74 -0
- package/dist/proxy/routes.d.ts.map +1 -0
- package/dist/proxy/routes.js +147 -0
- package/dist/proxy/routes.js.map +1 -0
- package/dist/rate-limit.d.ts +101 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +186 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/routes.d.ts +126 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +788 -0
- package/dist/routes.js.map +1 -0
- package/dist/ws.d.ts +230 -0
- package/dist/ws.d.ts.map +1 -0
- package/dist/ws.js +601 -0
- package/dist/ws.js.map +1 -0
- package/package.json +73 -0
- package/src/__tests__/create-server.test.ts +187 -0
- package/src/__tests__/pull-chunk-storage.test.ts +189 -0
- package/src/__tests__/rate-limit.test.ts +78 -0
- package/src/__tests__/realtime-bridge.test.ts +131 -0
- package/src/__tests__/ws-connection-manager.test.ts +176 -0
- package/src/api-key-auth.ts +179 -0
- package/src/blobs.ts +534 -0
- package/src/console/index.ts +17 -0
- package/src/console/routes.ts +2155 -0
- package/src/console/schemas.ts +299 -0
- package/src/create-server.ts +180 -0
- package/src/index.ts +42 -0
- package/src/openapi.ts +74 -0
- package/src/proxy/connection-manager.ts +340 -0
- package/src/proxy/index.ts +8 -0
- package/src/proxy/routes.ts +223 -0
- package/src/rate-limit.ts +321 -0
- package/src/routes.ts +1186 -0
- package/src/ws.ts +789 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simplified server factory for Hono
|
|
3
|
+
*
|
|
4
|
+
* Breaking changes from legacy createSyncRoutes:
|
|
5
|
+
* - handlers: array instead of TableRegistry
|
|
6
|
+
* - Combined sync + console routes in one call
|
|
7
|
+
*/
|
|
8
|
+
import type { ServerSyncDialect, ServerTableHandler, SyncCoreDb } from '@syncular/server';
|
|
9
|
+
import type { Context } from 'hono';
|
|
10
|
+
import type { UpgradeWebSocket } from 'hono/ws';
|
|
11
|
+
import type { Kysely } from 'kysely';
|
|
12
|
+
import { type ConsoleEventEmitter, createConsoleRoutes } from './console';
|
|
13
|
+
import { createSyncRoutes, type SyncAuthResult, type SyncRoutesConfigWithRateLimit } from './routes';
|
|
14
|
+
export interface SyncServerOptions<DB extends SyncCoreDb = SyncCoreDb> {
|
|
15
|
+
/** Kysely database instance */
|
|
16
|
+
db: Kysely<DB>;
|
|
17
|
+
/** Server sync dialect */
|
|
18
|
+
dialect: ServerSyncDialect;
|
|
19
|
+
/**
|
|
20
|
+
* Table handlers for sync operations.
|
|
21
|
+
*/
|
|
22
|
+
handlers: ServerTableHandler<DB>[];
|
|
23
|
+
/** Authentication function - returns actorId or null for unauthenticated */
|
|
24
|
+
authenticate: (c: Context) => Promise<SyncAuthResult | null>;
|
|
25
|
+
/** Sync route configuration */
|
|
26
|
+
sync?: SyncRoutesConfigWithRateLimit;
|
|
27
|
+
/** WebSocket upgrader for realtime */
|
|
28
|
+
upgradeWebSocket?: UpgradeWebSocket;
|
|
29
|
+
/**
|
|
30
|
+
* Console configuration for dashboard/monitoring.
|
|
31
|
+
* Omit or set to false to disable console routes.
|
|
32
|
+
*/
|
|
33
|
+
console?: false | {
|
|
34
|
+
/** Console bearer token for authentication (required unless SYNC_CONSOLE_TOKEN is set) */
|
|
35
|
+
token?: string;
|
|
36
|
+
/** CORS origins (defaults to '*') */
|
|
37
|
+
corsOrigins?: '*' | string[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface SyncServerResult {
|
|
41
|
+
/** Sync routes for Hono */
|
|
42
|
+
syncRoutes: ReturnType<typeof createSyncRoutes>;
|
|
43
|
+
/** Console routes for Hono (if enabled) */
|
|
44
|
+
consoleRoutes?: ReturnType<typeof createConsoleRoutes>;
|
|
45
|
+
/** Console event emitter (if console enabled) */
|
|
46
|
+
consoleEventEmitter?: ConsoleEventEmitter;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a simplified sync server with sync and optional console routes.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // With handlers
|
|
54
|
+
* const { syncRoutes } = createSyncServer({
|
|
55
|
+
* db,
|
|
56
|
+
* dialect,
|
|
57
|
+
* handlers: [tasksHandler, notesHandler],
|
|
58
|
+
* authenticate: async (c) => {
|
|
59
|
+
* const userId = c.req.header('x-user-id');
|
|
60
|
+
* return userId ? { actorId: userId } : null;
|
|
61
|
+
* },
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // With custom handlers
|
|
65
|
+
* const { syncRoutes, consoleRoutes } = createSyncServer({
|
|
66
|
+
* db,
|
|
67
|
+
* dialect,
|
|
68
|
+
* handlers: [tasksHandler, notesHandler],
|
|
69
|
+
* authenticate: async (c) => {
|
|
70
|
+
* const userId = c.req.header('x-user-id');
|
|
71
|
+
* return userId ? { actorId: userId } : null;
|
|
72
|
+
* },
|
|
73
|
+
* console: { token: process.env.CONSOLE_TOKEN },
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function createSyncServer<DB extends SyncCoreDb = SyncCoreDb>(options: SyncServerOptions<DB>): SyncServerResult;
|
|
78
|
+
//# sourceMappingURL=create-server.d.ts.map
|
|
@@ -0,0 +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,kBAAkB,EAClB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EACL,KAAK,mBAAmB,EAExB,mBAAmB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,gBAAgB,EAEhB,KAAK,cAAc,EACnB,KAAK,6BAA6B,EACnC,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,iBAAiB,CAAC,EAAE,SAAS,UAAU,GAAG,UAAU;IACnE,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAEf,0BAA0B;IAC1B,OAAO,EAAE,iBAAiB,CAAC;IAE3B;;OAEG;IACH,QAAQ,EAAE,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;IAEnC,4EAA4E;IAC5E,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAE7D,+BAA+B;IAC/B,IAAI,CAAC,EAAE,6BAA6B,CAAC;IAErC,sCAAsC;IACtC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;OAGG;IACH,OAAO,CAAC,EACJ,KAAK,GACL;QACE,0FAA0F;QAC1F,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,qCAAqC;QACrC,WAAW,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAAC;KAC9B,CAAC;CACP;AAED,MAAM,WAAW,gBAAgB;IAC/B,2BAA2B;IAC3B,UAAU,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;IAChD,2CAA2C;IAC3C,aAAa,CAAC,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;IACvD,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,UAAU,GAAG,UAAU,EACjE,OAAO,EAAE,iBAAiB,CAAC,EAAE,CAAC,GAC7B,gBAAgB,CA2ElB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simplified server factory for Hono
|
|
3
|
+
*
|
|
4
|
+
* Breaking changes from legacy createSyncRoutes:
|
|
5
|
+
* - handlers: array instead of TableRegistry
|
|
6
|
+
* - Combined sync + console routes in one call
|
|
7
|
+
*/
|
|
8
|
+
import { createConsoleEventEmitter, createConsoleRoutes, createTokenAuthenticator, } from './console';
|
|
9
|
+
import { createSyncRoutes, getSyncWebSocketConnectionManager, } from './routes';
|
|
10
|
+
/**
|
|
11
|
+
* Create a simplified sync server with sync and optional console routes.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // With handlers
|
|
16
|
+
* const { syncRoutes } = createSyncServer({
|
|
17
|
+
* db,
|
|
18
|
+
* dialect,
|
|
19
|
+
* handlers: [tasksHandler, notesHandler],
|
|
20
|
+
* authenticate: async (c) => {
|
|
21
|
+
* const userId = c.req.header('x-user-id');
|
|
22
|
+
* return userId ? { actorId: userId } : null;
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // With custom handlers
|
|
27
|
+
* const { syncRoutes, consoleRoutes } = createSyncServer({
|
|
28
|
+
* db,
|
|
29
|
+
* dialect,
|
|
30
|
+
* handlers: [tasksHandler, notesHandler],
|
|
31
|
+
* authenticate: async (c) => {
|
|
32
|
+
* const userId = c.req.header('x-user-id');
|
|
33
|
+
* return userId ? { actorId: userId } : null;
|
|
34
|
+
* },
|
|
35
|
+
* console: { token: process.env.CONSOLE_TOKEN },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function createSyncServer(options) {
|
|
40
|
+
const { db, dialect, handlers, authenticate, sync, upgradeWebSocket, console: consoleConfig, } = options;
|
|
41
|
+
if (handlers.length === 0) {
|
|
42
|
+
throw new Error('At least one handler must be provided');
|
|
43
|
+
}
|
|
44
|
+
// Create sync routes
|
|
45
|
+
const syncRoutes = createSyncRoutes({
|
|
46
|
+
db,
|
|
47
|
+
dialect,
|
|
48
|
+
handlers,
|
|
49
|
+
authenticate,
|
|
50
|
+
sync: {
|
|
51
|
+
...sync,
|
|
52
|
+
websocket: upgradeWebSocket
|
|
53
|
+
? {
|
|
54
|
+
enabled: true,
|
|
55
|
+
upgradeWebSocket,
|
|
56
|
+
...(sync?.websocket?.heartbeatIntervalMs !== undefined && {
|
|
57
|
+
heartbeatIntervalMs: sync.websocket.heartbeatIntervalMs,
|
|
58
|
+
}),
|
|
59
|
+
...(sync?.websocket?.maxConnectionsTotal !== undefined && {
|
|
60
|
+
maxConnectionsTotal: sync.websocket.maxConnectionsTotal,
|
|
61
|
+
}),
|
|
62
|
+
...(sync?.websocket?.maxConnectionsPerClient !== undefined && {
|
|
63
|
+
maxConnectionsPerClient: sync.websocket.maxConnectionsPerClient,
|
|
64
|
+
}),
|
|
65
|
+
}
|
|
66
|
+
: { enabled: false },
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
// Console is opt-in; disable unless explicitly configured.
|
|
70
|
+
if (!consoleConfig) {
|
|
71
|
+
return { syncRoutes };
|
|
72
|
+
}
|
|
73
|
+
const consoleToken = consoleConfig.token ?? process.env.SYNC_CONSOLE_TOKEN;
|
|
74
|
+
if (!consoleToken) {
|
|
75
|
+
throw new Error('Console is enabled but no token is configured. Set `console.token` or SYNC_CONSOLE_TOKEN.');
|
|
76
|
+
}
|
|
77
|
+
const consoleEventEmitter = createConsoleEventEmitter();
|
|
78
|
+
const consoleRoutes = createConsoleRoutes({
|
|
79
|
+
db,
|
|
80
|
+
dialect,
|
|
81
|
+
handlers,
|
|
82
|
+
authenticate: createTokenAuthenticator(consoleToken),
|
|
83
|
+
corsOrigins: consoleConfig.corsOrigins ?? '*',
|
|
84
|
+
eventEmitter: consoleEventEmitter,
|
|
85
|
+
wsConnectionManager: getSyncWebSocketConnectionManager(syncRoutes),
|
|
86
|
+
...(upgradeWebSocket && {
|
|
87
|
+
websocket: {
|
|
88
|
+
enabled: true,
|
|
89
|
+
upgradeWebSocket,
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
syncRoutes,
|
|
95
|
+
consoleRoutes,
|
|
96
|
+
consoleEventEmitter,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=create-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-server.js","sourceRoot":"","sources":["../src/create-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,EAEL,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,gBAAgB,EAChB,iCAAiC,GAGlC,MAAM,UAAU,CAAC;AA8ClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA8B,EACZ;IAClB,MAAM,EACJ,EAAE,EACF,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,gBAAgB,EAChB,OAAO,EAAE,aAAa,GACvB,GAAG,OAAO,CAAC;IAEZ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,qBAAqB;IACrB,MAAM,UAAU,GAAG,gBAAgB,CAAC;QAClC,EAAE;QACF,OAAO;QACP,QAAQ;QACR,YAAY;QACZ,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,SAAS,EAAE,gBAAgB;gBACzB,CAAC,CAAC;oBACE,OAAO,EAAE,IAAI;oBACb,gBAAgB;oBAChB,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,mBAAmB,KAAK,SAAS,IAAI;wBACxD,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB;qBACxD,CAAC;oBACF,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,mBAAmB,KAAK,SAAS,IAAI;wBACxD,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB;qBACxD,CAAC;oBACF,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,uBAAuB,KAAK,SAAS,IAAI;wBAC5D,uBAAuB,EAAE,IAAI,CAAC,SAAS,CAAC,uBAAuB;qBAChE,CAAC;iBACH;gBACH,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE;SACvB;KACF,CAAC,CAAC;IAEH,2DAA2D;IAC3D,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;IAED,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC3E,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IACD,MAAM,mBAAmB,GAAG,yBAAyB,EAAE,CAAC;IAExD,MAAM,aAAa,GAAG,mBAAmB,CAAC;QACxC,EAAE;QACF,OAAO;QACP,QAAQ;QACR,YAAY,EAAE,wBAAwB,CAAC,YAAY,CAAC;QACpD,WAAW,EAAE,aAAa,CAAC,WAAW,IAAI,GAAG;QAC7C,YAAY,EAAE,mBAAmB;QACjC,mBAAmB,EAAE,iCAAiC,CAAC,UAAU,CAAC;QAClE,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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server-hono - Hono adapter for sync infrastructure
|
|
3
|
+
*
|
|
4
|
+
* This package provides Hono-specific routes for @syncular/server.
|
|
5
|
+
* Keeps @syncular/server framework-agnostic.
|
|
6
|
+
*/
|
|
7
|
+
export * from './api-key-auth';
|
|
8
|
+
export { type CreateBlobRoutesOptions, createBlobRoutes } from './blobs';
|
|
9
|
+
export * from './console';
|
|
10
|
+
export { createSyncServer, type SyncServerOptions, type SyncServerResult, } from './create-server';
|
|
11
|
+
export * from './openapi';
|
|
12
|
+
export * from './proxy';
|
|
13
|
+
export * from './rate-limit';
|
|
14
|
+
export { type CreateSyncRoutesOptions, createSyncRoutes, getSyncRealtimeUnsubscribe, getSyncWebSocketConnectionManager, } from './routes';
|
|
15
|
+
export * from './ws';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EAAE,KAAK,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGzE,cAAc,WAAW,CAAC;AAG1B,OAAO,EACL,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,cAAc,WAAW,CAAC;AAG1B,cAAc,SAAS,CAAC;AAGxB,cAAc,cAAc,CAAC;AAG7B,OAAO,EACL,KAAK,uBAAuB,EAC5B,gBAAgB,EAChB,0BAA0B,EAC1B,iCAAiC,GAClC,MAAM,UAAU,CAAC;AAGlB,cAAc,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server-hono - Hono adapter for sync infrastructure
|
|
3
|
+
*
|
|
4
|
+
* This package provides Hono-specific routes for @syncular/server.
|
|
5
|
+
* Keeps @syncular/server framework-agnostic.
|
|
6
|
+
*/
|
|
7
|
+
// API Key Auth
|
|
8
|
+
export * from './api-key-auth';
|
|
9
|
+
// Blob routes
|
|
10
|
+
export { createBlobRoutes } from './blobs';
|
|
11
|
+
// Console
|
|
12
|
+
export * from './console';
|
|
13
|
+
// Simplified server factory
|
|
14
|
+
export { createSyncServer, } from './create-server';
|
|
15
|
+
// OpenAPI utilities
|
|
16
|
+
export * from './openapi';
|
|
17
|
+
// Proxy
|
|
18
|
+
export * from './proxy';
|
|
19
|
+
// Rate limiting
|
|
20
|
+
export * from './rate-limit';
|
|
21
|
+
// Route types and factory
|
|
22
|
+
export { createSyncRoutes, getSyncRealtimeUnsubscribe, getSyncWebSocketConnectionManager, } from './routes';
|
|
23
|
+
// WebSocket helpers for realtime sync
|
|
24
|
+
export * from './ws';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAe;AACf,cAAc,gBAAgB,CAAC;AAE/B,cAAc;AACd,OAAO,EAAgC,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEzE,UAAU;AACV,cAAc,WAAW,CAAC;AAE1B,4BAA4B;AAC5B,OAAO,EACL,gBAAgB,GAGjB,MAAM,iBAAiB,CAAC;AAEzB,oBAAoB;AACpB,cAAc,WAAW,CAAC;AAE1B,QAAQ;AACR,cAAc,SAAS,CAAC;AAExB,gBAAgB;AAChB,cAAc,cAAc,CAAC;AAE7B,0BAA0B;AAC1B,OAAO,EAEL,gBAAgB,EAChB,0BAA0B,EAC1B,iCAAiC,GAClC,MAAM,UAAU,CAAC;AAElB,sCAAsC;AACtC,cAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server-hono - OpenAPI Spec Export
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for generating and serving OpenAPI specifications.
|
|
5
|
+
*/
|
|
6
|
+
import type { Hono } from 'hono';
|
|
7
|
+
interface OpenAPIConfig {
|
|
8
|
+
title?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
servers?: Array<{
|
|
12
|
+
url: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create an OpenAPI spec handler that can be used with Hono routes.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { Hono } from 'hono';
|
|
22
|
+
* import { createSyncRoutes, createConsoleRoutes, createOpenAPIHandler } from '@syncular/server-hono';
|
|
23
|
+
*
|
|
24
|
+
* const app = new Hono();
|
|
25
|
+
* const syncRoutes = createSyncRoutes({ ... });
|
|
26
|
+
* const consoleRoutes = createConsoleRoutes({ ... });
|
|
27
|
+
*
|
|
28
|
+
* app.route('/sync', syncRoutes);
|
|
29
|
+
* app.route('/console', consoleRoutes);
|
|
30
|
+
*
|
|
31
|
+
* // Add OpenAPI spec endpoint
|
|
32
|
+
* app.get('/openapi.json', createOpenAPIHandler(app, {
|
|
33
|
+
* title: 'Syncular API',
|
|
34
|
+
* version: '1.0.0',
|
|
35
|
+
* }));
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function createOpenAPIHandler(app: Hono, config?: OpenAPIConfig): import("hono").MiddlewareHandler<import("hono/types").BlankEnv, "/", import("hono/types").BlankInput>;
|
|
39
|
+
/**
|
|
40
|
+
* Generate OpenAPI document from a Hono app instance.
|
|
41
|
+
* This is useful for build-time spec generation.
|
|
42
|
+
*/
|
|
43
|
+
export declare function generateOpenAPIDocument(app: Hono, config?: OpenAPIConfig): Promise<unknown>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,UAAU,aAAa;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,GAAE,aAAkB,yGAazE;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,IAAI,EACT,MAAM,GAAE,aAAkB,GACzB,OAAO,CAAC,OAAO,CAAC,CAalB"}
|
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server-hono - OpenAPI Spec Export
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for generating and serving OpenAPI specifications.
|
|
5
|
+
*/
|
|
6
|
+
import { generateSpecs, openAPIRouteHandler } from 'hono-openapi';
|
|
7
|
+
/**
|
|
8
|
+
* Create an OpenAPI spec handler that can be used with Hono routes.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { Hono } from 'hono';
|
|
13
|
+
* import { createSyncRoutes, createConsoleRoutes, createOpenAPIHandler } from '@syncular/server-hono';
|
|
14
|
+
*
|
|
15
|
+
* const app = new Hono();
|
|
16
|
+
* const syncRoutes = createSyncRoutes({ ... });
|
|
17
|
+
* const consoleRoutes = createConsoleRoutes({ ... });
|
|
18
|
+
*
|
|
19
|
+
* app.route('/sync', syncRoutes);
|
|
20
|
+
* app.route('/console', consoleRoutes);
|
|
21
|
+
*
|
|
22
|
+
* // Add OpenAPI spec endpoint
|
|
23
|
+
* app.get('/openapi.json', createOpenAPIHandler(app, {
|
|
24
|
+
* title: 'Syncular API',
|
|
25
|
+
* version: '1.0.0',
|
|
26
|
+
* }));
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function createOpenAPIHandler(app, config = {}) {
|
|
30
|
+
return openAPIRouteHandler(app, {
|
|
31
|
+
documentation: {
|
|
32
|
+
info: {
|
|
33
|
+
title: config.title ?? 'Syncular API',
|
|
34
|
+
version: config.version ?? '1.0.0',
|
|
35
|
+
description: config.description ??
|
|
36
|
+
'Sync infrastructure API for real-time data synchronization',
|
|
37
|
+
},
|
|
38
|
+
servers: config.servers,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate OpenAPI document from a Hono app instance.
|
|
44
|
+
* This is useful for build-time spec generation.
|
|
45
|
+
*/
|
|
46
|
+
export async function generateOpenAPIDocument(app, config = {}) {
|
|
47
|
+
return generateSpecs(app, {
|
|
48
|
+
documentation: {
|
|
49
|
+
info: {
|
|
50
|
+
title: config.title ?? 'Syncular API',
|
|
51
|
+
version: config.version ?? '1.0.0',
|
|
52
|
+
description: config.description ??
|
|
53
|
+
'Sync infrastructure API for real-time data synchronization',
|
|
54
|
+
},
|
|
55
|
+
servers: config.servers,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=openapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AASlE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAS,EAAE,MAAM,GAAkB,EAAE,EAAE;IAC1E,OAAO,mBAAmB,CAAC,GAAG,EAAE;QAC9B,aAAa,EAAE;YACb,IAAI,EAAE;gBACJ,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,cAAc;gBACrC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO;gBAClC,WAAW,EACT,MAAM,CAAC,WAAW;oBAClB,4DAA4D;aAC/D;YACD,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB;KACF,CAAC,CAAC;AAAA,CACJ;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,GAAS,EACT,MAAM,GAAkB,EAAE,EACR;IAClB,OAAO,aAAa,CAAC,GAAG,EAAE;QACxB,aAAa,EAAE;YACb,IAAI,EAAE;gBACJ,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,cAAc;gBACrC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,OAAO;gBAClC,WAAW,EACT,MAAM,CAAC,WAAW;oBAClB,4DAA4D;aAC/D;YACD,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB;KACF,CAAC,CAAC;AAAA,CACJ"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server-hono - Proxy Connection Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages WebSocket connections for the proxy.
|
|
5
|
+
*/
|
|
6
|
+
import type { ProxyHandshake, ProxyMessage, ProxyResponse } from '@syncular/core';
|
|
7
|
+
import type { ProxyTableRegistry, ServerSyncDialect, SyncCoreDb } from '@syncular/server';
|
|
8
|
+
import type { WSContext } from 'hono/ws';
|
|
9
|
+
import type { Kysely, Transaction } from 'kysely';
|
|
10
|
+
export interface ProxyConnectionManagerConfig<DB extends SyncCoreDb = SyncCoreDb> {
|
|
11
|
+
/** Database connection */
|
|
12
|
+
db: Kysely<DB>;
|
|
13
|
+
/** Server sync dialect */
|
|
14
|
+
dialect: ServerSyncDialect;
|
|
15
|
+
/** Proxy table registry for oplog generation */
|
|
16
|
+
shapes: ProxyTableRegistry;
|
|
17
|
+
/** Maximum concurrent connections (default: 100) */
|
|
18
|
+
maxConnections?: number;
|
|
19
|
+
/** Idle connection timeout in ms (default: 30000) */
|
|
20
|
+
idleTimeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
interface ProxyConnectionState<DB extends SyncCoreDb> {
|
|
23
|
+
ws: WSContext;
|
|
24
|
+
actorId: string;
|
|
25
|
+
clientId: string;
|
|
26
|
+
transaction: Transaction<DB> | null;
|
|
27
|
+
lastActivity: number;
|
|
28
|
+
idleTimer: ReturnType<typeof setTimeout> | null;
|
|
29
|
+
/** Transaction promise resolve callback */
|
|
30
|
+
__resolveTransaction?: () => void;
|
|
31
|
+
/** Transaction promise reject callback */
|
|
32
|
+
__rejectTransaction?: (error: Error) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Manages proxy WebSocket connections and their state.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ProxyConnectionManager<DB extends SyncCoreDb = SyncCoreDb> {
|
|
38
|
+
private connections;
|
|
39
|
+
private config;
|
|
40
|
+
private idleTimeoutMs;
|
|
41
|
+
private maxConnections;
|
|
42
|
+
constructor(config: ProxyConnectionManagerConfig<DB>);
|
|
43
|
+
/**
|
|
44
|
+
* Check if a new connection can be accepted.
|
|
45
|
+
*/
|
|
46
|
+
canAccept(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Get the current connection count.
|
|
49
|
+
*/
|
|
50
|
+
getConnectionCount(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Handle the handshake message and register the connection.
|
|
53
|
+
*/
|
|
54
|
+
register(ws: WSContext, handshake: ProxyHandshake): ProxyConnectionState<DB>;
|
|
55
|
+
/**
|
|
56
|
+
* Get the connection state for a WebSocket.
|
|
57
|
+
*/
|
|
58
|
+
get(ws: WSContext): ProxyConnectionState<DB> | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Unregister and cleanup a connection.
|
|
61
|
+
*/
|
|
62
|
+
unregister(ws: WSContext): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Handle a proxy message and return the response.
|
|
65
|
+
*/
|
|
66
|
+
handleMessage(ws: WSContext, message: ProxyMessage): Promise<ProxyResponse>;
|
|
67
|
+
private handleBegin;
|
|
68
|
+
private handleCommit;
|
|
69
|
+
private handleRollback;
|
|
70
|
+
private handleQuery;
|
|
71
|
+
private resetIdleTimer;
|
|
72
|
+
/**
|
|
73
|
+
* Close all connections.
|
|
74
|
+
*/
|
|
75
|
+
closeAll(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=connection-manager.d.ts.map
|
|
@@ -0,0 +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,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAElD,MAAM,WAAW,4BAA4B,CAC3C,EAAE,SAAS,UAAU,GAAG,UAAU;IAElC,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACf,0BAA0B;IAC1B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,gDAAgD;IAChD,MAAM,EAAE,kBAAkB,CAAC;IAC3B,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,oBAAoB,CAAC,EAAE,SAAS,UAAU;IAClD,EAAE,EAAE,SAAS,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC;IAChD,2CAA2C;IAC3C,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,0CAA0C;IAC1C,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,qBAAa,sBAAsB,CAAC,EAAE,SAAS,UAAU,GAAG,UAAU;IACpE,OAAO,CAAC,WAAW,CAAkD;IACrE,OAAO,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"}
|