@syncular/server 0.0.6-96 → 0.1.1
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/README.md +1 -2
- package/dist/auth-leases.d.ts +85 -0
- package/dist/auth-leases.d.ts.map +1 -0
- package/dist/auth-leases.js +368 -0
- package/dist/auth-leases.js.map +1 -0
- package/dist/better-sqlite3.d.ts +22 -0
- package/dist/better-sqlite3.d.ts.map +1 -0
- package/dist/better-sqlite3.js +16 -0
- package/dist/better-sqlite3.js.map +1 -0
- package/dist/blobs/access.d.ts +35 -0
- package/dist/blobs/access.d.ts.map +1 -0
- package/dist/blobs/access.js +149 -0
- package/dist/blobs/access.js.map +1 -0
- package/dist/blobs/adapters/database.d.ts +26 -9
- package/dist/blobs/adapters/database.d.ts.map +1 -1
- package/dist/blobs/adapters/database.js +68 -23
- package/dist/blobs/adapters/database.js.map +1 -1
- package/dist/blobs/index.d.ts +1 -0
- package/dist/blobs/index.d.ts.map +1 -1
- package/dist/blobs/index.js +1 -0
- package/dist/blobs/index.js.map +1 -1
- package/dist/blobs/manager.d.ts +69 -44
- package/dist/blobs/manager.d.ts.map +1 -1
- package/dist/blobs/manager.js +250 -65
- package/dist/blobs/manager.js.map +1 -1
- package/dist/blobs/migrate.d.ts.map +1 -1
- package/dist/blobs/migrate.js +16 -8
- package/dist/blobs/migrate.js.map +1 -1
- package/dist/blobs/types.d.ts +4 -0
- package/dist/blobs/types.d.ts.map +1 -1
- package/dist/bun-sqlite.d.ts +19 -0
- package/dist/bun-sqlite.d.ts.map +1 -0
- package/dist/bun-sqlite.js +19 -0
- package/dist/bun-sqlite.js.map +1 -0
- package/dist/clients.d.ts +1 -0
- package/dist/clients.d.ts.map +1 -1
- package/dist/clients.js.map +1 -1
- package/dist/cloudflare/durable-object.d.ts +93 -0
- package/dist/cloudflare/durable-object.d.ts.map +1 -0
- package/dist/cloudflare/durable-object.js +210 -0
- package/dist/cloudflare/durable-object.js.map +1 -0
- package/dist/cloudflare/index.d.ts +22 -0
- package/dist/cloudflare/index.d.ts.map +1 -0
- package/dist/cloudflare/index.js +22 -0
- package/dist/cloudflare/index.js.map +1 -0
- package/dist/cloudflare/r2.d.ts +180 -0
- package/dist/cloudflare/r2.d.ts.map +1 -0
- package/dist/cloudflare/r2.js +258 -0
- package/dist/cloudflare/r2.js.map +1 -0
- package/dist/cloudflare/scope-cache.d.ts +54 -0
- package/dist/cloudflare/scope-cache.d.ts.map +1 -0
- package/dist/cloudflare/scope-cache.js +223 -0
- package/dist/cloudflare/scope-cache.js.map +1 -0
- package/dist/cloudflare/sentry.d.ts +47 -0
- package/dist/cloudflare/sentry.d.ts.map +1 -0
- package/dist/cloudflare/sentry.js +163 -0
- package/dist/cloudflare/sentry.js.map +1 -0
- package/dist/cloudflare/worker.d.ts +46 -0
- package/dist/cloudflare/worker.d.ts.map +1 -0
- package/dist/cloudflare/worker.js +63 -0
- package/dist/cloudflare/worker.js.map +1 -0
- package/dist/commit-integrity.d.ts +38 -0
- package/dist/commit-integrity.d.ts.map +1 -0
- package/dist/commit-integrity.js +260 -0
- package/dist/commit-integrity.js.map +1 -0
- package/dist/compaction.js.map +1 -1
- package/dist/crdt-yjs/index.d.ts +99 -0
- package/dist/crdt-yjs/index.d.ts.map +1 -0
- package/dist/crdt-yjs/index.js +629 -0
- package/dist/crdt-yjs/index.js.map +1 -0
- package/dist/d1.d.ts +13 -0
- package/dist/d1.d.ts.map +1 -0
- package/dist/d1.js +14 -0
- package/dist/d1.js.map +1 -0
- package/dist/dialect/base.d.ts +11 -1
- package/dist/dialect/base.d.ts.map +1 -1
- package/dist/dialect/base.js +42 -5
- package/dist/dialect/base.js.map +1 -1
- package/dist/dialect/helpers.d.ts +6 -0
- package/dist/dialect/helpers.d.ts.map +1 -1
- package/dist/dialect/helpers.js +24 -0
- package/dist/dialect/helpers.js.map +1 -1
- package/dist/dialect/types.d.ts +40 -0
- package/dist/dialect/types.d.ts.map +1 -1
- package/dist/encrypted-crdt.d.ts +67 -0
- package/dist/encrypted-crdt.d.ts.map +1 -0
- package/dist/encrypted-crdt.js +426 -0
- package/dist/encrypted-crdt.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/filesystem/index.d.ts +44 -0
- package/dist/filesystem/index.d.ts.map +1 -0
- package/dist/filesystem/index.js +164 -0
- package/dist/filesystem/index.js.map +1 -0
- package/dist/handlers/collection.d.ts +11 -3
- package/dist/handlers/collection.d.ts.map +1 -1
- package/dist/handlers/collection.js +34 -56
- package/dist/handlers/collection.js.map +1 -1
- package/dist/handlers/create-handler.d.ts +31 -7
- package/dist/handlers/create-handler.d.ts.map +1 -1
- package/dist/handlers/create-handler.js +332 -115
- package/dist/handlers/create-handler.js.map +1 -1
- package/dist/handlers/types.d.ts +86 -1
- package/dist/handlers/types.d.ts.map +1 -1
- package/dist/helpers/conflict.js.map +1 -1
- package/dist/helpers/emitted-change.js.map +1 -1
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/paginate.js.map +1 -1
- package/dist/helpers/scope-authorization.d.ts +7 -0
- package/dist/helpers/scope-authorization.d.ts.map +1 -0
- package/dist/helpers/scope-authorization.js +19 -0
- package/dist/helpers/scope-authorization.js.map +1 -0
- package/dist/helpers/scope-commit-index.d.ts +12 -0
- package/dist/helpers/scope-commit-index.d.ts.map +1 -0
- package/dist/helpers/scope-commit-index.js +35 -0
- package/dist/helpers/scope-commit-index.js.map +1 -0
- package/dist/helpers/scope-strings.js.map +1 -1
- package/dist/hono/api-key-auth.d.ts +49 -0
- package/dist/hono/api-key-auth.d.ts.map +1 -0
- package/dist/hono/api-key-auth.js +108 -0
- package/dist/hono/api-key-auth.js.map +1 -0
- package/dist/hono/audit-redaction.d.ts +20 -0
- package/dist/hono/audit-redaction.d.ts.map +1 -0
- package/dist/hono/audit-redaction.js +85 -0
- package/dist/hono/audit-redaction.js.map +1 -0
- package/dist/hono/blobs.d.ts +75 -0
- package/dist/hono/blobs.d.ts.map +1 -0
- package/dist/hono/blobs.js +586 -0
- package/dist/hono/blobs.js.map +1 -0
- package/dist/hono/console/gateway.d.ts +42 -0
- package/dist/hono/console/gateway.d.ts.map +1 -0
- package/dist/hono/console/gateway.js +2158 -0
- package/dist/hono/console/gateway.js.map +1 -0
- package/dist/hono/console/live-auth.d.ts +7 -0
- package/dist/hono/console/live-auth.d.ts.map +1 -0
- package/dist/hono/console/live-auth.js +39 -0
- package/dist/hono/console/live-auth.js.map +1 -0
- package/dist/hono/console/route-descriptor.d.ts +6 -0
- package/dist/hono/console/route-descriptor.d.ts.map +1 -0
- package/dist/hono/console/route-descriptor.js +16 -0
- package/dist/hono/console/route-descriptor.js.map +1 -0
- package/dist/hono/console/routes/api-keys.d.ts +8 -0
- package/dist/hono/console/routes/api-keys.d.ts.map +1 -0
- package/dist/hono/console/routes/api-keys.js +575 -0
- package/dist/hono/console/routes/api-keys.js.map +1 -0
- package/dist/hono/console/routes/clients.d.ts +8 -0
- package/dist/hono/console/routes/clients.d.ts.map +1 -0
- package/dist/hono/console/routes/clients.js +322 -0
- package/dist/hono/console/routes/clients.js.map +1 -0
- package/dist/hono/console/routes/commits.d.ts +8 -0
- package/dist/hono/console/routes/commits.d.ts.map +1 -0
- package/dist/hono/console/routes/commits.js +882 -0
- package/dist/hono/console/routes/commits.js.map +1 -0
- package/dist/hono/console/routes/context.d.ts +188 -0
- package/dist/hono/console/routes/context.d.ts.map +1 -0
- package/dist/hono/console/routes/context.js +633 -0
- package/dist/hono/console/routes/context.js.map +1 -0
- package/dist/hono/console/routes/events.d.ts +8 -0
- package/dist/hono/console/routes/events.d.ts.map +1 -0
- package/dist/hono/console/routes/events.js +501 -0
- package/dist/hono/console/routes/events.js.map +1 -0
- package/dist/hono/console/routes/maintenance.d.ts +8 -0
- package/dist/hono/console/routes/maintenance.d.ts.map +1 -0
- package/dist/hono/console/routes/maintenance.js +341 -0
- package/dist/hono/console/routes/maintenance.js.map +1 -0
- package/dist/hono/console/routes/shared.d.ts +174 -0
- package/dist/hono/console/routes/shared.d.ts.map +1 -0
- package/dist/hono/console/routes/shared.js +583 -0
- package/dist/hono/console/routes/shared.js.map +1 -0
- package/dist/hono/console/routes/stats.d.ts +8 -0
- package/dist/hono/console/routes/stats.d.ts.map +1 -0
- package/dist/hono/console/routes/stats.js +295 -0
- package/dist/hono/console/routes/stats.js.map +1 -0
- package/dist/hono/console/routes/storage.d.ts +8 -0
- package/dist/hono/console/routes/storage.d.ts.map +1 -0
- package/dist/hono/console/routes/storage.js +121 -0
- package/dist/hono/console/routes/storage.js.map +1 -0
- package/dist/hono/console/routes.d.ts +36 -0
- package/dist/hono/console/routes.d.ts.map +1 -0
- package/dist/hono/console/routes.js +112 -0
- package/dist/hono/console/routes.js.map +1 -0
- package/dist/hono/console/schema-errors.d.ts +2 -0
- package/dist/hono/console/schema-errors.d.ts.map +1 -0
- package/dist/hono/console/schema-errors.js +17 -0
- package/dist/hono/console/schema-errors.js.map +1 -0
- package/dist/hono/console/schemas.d.ts +1515 -0
- package/dist/hono/console/schemas.d.ts.map +1 -0
- package/dist/hono/console/schemas.js +661 -0
- package/dist/hono/console/schemas.js.map +1 -0
- package/dist/hono/console/types.d.ts +213 -0
- package/dist/hono/console/types.d.ts.map +1 -0
- package/dist/hono/console/types.js +2 -0
- package/dist/hono/console/types.js.map +1 -0
- package/dist/hono/console/ui.d.ts +38 -0
- package/dist/hono/console/ui.d.ts.map +1 -0
- package/dist/hono/console/ui.js +43 -0
- package/dist/hono/console/ui.js.map +1 -0
- package/dist/hono/create-server.d.ts +71 -0
- package/dist/hono/create-server.d.ts.map +1 -0
- package/dist/hono/create-server.js +121 -0
- package/dist/hono/create-server.js.map +1 -0
- package/dist/hono/errors.d.ts +13 -0
- package/dist/hono/errors.d.ts.map +1 -0
- package/dist/hono/errors.js +21 -0
- package/dist/hono/errors.js.map +1 -0
- package/dist/hono/index.d.ts +20 -0
- package/dist/hono/index.d.ts.map +1 -0
- package/dist/hono/index.js +31 -0
- package/dist/hono/index.js.map +1 -0
- package/dist/hono/openapi.d.ts +72 -0
- package/dist/hono/openapi.d.ts.map +1 -0
- package/dist/hono/openapi.js +99 -0
- package/dist/hono/openapi.js.map +1 -0
- package/dist/hono/proxy/connection-manager.d.ts +78 -0
- package/dist/hono/proxy/connection-manager.d.ts.map +1 -0
- package/dist/hono/proxy/connection-manager.js +251 -0
- package/dist/hono/proxy/connection-manager.js.map +1 -0
- package/dist/hono/proxy/index.d.ts +8 -0
- package/dist/hono/proxy/index.d.ts.map +1 -0
- package/dist/hono/proxy/index.js +8 -0
- package/dist/hono/proxy/index.js.map +1 -0
- package/dist/hono/proxy/routes.d.ts +86 -0
- package/dist/hono/proxy/routes.d.ts.map +1 -0
- package/dist/hono/proxy/routes.js +183 -0
- package/dist/hono/proxy/routes.js.map +1 -0
- package/dist/hono/rate-limit.d.ts +101 -0
- package/dist/hono/rate-limit.d.ts.map +1 -0
- package/dist/hono/rate-limit.js +184 -0
- package/dist/hono/rate-limit.js.map +1 -0
- package/dist/hono/realtime-sync-packs.d.ts +43 -0
- package/dist/hono/realtime-sync-packs.d.ts.map +1 -0
- package/dist/hono/realtime-sync-packs.js +219 -0
- package/dist/hono/realtime-sync-packs.js.map +1 -0
- package/dist/hono/routes/audit.d.ts +12 -0
- package/dist/hono/routes/audit.d.ts.map +1 -0
- package/dist/hono/routes/audit.js +385 -0
- package/dist/hono/routes/audit.js.map +1 -0
- package/dist/hono/routes/auth-leases.d.ts +8 -0
- package/dist/hono/routes/auth-leases.d.ts.map +1 -0
- package/dist/hono/routes/auth-leases.js +88 -0
- package/dist/hono/routes/auth-leases.js.map +1 -0
- package/dist/hono/routes/combined.d.ts +8 -0
- package/dist/hono/routes/combined.d.ts.map +1 -0
- package/dist/hono/routes/combined.js +392 -0
- package/dist/hono/routes/combined.js.map +1 -0
- package/dist/hono/routes/context.d.ts +314 -0
- package/dist/hono/routes/context.d.ts.map +1 -0
- package/dist/hono/routes/context.js +1147 -0
- package/dist/hono/routes/context.js.map +1 -0
- package/dist/hono/routes/health.d.ts +8 -0
- package/dist/hono/routes/health.d.ts.map +1 -0
- package/dist/hono/routes/health.js +16 -0
- package/dist/hono/routes/health.js.map +1 -0
- package/dist/hono/routes/realtime.d.ts +9 -0
- package/dist/hono/routes/realtime.d.ts.map +1 -0
- package/dist/hono/routes/realtime.js +626 -0
- package/dist/hono/routes/realtime.js.map +1 -0
- package/dist/hono/routes/shared.d.ts +689 -0
- package/dist/hono/routes/shared.d.ts.map +1 -0
- package/dist/hono/routes/shared.js +972 -0
- package/dist/hono/routes/shared.js.map +1 -0
- package/dist/hono/routes/snapshots.d.ts +10 -0
- package/dist/hono/routes/snapshots.d.ts.map +1 -0
- package/dist/hono/routes/snapshots.js +281 -0
- package/dist/hono/routes/snapshots.js.map +1 -0
- package/dist/hono/routes.d.ts +19 -0
- package/dist/hono/routes.d.ts.map +1 -0
- package/dist/hono/routes.js +37 -0
- package/dist/hono/routes.js.map +1 -0
- package/dist/hono/validation.d.ts +5 -0
- package/dist/hono/validation.d.ts.map +1 -0
- package/dist/hono/validation.js +47 -0
- package/dist/hono/validation.js.map +1 -0
- package/dist/hono/websocket-origin.d.ts +9 -0
- package/dist/hono/websocket-origin.d.ts.map +1 -0
- package/dist/hono/websocket-origin.js +96 -0
- package/dist/hono/websocket-origin.js.map +1 -0
- package/dist/hono/ws.d.ts +341 -0
- package/dist/hono/ws.d.ts.map +1 -0
- package/dist/hono/ws.js +711 -0
- package/dist/hono/ws.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/libsql.d.ts +29 -0
- package/dist/libsql.d.ts.map +1 -0
- package/dist/libsql.js +25 -0
- package/dist/libsql.js.map +1 -0
- package/dist/migrate.js.map +1 -1
- package/dist/neon.d.ts +21 -0
- package/dist/neon.d.ts.map +1 -0
- package/dist/neon.js +22 -0
- package/dist/neon.js.map +1 -0
- package/dist/notify.d.ts +30 -0
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +160 -41
- package/dist/notify.js.map +1 -1
- package/dist/pglite.d.ts +37 -0
- package/dist/pglite.d.ts.map +1 -0
- package/dist/pglite.js +37 -0
- package/dist/pglite.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/types.d.ts +73 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +30 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/postgres/index.d.ts +68 -0
- package/dist/postgres/index.d.ts.map +1 -0
- package/dist/postgres/index.js +924 -0
- package/dist/postgres/index.js.map +1 -0
- package/dist/proxy/collection.d.ts +0 -2
- package/dist/proxy/collection.d.ts.map +1 -1
- package/dist/proxy/collection.js +2 -17
- package/dist/proxy/collection.js.map +1 -1
- package/dist/proxy/handler.d.ts +1 -1
- package/dist/proxy/handler.d.ts.map +1 -1
- package/dist/proxy/handler.js +1 -2
- package/dist/proxy/handler.js.map +1 -1
- package/dist/proxy/index.d.ts +1 -1
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +1 -1
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/mutation-detector.js.map +1 -1
- package/dist/proxy/oplog.d.ts.map +1 -1
- package/dist/proxy/oplog.js +32 -8
- package/dist/proxy/oplog.js.map +1 -1
- package/dist/prune.d.ts +8 -1
- package/dist/prune.d.ts.map +1 -1
- package/dist/prune.js +68 -28
- package/dist/prune.js.map +1 -1
- package/dist/pull.d.ts +31 -0
- package/dist/pull.d.ts.map +1 -1
- package/dist/pull.js +1011 -471
- package/dist/pull.js.map +1 -1
- package/dist/push.d.ts +36 -2
- package/dist/push.d.ts.map +1 -1
- package/dist/push.js +603 -358
- package/dist/push.js.map +1 -1
- package/dist/realtime/in-memory.js.map +1 -1
- package/dist/realtime/index.d.ts +2 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +1 -0
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime/types.d.ts +12 -0
- package/dist/realtime/types.d.ts.map +1 -1
- package/dist/realtime/types.js +13 -1
- package/dist/realtime/types.js.map +1 -1
- package/dist/relay/client-role/forward-engine.d.ts +63 -0
- package/dist/relay/client-role/forward-engine.d.ts.map +1 -0
- package/dist/relay/client-role/forward-engine.js +267 -0
- package/dist/relay/client-role/forward-engine.js.map +1 -0
- package/dist/relay/client-role/index.d.ts +9 -0
- package/dist/relay/client-role/index.d.ts.map +1 -0
- package/dist/relay/client-role/index.js +9 -0
- package/dist/relay/client-role/index.js.map +1 -0
- package/dist/relay/client-role/pull-engine.d.ts +72 -0
- package/dist/relay/client-role/pull-engine.d.ts.map +1 -0
- package/dist/relay/client-role/pull-engine.js +249 -0
- package/dist/relay/client-role/pull-engine.js.map +1 -0
- package/dist/relay/client-role/sequence-mapper.d.ts +65 -0
- package/dist/relay/client-role/sequence-mapper.d.ts.map +1 -0
- package/dist/relay/client-role/sequence-mapper.js +161 -0
- package/dist/relay/client-role/sequence-mapper.js.map +1 -0
- package/dist/relay/evaluation/relay-paths.d.ts +41 -0
- package/dist/relay/evaluation/relay-paths.d.ts.map +1 -0
- package/dist/relay/evaluation/relay-paths.js +504 -0
- package/dist/relay/evaluation/relay-paths.js.map +1 -0
- package/dist/relay/evaluation/rust-boundary.d.ts +47 -0
- package/dist/relay/evaluation/rust-boundary.d.ts.map +1 -0
- package/dist/relay/evaluation/rust-boundary.js +220 -0
- package/dist/relay/evaluation/rust-boundary.js.map +1 -0
- package/dist/relay/index.d.ts +37 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/index.js +44 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/relay/migrate.d.ts +18 -0
- package/dist/relay/migrate.d.ts.map +1 -0
- package/dist/relay/migrate.js +99 -0
- package/dist/relay/migrate.js.map +1 -0
- package/dist/relay/mode-manager.d.ts +60 -0
- package/dist/relay/mode-manager.d.ts.map +1 -0
- package/dist/relay/mode-manager.js +114 -0
- package/dist/relay/mode-manager.js.map +1 -0
- package/dist/relay/realtime.d.ts +90 -0
- package/dist/relay/realtime.d.ts.map +1 -0
- package/dist/relay/realtime.js +147 -0
- package/dist/relay/realtime.js.map +1 -0
- package/dist/relay/relay.d.ts +190 -0
- package/dist/relay/relay.d.ts.map +1 -0
- package/dist/relay/relay.js +320 -0
- package/dist/relay/relay.js.map +1 -0
- package/dist/relay/schema.d.ts +158 -0
- package/dist/relay/schema.d.ts.map +1 -0
- package/dist/relay/schema.js +7 -0
- package/dist/relay/schema.js.map +1 -0
- package/dist/relay/server-role/index.d.ts +56 -0
- package/dist/relay/server-role/index.d.ts.map +1 -0
- package/dist/relay/server-role/index.js +193 -0
- package/dist/relay/server-role/index.js.map +1 -0
- package/dist/relay/server-role/pull.d.ts +27 -0
- package/dist/relay/server-role/pull.d.ts.map +1 -0
- package/dist/relay/server-role/pull.js +24 -0
- package/dist/relay/server-role/pull.js.map +1 -0
- package/dist/relay/server-role/push.d.ts +29 -0
- package/dist/relay/server-role/push.d.ts.map +1 -0
- package/dist/relay/server-role/push.js +122 -0
- package/dist/relay/server-role/push.js.map +1 -0
- package/dist/s3/index.d.ts +83 -0
- package/dist/s3/index.d.ts.map +1 -0
- package/dist/s3/index.js +223 -0
- package/dist/s3/index.js.map +1 -0
- package/dist/schema.d.ts +137 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -0
- package/dist/schema.js.map +1 -1
- package/dist/service-worker/index.d.ts +114 -0
- package/dist/service-worker/index.d.ts.map +1 -0
- package/dist/service-worker/index.js +487 -0
- package/dist/service-worker/index.js.map +1 -0
- package/dist/snapshot-artifacts/sqlite-bun.d.ts +15 -0
- package/dist/snapshot-artifacts/sqlite-bun.d.ts.map +1 -0
- package/dist/snapshot-artifacts/sqlite-bun.js +128 -0
- package/dist/snapshot-artifacts/sqlite-bun.js.map +1 -0
- package/dist/snapshot-artifacts.d.ts +206 -0
- package/dist/snapshot-artifacts.d.ts.map +1 -0
- package/dist/snapshot-artifacts.js +545 -0
- package/dist/snapshot-artifacts.js.map +1 -0
- package/dist/snapshot-chunks/db-metadata.d.ts +18 -0
- package/dist/snapshot-chunks/db-metadata.d.ts.map +1 -1
- package/dist/snapshot-chunks/db-metadata.js +91 -63
- package/dist/snapshot-chunks/db-metadata.js.map +1 -1
- package/dist/snapshot-chunks/types.d.ts +2 -0
- package/dist/snapshot-chunks/types.d.ts.map +1 -1
- package/dist/snapshot-chunks.d.ts +33 -3
- package/dist/snapshot-chunks.d.ts.map +1 -1
- package/dist/snapshot-chunks.js +136 -55
- package/dist/snapshot-chunks.js.map +1 -1
- package/dist/sqlite/index.d.ts +53 -0
- package/dist/sqlite/index.d.ts.map +1 -0
- package/dist/sqlite/index.js +795 -0
- package/dist/sqlite/index.js.map +1 -0
- package/dist/sqlite3.d.ts +22 -0
- package/dist/sqlite3.d.ts.map +1 -0
- package/dist/sqlite3.js +99 -0
- package/dist/sqlite3.js.map +1 -0
- package/dist/stats.d.ts +8 -0
- package/dist/stats.d.ts.map +1 -1
- package/dist/stats.js +45 -13
- package/dist/stats.js.map +1 -1
- package/dist/subscriptions/cache.d.ts +3 -0
- package/dist/subscriptions/cache.d.ts.map +1 -1
- package/dist/subscriptions/cache.js +44 -0
- package/dist/subscriptions/cache.js.map +1 -1
- package/dist/subscriptions/resolve.d.ts +3 -1
- package/dist/subscriptions/resolve.d.ts.map +1 -1
- package/dist/subscriptions/resolve.js +90 -51
- package/dist/subscriptions/resolve.js.map +1 -1
- package/dist/sync.d.ts +3 -0
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +8 -4
- package/dist/sync.js.map +1 -1
- package/package.json +296 -7
- package/src/auth-leases.ts +649 -0
- package/src/better-sqlite3.ts +35 -0
- package/src/blobs/access.ts +244 -0
- package/src/blobs/adapters/database.ts +125 -43
- package/src/blobs/index.ts +1 -0
- package/src/blobs/manager.ts +366 -65
- package/src/blobs/migrate.ts +16 -8
- package/src/blobs/types.ts +4 -0
- package/src/bun-sqlite-ambient.d.ts +19 -0
- package/src/bun-sqlite.ts +27 -0
- package/src/clients.ts +1 -0
- package/src/cloudflare/durable-object.ts +289 -0
- package/src/cloudflare/index.ts +22 -0
- package/src/cloudflare/r2.ts +526 -0
- package/src/cloudflare/scope-cache.ts +341 -0
- package/src/cloudflare/sentry.ts +230 -0
- package/src/cloudflare/worker.ts +77 -0
- package/src/commit-integrity.ts +371 -0
- package/src/crdt-yjs/index.ts +931 -0
- package/src/d1.ts +16 -0
- package/src/dialect/base.ts +71 -5
- package/src/dialect/helpers.ts +31 -0
- package/src/dialect/types.ts +47 -0
- package/src/encrypted-crdt.ts +786 -0
- package/src/errors.ts +22 -0
- package/src/filesystem/index.ts +262 -0
- package/src/handlers/collection.ts +78 -78
- package/src/handlers/create-handler.ts +540 -147
- package/src/handlers/types.ts +116 -0
- package/src/helpers/index.ts +2 -0
- package/src/helpers/scope-authorization.ts +27 -0
- package/src/helpers/scope-commit-index.ts +52 -0
- package/src/hono/api-key-auth.ts +177 -0
- package/src/hono/audit-redaction.ts +135 -0
- package/src/hono/blobs.ts +851 -0
- package/src/hono/console/gateway.ts +3046 -0
- package/src/hono/console/live-auth.ts +46 -0
- package/src/hono/console/route-descriptor.ts +22 -0
- package/src/hono/console/routes/api-keys.ts +721 -0
- package/src/hono/console/routes/clients.ts +447 -0
- package/src/hono/console/routes/commits.ts +1137 -0
- package/src/hono/console/routes/context.ts +956 -0
- package/src/hono/console/routes/events.ts +669 -0
- package/src/hono/console/routes/maintenance.ts +461 -0
- package/src/hono/console/routes/shared.ts +816 -0
- package/src/hono/console/routes/stats.ts +392 -0
- package/src/hono/console/routes/storage.ts +159 -0
- package/src/hono/console/routes.ts +146 -0
- package/src/hono/console/schema-errors.ts +23 -0
- package/src/hono/console/schemas.ts +914 -0
- package/src/hono/console/types.ts +223 -0
- package/src/hono/console/ui.ts +100 -0
- package/src/hono/create-server.ts +230 -0
- package/src/hono/errors.ts +50 -0
- package/src/hono/index.ts +54 -0
- package/src/hono/openapi.ts +139 -0
- package/src/hono/proxy/connection-manager.ts +340 -0
- package/src/hono/proxy/index.ts +8 -0
- package/src/hono/proxy/routes.ts +272 -0
- package/src/hono/rate-limit.ts +319 -0
- package/src/hono/realtime-sync-packs.ts +354 -0
- package/src/hono/routes/audit.ts +499 -0
- package/src/hono/routes/auth-leases.ts +119 -0
- package/src/hono/routes/combined.ts +583 -0
- package/src/hono/routes/context.ts +1629 -0
- package/src/hono/routes/health.ts +26 -0
- package/src/hono/routes/realtime.ts +808 -0
- package/src/hono/routes/shared.ts +1626 -0
- package/src/hono/routes/snapshots.ts +345 -0
- package/src/hono/routes.ts +68 -0
- package/src/hono/validation.ts +81 -0
- package/src/hono/websocket-origin.ts +131 -0
- package/src/hono/ws.ts +1134 -0
- package/src/index.ts +6 -0
- package/src/libsql.ts +51 -0
- package/src/neon.ts +28 -0
- package/src/notify.ts +224 -44
- package/src/pglite.ts +68 -0
- package/src/plugins/index.ts +1 -0
- package/src/plugins/types.ts +144 -0
- package/src/postgres/index.ts +1291 -0
- package/src/proxy/collection.ts +5 -27
- package/src/proxy/handler.ts +2 -2
- package/src/proxy/index.ts +0 -2
- package/src/proxy/oplog.ts +41 -10
- package/src/prune.ts +137 -36
- package/src/pull.ts +1504 -591
- package/src/push.ts +881 -443
- package/src/realtime/index.ts +2 -0
- package/src/realtime/types.ts +35 -0
- package/src/relay/bun-types.d.ts +50 -0
- package/src/relay/client-role/forward-engine.ts +355 -0
- package/src/relay/client-role/index.ts +9 -0
- package/src/relay/client-role/pull-engine.ts +329 -0
- package/src/relay/client-role/sequence-mapper.ts +201 -0
- package/src/relay/evaluation/relay-paths.ts +699 -0
- package/src/relay/evaluation/rust-boundary.ts +464 -0
- package/src/relay/index.ts +50 -0
- package/src/relay/migrate.ts +113 -0
- package/src/relay/mode-manager.ts +142 -0
- package/src/relay/realtime.ts +207 -0
- package/src/relay/relay.ts +431 -0
- package/src/relay/schema.ts +171 -0
- package/src/relay/server-role/index.ts +338 -0
- package/src/relay/server-role/pull.ts +43 -0
- package/src/relay/server-role/push.ts +164 -0
- package/src/s3/index.ts +346 -0
- package/src/schema.ts +141 -1
- package/src/service-worker/index.ts +773 -0
- package/src/snapshot-artifacts/sqlite-bun.ts +168 -0
- package/src/snapshot-artifacts.ts +896 -0
- package/src/snapshot-chunks/db-metadata.ts +131 -72
- package/src/snapshot-chunks/types.ts +2 -0
- package/src/snapshot-chunks.ts +194 -70
- package/src/sqlite/index.ts +1064 -0
- package/src/sqlite3.ts +137 -0
- package/src/stats.ts +76 -13
- package/src/subscriptions/cache.ts +58 -0
- package/src/subscriptions/resolve.ts +99 -58
- package/src/sync.ts +16 -6
- package/src/blobs/adapters/database.test.ts +0 -67
- package/src/notify.test.ts +0 -520
- package/src/proxy/handler.test.ts +0 -126
- package/src/proxy/mutation-detector.test.ts +0 -71
- package/src/snapshot-chunks/db-metadata.test.ts +0 -172
- package/src/subscriptions/resolve.test.ts +0 -180
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server/hono - OpenAPI Spec Export
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for generating and serving OpenAPI specifications.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Scalar } from '@scalar/hono-api-reference';
|
|
8
|
+
import { type Handler, Hono } from 'hono';
|
|
9
|
+
import { generateSpecs, openAPIRouteHandler } from 'hono-openapi';
|
|
10
|
+
|
|
11
|
+
const DEFAULT_SCALAR_CDN =
|
|
12
|
+
'https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest';
|
|
13
|
+
|
|
14
|
+
export interface OpenAPIConfig {
|
|
15
|
+
title?: string;
|
|
16
|
+
version?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
servers?: Array<{ url: string; description?: string }>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ScalarReferenceConfig {
|
|
22
|
+
url?: string;
|
|
23
|
+
cdn?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OpenAPIDocsRoutesConfig extends OpenAPIConfig {
|
|
27
|
+
openAPIPath?: string;
|
|
28
|
+
scalarPath?: string;
|
|
29
|
+
scalar?: ScalarReferenceConfig;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizeRoutePath(path: string): string {
|
|
33
|
+
return path.startsWith('/') ? path : `/${path}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create an OpenAPI spec handler that can be used with Hono routes.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { Hono } from 'hono';
|
|
42
|
+
* import { createSyncRoutes, createConsoleRoutes, createOpenAPIHandler } from '@syncular/server/hono';
|
|
43
|
+
*
|
|
44
|
+
* const app = new Hono();
|
|
45
|
+
* const syncRoutes = createSyncRoutes({ ... });
|
|
46
|
+
* const consoleRoutes = createConsoleRoutes({ ... });
|
|
47
|
+
*
|
|
48
|
+
* app.route('/sync', syncRoutes);
|
|
49
|
+
* app.route('/console', consoleRoutes);
|
|
50
|
+
*
|
|
51
|
+
* // Add OpenAPI spec endpoint
|
|
52
|
+
* app.get('/openapi.json', createOpenAPIHandler(app, {
|
|
53
|
+
* title: 'Syncular API',
|
|
54
|
+
* version: '1.0.0',
|
|
55
|
+
* }));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function createOpenAPIHandler(app: Hono, config: OpenAPIConfig = {}) {
|
|
59
|
+
return openAPIRouteHandler(app, {
|
|
60
|
+
documentation: {
|
|
61
|
+
info: {
|
|
62
|
+
title: config.title ?? 'Syncular API',
|
|
63
|
+
version: config.version ?? '1.0.0',
|
|
64
|
+
description:
|
|
65
|
+
config.description ??
|
|
66
|
+
'Sync infrastructure API for real-time data synchronization',
|
|
67
|
+
},
|
|
68
|
+
servers: config.servers,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Create a Scalar API reference handler that points at an OpenAPI document.
|
|
75
|
+
*/
|
|
76
|
+
export function createScalarReferenceHandler(
|
|
77
|
+
config: ScalarReferenceConfig = {}
|
|
78
|
+
): Handler {
|
|
79
|
+
return Scalar({
|
|
80
|
+
url: config.url ?? '/openapi.json',
|
|
81
|
+
cdn: config.cdn ?? DEFAULT_SCALAR_CDN,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create a small Hono app that serves both `/openapi.json` and `/spec`.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { Hono } from 'hono';
|
|
91
|
+
* import { createOpenAPIDocsRoutes } from '@syncular/server/hono';
|
|
92
|
+
*
|
|
93
|
+
* const app = new Hono();
|
|
94
|
+
* app.route('/', createOpenAPIDocsRoutes(app, {
|
|
95
|
+
* title: 'Syncular API',
|
|
96
|
+
* }));
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function createOpenAPIDocsRoutes(
|
|
100
|
+
app: Hono,
|
|
101
|
+
config: OpenAPIDocsRoutesConfig = {}
|
|
102
|
+
) {
|
|
103
|
+
const docsApp = new Hono();
|
|
104
|
+
const openAPIPath = normalizeRoutePath(config.openAPIPath ?? '/openapi.json');
|
|
105
|
+
const scalarPath = normalizeRoutePath(config.scalarPath ?? '/spec');
|
|
106
|
+
|
|
107
|
+
docsApp.get(openAPIPath, createOpenAPIHandler(app, config));
|
|
108
|
+
docsApp.get(
|
|
109
|
+
scalarPath,
|
|
110
|
+
createScalarReferenceHandler({
|
|
111
|
+
url: config.scalar?.url ?? openAPIPath,
|
|
112
|
+
cdn: config.scalar?.cdn,
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
return docsApp;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Generate OpenAPI document from a Hono app instance.
|
|
121
|
+
* This is useful for build-time spec generation.
|
|
122
|
+
*/
|
|
123
|
+
export async function generateOpenAPIDocument(
|
|
124
|
+
app: Hono,
|
|
125
|
+
config: OpenAPIConfig = {}
|
|
126
|
+
): Promise<unknown> {
|
|
127
|
+
return generateSpecs(app, {
|
|
128
|
+
documentation: {
|
|
129
|
+
info: {
|
|
130
|
+
title: config.title ?? 'Syncular API',
|
|
131
|
+
version: config.version ?? '1.0.0',
|
|
132
|
+
description:
|
|
133
|
+
config.description ??
|
|
134
|
+
'Sync infrastructure API for real-time data synchronization',
|
|
135
|
+
},
|
|
136
|
+
servers: config.servers,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/server/hono - Proxy Connection Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages WebSocket connections for the proxy.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
ProxyHandshake,
|
|
9
|
+
ProxyMessage,
|
|
10
|
+
ProxyResponse,
|
|
11
|
+
} from '@syncular/core';
|
|
12
|
+
import type {
|
|
13
|
+
ExecuteProxyQueryResult,
|
|
14
|
+
ProxyHandlerCollection,
|
|
15
|
+
ServerSyncDialect,
|
|
16
|
+
SyncCoreDb,
|
|
17
|
+
} from '@syncular/server';
|
|
18
|
+
import { executeProxyQuery } from '@syncular/server';
|
|
19
|
+
import type { WSContext } from 'hono/ws';
|
|
20
|
+
import type { Kysely, Transaction } from 'kysely';
|
|
21
|
+
|
|
22
|
+
export interface ProxyConnectionManagerConfig<
|
|
23
|
+
DB extends SyncCoreDb = SyncCoreDb,
|
|
24
|
+
> {
|
|
25
|
+
/** Database connection */
|
|
26
|
+
db: Kysely<DB>;
|
|
27
|
+
/** Server sync dialect */
|
|
28
|
+
dialect: ServerSyncDialect;
|
|
29
|
+
/** Proxy table handlers for oplog generation */
|
|
30
|
+
handlers: ProxyHandlerCollection;
|
|
31
|
+
/** Maximum concurrent connections (default: 100) */
|
|
32
|
+
maxConnections?: number;
|
|
33
|
+
/** Idle connection timeout in ms (default: 30000) */
|
|
34
|
+
idleTimeoutMs?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ProxyConnectionState<DB extends SyncCoreDb> {
|
|
38
|
+
ws: WSContext;
|
|
39
|
+
actorId: string;
|
|
40
|
+
clientId: string;
|
|
41
|
+
transaction: Transaction<DB> | null;
|
|
42
|
+
lastActivity: number;
|
|
43
|
+
idleTimer: ReturnType<typeof setTimeout> | null;
|
|
44
|
+
/** Transaction promise resolve callback */
|
|
45
|
+
__resolveTransaction?: () => void;
|
|
46
|
+
/** Transaction promise reject callback */
|
|
47
|
+
__rejectTransaction?: (error: Error) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Manages proxy WebSocket connections and their state.
|
|
52
|
+
*/
|
|
53
|
+
export class ProxyConnectionManager<DB extends SyncCoreDb = SyncCoreDb> {
|
|
54
|
+
private connections = new Map<WSContext, ProxyConnectionState<DB>>();
|
|
55
|
+
private config: ProxyConnectionManagerConfig<DB>;
|
|
56
|
+
private idleTimeoutMs: number;
|
|
57
|
+
private maxConnections: number;
|
|
58
|
+
|
|
59
|
+
constructor(config: ProxyConnectionManagerConfig<DB>) {
|
|
60
|
+
this.config = config;
|
|
61
|
+
this.idleTimeoutMs = config.idleTimeoutMs ?? 30000;
|
|
62
|
+
this.maxConnections = config.maxConnections ?? 100;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Check if a new connection can be accepted.
|
|
67
|
+
*/
|
|
68
|
+
canAccept(): boolean {
|
|
69
|
+
return this.connections.size < this.maxConnections;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get the current connection count.
|
|
74
|
+
*/
|
|
75
|
+
getConnectionCount(): number {
|
|
76
|
+
return this.connections.size;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Handle the handshake message and register the connection.
|
|
81
|
+
*/
|
|
82
|
+
register(ws: WSContext, handshake: ProxyHandshake): ProxyConnectionState<DB> {
|
|
83
|
+
const state: ProxyConnectionState<DB> = {
|
|
84
|
+
ws,
|
|
85
|
+
actorId: handshake.actorId,
|
|
86
|
+
clientId: handshake.clientId,
|
|
87
|
+
transaction: null,
|
|
88
|
+
lastActivity: Date.now(),
|
|
89
|
+
idleTimer: null,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
this.connections.set(ws, state);
|
|
93
|
+
this.resetIdleTimer(state);
|
|
94
|
+
|
|
95
|
+
return state;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get the connection state for a WebSocket.
|
|
100
|
+
*/
|
|
101
|
+
get(ws: WSContext): ProxyConnectionState<DB> | undefined {
|
|
102
|
+
return this.connections.get(ws);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Unregister and cleanup a connection.
|
|
107
|
+
*/
|
|
108
|
+
async unregister(ws: WSContext): Promise<void> {
|
|
109
|
+
const state = this.connections.get(ws);
|
|
110
|
+
if (!state) return;
|
|
111
|
+
|
|
112
|
+
// Clear idle timer
|
|
113
|
+
if (state.idleTimer) {
|
|
114
|
+
clearTimeout(state.idleTimer);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Rollback any pending transaction by rejecting the promise
|
|
118
|
+
if (state.transaction) {
|
|
119
|
+
const rejectTransaction = state.__rejectTransaction;
|
|
120
|
+
if (rejectTransaction) {
|
|
121
|
+
rejectTransaction(new Error('Connection closed'));
|
|
122
|
+
}
|
|
123
|
+
state.transaction = null;
|
|
124
|
+
state.__resolveTransaction = undefined;
|
|
125
|
+
state.__rejectTransaction = undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.connections.delete(ws);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Handle a proxy message and return the response.
|
|
133
|
+
*/
|
|
134
|
+
async handleMessage(
|
|
135
|
+
ws: WSContext,
|
|
136
|
+
message: ProxyMessage
|
|
137
|
+
): Promise<ProxyResponse> {
|
|
138
|
+
const state = this.connections.get(ws);
|
|
139
|
+
if (!state) {
|
|
140
|
+
return {
|
|
141
|
+
id: message.id,
|
|
142
|
+
type: 'error',
|
|
143
|
+
error: 'Connection not registered',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Update activity and reset idle timer
|
|
148
|
+
state.lastActivity = Date.now();
|
|
149
|
+
this.resetIdleTimer(state);
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
switch (message.type) {
|
|
153
|
+
case 'begin':
|
|
154
|
+
return await this.handleBegin(state, message);
|
|
155
|
+
|
|
156
|
+
case 'commit':
|
|
157
|
+
return await this.handleCommit(state, message);
|
|
158
|
+
|
|
159
|
+
case 'rollback':
|
|
160
|
+
return await this.handleRollback(state, message);
|
|
161
|
+
|
|
162
|
+
case 'query':
|
|
163
|
+
return await this.handleQuery(state, message);
|
|
164
|
+
|
|
165
|
+
default:
|
|
166
|
+
return {
|
|
167
|
+
id: message.id,
|
|
168
|
+
type: 'error',
|
|
169
|
+
error: `Unknown message type: ${message.type}`,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
return {
|
|
174
|
+
id: message.id,
|
|
175
|
+
type: 'error',
|
|
176
|
+
error: err instanceof Error ? err.message : 'Unknown error',
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private async handleBegin(
|
|
182
|
+
state: ProxyConnectionState<DB>,
|
|
183
|
+
message: ProxyMessage
|
|
184
|
+
): Promise<ProxyResponse> {
|
|
185
|
+
if (state.transaction) {
|
|
186
|
+
return {
|
|
187
|
+
id: message.id,
|
|
188
|
+
type: 'error',
|
|
189
|
+
error: 'Transaction already in progress',
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Start a transaction and keep it open
|
|
194
|
+
// We use a workaround since Kysely doesn't expose raw transaction control
|
|
195
|
+
return new Promise((resolve) => {
|
|
196
|
+
this.config.db
|
|
197
|
+
.transaction()
|
|
198
|
+
.execute(async (trx) => {
|
|
199
|
+
state.transaction = trx;
|
|
200
|
+
|
|
201
|
+
// Wait for commit or rollback
|
|
202
|
+
return new Promise<void>((resolveTransaction, rejectTransaction) => {
|
|
203
|
+
state.__resolveTransaction = resolveTransaction;
|
|
204
|
+
state.__rejectTransaction = rejectTransaction;
|
|
205
|
+
resolve({
|
|
206
|
+
id: message.id,
|
|
207
|
+
type: 'result',
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
})
|
|
211
|
+
.catch(() => {
|
|
212
|
+
// Transaction was rolled back externally
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private async handleCommit(
|
|
218
|
+
state: ProxyConnectionState<DB>,
|
|
219
|
+
message: ProxyMessage
|
|
220
|
+
): Promise<ProxyResponse> {
|
|
221
|
+
if (!state.transaction) {
|
|
222
|
+
return {
|
|
223
|
+
id: message.id,
|
|
224
|
+
type: 'error',
|
|
225
|
+
error: 'No transaction in progress',
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Resolve the transaction promise to commit
|
|
230
|
+
const resolveTransaction = state.__resolveTransaction;
|
|
231
|
+
if (resolveTransaction) {
|
|
232
|
+
resolveTransaction();
|
|
233
|
+
}
|
|
234
|
+
state.transaction = null;
|
|
235
|
+
state.__resolveTransaction = undefined;
|
|
236
|
+
state.__rejectTransaction = undefined;
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
id: message.id,
|
|
240
|
+
type: 'result',
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private async handleRollback(
|
|
245
|
+
state: ProxyConnectionState<DB>,
|
|
246
|
+
message: ProxyMessage
|
|
247
|
+
): Promise<ProxyResponse> {
|
|
248
|
+
if (!state.transaction) {
|
|
249
|
+
return {
|
|
250
|
+
id: message.id,
|
|
251
|
+
type: 'error',
|
|
252
|
+
error: 'No transaction in progress',
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Reject the transaction promise to trigger rollback
|
|
257
|
+
const rejectTransaction = state.__rejectTransaction;
|
|
258
|
+
if (rejectTransaction) {
|
|
259
|
+
rejectTransaction(new Error('Transaction rolled back'));
|
|
260
|
+
}
|
|
261
|
+
state.transaction = null;
|
|
262
|
+
state.__resolveTransaction = undefined;
|
|
263
|
+
state.__rejectTransaction = undefined;
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
id: message.id,
|
|
267
|
+
type: 'result',
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private async handleQuery(
|
|
272
|
+
state: ProxyConnectionState<DB>,
|
|
273
|
+
message: ProxyMessage
|
|
274
|
+
): Promise<ProxyResponse> {
|
|
275
|
+
if (!message.sql) {
|
|
276
|
+
return {
|
|
277
|
+
id: message.id,
|
|
278
|
+
type: 'error',
|
|
279
|
+
error: 'Missing SQL query',
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const db = state.transaction ?? this.config.db;
|
|
284
|
+
|
|
285
|
+
const result: ExecuteProxyQueryResult = await executeProxyQuery({
|
|
286
|
+
db,
|
|
287
|
+
dialect: this.config.dialect,
|
|
288
|
+
handlers: this.config.handlers,
|
|
289
|
+
ctx: {
|
|
290
|
+
actorId: state.actorId,
|
|
291
|
+
clientId: state.clientId,
|
|
292
|
+
},
|
|
293
|
+
sqlQuery: message.sql,
|
|
294
|
+
parameters: message.parameters ?? [],
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
id: message.id,
|
|
299
|
+
type: 'result',
|
|
300
|
+
rows: result.rows,
|
|
301
|
+
rowCount: result.rowCount,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private resetIdleTimer(state: ProxyConnectionState<DB>): void {
|
|
306
|
+
if (state.idleTimer) {
|
|
307
|
+
clearTimeout(state.idleTimer);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (this.idleTimeoutMs <= 0) return;
|
|
311
|
+
|
|
312
|
+
state.idleTimer = setTimeout(() => {
|
|
313
|
+
// Close idle connection
|
|
314
|
+
try {
|
|
315
|
+
state.ws.close(4000, 'Idle timeout');
|
|
316
|
+
} catch {
|
|
317
|
+
// Ignore close errors
|
|
318
|
+
}
|
|
319
|
+
this.unregister(state.ws);
|
|
320
|
+
}, this.idleTimeoutMs);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Close all connections.
|
|
325
|
+
*/
|
|
326
|
+
async closeAll(): Promise<void> {
|
|
327
|
+
const promises: Promise<void>[] = [];
|
|
328
|
+
|
|
329
|
+
for (const [ws] of this.connections) {
|
|
330
|
+
try {
|
|
331
|
+
ws.close(1000, 'Server shutdown');
|
|
332
|
+
} catch {
|
|
333
|
+
// Ignore close errors
|
|
334
|
+
}
|
|
335
|
+
promises.push(this.unregister(ws));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
await Promise.all(promises);
|
|
339
|
+
}
|
|
340
|
+
}
|