@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,244 @@
|
|
|
1
|
+
import { collectScopeVars, type ScopeValues } from '@syncular/core';
|
|
2
|
+
import { type Kysely, sql } from 'kysely';
|
|
3
|
+
import type { ServerTableHandler, SyncServerAuth } from '../handlers/types';
|
|
4
|
+
import { rowScopesAllowed } from '../helpers/scope-authorization';
|
|
5
|
+
import type { SyncCoreDb } from '../schema';
|
|
6
|
+
|
|
7
|
+
export type ScopedBlobAccessDecisionReason =
|
|
8
|
+
| 'allowed'
|
|
9
|
+
| 'handler_missing'
|
|
10
|
+
| 'missing_reference'
|
|
11
|
+
| 'resolve_scopes_failed'
|
|
12
|
+
| 'scope_denied';
|
|
13
|
+
|
|
14
|
+
export interface ScopedBlobAccessDecision {
|
|
15
|
+
actorId: string;
|
|
16
|
+
partitionId: string;
|
|
17
|
+
hash: string;
|
|
18
|
+
allowed: boolean;
|
|
19
|
+
reason: ScopedBlobAccessDecisionReason;
|
|
20
|
+
table?: string;
|
|
21
|
+
column?: string;
|
|
22
|
+
rowId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ScopedBlobReferenceTable {
|
|
26
|
+
table: string;
|
|
27
|
+
blobColumns: readonly string[];
|
|
28
|
+
primaryKeyColumn?: string;
|
|
29
|
+
candidateLimit?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CreateScopedBlobAccessCheckerOptions<
|
|
33
|
+
DB extends SyncCoreDb = SyncCoreDb,
|
|
34
|
+
Auth extends SyncServerAuth = SyncServerAuth,
|
|
35
|
+
> {
|
|
36
|
+
db: Kysely<DB>;
|
|
37
|
+
handlers: readonly ServerTableHandler<DB, Auth>[];
|
|
38
|
+
references: readonly ScopedBlobReferenceTable[];
|
|
39
|
+
candidateLimit?: number;
|
|
40
|
+
onDecision?: (decision: ScopedBlobAccessDecision) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ScopedBlobAccessRequest<Auth extends SyncServerAuth> {
|
|
44
|
+
actorId: string;
|
|
45
|
+
partitionId: string;
|
|
46
|
+
hash: string;
|
|
47
|
+
auth?: Auth;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createScopedBlobAccessChecker<
|
|
51
|
+
DB extends SyncCoreDb,
|
|
52
|
+
Auth extends SyncServerAuth = SyncServerAuth,
|
|
53
|
+
>(
|
|
54
|
+
options: CreateScopedBlobAccessCheckerOptions<DB, Auth>
|
|
55
|
+
): (request: ScopedBlobAccessRequest<Auth>) => Promise<boolean> {
|
|
56
|
+
const handlersByTable = new Map(
|
|
57
|
+
options.handlers.map((handler) => [handler.table, handler])
|
|
58
|
+
);
|
|
59
|
+
const candidateLimit = options.candidateLimit ?? 100;
|
|
60
|
+
|
|
61
|
+
const emit = (decision: ScopedBlobAccessDecision): void => {
|
|
62
|
+
options.onDecision?.(decision);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return async (request) => {
|
|
66
|
+
let deniedDecision: ScopedBlobAccessDecision | null = null;
|
|
67
|
+
let configurationDecision: ScopedBlobAccessDecision | null = null;
|
|
68
|
+
|
|
69
|
+
for (const reference of options.references) {
|
|
70
|
+
if (reference.blobColumns.length === 0) continue;
|
|
71
|
+
|
|
72
|
+
const rows = await readBlobReferenceCandidateRows({
|
|
73
|
+
db: options.db,
|
|
74
|
+
table: reference.table,
|
|
75
|
+
columns: reference.blobColumns,
|
|
76
|
+
hash: request.hash,
|
|
77
|
+
limit: reference.candidateLimit ?? candidateLimit,
|
|
78
|
+
});
|
|
79
|
+
if (rows.length === 0) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const handler = handlersByTable.get(reference.table);
|
|
84
|
+
if (!handler) {
|
|
85
|
+
configurationDecision ??= {
|
|
86
|
+
...request,
|
|
87
|
+
allowed: false,
|
|
88
|
+
reason: 'handler_missing',
|
|
89
|
+
table: reference.table,
|
|
90
|
+
};
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const allowedScopes = await resolveBlobAccessScopes({
|
|
95
|
+
db: options.db,
|
|
96
|
+
handler,
|
|
97
|
+
request,
|
|
98
|
+
});
|
|
99
|
+
if (!allowedScopes.ok) {
|
|
100
|
+
configurationDecision ??= {
|
|
101
|
+
...request,
|
|
102
|
+
allowed: false,
|
|
103
|
+
reason: 'resolve_scopes_failed',
|
|
104
|
+
table: reference.table,
|
|
105
|
+
};
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const requiredScopeKeys = Array.from(
|
|
110
|
+
collectScopeVars(handler.scopePatterns)
|
|
111
|
+
);
|
|
112
|
+
for (const row of rows) {
|
|
113
|
+
const matchedColumn = reference.blobColumns.find((column) =>
|
|
114
|
+
blobColumnMatchesHash(row[column], request.hash)
|
|
115
|
+
);
|
|
116
|
+
if (!matchedColumn) continue;
|
|
117
|
+
|
|
118
|
+
const rowScopes = handler.extractScopes(row);
|
|
119
|
+
if (
|
|
120
|
+
!rowScopesAllowed({
|
|
121
|
+
rowScopes,
|
|
122
|
+
allowedScopes: allowedScopes.scopes,
|
|
123
|
+
requiredScopeKeys,
|
|
124
|
+
})
|
|
125
|
+
) {
|
|
126
|
+
deniedDecision ??= {
|
|
127
|
+
...request,
|
|
128
|
+
allowed: false,
|
|
129
|
+
reason: 'scope_denied',
|
|
130
|
+
table: reference.table,
|
|
131
|
+
column: matchedColumn,
|
|
132
|
+
rowId: readRowId(
|
|
133
|
+
row,
|
|
134
|
+
reference.primaryKeyColumn ?? handler.primaryKeyColumn
|
|
135
|
+
),
|
|
136
|
+
};
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
emit({
|
|
141
|
+
...request,
|
|
142
|
+
allowed: true,
|
|
143
|
+
reason: 'allowed',
|
|
144
|
+
table: reference.table,
|
|
145
|
+
column: matchedColumn,
|
|
146
|
+
rowId: readRowId(
|
|
147
|
+
row,
|
|
148
|
+
reference.primaryKeyColumn ?? handler.primaryKeyColumn
|
|
149
|
+
),
|
|
150
|
+
});
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
emit(
|
|
156
|
+
deniedDecision ??
|
|
157
|
+
configurationDecision ?? {
|
|
158
|
+
...request,
|
|
159
|
+
allowed: false,
|
|
160
|
+
reason: 'missing_reference',
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
return false;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function resolveBlobAccessScopes<
|
|
168
|
+
DB extends SyncCoreDb,
|
|
169
|
+
Auth extends SyncServerAuth,
|
|
170
|
+
>(args: {
|
|
171
|
+
db: Kysely<DB>;
|
|
172
|
+
handler: ServerTableHandler<DB, Auth>;
|
|
173
|
+
request: ScopedBlobAccessRequest<Auth>;
|
|
174
|
+
}): Promise<{ ok: true; scopes: ScopeValues } | { ok: false }> {
|
|
175
|
+
try {
|
|
176
|
+
const scopes = await args.handler.resolveScopes({
|
|
177
|
+
db: args.db,
|
|
178
|
+
actorId: args.request.actorId,
|
|
179
|
+
auth:
|
|
180
|
+
args.request.auth ??
|
|
181
|
+
({
|
|
182
|
+
actorId: args.request.actorId,
|
|
183
|
+
partitionId: args.request.partitionId,
|
|
184
|
+
} as Auth),
|
|
185
|
+
});
|
|
186
|
+
return { ok: true, scopes };
|
|
187
|
+
} catch {
|
|
188
|
+
return { ok: false };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function readBlobReferenceCandidateRows<DB extends SyncCoreDb>(args: {
|
|
193
|
+
db: Kysely<DB>;
|
|
194
|
+
table: string;
|
|
195
|
+
columns: readonly string[];
|
|
196
|
+
hash: string;
|
|
197
|
+
limit: number;
|
|
198
|
+
}): Promise<Record<string, unknown>[]> {
|
|
199
|
+
const pattern = `%${args.hash}%`;
|
|
200
|
+
const predicates = args.columns.map(
|
|
201
|
+
(column) => sql`${sql.ref(column)} like ${pattern}`
|
|
202
|
+
);
|
|
203
|
+
const result = await sql<Record<string, unknown>>`
|
|
204
|
+
select *
|
|
205
|
+
from ${sql.table(args.table)}
|
|
206
|
+
where ${sql.join(predicates, sql` or `)}
|
|
207
|
+
limit ${args.limit}
|
|
208
|
+
`.execute(args.db);
|
|
209
|
+
return result.rows;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function readRowId(
|
|
213
|
+
row: Record<string, unknown>,
|
|
214
|
+
primaryKeyColumn: string | undefined
|
|
215
|
+
): string | undefined {
|
|
216
|
+
const column = primaryKeyColumn ?? 'id';
|
|
217
|
+
const value = row[column];
|
|
218
|
+
return value === null || value === undefined ? undefined : String(value);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function blobColumnMatchesHash(value: unknown, hash: string): boolean {
|
|
222
|
+
const parsed = parseMaybeJson(value);
|
|
223
|
+
if (isBlobRefHash(parsed, hash)) return true;
|
|
224
|
+
if (Array.isArray(parsed)) {
|
|
225
|
+
return parsed.some((entry) => isBlobRefHash(parseMaybeJson(entry), hash));
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function parseMaybeJson(value: unknown): unknown {
|
|
231
|
+
if (typeof value !== 'string') return value;
|
|
232
|
+
try {
|
|
233
|
+
return JSON.parse(value);
|
|
234
|
+
} catch {
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function isBlobRefHash(value: unknown, hash: string): boolean {
|
|
240
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
return (value as { hash?: unknown }).hash === hash;
|
|
244
|
+
}
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
BlobSignUploadOptions,
|
|
13
13
|
BlobStorageAdapter,
|
|
14
14
|
} from '@syncular/core';
|
|
15
|
+
import { resolveUrlFromBase } from '@syncular/core';
|
|
15
16
|
import { type Kysely, sql } from 'kysely';
|
|
16
17
|
import type { SyncBlobsDb } from '../types';
|
|
17
18
|
|
|
@@ -20,25 +21,49 @@ import type { SyncBlobsDb } from '../types';
|
|
|
20
21
|
*/
|
|
21
22
|
export interface BlobTokenSigner {
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param expiresIn Expiration time in seconds
|
|
26
|
-
* @returns A signed token string
|
|
24
|
+
* Token payload for upload/download authorization.
|
|
25
|
+
* Upload tokens are bound to hash + expected byte size.
|
|
27
26
|
*/
|
|
28
27
|
sign(
|
|
29
|
-
payload:
|
|
28
|
+
payload:
|
|
29
|
+
| {
|
|
30
|
+
hash: string;
|
|
31
|
+
partitionId: string;
|
|
32
|
+
action: 'upload';
|
|
33
|
+
size: number;
|
|
34
|
+
expiresAt: number;
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
hash: string;
|
|
38
|
+
partitionId: string;
|
|
39
|
+
action: 'download';
|
|
40
|
+
expiresAt: number;
|
|
41
|
+
},
|
|
30
42
|
expiresIn: number
|
|
31
43
|
): Promise<string>;
|
|
32
44
|
|
|
33
45
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
46
|
+
* Sign a token for blob upload/download authorization.
|
|
47
|
+
* @param payload The data to sign
|
|
48
|
+
* @param expiresIn Expiration time in seconds
|
|
49
|
+
* @returns A signed token string
|
|
36
50
|
*/
|
|
37
|
-
verify(token: string): Promise<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
verify(token: string): Promise<
|
|
52
|
+
| {
|
|
53
|
+
hash: string;
|
|
54
|
+
partitionId: string;
|
|
55
|
+
action: 'upload';
|
|
56
|
+
size: number;
|
|
57
|
+
expiresAt: number;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
hash: string;
|
|
61
|
+
partitionId: string;
|
|
62
|
+
action: 'download';
|
|
63
|
+
expiresAt: number;
|
|
64
|
+
}
|
|
65
|
+
| null
|
|
66
|
+
>;
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
/**
|
|
@@ -92,15 +117,37 @@ export function createHmacTokenSigner(secret: string): BlobTokenSigner {
|
|
|
92
117
|
if (!isValidSig) return null;
|
|
93
118
|
|
|
94
119
|
try {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (
|
|
120
|
+
const parsed = JSON.parse(atob(dataB64)) as Record<string, unknown>;
|
|
121
|
+
if (typeof parsed.hash !== 'string') return null;
|
|
122
|
+
if (typeof parsed.partitionId !== 'string') return null;
|
|
123
|
+
if (typeof parsed.expiresAt !== 'number') return null;
|
|
124
|
+
if (Date.now() > parsed.expiresAt) return null;
|
|
125
|
+
|
|
126
|
+
if (parsed.action === 'download') {
|
|
127
|
+
return {
|
|
128
|
+
hash: parsed.hash,
|
|
129
|
+
partitionId: parsed.partitionId,
|
|
130
|
+
action: 'download',
|
|
131
|
+
expiresAt: parsed.expiresAt,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (
|
|
136
|
+
parsed.action === 'upload' &&
|
|
137
|
+
typeof parsed.size === 'number' &&
|
|
138
|
+
Number.isFinite(parsed.size) &&
|
|
139
|
+
parsed.size >= 0
|
|
140
|
+
) {
|
|
141
|
+
return {
|
|
142
|
+
hash: parsed.hash,
|
|
143
|
+
partitionId: parsed.partitionId,
|
|
144
|
+
action: 'upload',
|
|
145
|
+
size: parsed.size,
|
|
146
|
+
expiresAt: parsed.expiresAt,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
102
149
|
|
|
103
|
-
return
|
|
150
|
+
return null;
|
|
104
151
|
} catch {
|
|
105
152
|
return null;
|
|
106
153
|
}
|
|
@@ -156,22 +203,31 @@ export function createDatabaseBlobStorageAdapter<DB extends SyncBlobsDb>(
|
|
|
156
203
|
options: DatabaseBlobStorageAdapterOptions<DB>
|
|
157
204
|
): BlobStorageAdapter {
|
|
158
205
|
const { db, baseUrl, tokenSigner } = options;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
206
|
+
const resolvePartitionId = (partitionId?: string): string =>
|
|
207
|
+
partitionId ?? 'default';
|
|
208
|
+
const normalizeBlobSizeValue = (value: number | string): number =>
|
|
209
|
+
typeof value === 'number' ? value : Number(value);
|
|
162
210
|
|
|
163
211
|
return {
|
|
164
212
|
name: 'database',
|
|
165
213
|
|
|
166
214
|
async signUpload(opts: BlobSignUploadOptions): Promise<BlobSignedUpload> {
|
|
215
|
+
const partitionId = resolvePartitionId(opts.partitionId);
|
|
167
216
|
const expiresAt = Date.now() + opts.expiresIn * 1000;
|
|
168
217
|
const token = await tokenSigner.sign(
|
|
169
|
-
{
|
|
218
|
+
{
|
|
219
|
+
hash: opts.hash,
|
|
220
|
+
partitionId,
|
|
221
|
+
action: 'upload',
|
|
222
|
+
size: opts.size,
|
|
223
|
+
expiresAt,
|
|
224
|
+
},
|
|
170
225
|
opts.expiresIn
|
|
171
226
|
);
|
|
172
227
|
|
|
173
228
|
// URL points to server's blob upload endpoint
|
|
174
|
-
const
|
|
229
|
+
const uploadPath = `/blobs/${encodeURIComponent(opts.hash)}/upload?token=${encodeURIComponent(token)}`;
|
|
230
|
+
const url = resolveUrlFromBase(baseUrl, uploadPath);
|
|
175
231
|
|
|
176
232
|
return {
|
|
177
233
|
url,
|
|
@@ -184,39 +240,53 @@ export function createDatabaseBlobStorageAdapter<DB extends SyncBlobsDb>(
|
|
|
184
240
|
},
|
|
185
241
|
|
|
186
242
|
async signDownload(opts: BlobSignDownloadOptions): Promise<string> {
|
|
243
|
+
const partitionId = resolvePartitionId(opts.partitionId);
|
|
187
244
|
const expiresAt = Date.now() + opts.expiresIn * 1000;
|
|
188
245
|
const token = await tokenSigner.sign(
|
|
189
|
-
{ hash: opts.hash, action: 'download', expiresAt },
|
|
246
|
+
{ hash: opts.hash, partitionId, action: 'download', expiresAt },
|
|
190
247
|
opts.expiresIn
|
|
191
248
|
);
|
|
192
249
|
|
|
193
|
-
return
|
|
250
|
+
return resolveUrlFromBase(
|
|
251
|
+
baseUrl,
|
|
252
|
+
`/blobs/${encodeURIComponent(opts.hash)}/download?token=${encodeURIComponent(token)}`
|
|
253
|
+
);
|
|
194
254
|
},
|
|
195
255
|
|
|
196
|
-
async exists(
|
|
256
|
+
async exists(
|
|
257
|
+
hash: string,
|
|
258
|
+
options?: { partitionId?: string }
|
|
259
|
+
): Promise<boolean> {
|
|
260
|
+
const partitionId = resolvePartitionId(options?.partitionId);
|
|
197
261
|
const rowResult = await sql<{ hash: string }>`
|
|
198
262
|
select hash
|
|
199
263
|
from ${sql.table('sync_blobs')}
|
|
200
|
-
where hash = ${hash}
|
|
264
|
+
where partition_id = ${partitionId} and hash = ${hash}
|
|
201
265
|
limit 1
|
|
202
266
|
`.execute(db);
|
|
203
267
|
return rowResult.rows.length > 0;
|
|
204
268
|
},
|
|
205
269
|
|
|
206
|
-
async delete(
|
|
270
|
+
async delete(
|
|
271
|
+
hash: string,
|
|
272
|
+
options?: { partitionId?: string }
|
|
273
|
+
): Promise<void> {
|
|
274
|
+
const partitionId = resolvePartitionId(options?.partitionId);
|
|
207
275
|
await sql`
|
|
208
276
|
delete from ${sql.table('sync_blobs')}
|
|
209
|
-
where hash = ${hash}
|
|
277
|
+
where partition_id = ${partitionId} and hash = ${hash}
|
|
210
278
|
`.execute(db);
|
|
211
279
|
},
|
|
212
280
|
|
|
213
281
|
async getMetadata(
|
|
214
|
-
hash: string
|
|
282
|
+
hash: string,
|
|
283
|
+
options?: { partitionId?: string }
|
|
215
284
|
): Promise<{ size: number; mimeType?: string } | null> {
|
|
216
|
-
const
|
|
285
|
+
const partitionId = resolvePartitionId(options?.partitionId);
|
|
286
|
+
const rowResult = await sql<{ size: number | string; mime_type: string }>`
|
|
217
287
|
select size, mime_type
|
|
218
288
|
from ${sql.table('sync_blobs')}
|
|
219
|
-
where hash = ${hash}
|
|
289
|
+
where partition_id = ${partitionId} and hash = ${hash}
|
|
220
290
|
limit 1
|
|
221
291
|
`.execute(db);
|
|
222
292
|
const row = rowResult.rows[0];
|
|
@@ -224,7 +294,7 @@ export function createDatabaseBlobStorageAdapter<DB extends SyncBlobsDb>(
|
|
|
224
294
|
if (!row) return null;
|
|
225
295
|
|
|
226
296
|
return {
|
|
227
|
-
size: row.size,
|
|
297
|
+
size: normalizeBlobSizeValue(row.size),
|
|
228
298
|
mimeType: row.mime_type,
|
|
229
299
|
};
|
|
230
300
|
},
|
|
@@ -232,13 +302,16 @@ export function createDatabaseBlobStorageAdapter<DB extends SyncBlobsDb>(
|
|
|
232
302
|
async put(
|
|
233
303
|
hash: string,
|
|
234
304
|
data: Uint8Array,
|
|
235
|
-
metadata?: Record<string, unknown
|
|
305
|
+
metadata?: Record<string, unknown>,
|
|
306
|
+
options?: { partitionId?: string }
|
|
236
307
|
): Promise<void> {
|
|
308
|
+
const partitionId = resolvePartitionId(options?.partitionId);
|
|
237
309
|
const mimeType =
|
|
238
310
|
typeof metadata?.mimeType === 'string'
|
|
239
311
|
? metadata.mimeType
|
|
240
312
|
: 'application/octet-stream';
|
|
241
313
|
await storeBlobInDatabase(db, {
|
|
314
|
+
partitionId,
|
|
242
315
|
hash,
|
|
243
316
|
size: data.length,
|
|
244
317
|
mimeType,
|
|
@@ -246,8 +319,12 @@ export function createDatabaseBlobStorageAdapter<DB extends SyncBlobsDb>(
|
|
|
246
319
|
});
|
|
247
320
|
},
|
|
248
321
|
|
|
249
|
-
async get(
|
|
250
|
-
|
|
322
|
+
async get(
|
|
323
|
+
hash: string,
|
|
324
|
+
options?: { partitionId?: string }
|
|
325
|
+
): Promise<Uint8Array | null> {
|
|
326
|
+
const partitionId = resolvePartitionId(options?.partitionId);
|
|
327
|
+
const result = await readBlobFromDatabase(db, hash, { partitionId });
|
|
251
328
|
return result?.body ?? null;
|
|
252
329
|
},
|
|
253
330
|
};
|
|
@@ -260,6 +337,7 @@ export function createDatabaseBlobStorageAdapter<DB extends SyncBlobsDb>(
|
|
|
260
337
|
export async function storeBlobInDatabase<DB extends SyncBlobsDb>(
|
|
261
338
|
db: Kysely<DB>,
|
|
262
339
|
args: {
|
|
340
|
+
partitionId: string;
|
|
263
341
|
hash: string;
|
|
264
342
|
size: number;
|
|
265
343
|
mimeType: string;
|
|
@@ -268,6 +346,7 @@ export async function storeBlobInDatabase<DB extends SyncBlobsDb>(
|
|
|
268
346
|
): Promise<void> {
|
|
269
347
|
await sql`
|
|
270
348
|
insert into ${sql.table('sync_blobs')} (
|
|
349
|
+
partition_id,
|
|
271
350
|
hash,
|
|
272
351
|
size,
|
|
273
352
|
mime_type,
|
|
@@ -275,13 +354,14 @@ export async function storeBlobInDatabase<DB extends SyncBlobsDb>(
|
|
|
275
354
|
created_at
|
|
276
355
|
)
|
|
277
356
|
values (
|
|
357
|
+
${args.partitionId},
|
|
278
358
|
${args.hash},
|
|
279
359
|
${args.size},
|
|
280
360
|
${args.mimeType},
|
|
281
361
|
${args.body},
|
|
282
362
|
${new Date().toISOString()}
|
|
283
363
|
)
|
|
284
|
-
on conflict (hash) do nothing
|
|
364
|
+
on conflict (partition_id, hash) do nothing
|
|
285
365
|
`.execute(db);
|
|
286
366
|
}
|
|
287
367
|
|
|
@@ -291,16 +371,18 @@ export async function storeBlobInDatabase<DB extends SyncBlobsDb>(
|
|
|
291
371
|
*/
|
|
292
372
|
export async function readBlobFromDatabase<DB extends SyncBlobsDb>(
|
|
293
373
|
db: Kysely<DB>,
|
|
294
|
-
hash: string
|
|
374
|
+
hash: string,
|
|
375
|
+
options?: { partitionId?: string }
|
|
295
376
|
): Promise<{ body: Uint8Array; mimeType: string; size: number } | null> {
|
|
377
|
+
const partitionId = options?.partitionId ?? 'default';
|
|
296
378
|
const rowResult = await sql<{
|
|
297
379
|
body: Uint8Array;
|
|
298
380
|
mime_type: string;
|
|
299
|
-
size: number;
|
|
381
|
+
size: number | string;
|
|
300
382
|
}>`
|
|
301
383
|
select body, mime_type, size
|
|
302
384
|
from ${sql.table('sync_blobs')}
|
|
303
|
-
where hash = ${hash}
|
|
385
|
+
where partition_id = ${partitionId} and hash = ${hash}
|
|
304
386
|
limit 1
|
|
305
387
|
`.execute(db);
|
|
306
388
|
const row = rowResult.rows[0];
|
|
@@ -310,6 +392,6 @@ export async function readBlobFromDatabase<DB extends SyncBlobsDb>(
|
|
|
310
392
|
return {
|
|
311
393
|
body: row.body,
|
|
312
394
|
mimeType: row.mime_type,
|
|
313
|
-
size: row.size,
|
|
395
|
+
size: typeof row.size === 'number' ? row.size : Number(row.size),
|
|
314
396
|
};
|
|
315
397
|
}
|