jazz-tools 2.0.0-alpha.6 → 2.0.0-alpha.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/LICENSE +21 -0
- package/README.md +178 -2
- package/bin/jazz-tools.js +91 -45
- package/dist/_dev/inspector-cache-runtime.d.ts +8 -0
- package/dist/_dev/inspector-cache-runtime.d.ts.map +1 -0
- package/dist/_dev/inspector-cache-runtime.js +237 -0
- package/dist/_dev/inspector-cache-runtime.js.map +1 -0
- package/dist/_dev/inspector-client.d.ts +15 -0
- package/dist/_dev/inspector-client.d.ts.map +1 -0
- package/dist/_dev/inspector-client.js +134 -0
- package/dist/_dev/inspector-client.js.map +1 -0
- package/dist/_dev/native-account-session.d.ts +16 -0
- package/dist/_dev/native-account-session.d.ts.map +1 -0
- package/dist/_dev/native-account-session.js +51 -0
- package/dist/_dev/native-account-session.js.map +1 -0
- package/dist/_dev/native-binding-codec.d.ts +9 -0
- package/dist/_dev/native-binding-codec.d.ts.map +1 -0
- package/dist/_dev/native-binding-codec.js +9 -0
- package/dist/_dev/native-binding-codec.js.map +1 -0
- package/dist/accounts/account-manager-core.d.ts +28 -0
- package/dist/accounts/account-manager-core.d.ts.map +1 -0
- package/dist/accounts/account-manager-core.js +179 -0
- package/dist/accounts/account-manager-core.js.map +1 -0
- package/dist/accounts/browser-host.d.ts +8 -0
- package/dist/accounts/browser-host.d.ts.map +1 -0
- package/dist/accounts/browser-host.js +16 -0
- package/dist/accounts/browser-host.js.map +1 -0
- package/dist/accounts/config-capability.d.ts +26 -0
- package/dist/accounts/config-capability.d.ts.map +1 -0
- package/dist/accounts/config-capability.js +58 -0
- package/dist/accounts/config-capability.js.map +1 -0
- package/dist/accounts/context.d.ts +14 -0
- package/dist/accounts/context.d.ts.map +1 -0
- package/dist/accounts/context.js +214 -0
- package/dist/accounts/context.js.map +1 -0
- package/dist/accounts/create-account-manager.d.ts +52 -0
- package/dist/accounts/create-account-manager.d.ts.map +1 -0
- package/dist/accounts/create-account-manager.js +17 -0
- package/dist/accounts/create-account-manager.js.map +1 -0
- package/dist/accounts/enrollment.d.ts +87 -0
- package/dist/accounts/enrollment.d.ts.map +1 -0
- package/dist/accounts/enrollment.js +305 -0
- package/dist/accounts/enrollment.js.map +1 -0
- package/dist/accounts/exports.d.ts +4 -0
- package/dist/accounts/exports.d.ts.map +1 -0
- package/dist/accounts/exports.js +2 -0
- package/dist/accounts/exports.js.map +1 -0
- package/dist/accounts/local-first.d.ts +14 -0
- package/dist/accounts/local-first.d.ts.map +1 -0
- package/dist/accounts/local-first.js +62 -0
- package/dist/accounts/local-first.js.map +1 -0
- package/dist/accounts/persistence.d.ts +34 -0
- package/dist/accounts/persistence.d.ts.map +1 -0
- package/dist/accounts/persistence.js +299 -0
- package/dist/accounts/persistence.js.map +1 -0
- package/dist/accounts/registry-client.d.ts +50 -0
- package/dist/accounts/registry-client.d.ts.map +1 -0
- package/dist/accounts/registry-client.js +108 -0
- package/dist/accounts/registry-client.js.map +1 -0
- package/dist/accounts/state.d.ts +76 -0
- package/dist/accounts/state.d.ts.map +1 -0
- package/dist/accounts/state.js +171 -0
- package/dist/accounts/state.js.map +1 -0
- package/dist/backend/admission.d.ts +18 -0
- package/dist/backend/admission.d.ts.map +1 -0
- package/dist/backend/admission.js +139 -0
- package/dist/backend/admission.js.map +1 -0
- package/dist/backend/backend-clients.d.ts +76 -0
- package/dist/backend/backend-clients.d.ts.map +1 -0
- package/dist/backend/backend-clients.js +237 -0
- package/dist/backend/backend-clients.js.map +1 -0
- package/dist/backend/backend-issuer.d.ts +6 -0
- package/dist/backend/backend-issuer.d.ts.map +1 -0
- package/dist/backend/backend-issuer.js +6 -0
- package/dist/backend/backend-issuer.js.map +1 -0
- package/dist/backend/blobs.d.ts +121 -0
- package/dist/backend/blobs.d.ts.map +1 -0
- package/dist/backend/blobs.js +123 -0
- package/dist/backend/blobs.js.map +1 -0
- package/dist/backend/create-jazz-context.d.ts +116 -0
- package/dist/backend/create-jazz-context.d.ts.map +1 -0
- package/dist/backend/create-jazz-context.js +607 -0
- package/dist/backend/create-jazz-context.js.map +1 -0
- package/dist/backend/create-jazz-session.d.ts +105 -0
- package/dist/backend/create-jazz-session.d.ts.map +1 -0
- package/dist/backend/create-jazz-session.js +467 -0
- package/dist/backend/create-jazz-session.js.map +1 -0
- package/dist/backend/create-jazz.d.ts +405 -0
- package/dist/backend/create-jazz.d.ts.map +1 -0
- package/dist/backend/create-jazz.js +2731 -0
- package/dist/backend/create-jazz.js.map +1 -0
- package/dist/backend/early-db.d.ts +29 -0
- package/dist/backend/early-db.d.ts.map +1 -0
- package/dist/backend/early-db.js +202 -0
- package/dist/backend/early-db.js.map +1 -0
- package/dist/backend/external-jwt.d.ts +27 -0
- package/dist/backend/external-jwt.d.ts.map +1 -0
- package/dist/backend/external-jwt.js +380 -0
- package/dist/backend/external-jwt.js.map +1 -0
- package/dist/backend/from-jwt.d.ts +62 -0
- package/dist/backend/from-jwt.d.ts.map +1 -0
- package/dist/backend/from-jwt.js +96 -0
- package/dist/backend/from-jwt.js.map +1 -0
- package/dist/backend/index.d.ts +11 -1
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +8 -1
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/no-account-error.d.ts +23 -0
- package/dist/backend/no-account-error.d.ts.map +1 -0
- package/dist/backend/no-account-error.js +30 -0
- package/dist/backend/no-account-error.js.map +1 -0
- package/dist/backend/optional-peer.d.ts +9 -0
- package/dist/backend/optional-peer.d.ts.map +1 -0
- package/dist/backend/optional-peer.js +24 -0
- package/dist/backend/optional-peer.js.map +1 -0
- package/dist/backend/request-auth.d.ts +39 -0
- package/dist/backend/request-auth.d.ts.map +1 -0
- package/dist/backend/request-auth.js +77 -0
- package/dist/backend/request-auth.js.map +1 -0
- package/dist/backend/session-recheck.d.ts +18 -0
- package/dist/backend/session-recheck.d.ts.map +1 -0
- package/dist/backend/session-recheck.js +57 -0
- package/dist/backend/session-recheck.js.map +1 -0
- package/dist/backend/socket-deadline.d.ts +23 -0
- package/dist/backend/socket-deadline.d.ts.map +1 -0
- package/dist/backend/socket-deadline.js +70 -0
- package/dist/backend/socket-deadline.js.map +1 -0
- package/dist/backend/vercel-store.d.ts +223 -0
- package/dist/backend/vercel-store.d.ts.map +1 -0
- package/dist/backend/vercel-store.js +932 -0
- package/dist/backend/vercel-store.js.map +1 -0
- package/dist/better-auth-adapter/fixtures/permissions.d.ts +2 -0
- package/dist/better-auth-adapter/fixtures/permissions.d.ts.map +1 -0
- package/dist/better-auth-adapter/fixtures/permissions.js +2 -0
- package/dist/better-auth-adapter/fixtures/permissions.js.map +1 -0
- package/dist/better-auth-adapter/fixtures/schema.d.ts +69 -0
- package/dist/better-auth-adapter/fixtures/schema.d.ts.map +1 -0
- package/dist/better-auth-adapter/fixtures/schema.js +84 -0
- package/dist/better-auth-adapter/fixtures/schema.js.map +1 -0
- package/dist/better-auth-adapter/index.d.ts +13 -0
- package/dist/better-auth-adapter/index.d.ts.map +1 -0
- package/dist/better-auth-adapter/index.js +366 -0
- package/dist/better-auth-adapter/index.js.map +1 -0
- package/dist/better-auth-adapter/indexes.d.ts +9 -0
- package/dist/better-auth-adapter/indexes.d.ts.map +1 -0
- package/dist/better-auth-adapter/indexes.js +40 -0
- package/dist/better-auth-adapter/indexes.js.map +1 -0
- package/dist/better-auth-adapter/schema.d.ts +49 -0
- package/dist/better-auth-adapter/schema.d.ts.map +1 -0
- package/dist/better-auth-adapter/schema.js +300 -0
- package/dist/better-auth-adapter/schema.js.map +1 -0
- package/dist/better-auth-adapter/types.d.ts +13 -0
- package/dist/better-auth-adapter/types.d.ts.map +1 -0
- package/dist/better-auth-adapter/types.js +2 -0
- package/dist/better-auth-adapter/types.js.map +1 -0
- package/dist/better-auth-adapter/utils.d.ts +27 -0
- package/dist/better-auth-adapter/utils.d.ts.map +1 -0
- package/dist/better-auth-adapter/utils.js +189 -0
- package/dist/better-auth-adapter/utils.js.map +1 -0
- package/dist/browser-benchmark-mode.d.ts +6 -0
- package/dist/browser-benchmark-mode.d.ts.map +1 -0
- package/dist/browser-benchmark-mode.js +13 -0
- package/dist/browser-benchmark-mode.js.map +1 -0
- package/dist/classic-api.d.ts +59 -0
- package/dist/classic-api.d.ts.map +1 -0
- package/dist/classic-api.js +86 -0
- package/dist/classic-api.js.map +1 -0
- package/dist/cli.d.ts +29 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +358 -268
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +8 -0
- package/dist/client/index.js.map +1 -0
- package/dist/cloud/api.d.ts +11 -0
- package/dist/cloud/api.d.ts.map +1 -0
- package/dist/cloud/api.js +46 -0
- package/dist/cloud/api.js.map +1 -0
- package/dist/cloud/commands.d.ts +13 -0
- package/dist/cloud/commands.d.ts.map +1 -0
- package/dist/cloud/commands.js +413 -0
- package/dist/cloud/commands.js.map +1 -0
- package/dist/cloud/credentials.d.ts +49 -0
- package/dist/cloud/credentials.d.ts.map +1 -0
- package/dist/cloud/credentials.js +219 -0
- package/dist/cloud/credentials.js.map +1 -0
- package/dist/cloud/session.d.ts +57 -0
- package/dist/cloud/session.d.ts.map +1 -0
- package/dist/cloud/session.js +269 -0
- package/dist/cloud/session.js.map +1 -0
- package/dist/codegen/relation-analyzer.d.ts +5 -12
- package/dist/codegen/relation-analyzer.d.ts.map +1 -1
- package/dist/codegen/relation-analyzer.js +54 -65
- package/dist/codegen/relation-analyzer.js.map +1 -1
- package/dist/codegen/schema-reader.d.ts +6 -2
- package/dist/codegen/schema-reader.d.ts.map +1 -1
- package/dist/codegen/schema-reader.js +129 -98
- package/dist/codegen/schema-reader.js.map +1 -1
- package/dist/dev/catalogue-api.d.ts +157 -0
- package/dist/dev/catalogue-api.d.ts.map +1 -0
- package/dist/dev/catalogue-api.js +145 -0
- package/dist/dev/catalogue-api.js.map +1 -0
- package/dist/dev/catalogue-project.d.ts +150 -0
- package/dist/dev/catalogue-project.d.ts.map +1 -0
- package/dist/dev/catalogue-project.js +1466 -0
- package/dist/dev/catalogue-project.js.map +1 -0
- package/dist/dev/catalogue.d.ts +72 -0
- package/dist/dev/catalogue.d.ts.map +1 -0
- package/dist/dev/catalogue.js +279 -0
- package/dist/dev/catalogue.js.map +1 -0
- package/dist/dev/dev-server.d.ts +57 -0
- package/dist/dev/dev-server.d.ts.map +1 -0
- package/dist/dev/dev-server.js +122 -0
- package/dist/dev/dev-server.js.map +1 -0
- package/dist/dev/index.d.ts +3 -0
- package/dist/dev/index.d.ts.map +1 -0
- package/dist/dev/index.js +3 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/dev/inspector-overlay/browser-control-registry.d.ts +10 -0
- package/dist/dev/inspector-overlay/browser-control-registry.d.ts.map +1 -0
- package/dist/dev/inspector-overlay/browser-control-registry.js +188 -0
- package/dist/dev/inspector-overlay/browser-control-registry.js.map +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/create-legacy-browser-delegate-X_T_QKCN.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/esm-7mP3GQX4.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/esm-BX6IY2Mv.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/esm-CH5eVyQQ.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/esm-aRzpnC3u.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/esm-ezD5H765.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/esm-k3rsq4Gn.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/index-C-btvLcw.js +20 -0
- package/dist/dev/inspector-overlay/embedded/assets/index-C78Pprka.css +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CAMcDeUa.js +3 -0
- package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-XRRxJUcx.js +23997 -0
- package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-Cc71x_6y.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm_bg-KR7h3v27.wasm +0 -0
- package/dist/dev/inspector-overlay/embedded/assets/node-foreground-node-lease.browser-Bm3gYjlT.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/trace-api-B5CaetI0.js +1 -0
- package/dist/dev/inspector-overlay/embedded/embedded.html +13 -0
- package/dist/dev/inspector-overlay/embedded/favicon.ico +0 -0
- package/dist/dev/inspector-overlay/host-bridge.d.ts +8 -0
- package/dist/dev/inspector-overlay/host-bridge.d.ts.map +1 -0
- package/dist/dev/inspector-overlay/host-bridge.js +136 -0
- package/dist/dev/inspector-overlay/host-bridge.js.map +1 -0
- package/dist/dev/inspector-overlay/inspector-host-types.d.ts +35 -0
- package/dist/dev/inspector-overlay/inspector-host-types.d.ts.map +1 -0
- package/dist/dev/inspector-overlay/inspector-host-types.js +10 -0
- package/dist/dev/inspector-overlay/inspector-host-types.js.map +1 -0
- package/dist/dev/inspector-overlay/loader.d.ts +13 -0
- package/dist/dev/inspector-overlay/loader.d.ts.map +1 -0
- package/dist/dev/inspector-overlay/loader.js +506 -0
- package/dist/dev/inspector-overlay/loader.js.map +1 -0
- package/dist/dev/inspector-overlay/serve.d.ts +46 -0
- package/dist/dev/inspector-overlay/serve.d.ts.map +1 -0
- package/dist/dev/inspector-overlay/serve.js +131 -0
- package/dist/dev/inspector-overlay/serve.js.map +1 -0
- package/dist/dev/legacy-schema-hash.d.ts +4 -0
- package/dist/dev/legacy-schema-hash.d.ts.map +1 -0
- package/dist/dev/legacy-schema-hash.js +12 -0
- package/dist/dev/legacy-schema-hash.js.map +1 -0
- package/dist/dev/migration-graph.d.ts +32 -0
- package/dist/dev/migration-graph.d.ts.map +1 -0
- package/dist/dev/migration-graph.js +136 -0
- package/dist/dev/migration-graph.js.map +1 -0
- package/dist/dev/migrations.d.ts +14 -0
- package/dist/dev/migrations.d.ts.map +1 -0
- package/dist/dev/migrations.js +441 -0
- package/dist/dev/migrations.js.map +1 -0
- package/dist/dev/schema-utils.d.ts +18 -0
- package/dist/dev/schema-utils.d.ts.map +1 -0
- package/dist/dev/schema-utils.js +365 -0
- package/dist/dev/schema-utils.js.map +1 -0
- package/dist/dev/schema-validation.d.ts +5 -0
- package/dist/dev/schema-validation.d.ts.map +1 -0
- package/dist/dev/schema-validation.js +11 -0
- package/dist/dev/schema-validation.js.map +1 -0
- package/dist/dev-tools/auto-attach.d.ts +11 -0
- package/dist/dev-tools/auto-attach.d.ts.map +1 -0
- package/dist/dev-tools/auto-attach.js +26 -0
- package/dist/dev-tools/auto-attach.js.map +1 -0
- package/dist/drivers/index.d.ts +1 -1
- package/dist/drivers/index.d.ts.map +1 -1
- package/dist/drivers/index.js.map +1 -1
- package/dist/drivers/schema-wire.d.ts +18 -0
- package/dist/drivers/schema-wire.d.ts.map +1 -0
- package/dist/drivers/schema-wire.js +66 -0
- package/dist/drivers/schema-wire.js.map +1 -0
- package/dist/drivers/types.d.ts +322 -45
- package/dist/drivers/types.d.ts.map +1 -1
- package/dist/drivers/types.js +5 -4
- package/dist/drivers/types.js.map +1 -1
- package/dist/dsl.d.ts +291 -101
- package/dist/dsl.d.ts.map +1 -1
- package/dist/dsl.js +244 -113
- package/dist/dsl.js.map +1 -1
- package/dist/e2ee/SODIUM-LICENSE.txt +36 -0
- package/dist/e2ee/SODIUM-SOURCES.json +4 -0
- package/dist/e2ee/browser.d.ts +18 -0
- package/dist/e2ee/browser.d.ts.map +1 -0
- package/dist/e2ee/browser.js +111 -0
- package/dist/e2ee/browser.js.map +1 -0
- package/dist/e2ee/context.d.ts +23 -0
- package/dist/e2ee/context.d.ts.map +1 -0
- package/dist/e2ee/context.js +49 -0
- package/dist/e2ee/context.js.map +1 -0
- package/dist/e2ee/crypto.d.ts +10 -0
- package/dist/e2ee/crypto.d.ts.map +1 -0
- package/dist/e2ee/crypto.js +22 -0
- package/dist/e2ee/crypto.js.map +1 -0
- package/dist/e2ee/envelope.d.ts +22 -0
- package/dist/e2ee/envelope.d.ts.map +1 -0
- package/dist/e2ee/envelope.js +52 -0
- package/dist/e2ee/envelope.js.map +1 -0
- package/dist/e2ee/index.d.ts +14 -0
- package/dist/e2ee/index.d.ts.map +1 -0
- package/dist/e2ee/index.js +3 -0
- package/dist/e2ee/index.js.map +1 -0
- package/dist/e2ee/large-value.d.ts +20 -0
- package/dist/e2ee/large-value.d.ts.map +1 -0
- package/dist/e2ee/large-value.js +204 -0
- package/dist/e2ee/large-value.js.map +1 -0
- package/dist/e2ee/native.d.ts +18 -0
- package/dist/e2ee/native.d.ts.map +1 -0
- package/dist/e2ee/native.js +91 -0
- package/dist/e2ee/native.js.map +1 -0
- package/dist/e2ee/record-frame.d.ts +3 -0
- package/dist/e2ee/record-frame.d.ts.map +1 -0
- package/dist/e2ee/record-frame.js +18 -0
- package/dist/e2ee/record-frame.js.map +1 -0
- package/dist/e2ee/signer.d.ts +10 -0
- package/dist/e2ee/signer.d.ts.map +1 -0
- package/dist/e2ee/signer.js +54 -0
- package/dist/e2ee/signer.js.map +1 -0
- package/dist/e2ee/sodium-browser.d.ts +2 -0
- package/dist/e2ee/sodium-browser.d.ts.map +1 -0
- package/dist/e2ee/sodium-browser.js +3432 -0
- package/dist/e2ee/sodium.d.ts +20 -0
- package/dist/e2ee/sodium.d.ts.map +1 -0
- package/dist/e2ee/sodium.js +165 -0
- package/dist/e2ee/sodium.js.map +1 -0
- package/dist/e2ee/types.d.ts +92 -0
- package/dist/e2ee/types.d.ts.map +1 -0
- package/dist/e2ee/types.js +2 -0
- package/dist/e2ee/types.js.map +1 -0
- package/dist/effect/backend/index.d.ts +8 -0
- package/dist/effect/backend/index.d.ts.map +1 -0
- package/dist/effect/backend/index.js +8 -0
- package/dist/effect/backend/index.js.map +1 -0
- package/dist/effect/errors.d.ts +53 -0
- package/dist/effect/errors.d.ts.map +1 -0
- package/dist/effect/errors.js +61 -0
- package/dist/effect/errors.js.map +1 -0
- package/dist/effect/index.d.ts +9 -0
- package/dist/effect/index.d.ts.map +1 -0
- package/dist/effect/index.js +9 -0
- package/dist/effect/index.js.map +1 -0
- package/dist/effect/jazz-backend.d.ts +69 -0
- package/dist/effect/jazz-backend.d.ts.map +1 -0
- package/dist/effect/jazz-backend.js +92 -0
- package/dist/effect/jazz-backend.js.map +1 -0
- package/dist/effect/jazz.d.ts +122 -0
- package/dist/effect/jazz.d.ts.map +1 -0
- package/dist/effect/jazz.js +159 -0
- package/dist/effect/jazz.js.map +1 -0
- package/dist/expo/auth-secret-store.d.ts +37 -0
- package/dist/expo/auth-secret-store.d.ts.map +1 -0
- package/dist/expo/auth-secret-store.js +139 -0
- package/dist/expo/auth-secret-store.js.map +1 -0
- package/dist/expo/create-account-manager.d.ts +28 -0
- package/dist/expo/create-account-manager.d.ts.map +1 -0
- package/dist/expo/create-account-manager.js +35 -0
- package/dist/expo/create-account-manager.js.map +1 -0
- package/dist/expo/create-jazz-session.d.ts +35 -0
- package/dist/expo/create-jazz-session.d.ts.map +1 -0
- package/dist/expo/create-jazz-session.js +39 -0
- package/dist/expo/create-jazz-session.js.map +1 -0
- package/dist/expo/index.d.ts +16 -0
- package/dist/expo/index.d.ts.map +1 -0
- package/dist/expo/index.js +14 -0
- package/dist/expo/index.js.map +1 -0
- package/dist/expo/polyfills.d.ts +2 -0
- package/dist/expo/polyfills.d.ts.map +1 -0
- package/dist/expo/polyfills.js +5 -0
- package/dist/expo/polyfills.js.map +1 -0
- package/dist/expo/provider.d.ts +7 -0
- package/dist/expo/provider.d.ts.map +1 -0
- package/dist/expo/provider.js +10 -0
- package/dist/expo/provider.js.map +1 -0
- package/dist/expo/session.d.ts +10 -0
- package/dist/expo/session.d.ts.map +1 -0
- package/dist/expo/session.js +5 -0
- package/dist/expo/session.js.map +1 -0
- package/dist/expo/use-local-first-auth.d.ts +12 -0
- package/dist/expo/use-local-first-auth.d.ts.map +1 -0
- package/dist/expo/use-local-first-auth.js +13 -0
- package/dist/expo/use-local-first-auth.js.map +1 -0
- package/dist/index.d.ts +24 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/inspector-query.d.ts +6 -0
- package/dist/internal/inspector-query.d.ts.map +1 -0
- package/dist/internal/inspector-query.js +20 -0
- package/dist/internal/inspector-query.js.map +1 -0
- package/dist/ir.d.ts +139 -115
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js +496 -1
- package/dist/ir.js.map +1 -1
- package/dist/local-first/index.d.ts +16 -0
- package/dist/local-first/index.d.ts.map +1 -0
- package/dist/local-first/index.js +15 -0
- package/dist/local-first/index.js.map +1 -0
- package/dist/local-first-auth/browser.d.ts +18 -0
- package/dist/local-first-auth/browser.d.ts.map +1 -0
- package/dist/local-first-auth/browser.js +26 -0
- package/dist/local-first-auth/browser.js.map +1 -0
- package/dist/local-first-auth/encoding.d.ts +10 -0
- package/dist/local-first-auth/encoding.d.ts.map +1 -0
- package/dist/local-first-auth/encoding.js +38 -0
- package/dist/local-first-auth/encoding.js.map +1 -0
- package/dist/local-first-auth/identity.d.ts +73 -0
- package/dist/local-first-auth/identity.d.ts.map +1 -0
- package/dist/local-first-auth/identity.js +258 -0
- package/dist/local-first-auth/identity.js.map +1 -0
- package/dist/local-first-auth/index.d.ts +6 -0
- package/dist/local-first-auth/index.d.ts.map +1 -0
- package/dist/local-first-auth/index.js +4 -0
- package/dist/local-first-auth/index.js.map +1 -0
- package/dist/local-first-auth/passkey.d.ts +22 -0
- package/dist/local-first-auth/passkey.d.ts.map +1 -0
- package/dist/local-first-auth/passkey.js +116 -0
- package/dist/local-first-auth/passkey.js.map +1 -0
- package/dist/local-first-auth/recovery-phrase.d.ts +10 -0
- package/dist/local-first-auth/recovery-phrase.d.ts.map +1 -0
- package/dist/local-first-auth/recovery-phrase.js +59 -0
- package/dist/local-first-auth/recovery-phrase.js.map +1 -0
- package/dist/local-first-auth/secret.d.ts +25 -0
- package/dist/local-first-auth/secret.d.ts.map +1 -0
- package/dist/local-first-auth/secret.js +68 -0
- package/dist/local-first-auth/secret.js.map +1 -0
- package/dist/local-first-auth/server.d.ts +13 -0
- package/dist/local-first-auth/server.d.ts.map +1 -0
- package/dist/local-first-auth/server.js +32 -0
- package/dist/local-first-auth/server.js.map +1 -0
- package/dist/local-first-auth/store.d.ts +51 -0
- package/dist/local-first-auth/store.d.ts.map +1 -0
- package/dist/local-first-auth/store.js +112 -0
- package/dist/local-first-auth/store.js.map +1 -0
- package/dist/magic-columns.d.ts +34 -0
- package/dist/magic-columns.d.ts.map +1 -0
- package/dist/magic-columns.js +86 -0
- package/dist/magic-columns.js.map +1 -0
- package/dist/migration-namespace.d.ts +8 -0
- package/dist/migration-namespace.d.ts.map +1 -0
- package/dist/migration-namespace.js +9 -0
- package/dist/migration-namespace.js.map +1 -0
- package/dist/migrations.d.ts +229 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +383 -0
- package/dist/migrations.js.map +1 -0
- package/dist/observed-jazz-client.d.ts +15 -0
- package/dist/observed-jazz-client.d.ts.map +1 -0
- package/dist/observed-jazz-client.js +38 -0
- package/dist/observed-jazz-client.js.map +1 -0
- package/dist/passkey-backup.d.ts +3 -0
- package/dist/passkey-backup.d.ts.map +1 -0
- package/dist/passkey-backup.js +2 -0
- package/dist/passkey-backup.js.map +1 -0
- package/dist/passphrase.d.ts +2 -0
- package/dist/passphrase.d.ts.map +1 -0
- package/dist/passphrase.js +2 -0
- package/dist/passphrase.js.map +1 -0
- package/dist/permissions/index.d.ts +149 -41
- package/dist/permissions/index.d.ts.map +1 -1
- package/dist/permissions/index.js +1209 -423
- package/dist/permissions/index.js.map +1 -1
- package/dist/policy-expr-map.d.ts +15 -0
- package/dist/policy-expr-map.d.ts.map +1 -0
- package/dist/policy-expr-map.js +45 -0
- package/dist/policy-expr-map.js.map +1 -0
- package/dist/prosemirror/anchors.d.ts +30 -0
- package/dist/prosemirror/anchors.d.ts.map +1 -0
- package/dist/prosemirror/anchors.js +28 -0
- package/dist/prosemirror/anchors.js.map +1 -0
- package/dist/prosemirror/index.d.ts +7 -0
- package/dist/prosemirror/index.d.ts.map +1 -0
- package/dist/prosemirror/index.js +7 -0
- package/dist/prosemirror/index.js.map +1 -0
- package/dist/prosemirror/markdown.d.ts +95 -0
- package/dist/prosemirror/markdown.d.ts.map +1 -0
- package/dist/prosemirror/markdown.js +428 -0
- package/dist/prosemirror/markdown.js.map +1 -0
- package/dist/prosemirror/overlays.d.ts +69 -0
- package/dist/prosemirror/overlays.d.ts.map +1 -0
- package/dist/prosemirror/overlays.js +143 -0
- package/dist/prosemirror/overlays.js.map +1 -0
- package/dist/prosemirror/presence.d.ts +39 -0
- package/dist/prosemirror/presence.d.ts.map +1 -0
- package/dist/prosemirror/presence.js +88 -0
- package/dist/prosemirror/presence.js.map +1 -0
- package/dist/prosemirror/sync.d.ts +60 -0
- package/dist/prosemirror/sync.d.ts.map +1 -0
- package/dist/prosemirror/sync.js +174 -0
- package/dist/prosemirror/sync.js.map +1 -0
- package/dist/prosemirror/text-map.d.ts +21 -0
- package/dist/prosemirror/text-map.d.ts.map +1 -0
- package/dist/prosemirror/text-map.js +85 -0
- package/dist/prosemirror/text-map.js.map +1 -0
- package/dist/provenance-guidance.d.ts +3 -0
- package/dist/provenance-guidance.d.ts.map +1 -0
- package/dist/provenance-guidance.js +19 -0
- package/dist/provenance-guidance.js.map +1 -0
- package/dist/react/create-jazz-client.d.ts +2 -10
- package/dist/react/create-jazz-client.d.ts.map +1 -1
- package/dist/react/create-jazz-client.js +1 -25
- package/dist/react/create-jazz-client.js.map +1 -1
- package/dist/react/devtools-auto-attach.d.ts +2 -0
- package/dist/react/devtools-auto-attach.d.ts.map +1 -0
- package/dist/react/devtools-auto-attach.js +11 -0
- package/dist/react/devtools-auto-attach.js.map +1 -0
- package/dist/react/index.d.ts +20 -6
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +12 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +23 -11
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +43 -3
- package/dist/react/provider.js.map +1 -1
- package/dist/react/session.d.ts +18 -0
- package/dist/react/session.d.ts.map +1 -0
- package/dist/react/session.js +28 -0
- package/dist/react/session.js.map +1 -0
- package/dist/react/use-all.d.ts +1 -1
- package/dist/react/use-all.d.ts.map +1 -1
- package/dist/react/use-all.js +1 -1
- package/dist/react/use-all.js.map +1 -1
- package/dist/react/use-local-first-auth.d.ts +11 -0
- package/dist/react/use-local-first-auth.d.ts.map +1 -0
- package/dist/react/use-local-first-auth.js +13 -0
- package/dist/react/use-local-first-auth.js.map +1 -0
- package/dist/react/use-one.d.ts +2 -0
- package/dist/react/use-one.d.ts.map +1 -0
- package/dist/react/use-one.js +2 -0
- package/dist/react/use-one.js.map +1 -0
- package/dist/react-core/app.d.ts +31 -0
- package/dist/react-core/app.d.ts.map +1 -0
- package/dist/react-core/app.js +65 -0
- package/dist/react-core/app.js.map +1 -0
- package/dist/react-core/index.d.ts +11 -4
- package/dist/react-core/index.d.ts.map +1 -1
- package/dist/react-core/index.js +8 -2
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/provider.d.ts +44 -12
- package/dist/react-core/provider.d.ts.map +1 -1
- package/dist/react-core/provider.js +110 -10
- package/dist/react-core/provider.js.map +1 -1
- package/dist/react-core/session.d.ts +45 -0
- package/dist/react-core/session.d.ts.map +1 -0
- package/dist/react-core/session.js +130 -0
- package/dist/react-core/session.js.map +1 -0
- package/dist/react-core/use-account-state.d.ts +4 -0
- package/dist/react-core/use-account-state.d.ts.map +1 -0
- package/dist/react-core/use-account-state.js +6 -0
- package/dist/react-core/use-account-state.js.map +1 -0
- package/dist/react-core/use-all.d.ts +95 -3
- package/dist/react-core/use-all.d.ts.map +1 -1
- package/dist/react-core/use-all.js +126 -52
- package/dist/react-core/use-all.js.map +1 -1
- package/dist/react-core/use-auth-state.d.ts +13 -0
- package/dist/react-core/use-auth-state.d.ts.map +1 -0
- package/dist/react-core/use-auth-state.js +15 -0
- package/dist/react-core/use-auth-state.js.map +1 -0
- package/dist/react-core/use-local-first-auth.d.ts +12 -0
- package/dist/react-core/use-local-first-auth.d.ts.map +1 -0
- package/dist/react-core/use-local-first-auth.js +14 -0
- package/dist/react-core/use-local-first-auth.js.map +1 -0
- package/dist/react-core/use-one.d.ts +58 -0
- package/dist/react-core/use-one.d.ts.map +1 -0
- package/dist/react-core/use-one.js +19 -0
- package/dist/react-core/use-one.js.map +1 -0
- package/dist/react-core/use-sync-status.d.ts +8 -0
- package/dist/react-core/use-sync-status.d.ts.map +1 -0
- package/dist/react-core/use-sync-status.js +12 -0
- package/dist/react-core/use-sync-status.js.map +1 -0
- package/dist/react-native/abort-signal.d.ts +9 -0
- package/dist/react-native/abort-signal.d.ts.map +1 -0
- package/dist/react-native/abort-signal.js +51 -0
- package/dist/react-native/abort-signal.js.map +1 -0
- package/dist/react-native/account-session.d.ts +11 -0
- package/dist/react-native/account-session.d.ts.map +1 -0
- package/dist/react-native/account-session.js +59 -0
- package/dist/react-native/account-session.js.map +1 -0
- package/dist/react-native/create-account-manager.d.ts +28 -0
- package/dist/react-native/create-account-manager.d.ts.map +1 -0
- package/dist/react-native/create-account-manager.js +30 -0
- package/dist/react-native/create-account-manager.js.map +1 -0
- package/dist/react-native/create-db.d.ts +8 -0
- package/dist/react-native/create-db.d.ts.map +1 -0
- package/dist/react-native/create-db.js +9 -0
- package/dist/react-native/create-db.js.map +1 -0
- package/dist/react-native/create-jazz-client.d.ts +12 -10
- package/dist/react-native/create-jazz-client.d.ts.map +1 -1
- package/dist/react-native/create-jazz-client.js +6 -21
- package/dist/react-native/create-jazz-client.js.map +1 -1
- package/dist/react-native/create-jazz-session.d.ts +35 -0
- package/dist/react-native/create-jazz-session.d.ts.map +1 -0
- package/dist/react-native/create-jazz-session.js +39 -0
- package/dist/react-native/create-jazz-session.js.map +1 -0
- package/dist/react-native/errors.d.ts +6 -0
- package/dist/react-native/errors.d.ts.map +1 -0
- package/dist/react-native/errors.js +6 -0
- package/dist/react-native/errors.js.map +1 -0
- package/dist/react-native/index.d.ts +25 -9
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +17 -7
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/native-foreground-db.d.ts +192 -0
- package/dist/react-native/native-foreground-db.d.ts.map +1 -0
- package/dist/react-native/native-foreground-db.js +801 -0
- package/dist/react-native/native-foreground-db.js.map +1 -0
- package/dist/react-native/native-relay.d.ts +7 -0
- package/dist/react-native/native-relay.d.ts.map +1 -0
- package/dist/react-native/native-relay.js +14 -0
- package/dist/react-native/native-relay.js.map +1 -0
- package/dist/react-native/provider.d.ts +23 -10
- package/dist/react-native/provider.d.ts.map +1 -1
- package/dist/react-native/provider.js +23 -3
- package/dist/react-native/provider.js.map +1 -1
- package/dist/react-native/runtime-source.d.ts +40 -0
- package/dist/react-native/runtime-source.d.ts.map +1 -0
- package/dist/react-native/runtime-source.js +250 -0
- package/dist/react-native/runtime-source.js.map +1 -0
- package/dist/react-native/session.d.ts +10 -0
- package/dist/react-native/session.d.ts.map +1 -0
- package/dist/react-native/session.js +5 -0
- package/dist/react-native/session.js.map +1 -0
- package/dist/react-native/use-all.d.ts +1 -1
- package/dist/react-native/use-all.d.ts.map +1 -1
- package/dist/react-native/use-all.js +1 -1
- package/dist/react-native/use-all.js.map +1 -1
- package/dist/react-native/use-local-first-auth.d.ts +15 -0
- package/dist/react-native/use-local-first-auth.d.ts.map +1 -0
- package/dist/react-native/use-local-first-auth.js +14 -0
- package/dist/react-native/use-local-first-auth.js.map +1 -0
- package/dist/react-native/use-one.d.ts +2 -0
- package/dist/react-native/use-one.d.ts.map +1 -0
- package/dist/react-native/use-one.js +2 -0
- package/dist/react-native/use-one.js.map +1 -0
- package/dist/reconcile-array.d.ts +45 -0
- package/dist/reconcile-array.d.ts.map +1 -0
- package/dist/reconcile-array.js +252 -0
- package/dist/reconcile-array.js.map +1 -0
- package/dist/relationships.d.ts +18 -0
- package/dist/relationships.d.ts.map +1 -0
- package/dist/relationships.js +28 -0
- package/dist/relationships.js.map +1 -0
- package/dist/runtime/anonymous-write-denied-error.d.ts +13 -0
- package/dist/runtime/anonymous-write-denied-error.d.ts.map +1 -0
- package/dist/runtime/anonymous-write-denied-error.js +58 -0
- package/dist/runtime/anonymous-write-denied-error.js.map +1 -0
- package/dist/runtime/auth-renewal-backoff.d.ts +14 -0
- package/dist/runtime/auth-renewal-backoff.d.ts.map +1 -0
- package/dist/runtime/auth-renewal-backoff.js +23 -0
- package/dist/runtime/auth-renewal-backoff.js.map +1 -0
- package/dist/runtime/auth-request-deadline.d.ts +3 -0
- package/dist/runtime/auth-request-deadline.d.ts.map +1 -0
- package/dist/runtime/auth-request-deadline.js +24 -0
- package/dist/runtime/auth-request-deadline.js.map +1 -0
- package/dist/runtime/auth-secret-codec.d.ts +21 -0
- package/dist/runtime/auth-secret-codec.d.ts.map +1 -0
- package/dist/runtime/auth-secret-codec.js +32 -0
- package/dist/runtime/auth-secret-codec.js.map +1 -0
- package/dist/runtime/auth-secret-store.d.ts +51 -0
- package/dist/runtime/auth-secret-store.d.ts.map +1 -0
- package/dist/runtime/auth-secret-store.js +114 -0
- package/dist/runtime/auth-secret-store.js.map +1 -0
- package/dist/runtime/auth-state.d.ts +40 -0
- package/dist/runtime/auth-state.d.ts.map +1 -0
- package/dist/runtime/auth-state.js +145 -0
- package/dist/runtime/auth-state.js.map +1 -0
- package/dist/runtime/author-id.d.ts +42 -0
- package/dist/runtime/author-id.d.ts.map +1 -0
- package/dist/runtime/author-id.js +172 -0
- package/dist/runtime/author-id.js.map +1 -0
- package/dist/runtime/authority-changed-error.d.ts +54 -0
- package/dist/runtime/authority-changed-error.d.ts.map +1 -0
- package/dist/runtime/authority-changed-error.js +72 -0
- package/dist/runtime/authority-changed-error.js.map +1 -0
- package/dist/runtime/browser-physical-database-epoch.d.ts +37 -0
- package/dist/runtime/browser-physical-database-epoch.d.ts.map +1 -0
- package/dist/runtime/browser-physical-database-epoch.js +89 -0
- package/dist/runtime/browser-physical-database-epoch.js.map +1 -0
- package/dist/runtime/browser-storage-invalidation.d.ts +8 -0
- package/dist/runtime/browser-storage-invalidation.d.ts.map +1 -0
- package/dist/runtime/browser-storage-invalidation.js +20 -0
- package/dist/runtime/browser-storage-invalidation.js.map +1 -0
- package/dist/runtime/browser-worker-assets.d.ts +4 -0
- package/dist/runtime/browser-worker-assets.d.ts.map +1 -0
- package/dist/runtime/browser-worker-assets.js +8 -0
- package/dist/runtime/browser-worker-assets.js.map +1 -0
- package/dist/runtime/browser-worker-assets.native.d.ts +5 -0
- package/dist/runtime/browser-worker-assets.native.d.ts.map +1 -0
- package/dist/runtime/browser-worker-assets.native.js +6 -0
- package/dist/runtime/browser-worker-assets.native.js.map +1 -0
- package/dist/runtime/browser-worker-config.d.ts +55 -0
- package/dist/runtime/browser-worker-config.d.ts.map +1 -0
- package/dist/runtime/browser-worker-config.js +222 -0
- package/dist/runtime/browser-worker-config.js.map +1 -0
- package/dist/runtime/client-config-key.d.ts +6 -0
- package/dist/runtime/client-config-key.d.ts.map +1 -0
- package/dist/runtime/client-config-key.js +83 -0
- package/dist/runtime/client-config-key.js.map +1 -0
- package/dist/runtime/client-migrations.d.ts +33 -0
- package/dist/runtime/client-migrations.d.ts.map +1 -0
- package/dist/runtime/client-migrations.js +30 -0
- package/dist/runtime/client-migrations.js.map +1 -0
- package/dist/runtime/client-registry.d.ts +21 -0
- package/dist/runtime/client-registry.d.ts.map +1 -0
- package/dist/runtime/client-registry.js +169 -0
- package/dist/runtime/client-registry.js.map +1 -0
- package/dist/runtime/client-scope.d.ts +38 -0
- package/dist/runtime/client-scope.d.ts.map +1 -0
- package/dist/runtime/client-scope.js +64 -0
- package/dist/runtime/client-scope.js.map +1 -0
- package/dist/runtime/client-session.d.ts +56 -13
- package/dist/runtime/client-session.d.ts.map +1 -1
- package/dist/runtime/client-session.js +212 -196
- package/dist/runtime/client-session.js.map +1 -1
- package/dist/runtime/client.d.ts +624 -191
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +1105 -425
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/column-transforms.d.ts +40 -0
- package/dist/runtime/column-transforms.d.ts.map +1 -0
- package/dist/runtime/column-transforms.js +279 -0
- package/dist/runtime/column-transforms.js.map +1 -0
- package/dist/runtime/connection-manager/browser-connection-manager.d.ts +119 -0
- package/dist/runtime/connection-manager/browser-connection-manager.d.ts.map +1 -0
- package/dist/runtime/connection-manager/browser-connection-manager.js +836 -0
- package/dist/runtime/connection-manager/browser-connection-manager.js.map +1 -0
- package/dist/runtime/connection-manager/direct-connection-manager.d.ts +26 -0
- package/dist/runtime/connection-manager/direct-connection-manager.d.ts.map +1 -0
- package/dist/runtime/connection-manager/direct-connection-manager.js +198 -0
- package/dist/runtime/connection-manager/direct-connection-manager.js.map +1 -0
- package/dist/runtime/connection-manager/index.d.ts +5 -0
- package/dist/runtime/connection-manager/index.d.ts.map +1 -0
- package/dist/runtime/connection-manager/index.js +4 -0
- package/dist/runtime/connection-manager/index.js.map +1 -0
- package/dist/runtime/connection-manager/types.d.ts +136 -0
- package/dist/runtime/connection-manager/types.d.ts.map +1 -0
- package/dist/runtime/connection-manager/types.js +340 -0
- package/dist/runtime/connection-manager/types.js.map +1 -0
- package/dist/runtime/context.d.ts +90 -30
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/credentialed-transport.d.ts +27 -0
- package/dist/runtime/credentialed-transport.d.ts.map +1 -0
- package/dist/runtime/credentialed-transport.js +155 -0
- package/dist/runtime/credentialed-transport.js.map +1 -0
- package/dist/runtime/db-access-context.d.ts +14 -0
- package/dist/runtime/db-access-context.d.ts.map +1 -0
- package/dist/runtime/db-access-context.js +26 -0
- package/dist/runtime/db-access-context.js.map +1 -0
- package/dist/runtime/db-internal-session.d.ts +7 -0
- package/dist/runtime/db-internal-session.d.ts.map +1 -0
- package/dist/runtime/db-internal-session.js +21 -0
- package/dist/runtime/db-internal-session.js.map +1 -0
- package/dist/runtime/db-replaced-error.d.ts +19 -0
- package/dist/runtime/db-replaced-error.d.ts.map +1 -0
- package/dist/runtime/db-replaced-error.js +20 -0
- package/dist/runtime/db-replaced-error.js.map +1 -0
- package/dist/runtime/db.d.ts +735 -201
- package/dist/runtime/db.d.ts.map +1 -1
- package/dist/runtime/db.js +3287 -727
- package/dist/runtime/db.js.map +1 -1
- package/dist/runtime/default-create-db.d.ts +5 -0
- package/dist/runtime/default-create-db.d.ts.map +1 -0
- package/dist/runtime/default-create-db.js +7 -0
- package/dist/runtime/default-create-db.js.map +1 -0
- package/dist/runtime/default-runtime-source.d.ts +41 -0
- package/dist/runtime/default-runtime-source.d.ts.map +1 -0
- package/dist/runtime/default-runtime-source.js +315 -0
- package/dist/runtime/default-runtime-source.js.map +1 -0
- package/dist/runtime/deterministic-bytes.d.ts +6 -0
- package/dist/runtime/deterministic-bytes.d.ts.map +1 -0
- package/dist/runtime/deterministic-bytes.js +18 -0
- package/dist/runtime/deterministic-bytes.js.map +1 -0
- package/dist/runtime/graceful-shutdown-error.d.ts +9 -0
- package/dist/runtime/graceful-shutdown-error.d.ts.map +1 -0
- package/dist/runtime/graceful-shutdown-error.js +17 -0
- package/dist/runtime/graceful-shutdown-error.js.map +1 -0
- package/dist/runtime/hex.d.ts +17 -0
- package/dist/runtime/hex.d.ts.map +1 -0
- package/dist/runtime/hex.js +56 -0
- package/dist/runtime/hex.js.map +1 -0
- package/dist/runtime/history-relation.d.ts +8 -0
- package/dist/runtime/history-relation.d.ts.map +1 -0
- package/dist/runtime/history-relation.js +44 -0
- package/dist/runtime/history-relation.js.map +1 -0
- package/dist/runtime/in-process-transport.d.ts +18 -0
- package/dist/runtime/in-process-transport.d.ts.map +1 -0
- package/dist/runtime/in-process-transport.js +32 -0
- package/dist/runtime/in-process-transport.js.map +1 -0
- package/dist/runtime/index.d.ts +22 -11
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +14 -10
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/indexeddb-page-store.d.ts +214 -0
- package/dist/runtime/indexeddb-page-store.d.ts.map +1 -0
- package/dist/runtime/indexeddb-page-store.js +848 -0
- package/dist/runtime/indexeddb-page-store.js.map +1 -0
- package/dist/runtime/introspection-fetch.d.ts +18 -0
- package/dist/runtime/introspection-fetch.d.ts.map +1 -0
- package/dist/runtime/introspection-fetch.js +12 -0
- package/dist/runtime/introspection-fetch.js.map +1 -0
- package/dist/runtime/json-schema-evaluate.d.ts +55 -0
- package/dist/runtime/json-schema-evaluate.d.ts.map +1 -0
- package/dist/runtime/json-schema-evaluate.js +946 -0
- package/dist/runtime/json-schema-evaluate.js.map +1 -0
- package/dist/runtime/json-schema-formats.d.ts +14 -0
- package/dist/runtime/json-schema-formats.d.ts.map +1 -0
- package/dist/runtime/json-schema-formats.js +555 -0
- package/dist/runtime/json-schema-formats.js.map +1 -0
- package/dist/runtime/json-schema-json.d.ts +41 -0
- package/dist/runtime/json-schema-json.d.ts.map +1 -0
- package/dist/runtime/json-schema-json.js +309 -0
- package/dist/runtime/json-schema-json.js.map +1 -0
- package/dist/runtime/json-schema-metaschemas.d.ts +1403 -0
- package/dist/runtime/json-schema-metaschemas.d.ts.map +1 -0
- package/dist/runtime/json-schema-metaschemas.js +64 -0
- package/dist/runtime/json-schema-metaschemas.js.map +1 -0
- package/dist/runtime/json-schema-regex.d.ts +32 -0
- package/dist/runtime/json-schema-regex.d.ts.map +1 -0
- package/dist/runtime/json-schema-regex.js +895 -0
- package/dist/runtime/json-schema-regex.js.map +1 -0
- package/dist/runtime/json-schema-validator.d.ts +47 -0
- package/dist/runtime/json-schema-validator.d.ts.map +1 -0
- package/dist/runtime/json-schema-validator.js +404 -0
- package/dist/runtime/json-schema-validator.js.map +1 -0
- package/dist/runtime/json-text.d.ts +2 -0
- package/dist/runtime/json-text.d.ts.map +1 -0
- package/dist/runtime/json-text.js +17 -0
- package/dist/runtime/json-text.js.map +1 -0
- package/dist/runtime/local-first-auth-controller.d.ts +29 -0
- package/dist/runtime/local-first-auth-controller.d.ts.map +1 -0
- package/dist/runtime/local-first-auth-controller.js +101 -0
- package/dist/runtime/local-first-auth-controller.js.map +1 -0
- package/dist/runtime/local-first-token.d.ts +11 -0
- package/dist/runtime/local-first-token.d.ts.map +1 -0
- package/dist/runtime/local-first-token.js +20 -0
- package/dist/runtime/local-first-token.js.map +1 -0
- package/dist/runtime/local-first-upgrade.d.ts +27 -0
- package/dist/runtime/local-first-upgrade.d.ts.map +1 -0
- package/dist/runtime/local-first-upgrade.js +31 -0
- package/dist/runtime/local-first-upgrade.js.map +1 -0
- package/dist/runtime/local-write-observer.d.ts +5 -0
- package/dist/runtime/local-write-observer.d.ts.map +1 -0
- package/dist/runtime/local-write-observer.js +31 -0
- package/dist/runtime/local-write-observer.js.map +1 -0
- package/dist/runtime/native-artifact-compatibility.d.ts +12 -0
- package/dist/runtime/native-artifact-compatibility.d.ts.map +1 -0
- package/dist/runtime/native-artifact-compatibility.js +24 -0
- package/dist/runtime/native-artifact-compatibility.js.map +1 -0
- package/dist/runtime/native-artifact-fingerprint-napi.d.ts +2 -0
- package/dist/runtime/native-artifact-fingerprint-napi.d.ts.map +1 -0
- package/dist/runtime/native-artifact-fingerprint-napi.js +3 -0
- package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -0
- package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +2 -0
- package/dist/runtime/native-artifact-fingerprint-wasm.d.ts.map +1 -0
- package/dist/runtime/native-artifact-fingerprint-wasm.js +3 -0
- package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -0
- package/dist/runtime/native-artifact-fingerprints.d.ts +5 -0
- package/dist/runtime/native-artifact-fingerprints.d.ts.map +1 -0
- package/dist/runtime/native-artifact-fingerprints.js +7 -0
- package/dist/runtime/native-artifact-fingerprints.js.map +1 -0
- package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts +20 -0
- package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts.map +1 -0
- package/dist/runtime/native-runtime/attached-browser-worker-connection.js +42 -0
- package/dist/runtime/native-runtime/attached-browser-worker-connection.js.map +1 -0
- package/dist/runtime/native-runtime/auxiliary-receive-deadline.d.ts +15 -0
- package/dist/runtime/native-runtime/auxiliary-receive-deadline.d.ts.map +1 -0
- package/dist/runtime/native-runtime/auxiliary-receive-deadline.js +64 -0
- package/dist/runtime/native-runtime/auxiliary-receive-deadline.js.map +1 -0
- package/dist/runtime/native-runtime/browser-follower-connection.d.ts +78 -0
- package/dist/runtime/native-runtime/browser-follower-connection.d.ts.map +1 -0
- package/dist/runtime/native-runtime/browser-follower-connection.js +494 -0
- package/dist/runtime/native-runtime/browser-follower-connection.js.map +1 -0
- package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts +96 -0
- package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts.map +1 -0
- package/dist/runtime/native-runtime/browser-shared-worker-connection.js +780 -0
- package/dist/runtime/native-runtime/browser-shared-worker-connection.js.map +1 -0
- package/dist/runtime/native-runtime/browser-worker-protocol.d.ts +455 -0
- package/dist/runtime/native-runtime/browser-worker-protocol.d.ts.map +1 -0
- package/dist/runtime/native-runtime/browser-worker-protocol.js +281 -0
- package/dist/runtime/native-runtime/browser-worker-protocol.js.map +1 -0
- package/dist/runtime/native-runtime/browser-worker-transport.d.ts +53 -0
- package/dist/runtime/native-runtime/browser-worker-transport.d.ts.map +1 -0
- package/dist/runtime/native-runtime/browser-worker-transport.js +252 -0
- package/dist/runtime/native-runtime/browser-worker-transport.js.map +1 -0
- package/dist/runtime/native-runtime/exact-integer.d.ts +7 -0
- package/dist/runtime/native-runtime/exact-integer.d.ts.map +1 -0
- package/dist/runtime/native-runtime/exact-integer.js +18 -0
- package/dist/runtime/native-runtime/exact-integer.js.map +1 -0
- package/dist/runtime/native-runtime/http-stream-socket.d.ts +85 -0
- package/dist/runtime/native-runtime/http-stream-socket.d.ts.map +1 -0
- package/dist/runtime/native-runtime/http-stream-socket.js +433 -0
- package/dist/runtime/native-runtime/http-stream-socket.js.map +1 -0
- package/dist/runtime/native-runtime/inspector-control-lifecycle.d.ts +4 -0
- package/dist/runtime/native-runtime/inspector-control-lifecycle.d.ts.map +1 -0
- package/dist/runtime/native-runtime/inspector-control-lifecycle.js +33 -0
- package/dist/runtime/native-runtime/inspector-control-lifecycle.js.map +1 -0
- package/dist/runtime/native-runtime/native-codec.d.ts +177 -0
- package/dist/runtime/native-runtime/native-codec.d.ts.map +1 -0
- package/dist/runtime/native-runtime/native-codec.js +627 -0
- package/dist/runtime/native-runtime/native-codec.js.map +1 -0
- package/dist/runtime/native-runtime/native-error-code.d.ts +39 -0
- package/dist/runtime/native-runtime/native-error-code.d.ts.map +1 -0
- package/dist/runtime/native-runtime/native-error-code.js +62 -0
- package/dist/runtime/native-runtime/native-error-code.js.map +1 -0
- package/dist/runtime/native-runtime/native-row-codec.d.ts +161 -0
- package/dist/runtime/native-runtime/native-row-codec.d.ts.map +1 -0
- package/dist/runtime/native-runtime/native-row-codec.js +942 -0
- package/dist/runtime/native-runtime/native-row-codec.js.map +1 -0
- package/dist/runtime/native-runtime/native-row-descriptor-key.d.ts +15 -0
- package/dist/runtime/native-runtime/native-row-descriptor-key.d.ts.map +1 -0
- package/dist/runtime/native-runtime/native-row-descriptor-key.js +25 -0
- package/dist/runtime/native-runtime/native-row-descriptor-key.js.map +1 -0
- package/dist/runtime/native-runtime/native-runtime-adapter.d.ts +728 -0
- package/dist/runtime/native-runtime/native-runtime-adapter.d.ts.map +1 -0
- package/dist/runtime/native-runtime/native-runtime-adapter.js +5705 -0
- package/dist/runtime/native-runtime/native-runtime-adapter.js.map +1 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.browser.d.ts +17 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.browser.d.ts.map +1 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.browser.js +4 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.browser.js.map +1 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.d.ts +19 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.d.ts.map +1 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.js +297 -0
- package/dist/runtime/native-runtime/node-foreground-node-lease.js.map +1 -0
- package/dist/runtime/native-runtime/row-values-transport.d.ts +2 -0
- package/dist/runtime/native-runtime/row-values-transport.d.ts.map +1 -0
- package/dist/runtime/native-runtime/row-values-transport.js +21 -0
- package/dist/runtime/native-runtime/row-values-transport.js.map +1 -0
- package/dist/runtime/native-runtime/schema-codec.d.ts +10 -0
- package/dist/runtime/native-runtime/schema-codec.d.ts.map +1 -0
- package/dist/runtime/native-runtime/schema-codec.js +13 -0
- package/dist/runtime/native-runtime/schema-codec.js.map +1 -0
- package/dist/runtime/native-runtime/websocket.d.ts +165 -0
- package/dist/runtime/native-runtime/websocket.d.ts.map +1 -0
- package/dist/runtime/native-runtime/websocket.js +713 -0
- package/dist/runtime/native-runtime/websocket.js.map +1 -0
- package/dist/runtime/passkey-backup.d.ts +3 -0
- package/dist/runtime/passkey-backup.d.ts.map +1 -0
- package/dist/runtime/passkey-backup.js +2 -0
- package/dist/runtime/passkey-backup.js.map +1 -0
- package/dist/runtime/platform-url.d.ts +10 -0
- package/dist/runtime/platform-url.d.ts.map +1 -0
- package/dist/runtime/platform-url.js +3 -0
- package/dist/runtime/platform-url.js.map +1 -0
- package/dist/runtime/platform-url.native.d.ts +6 -0
- package/dist/runtime/platform-url.native.d.ts.map +1 -0
- package/dist/runtime/platform-url.native.js +37 -0
- package/dist/runtime/platform-url.native.js.map +1 -0
- package/dist/runtime/query-adapter.d.ts +7 -15
- package/dist/runtime/query-adapter.d.ts.map +1 -1
- package/dist/runtime/query-adapter.js +554 -167
- package/dist/runtime/query-adapter.js.map +1 -1
- package/dist/runtime/query-builder-shape.d.ts +75 -0
- package/dist/runtime/query-builder-shape.d.ts.map +1 -0
- package/dist/runtime/query-builder-shape.js +225 -0
- package/dist/runtime/query-builder-shape.js.map +1 -0
- package/dist/runtime/query-column-name.d.ts +3 -0
- package/dist/runtime/query-column-name.d.ts.map +1 -0
- package/dist/runtime/query-column-name.js +10 -0
- package/dist/runtime/query-column-name.js.map +1 -0
- package/dist/runtime/query-output-table.d.ts +5 -0
- package/dist/runtime/query-output-table.d.ts.map +1 -0
- package/dist/runtime/query-output-table.js +30 -0
- package/dist/runtime/query-output-table.js.map +1 -0
- package/dist/runtime/recovery-phrase.d.ts +3 -0
- package/dist/runtime/recovery-phrase.d.ts.map +1 -0
- package/dist/runtime/recovery-phrase.js +2 -0
- package/dist/runtime/recovery-phrase.js.map +1 -0
- package/dist/runtime/remote-link-state.d.ts +20 -0
- package/dist/runtime/remote-link-state.d.ts.map +1 -0
- package/dist/runtime/remote-link-state.js +5 -0
- package/dist/runtime/remote-link-state.js.map +1 -0
- package/dist/runtime/row-transformer.d.ts +18 -6
- package/dist/runtime/row-transformer.d.ts.map +1 -1
- package/dist/runtime/row-transformer.js +195 -41
- package/dist/runtime/row-transformer.js.map +1 -1
- package/dist/runtime/run-cleanup-steps.d.ts +5 -0
- package/dist/runtime/run-cleanup-steps.d.ts.map +1 -0
- package/dist/runtime/run-cleanup-steps.js +19 -0
- package/dist/runtime/run-cleanup-steps.js.map +1 -0
- package/dist/runtime/runtime-closed-error.d.ts +9 -0
- package/dist/runtime/runtime-closed-error.d.ts.map +1 -0
- package/dist/runtime/runtime-closed-error.js +12 -0
- package/dist/runtime/runtime-closed-error.js.map +1 -0
- package/dist/runtime/runtime-config.d.ts +9 -0
- package/dist/runtime/runtime-config.d.ts.map +1 -0
- package/dist/runtime/runtime-config.js +111 -0
- package/dist/runtime/runtime-config.js.map +1 -0
- package/dist/runtime/runtime-entropy.d.ts +14 -0
- package/dist/runtime/runtime-entropy.d.ts.map +1 -0
- package/dist/runtime/runtime-entropy.js +43 -0
- package/dist/runtime/runtime-entropy.js.map +1 -0
- package/dist/runtime/runtime-source.d.ts +167 -0
- package/dist/runtime/runtime-source.d.ts.map +1 -0
- package/dist/runtime/runtime-source.js +64 -0
- package/dist/runtime/runtime-source.js.map +1 -0
- package/dist/runtime/schema-metadata.d.ts +5 -0
- package/dist/runtime/schema-metadata.d.ts.map +1 -0
- package/dist/runtime/schema-metadata.js +34 -0
- package/dist/runtime/schema-metadata.js.map +1 -0
- package/dist/runtime/select-projection.d.ts +5 -0
- package/dist/runtime/select-projection.d.ts.map +1 -0
- package/dist/runtime/select-projection.js +47 -0
- package/dist/runtime/select-projection.js.map +1 -0
- package/dist/runtime/snapshot-ref.d.ts +24 -0
- package/dist/runtime/snapshot-ref.d.ts.map +1 -0
- package/dist/runtime/snapshot-ref.js +43 -0
- package/dist/runtime/snapshot-ref.js.map +1 -0
- package/dist/runtime/store-held-by-another-tab-error.d.ts +36 -0
- package/dist/runtime/store-held-by-another-tab-error.d.ts.map +1 -0
- package/dist/runtime/store-held-by-another-tab-error.js +38 -0
- package/dist/runtime/store-held-by-another-tab-error.js.map +1 -0
- package/dist/runtime/streaming-source.d.ts +4 -0
- package/dist/runtime/streaming-source.d.ts.map +1 -0
- package/dist/runtime/streaming-source.js +53 -0
- package/dist/runtime/streaming-source.js.map +1 -0
- package/dist/runtime/structural-values.d.ts +6 -0
- package/dist/runtime/structural-values.d.ts.map +1 -0
- package/dist/runtime/structural-values.js +55 -0
- package/dist/runtime/structural-values.js.map +1 -0
- package/dist/runtime/subscription-manager.d.ts +98 -14
- package/dist/runtime/subscription-manager.d.ts.map +1 -1
- package/dist/runtime/subscription-manager.js +1049 -25
- package/dist/runtime/subscription-manager.js.map +1 -1
- package/dist/runtime/sync-status.d.ts +98 -0
- package/dist/runtime/sync-status.d.ts.map +1 -0
- package/dist/runtime/sync-status.js +93 -0
- package/dist/runtime/sync-status.js.map +1 -0
- package/dist/runtime/sync-telemetry.d.ts +35 -0
- package/dist/runtime/sync-telemetry.d.ts.map +1 -0
- package/dist/runtime/sync-telemetry.js +354 -0
- package/dist/runtime/sync-telemetry.js.map +1 -0
- package/dist/runtime/system-identity.d.ts +5 -0
- package/dist/runtime/system-identity.d.ts.map +1 -0
- package/dist/runtime/system-identity.js +10 -0
- package/dist/runtime/system-identity.js.map +1 -0
- package/dist/runtime/telemetry-env.d.ts +2 -0
- package/dist/runtime/telemetry-env.d.ts.map +1 -0
- package/dist/runtime/telemetry-env.js +16 -0
- package/dist/runtime/telemetry-env.js.map +1 -0
- package/dist/runtime/telemetry-env.native.d.ts +3 -0
- package/dist/runtime/telemetry-env.native.d.ts.map +1 -0
- package/dist/runtime/telemetry-env.native.js +7 -0
- package/dist/runtime/telemetry-env.native.js.map +1 -0
- package/dist/runtime/text-anchors.d.ts +58 -0
- package/dist/runtime/text-anchors.d.ts.map +1 -0
- package/dist/runtime/text-anchors.js +9 -0
- package/dist/runtime/text-anchors.js.map +1 -0
- package/dist/runtime/unsupported-storage-codecs-error.d.ts +53 -0
- package/dist/runtime/unsupported-storage-codecs-error.d.ts.map +1 -0
- package/dist/runtime/unsupported-storage-codecs-error.js +74 -0
- package/dist/runtime/unsupported-storage-codecs-error.js.map +1 -0
- package/dist/runtime/url.d.ts +32 -0
- package/dist/runtime/url.d.ts.map +1 -0
- package/dist/runtime/url.js +96 -0
- package/dist/runtime/url.js.map +1 -0
- package/dist/runtime/utf8.d.ts +10 -0
- package/dist/runtime/utf8.d.ts.map +1 -0
- package/dist/runtime/utf8.js +93 -0
- package/dist/runtime/utf8.js.map +1 -0
- package/dist/runtime/util.d.ts +18 -0
- package/dist/runtime/util.d.ts.map +1 -0
- package/dist/runtime/util.js +59 -0
- package/dist/runtime/util.js.map +1 -0
- package/dist/runtime/value-converter.d.ts +9 -17
- package/dist/runtime/value-converter.d.ts.map +1 -1
- package/dist/runtime/value-converter.js +196 -43
- package/dist/runtime/value-converter.js.map +1 -1
- package/dist/runtime/wasm-loader.d.ts +6 -0
- package/dist/runtime/wasm-loader.d.ts.map +1 -0
- package/dist/runtime/wasm-loader.js +120 -0
- package/dist/runtime/wasm-loader.js.map +1 -0
- package/dist/runtime/write-preparation.d.ts +24 -0
- package/dist/runtime/write-preparation.d.ts.map +1 -0
- package/dist/runtime/write-preparation.js +63 -0
- package/dist/runtime/write-preparation.js.map +1 -0
- package/dist/runtime/write-row.d.ts +8 -0
- package/dist/runtime/write-row.d.ts.map +1 -0
- package/dist/runtime/write-row.js +17 -0
- package/dist/runtime/write-row.js.map +1 -0
- package/dist/schema-hash.d.ts +3 -0
- package/dist/schema-hash.d.ts.map +1 -0
- package/dist/schema-hash.js +5 -0
- package/dist/schema-hash.js.map +1 -0
- package/dist/schema-loader.d.ts +31 -0
- package/dist/schema-loader.d.ts.map +1 -0
- package/dist/schema-loader.js +501 -0
- package/dist/schema-loader.js.map +1 -0
- package/dist/schema-name.d.ts +2 -0
- package/dist/schema-name.d.ts.map +1 -0
- package/dist/schema-name.js +19 -0
- package/dist/schema-name.js.map +1 -0
- package/dist/schema-namespace.d.ts +35 -0
- package/dist/schema-namespace.d.ts.map +1 -0
- package/dist/schema-namespace.js +17 -0
- package/dist/schema-namespace.js.map +1 -0
- package/dist/schema-permissions.d.ts +16 -0
- package/dist/schema-permissions.d.ts.map +1 -0
- package/dist/schema-permissions.js +405 -0
- package/dist/schema-permissions.js.map +1 -0
- package/dist/schema-source.d.ts +11 -0
- package/dist/schema-source.d.ts.map +1 -0
- package/dist/schema-source.js +39 -0
- package/dist/schema-source.js.map +1 -0
- package/dist/schema.d.ts +108 -36
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -10
- package/dist/schema.js.map +1 -1
- package/dist/session/app.d.ts +58 -0
- package/dist/session/app.d.ts.map +1 -0
- package/dist/session/app.js +325 -0
- package/dist/session/app.js.map +1 -0
- package/dist/session/backend-watch.d.ts +138 -0
- package/dist/session/backend-watch.d.ts.map +1 -0
- package/dist/session/backend-watch.js +576 -0
- package/dist/session/backend-watch.js.map +1 -0
- package/dist/session/consumer.d.ts +3 -0
- package/dist/session/consumer.d.ts.map +1 -0
- package/dist/session/consumer.js +3 -0
- package/dist/session/consumer.js.map +1 -0
- package/dist/session/create-jazz-app.d.ts +11 -0
- package/dist/session/create-jazz-app.d.ts.map +1 -0
- package/dist/session/create-jazz-app.js +11 -0
- package/dist/session/create-jazz-app.js.map +1 -0
- package/dist/session/create-jazz-session.d.ts +68 -0
- package/dist/session/create-jazz-session.d.ts.map +1 -0
- package/dist/session/create-jazz-session.js +448 -0
- package/dist/session/create-jazz-session.js.map +1 -0
- package/dist/session/follow-user.d.ts +53 -0
- package/dist/session/follow-user.d.ts.map +1 -0
- package/dist/session/follow-user.js +107 -0
- package/dist/session/follow-user.js.map +1 -0
- package/dist/session/left-behind-replicas.d.ts +62 -0
- package/dist/session/left-behind-replicas.d.ts.map +1 -0
- package/dist/session/left-behind-replicas.js +146 -0
- package/dist/session/left-behind-replicas.js.map +1 -0
- package/dist/session/native-backend-watch.d.ts +4 -0
- package/dist/session/native-backend-watch.d.ts.map +1 -0
- package/dist/session/native-backend-watch.js +14 -0
- package/dist/session/native-backend-watch.js.map +1 -0
- package/dist/session/state.d.ts +93 -0
- package/dist/session/state.d.ts.map +1 -0
- package/dist/session/state.js +383 -0
- package/dist/session/state.js.map +1 -0
- package/dist/shared/index.d.ts +20 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +17 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/solid/app.d.ts +30 -0
- package/dist/solid/app.d.ts.map +1 -0
- package/dist/solid/app.js +95 -0
- package/dist/solid/app.js.map +1 -0
- package/dist/solid/app.ssr.js +109 -0
- package/dist/solid/app.ssr.js.map +1 -0
- package/dist/solid/create-account-state.d.ts +4 -0
- package/dist/solid/create-account-state.d.ts.map +1 -0
- package/dist/solid/create-account-state.js +10 -0
- package/dist/solid/create-account-state.js.map +1 -0
- package/dist/solid/create-account-state.ssr.js +12 -0
- package/dist/solid/create-account-state.ssr.js.map +1 -0
- package/dist/solid/create-solid-jazz-client-internal.d.ts +13 -0
- package/dist/solid/create-solid-jazz-client-internal.d.ts.map +1 -0
- package/dist/solid/create-solid-jazz-client-internal.js +83 -0
- package/dist/solid/create-solid-jazz-client-internal.js.map +1 -0
- package/dist/solid/create-solid-jazz-client-internal.ssr.js +101 -0
- package/dist/solid/create-solid-jazz-client-internal.ssr.js.map +1 -0
- package/dist/solid/create-solid-jazz-client.d.ts +24 -0
- package/dist/solid/create-solid-jazz-client.d.ts.map +1 -0
- package/dist/solid/create-solid-jazz-client.js +43 -0
- package/dist/solid/create-solid-jazz-client.js.map +1 -0
- package/dist/solid/create-solid-jazz-client.ssr.js +46 -0
- package/dist/solid/create-solid-jazz-client.ssr.js.map +1 -0
- package/dist/solid/index.d.ts +20 -0
- package/dist/solid/index.d.ts.map +1 -0
- package/dist/solid/index.js +13 -0
- package/dist/solid/index.ssr.js +13 -0
- package/dist/solid/provider.d.ts +32 -0
- package/dist/solid/provider.d.ts.map +1 -0
- package/dist/solid/provider.js +63 -0
- package/dist/solid/provider.js.map +1 -0
- package/dist/solid/provider.ssr.js +64 -0
- package/dist/solid/provider.ssr.js.map +1 -0
- package/dist/solid/session.d.ts +22 -0
- package/dist/solid/session.d.ts.map +1 -0
- package/dist/solid/session.js +76 -0
- package/dist/solid/session.js.map +1 -0
- package/dist/solid/session.ssr.js +85 -0
- package/dist/solid/session.ssr.js.map +1 -0
- package/dist/solid/solid-jazz-client-store.d.ts +11 -0
- package/dist/solid/solid-jazz-client-store.d.ts.map +1 -0
- package/dist/solid/solid-jazz-client-store.js +37 -0
- package/dist/solid/solid-jazz-client-store.js.map +1 -0
- package/dist/solid/solid-jazz-client-store.ssr.js +39 -0
- package/dist/solid/solid-jazz-client-store.ssr.js.map +1 -0
- package/dist/solid/use-all.d.ts +18 -0
- package/dist/solid/use-all.d.ts.map +1 -0
- package/dist/solid/use-all.js +73 -0
- package/dist/solid/use-all.js.map +1 -0
- package/dist/solid/use-all.ssr.js +84 -0
- package/dist/solid/use-all.ssr.js.map +1 -0
- package/dist/solid/use-local-first-auth.d.ts +11 -0
- package/dist/solid/use-local-first-auth.d.ts.map +1 -0
- package/dist/solid/use-local-first-auth.js +30 -0
- package/dist/solid/use-local-first-auth.js.map +1 -0
- package/dist/solid/use-local-first-auth.ssr.js +31 -0
- package/dist/solid/use-local-first-auth.ssr.js.map +1 -0
- package/dist/solid/use-one.d.ts +18 -0
- package/dist/solid/use-one.d.ts.map +1 -0
- package/dist/solid/use-one.js +28 -0
- package/dist/solid/use-one.js.map +1 -0
- package/dist/solid/use-one.ssr.js +28 -0
- package/dist/solid/use-one.ssr.js.map +1 -0
- package/dist/solid/use-sync-status.d.ts +8 -0
- package/dist/solid/use-sync-status.d.ts.map +1 -0
- package/dist/solid/use-sync-status.js +14 -0
- package/dist/solid/use-sync-status.js.map +1 -0
- package/dist/solid/use-sync-status.ssr.js +21 -0
- package/dist/solid/use-sync-status.ssr.js.map +1 -0
- package/dist/subscription-store-internal.d.ts +11 -0
- package/dist/subscription-store-internal.d.ts.map +1 -0
- package/dist/subscription-store-internal.js +18 -0
- package/dist/subscription-store-internal.js.map +1 -0
- package/dist/subscriptions-orchestrator.d.ts +53 -13
- package/dist/subscriptions-orchestrator.d.ts.map +1 -1
- package/dist/subscriptions-orchestrator.js +295 -74
- package/dist/subscriptions-orchestrator.js.map +1 -1
- package/dist/svelte/JazzProvider.svelte +62 -0
- package/dist/svelte/JazzProvider.svelte.d.ts +13 -0
- package/dist/svelte/JazzProvider.svelte.d.ts.map +1 -0
- package/dist/svelte/JazzSessionClientProvider.svelte +42 -0
- package/dist/svelte/JazzSessionClientProvider.svelte.d.ts +13 -0
- package/dist/svelte/JazzSessionClientProvider.svelte.d.ts.map +1 -0
- package/dist/svelte/JazzSessionProvider.svelte +68 -0
- package/dist/svelte/JazzSessionProvider.svelte.d.ts +19 -0
- package/dist/svelte/JazzSessionProvider.svelte.d.ts.map +1 -0
- package/dist/svelte/JazzSvelteClientProvider.svelte +79 -0
- package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts +14 -0
- package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts.map +1 -0
- package/dist/svelte/JazzSvelteProvider.svelte +158 -27
- package/dist/svelte/JazzSvelteProvider.svelte.d.ts +3 -2
- package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +1 -1
- package/dist/svelte/account-state.d.ts +5 -0
- package/dist/svelte/account-state.d.ts.map +1 -0
- package/dist/svelte/account-state.js +9 -0
- package/dist/svelte/auth-state.d.ts +23 -0
- package/dist/svelte/auth-state.d.ts.map +1 -0
- package/dist/svelte/auth-state.js +16 -0
- package/dist/svelte/context.svelte.d.ts +23 -3
- package/dist/svelte/context.svelte.d.ts.map +1 -1
- package/dist/svelte/context.svelte.js +23 -3
- package/dist/svelte/create-jazz-client.d.ts +2 -8
- package/dist/svelte/create-jazz-client.d.ts.map +1 -1
- package/dist/svelte/create-jazz-client.js +1 -17
- package/dist/svelte/index.d.ts +21 -5
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +14 -5
- package/dist/svelte/local-first-auth.svelte.d.ts +50 -0
- package/dist/svelte/local-first-auth.svelte.d.ts.map +1 -0
- package/dist/svelte/local-first-auth.svelte.js +58 -0
- package/dist/svelte/query-subscription.svelte.d.ts +60 -0
- package/dist/svelte/query-subscription.svelte.d.ts.map +1 -0
- package/dist/svelte/query-subscription.svelte.js +135 -0
- package/dist/svelte/session-state.d.ts +11 -0
- package/dist/svelte/session-state.d.ts.map +1 -0
- package/dist/svelte/session-state.js +23 -0
- package/dist/svelte/sync-status.d.ts +11 -0
- package/dist/svelte/sync-status.d.ts.map +1 -0
- package/dist/svelte/sync-status.js +15 -0
- package/dist/testing/client-migrations.d.ts +29 -0
- package/dist/testing/client-migrations.d.ts.map +1 -0
- package/dist/testing/client-migrations.js +34 -0
- package/dist/testing/client-migrations.js.map +1 -0
- package/dist/testing/fixtures/basic/schema.d.ts +11 -0
- package/dist/testing/fixtures/basic/schema.d.ts.map +1 -0
- package/dist/testing/fixtures/basic/schema.js +10 -0
- package/dist/testing/fixtures/basic/schema.js.map +1 -0
- package/dist/testing/fixtures/with-bigint/schema.d.ts +18 -0
- package/dist/testing/fixtures/with-bigint/schema.d.ts.map +1 -0
- package/dist/testing/fixtures/with-bigint/schema.js +15 -0
- package/dist/testing/fixtures/with-bigint/schema.js.map +1 -0
- package/dist/testing/fixtures/with-defaults/schema.d.ts +385 -0
- package/dist/testing/fixtures/with-defaults/schema.d.ts.map +1 -0
- package/dist/testing/fixtures/with-defaults/schema.js +15 -0
- package/dist/testing/fixtures/with-defaults/schema.js.map +1 -0
- package/dist/testing/fixtures/with-enum-payload-defaults/schema.d.ts +4 -0
- package/dist/testing/fixtures/with-enum-payload-defaults/schema.d.ts.map +1 -0
- package/dist/testing/fixtures/with-enum-payload-defaults/schema.js +22 -0
- package/dist/testing/fixtures/with-enum-payload-defaults/schema.js.map +1 -0
- package/dist/testing/fixtures/with-enum-payload-required-null/schema.d.ts +4 -0
- package/dist/testing/fixtures/with-enum-payload-required-null/schema.d.ts.map +1 -0
- package/dist/testing/fixtures/with-enum-payload-required-null/schema.js +14 -0
- package/dist/testing/fixtures/with-enum-payload-required-null/schema.js.map +1 -0
- package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.d.ts +4 -0
- package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.d.ts.map +1 -0
- package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.js +14 -0
- package/dist/testing/fixtures/with-enum-payload-wrong-tag/schema.js.map +1 -0
- package/dist/testing/index.d.ts +6 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +5 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/policy-test-app.d.ts +123 -0
- package/dist/testing/policy-test-app.d.ts.map +1 -0
- package/dist/testing/policy-test-app.js +215 -0
- package/dist/testing/policy-test-app.js.map +1 -0
- package/dist/testing/test-jazz.d.ts +106 -0
- package/dist/testing/test-jazz.d.ts.map +1 -0
- package/dist/testing/test-jazz.js +154 -0
- package/dist/testing/test-jazz.js.map +1 -0
- package/dist/testing/test-jwt-issuer.d.ts +19 -0
- package/dist/testing/test-jwt-issuer.d.ts.map +1 -0
- package/dist/testing/test-jwt-issuer.js +40 -0
- package/dist/testing/test-jwt-issuer.js.map +1 -0
- package/dist/text-field/index.d.ts +40 -0
- package/dist/text-field/index.d.ts.map +1 -0
- package/dist/text-field/index.js +129 -0
- package/dist/text-field/index.js.map +1 -0
- package/dist/thin/index.d.ts +84 -0
- package/dist/thin/index.d.ts.map +1 -0
- package/dist/thin/index.js +204 -0
- package/dist/thin/index.js.map +1 -0
- package/dist/thin/self-signed-token.d.ts +13 -0
- package/dist/thin/self-signed-token.d.ts.map +1 -0
- package/dist/thin/self-signed-token.js +84 -0
- package/dist/thin/self-signed-token.js.map +1 -0
- package/dist/thin/thin-runtime-source.d.ts +19 -0
- package/dist/thin/thin-runtime-source.d.ts.map +1 -0
- package/dist/thin/thin-runtime-source.js +66 -0
- package/dist/thin/thin-runtime-source.js.map +1 -0
- package/dist/thin/thin-runtime.d.ts +224 -0
- package/dist/thin/thin-runtime.d.ts.map +1 -0
- package/dist/thin/thin-runtime.js +1190 -0
- package/dist/thin/thin-runtime.js.map +1 -0
- package/dist/thin/wire.d.ts +160 -0
- package/dist/thin/wire.d.ts.map +1 -0
- package/dist/thin/wire.js +304 -0
- package/dist/thin/wire.js.map +1 -0
- package/dist/typed-app.d.ts +729 -0
- package/dist/typed-app.d.ts.map +1 -0
- package/dist/typed-app.js +789 -0
- package/dist/typed-app.js.map +1 -0
- package/dist/vue/app.d.ts +76 -0
- package/dist/vue/app.d.ts.map +1 -0
- package/dist/vue/app.js +100 -0
- package/dist/vue/app.js.map +1 -0
- package/dist/vue/create-jazz-client.d.ts +3 -0
- package/dist/vue/create-jazz-client.d.ts.map +1 -0
- package/dist/vue/create-jazz-client.js +2 -0
- package/dist/vue/create-jazz-client.js.map +1 -0
- package/dist/vue/index.d.ts +19 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/index.js +13 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/provider.d.ts +87 -0
- package/dist/vue/provider.d.ts.map +1 -0
- package/dist/vue/provider.js +225 -0
- package/dist/vue/provider.js.map +1 -0
- package/dist/vue/session.d.ts +39 -0
- package/dist/vue/session.d.ts.map +1 -0
- package/dist/vue/session.js +42 -0
- package/dist/vue/session.js.map +1 -0
- package/dist/vue/use-account-state.d.ts +5 -0
- package/dist/vue/use-account-state.d.ts.map +1 -0
- package/dist/vue/use-account-state.js +10 -0
- package/dist/vue/use-account-state.js.map +1 -0
- package/dist/vue/use-all.d.ts +61 -0
- package/dist/vue/use-all.d.ts.map +1 -0
- package/dist/vue/use-all.js +104 -0
- package/dist/vue/use-all.js.map +1 -0
- package/dist/vue/use-local-first-auth.d.ts +53 -0
- package/dist/vue/use-local-first-auth.d.ts.map +1 -0
- package/dist/vue/use-local-first-auth.js +67 -0
- package/dist/vue/use-local-first-auth.js.map +1 -0
- package/dist/vue/use-one.d.ts +24 -0
- package/dist/vue/use-one.d.ts.map +1 -0
- package/dist/vue/use-one.js +17 -0
- package/dist/vue/use-one.js.map +1 -0
- package/dist/vue/use-sync-status.d.ts +9 -0
- package/dist/vue/use-sync-status.d.ts.map +1 -0
- package/dist/vue/use-sync-status.js +16 -0
- package/dist/vue/use-sync-status.js.map +1 -0
- package/dist/web/create-jazz-client.d.ts +8 -0
- package/dist/web/create-jazz-client.d.ts.map +1 -0
- package/dist/web/create-jazz-client.js +8 -0
- package/dist/web/create-jazz-client.js.map +1 -0
- package/dist/web/lazy-local-first.d.ts +8 -0
- package/dist/web/lazy-local-first.d.ts.map +1 -0
- package/dist/web/lazy-local-first.js +13 -0
- package/dist/web/lazy-local-first.js.map +1 -0
- package/dist/web/registered-jazz-client.d.ts +15 -0
- package/dist/web/registered-jazz-client.d.ts.map +1 -0
- package/dist/web/registered-jazz-client.js +35 -0
- package/dist/web/registered-jazz-client.js.map +1 -0
- package/dist/where-operators.d.ts +13 -0
- package/dist/where-operators.d.ts.map +1 -0
- package/dist/where-operators.js +70 -0
- package/dist/where-operators.js.map +1 -0
- package/dist/window-client-storage.d.ts +33 -0
- package/dist/window-client-storage.d.ts.map +1 -0
- package/dist/window-client-storage.js +88 -0
- package/dist/window-client-storage.js.map +1 -0
- package/dist/worker/jazz-broker-worker-core.d.ts +34 -0
- package/dist/worker/jazz-broker-worker-core.d.ts.map +1 -0
- package/dist/worker/jazz-broker-worker-core.js +2033 -0
- package/dist/worker/jazz-broker-worker-core.js.map +1 -0
- package/dist/worker/jazz-broker-worker.d.ts +2 -0
- package/dist/worker/jazz-broker-worker.d.ts.map +1 -0
- package/dist/worker/jazz-broker-worker.js +23997 -0
- package/dist/worker/jazz_wasm_bg.wasm +0 -0
- package/dist/worker/mutation-error-delivery.d.ts +8 -0
- package/dist/worker/mutation-error-delivery.d.ts.map +1 -0
- package/dist/worker/mutation-error-delivery.js +10 -0
- package/dist/worker/mutation-error-delivery.js.map +1 -0
- package/package.json +248 -30
- package/bin/native/.gitkeep +0 -0
- package/bin/native/jazz-tools-darwin-arm64 +0 -0
- package/bin/native/jazz-tools-darwin-x64 +0 -0
- package/bin/native/jazz-tools-linux-arm64 +0 -0
- package/bin/native/jazz-tools-linux-x64 +0 -0
- package/bin/native/jazz-tools-windows-x64.exe +0 -0
- package/dist/cli.test.d.ts +0 -2
- package/dist/cli.test.d.ts.map +0 -1
- package/dist/cli.test.js +0 -154
- package/dist/cli.test.js.map +0 -1
- package/dist/codegen/codegen.test.d.ts +0 -2
- package/dist/codegen/codegen.test.d.ts.map +0 -1
- package/dist/codegen/codegen.test.js +0 -844
- package/dist/codegen/codegen.test.js.map +0 -1
- package/dist/codegen/index.d.ts +0 -18
- package/dist/codegen/index.d.ts.map +0 -1
- package/dist/codegen/index.js +0 -22
- package/dist/codegen/index.js.map +0 -1
- package/dist/codegen/query-builder-generator.d.ts +0 -23
- package/dist/codegen/query-builder-generator.d.ts.map +0 -1
- package/dist/codegen/query-builder-generator.js +0 -325
- package/dist/codegen/query-builder-generator.js.map +0 -1
- package/dist/codegen/type-generator.d.ts +0 -29
- package/dist/codegen/type-generator.d.ts.map +0 -1
- package/dist/codegen/type-generator.js +0 -226
- package/dist/codegen/type-generator.js.map +0 -1
- package/dist/dsl.test.d.ts +0 -2
- package/dist/dsl.test.d.ts.map +0 -1
- package/dist/dsl.test.js +0 -51
- package/dist/dsl.test.js.map +0 -1
- package/dist/permissions/index.test.d.ts +0 -2
- package/dist/permissions/index.test.d.ts.map +0 -1
- package/dist/permissions/index.test.js +0 -830
- package/dist/permissions/index.test.js.map +0 -1
- package/dist/permissions/type-inference.test.d.ts +0 -2
- package/dist/permissions/type-inference.test.d.ts.map +0 -1
- package/dist/permissions/type-inference.test.js +0 -151
- package/dist/permissions/type-inference.test.js.map +0 -1
- package/dist/react/create-jazz-client.integration.test.d.ts +0 -2
- package/dist/react/create-jazz-client.integration.test.d.ts.map +0 -1
- package/dist/react/create-jazz-client.integration.test.js +0 -84
- package/dist/react/create-jazz-client.integration.test.js.map +0 -1
- package/dist/react/create-jazz-client.test.d.ts +0 -2
- package/dist/react/create-jazz-client.test.d.ts.map +0 -1
- package/dist/react/create-jazz-client.test.js +0 -133
- package/dist/react/create-jazz-client.test.js.map +0 -1
- package/dist/react/synthetic-user-switcher.d.ts +0 -9
- package/dist/react/synthetic-user-switcher.d.ts.map +0 -1
- package/dist/react/synthetic-user-switcher.js +0 -65
- package/dist/react/synthetic-user-switcher.js.map +0 -1
- package/dist/react/synthetic-users.d.ts +0 -2
- package/dist/react/synthetic-users.d.ts.map +0 -1
- package/dist/react/synthetic-users.js +0 -2
- package/dist/react/synthetic-users.js.map +0 -1
- package/dist/react/synthetic-users.test.d.ts +0 -2
- package/dist/react/synthetic-users.test.d.ts.map +0 -1
- package/dist/react/synthetic-users.test.js +0 -43
- package/dist/react/synthetic-users.test.js.map +0 -1
- package/dist/react/use-link-external-identity.d.ts +0 -25
- package/dist/react/use-link-external-identity.d.ts.map +0 -1
- package/dist/react/use-link-external-identity.js +0 -45
- package/dist/react/use-link-external-identity.js.map +0 -1
- package/dist/react-native/create-jazz-client.test.d.ts +0 -2
- package/dist/react-native/create-jazz-client.test.d.ts.map +0 -1
- package/dist/react-native/create-jazz-client.test.js +0 -162
- package/dist/react-native/create-jazz-client.test.js.map +0 -1
- package/dist/react-native/create-jazz-rn-runtime.d.ts +0 -13
- package/dist/react-native/create-jazz-rn-runtime.d.ts.map +0 -1
- package/dist/react-native/create-jazz-rn-runtime.js +0 -7
- package/dist/react-native/create-jazz-rn-runtime.js.map +0 -1
- package/dist/react-native/db.d.ts +0 -16
- package/dist/react-native/db.d.ts.map +0 -1
- package/dist/react-native/db.js +0 -50
- package/dist/react-native/db.js.map +0 -1
- package/dist/react-native/db.test.d.ts +0 -2
- package/dist/react-native/db.test.d.ts.map +0 -1
- package/dist/react-native/db.test.js +0 -150
- package/dist/react-native/db.test.js.map +0 -1
- package/dist/react-native/jazz-rn-runtime-adapter.d.ts +0 -56
- package/dist/react-native/jazz-rn-runtime-adapter.d.ts.map +0 -1
- package/dist/react-native/jazz-rn-runtime-adapter.js +0 -192
- package/dist/react-native/jazz-rn-runtime-adapter.js.map +0 -1
- package/dist/react-native/jazz-rn-runtime-adapter.test.d.ts +0 -2
- package/dist/react-native/jazz-rn-runtime-adapter.test.d.ts.map +0 -1
- package/dist/react-native/jazz-rn-runtime-adapter.test.js +0 -165
- package/dist/react-native/jazz-rn-runtime-adapter.test.js.map +0 -1
- package/dist/runtime/client-session.test.d.ts +0 -2
- package/dist/runtime/client-session.test.d.ts.map +0 -1
- package/dist/runtime/client-session.test.js +0 -84
- package/dist/runtime/client-session.test.js.map +0 -1
- package/dist/runtime/client.for-request.test.d.ts +0 -2
- package/dist/runtime/client.for-request.test.d.ts.map +0 -1
- package/dist/runtime/client.for-request.test.js +0 -171
- package/dist/runtime/client.for-request.test.js.map +0 -1
- package/dist/runtime/cloud-server.integration.test.d.ts +0 -2
- package/dist/runtime/cloud-server.integration.test.d.ts.map +0 -1
- package/dist/runtime/cloud-server.integration.test.js +0 -985
- package/dist/runtime/cloud-server.integration.test.js.map +0 -1
- package/dist/runtime/leader-lock.d.ts +0 -15
- package/dist/runtime/leader-lock.d.ts.map +0 -1
- package/dist/runtime/leader-lock.js +0 -49
- package/dist/runtime/leader-lock.js.map +0 -1
- package/dist/runtime/local-auth.d.ts +0 -32
- package/dist/runtime/local-auth.d.ts.map +0 -1
- package/dist/runtime/local-auth.js +0 -93
- package/dist/runtime/local-auth.js.map +0 -1
- package/dist/runtime/local-auth.test.d.ts +0 -2
- package/dist/runtime/local-auth.test.d.ts.map +0 -1
- package/dist/runtime/local-auth.test.js +0 -50
- package/dist/runtime/local-auth.test.js.map +0 -1
- package/dist/runtime/query-adapter.test.d.ts +0 -5
- package/dist/runtime/query-adapter.test.d.ts.map +0 -1
- package/dist/runtime/query-adapter.test.js +0 -1209
- package/dist/runtime/query-adapter.test.js.map +0 -1
- package/dist/runtime/row-transformer.test.d.ts +0 -5
- package/dist/runtime/row-transformer.test.d.ts.map +0 -1
- package/dist/runtime/row-transformer.test.js +0 -364
- package/dist/runtime/row-transformer.test.js.map +0 -1
- package/dist/runtime/subscription-manager.test.d.ts +0 -5
- package/dist/runtime/subscription-manager.test.d.ts.map +0 -1
- package/dist/runtime/subscription-manager.test.js +0 -120
- package/dist/runtime/subscription-manager.test.js.map +0 -1
- package/dist/runtime/sync-transport.d.ts +0 -163
- package/dist/runtime/sync-transport.d.ts.map +0 -1
- package/dist/runtime/sync-transport.js +0 -477
- package/dist/runtime/sync-transport.js.map +0 -1
- package/dist/runtime/sync-transport.test.d.ts +0 -2
- package/dist/runtime/sync-transport.test.d.ts.map +0 -1
- package/dist/runtime/sync-transport.test.js +0 -310
- package/dist/runtime/sync-transport.test.js.map +0 -1
- package/dist/runtime/tab-leader-election.d.ts +0 -97
- package/dist/runtime/tab-leader-election.d.ts.map +0 -1
- package/dist/runtime/tab-leader-election.js +0 -339
- package/dist/runtime/tab-leader-election.js.map +0 -1
- package/dist/runtime/tab-leader-election.test.d.ts +0 -2
- package/dist/runtime/tab-leader-election.test.d.ts.map +0 -1
- package/dist/runtime/tab-leader-election.test.js +0 -278
- package/dist/runtime/tab-leader-election.test.js.map +0 -1
- package/dist/runtime/testing/wasm-runtime-test-utils.d.ts +0 -13
- package/dist/runtime/testing/wasm-runtime-test-utils.d.ts.map +0 -1
- package/dist/runtime/testing/wasm-runtime-test-utils.js +0 -75
- package/dist/runtime/testing/wasm-runtime-test-utils.js.map +0 -1
- package/dist/runtime/utils.d.ts +0 -2
- package/dist/runtime/utils.d.ts.map +0 -1
- package/dist/runtime/utils.js +0 -16
- package/dist/runtime/utils.js.map +0 -1
- package/dist/runtime/value-converter.test.d.ts +0 -5
- package/dist/runtime/value-converter.test.d.ts.map +0 -1
- package/dist/runtime/value-converter.test.js +0 -212
- package/dist/runtime/value-converter.test.js.map +0 -1
- package/dist/runtime/worker-bridge.d.ts +0 -86
- package/dist/runtime/worker-bridge.d.ts.map +0 -1
- package/dist/runtime/worker-bridge.js +0 -250
- package/dist/runtime/worker-bridge.js.map +0 -1
- package/dist/runtime/worker-bridge.race-harness.test.d.ts +0 -2
- package/dist/runtime/worker-bridge.race-harness.test.d.ts.map +0 -1
- package/dist/runtime/worker-bridge.race-harness.test.js +0 -265
- package/dist/runtime/worker-bridge.race-harness.test.js.map +0 -1
- package/dist/runtime/worker-bridge.test.d.ts +0 -2
- package/dist/runtime/worker-bridge.test.d.ts.map +0 -1
- package/dist/runtime/worker-bridge.test.js +0 -233
- package/dist/runtime/worker-bridge.test.js.map +0 -1
- package/dist/sql-gen.d.ts +0 -4
- package/dist/sql-gen.d.ts.map +0 -1
- package/dist/sql-gen.js +0 -163
- package/dist/sql-gen.js.map +0 -1
- package/dist/sql-gen.test.d.ts +0 -2
- package/dist/sql-gen.test.d.ts.map +0 -1
- package/dist/sql-gen.test.js +0 -412
- package/dist/sql-gen.test.js.map +0 -1
- package/dist/subscriptions-orchestrator.integration.test.d.ts +0 -2
- package/dist/subscriptions-orchestrator.integration.test.d.ts.map +0 -1
- package/dist/subscriptions-orchestrator.integration.test.js +0 -194
- package/dist/subscriptions-orchestrator.integration.test.js.map +0 -1
- package/dist/subscriptions-orchestrator.test.d.ts +0 -2
- package/dist/subscriptions-orchestrator.test.d.ts.map +0 -1
- package/dist/subscriptions-orchestrator.test.js +0 -367
- package/dist/subscriptions-orchestrator.test.js.map +0 -1
- package/dist/svelte/SyntheticUserSwitcher.svelte +0 -121
- package/dist/svelte/SyntheticUserSwitcher.svelte.d.ts +0 -11
- package/dist/svelte/SyntheticUserSwitcher.svelte.d.ts.map +0 -1
- package/dist/svelte/context.test.d.ts +0 -2
- package/dist/svelte/context.test.d.ts.map +0 -1
- package/dist/svelte/context.test.js +0 -51
- package/dist/svelte/create-jazz-client.test.d.ts +0 -2
- package/dist/svelte/create-jazz-client.test.d.ts.map +0 -1
- package/dist/svelte/create-jazz-client.test.js +0 -50
- package/dist/svelte/use-all.svelte.d.ts +0 -32
- package/dist/svelte/use-all.svelte.d.ts.map +0 -1
- package/dist/svelte/use-all.svelte.js +0 -61
- package/dist/svelte/use-all.test.d.ts +0 -2
- package/dist/svelte/use-all.test.d.ts.map +0 -1
- package/dist/svelte/use-all.test.js +0 -154
- package/dist/svelte/use-link-external-identity.d.ts +0 -25
- package/dist/svelte/use-link-external-identity.d.ts.map +0 -1
- package/dist/svelte/use-link-external-identity.js +0 -33
- package/dist/svelte/use-link-external-identity.test.d.ts +0 -2
- package/dist/svelte/use-link-external-identity.test.d.ts.map +0 -1
- package/dist/svelte/use-link-external-identity.test.js +0 -97
- package/dist/synthetic-user-switcher.d.ts +0 -16
- package/dist/synthetic-user-switcher.d.ts.map +0 -1
- package/dist/synthetic-user-switcher.js +0 -134
- package/dist/synthetic-user-switcher.js.map +0 -1
- package/dist/synthetic-users.d.ts +0 -32
- package/dist/synthetic-users.d.ts.map +0 -1
- package/dist/synthetic-users.js +0 -124
- package/dist/synthetic-users.js.map +0 -1
- package/dist/testing/fixtures/basic/app.d.ts +0 -55
- package/dist/testing/fixtures/basic/app.d.ts.map +0 -1
- package/dist/testing/fixtures/basic/app.js +0 -176
- package/dist/testing/fixtures/basic/app.js.map +0 -1
- package/dist/testing/fixtures/basic/current.d.ts +0 -2
- package/dist/testing/fixtures/basic/current.d.ts.map +0 -1
- package/dist/testing/fixtures/basic/current.js +0 -6
- package/dist/testing/fixtures/basic/current.js.map +0 -1
- package/dist/testing/index.test.d.ts +0 -2
- package/dist/testing/index.test.d.ts.map +0 -1
- package/dist/testing/index.test.js +0 -234
- package/dist/testing/index.test.js.map +0 -1
- package/dist/testing/local-jazz-server.d.ts +0 -34
- package/dist/testing/local-jazz-server.d.ts.map +0 -1
- package/dist/testing/local-jazz-server.js +0 -313
- package/dist/testing/local-jazz-server.js.map +0 -1
- package/dist/worker/jazz-worker.d.ts +0 -9
- package/dist/worker/jazz-worker.d.ts.map +0 -1
- package/dist/worker/jazz-worker.js +0 -516
- package/dist/worker/jazz-worker.js.map +0 -1
- package/dist/worker/jazz-worker.ts +0 -581
- package/dist/worker/worker-protocol.d.ts +0 -136
- package/dist/worker/worker-protocol.d.ts.map +0 -1
- package/dist/worker/worker-protocol.js +0 -7
- package/dist/worker/worker-protocol.js.map +0 -1
package/dist/runtime/db.js
CHANGED
|
@@ -1,776 +1,2495 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
import { JazzClient, loadWasmModule } from "./client.js";
|
|
13
|
-
import { WorkerBridge } from "./worker-bridge.js";
|
|
1
|
+
import { clientScope } from "./client-scope.js";
|
|
2
|
+
import { isHistoryTable, resolveQueryTable } from "./history-relation.js";
|
|
3
|
+
import { Utf8Decoder } from "./utf8.js";
|
|
4
|
+
import { parseSnapshotRef } from "./snapshot-ref.js";
|
|
5
|
+
import { runtimeRandomBytes } from "./runtime-entropy.js";
|
|
6
|
+
import { GracefulShutdownSyncError } from "./graceful-shutdown-error.js";
|
|
7
|
+
import { accountToken, accountRegistry } from "../accounts/enrollment.js";
|
|
8
|
+
import { assertAccountConfig, copyAccountConfigAdmission } from "../accounts/config-capability.js";
|
|
9
|
+
import { SerializableWriteHandle, SerializableWriteResult, WriteResult, beginClientTransactionAfter, WriteHandle, createOpenTransactionId, setWriteWaitReadiness, isPublicQueryReadTier, rejectRemovedReadTier, normalizeFirstLoadRemoteWaitMs, resolveEffectiveQueryExecutionOptions, validateWriteWaitTimeout, WriteWaitTimeoutError, } from "./client.js";
|
|
10
|
+
import { sameSyncStatus } from "./sync-status.js";
|
|
14
11
|
import { translateQuery } from "./query-adapter.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
12
|
+
import { resolveQueryOutputTable } from "./query-output-table.js";
|
|
13
|
+
import { applyColumnTransforms, createRowTransformer, transformRow, unwrapValue, } from "./row-transformer.js";
|
|
14
|
+
import { getOwnerPreparation, runAfterPreparation, WritePreparation } from "./write-preparation.js";
|
|
15
|
+
import { nativeCoreErrorCode, unreadableTargetError } from "./native-runtime/native-error-code.js";
|
|
16
|
+
import { writeRow } from "./write-row.js";
|
|
17
|
+
import { ComputedReadState, MissingComputedDependency, columnTransformDependencies, computedColumnValues, dependencyContext, storedDependencyValues, } from "./column-transforms.js";
|
|
18
|
+
import { toValue, toWriteRecord } from "./value-converter.js";
|
|
19
|
+
import { RowChangeKind, SubscriptionManager, } from "./subscription-manager.js";
|
|
20
|
+
import { createAuthStateStore } from "./auth-state.js";
|
|
21
|
+
import { AuthRenewalBackoff } from "./auth-renewal-backoff.js";
|
|
22
|
+
import { parseJwtPayload, internalSessionFromVerifiedReservedJwtPayload, resolveClientInternalSessionSync, } from "./client-session.js";
|
|
23
|
+
import { createBrowserPhysicalDatabaseName, createBrowserStorageOwner, } from "./browser-worker-config.js";
|
|
24
|
+
import { createInspectorLocalQueryOptions, isInspectorLocalQueryOptions, } from "../internal/inspector-query.js";
|
|
25
|
+
import { authSecretSeedForMinting } from "./auth-secret-codec.js";
|
|
26
|
+
import { getDbInternalSession, getTrustedReservedSession, setDbInternalSession, setTrustedReservedSession, } from "./db-internal-session.js";
|
|
27
|
+
import { notifyLocalWrite } from "./local-write-observer.js";
|
|
19
28
|
import { analyzeRelations } from "../codegen/relation-analyzer.js";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
29
|
+
import { normalizeBuiltQuery, } from "./query-builder-shape.js";
|
|
30
|
+
import { BrowserConnectionManager, DirectConnectionManager, } from "./connection-manager/index.js";
|
|
31
|
+
import { toError } from "./util.js";
|
|
32
|
+
import { isThinDb, upgradeDbToLocalFirst } from "./local-first-upgrade.js";
|
|
33
|
+
import { DbReplacedError } from "./db-replaced-error.js";
|
|
34
|
+
import { RuntimeClosedError } from "./runtime-closed-error.js";
|
|
35
|
+
function resolveStorageDriver(driver) {
|
|
36
|
+
return driver ?? { type: "persistent" };
|
|
37
|
+
}
|
|
38
|
+
function trimOptionalString(value) {
|
|
39
|
+
if (typeof value !== "string") {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const trimmed = value.trim();
|
|
43
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
44
|
+
}
|
|
45
|
+
/** @internal Resolve the caller-selected logical base for browser persistence. */
|
|
46
|
+
export function resolvePersistentDbBaseName(config) {
|
|
47
|
+
const driver = resolveStorageDriver(config.driver);
|
|
48
|
+
const explicitDbName = trimOptionalString((driver.type === "persistent" ? driver.dbName : undefined) ?? config.dbName);
|
|
49
|
+
return explicitDbName ?? clientScope(config);
|
|
50
|
+
}
|
|
51
|
+
/** @internal Derive the physical browser persistence namespace for this Db config. */
|
|
52
|
+
export function resolveDefaultPersistentDbName(config) {
|
|
53
|
+
return createBrowserPhysicalDatabaseName(config, resolvePersistentDbBaseName(config));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Lower product options to the internal native-read controls. This is a
|
|
57
|
+
* runtime boundary, rather than merely a TypeScript one: JavaScript callers
|
|
58
|
+
* must not be able to select local-only propagation or a deferred own-write
|
|
59
|
+
* overlay by adding private fields to an options object.
|
|
60
|
+
*/
|
|
61
|
+
function lowerPublicDbQueryOptions(options) {
|
|
62
|
+
if (!options)
|
|
63
|
+
return undefined;
|
|
64
|
+
const candidate = options;
|
|
65
|
+
rejectRemovedReadTier(candidate.tier);
|
|
66
|
+
const lowered = {};
|
|
67
|
+
if (isPublicQueryReadTier(candidate.tier))
|
|
68
|
+
lowered.tier = candidate.tier;
|
|
69
|
+
const firstLoadRemoteWaitMs = normalizeFirstLoadRemoteWaitMs(candidate.firstLoadRemoteWaitMs);
|
|
70
|
+
if (firstLoadRemoteWaitMs !== undefined)
|
|
71
|
+
lowered.firstLoadRemoteWaitMs = firstLoadRemoteWaitMs;
|
|
72
|
+
if (candidate.branch !== undefined)
|
|
73
|
+
lowered.branch = candidate.branch;
|
|
74
|
+
if (candidate.base !== undefined)
|
|
75
|
+
lowered.base = candidate.base;
|
|
76
|
+
const splices = candidate.splices;
|
|
77
|
+
if (splices !== undefined) {
|
|
78
|
+
if (!Array.isArray(splices) || !splices.every((column) => typeof column === "string")) {
|
|
79
|
+
throw new Error("splices must be an array of column names.");
|
|
56
80
|
}
|
|
57
|
-
|
|
81
|
+
if (splices.length > 0)
|
|
82
|
+
lowered.splices = [...splices];
|
|
83
|
+
}
|
|
84
|
+
if (isInspectorLocalQueryOptions(options))
|
|
85
|
+
lowered.tier = "local-only";
|
|
86
|
+
return lowered;
|
|
87
|
+
}
|
|
88
|
+
const dbSubscriptionSources = new WeakMap();
|
|
89
|
+
/**
|
|
90
|
+
* What a Db hands to its successor after the local-first upgrade: everything
|
|
91
|
+
* an app or framework calls. Its shutdown, and the internals its own runtime
|
|
92
|
+
* needs to finish uploading, stay with it.
|
|
93
|
+
*/
|
|
94
|
+
const FORWARDED_TO_SUCCESSOR = [
|
|
95
|
+
"allFromInspectorAttachment",
|
|
96
|
+
"subscribeFromInspectorAttachment",
|
|
97
|
+
"currentRuntime",
|
|
98
|
+
"prefetchRuntimeQueries",
|
|
99
|
+
"refreshAccountAuth",
|
|
100
|
+
"updateAuthToken",
|
|
101
|
+
"updateCookieSession",
|
|
102
|
+
"getAuthState",
|
|
103
|
+
"getLocalFirstIdentityProof",
|
|
104
|
+
"onAuthChanged",
|
|
105
|
+
"onMutationError",
|
|
106
|
+
"textAnchors",
|
|
107
|
+
"getSyncStatus",
|
|
108
|
+
"waitForSync",
|
|
109
|
+
"getConfig",
|
|
110
|
+
"setDevMode",
|
|
111
|
+
"disconnect",
|
|
112
|
+
"reconnect",
|
|
113
|
+
"getActiveQuerySubscriptions",
|
|
114
|
+
"onActiveQuerySubscriptionsChange",
|
|
115
|
+
"getRuntimeSchema",
|
|
116
|
+
"openInspectorControlPort",
|
|
117
|
+
"insert",
|
|
118
|
+
"insertStreaming",
|
|
119
|
+
"updateStreaming",
|
|
120
|
+
"upsertStreaming",
|
|
121
|
+
"restore",
|
|
122
|
+
"upsert",
|
|
123
|
+
"update",
|
|
124
|
+
"delete",
|
|
125
|
+
"canInsert",
|
|
126
|
+
"canRead",
|
|
127
|
+
"canUpdate",
|
|
128
|
+
"canDelete",
|
|
129
|
+
"createTransaction",
|
|
130
|
+
"captureSnapshot",
|
|
131
|
+
"beginTransaction",
|
|
132
|
+
"beginSerializableTransaction",
|
|
133
|
+
"transaction",
|
|
134
|
+
"serializableTransaction",
|
|
135
|
+
"upgradeToLocalFirst",
|
|
136
|
+
"deleteClientStorage",
|
|
137
|
+
"logout",
|
|
138
|
+
"all",
|
|
139
|
+
"allInternal",
|
|
140
|
+
"one",
|
|
141
|
+
"subscribe",
|
|
142
|
+
"subscribeDelta",
|
|
143
|
+
];
|
|
144
|
+
/** @internal Retrieve the incremental source associated with a public Db. */
|
|
145
|
+
export function getDbSubscriptionSource(db) {
|
|
146
|
+
const source = dbSubscriptionSources.get(db);
|
|
147
|
+
if (!source)
|
|
148
|
+
throw new Error("Jazz Db is missing its internal subscription source.");
|
|
149
|
+
return source;
|
|
150
|
+
}
|
|
151
|
+
function branchColumn(schema, name) {
|
|
152
|
+
const matches = Object.values(schema)
|
|
153
|
+
.flatMap((table) => table.columns)
|
|
154
|
+
.filter((column) => column.name === name);
|
|
155
|
+
const column = matches[0];
|
|
156
|
+
if (!column)
|
|
157
|
+
throw new Error(`Unknown branch column "${name}".`);
|
|
158
|
+
return column;
|
|
159
|
+
}
|
|
160
|
+
function normalizeBranchSelector(schema, tableName, input, scope) {
|
|
161
|
+
const table = resolveQueryTable(schema, tableName);
|
|
162
|
+
if (!table)
|
|
163
|
+
throw new Error(`Unknown table "${tableName}".`);
|
|
164
|
+
const tableColumns = table.branchBy ?? [];
|
|
165
|
+
const expected = scope === "table"
|
|
166
|
+
? new Set(tableColumns)
|
|
167
|
+
: new Set(Object.values(schema).flatMap((candidate) => candidate.branchBy ?? []));
|
|
168
|
+
const qualified = typeof input === "object" && input !== null && !Array.isArray(input)
|
|
169
|
+
? input
|
|
170
|
+
: expected.size === 1
|
|
171
|
+
? { [[...expected][0]]: input }
|
|
172
|
+
: (() => {
|
|
173
|
+
throw new Error(`A scalar branch selector requires exactly one ${scope === "table" ? "table" : "schema"} branch column.`);
|
|
174
|
+
})();
|
|
175
|
+
const actual = Object.keys(qualified);
|
|
176
|
+
if (actual.length !== expected.size || actual.some((name) => !expected.has(name))) {
|
|
177
|
+
throw new Error(`Branch selector must provide exactly: ${[...expected].sort().join(", ") || "no columns"}.`);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
values: Object.fromEntries(actual.map((name) => [
|
|
181
|
+
name,
|
|
182
|
+
toValue(qualified[name], branchColumn(schema, name).column_type),
|
|
183
|
+
])),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function normalizeBranchView(schema, tableName, branch, base) {
|
|
187
|
+
const head = normalizeBranchSelector(schema, tableName, branch, "schema");
|
|
188
|
+
if (base === undefined)
|
|
189
|
+
return { head };
|
|
190
|
+
if (Array.isArray(base)) {
|
|
191
|
+
return {
|
|
192
|
+
head,
|
|
193
|
+
base: {
|
|
194
|
+
kind: "snapshot",
|
|
195
|
+
branch: normalizeBranchSelector(schema, tableName, base[0], "schema"),
|
|
196
|
+
snapshot: parseSnapshotRef(base[1]),
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
58
200
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
offset: typeof raw.offset === "number" ? raw.offset : undefined,
|
|
65
|
-
hops,
|
|
66
|
-
gather,
|
|
201
|
+
head,
|
|
202
|
+
base: {
|
|
203
|
+
kind: "current",
|
|
204
|
+
branch: normalizeBranchSelector(schema, tableName, base, "schema"),
|
|
205
|
+
},
|
|
67
206
|
};
|
|
68
207
|
}
|
|
69
|
-
function
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
208
|
+
function normalizeSelectorOptions(schema, tableName, options) {
|
|
209
|
+
if (!options)
|
|
210
|
+
return undefined;
|
|
211
|
+
const { branch, ...rest } = options;
|
|
212
|
+
return branch === undefined
|
|
213
|
+
? rest
|
|
214
|
+
: {
|
|
215
|
+
...rest,
|
|
216
|
+
branch: normalizeBranchSelector(schema, tableName, branch, "table"),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function normalizeViewOptions(schema, tableName, options) {
|
|
220
|
+
if (!options)
|
|
221
|
+
return undefined;
|
|
222
|
+
const { branch, base, ...rest } = options;
|
|
223
|
+
if (branch === undefined) {
|
|
224
|
+
if (base !== undefined)
|
|
225
|
+
throw new Error("A branch base requires a branch head.");
|
|
226
|
+
return rest;
|
|
72
227
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
228
|
+
return {
|
|
229
|
+
...rest,
|
|
230
|
+
branch: normalizeBranchView(schema, tableName, branch, base),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
export function limitQueryToOne(query) {
|
|
234
|
+
return {
|
|
235
|
+
get _table() {
|
|
236
|
+
return query._table;
|
|
237
|
+
},
|
|
238
|
+
get _schema() {
|
|
239
|
+
return query._schema;
|
|
240
|
+
},
|
|
241
|
+
get _columnTransforms() {
|
|
242
|
+
return query._columnTransforms;
|
|
243
|
+
},
|
|
244
|
+
get _columnTransformsByTable() {
|
|
245
|
+
return query._columnTransformsByTable;
|
|
246
|
+
},
|
|
247
|
+
get _rowType() {
|
|
248
|
+
return query._rowType;
|
|
249
|
+
},
|
|
250
|
+
_build() {
|
|
251
|
+
const builtQuery = JSON.parse(query._build());
|
|
252
|
+
builtQuery.limit = 1;
|
|
253
|
+
return JSON.stringify(builtQuery);
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function queryUsesRelationTraversal(builtQuery) {
|
|
258
|
+
return (builtQuery.hops.length > 0 ||
|
|
259
|
+
builtQuery.gather !== undefined ||
|
|
260
|
+
Object.keys(builtQuery.includes).length > 0);
|
|
261
|
+
}
|
|
262
|
+
function trimSubscriptionTraceStack(stack) {
|
|
263
|
+
if (!stack) {
|
|
264
|
+
return stack;
|
|
265
|
+
}
|
|
266
|
+
const lines = stack.split("\n");
|
|
267
|
+
if (lines.length <= 1) {
|
|
268
|
+
return stack;
|
|
269
|
+
}
|
|
270
|
+
const isInternalFrame = (line) => {
|
|
271
|
+
return (line.includes("Db.registerActiveQuerySubscriptionTrace") ||
|
|
272
|
+
line.includes("Db.subscribe") ||
|
|
273
|
+
line.includes("SubscriptionsOrchestrator.ensureEntryForKey") ||
|
|
274
|
+
line.includes("SubscriptionsOrchestrator.getCacheEntry") ||
|
|
275
|
+
line.includes("/node_modules/") ||
|
|
276
|
+
line.includes("react-dom") ||
|
|
277
|
+
line.includes("react_stack_bottom_frame"));
|
|
278
|
+
};
|
|
279
|
+
const firstOriginIndex = lines.findIndex((line, index) => index > 0 && !isInternalFrame(line));
|
|
280
|
+
if (firstOriginIndex <= 0) {
|
|
281
|
+
return stack;
|
|
282
|
+
}
|
|
283
|
+
return [lines[0], ...lines.slice(firstOriginIndex)].join("\n");
|
|
284
|
+
}
|
|
285
|
+
function cloneActiveQuerySubscriptionTrace(trace) {
|
|
286
|
+
return {
|
|
287
|
+
...trace,
|
|
288
|
+
branches: [...trace.branches],
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function requireSchemaWithTable(preferredSchema, tableName) {
|
|
292
|
+
if (resolveQueryTable(preferredSchema, tableName)) {
|
|
293
|
+
return preferredSchema;
|
|
294
|
+
}
|
|
295
|
+
throw new Error(`Query schema is missing table "${tableName}".`);
|
|
296
|
+
}
|
|
297
|
+
function normalizeQueryOptions(schema, table, options) {
|
|
298
|
+
return normalizeViewOptions(schema, table, options) ?? {};
|
|
299
|
+
}
|
|
300
|
+
/** Splices are only defined for plain TEXT and BYTEA columns of the result table. */
|
|
301
|
+
function assertSpliceableColumns(schema, table, query, columns) {
|
|
302
|
+
const descriptors = resolveQueryTable(schema, table)?.columns ?? [];
|
|
303
|
+
for (const column of columns) {
|
|
304
|
+
const descriptor = descriptors.find((candidate) => candidate.name === column);
|
|
305
|
+
if (!descriptor)
|
|
306
|
+
throw new Error(`splices: "${column}" is not a column of "${table}".`);
|
|
307
|
+
const type = descriptor.column_type.type;
|
|
308
|
+
if (type !== "Text" && type !== "Bytea") {
|
|
309
|
+
throw new Error(`splices: column "${column}" is ${type}; splices are not supported yet for columns other than TEXT and BYTEA.`);
|
|
310
|
+
}
|
|
311
|
+
if (query._columnTransforms?.[column]) {
|
|
312
|
+
throw new Error(`splices: column "${column}" has a column transform; splices are not supported yet for transformed columns.`);
|
|
80
313
|
}
|
|
81
|
-
currentTable = relation.toTable;
|
|
82
314
|
}
|
|
83
|
-
return currentTable;
|
|
84
315
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
316
|
+
/**
|
|
317
|
+
* A range-selected splice column must be read in part: a computed or
|
|
318
|
+
* transformed column that depends on it makes the engine read it whole and
|
|
319
|
+
* TypeScript cut the window, so the engine's splices would be in whole-value
|
|
320
|
+
* coordinates while the rows show the window.
|
|
321
|
+
*/
|
|
322
|
+
function assertSplicesReadInPart(built, physical, columns) {
|
|
323
|
+
for (const column of columns) {
|
|
324
|
+
if (Object.hasOwn(built.partialSelect, column) &&
|
|
325
|
+
!Object.hasOwn(physical.partialSelect, column))
|
|
326
|
+
throw new Error(`splices: column "${column}" is selected in part, but a computed or transformed column depends on it, so it is read whole; splices are not supported yet for such columns.`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function assertWritableTable(table) {
|
|
330
|
+
if (isHistoryTable(table._table)) {
|
|
331
|
+
throw new Error(`History table "${table._table}" is read-only`);
|
|
332
|
+
}
|
|
90
333
|
}
|
|
91
|
-
|
|
92
|
-
|
|
334
|
+
/** Apply the table's input transforms, then encode `data` as the write record for `operation`. */
|
|
335
|
+
function writeRecord(operation, table, data) {
|
|
336
|
+
return toWriteRecordForOperation(operation, transformInputColumns(table, data), table._schema, table._table);
|
|
93
337
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
const message = value;
|
|
98
|
-
if (message.type === "follower-sync") {
|
|
99
|
-
return (typeof message.fromTabId === "string" &&
|
|
100
|
-
typeof message.toLeaderTabId === "string" &&
|
|
101
|
-
typeof message.term === "number" &&
|
|
102
|
-
isStringArray(message.payload));
|
|
103
|
-
}
|
|
104
|
-
if (message.type === "leader-sync") {
|
|
105
|
-
return (typeof message.fromLeaderTabId === "string" &&
|
|
106
|
-
typeof message.toTabId === "string" &&
|
|
107
|
-
typeof message.term === "number" &&
|
|
108
|
-
isStringArray(message.payload));
|
|
109
|
-
}
|
|
110
|
-
if (message.type === "follower-close") {
|
|
111
|
-
return (typeof message.fromTabId === "string" &&
|
|
112
|
-
typeof message.toLeaderTabId === "string" &&
|
|
113
|
-
typeof message.term === "number");
|
|
338
|
+
function toWriteRecordForOperation(operation, data, schema, tableName) {
|
|
339
|
+
try {
|
|
340
|
+
return toWriteRecord(data, schema, tableName);
|
|
114
341
|
}
|
|
115
|
-
|
|
342
|
+
catch (error) {
|
|
343
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
344
|
+
throw new Error(`${operation} failed: WriteError("${escapeWriteErrorReason(message)}")`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function isPartialLargeValueUpdate(value) {
|
|
348
|
+
return typeof value === "object" && value !== null && ("splices" in value || "edits" in value);
|
|
349
|
+
}
|
|
350
|
+
function requireRecord(value, message) {
|
|
351
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
352
|
+
throw new Error(message);
|
|
353
|
+
}
|
|
354
|
+
return value;
|
|
355
|
+
}
|
|
356
|
+
function requireNonNegativeCoordinate(value, label, column) {
|
|
357
|
+
const coordinate = Number(value);
|
|
358
|
+
if (!Number.isSafeInteger(coordinate) || coordinate < 0) {
|
|
359
|
+
throw new Error(`${label} for "${column}" must be a non-negative safe integer.`);
|
|
360
|
+
}
|
|
361
|
+
return coordinate;
|
|
116
362
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
|
|
363
|
+
function requirePageRange(from, to, column) {
|
|
364
|
+
if (from > to) {
|
|
365
|
+
throw new Error(`Large-value page for "${column}" must have from <= to.`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* An `update` call's replacements and wire descriptors: its `applyDiffs`,
|
|
370
|
+
* and each `editedFrom` column's replacement as a text edit of that value.
|
|
371
|
+
*/
|
|
372
|
+
function lowerUpdate(table, data, options) {
|
|
373
|
+
const descriptors = lowerApplyDiffs(table, data, options?.applyDiffs);
|
|
374
|
+
const editedFrom = options?.editedFrom;
|
|
375
|
+
if (editedFrom === undefined) {
|
|
376
|
+
rejectIncompleteDependencies(table, data, Object.keys(options?.applyDiffs ?? {}));
|
|
377
|
+
return { replacements: data, descriptors };
|
|
378
|
+
}
|
|
379
|
+
if (typeof editedFrom !== "object" || editedFrom === null || Array.isArray(editedFrom)) {
|
|
380
|
+
throw new Error("update option editedFrom must be an object keyed by column name.");
|
|
381
|
+
}
|
|
382
|
+
const replacements = { ...data };
|
|
383
|
+
const edited = [];
|
|
384
|
+
for (const [column, from] of Object.entries(editedFrom)) {
|
|
385
|
+
if (from === undefined)
|
|
386
|
+
continue;
|
|
387
|
+
const transform = table._columnTransforms?.[column];
|
|
388
|
+
if (transform && !transform.computed) {
|
|
389
|
+
throw new Error(`update option editedFrom is not supported yet on "${column}", which has a transform.`);
|
|
390
|
+
}
|
|
391
|
+
const text = replacements[column];
|
|
392
|
+
if (typeof text !== "string" || typeof from !== "string") {
|
|
393
|
+
throw new Error(`update option editedFrom.${column} needs a string, and a string replacement for "${column}".`);
|
|
394
|
+
}
|
|
395
|
+
delete replacements[column];
|
|
396
|
+
edited.push(column);
|
|
397
|
+
descriptors.push({ kind: "text_edit", column, text, edited_from: from });
|
|
398
|
+
}
|
|
399
|
+
rejectIncompleteDependencies(table, replacements, [
|
|
400
|
+
...Object.keys(options?.applyDiffs ?? {}),
|
|
401
|
+
...edited,
|
|
402
|
+
]);
|
|
403
|
+
return { replacements, descriptors };
|
|
404
|
+
}
|
|
405
|
+
/** `options` without `editedFrom`, which {@link lowerUpdate} turned into descriptors. */
|
|
406
|
+
function withoutEditedFrom(options) {
|
|
407
|
+
if (options?.editedFrom === undefined)
|
|
408
|
+
return options;
|
|
409
|
+
const { editedFrom: _, ...rest } = options;
|
|
410
|
+
return rest;
|
|
411
|
+
}
|
|
412
|
+
/** Validate an `update` call's `applyDiffs` option and lower it to wire descriptors. */
|
|
413
|
+
function lowerApplyDiffs(table, data, diffs) {
|
|
414
|
+
if (diffs === undefined)
|
|
415
|
+
return [];
|
|
416
|
+
if (typeof diffs !== "object" || diffs === null || Array.isArray(diffs)) {
|
|
417
|
+
throw new Error("update option applyDiffs must be an object keyed by column name.");
|
|
418
|
+
}
|
|
419
|
+
if (Object.keys(data).some((column) => Object.hasOwn(diffs, column))) {
|
|
420
|
+
throw new Error("update replacements and applyDiffs must not both specify the same column.");
|
|
421
|
+
}
|
|
422
|
+
const { ordinary, descriptors } = splitLargeValueUpdate(diffs, table._schema, table._table);
|
|
423
|
+
if (Object.keys(ordinary).length > 0) {
|
|
424
|
+
throw new Error("update option applyDiffs accepts only field diff descriptors, not whole-column values.");
|
|
425
|
+
}
|
|
426
|
+
return descriptors;
|
|
427
|
+
}
|
|
428
|
+
function splitLargeValueUpdate(data, schema, table) {
|
|
429
|
+
const ordinary = {};
|
|
430
|
+
const descriptors = [];
|
|
431
|
+
const columns = schema[table]?.columns;
|
|
432
|
+
if (!columns)
|
|
433
|
+
throw new Error(`Unknown table "${table}"`);
|
|
434
|
+
for (const [column, value] of Object.entries(data)) {
|
|
435
|
+
if (!isPartialLargeValueUpdate(value)) {
|
|
436
|
+
ordinary[column] = value;
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const type = columns.find((candidate) => candidate.name === column)?.column_type;
|
|
440
|
+
if (!type)
|
|
441
|
+
throw new Error(`Unknown column "${column}" in table "${table}"`);
|
|
442
|
+
if ("splices" in value && "within" in value) {
|
|
443
|
+
const within = requireRecord(value.within, `Large-value update "${column}" has an invalid page.`);
|
|
444
|
+
const splices = value.splices;
|
|
445
|
+
if (!Array.isArray(splices))
|
|
446
|
+
throw new Error(`Large-value update "${column}" has invalid splices.`);
|
|
447
|
+
let page;
|
|
448
|
+
if ("fromUtf8" in within || "toUtf8" in within) {
|
|
449
|
+
if (type.type !== "Text")
|
|
450
|
+
throw new Error(`UTF-8 splice requires a Text column, got "${column}".`);
|
|
451
|
+
const from = requireNonNegativeCoordinate(within.fromUtf8, "fromUtf8", column);
|
|
452
|
+
const to = requireNonNegativeCoordinate(within.toUtf8, "toUtf8", column);
|
|
453
|
+
requirePageRange(from, to, column);
|
|
454
|
+
page = { kind: "text_utf8", from, to };
|
|
455
|
+
}
|
|
456
|
+
else if (type.type === "Bytea") {
|
|
457
|
+
const from = requireNonNegativeCoordinate(within.from, "from", column);
|
|
458
|
+
const to = requireNonNegativeCoordinate(within.to, "to", column);
|
|
459
|
+
requirePageRange(from, to, column);
|
|
460
|
+
page = { kind: "bytes", from, to };
|
|
461
|
+
}
|
|
462
|
+
else if (type.type === "Text") {
|
|
463
|
+
const from = requireNonNegativeCoordinate(within.from, "from", column);
|
|
464
|
+
const to = requireNonNegativeCoordinate(within.to, "to", column);
|
|
465
|
+
requirePageRange(from, to, column);
|
|
466
|
+
page = { kind: "text_utf16", from, to };
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
throw new Error(`Splice requires a Text or Bytea column, got "${column}".`);
|
|
470
|
+
}
|
|
471
|
+
descriptors.push({
|
|
472
|
+
kind: "splice",
|
|
473
|
+
column,
|
|
474
|
+
within: page,
|
|
475
|
+
splices: splices.map((splice) => {
|
|
476
|
+
const item = requireRecord(splice, `Large-value splice for "${column}" is invalid.`);
|
|
477
|
+
const utf8 = page.kind === "text_utf8";
|
|
478
|
+
const at = requireNonNegativeCoordinate(utf8 ? item.atUtf8 : item.at, "at", column);
|
|
479
|
+
const deleted = requireNonNegativeCoordinate(utf8 ? item.deleteUtf8 : item.delete, "delete", column);
|
|
480
|
+
const insert = item.insert;
|
|
481
|
+
let bytes;
|
|
482
|
+
if (page.kind === "bytes") {
|
|
483
|
+
if (!(insert instanceof Uint8Array)) {
|
|
484
|
+
throw new Error(`Byte splice insert for "${column}" must be a Uint8Array.`);
|
|
485
|
+
}
|
|
486
|
+
bytes = [...insert];
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
if (typeof insert !== "string") {
|
|
490
|
+
throw new Error(`Text splice insert for "${column}" must be a string.`);
|
|
491
|
+
}
|
|
492
|
+
bytes = [...new TextEncoder().encode(insert)];
|
|
493
|
+
}
|
|
494
|
+
return { at, delete: deleted, insert: bytes };
|
|
495
|
+
}),
|
|
496
|
+
});
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if ("edits" in value) {
|
|
500
|
+
if (type.type !== "Json")
|
|
501
|
+
throw new Error(`JSON set requires a JSON column, got "${column}".`);
|
|
502
|
+
if (!Array.isArray(value.edits))
|
|
503
|
+
throw new Error(`JSON update "${column}" has invalid edits.`);
|
|
504
|
+
descriptors.push({
|
|
505
|
+
kind: "json_set",
|
|
506
|
+
column,
|
|
507
|
+
edits: value.edits.map((edit) => {
|
|
508
|
+
const item = requireRecord(edit, `JSON update edit for "${column}" is invalid.`);
|
|
509
|
+
if (item.op !== "set" || typeof item.at !== "string") {
|
|
510
|
+
throw new Error(`JSON update "${column}" supports only { op: "set", at, value } edits.`);
|
|
511
|
+
}
|
|
512
|
+
return { at: item.at, value: item.value };
|
|
513
|
+
}),
|
|
514
|
+
});
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
ordinary[column] = value;
|
|
518
|
+
}
|
|
519
|
+
return { ordinary, descriptors };
|
|
520
|
+
}
|
|
521
|
+
function utf16Boundary(text, offset) {
|
|
522
|
+
if (offset < 0 || offset > text.length)
|
|
523
|
+
return false;
|
|
524
|
+
if (offset === 0 || offset === text.length)
|
|
120
525
|
return true;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
526
|
+
const before = text.charCodeAt(offset - 1);
|
|
527
|
+
const after = text.charCodeAt(offset);
|
|
528
|
+
return !(before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff);
|
|
529
|
+
}
|
|
530
|
+
function jsonPointerToken(token) {
|
|
531
|
+
let decoded = "";
|
|
532
|
+
for (let index = 0; index < token.length; index += 1) {
|
|
533
|
+
const character = token[index];
|
|
534
|
+
if (character !== "~") {
|
|
535
|
+
decoded += character;
|
|
536
|
+
continue;
|
|
124
537
|
}
|
|
538
|
+
const escape = token[++index];
|
|
539
|
+
if (escape === "0")
|
|
540
|
+
decoded += "~";
|
|
541
|
+
else if (escape === "1")
|
|
542
|
+
decoded += "/";
|
|
543
|
+
else
|
|
544
|
+
throw new Error("JSON pointer has an invalid escape.");
|
|
125
545
|
}
|
|
126
|
-
|
|
127
|
-
|
|
546
|
+
return decoded;
|
|
547
|
+
}
|
|
548
|
+
function jsonPointerValue(value, pointer) {
|
|
549
|
+
if (pointer === "")
|
|
550
|
+
return value;
|
|
551
|
+
if (!pointer.startsWith("/"))
|
|
552
|
+
throw new Error("JSON pointer must be empty or begin with '/'.");
|
|
553
|
+
let current = value;
|
|
554
|
+
for (const rawToken of pointer.slice(1).split("/")) {
|
|
555
|
+
const token = jsonPointerToken(rawToken);
|
|
556
|
+
if (Array.isArray(current)) {
|
|
557
|
+
if (!/^(0|[1-9]\d*)$/.test(token)) {
|
|
558
|
+
throw new Error("JSON array pointer token is not an index.");
|
|
559
|
+
}
|
|
560
|
+
const index = Number(token);
|
|
561
|
+
if (!Number.isSafeInteger(index) || index >= current.length) {
|
|
562
|
+
throw new Error("JSON pointer path does not exist.");
|
|
563
|
+
}
|
|
564
|
+
current = current[index];
|
|
565
|
+
}
|
|
566
|
+
else if (typeof current === "object" && current !== null && Object.hasOwn(current, token)) {
|
|
567
|
+
current = current[token];
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
throw new Error("JSON pointer path does not exist.");
|
|
571
|
+
}
|
|
128
572
|
}
|
|
129
|
-
return
|
|
573
|
+
return current;
|
|
130
574
|
}
|
|
131
575
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* ```typescript
|
|
136
|
-
* const db = await createDb({ appId: "my-app", driver });
|
|
137
|
-
*
|
|
138
|
-
* // Sync mutations (after WASM is pre-loaded)
|
|
139
|
-
* const id = db.insert(app.todos, { title: "Buy milk", done: false });
|
|
140
|
-
* db.update(app.todos, id, { done: true });
|
|
141
|
-
* db.deleteFrom(app.todos, id);
|
|
142
|
-
*
|
|
143
|
-
* // Async queries (need storage I/O)
|
|
144
|
-
* const todos = await db.all(app.todos.where({ done: false }));
|
|
145
|
-
* const todo = await db.one(app.todos.where({ id }));
|
|
146
|
-
*
|
|
147
|
-
* // Subscriptions
|
|
148
|
-
* const unsubscribe = db.subscribeAll(app.todos, (delta) => {
|
|
149
|
-
* console.log("All todos:", delta.all);
|
|
150
|
-
* console.log("Changes:", delta.delta);
|
|
151
|
-
* });
|
|
152
|
-
* ```
|
|
576
|
+
* The engine reads each partial selection of the physical query only in part
|
|
577
|
+
* (SPEC 19.12). A column a transform also depends on is read whole instead,
|
|
578
|
+
* and its visible selection is taken here from the whole value.
|
|
153
579
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
580
|
+
function applyPartialValueSelections(row, selections) {
|
|
581
|
+
if (Object.keys(selections).length === 0 || typeof row !== "object" || row === null)
|
|
582
|
+
return row;
|
|
583
|
+
const projected = { ...row };
|
|
584
|
+
for (const [column, selection] of Object.entries(selections)) {
|
|
585
|
+
const value = projected[column];
|
|
586
|
+
if ("at" in selection) {
|
|
587
|
+
projected[column] = jsonPointerValue(value, selection.at);
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
if (value instanceof Uint8Array) {
|
|
591
|
+
if ("fromUtf8" in selection || selection.from > selection.to || selection.to > value.length) {
|
|
592
|
+
throw new Error(`Byte range for "${column}" is out of bounds.`);
|
|
593
|
+
}
|
|
594
|
+
projected[column] = value.slice(selection.from, selection.to);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
if (typeof value !== "string") {
|
|
598
|
+
throw new Error(`Large-value selection for "${column}" has an incompatible column type.`);
|
|
599
|
+
}
|
|
600
|
+
if ("fromUtf8" in selection) {
|
|
601
|
+
const bytes = new TextEncoder().encode(value);
|
|
602
|
+
if (selection.fromUtf8 > selection.toUtf8 ||
|
|
603
|
+
selection.toUtf8 > bytes.length ||
|
|
604
|
+
(selection.fromUtf8 < bytes.length &&
|
|
605
|
+
(bytes[selection.fromUtf8] & 0b1100_0000) === 0b1000_0000) ||
|
|
606
|
+
(selection.toUtf8 < bytes.length &&
|
|
607
|
+
(bytes[selection.toUtf8] & 0b1100_0000) === 0b1000_0000)) {
|
|
608
|
+
throw new Error(`UTF-8 range for "${column}" splits a code point or is out of bounds.`);
|
|
609
|
+
}
|
|
610
|
+
projected[column] = new Utf8Decoder({ fatal: true }).decode(bytes.slice(selection.fromUtf8, selection.toUtf8));
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (selection.from > selection.to ||
|
|
614
|
+
!utf16Boundary(value, selection.from) ||
|
|
615
|
+
!utf16Boundary(value, selection.to)) {
|
|
616
|
+
throw new Error(`UTF-16 range for "${column}" splits a surrogate pair or is out of bounds.`);
|
|
617
|
+
}
|
|
618
|
+
projected[column] = value.slice(selection.from, selection.to);
|
|
619
|
+
}
|
|
620
|
+
return projected;
|
|
621
|
+
}
|
|
622
|
+
function escapeWriteErrorReason(message) {
|
|
623
|
+
return message.replaceAll('"', '\\"');
|
|
624
|
+
}
|
|
625
|
+
function resolveOutputColumnTransforms(query, inputTable, outputTable) {
|
|
626
|
+
return (query._columnTransformsByTable?.[outputTable] ??
|
|
627
|
+
(inputTable === outputTable ? query._columnTransforms : undefined));
|
|
628
|
+
}
|
|
629
|
+
function prepareTransformRead(query, built, outputTable, computedState) {
|
|
630
|
+
const outputTransforms = resolveOutputColumnTransforms(query, built.table, outputTable);
|
|
631
|
+
const outputIncludes = outputTable === built.table || !Object.keys(built.includes).length ? built.includes : {};
|
|
632
|
+
const hasIncludes = Object.keys(outputIncludes).length > 0;
|
|
633
|
+
if (!outputTransforms && (!query._columnTransformsByTable || !hasIncludes)) {
|
|
634
|
+
const decode = createRowTransformer(query._schema, outputTable, outputIncludes, built.select);
|
|
635
|
+
return {
|
|
636
|
+
computedState: undefined,
|
|
637
|
+
version: 0,
|
|
638
|
+
physical: outputIncludes === built.includes ? built : { ...built, includes: outputIncludes },
|
|
639
|
+
// The engine applies every partial selection of this physical query.
|
|
640
|
+
transform: decode,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
const relations = hasIncludes ? analyzeRelations(query._schema) : undefined;
|
|
644
|
+
const prepare = (table, select, includes, partialSelect) => {
|
|
645
|
+
const transforms = query._columnTransformsByTable?.[table] ??
|
|
646
|
+
(table === outputTable ? outputTransforms : undefined);
|
|
647
|
+
let physical = select;
|
|
648
|
+
let partial = partialSelect;
|
|
649
|
+
const selectAll = !select.length || select.includes("*");
|
|
650
|
+
let visibleTransforms;
|
|
651
|
+
let dependencies;
|
|
652
|
+
let hidden;
|
|
653
|
+
let computed;
|
|
654
|
+
const addDependency = (dependency) => {
|
|
655
|
+
if (transforms?.[dependency]?.computed)
|
|
656
|
+
return;
|
|
657
|
+
(dependencies ??= new Set()).add(dependency);
|
|
658
|
+
if (!selectAll && dependency !== "id" && !physical.includes(dependency)) {
|
|
659
|
+
if (physical === select)
|
|
660
|
+
physical = [...select];
|
|
661
|
+
physical.push(dependency);
|
|
662
|
+
(hidden ??= []).push(dependency);
|
|
663
|
+
}
|
|
664
|
+
if (Object.hasOwn(partial, dependency)) {
|
|
665
|
+
if (partial === partialSelect)
|
|
666
|
+
partial = { ...partialSelect };
|
|
667
|
+
delete partial[dependency];
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
if (transforms && select.some((column) => transforms[column]?.computed))
|
|
671
|
+
physical = select.filter((column) => !transforms[column]?.computed);
|
|
672
|
+
if (transforms)
|
|
673
|
+
for (const column of selectAll ? Object.keys(transforms) : select) {
|
|
674
|
+
if (!Object.hasOwn(transforms, column))
|
|
675
|
+
continue;
|
|
676
|
+
(visibleTransforms ??= {})[column] = transforms[column];
|
|
677
|
+
if (transforms[column].computed) {
|
|
678
|
+
computedState ??= new ComputedReadState();
|
|
679
|
+
(computed ??= []).push(column);
|
|
680
|
+
for (const dependency of computedState.storedColumns(transforms, column))
|
|
681
|
+
addDependency(dependency);
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
for (const dependency of transforms[column].dependsOn ?? [])
|
|
685
|
+
addDependency(dependency);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (!selectAll && !physical.length)
|
|
689
|
+
physical = ["id"];
|
|
690
|
+
let preparedIncludes = includes;
|
|
691
|
+
const finishIncludes = [];
|
|
692
|
+
for (const [name, include] of Object.entries(includes)) {
|
|
693
|
+
const target = relations?.get(table)?.find((relation) => relation.name === name)?.toTable;
|
|
694
|
+
if (!target)
|
|
695
|
+
continue;
|
|
696
|
+
const prepared = prepare(target, include.select, include.includes, include.partialSelect);
|
|
697
|
+
if (prepared.select !== include.select ||
|
|
698
|
+
prepared.includes !== include.includes ||
|
|
699
|
+
prepared.partialSelect !== include.partialSelect) {
|
|
700
|
+
if (preparedIncludes === includes)
|
|
701
|
+
preparedIncludes = { ...includes };
|
|
702
|
+
preparedIncludes[name] = {
|
|
703
|
+
...include,
|
|
704
|
+
select: prepared.select,
|
|
705
|
+
includes: prepared.includes,
|
|
706
|
+
partialSelect: prepared.partialSelect,
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
if (prepared.finish)
|
|
710
|
+
finishIncludes.push([name, prepared.finish]);
|
|
711
|
+
}
|
|
712
|
+
const dependencyColumns = dependencies ? [...dependencies] : noWriteDependencies;
|
|
713
|
+
const hasPartial = Object.keys(partialSelect).length > 0;
|
|
714
|
+
// Selections the engine did not apply: those whose column it read whole.
|
|
715
|
+
const wholeRead = Object.fromEntries(Object.entries(partialSelect).filter(([column]) => !Object.hasOwn(partial, column)));
|
|
716
|
+
const sliceWhole = Object.keys(wholeRead).length > 0;
|
|
717
|
+
const excluded = Object.keys(includes);
|
|
718
|
+
return {
|
|
719
|
+
select: physical,
|
|
720
|
+
includes: preparedIncludes,
|
|
721
|
+
partialSelect: partial,
|
|
722
|
+
finish: visibleTransforms || hasPartial || finishIncludes.length
|
|
723
|
+
? (row) => {
|
|
724
|
+
const stored = computed
|
|
725
|
+
? { ...row }
|
|
726
|
+
: visibleTransforms
|
|
727
|
+
? storedDependencyValues(dependencyColumns, row)
|
|
728
|
+
: undefined;
|
|
729
|
+
const appValues = computed
|
|
730
|
+
? computedColumnValues(transforms, computed, stored, computedState, partial)
|
|
731
|
+
: undefined;
|
|
732
|
+
const result = sliceWhole ? applyPartialValueSelections(row, wholeRead) : row;
|
|
733
|
+
if (visibleTransforms)
|
|
734
|
+
applyColumnTransforms(result, visibleTransforms, excluded, stored, appValues, hasPartial ? partialSelect : undefined);
|
|
735
|
+
if (computed)
|
|
736
|
+
for (const column of computed)
|
|
737
|
+
result[column] = appValues.get(column);
|
|
738
|
+
for (const [name, finish] of finishIncludes) {
|
|
739
|
+
const value = result[name];
|
|
740
|
+
if (Array.isArray(value))
|
|
741
|
+
for (let i = 0; i < value.length; i++)
|
|
742
|
+
value[i] = finish(value[i]);
|
|
743
|
+
else if (value && typeof value === "object")
|
|
744
|
+
result[name] = finish(value);
|
|
745
|
+
}
|
|
746
|
+
if (hidden)
|
|
747
|
+
for (const column of hidden)
|
|
748
|
+
delete result[column];
|
|
749
|
+
return result;
|
|
750
|
+
}
|
|
751
|
+
: undefined,
|
|
752
|
+
};
|
|
186
753
|
};
|
|
187
|
-
|
|
188
|
-
|
|
754
|
+
const prepared = prepare(outputTable, built.select, outputIncludes, built.partialSelect);
|
|
755
|
+
const decode = createRowTransformer(query._schema, outputTable, prepared.includes, prepared.select, undefined, false, relations);
|
|
756
|
+
return {
|
|
757
|
+
computedState,
|
|
758
|
+
version: computedState?.version ?? 0,
|
|
759
|
+
physical: prepared.select === built.select &&
|
|
760
|
+
prepared.partialSelect === built.partialSelect &&
|
|
761
|
+
prepared.includes === built.includes
|
|
762
|
+
? built
|
|
763
|
+
: {
|
|
764
|
+
...built,
|
|
765
|
+
select: prepared.select,
|
|
766
|
+
partialSelect: prepared.partialSelect,
|
|
767
|
+
includes: prepared.includes,
|
|
768
|
+
},
|
|
769
|
+
transform: prepared.finish
|
|
770
|
+
? (row) => prepared.finish(decode(row))
|
|
771
|
+
: decode,
|
|
189
772
|
};
|
|
190
|
-
|
|
191
|
-
|
|
773
|
+
}
|
|
774
|
+
/** Retry only computations that discovered a missing field, preserving the caller's read scope. */
|
|
775
|
+
async function finishComputedRead(query, built, outputTable, prepared, rows, read) {
|
|
776
|
+
for (;;) {
|
|
777
|
+
const results = [];
|
|
778
|
+
let missing;
|
|
779
|
+
// Visit every root before retrying so different rows' branches share a lookup.
|
|
780
|
+
for (const row of rows) {
|
|
781
|
+
try {
|
|
782
|
+
results.push(prepared.transform(row));
|
|
783
|
+
}
|
|
784
|
+
catch (error) {
|
|
785
|
+
if (!(error instanceof MissingComputedDependency))
|
|
786
|
+
throw error;
|
|
787
|
+
missing = error;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (!missing)
|
|
791
|
+
return results;
|
|
792
|
+
if (!prepared.computedState || prepared.computedState.version === prepared.version)
|
|
793
|
+
throw missing;
|
|
794
|
+
prepared = prepareTransformRead(query, built, outputTable, prepared.computedState);
|
|
795
|
+
rows = await read(prepared.physical);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
const dbTxHandleBindings = new WeakMap();
|
|
799
|
+
function getDbTxHandleBinding(handle, operation) {
|
|
800
|
+
const binding = dbTxHandleBindings.get(handle);
|
|
801
|
+
if (!binding) {
|
|
802
|
+
throw new Error(`DbTransaction.${operation}() requires at least one table operation first`);
|
|
803
|
+
}
|
|
804
|
+
return binding;
|
|
805
|
+
}
|
|
806
|
+
function transformOutputRow(source, row) {
|
|
807
|
+
return transformOutputColumns(source, row);
|
|
808
|
+
}
|
|
809
|
+
function transformOutputColumns(source, row) {
|
|
810
|
+
if (!source._columnTransforms || typeof row !== "object" || row === null) {
|
|
811
|
+
return row;
|
|
812
|
+
}
|
|
813
|
+
const record = row;
|
|
814
|
+
const computed = columnTransformDependencies(source._columnTransforms).computedColumns;
|
|
815
|
+
const appValues = computed.length
|
|
816
|
+
? computedColumnValues(source._columnTransforms, computed, record)
|
|
817
|
+
: undefined;
|
|
818
|
+
applyColumnTransforms(record, source._columnTransforms, [], undefined, appValues);
|
|
819
|
+
for (const column of computed)
|
|
820
|
+
record[column] = appValues.get(column);
|
|
821
|
+
return record;
|
|
822
|
+
}
|
|
823
|
+
function transformInputColumns(table, data, storedValues, creation = false) {
|
|
824
|
+
const record = data;
|
|
825
|
+
if (!table._columnTransforms) {
|
|
826
|
+
return record;
|
|
827
|
+
}
|
|
828
|
+
const transforms = table._columnTransforms;
|
|
829
|
+
let hasTransform = false;
|
|
830
|
+
let hasDependencies = false;
|
|
831
|
+
for (const column in record) {
|
|
832
|
+
if (Object.hasOwn(record, column) && transforms[column]?.computed)
|
|
833
|
+
throw new TypeError(`Computed field "${column}" is read-only.`);
|
|
834
|
+
if (!Object.hasOwn(record, column) || record[column] === undefined)
|
|
835
|
+
continue;
|
|
836
|
+
const transform = transforms[column];
|
|
837
|
+
if (transform) {
|
|
838
|
+
hasTransform = true;
|
|
839
|
+
if (transform.dependsOn?.length)
|
|
840
|
+
hasDependencies = true;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (!hasTransform)
|
|
844
|
+
return record;
|
|
845
|
+
if (!hasDependencies) {
|
|
846
|
+
const result = { ...record };
|
|
847
|
+
for (const column in record) {
|
|
848
|
+
if (!Object.hasOwn(record, column) || record[column] === undefined)
|
|
849
|
+
continue;
|
|
850
|
+
const transform = transforms[column];
|
|
851
|
+
if (transform)
|
|
852
|
+
result[column] = transform.to(record[column], dependencyContext(transform, record));
|
|
853
|
+
}
|
|
854
|
+
return result;
|
|
855
|
+
}
|
|
856
|
+
const stored = { ...storedValues };
|
|
857
|
+
const app = {};
|
|
858
|
+
const resolved = new Set();
|
|
859
|
+
const resolve = (column) => {
|
|
860
|
+
if (resolved.has(column))
|
|
861
|
+
return;
|
|
862
|
+
const transform = table._columnTransforms?.[column];
|
|
863
|
+
for (const dependency of transform?.dependsOn ?? [])
|
|
864
|
+
resolve(dependency);
|
|
865
|
+
if (Object.hasOwn(record, column) && record[column] !== undefined) {
|
|
866
|
+
app[column] = record[column];
|
|
867
|
+
stored[column] = transform
|
|
868
|
+
? transform.to(record[column], dependencyContext(transform, app))
|
|
869
|
+
: record[column];
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
if (creation && !Object.hasOwn(stored, column)) {
|
|
873
|
+
const descriptor = table._schema[table._table].columns.find((item) => item.name === column);
|
|
874
|
+
if (descriptor?.default !== undefined)
|
|
875
|
+
stored[column] = unwrapValue(descriptor.default, descriptor.column_type);
|
|
876
|
+
else if (descriptor?.nullable)
|
|
877
|
+
stored[column] = null;
|
|
878
|
+
}
|
|
879
|
+
if (!Object.hasOwn(stored, column))
|
|
880
|
+
throw new Error(`Transform dependency "${column}" is unavailable.`);
|
|
881
|
+
app[column] = transform
|
|
882
|
+
? transform.from(stored[column], dependencyContext(transform, stored))
|
|
883
|
+
: stored[column];
|
|
884
|
+
}
|
|
885
|
+
resolved.add(column);
|
|
192
886
|
};
|
|
887
|
+
const result = { ...record };
|
|
888
|
+
for (const column of Object.keys(record)) {
|
|
889
|
+
if (record[column] === undefined)
|
|
890
|
+
continue;
|
|
891
|
+
resolve(column);
|
|
892
|
+
result[column] = stored[column];
|
|
893
|
+
}
|
|
894
|
+
return result;
|
|
895
|
+
}
|
|
896
|
+
const noWriteDependencies = [];
|
|
897
|
+
/**
|
|
898
|
+
* How long an update of a row this replica hasn't loaded waits for the
|
|
899
|
+
* server to send it, before it is refused as a row the session can't find.
|
|
900
|
+
*/
|
|
901
|
+
const LOAD_ROW_WAIT_MS = 10_000;
|
|
902
|
+
/**
|
|
903
|
+
* Read one row by id from the server through the caller's session, so this
|
|
904
|
+
* replica holds it before a write stages against it. The read waits for the
|
|
905
|
+
* server at most {@link LOAD_ROW_WAIT_MS}: offline, it finds no row and the
|
|
906
|
+
* update fails instead of hanging, with the writes queued behind it.
|
|
907
|
+
*/
|
|
908
|
+
function loadRow(client, table, id, session, branch) {
|
|
909
|
+
const built = JSON.stringify({
|
|
910
|
+
table: table._table,
|
|
911
|
+
conditions: [{ column: "id", op: "eq", value: id }],
|
|
912
|
+
limit: 1,
|
|
913
|
+
});
|
|
914
|
+
const read = client.queryInternal(translateQuery(built, table._schema), branch ? { tier: "remote", branch } : { tier: "remote" }, session);
|
|
915
|
+
let timer;
|
|
916
|
+
const timeout = new Promise((resolve) => {
|
|
917
|
+
timer = setTimeout(() => resolve([]), LOAD_ROW_WAIT_MS);
|
|
918
|
+
});
|
|
919
|
+
return Promise.race([read, timeout]).finally(() => clearTimeout(timer));
|
|
920
|
+
}
|
|
921
|
+
function missingWriteDependencies(table, data, id) {
|
|
922
|
+
if (!table._columnTransforms)
|
|
923
|
+
return noWriteDependencies;
|
|
924
|
+
const { byColumn } = columnTransformDependencies(table._columnTransforms);
|
|
925
|
+
let missing;
|
|
926
|
+
for (const column of Object.keys(data)) {
|
|
927
|
+
if (table._columnTransforms[column]?.computed)
|
|
928
|
+
throw new TypeError(`Computed field "${column}" is read-only.`);
|
|
929
|
+
if (data[column] === undefined)
|
|
930
|
+
continue;
|
|
931
|
+
for (const dependency of byColumn.get(column) ?? noWriteDependencies) {
|
|
932
|
+
if (dependency !== "id" || id === undefined) {
|
|
933
|
+
if (!Object.hasOwn(data, dependency) || data[dependency] === undefined)
|
|
934
|
+
(missing ??= new Set()).add(dependency);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return missing ? [...missing] : noWriteDependencies;
|
|
939
|
+
}
|
|
940
|
+
function prepareInputColumns(table, data, operation, id, client, session, openTransactionId, options, missing) {
|
|
941
|
+
if (!table._columnTransforms)
|
|
942
|
+
return data;
|
|
943
|
+
missing ??= missingWriteDependencies(table, data, id);
|
|
944
|
+
const stored = id === undefined ? {} : { id };
|
|
945
|
+
if (operation === "Insert" || operation === "Restore" || missing.length === 0)
|
|
946
|
+
return transformInputColumns(table, data, stored, operation === "Insert" || operation === "Restore");
|
|
947
|
+
const built = JSON.stringify({
|
|
948
|
+
table: table._table,
|
|
949
|
+
conditions: [{ column: "id", op: "eq", value: id }],
|
|
950
|
+
select: missing.filter((column) => column !== "id"),
|
|
951
|
+
limit: 1,
|
|
952
|
+
includeDeleted: operation === "Upsert",
|
|
953
|
+
});
|
|
954
|
+
return client
|
|
955
|
+
.queryInternal(translateQuery(built, table._schema), {
|
|
956
|
+
...(options?.branch ? { branch: options.branch } : {}),
|
|
957
|
+
...(openTransactionId ? { openTransactionId, localUpdates: "deferred" } : {}),
|
|
958
|
+
}, session)
|
|
959
|
+
.then((rows) => {
|
|
960
|
+
const row = rows[0];
|
|
961
|
+
if (!row && operation !== "Upsert")
|
|
962
|
+
throw new Error("Transform dependency row is unavailable.");
|
|
963
|
+
if (!row && !client.readCanEstablishAbsence(session, openTransactionId))
|
|
964
|
+
throw new Error("Transform dependencies are unavailable: a scoped read cannot establish that the upsert row is absent.");
|
|
965
|
+
const existing = row
|
|
966
|
+
? transformRow(row, table._schema, table._table, {}, missing)
|
|
967
|
+
: stored;
|
|
968
|
+
return transformInputColumns(table, data, existing, !row && operation === "Upsert");
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
function rejectIncompleteDependencies(table, data, incomplete) {
|
|
972
|
+
if (!table._columnTransforms || !incomplete.length)
|
|
973
|
+
return;
|
|
974
|
+
const { byColumn } = columnTransformDependencies(table._columnTransforms);
|
|
975
|
+
for (const column of Object.keys(data)) {
|
|
976
|
+
for (const dependency of byColumn.get(column) ?? noWriteDependencies) {
|
|
977
|
+
if (incomplete.includes(dependency))
|
|
978
|
+
throw new Error(`Transform dependency "${dependency}" requires a whole-value replacement in this write.`);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* @internal The row an insert or restore of `data` as row `id` writes, as
|
|
984
|
+
* the table's schema alone decides it: for writes made before a client
|
|
985
|
+
* exists (`createJazz`'s `db` while its store opens).
|
|
986
|
+
*/
|
|
987
|
+
export function previewWrittenRow(table, operation, id, data) {
|
|
988
|
+
assertWritableTable(table);
|
|
989
|
+
const transformedData = table._columnTransforms
|
|
990
|
+
? transformInputColumns(table, data, { id }, true)
|
|
991
|
+
: data;
|
|
992
|
+
return immediateWriteRow(table, id, toWriteRecordForOperation(operation, transformedData, table._schema, table._table));
|
|
993
|
+
}
|
|
994
|
+
/** @internal A fresh row id, as an insert without one would get. */
|
|
995
|
+
export function reserveRowId() {
|
|
996
|
+
const hex = createOpenTransactionId();
|
|
997
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
998
|
+
}
|
|
999
|
+
function hasDependentTransforms(table) {
|
|
1000
|
+
return (!!table._columnTransforms &&
|
|
1001
|
+
columnTransformDependencies(table._columnTransforms).hasWriteDependencies);
|
|
1002
|
+
}
|
|
1003
|
+
function immediateWriteRow(table, id, values) {
|
|
1004
|
+
return transformOutputRow(table, transformRow(writeRow(table._table, id, table._schema[table._table].columns, values), table._schema, table._table));
|
|
1005
|
+
}
|
|
1006
|
+
function splitStreamingMutation(table, data) {
|
|
1007
|
+
if (typeof data !== "object" || data === null) {
|
|
1008
|
+
throw new Error("Streaming insert data must be an object");
|
|
1009
|
+
}
|
|
1010
|
+
const record = data;
|
|
1011
|
+
const streamableColumns = table._schema[table._table]?.columns.filter((column) => ["Text", "Json", "Bytea"].includes(column.column_type.type));
|
|
1012
|
+
const streamed = streamableColumns?.filter((column) => Object.hasOwn(record, column.name) && isStreamingValueSource(record[column.name]));
|
|
1013
|
+
if (streamed?.length !== 1) {
|
|
1014
|
+
throw new Error("Streaming insert requires exactly one streamed Text, Json, or Bytea column");
|
|
1015
|
+
}
|
|
1016
|
+
const column = streamed[0].name;
|
|
1017
|
+
if (table._schema[table._table]?.branchBy?.includes(column)) {
|
|
1018
|
+
throw new Error(`Streaming a branchBy column is not supported: ${table._table}.${column}`);
|
|
1019
|
+
}
|
|
1020
|
+
const source = record[column];
|
|
1021
|
+
const values = { ...record };
|
|
1022
|
+
delete values[column];
|
|
1023
|
+
return { column, source, values };
|
|
1024
|
+
}
|
|
1025
|
+
function isStreamingValueSource(value) {
|
|
1026
|
+
if (typeof value !== "object" || value === null)
|
|
1027
|
+
return false;
|
|
1028
|
+
const candidate = value;
|
|
1029
|
+
return (typeof candidate.getReader === "function" ||
|
|
1030
|
+
typeof candidate[Symbol.asyncIterator] === "function");
|
|
1031
|
+
}
|
|
1032
|
+
function deriveStreamingInsertBranch(table, values) {
|
|
1033
|
+
const branchColumns = table._schema[table._table]?.branchBy ?? [];
|
|
1034
|
+
if (branchColumns.length === 0)
|
|
1035
|
+
return undefined;
|
|
1036
|
+
const branch = {};
|
|
1037
|
+
for (const column of branchColumns) {
|
|
1038
|
+
const value = values[column];
|
|
1039
|
+
if (isStreamingValueSource(value)) {
|
|
1040
|
+
throw new Error(`Streaming a branchBy column is not supported: ${table._table}.${column}`);
|
|
1041
|
+
}
|
|
1042
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
|
|
1043
|
+
throw new Error(`Streaming insert requires branch column ${table._table}.${column}`);
|
|
1044
|
+
}
|
|
1045
|
+
branch[column] = value;
|
|
1046
|
+
}
|
|
1047
|
+
return branch;
|
|
1048
|
+
}
|
|
1049
|
+
function createTransactionScope(transaction) {
|
|
1050
|
+
return new Proxy(transaction, {
|
|
1051
|
+
get(target, property) {
|
|
1052
|
+
if (property === "commit" || property === "rollback") {
|
|
1053
|
+
return undefined;
|
|
1054
|
+
}
|
|
1055
|
+
const value = Reflect.get(target, property, target);
|
|
1056
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
1057
|
+
},
|
|
1058
|
+
has(target, property) {
|
|
1059
|
+
if (property === "commit" || property === "rollback") {
|
|
1060
|
+
return false;
|
|
1061
|
+
}
|
|
1062
|
+
return Reflect.has(target, property);
|
|
1063
|
+
},
|
|
1064
|
+
set(target, property, value) {
|
|
1065
|
+
return Reflect.set(target, property, value, target);
|
|
1066
|
+
},
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
function createTransactionWriteResult(transaction, value, txId, client) {
|
|
1070
|
+
if (transaction.kind === "serializable") {
|
|
1071
|
+
return new SerializableWriteResult(value, txId, client);
|
|
1072
|
+
}
|
|
1073
|
+
return new WriteResult(value, txId, client);
|
|
1074
|
+
}
|
|
1075
|
+
export async function runInTransaction(transaction, callback, client) {
|
|
1076
|
+
let value;
|
|
1077
|
+
try {
|
|
1078
|
+
const scope = createTransactionScope(transaction);
|
|
1079
|
+
value = callback(scope);
|
|
1080
|
+
}
|
|
1081
|
+
catch (error) {
|
|
1082
|
+
try {
|
|
1083
|
+
await transaction.rollback();
|
|
1084
|
+
}
|
|
1085
|
+
catch {
|
|
1086
|
+
// Preserve the original callback error.
|
|
1087
|
+
}
|
|
1088
|
+
throw error;
|
|
1089
|
+
}
|
|
1090
|
+
const resultClient = typeof client === "function" ? client : () => client;
|
|
1091
|
+
let resolvedValue;
|
|
1092
|
+
try {
|
|
1093
|
+
resolvedValue = await value;
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
try {
|
|
1097
|
+
await transaction.rollback();
|
|
1098
|
+
}
|
|
1099
|
+
catch {
|
|
1100
|
+
// Preserve the original callback error.
|
|
1101
|
+
}
|
|
1102
|
+
throw error;
|
|
1103
|
+
}
|
|
1104
|
+
let committed;
|
|
1105
|
+
try {
|
|
1106
|
+
committed = await transaction.commit();
|
|
1107
|
+
}
|
|
1108
|
+
catch (error) {
|
|
1109
|
+
try {
|
|
1110
|
+
await transaction.rollback();
|
|
1111
|
+
}
|
|
1112
|
+
catch {
|
|
1113
|
+
// Preserve the commit error while ensuring an empty mergeable transaction is
|
|
1114
|
+
// consumed when the callback helper has no handle to return to callers.
|
|
1115
|
+
}
|
|
1116
|
+
throw error;
|
|
1117
|
+
}
|
|
1118
|
+
const txId = committed.txId.catch(async (error) => {
|
|
1119
|
+
try {
|
|
1120
|
+
await transaction.rollback();
|
|
1121
|
+
}
|
|
1122
|
+
catch {
|
|
1123
|
+
// Preserve the deferred commit error, just as for synchronous commit failure.
|
|
1124
|
+
}
|
|
1125
|
+
throw error;
|
|
1126
|
+
});
|
|
1127
|
+
return createTransactionWriteResult(transaction, resolvedValue, txId, resultClient());
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Groups a set of writes as either a mergeable or serializable transaction (see {@link TransactionKind}).
|
|
1131
|
+
*/
|
|
1132
|
+
export class Transaction {
|
|
1133
|
+
kind;
|
|
1134
|
+
resolveClient;
|
|
1135
|
+
context;
|
|
1136
|
+
/** @internal Install the prerequisite before binding the owner. */
|
|
1137
|
+
static createWithAdmission(kind, resolveClient, context, ownerClient, prerequisite) {
|
|
1138
|
+
const transaction = new Transaction(kind, resolveClient, context);
|
|
1139
|
+
transaction.openingPrerequisite = prerequisite;
|
|
1140
|
+
if (ownerClient)
|
|
1141
|
+
transaction.bindOwnerClient(ownerClient);
|
|
1142
|
+
return transaction;
|
|
1143
|
+
}
|
|
1144
|
+
openingPrerequisite;
|
|
1145
|
+
pendingReads = new Set();
|
|
1146
|
+
committing = false;
|
|
1147
|
+
constructor(kind, resolveClient, context = null, ownerClient) {
|
|
1148
|
+
this.kind = kind;
|
|
1149
|
+
this.resolveClient = resolveClient;
|
|
1150
|
+
this.context = context;
|
|
1151
|
+
if (ownerClient)
|
|
1152
|
+
this.bindOwnerClient(ownerClient);
|
|
1153
|
+
}
|
|
1154
|
+
bindTable(table) {
|
|
1155
|
+
const client = this.resolveClient(table._schema);
|
|
1156
|
+
if (!dbTxHandleBindings.has(this))
|
|
1157
|
+
this.bindOwnerClient(client);
|
|
1158
|
+
if (this.requireBinding("table operation").committing)
|
|
1159
|
+
throw new Error("Transaction commit has already been requested.");
|
|
1160
|
+
return this.requireBinding("table operation");
|
|
1161
|
+
}
|
|
1162
|
+
bindQuery(query) {
|
|
1163
|
+
return this.bindTable(query);
|
|
1164
|
+
}
|
|
1165
|
+
requireBinding(operation) {
|
|
1166
|
+
if (this.committing) {
|
|
1167
|
+
throw new Error(`DbTransaction.${operation}() cannot run after commit has been requested`);
|
|
1168
|
+
}
|
|
1169
|
+
return getDbTxHandleBinding(this, operation);
|
|
1170
|
+
}
|
|
1171
|
+
bindOwnerClient(ownerClient) {
|
|
1172
|
+
const { writeSession: session, attribution } = this.context ?? {};
|
|
1173
|
+
const preparation = new WritePreparation(true);
|
|
1174
|
+
const owner = getOwnerPreparation(ownerClient);
|
|
1175
|
+
const openTransactionId = owner?.pending
|
|
1176
|
+
? createOpenTransactionId()
|
|
1177
|
+
: this.openingPrerequisite
|
|
1178
|
+
? beginClientTransactionAfter(ownerClient, this.kind, session, attribution, undefined, this.openingPrerequisite)
|
|
1179
|
+
: ownerClient.beginTransaction(this.kind, session, attribution);
|
|
1180
|
+
const binding = {
|
|
1181
|
+
ownerClient,
|
|
1182
|
+
openTransactionId,
|
|
1183
|
+
session: session,
|
|
1184
|
+
attribution: attribution,
|
|
1185
|
+
preparation,
|
|
1186
|
+
begun: !owner?.pending,
|
|
1187
|
+
};
|
|
1188
|
+
dbTxHandleBindings.set(this, binding);
|
|
1189
|
+
if (!binding.begun)
|
|
1190
|
+
preparation.run(() => owner.run(() => {
|
|
1191
|
+
if (preparation.cancelled)
|
|
1192
|
+
return;
|
|
1193
|
+
if (this.openingPrerequisite)
|
|
1194
|
+
beginClientTransactionAfter(ownerClient, this.kind, session, attribution, openTransactionId, this.openingPrerequisite);
|
|
1195
|
+
else
|
|
1196
|
+
ownerClient.beginTransaction(this.kind, session, attribution, openTransactionId);
|
|
1197
|
+
binding.begun = true;
|
|
1198
|
+
}));
|
|
1199
|
+
}
|
|
1200
|
+
openTransactionId() {
|
|
1201
|
+
return this.requireBinding("openTransactionId").openTransactionId;
|
|
1202
|
+
}
|
|
193
1203
|
/**
|
|
194
|
-
*
|
|
1204
|
+
* Commit this transaction.
|
|
195
1205
|
*/
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
1206
|
+
commit() {
|
|
1207
|
+
const binding = this.requireBinding("commit");
|
|
1208
|
+
const { ownerClient, openTransactionId, preparation } = binding;
|
|
1209
|
+
if (binding.committing)
|
|
1210
|
+
throw new Error("Transaction commit has already been requested.");
|
|
1211
|
+
if (preparation.pending || preparation.failed)
|
|
1212
|
+
binding.committing = true;
|
|
1213
|
+
const txId = preparation.pending || preparation.failed || this.pendingReads.size > 0
|
|
1214
|
+
? Promise.all([preparation.drain(), ...this.pendingReads]).then(() => ownerClient.commitTransaction(openTransactionId).txId)
|
|
1215
|
+
: ownerClient.commitTransaction(openTransactionId).txId;
|
|
1216
|
+
this.committing = true;
|
|
1217
|
+
const finishCommit = () => {
|
|
1218
|
+
this.committing = false;
|
|
1219
|
+
};
|
|
1220
|
+
txId.then(finishCommit, finishCommit);
|
|
1221
|
+
if (this.kind === "serializable") {
|
|
1222
|
+
return new SerializableWriteHandle(txId, ownerClient);
|
|
1223
|
+
}
|
|
1224
|
+
return new WriteHandle(txId, ownerClient);
|
|
199
1225
|
}
|
|
200
1226
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
1227
|
+
* Roll back this transaction locally.
|
|
1228
|
+
*
|
|
1229
|
+
* Pending rows remain pending, but this transaction can no longer be committed.
|
|
1230
|
+
*
|
|
1231
|
+
* Only available on transactions created with {@link Db.beginTransaction}.
|
|
1232
|
+
* When using {@link Db.transaction}, throw an error inside the callback to roll back.
|
|
203
1233
|
*/
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
1234
|
+
rollback() {
|
|
1235
|
+
const { ownerClient, openTransactionId, preparation, begun } = this.requireBinding("rollback");
|
|
1236
|
+
if (!begun) {
|
|
1237
|
+
preparation.cancelled = true;
|
|
1238
|
+
return Promise.resolve(true);
|
|
1239
|
+
}
|
|
1240
|
+
const result = ownerClient.rollbackTransaction(openTransactionId);
|
|
1241
|
+
preparation.cancelled = true;
|
|
1242
|
+
return result;
|
|
207
1243
|
}
|
|
208
1244
|
/**
|
|
209
|
-
*
|
|
1245
|
+
* Stream one Text, Json, or Bytea column into a new row, staged in this
|
|
1246
|
+
* transaction. Resolves with the row id once the stream is consumed; the
|
|
1247
|
+
* commit waits for it and fails if the stream did.
|
|
210
1248
|
*
|
|
211
|
-
* The
|
|
212
|
-
*
|
|
213
|
-
*
|
|
1249
|
+
* The streamed value is held for the transaction for at most the store's
|
|
1250
|
+
* staging max age (10 minutes by default) after the stream finishes. A
|
|
1251
|
+
* transaction left open longer than that is refused at commit, with
|
|
1252
|
+
* `streaming upload expired`, so its storage is never held indefinitely;
|
|
1253
|
+
* start it again. The same applies to `updateStreaming` and
|
|
1254
|
+
* `upsertStreaming`.
|
|
1255
|
+
*/
|
|
1256
|
+
insertStreaming(table, data, options) {
|
|
1257
|
+
return this.streamingMutation("insert", table, options?.id, data, options);
|
|
1258
|
+
}
|
|
1259
|
+
/** Stream one large column of an existing row, staged in this transaction. */
|
|
1260
|
+
updateStreaming(table, id, data, options) {
|
|
1261
|
+
return this.streamingMutation("update", table, id, data, options);
|
|
1262
|
+
}
|
|
1263
|
+
/** Stream one large column of a row, creating it if absent, staged in this transaction. */
|
|
1264
|
+
upsertStreaming(table, id, data, options) {
|
|
1265
|
+
return this.streamingMutation("upsert", table, id, data, options);
|
|
1266
|
+
}
|
|
1267
|
+
streamingMutation(mutation, table, id, data, options) {
|
|
1268
|
+
assertWritableTable(table);
|
|
1269
|
+
this.bindTable(table);
|
|
1270
|
+
const client = this.resolveClient(table._schema);
|
|
1271
|
+
const operation = mutation === "insert" ? "Insert" : mutation === "update" ? "Update" : "Upsert";
|
|
1272
|
+
const { openTransactionId, session, attribution, preparation } = this.requireBinding(`${mutation}Streaming`);
|
|
1273
|
+
const { column, source, values: ordinaryData } = splitStreamingMutation(table, data);
|
|
1274
|
+
rejectIncompleteDependencies(table, ordinaryData, [column]);
|
|
1275
|
+
const rowId = id ??
|
|
1276
|
+
(missingWriteDependencies(table, ordinaryData).includes("id") ? reserveRowId() : undefined);
|
|
1277
|
+
const stage = async () => {
|
|
1278
|
+
const record = mutation === "insert"
|
|
1279
|
+
? transformInputColumns(table, ordinaryData, rowId ? { id: rowId } : {}, true)
|
|
1280
|
+
: await prepareInputColumns(table, ordinaryData, operation, rowId, client, session, undefined, normalizeViewOptions(table._schema, table._table, options));
|
|
1281
|
+
const values = toWriteRecordForOperation(operation, record, table._schema, table._table);
|
|
1282
|
+
const branch = mutation === "insert" ? deriveStreamingInsertBranch(table, ordinaryData) : undefined;
|
|
1283
|
+
const normalized = mutation === "insert"
|
|
1284
|
+
? normalizeSelectorOptions(table._schema, table._table, {
|
|
1285
|
+
...options,
|
|
1286
|
+
...(rowId ? { id: rowId } : {}),
|
|
1287
|
+
...(branch ? { branch } : {}),
|
|
1288
|
+
})
|
|
1289
|
+
: normalizeViewOptions(table._schema, table._table, options);
|
|
1290
|
+
return client.streamingMutationInTransaction(mutation, table._table, values, column, source, openTransactionId, normalized, session, attribution, rowId);
|
|
1291
|
+
};
|
|
1292
|
+
return Promise.resolve(preparation.run(() => runAfterPreparation(client, () => (preparation.cancelled ? undefined : stage())))).then((staged) => {
|
|
1293
|
+
if (!staged)
|
|
1294
|
+
throw new Error("Transaction was rolled back before the stream was staged");
|
|
1295
|
+
return staged;
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Insert a new row into a table.
|
|
214
1300
|
*
|
|
215
|
-
*
|
|
1301
|
+
* The insert is scoped to this transaction, and will only be globally visible
|
|
1302
|
+
* once it's committed.
|
|
216
1303
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
1304
|
+
insert(table, data, options) {
|
|
1305
|
+
assertWritableTable(table);
|
|
1306
|
+
this.bindTable(table);
|
|
1307
|
+
const client = this.resolveClient(table._schema);
|
|
1308
|
+
const { openTransactionId, session, attribution, preparation } = this.requireBinding("insert");
|
|
1309
|
+
let id = options?.id ?? (hasDependentTransforms(table) ? reserveRowId() : undefined);
|
|
1310
|
+
const { values, value } = this.prepareCreation(table, data, id, "Insert");
|
|
1311
|
+
if (!id && (preparation.pending || getOwnerPreparation(client)?.pending))
|
|
1312
|
+
id = reserveRowId();
|
|
1313
|
+
let row;
|
|
1314
|
+
const stage = () => {
|
|
1315
|
+
row = client.insertInternal(table._table, values, normalizeSelectorOptions(table._schema, table._table, id ? { ...options, id } : options), session, attribution, openTransactionId);
|
|
1316
|
+
};
|
|
1317
|
+
if (preparation.cancelled)
|
|
1318
|
+
stage();
|
|
1319
|
+
else
|
|
1320
|
+
preparation.run(() => runAfterPreparation(client, () => {
|
|
1321
|
+
if (!preparation.cancelled)
|
|
1322
|
+
stage();
|
|
1323
|
+
}));
|
|
222
1324
|
try {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
db.leaderElection = election;
|
|
228
|
-
election.start();
|
|
229
|
-
let initialLeader = null;
|
|
230
|
-
try {
|
|
231
|
-
// Allow at least one startup election window with default heartbeat settings.
|
|
232
|
-
initialLeader = await election.waitForInitialLeader(1600);
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
// Fall back to whatever state election has reached so far.
|
|
236
|
-
initialLeader = election.snapshot();
|
|
237
|
-
}
|
|
238
|
-
db.adoptLeaderSnapshot(initialLeader);
|
|
239
|
-
db.workerDbName = Db.resolveWorkerDbNameForSnapshot(db.primaryDbName, initialLeader);
|
|
240
|
-
db.logLeaderDebug("initial-election");
|
|
241
|
-
db.openSyncChannel();
|
|
242
|
-
db.attachLifecycleHooks();
|
|
243
|
-
db.leaderElectionUnsubscribe = election.onChange((snapshot) => {
|
|
244
|
-
db.onLeaderElectionChange(snapshot);
|
|
245
|
-
});
|
|
246
|
-
db.worker = await Db.spawnWorker();
|
|
247
|
-
return db;
|
|
1325
|
+
return (value ??
|
|
1326
|
+
(row
|
|
1327
|
+
? transformOutputRow(table, transformRow(row, table._schema, table._table))
|
|
1328
|
+
: immediateWriteRow(table, id, values)));
|
|
248
1329
|
}
|
|
249
1330
|
catch (error) {
|
|
250
|
-
|
|
251
|
-
db.detachLifecycleHooks();
|
|
252
|
-
if (db.leaderElectionUnsubscribe) {
|
|
253
|
-
db.leaderElectionUnsubscribe();
|
|
254
|
-
db.leaderElectionUnsubscribe = null;
|
|
255
|
-
}
|
|
256
|
-
if (db.leaderElection) {
|
|
257
|
-
db.leaderElection.stop();
|
|
258
|
-
db.leaderElection = null;
|
|
259
|
-
}
|
|
1331
|
+
preparation.failure = error;
|
|
260
1332
|
throw error;
|
|
261
1333
|
}
|
|
262
1334
|
}
|
|
263
1335
|
/**
|
|
264
|
-
*
|
|
265
|
-
* Synchronous because WASM module is pre-loaded.
|
|
1336
|
+
* Restore a soft-deleted row.
|
|
266
1337
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
1338
|
+
* The restore is scoped to this transaction, and will only be globally visible
|
|
1339
|
+
* once it's committed.
|
|
269
1340
|
*/
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.
|
|
1341
|
+
restore(table, id, data, options) {
|
|
1342
|
+
assertWritableTable(table);
|
|
1343
|
+
this.bindTable(table);
|
|
1344
|
+
const { values, value } = this.prepareCreation(table, data, id, "Restore");
|
|
1345
|
+
const client = this.resolveClient(table._schema);
|
|
1346
|
+
const { openTransactionId, session, attribution, preparation } = this.requireBinding("restore");
|
|
1347
|
+
const stage = () => {
|
|
1348
|
+
client.restoreInternal(table._table, id, values, normalizeSelectorOptions(table._schema, table._table, options), session, attribution, openTransactionId);
|
|
1349
|
+
};
|
|
1350
|
+
if (preparation.cancelled)
|
|
1351
|
+
stage();
|
|
1352
|
+
else
|
|
1353
|
+
preparation.run(() => runAfterPreparation(client, () => {
|
|
1354
|
+
if (!preparation.cancelled)
|
|
1355
|
+
stage();
|
|
1356
|
+
}));
|
|
1357
|
+
return value;
|
|
1358
|
+
}
|
|
1359
|
+
prepareCreation(table, data, id, operation) {
|
|
1360
|
+
let record;
|
|
1361
|
+
try {
|
|
1362
|
+
record = table._columnTransforms
|
|
1363
|
+
? transformInputColumns(table, data, id === undefined ? undefined : { id }, true)
|
|
1364
|
+
: data;
|
|
1365
|
+
}
|
|
1366
|
+
catch (error) {
|
|
1367
|
+
this.requireBinding(operation).preparation.failure = error;
|
|
1368
|
+
throw error;
|
|
1369
|
+
}
|
|
1370
|
+
const values = toWriteRecordForOperation(operation, record, table._schema, table._table);
|
|
1371
|
+
try {
|
|
1372
|
+
return {
|
|
1373
|
+
values,
|
|
1374
|
+
value: id === undefined ? undefined : immediateWriteRow(table, id, values),
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
catch (error) {
|
|
1378
|
+
this.requireBinding(operation).preparation.failure = error;
|
|
1379
|
+
throw error;
|
|
297
1380
|
}
|
|
298
|
-
return this.clients.get(key);
|
|
299
1381
|
}
|
|
300
1382
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
1383
|
+
* Create or update a row with a caller-supplied id.
|
|
1384
|
+
*
|
|
1385
|
+
* The upsert is scoped to this transaction, and will only be globally visible
|
|
1386
|
+
* once it's committed.
|
|
303
1387
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
1388
|
+
upsert(table, id, data, options) {
|
|
1389
|
+
assertWritableTable(table);
|
|
1390
|
+
this.bindTable(table);
|
|
1391
|
+
const client = this.resolveClient(table._schema);
|
|
1392
|
+
const { openTransactionId, session, attribution } = this.requireBinding("upsert");
|
|
1393
|
+
this.prepareMutation(table, id, data, "Upsert", options, (values) => {
|
|
1394
|
+
client.upsertInternal(table._table, id, values, normalizeViewOptions(table._schema, table._table, options), session, attribution, openTransactionId);
|
|
1395
|
+
});
|
|
309
1396
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
this.
|
|
316
|
-
|
|
317
|
-
|
|
1397
|
+
update(table, id, data, options) {
|
|
1398
|
+
assertWritableTable(table);
|
|
1399
|
+
this.bindTable(table);
|
|
1400
|
+
const { replacements, descriptors } = lowerUpdate(table, data, options);
|
|
1401
|
+
options = withoutEditedFrom(options);
|
|
1402
|
+
const client = this.resolveClient(table._schema);
|
|
1403
|
+
const { openTransactionId, session, attribution } = this.requireBinding("update");
|
|
1404
|
+
const normalizedOptions = normalizeViewOptions(table._schema, table._table, options);
|
|
1405
|
+
this.prepareMutation(table, id, replacements, "Update", options, (updates) => {
|
|
1406
|
+
if (descriptors.length > 0) {
|
|
1407
|
+
client.updateLargeValuesInternal(table._table, id, updates, descriptors, normalizedOptions?.updatedAt, session, attribution, openTransactionId, normalizedOptions?.branch);
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
client.updateInternal(table._table, id, updates, normalizedOptions?.updatedAt, session, attribution, openTransactionId, normalizedOptions?.branch);
|
|
318
1411
|
});
|
|
319
|
-
this.applyBridgeRoutingForCurrentLeader(bridge, false);
|
|
320
|
-
this.workerBridge = bridge;
|
|
321
|
-
this.bridgeReady = bridge.init(this.buildWorkerBridgeOptions(schemaJson)).then(() => undefined);
|
|
322
1412
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
serverPathPrefix: this.config.serverPathPrefix,
|
|
332
|
-
jwtToken: this.config.jwtToken,
|
|
333
|
-
localAuthMode: this.config.localAuthMode,
|
|
334
|
-
localAuthToken: this.config.localAuthToken,
|
|
335
|
-
adminSecret: this.config.adminSecret,
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
adoptLeaderSnapshot(snapshot) {
|
|
339
|
-
this.tabRole = snapshot.role;
|
|
340
|
-
this.tabId = snapshot.tabId;
|
|
341
|
-
this.currentLeaderTabId = snapshot.leaderTabId;
|
|
342
|
-
this.currentLeaderTerm = snapshot.term;
|
|
343
|
-
}
|
|
344
|
-
openSyncChannel() {
|
|
345
|
-
if (this.syncChannel || !this.primaryDbName)
|
|
346
|
-
return;
|
|
347
|
-
const ChannelCtor = resolveBroadcastChannelCtor();
|
|
348
|
-
if (!ChannelCtor) {
|
|
349
|
-
this.logLeaderDebug("sync-channel-unavailable");
|
|
1413
|
+
prepareMutation(table, id, data, operation, options, stage) {
|
|
1414
|
+
const { ownerClient, openTransactionId, preparation } = this.requireBinding(operation);
|
|
1415
|
+
if (preparation.pending ||
|
|
1416
|
+
getOwnerPreparation(ownerClient)?.pending ||
|
|
1417
|
+
missingWriteDependencies(table, data, id).length)
|
|
1418
|
+
data = { ...data };
|
|
1419
|
+
if (preparation.cancelled) {
|
|
1420
|
+
stage({});
|
|
350
1421
|
return;
|
|
351
1422
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
1423
|
+
preparation.run(() => runAfterPreparation(ownerClient, () => {
|
|
1424
|
+
if (preparation.cancelled)
|
|
1425
|
+
return;
|
|
1426
|
+
let prepared;
|
|
1427
|
+
try {
|
|
1428
|
+
prepared = prepareInputColumns(table, data, operation, id, ownerClient, this.context?.readSession, openTransactionId, normalizeViewOptions(table._schema, table._table, options));
|
|
1429
|
+
}
|
|
1430
|
+
catch (error) {
|
|
1431
|
+
preparation.failure = error;
|
|
1432
|
+
throw error;
|
|
1433
|
+
}
|
|
1434
|
+
const finish = (record) => {
|
|
1435
|
+
if (preparation.cancelled)
|
|
1436
|
+
return;
|
|
1437
|
+
if (preparation.failed)
|
|
1438
|
+
throw preparation.failure;
|
|
1439
|
+
const values = toWriteRecordForOperation(operation, record, table._schema, table._table);
|
|
1440
|
+
stage(values);
|
|
1441
|
+
};
|
|
1442
|
+
return prepared instanceof Promise ? prepared.then(finish) : finish(prepared);
|
|
1443
|
+
}));
|
|
358
1444
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
1445
|
+
/**
|
|
1446
|
+
* Delete an existing row from a table.
|
|
1447
|
+
*
|
|
1448
|
+
* The delete is scoped to this transaction, and will only be globally visible
|
|
1449
|
+
* once it's committed.
|
|
1450
|
+
*/
|
|
1451
|
+
delete(table, id, options) {
|
|
1452
|
+
assertWritableTable(table);
|
|
1453
|
+
this.bindTable(table);
|
|
1454
|
+
const client = this.resolveClient(table._schema);
|
|
1455
|
+
const { openTransactionId, session, attribution, preparation } = this.requireBinding("delete");
|
|
1456
|
+
const normalizedOptions = normalizeViewOptions(table._schema, table._table, options);
|
|
1457
|
+
const stage = () => {
|
|
1458
|
+
client.deleteInternal(table._table, id, normalizedOptions?.updatedAt, session, attribution, openTransactionId, normalizedOptions?.branch);
|
|
1459
|
+
};
|
|
1460
|
+
if (preparation.cancelled)
|
|
1461
|
+
stage();
|
|
1462
|
+
else
|
|
1463
|
+
preparation.run(() => runAfterPreparation(client, () => {
|
|
1464
|
+
if (!preparation.cancelled)
|
|
1465
|
+
stage();
|
|
1466
|
+
}));
|
|
366
1467
|
}
|
|
367
|
-
|
|
368
|
-
|
|
1468
|
+
/**
|
|
1469
|
+
* Execute a query and return all matching rows.
|
|
1470
|
+
*
|
|
1471
|
+
* Read data is scoped to this transaction.
|
|
1472
|
+
*/
|
|
1473
|
+
all(query, options) {
|
|
1474
|
+
const reading = this.readAll(query, options);
|
|
1475
|
+
this.pendingReads.add(reading);
|
|
1476
|
+
const settled = () => this.pendingReads.delete(reading);
|
|
1477
|
+
reading.then(settled, settled);
|
|
1478
|
+
return reading;
|
|
369
1479
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (this.isShuttingDown || !this.worker)
|
|
395
|
-
return;
|
|
396
|
-
this.logLeaderDebug("lifecycle-hint", { event });
|
|
397
|
-
if (this.workerBridge) {
|
|
398
|
-
this.workerBridge.sendLifecycleHint(event);
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
this.worker.postMessage({
|
|
402
|
-
type: "lifecycle-hint",
|
|
403
|
-
event,
|
|
404
|
-
sentAtMs: Date.now(),
|
|
405
|
-
});
|
|
1480
|
+
async readAll(query, options) {
|
|
1481
|
+
this.bindQuery(query);
|
|
1482
|
+
const { preparation, openTransactionId } = this.requireBinding("query");
|
|
1483
|
+
if (preparation.pending || preparation.failed)
|
|
1484
|
+
await preparation.drain();
|
|
1485
|
+
const client = this.resolveClient(query._schema);
|
|
1486
|
+
const builderJson = query._build();
|
|
1487
|
+
const builtQuery = normalizeBuiltQuery(JSON.parse(builderJson));
|
|
1488
|
+
const planningSchema = requireSchemaWithTable(query._schema, builtQuery.table);
|
|
1489
|
+
const outputTable = resolveQueryOutputTable(planningSchema, builtQuery);
|
|
1490
|
+
const prepared = prepareTransformRead(query, builtQuery, outputTable);
|
|
1491
|
+
// Transactions accept the same public options surface as Db. Lower before
|
|
1492
|
+
// reaching native options so JavaScript callers cannot smuggle runtime
|
|
1493
|
+
// controls (for example `localUpdates` or `openTransactionId`) through this
|
|
1494
|
+
// otherwise separate execution path.
|
|
1495
|
+
const queryOptions = normalizeViewOptions(query._schema, builtQuery.table, lowerPublicDbQueryOptions(options)) ??
|
|
1496
|
+
{};
|
|
1497
|
+
const rows = await client.queryInternal(translateQuery(builderJson, planningSchema, prepared.physical), {
|
|
1498
|
+
...queryOptions,
|
|
1499
|
+
openTransactionId,
|
|
1500
|
+
}, this.context?.readSession);
|
|
1501
|
+
if (!prepared.computedState)
|
|
1502
|
+
return rows.map(prepared.transform);
|
|
1503
|
+
return finishComputedRead(query, builtQuery, outputTable, prepared, rows, (physical) => client.queryInternal(translateQuery(builderJson, planningSchema, physical), { ...queryOptions, openTransactionId }, this.context?.readSession));
|
|
406
1504
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
1505
|
+
/**
|
|
1506
|
+
* Execute a query with a limit of one and return the first matching row, or null.
|
|
1507
|
+
*
|
|
1508
|
+
* Read data is scoped to this transaction.
|
|
1509
|
+
*/
|
|
1510
|
+
async one(query, options) {
|
|
1511
|
+
const results = await this.all(limitQueryToOne(query), options);
|
|
1512
|
+
return results[0] ?? null;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
/** @internal The compiler opts in before staging any operations. */
|
|
1516
|
+
export function beginDbTransactionAfter(db, prepare) {
|
|
1517
|
+
return db.createTransaction("serializable", prepare);
|
|
1518
|
+
}
|
|
1519
|
+
export class Db {
|
|
1520
|
+
config;
|
|
1521
|
+
runtimeSource;
|
|
1522
|
+
authStateStore;
|
|
1523
|
+
connection;
|
|
1524
|
+
_localFirstSecret = null;
|
|
1525
|
+
localFirstRefreshOwned = false;
|
|
1526
|
+
localFirstRenewals = new AuthRenewalBackoff();
|
|
1527
|
+
localFirstRefreshTimer = null;
|
|
1528
|
+
shutdownPromise = null;
|
|
1529
|
+
/** Set once the session that owned this Db moved on to another one. */
|
|
1530
|
+
replaced = null;
|
|
1531
|
+
/** Ends each live subscription with a terminal error. */
|
|
1532
|
+
liveSubscriptionEnders = new Set();
|
|
1533
|
+
/** The Db this one hands its work to after the local-first upgrade. */
|
|
1534
|
+
successor = null;
|
|
1535
|
+
/** Queries and listeners that move to the successor with the upgrade. */
|
|
1536
|
+
movable = new Set();
|
|
1537
|
+
shutdownAbort = new AbortController();
|
|
1538
|
+
syncStatusSnapshot = null;
|
|
1539
|
+
activeQuerySubscriptionTraces = new Map();
|
|
1540
|
+
activeQuerySubscriptionTraceListeners = new Set();
|
|
1541
|
+
mutationErrorListeners = new Set();
|
|
1542
|
+
pendingMutationErrorEvents = [];
|
|
1543
|
+
nextActiveQuerySubscriptionTraceId = 1;
|
|
1544
|
+
#authenticatedInspectorPhysicalDbName = null;
|
|
1545
|
+
/**
|
|
1546
|
+
* Protected constructor - use {@link createDb} in regular app code.
|
|
1547
|
+
*/
|
|
1548
|
+
constructor(config, runtimeSource, authStateOptions) {
|
|
1549
|
+
assertAccountConfig(config);
|
|
1550
|
+
this.config = config;
|
|
1551
|
+
this.runtimeSource = runtimeSource;
|
|
1552
|
+
const sessionInput = {
|
|
1553
|
+
...config,
|
|
1554
|
+
trustedReservedSession: getTrustedReservedSession(config),
|
|
1555
|
+
};
|
|
1556
|
+
setDbInternalSession(this, resolveClientInternalSessionSync(sessionInput));
|
|
1557
|
+
this.authStateStore = createAuthStateStore(sessionInput, authStateOptions);
|
|
1558
|
+
this.connection = new DirectConnectionManager(this.dbForConnection());
|
|
1559
|
+
// An overlay peer gets its port only through the authenticated Inspector
|
|
1560
|
+
// control handoff. Keep the resulting read policy inside this source: the
|
|
1561
|
+
// Inspector UI uses ordinary `useAll`, while no application-facing option
|
|
1562
|
+
// or package export can manufacture local-only reads.
|
|
1563
|
+
const inspectorAttachmentRequested = config.runtimeSources?.browserWorkerPort !== undefined &&
|
|
1564
|
+
config.runtimeSources.inspectorHostPhysicalDbName !== undefined;
|
|
1565
|
+
dbSubscriptionSources.set(this, {
|
|
1566
|
+
// Cache identity is reserved before the async worker receipt arrives so
|
|
1567
|
+
// an Inspector entry can never share a host application's query cache.
|
|
1568
|
+
// This marker is not authority: execution below strips it unless the
|
|
1569
|
+
// worker subsequently authenticates this attachment.
|
|
1570
|
+
...(inspectorAttachmentRequested
|
|
1571
|
+
? {
|
|
1572
|
+
prepareQueryOptions: (options) => createInspectorLocalQueryOptions(options),
|
|
1573
|
+
}
|
|
1574
|
+
: {}),
|
|
1575
|
+
all: (query, options) => inspectorAttachmentRequested
|
|
1576
|
+
? this.allFromInspectorAttachment(query, options)
|
|
1577
|
+
: this.allInternal(query, lowerPublicDbQueryOptions(options)),
|
|
1578
|
+
subscribeDelta: (query, callback, options) => inspectorAttachmentRequested
|
|
1579
|
+
? this.subscribeFromInspectorAttachment(query, callback, options)
|
|
1580
|
+
: this.subscribeDelta(query, callback, lowerPublicDbQueryOptions(options)),
|
|
417
1581
|
});
|
|
418
1582
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
1583
|
+
dbForConnection() {
|
|
1584
|
+
// oxlint-disable-next-line typescript/no-this-alias
|
|
1585
|
+
const thisDb = this;
|
|
1586
|
+
return {
|
|
1587
|
+
get config() {
|
|
1588
|
+
return thisDb.config;
|
|
1589
|
+
},
|
|
1590
|
+
get runtimeSource() {
|
|
1591
|
+
return thisDb.runtimeSource;
|
|
1592
|
+
},
|
|
1593
|
+
get isShuttingDown() {
|
|
1594
|
+
return thisDb.shutdownPromise !== null;
|
|
1595
|
+
},
|
|
1596
|
+
markUnauthenticated: (reason) => this.markUnauthenticated(reason),
|
|
1597
|
+
renewsCredential: (reason) => (credentialRenewers.get(this) ?? 0) > 0 ||
|
|
1598
|
+
(reason === "expired" && this.localFirstRefreshOwned),
|
|
1599
|
+
clearAuthError: () => this.authStateStore.clearError(),
|
|
1600
|
+
onMutationError: (event) => this.handleMutationError(event),
|
|
1601
|
+
enableAuthenticatedInspectorLocalReads: (physicalDbName) => this.#enableAuthenticatedInspectorLocalReads(physicalDbName),
|
|
1602
|
+
clearAuthenticatedInspectorLocalReads: () => this.#clearAuthenticatedInspectorLocalReads(),
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
#enableAuthenticatedInspectorLocalReads(physicalDbName) {
|
|
1606
|
+
// The configured coordinate is only selection metadata. It becomes
|
|
1607
|
+
// authority only when the worker returns this exact root in the init
|
|
1608
|
+
// receipt for a peer it created through Inspector control.
|
|
1609
|
+
if (this.config.runtimeSources?.inspectorHostPhysicalDbName !== physicalDbName)
|
|
423
1610
|
return;
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
1611
|
+
this.#authenticatedInspectorPhysicalDbName = physicalDbName;
|
|
1612
|
+
}
|
|
1613
|
+
#clearAuthenticatedInspectorLocalReads() {
|
|
1614
|
+
this.#authenticatedInspectorPhysicalDbName = null;
|
|
1615
|
+
}
|
|
1616
|
+
async inspectorAttachmentOptions(query, options) {
|
|
1617
|
+
// Client construction starts the follower's init handshake. Do not decide
|
|
1618
|
+
// the read tier from config/MessagePort shape: wait for the worker receipt.
|
|
1619
|
+
this.getClient(query._schema);
|
|
1620
|
+
await this.connection.ensureReady("runtime");
|
|
1621
|
+
const selectedOptions = this.#authenticatedInspectorPhysicalDbName
|
|
1622
|
+
? createInspectorLocalQueryOptions(options)
|
|
1623
|
+
: // Drop a source's cache-only marker when the worker did not issue an
|
|
1624
|
+
// Inspector receipt. Symbols are deliberately non-enumerable.
|
|
1625
|
+
options && { ...options };
|
|
1626
|
+
return lowerPublicDbQueryOptions(selectedOptions) ?? {};
|
|
1627
|
+
}
|
|
1628
|
+
async allFromInspectorAttachment(query, options) {
|
|
1629
|
+
return this.allInternal(query, await this.inspectorAttachmentOptions(query, options));
|
|
1630
|
+
}
|
|
1631
|
+
subscribeFromInspectorAttachment(query, callback, options) {
|
|
1632
|
+
let inner = null;
|
|
1633
|
+
let cancelled = false;
|
|
1634
|
+
const ready = this.inspectorAttachmentOptions(query, options).then((prepared) => {
|
|
1635
|
+
if (cancelled)
|
|
433
1636
|
return;
|
|
1637
|
+
inner = this.subscribeDelta(query, callback, prepared);
|
|
1638
|
+
return inner.ready;
|
|
1639
|
+
});
|
|
1640
|
+
const handle = (() => {
|
|
1641
|
+
cancelled = true;
|
|
1642
|
+
inner?.();
|
|
1643
|
+
});
|
|
1644
|
+
Object.defineProperty(handle, "ready", { value: ready });
|
|
1645
|
+
return handle;
|
|
1646
|
+
}
|
|
1647
|
+
/** @internal Store the seed used for local-first auth and optionally schedule token refresh. */
|
|
1648
|
+
initLocalFirstAuth(seed, ttlSeconds, refresh = true) {
|
|
1649
|
+
this._localFirstSecret = seed;
|
|
1650
|
+
this.localFirstRefreshOwned = refresh;
|
|
1651
|
+
if (refresh) {
|
|
1652
|
+
this.scheduleLocalFirstRefresh(ttlSeconds);
|
|
434
1653
|
}
|
|
435
1654
|
}
|
|
436
|
-
|
|
437
|
-
if (this.
|
|
438
|
-
|
|
439
|
-
if (!this.workerBridge)
|
|
440
|
-
return;
|
|
441
|
-
if (!this.tabId || message.toLeaderTabId !== this.tabId)
|
|
442
|
-
return;
|
|
443
|
-
if (message.term !== this.currentLeaderTerm)
|
|
444
|
-
return;
|
|
445
|
-
if (!this.leaderPeerIds.has(message.fromTabId)) {
|
|
446
|
-
this.leaderPeerIds.add(message.fromTabId);
|
|
447
|
-
this.workerBridge.openPeer(message.fromTabId);
|
|
448
|
-
this.logLeaderDebug("peer-open", {
|
|
449
|
-
peerId: message.fromTabId,
|
|
450
|
-
});
|
|
1655
|
+
scheduleLocalFirstRefresh(ttlSeconds) {
|
|
1656
|
+
if (this.localFirstRefreshTimer) {
|
|
1657
|
+
clearTimeout(this.localFirstRefreshTimer);
|
|
451
1658
|
}
|
|
452
|
-
|
|
1659
|
+
// Refresh at 80% of TTL
|
|
1660
|
+
const refreshMs = ttlSeconds * 800; // 80% of TTL in ms
|
|
1661
|
+
this.localFirstRefreshTimer = setTimeout(() => {
|
|
1662
|
+
// The token lived to its scheduled refresh, so earlier renewals took.
|
|
1663
|
+
this.localFirstRenewals.reset();
|
|
1664
|
+
this.refreshLocalFirstToken();
|
|
1665
|
+
}, refreshMs);
|
|
453
1666
|
}
|
|
454
|
-
|
|
455
|
-
if (this.
|
|
456
|
-
return;
|
|
457
|
-
if (!this.workerBridge)
|
|
458
|
-
return;
|
|
459
|
-
if (!this.tabId || message.toTabId !== this.tabId)
|
|
1667
|
+
refreshLocalFirstToken() {
|
|
1668
|
+
if (!this._localFirstSecret || this.shutdownPromise)
|
|
460
1669
|
return;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
1670
|
+
try {
|
|
1671
|
+
const ttlSeconds = 3600;
|
|
1672
|
+
const newToken = this.mintLocalFirstToken(this._localFirstSecret, clientScope(this.config), ttlSeconds);
|
|
1673
|
+
const trustedReservedSession = internalSessionFromVerifiedReservedJwtPayload(parseJwtPayload(newToken) ?? {}, "local-first");
|
|
1674
|
+
if (!trustedReservedSession) {
|
|
1675
|
+
throw new Error("Minted local-first token is missing its reserved session identity");
|
|
1676
|
+
}
|
|
1677
|
+
this.applyAuthUpdate(newToken, trustedReservedSession);
|
|
1678
|
+
this.scheduleLocalFirstRefresh(ttlSeconds);
|
|
1679
|
+
}
|
|
1680
|
+
catch (e) {
|
|
1681
|
+
console.error("Failed to refresh local-first token:", e);
|
|
467
1682
|
}
|
|
468
1683
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return;
|
|
476
|
-
if (message.term !== this.currentLeaderTerm)
|
|
477
|
-
return;
|
|
478
|
-
if (!this.leaderPeerIds.has(message.fromTabId))
|
|
479
|
-
return;
|
|
480
|
-
this.leaderPeerIds.delete(message.fromTabId);
|
|
481
|
-
this.workerBridge.closePeer(message.fromTabId);
|
|
482
|
-
this.logLeaderDebug("peer-close", {
|
|
483
|
-
peerId: message.fromTabId,
|
|
1684
|
+
mintLocalFirstToken(secret, audience, ttlSeconds) {
|
|
1685
|
+
return this.runtimeSource.mintLocalFirstToken({
|
|
1686
|
+
secret,
|
|
1687
|
+
audience,
|
|
1688
|
+
ttlSeconds,
|
|
1689
|
+
nowSeconds: BigInt(Math.floor(Date.now() / 1000)),
|
|
484
1690
|
});
|
|
485
1691
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
1692
|
+
markUnauthenticated(reason) {
|
|
1693
|
+
try {
|
|
1694
|
+
this.authStateStore.markUnauthenticated(reason);
|
|
1695
|
+
}
|
|
1696
|
+
finally {
|
|
1697
|
+
// Observer failures must not skip renewal of an owned local-first token.
|
|
1698
|
+
if (reason === "expired" && this.localFirstRefreshOwned)
|
|
1699
|
+
this.renewExpiredLocalFirstToken();
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
renewExpiredLocalFirstToken() {
|
|
1703
|
+
const delay = this.localFirstRenewals.next();
|
|
1704
|
+
if (delay === 0) {
|
|
1705
|
+
this.refreshLocalFirstToken();
|
|
494
1706
|
return;
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
1707
|
+
}
|
|
1708
|
+
if (this.localFirstRefreshTimer)
|
|
1709
|
+
clearTimeout(this.localFirstRefreshTimer);
|
|
1710
|
+
this.localFirstRefreshTimer = setTimeout(() => this.refreshLocalFirstToken(), delay);
|
|
1711
|
+
}
|
|
1712
|
+
publishAuthStateWithInternalSession(nextSession, publish) {
|
|
1713
|
+
// Commit every snapshot before notifying observers. Observer failures are
|
|
1714
|
+
// reported to the caller without rolling back into a split snapshot.
|
|
1715
|
+
setDbInternalSession(this, nextSession);
|
|
1716
|
+
publish();
|
|
1717
|
+
}
|
|
1718
|
+
applyAuthUpdate(token, trustedReservedSession) {
|
|
1719
|
+
this.runtimeSource.assertAuthUpdateAllowed();
|
|
1720
|
+
const jwtToken = token ?? undefined;
|
|
1721
|
+
const previousToken = this.config.jwtToken;
|
|
1722
|
+
const previousCookieSession = this.config.cookieSession;
|
|
1723
|
+
const previousTrustedReservedSession = getTrustedReservedSession(this.config);
|
|
1724
|
+
const credentialsChanged = previousToken !== jwtToken ||
|
|
1725
|
+
previousCookieSession !== undefined ||
|
|
1726
|
+
JSON.stringify(previousTrustedReservedSession) !== JSON.stringify(trustedReservedSession);
|
|
1727
|
+
if (!credentialsChanged && this.authStateStore.getState().error === undefined)
|
|
1728
|
+
return false;
|
|
1729
|
+
if (!this.authStateStore.validateJwtToken(jwtToken, trustedReservedSession))
|
|
1730
|
+
return false;
|
|
1731
|
+
this.connection.updateAuth({
|
|
1732
|
+
mode: "bearer",
|
|
1733
|
+
jwtToken,
|
|
1734
|
+
trustedReservedSession,
|
|
501
1735
|
});
|
|
1736
|
+
this.publishAuthUpdate(jwtToken, trustedReservedSession);
|
|
1737
|
+
return true;
|
|
502
1738
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
1739
|
+
publishAuthUpdate(jwtToken, trustedReservedSession) {
|
|
1740
|
+
const nextConfig = {
|
|
1741
|
+
...this.config,
|
|
1742
|
+
jwtToken,
|
|
1743
|
+
cookieSession: undefined,
|
|
1744
|
+
};
|
|
1745
|
+
setTrustedReservedSession(nextConfig, trustedReservedSession);
|
|
1746
|
+
const nextInternalSession = resolveClientInternalSessionSync(nextConfig);
|
|
1747
|
+
this.config.jwtToken = jwtToken;
|
|
1748
|
+
this.config.cookieSession = undefined;
|
|
1749
|
+
setTrustedReservedSession(this.config, trustedReservedSession);
|
|
1750
|
+
this.publishAuthStateWithInternalSession(nextInternalSession, () => {
|
|
1751
|
+
this.authStateStore.applyJwtToken(jwtToken, trustedReservedSession);
|
|
511
1752
|
});
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
1753
|
+
}
|
|
1754
|
+
applyCookieSessionUpdate(session) {
|
|
1755
|
+
this.runtimeSource.assertAuthUpdateAllowed();
|
|
1756
|
+
const cookieSession = session ?? undefined;
|
|
1757
|
+
const previousCookieSession = this.config.cookieSession;
|
|
1758
|
+
const previousToken = this.config.jwtToken;
|
|
1759
|
+
const previousTrustedReservedSession = getTrustedReservedSession(this.config);
|
|
1760
|
+
const sessionChanged = JSON.stringify(previousCookieSession) !== JSON.stringify(cookieSession);
|
|
1761
|
+
const credentialsChanged = previousToken !== undefined || sessionChanged || previousTrustedReservedSession !== undefined;
|
|
1762
|
+
if (!credentialsChanged && this.authStateStore.getState().error === undefined)
|
|
1763
|
+
return false;
|
|
1764
|
+
if (!this.authStateStore.validateCookieSession(cookieSession))
|
|
1765
|
+
return false;
|
|
1766
|
+
this.connection.updateAuth({ mode: "cookie", cookieSession });
|
|
1767
|
+
const nextConfig = {
|
|
1768
|
+
...this.config,
|
|
1769
|
+
jwtToken: undefined,
|
|
1770
|
+
cookieSession,
|
|
1771
|
+
};
|
|
1772
|
+
const nextInternalSession = resolveClientInternalSessionSync(nextConfig);
|
|
1773
|
+
this.config.jwtToken = undefined;
|
|
1774
|
+
this.config.cookieSession = cookieSession;
|
|
1775
|
+
setTrustedReservedSession(this.config, undefined);
|
|
1776
|
+
this.publishAuthStateWithInternalSession(nextInternalSession, () => {
|
|
1777
|
+
this.authStateStore.applyCookieSession(cookieSession);
|
|
517
1778
|
});
|
|
1779
|
+
return true;
|
|
518
1780
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
1781
|
+
/**
|
|
1782
|
+
* Create a Db instance with a loaded runtime source.
|
|
1783
|
+
* @internal Use {@link createDb()} instead.
|
|
1784
|
+
*/
|
|
1785
|
+
static create(config, runtimeSource) {
|
|
1786
|
+
return new Db(config, runtimeSource);
|
|
1787
|
+
}
|
|
1788
|
+
/** @internal Create a direct Db after its pre-runtime identity bootstrap. */
|
|
1789
|
+
static async createWithDirectConnection(config, runtimeSource) {
|
|
1790
|
+
const db = new Db(config, runtimeSource);
|
|
1791
|
+
await db.connection.start();
|
|
1792
|
+
return db;
|
|
1793
|
+
}
|
|
1794
|
+
/** @internal Create a Db whose durable peer lives in a dedicated browser worker. */
|
|
1795
|
+
static async createWithBrowserWorker(config, runtimeSource, earlyLease) {
|
|
1796
|
+
const db = new Db(config, runtimeSource);
|
|
1797
|
+
const connection = new BrowserConnectionManager(db.dbForConnection(), earlyLease);
|
|
1798
|
+
db.connection = connection;
|
|
1799
|
+
await connection.start();
|
|
1800
|
+
return db;
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* Get or create a JazzClient for the given schema.
|
|
1804
|
+
* Synchronous because the runtime source is loaded before Db is created.
|
|
1805
|
+
*
|
|
1806
|
+
*/
|
|
1807
|
+
getClient(schema) {
|
|
1808
|
+
this.assertOpen();
|
|
1809
|
+
return this.connection.getClient(schema);
|
|
1810
|
+
}
|
|
1811
|
+
getCurrentClient() {
|
|
1812
|
+
return this.connection.getCurrentClient();
|
|
1813
|
+
}
|
|
1814
|
+
/** @internal The runtime behind this Db's client, once it exists. */
|
|
1815
|
+
currentRuntime() {
|
|
1816
|
+
return this.getCurrentClient()?.getRuntime() ?? null;
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* @internal Read each runtime query at the remote tier, so that this Db's
|
|
1820
|
+
* store holds what the server holds for it before anything subscribes.
|
|
1821
|
+
*/
|
|
1822
|
+
async prefetchRuntimeQueries(schema, queryJsons) {
|
|
1823
|
+
const client = this.getClient(schema);
|
|
1824
|
+
await this.ensureReady("server");
|
|
1825
|
+
await Promise.all(queryJsons.map((queryJson) => client.query(queryJson, { tier: "remote" })));
|
|
1826
|
+
}
|
|
1827
|
+
async ensureReady(requirement, signal) {
|
|
1828
|
+
await this.connection.ensureReady(requirement, signal ?? this.shutdownAbort.signal);
|
|
1829
|
+
this.assertOpen();
|
|
1830
|
+
}
|
|
1831
|
+
wrapWriteWait(handle) {
|
|
1832
|
+
notifyLocalWrite(this);
|
|
1833
|
+
return setWriteWaitReadiness(handle, async (tier) => {
|
|
1834
|
+
// A write made before this Db handed over to a successor waits on its
|
|
1835
|
+
// own runtime's last uploads, which the drain keeps going.
|
|
1836
|
+
if (this.drain)
|
|
1837
|
+
return;
|
|
1838
|
+
await this.ensureReady(tier === "global" ? "upload" : "runtime");
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
getAccessContext() {
|
|
1842
|
+
// Ordinary Dbs use the client's session. BackendDb overrides this to supply
|
|
1843
|
+
// per-Db session and attribution without changing the shared client's identity.
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
handleMutationError(event, logged = false) {
|
|
1847
|
+
// A write this Db took before the upgrade, rejected while it uploads:
|
|
1848
|
+
// the app's listeners are on the successor now.
|
|
1849
|
+
if (this.successor)
|
|
1850
|
+
return this.successor.handleMutationError(event, logged);
|
|
1851
|
+
if (this.mutationErrorListeners.size === 0) {
|
|
1852
|
+
if (!logged)
|
|
1853
|
+
console.error("Unhandled Jazz mutation error", event);
|
|
1854
|
+
this.pendingMutationErrorEvents.push(event);
|
|
1855
|
+
return;
|
|
526
1856
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
1857
|
+
for (const listener of this.mutationErrorListeners) {
|
|
1858
|
+
listener(event);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
/** @internal Refresh only through the immutable handle that owns this context. */
|
|
1862
|
+
async refreshAccountAuth(account) {
|
|
1863
|
+
return this.refreshOwnAccountAuth(account);
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* @internal Renew this Db's own runtime's credential. Its account context
|
|
1867
|
+
* calls this rather than {@link refreshAccountAuth}, which after the
|
|
1868
|
+
* local-first upgrade renews the successor: the thin runtime still needs
|
|
1869
|
+
* its own credential to finish uploading.
|
|
1870
|
+
*/
|
|
1871
|
+
async refreshOwnAccountAuth(account) {
|
|
1872
|
+
assertAccountConfig(this.config);
|
|
1873
|
+
const current = getDbInternalSession(this);
|
|
1874
|
+
if (account.id !== this.config.accountId ||
|
|
1875
|
+
accountRegistry(account) !== this.config.accountRegistryAuthority ||
|
|
1876
|
+
account.identity.issuer !== current?.issuer ||
|
|
1877
|
+
account.identity.subject !== current?.user_id)
|
|
1878
|
+
throw new Error("Account context mismatch");
|
|
1879
|
+
try {
|
|
1880
|
+
const token = await accountToken(account, accountRegistry(account));
|
|
1881
|
+
if (this.shutdownAbort.signal.aborted)
|
|
1882
|
+
throw new Error("Account context closed");
|
|
1883
|
+
const reserved = account.identity.issuer === "urn:jazz:local-first"
|
|
1884
|
+
? internalSessionFromVerifiedReservedJwtPayload(parseJwtPayload(token) ?? {}, "local-first")
|
|
1885
|
+
: undefined;
|
|
1886
|
+
if (!this.authStateStore.validateJwtToken(token, reserved ?? undefined))
|
|
1887
|
+
return token;
|
|
1888
|
+
this.connection.refreshAccountAuth(token, reserved ?? undefined);
|
|
1889
|
+
this.publishAuthUpdate(token, reserved ?? undefined);
|
|
1890
|
+
return token;
|
|
546
1891
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
1892
|
+
catch (error) {
|
|
1893
|
+
this.markUnauthenticated("invalid");
|
|
1894
|
+
throw error;
|
|
550
1895
|
}
|
|
551
1896
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
this.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
1897
|
+
updateAuthToken(jwtToken) {
|
|
1898
|
+
this.applyAuthUpdate(jwtToken);
|
|
1899
|
+
}
|
|
1900
|
+
updateCookieSession(cookieSession) {
|
|
1901
|
+
this.applyCookieSessionUpdate(cookieSession);
|
|
1902
|
+
}
|
|
1903
|
+
getAuthState() {
|
|
1904
|
+
return this.authStateStore.getState();
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Mint a short-lived local-first JWT proving possession of the current identity.
|
|
1908
|
+
* Returns `null` if the current session is not local-first.
|
|
1909
|
+
*/
|
|
1910
|
+
getLocalFirstIdentityProof(options) {
|
|
1911
|
+
if (!this._localFirstSecret) {
|
|
1912
|
+
return null;
|
|
1913
|
+
}
|
|
1914
|
+
const ttl = options?.ttlSeconds ?? 60;
|
|
1915
|
+
const audience = options?.audience ?? clientScope(this.config);
|
|
1916
|
+
return this.mintLocalFirstToken(this._localFirstSecret, audience, ttl);
|
|
1917
|
+
}
|
|
1918
|
+
/** @internal This Db's own runtime's auth state changes, which never move to a successor. */
|
|
1919
|
+
onOwnAuthChanged(listener) {
|
|
1920
|
+
return this.authStateStore.onChange((state) => listener(state));
|
|
1921
|
+
}
|
|
1922
|
+
onAuthChanged(listener) {
|
|
1923
|
+
return this.registerMovable((db) => db.authStateStore.onChange((state) => {
|
|
1924
|
+
listener(state);
|
|
1925
|
+
}));
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Register something on this Db that moves to its successor when the
|
|
1929
|
+
* session upgrades it to the local-first client, so code holding the
|
|
1930
|
+
* returned handle keeps hearing from whichever Db does the work.
|
|
1931
|
+
*/
|
|
1932
|
+
registerMovable(register,
|
|
1933
|
+
// Register again on this Db rather than on its successor: for what this
|
|
1934
|
+
// Db answers itself after the upgrade (its sync status covers the writes
|
|
1935
|
+
// its own runtime is still uploading).
|
|
1936
|
+
reregisterHere = false) {
|
|
1937
|
+
let detach = register(this);
|
|
1938
|
+
let closed = false;
|
|
1939
|
+
const entry = {
|
|
1940
|
+
move: (next) => {
|
|
1941
|
+
if (closed)
|
|
1942
|
+
return;
|
|
1943
|
+
detach();
|
|
1944
|
+
detach = reregisterHere ? register(this) : next.registerMovable(register);
|
|
1945
|
+
},
|
|
1946
|
+
};
|
|
1947
|
+
this.movable.add(entry);
|
|
1948
|
+
return () => {
|
|
1949
|
+
if (closed)
|
|
1950
|
+
return;
|
|
1951
|
+
closed = true;
|
|
1952
|
+
this.movable.delete(entry);
|
|
1953
|
+
detach();
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Attach a fallback listener for write rejections that are not handled by an
|
|
1958
|
+
* active {@link WriteHandle.wait} call.
|
|
1959
|
+
*
|
|
1960
|
+
* @returns an unsubscribe callback
|
|
1961
|
+
*/
|
|
1962
|
+
onMutationError(listener) {
|
|
1963
|
+
if (this.replaced)
|
|
1964
|
+
throw this.replaced;
|
|
1965
|
+
return this.registerMovable((db) => {
|
|
1966
|
+
db.mutationErrorListeners.add(listener);
|
|
1967
|
+
while (db.pendingMutationErrorEvents.length > 0) {
|
|
1968
|
+
listener(db.pendingMutationErrorEvents.shift());
|
|
1969
|
+
}
|
|
1970
|
+
return () => {
|
|
1971
|
+
db.mutationErrorListeners.delete(listener);
|
|
1972
|
+
};
|
|
563
1973
|
});
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Whether this Db's writes have reached the server: the upstream
|
|
1977
|
+
* connection, and how many committed transactions the server has not
|
|
1978
|
+
* accepted or rejected yet. The same object is returned until the status
|
|
1979
|
+
* changes, so it can back `useSyncExternalStore` directly.
|
|
1980
|
+
*/
|
|
1981
|
+
/**
|
|
1982
|
+
* Stateless anchors and ranges into text values, such as cursors,
|
|
1983
|
+
* selections and comments on a text column: captured from one value and
|
|
1984
|
+
* found again in later ones by the text around them.
|
|
1985
|
+
*/
|
|
1986
|
+
textAnchors() {
|
|
1987
|
+
return this.runtimeSource.textAnchors();
|
|
1988
|
+
}
|
|
1989
|
+
getSyncStatus() {
|
|
1990
|
+
const next = this.connection.syncStatus();
|
|
1991
|
+
if (this.syncStatusSnapshot && sameSyncStatus(next, this.syncStatusSnapshot)) {
|
|
1992
|
+
return this.syncStatusSnapshot;
|
|
1993
|
+
}
|
|
1994
|
+
this.syncStatusSnapshot = next;
|
|
1995
|
+
return next;
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Call `listener` whenever {@link getSyncStatus} changes.
|
|
1999
|
+
*
|
|
2000
|
+
* @returns an unsubscribe callback
|
|
2001
|
+
*/
|
|
2002
|
+
onSyncStatusChange(listener) {
|
|
2003
|
+
let last = this.getSyncStatus();
|
|
2004
|
+
const deliver = (status) => {
|
|
2005
|
+
if (status === last || sameSyncStatus(status, last))
|
|
575
2006
|
return;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
2007
|
+
last = status;
|
|
2008
|
+
listener(status);
|
|
2009
|
+
};
|
|
2010
|
+
return this.registerMovable((db) => {
|
|
2011
|
+
const stop = db.syncStatusChangeRegistration(deliver);
|
|
2012
|
+
// Moved at the upgrade: the status now covers both runtimes.
|
|
2013
|
+
if (db.successor)
|
|
2014
|
+
deliver(db.getSyncStatus());
|
|
2015
|
+
return stop;
|
|
2016
|
+
}, true);
|
|
2017
|
+
}
|
|
2018
|
+
/** How this Db reports sync status changes: its own, or combined with its successor's. */
|
|
2019
|
+
syncStatusChangeRegistration(listener) {
|
|
2020
|
+
return this.onSyncStatusChangeHere(listener);
|
|
2021
|
+
}
|
|
2022
|
+
onSyncStatusChangeHere(listener) {
|
|
2023
|
+
const subscription = new AbortController();
|
|
2024
|
+
const end = () => subscription.abort();
|
|
2025
|
+
this.shutdownAbort.signal.addEventListener("abort", end, { once: true });
|
|
2026
|
+
subscription.signal.addEventListener("abort", () => this.shutdownAbort.signal.removeEventListener("abort", end), { once: true });
|
|
2027
|
+
let published = this.getSyncStatus();
|
|
2028
|
+
this.connection.onSyncStatusChange(() => {
|
|
2029
|
+
const status = this.getSyncStatus();
|
|
2030
|
+
if (status === published)
|
|
581
2031
|
return;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
2032
|
+
published = status;
|
|
2033
|
+
listener(status);
|
|
2034
|
+
}, subscription.signal);
|
|
2035
|
+
return end;
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* Resolve once every write committed on this Db before the call has been
|
|
2039
|
+
* accepted by the server.
|
|
2040
|
+
*
|
|
2041
|
+
* Like `write.wait({ tier: "global" })`, the wait lasts through network
|
|
2042
|
+
* outages, reconnects and credential renewal. It rejects with the
|
|
2043
|
+
* server's error for the first of those writes it rejected, when the link
|
|
2044
|
+
* stops for good, with a {@link WriteWaitTimeoutError} once `timeoutMs`
|
|
2045
|
+
* passes, or with `signal.reason` when `signal` aborts. Ending the wait
|
|
2046
|
+
* never cancels the writes: they stay queued. In a browser tab it covers
|
|
2047
|
+
* that tab's own writes, not ones the shared worker recovered from storage.
|
|
2048
|
+
*/
|
|
2049
|
+
async waitForSync(options = {}) {
|
|
2050
|
+
const { timeoutMs, signal } = options;
|
|
2051
|
+
validateWriteWaitTimeout(timeoutMs);
|
|
2052
|
+
this.assertOpen();
|
|
2053
|
+
signal?.throwIfAborted();
|
|
2054
|
+
const control = new AbortController();
|
|
2055
|
+
const forward = () => control.abort(signal.reason);
|
|
2056
|
+
signal?.addEventListener("abort", forward, { once: true });
|
|
2057
|
+
// Shutdown ends the wait instead of leaving it parked on a closed runtime.
|
|
2058
|
+
const shutdown = () => control.abort(new Error("Db was shut down"));
|
|
2059
|
+
this.shutdownAbort.signal.addEventListener("abort", shutdown, {
|
|
2060
|
+
once: true,
|
|
586
2061
|
});
|
|
2062
|
+
const timer = timeoutMs === undefined
|
|
2063
|
+
? undefined
|
|
2064
|
+
: setTimeout(() => control.abort(new WriteWaitTimeoutError("global", timeoutMs)), timeoutMs);
|
|
2065
|
+
try {
|
|
2066
|
+
await this.connection.waitForSync(control.signal);
|
|
2067
|
+
}
|
|
2068
|
+
finally {
|
|
2069
|
+
if (timer !== undefined)
|
|
2070
|
+
clearTimeout(timer);
|
|
2071
|
+
signal?.removeEventListener("abort", forward);
|
|
2072
|
+
this.shutdownAbort.signal.removeEventListener("abort", shutdown);
|
|
2073
|
+
}
|
|
587
2074
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
2075
|
+
getConfig() {
|
|
2076
|
+
// Return a copy without internal live transport handles. MessagePorts are
|
|
2077
|
+
// neither configuration nor cloneable unless transferred.
|
|
2078
|
+
const { browserWorkerPort: _browserWorkerPort, browserWorkerSession: _browserWorkerSession, ...runtimeSources } = this.config.runtimeSources ?? {};
|
|
2079
|
+
return structuredClone({
|
|
2080
|
+
...this.config,
|
|
2081
|
+
runtimeSources: Object.keys(runtimeSources).length > 0 ? runtimeSources : undefined,
|
|
591
2082
|
});
|
|
592
2083
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
catch {
|
|
606
|
-
// Best effort
|
|
607
|
-
}
|
|
608
|
-
this.workerBridge = null;
|
|
2084
|
+
setDevMode(enabled) {
|
|
2085
|
+
this.config.devMode = enabled;
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* Temporarily disconnect this Db from its configured Jazz sync server.
|
|
2089
|
+
*
|
|
2090
|
+
* Local reads and writes can continue while disconnected. Call
|
|
2091
|
+
* {@link reconnect} to resume sync using the same Db instance.
|
|
2092
|
+
*/
|
|
2093
|
+
async disconnect() {
|
|
2094
|
+
if (this.shutdownPromise) {
|
|
2095
|
+
throw new Error("Cannot disconnect a Db that is shutting down.");
|
|
609
2096
|
}
|
|
610
|
-
this.
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
2097
|
+
this.offlineRequested = true;
|
|
2098
|
+
await this.connection.disconnect();
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Reconnect this Db to its configured Jazz sync server after
|
|
2102
|
+
* {@link disconnect}.
|
|
2103
|
+
*/
|
|
2104
|
+
async reconnect() {
|
|
2105
|
+
// Sync recovery is safe before teardown starts; it must remain available
|
|
2106
|
+
// while a graceful transition waits for previously committed writes.
|
|
2107
|
+
if (this.shutdownPromise && !this.cancelSyncShutdown) {
|
|
2108
|
+
throw new Error("Cannot reconnect a Db that is shutting down.");
|
|
621
2109
|
}
|
|
2110
|
+
this.offlineRequested = false;
|
|
2111
|
+
await this.connection.reconnect();
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* @internal
|
|
2115
|
+
*/
|
|
2116
|
+
getActiveQuerySubscriptions() {
|
|
2117
|
+
return Array.from(this.activeQuerySubscriptionTraces.values())
|
|
2118
|
+
.filter((trace) => trace.visibility === "public")
|
|
2119
|
+
.map(({ visibility: _visibility, ...trace }) => cloneActiveQuerySubscriptionTrace(trace));
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* @internal
|
|
2123
|
+
*/
|
|
2124
|
+
onActiveQuerySubscriptionsChange(listener) {
|
|
2125
|
+
return this.registerMovable((db) => {
|
|
2126
|
+
db.activeQuerySubscriptionTraceListeners.add(listener);
|
|
2127
|
+
listener(db.getActiveQuerySubscriptions());
|
|
2128
|
+
return () => {
|
|
2129
|
+
db.activeQuerySubscriptionTraceListeners.delete(listener);
|
|
2130
|
+
};
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* The engine-normalized runtime schema of this Db's live client, or null
|
|
2135
|
+
* before the client exists. This is a dev-introspection accessor (inspector
|
|
2136
|
+
* host handle, devtools bridge), not a general schema API.
|
|
2137
|
+
*/
|
|
2138
|
+
getRuntimeSchema() {
|
|
2139
|
+
return this.connection.getRuntimeSchema();
|
|
2140
|
+
}
|
|
2141
|
+
/** @internal Open a control channel for the same-origin embedded inspector. */
|
|
2142
|
+
openInspectorControlPort(signal) {
|
|
2143
|
+
return this.connection.openInspectorControlPort(signal);
|
|
2144
|
+
}
|
|
2145
|
+
/**
|
|
2146
|
+
* Insert a new row into a table without waiting for durability.
|
|
2147
|
+
*
|
|
2148
|
+
* Use {@link WriteResult.wait} to wait for durable confirmation.
|
|
2149
|
+
*
|
|
2150
|
+
* @param table Table proxy from generated app module
|
|
2151
|
+
* @param data Init object with column values
|
|
2152
|
+
* @returns Write result containing the inserted row
|
|
2153
|
+
*/
|
|
2154
|
+
insert(table, data, options) {
|
|
2155
|
+
assertWritableTable(table);
|
|
2156
|
+
const client = this.getClient(table._schema);
|
|
2157
|
+
let id = options?.id ?? (hasDependentTransforms(table) ? reserveRowId() : undefined);
|
|
2158
|
+
const transformedData = table._columnTransforms
|
|
2159
|
+
? transformInputColumns(table, data, id ? { id } : undefined, true)
|
|
2160
|
+
: data;
|
|
2161
|
+
const values = toWriteRecordForOperation("Insert", transformedData, table._schema, table._table);
|
|
2162
|
+
const context = this.getAccessContext();
|
|
2163
|
+
const deferred = !!getOwnerPreparation(client)?.pending;
|
|
2164
|
+
if (deferred && !id)
|
|
2165
|
+
id = reserveRowId();
|
|
2166
|
+
const value = deferred ? immediateWriteRow(table, id, values) : undefined;
|
|
2167
|
+
const inserted = runAfterPreparation(client, () => client.insert(table._table, values, normalizeSelectorOptions(table._schema, table._table, id ? { ...options, id } : options), context?.writeSession, context?.attribution));
|
|
2168
|
+
return this.wrapWriteWait(inserted instanceof Promise
|
|
2169
|
+
? new WriteResult(value, inserted.then((result) => result.txId), client)
|
|
2170
|
+
: inserted.mapValue((row) => value !== undefined
|
|
2171
|
+
? value
|
|
2172
|
+
: transformOutputRow(table, transformRow(row, table._schema, table._table))));
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* Stream one Text, Json, or Bytea column into a new row. The column's runtime
|
|
2176
|
+
* schema determines encoding; callers never pass a large-value kind.
|
|
2177
|
+
*
|
|
2178
|
+
* Unlike {@link insert}, this is asynchronous because it consumes the source
|
|
2179
|
+
* before publishing. Its handle returns only the generated id so the complete
|
|
2180
|
+
* streamed value is not copied back into JavaScript memory.
|
|
2181
|
+
*/
|
|
2182
|
+
async insertStreaming(table, data, options) {
|
|
2183
|
+
assertWritableTable(table);
|
|
2184
|
+
const client = this.getClient(table._schema);
|
|
2185
|
+
const { column, source, values: ordinaryData } = splitStreamingMutation(table, data);
|
|
2186
|
+
rejectIncompleteDependencies(table, ordinaryData, [column]);
|
|
2187
|
+
notifyLocalWrite(this);
|
|
2188
|
+
const id = options?.id ??
|
|
2189
|
+
(missingWriteDependencies(table, ordinaryData).includes("id") ? reserveRowId() : undefined);
|
|
2190
|
+
return runAfterPreparation(client, async () => {
|
|
2191
|
+
const transformedData = transformInputColumns(table, ordinaryData, id ? { id } : {}, true);
|
|
2192
|
+
const values = toWriteRecordForOperation("Insert", transformedData, table._schema, table._table);
|
|
2193
|
+
const context = this.getAccessContext();
|
|
2194
|
+
const branch = deriveStreamingInsertBranch(table, ordinaryData);
|
|
2195
|
+
return client.insertStreaming(table._table, values, column, source, normalizeSelectorOptions(table._schema, table._table, branch
|
|
2196
|
+
? { ...options, ...(id ? { id } : {}), branch }
|
|
2197
|
+
: id
|
|
2198
|
+
? { ...options, id }
|
|
2199
|
+
: options), context?.writeSession, context?.attribution);
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
async updateStreaming(table, id, data, options) {
|
|
2203
|
+
assertWritableTable(table);
|
|
2204
|
+
const client = this.getClient(table._schema);
|
|
2205
|
+
const { column, source, values: ordinaryData } = splitStreamingMutation(table, data);
|
|
2206
|
+
rejectIncompleteDependencies(table, ordinaryData, [column]);
|
|
2207
|
+
notifyLocalWrite(this);
|
|
2208
|
+
const context = this.getAccessContext();
|
|
2209
|
+
return runAfterPreparation(client, async () => {
|
|
2210
|
+
const transformedData = await prepareInputColumns(table, ordinaryData, "Update", id, client, context?.readSession, undefined, normalizeViewOptions(table._schema, table._table, options));
|
|
2211
|
+
const values = toWriteRecordForOperation("Update", transformedData, table._schema, table._table);
|
|
2212
|
+
return client.updateStreaming(table._table, id, values, column, source, normalizeViewOptions(table._schema, table._table, options), context?.writeSession, context?.attribution);
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
async upsertStreaming(table, id, data, options) {
|
|
2216
|
+
assertWritableTable(table);
|
|
2217
|
+
const client = this.getClient(table._schema);
|
|
2218
|
+
const { column, source, values: ordinaryData } = splitStreamingMutation(table, data);
|
|
2219
|
+
rejectIncompleteDependencies(table, ordinaryData, [column]);
|
|
2220
|
+
notifyLocalWrite(this);
|
|
2221
|
+
const context = this.getAccessContext();
|
|
2222
|
+
return runAfterPreparation(client, async () => {
|
|
2223
|
+
const transformedData = await prepareInputColumns(table, ordinaryData, "Upsert", id, client, context?.readSession, undefined, normalizeViewOptions(table._schema, table._table, options));
|
|
2224
|
+
const values = toWriteRecordForOperation("Upsert", transformedData, table._schema, table._table);
|
|
2225
|
+
return client.upsertStreaming(table._table, id, values, column, source, normalizeViewOptions(table._schema, table._table, options), context?.writeSession, context?.attribution);
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Restore a soft-deleted row without waiting for durability.
|
|
2230
|
+
*
|
|
2231
|
+
* Use {@link WriteResult.wait} to wait for durable confirmation.
|
|
2232
|
+
*/
|
|
2233
|
+
restore(table, id, data, options) {
|
|
2234
|
+
assertWritableTable(table);
|
|
2235
|
+
const client = this.getClient(table._schema);
|
|
2236
|
+
const transformedData = table._columnTransforms
|
|
2237
|
+
? transformInputColumns(table, data, { id }, true)
|
|
2238
|
+
: data;
|
|
2239
|
+
const values = toWriteRecordForOperation("Restore", transformedData, table._schema, table._table);
|
|
2240
|
+
const context = this.getAccessContext();
|
|
2241
|
+
const deferred = !!getOwnerPreparation(client)?.pending;
|
|
2242
|
+
const value = deferred ? immediateWriteRow(table, id, values) : undefined;
|
|
2243
|
+
const restored = runAfterPreparation(client, () => client.restore(table._table, id, values, normalizeSelectorOptions(table._schema, table._table, options), context?.writeSession, context?.attribution));
|
|
2244
|
+
return this.wrapWriteWait(restored instanceof Promise
|
|
2245
|
+
? new WriteResult(value, restored.then((result) => result.txId), client)
|
|
2246
|
+
: restored.mapValue((row) => transformOutputRow(table, transformRow(row, table._schema, table._table))));
|
|
622
2247
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
2248
|
+
/**
|
|
2249
|
+
* Create or update a row with a caller-supplied id without waiting for durability.
|
|
2250
|
+
*
|
|
2251
|
+
* Use {@link WriteHandle.wait} to wait for durable confirmation.
|
|
2252
|
+
*/
|
|
2253
|
+
upsert(table, id, data, options) {
|
|
2254
|
+
assertWritableTable(table);
|
|
2255
|
+
return this.prepareMutation(table, id, data, "Upsert", options);
|
|
627
2256
|
}
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
2257
|
+
prepareMutation(table, id, data, operation, options, stage) {
|
|
2258
|
+
const client = this.getClient(table._schema);
|
|
2259
|
+
const missing = missingWriteDependencies(table, data, id);
|
|
2260
|
+
if (getOwnerPreparation(client)?.pending || missing.length)
|
|
2261
|
+
data = { ...data };
|
|
2262
|
+
const context = this.getAccessContext();
|
|
2263
|
+
const normalized = normalizeViewOptions(table._schema, table._table, options);
|
|
2264
|
+
const result = runAfterPreparation(client, () => {
|
|
2265
|
+
const submit = (record, transaction) => {
|
|
2266
|
+
const values = toWriteRecordForOperation(operation, record, table._schema, table._table);
|
|
2267
|
+
if (stage)
|
|
2268
|
+
return stage(values);
|
|
2269
|
+
if (transaction) {
|
|
2270
|
+
if (operation === "Upsert")
|
|
2271
|
+
client.upsertInternal(table._table, id, values, normalized, context?.writeSession, context?.attribution, transaction);
|
|
2272
|
+
else
|
|
2273
|
+
client.updateInternal(table._table, id, values, normalized?.updatedAt, context?.writeSession, context?.attribution, transaction, normalized?.branch);
|
|
2274
|
+
return client.commitTransaction(transaction);
|
|
644
2275
|
}
|
|
2276
|
+
return operation === "Upsert"
|
|
2277
|
+
? client.upsert(table._table, id, values, normalized, context?.writeSession, context?.attribution)
|
|
2278
|
+
: client.update(table._table, id, values, normalized, context?.writeSession, context?.attribution);
|
|
645
2279
|
};
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
2280
|
+
if (missing.length === 0) {
|
|
2281
|
+
const record = table._columnTransforms ? transformInputColumns(table, data, { id }) : data;
|
|
2282
|
+
if (operation !== "Update")
|
|
2283
|
+
return submit(record);
|
|
2284
|
+
try {
|
|
2285
|
+
return submit(record);
|
|
2286
|
+
}
|
|
2287
|
+
catch (error) {
|
|
2288
|
+
// An update stages against the row's current cells. When this
|
|
2289
|
+
// replica has not loaded the row yet (a fresh process, another
|
|
2290
|
+
// instance), read it through the caller's session and stage again;
|
|
2291
|
+
// later writes wait behind this one, so their order holds.
|
|
2292
|
+
if (nativeCoreErrorCode(error) !== "not_observed")
|
|
2293
|
+
throw error;
|
|
2294
|
+
// The read's row count is not the answer: this replica may filter
|
|
2295
|
+
// out a row it now holds, lacking the rows that grant the session
|
|
2296
|
+
// access, and only the authority decides whether the session may
|
|
2297
|
+
// write it. Stage again whatever came back.
|
|
2298
|
+
return loadRow(client, table, id, context?.readSession, normalized?.branch).then(() => {
|
|
2299
|
+
try {
|
|
2300
|
+
return submit(record);
|
|
2301
|
+
}
|
|
2302
|
+
catch (retryError) {
|
|
2303
|
+
// Still not held: the server sent no row, so it does not exist
|
|
2304
|
+
// or the session may not read it, and the two are refused alike,
|
|
2305
|
+
// with the denial's code, as the authority answers.
|
|
2306
|
+
if (nativeCoreErrorCode(retryError) !== "not_observed")
|
|
2307
|
+
throw retryError;
|
|
2308
|
+
throw unreadableTargetError("Update", table._table);
|
|
2309
|
+
}
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
const transaction = client.beginTransaction("mergeable", context?.writeSession, context?.attribution);
|
|
2314
|
+
// An empty mergeable transaction has no staged overlay or read set. Native branch reads
|
|
2315
|
+
// currently require the ordinary scoped path; explicit transactions still fail closed.
|
|
2316
|
+
return Promise.resolve(prepareInputColumns(table, data, operation, id, client, context?.readSession, normalized?.branch ? undefined : transaction, normalized, missing))
|
|
2317
|
+
.then(async (record) => {
|
|
2318
|
+
// Partial edits already own their native transaction; mergeable reads add no read precondition.
|
|
2319
|
+
if (stage) {
|
|
2320
|
+
await client.rollbackTransaction(transaction);
|
|
2321
|
+
return submit(record);
|
|
2322
|
+
}
|
|
2323
|
+
return submit(record, transaction);
|
|
2324
|
+
})
|
|
2325
|
+
.catch(async (error) => {
|
|
2326
|
+
await client.rollbackTransaction(transaction).catch(() => { });
|
|
2327
|
+
throw error;
|
|
650
2328
|
});
|
|
651
2329
|
});
|
|
652
|
-
return
|
|
2330
|
+
return this.wrapWriteWait(result instanceof Promise
|
|
2331
|
+
? new WriteHandle(result.then((handle) => handle.txId), client)
|
|
2332
|
+
: result);
|
|
2333
|
+
}
|
|
2334
|
+
update(table, id, data, options) {
|
|
2335
|
+
assertWritableTable(table);
|
|
2336
|
+
const client = this.getClient(table._schema);
|
|
2337
|
+
const { replacements, descriptors } = lowerUpdate(table, data, options);
|
|
2338
|
+
options = withoutEditedFrom(options);
|
|
2339
|
+
const context = this.getAccessContext();
|
|
2340
|
+
if (descriptors.length > 0) {
|
|
2341
|
+
return this.prepareMutation(table, id, replacements, "Update", options, (updates) => client.updateLargeValues(table._table, id, updates, descriptors, normalizeViewOptions(table._schema, table._table, options), context?.writeSession, context?.attribution));
|
|
2342
|
+
}
|
|
2343
|
+
return this.prepareMutation(table, id, data, "Update", options);
|
|
653
2344
|
}
|
|
654
2345
|
/**
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* This is a **synchronous** operation - the row is created immediately
|
|
658
|
-
* in the local WASM runtime. Sync to server happens asynchronously.
|
|
659
|
-
*
|
|
660
|
-
* @param table Table proxy from generated app module
|
|
661
|
-
* @param data Init object with column values
|
|
662
|
-
* @returns The new row's ID (UUID string)
|
|
2346
|
+
* Delete a row without waiting for durability.
|
|
663
2347
|
*
|
|
664
|
-
* @
|
|
665
|
-
* ```typescript
|
|
666
|
-
* const id = db.insert(app.todos, { title: "Buy milk", done: false });
|
|
667
|
-
* ```
|
|
2348
|
+
* Use {@link WriteHandle.wait} to wait for durable confirmation.
|
|
668
2349
|
*/
|
|
669
|
-
|
|
2350
|
+
delete(table, id, options) {
|
|
2351
|
+
assertWritableTable(table);
|
|
2352
|
+
const client = this.getClient(table._schema);
|
|
2353
|
+
const context = this.getAccessContext();
|
|
2354
|
+
const result = runAfterPreparation(client, () => client.delete(table._table, id, normalizeViewOptions(table._schema, table._table, options), context?.writeSession, context?.attribution));
|
|
2355
|
+
return this.wrapWriteWait(result instanceof Promise
|
|
2356
|
+
? new WriteHandle(result.then((handle) => handle.txId), client)
|
|
2357
|
+
: result);
|
|
2358
|
+
}
|
|
2359
|
+
/** Request authoritative permission advice for inserting a row. */
|
|
2360
|
+
async canInsert(table, data) {
|
|
2361
|
+
const client = this.getClient(table._schema);
|
|
2362
|
+
const values = writeRecord("Insert", table, data);
|
|
2363
|
+
const context = this.getAccessContext();
|
|
2364
|
+
return client.requestInsertPermissionAdvice(table._table, values, context?.writeSession);
|
|
2365
|
+
}
|
|
2366
|
+
/** Request authoritative permission advice for reading a row. */
|
|
2367
|
+
async canRead(table, id) {
|
|
2368
|
+
const client = this.getClient(table._schema);
|
|
2369
|
+
const context = this.getAccessContext();
|
|
2370
|
+
return client.requestReadPermissionAdvice(table._table, id, context?.readSession);
|
|
2371
|
+
}
|
|
2372
|
+
/** Request authoritative permission advice for updating a row. */
|
|
2373
|
+
async canUpdate(table, id, data) {
|
|
2374
|
+
const client = this.getClient(table._schema);
|
|
2375
|
+
const updates = writeRecord("Update", table, data);
|
|
2376
|
+
const context = this.getAccessContext();
|
|
2377
|
+
return client.requestUpdatePermissionAdvice(table._table, id, updates, context?.writeSession);
|
|
2378
|
+
}
|
|
2379
|
+
/** Request authoritative permission advice for deleting a row. */
|
|
2380
|
+
async canDelete(table, id) {
|
|
670
2381
|
const client = this.getClient(table._schema);
|
|
671
|
-
const
|
|
672
|
-
return client.
|
|
2382
|
+
const context = this.getAccessContext();
|
|
2383
|
+
return client.requestDeletePermissionAdvice(table._table, id, context?.writeSession);
|
|
2384
|
+
}
|
|
2385
|
+
/** @internal Shared construction path; admission remains owned by the transaction. */
|
|
2386
|
+
createTransaction(kind, prerequisite) {
|
|
2387
|
+
this.assertOpen();
|
|
2388
|
+
notifyLocalWrite(this);
|
|
2389
|
+
const context = this.getAccessContext();
|
|
2390
|
+
const ownerClient = this.getCurrentClient();
|
|
2391
|
+
if (kind === "serializable" && !ownerClient) {
|
|
2392
|
+
throw new Error("Cannot begin a serializable transaction before the JazzClient has been created. Run a query or mutation first.");
|
|
2393
|
+
}
|
|
2394
|
+
return Transaction.createWithAdmission(kind, (schema) => this.getClient(schema), context, ownerClient ?? undefined, prerequisite);
|
|
673
2395
|
}
|
|
674
2396
|
/**
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* @param table Table proxy from generated app module
|
|
678
|
-
* @param data Init object with column values
|
|
679
|
-
* @param tier Acknowledgement tier to wait for
|
|
680
|
-
* @returns Promise resolving to the new row's ID when the tier acknowledges
|
|
2397
|
+
* Capture this database's local read frontier for a frozen branch base.
|
|
681
2398
|
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
2399
|
+
* Includes earlier locally committed writes, including pending server
|
|
2400
|
+
* acceptance, and excludes uncommitted transaction changes and later writes.
|
|
2401
|
+
* Works offline after the first query or mutation has attached a schema.
|
|
2402
|
+
* The reference does not retain history or grant permission. Persist it with
|
|
2403
|
+
* `serializeSnapshotRef`; restoring it requires the same dataset and enough
|
|
2404
|
+
* retained history to answer the requested read.
|
|
686
2405
|
*/
|
|
687
|
-
async
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
2406
|
+
async captureSnapshot() {
|
|
2407
|
+
this.assertOpen();
|
|
2408
|
+
const client = this.getCurrentClient();
|
|
2409
|
+
if (!client) {
|
|
2410
|
+
throw new Error("Cannot capture a snapshot before a schema is attached. Run a query or mutation first.");
|
|
2411
|
+
}
|
|
2412
|
+
// Admit capture now, before later writes, including writes whose async
|
|
2413
|
+
// transforms share this owner's preparation queue.
|
|
2414
|
+
return runAfterPreparation(client, () => client.captureSnapshot());
|
|
692
2415
|
}
|
|
693
2416
|
/**
|
|
694
|
-
*
|
|
2417
|
+
* Begin a mergeable transaction.
|
|
2418
|
+
*
|
|
2419
|
+
* Use {@link Transaction.commit} to commit the transaction.
|
|
2420
|
+
*
|
|
2421
|
+
* Prefer using {@link Db.transaction} when an explicit commit is not required.
|
|
695
2422
|
*/
|
|
696
|
-
|
|
697
|
-
return this.
|
|
2423
|
+
beginTransaction() {
|
|
2424
|
+
return this.createTransaction("mergeable");
|
|
698
2425
|
}
|
|
699
2426
|
/**
|
|
700
|
-
*
|
|
2427
|
+
* Begin a serializable transaction for writes that need serializable validation by the authority.
|
|
701
2428
|
*
|
|
702
|
-
*
|
|
703
|
-
* in the local WASM runtime. Sync to server happens asynchronously.
|
|
2429
|
+
* Use {@link Transaction.commit} to commit the transaction.
|
|
704
2430
|
*
|
|
705
|
-
* @
|
|
706
|
-
|
|
707
|
-
|
|
2431
|
+
* Prefer using {@link Db.serializableTransaction} when an explicit commit is not required.
|
|
2432
|
+
*/
|
|
2433
|
+
beginSerializableTransaction() {
|
|
2434
|
+
return this.createTransaction("serializable");
|
|
2435
|
+
}
|
|
2436
|
+
/**
|
|
2437
|
+
* Run {@link callback} inside a mergeable transaction and commit it once the callback returns.
|
|
708
2438
|
*
|
|
709
|
-
* @
|
|
710
|
-
* ```typescript
|
|
711
|
-
* db.update(app.todos, id, { done: true });
|
|
712
|
-
* ```
|
|
2439
|
+
* @returns a write result containing the result of the callback
|
|
713
2440
|
*/
|
|
714
|
-
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
client.update(id, updates);
|
|
2441
|
+
transaction(callback) {
|
|
2442
|
+
const transaction = this.beginTransaction();
|
|
2443
|
+
return runInTransaction(transaction, callback, () => getDbTxHandleBinding(transaction, "result").ownerClient);
|
|
718
2444
|
}
|
|
719
2445
|
/**
|
|
720
|
-
*
|
|
2446
|
+
* Run {@link callback} inside a serializable transaction and commit it once the callback returns.
|
|
721
2447
|
*
|
|
722
|
-
* @
|
|
723
|
-
* @param id Row ID to update
|
|
724
|
-
* @param data Partial object with fields to update
|
|
725
|
-
* @param tier Acknowledgement tier to wait for
|
|
2448
|
+
* @returns a write result containing the result of the callback
|
|
726
2449
|
*/
|
|
727
|
-
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
const updates = toUpdateRecord(data, table._schema, table._table);
|
|
731
|
-
await client.updateWithAck(id, updates, tier);
|
|
2450
|
+
serializableTransaction(callback) {
|
|
2451
|
+
const transaction = this.beginSerializableTransaction();
|
|
2452
|
+
return runInTransaction(transaction, callback, () => getDbTxHandleBinding(transaction, "result").ownerClient);
|
|
732
2453
|
}
|
|
733
2454
|
/**
|
|
734
|
-
*
|
|
2455
|
+
* Move this app from the thin client to the local-first one, loading it with
|
|
2456
|
+
* `loader` (for example `() => import("jazz-tools/local-first")`). Under a
|
|
2457
|
+
* Jazz provider the provider swaps in the local-first `Db` once it holds the
|
|
2458
|
+
* app's live queries, and this resolves then. A local-first `Db` resolves at
|
|
2459
|
+
* once. (A thin `Db` opened directly, outside a session, upgrades with
|
|
2460
|
+
* `upgradeToLocalFirst(thin, open)` from `jazz-tools/thin`, which returns
|
|
2461
|
+
* the new `Db` for the app to swap in itself.)
|
|
735
2462
|
*/
|
|
736
|
-
async
|
|
737
|
-
await this
|
|
2463
|
+
async upgradeToLocalFirst(loader) {
|
|
2464
|
+
await upgradeDbToLocalFirst(this, loader);
|
|
738
2465
|
}
|
|
739
2466
|
/**
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
* @param table Table proxy from generated app module
|
|
746
|
-
* @param id Row ID to delete
|
|
747
|
-
*
|
|
748
|
-
* @example
|
|
749
|
-
* ```typescript
|
|
750
|
-
* db.deleteFrom(app.todos, id);
|
|
751
|
-
* ```
|
|
2467
|
+
* Whether this `Db` reads and writes through a local store: true for a
|
|
2468
|
+
* local-first `Db`, and for a thin one once its session has upgraded it
|
|
2469
|
+
* (the same `Db` carries on), false for a thin one before. To wait for the
|
|
2470
|
+
* upgrade, `await db.upgradeToLocalFirst(loader)`.
|
|
752
2471
|
*/
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
client.delete(id);
|
|
2472
|
+
isLocalFirst() {
|
|
2473
|
+
return !isThinDb(this);
|
|
756
2474
|
}
|
|
757
2475
|
/**
|
|
758
|
-
* Delete
|
|
759
|
-
*
|
|
760
|
-
* @param table Table proxy from generated app module
|
|
761
|
-
* @param id Row ID to delete
|
|
762
|
-
* @param tier Acknowledgement tier to wait for
|
|
2476
|
+
* Delete browser IndexedDB storage for this Db's active namespace.
|
|
763
2477
|
*/
|
|
764
|
-
async
|
|
765
|
-
|
|
766
|
-
await this.ensureBridgeReady();
|
|
767
|
-
await client.deleteWithAck(id, tier);
|
|
2478
|
+
async deleteClientStorage() {
|
|
2479
|
+
await this.connection.deleteClientStorage();
|
|
768
2480
|
}
|
|
769
2481
|
/**
|
|
770
|
-
*
|
|
2482
|
+
* Release the current Db instance for logout flows.
|
|
2483
|
+
*
|
|
2484
|
+
* When `wipeData` is enabled, Jazz clears local client storage before shutting this Db down.
|
|
2485
|
+
* Callers should still sign out of their external auth provider separately and recreate
|
|
2486
|
+
* `JazzProvider` / `Db` after logout.
|
|
771
2487
|
*/
|
|
772
|
-
async
|
|
773
|
-
|
|
2488
|
+
async logout(options = {}) {
|
|
2489
|
+
if (options.wipeData) {
|
|
2490
|
+
await this.deleteClientStorage();
|
|
2491
|
+
}
|
|
2492
|
+
await this.shutdown();
|
|
774
2493
|
}
|
|
775
2494
|
/**
|
|
776
2495
|
* Execute a query and return all matching rows as typed objects.
|
|
@@ -778,46 +2497,115 @@ export class Db {
|
|
|
778
2497
|
* @param query QueryBuilder instance (e.g., app.todos.where({done: false}))
|
|
779
2498
|
* @returns Array of typed objects matching the query
|
|
780
2499
|
*/
|
|
781
|
-
async all(query,
|
|
2500
|
+
async all(query, options) {
|
|
2501
|
+
try {
|
|
2502
|
+
return await this.allInternal(query, lowerPublicDbQueryOptions(options));
|
|
2503
|
+
}
|
|
2504
|
+
catch (error) {
|
|
2505
|
+
// Begun before this Db handed over to a successor, and ended by that
|
|
2506
|
+
// (its own runtime closing): the successor answers it. Any other
|
|
2507
|
+
// error is the read's own answer.
|
|
2508
|
+
if (this.successor && isRuntimeClosed(error))
|
|
2509
|
+
return this.current().all(query, options);
|
|
2510
|
+
throw error;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
async allInternal(query, options) {
|
|
782
2514
|
const client = this.getClient(query._schema);
|
|
2515
|
+
const preparation = getOwnerPreparation(client);
|
|
2516
|
+
if (preparation?.pending)
|
|
2517
|
+
await preparation.drain();
|
|
2518
|
+
// A newly attached browser-worker follower learns the namespace-wide
|
|
2519
|
+
// connection state during its init handshake. The core read gate needs
|
|
2520
|
+
// that state before it decides whether the first load may wait.
|
|
2521
|
+
const mayWaitForServer = resolveEffectiveQueryExecutionOptions(this.config, {
|
|
2522
|
+
tier: options?.tier,
|
|
2523
|
+
firstLoadRemoteWaitMs: options?.firstLoadRemoteWaitMs,
|
|
2524
|
+
}).firstLoadRemoteWaitMs !== undefined;
|
|
2525
|
+
const initialOfflineState = mayWaitForServer
|
|
2526
|
+
? this.connection.initialExplicitOfflineState()
|
|
2527
|
+
: null;
|
|
2528
|
+
if (initialOfflineState)
|
|
2529
|
+
await initialOfflineState;
|
|
783
2530
|
const builderJson = query._build();
|
|
784
|
-
const builtQuery = normalizeBuiltQuery(JSON.parse(builderJson)
|
|
785
|
-
const
|
|
786
|
-
const outputTable = builtQuery
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
const
|
|
790
|
-
|
|
2531
|
+
const builtQuery = normalizeBuiltQuery(JSON.parse(builderJson));
|
|
2532
|
+
const planningSchema = requireSchemaWithTable(query._schema, builtQuery.table);
|
|
2533
|
+
const outputTable = resolveQueryOutputTable(planningSchema, builtQuery);
|
|
2534
|
+
const prepared = prepareTransformRead(query, builtQuery, outputTable);
|
|
2535
|
+
const queryOptions = normalizeQueryOptions(query._schema, builtQuery.table, options);
|
|
2536
|
+
const wasmQuery = translateQuery(builderJson, planningSchema, prepared.physical);
|
|
2537
|
+
const usesRelationTraversal = queryUsesRelationTraversal(builtQuery);
|
|
2538
|
+
const context = this.getAccessContext();
|
|
2539
|
+
const effectiveTier = resolveEffectiveQueryExecutionOptions(this.config, queryOptions).tier;
|
|
2540
|
+
await this.ensureReady(effectiveTier === "remote" ? "server" : "runtime");
|
|
2541
|
+
const rows = context || usesRelationTraversal
|
|
2542
|
+
? await client.queryInternal(wasmQuery, queryOptions, context?.readSession)
|
|
2543
|
+
: await client.queryInternal(wasmQuery, queryOptions);
|
|
2544
|
+
if (!prepared.computedState)
|
|
2545
|
+
return rows.map(prepared.transform);
|
|
2546
|
+
return finishComputedRead(query, builtQuery, outputTable, prepared, rows, (physical) => client.queryInternal(translateQuery(builderJson, planningSchema, physical), queryOptions, context?.readSession));
|
|
791
2547
|
}
|
|
792
2548
|
/**
|
|
793
|
-
* Execute a query and return the first matching row, or null.
|
|
2549
|
+
* Execute a query with a limit of one and return the first matching row, or null.
|
|
794
2550
|
*
|
|
795
2551
|
* @param query QueryBuilder instance
|
|
796
|
-
* @param
|
|
2552
|
+
* @param options Optional read durability options
|
|
797
2553
|
* @returns First matching typed object, or null if none found
|
|
798
2554
|
*/
|
|
799
|
-
async one(query,
|
|
800
|
-
const results = await this.all(query,
|
|
2555
|
+
async one(query, options) {
|
|
2556
|
+
const results = await this.all(limitQueryToOne(query), options);
|
|
801
2557
|
return results[0] ?? null;
|
|
802
2558
|
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Subscribe to a query and receive its complete current result whenever it changes.
|
|
2561
|
+
* Each update receives a fresh result array. Prefer the object form when the
|
|
2562
|
+
* subscription's terminal errors must be handled explicitly. The legacy
|
|
2563
|
+
* function form reports unhandled terminal errors to `console.error`.
|
|
2564
|
+
*/
|
|
2565
|
+
subscribe(query, callbacks, options, session) {
|
|
2566
|
+
const { onUpdate, onError } = typeof callbacks === "function" ? { onUpdate: callbacks, onError: undefined } : callbacks;
|
|
2567
|
+
const deltaCallbacks = {
|
|
2568
|
+
onDelta: (update) => {
|
|
2569
|
+
if (update.all === undefined) {
|
|
2570
|
+
throw new Error("Jazz subscription update is missing its materialized result.");
|
|
2571
|
+
}
|
|
2572
|
+
const splices = new Map();
|
|
2573
|
+
for (const change of update.delta) {
|
|
2574
|
+
if (change.kind === RowChangeKind.Updated && change.splices) {
|
|
2575
|
+
splices.set(change.id, change.splices);
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
onUpdate(update.all, { splices });
|
|
2579
|
+
},
|
|
2580
|
+
...(onError === undefined ? {} : { onError }),
|
|
2581
|
+
};
|
|
2582
|
+
return this.subscribeDelta(query, deltaCallbacks, lowerPublicDbQueryOptions(options), session);
|
|
2583
|
+
}
|
|
803
2584
|
/**
|
|
804
2585
|
* Subscribe to a query and receive updates when results change.
|
|
805
2586
|
*
|
|
806
2587
|
* The callback receives a SubscriptionDelta with:
|
|
807
|
-
* - `all`: Complete current result set
|
|
808
|
-
*
|
|
2588
|
+
* - `all`: Complete current result set. Freshly allocated on every delta —
|
|
2589
|
+
* the rows are new object references each time, so diffing `all` by identity
|
|
2590
|
+
* sees every row as changed. Reactive-framework consumers should reconcile
|
|
2591
|
+
* with `applyDelta`/`reconcileArray` from `reconcile-array.js` to preserve
|
|
2592
|
+
* identity for unchanged rows.
|
|
2593
|
+
* - `delta`: Ordered list of row-level changes (see `RowDelta`)
|
|
809
2594
|
*
|
|
810
2595
|
* @param query QueryBuilder instance
|
|
811
|
-
* @param
|
|
2596
|
+
* @param callbacks Called with deltas and, in object form, terminal subscription errors
|
|
2597
|
+
* @param options Optional read durability options
|
|
812
2598
|
* @returns Unsubscribe function
|
|
813
2599
|
*
|
|
814
2600
|
* @example
|
|
815
2601
|
* ```typescript
|
|
816
|
-
*
|
|
2602
|
+
* import { RowChangeKind } from "jazz-tools";
|
|
2603
|
+
*
|
|
2604
|
+
* const unsubscribe = db.subscribeDelta(app.todos, (delta) => {
|
|
817
2605
|
* setTodos(delta.all);
|
|
818
2606
|
* for (const change of delta.delta) {
|
|
819
|
-
* if (change.kind ===
|
|
820
|
-
* console.log("New row:", change.
|
|
2607
|
+
* if (change.kind === RowChangeKind.Added) {
|
|
2608
|
+
* console.log("New row:", change.item);
|
|
821
2609
|
* }
|
|
822
2610
|
* }
|
|
823
2611
|
* });
|
|
@@ -826,82 +2614,675 @@ export class Db {
|
|
|
826
2614
|
* unsubscribe();
|
|
827
2615
|
* ```
|
|
828
2616
|
*/
|
|
829
|
-
|
|
830
|
-
|
|
2617
|
+
subscribeDelta(query, callbacks, options, session) {
|
|
2618
|
+
if (this.replaced)
|
|
2619
|
+
throw this.replaced;
|
|
2620
|
+
const { onDelta, onError } = typeof callbacks === "function" ? { onDelta: callbacks, onError: undefined } : callbacks;
|
|
2621
|
+
let ready;
|
|
2622
|
+
let first = true;
|
|
2623
|
+
const stop = this.registerMovable((db) => {
|
|
2624
|
+
// On the successor the query starts over: its opening result replaces
|
|
2625
|
+
// what the subscriber has, rows the upgrade already read in included.
|
|
2626
|
+
let opening = !first;
|
|
2627
|
+
first = false;
|
|
2628
|
+
const handle = db.subscribeDeltaHere(query, {
|
|
2629
|
+
onDelta: (delta) => {
|
|
2630
|
+
if (opening) {
|
|
2631
|
+
opening = false;
|
|
2632
|
+
onDelta({
|
|
2633
|
+
delta: delta.delta,
|
|
2634
|
+
all: delta.all ?? [],
|
|
2635
|
+
reset: true,
|
|
2636
|
+
});
|
|
2637
|
+
return;
|
|
2638
|
+
}
|
|
2639
|
+
onDelta(delta);
|
|
2640
|
+
},
|
|
2641
|
+
...(onError === undefined ? {} : { onError }),
|
|
2642
|
+
}, options, session);
|
|
2643
|
+
ready ??= handle.ready;
|
|
2644
|
+
return handle;
|
|
2645
|
+
});
|
|
2646
|
+
const handle = (() => stop());
|
|
2647
|
+
if (ready)
|
|
2648
|
+
Object.defineProperty(handle, "ready", { value: ready });
|
|
2649
|
+
return handle;
|
|
2650
|
+
}
|
|
2651
|
+
subscribeDeltaHere(query, callbacks, options, session) {
|
|
2652
|
+
const { onDelta, onError } = callbacks;
|
|
2653
|
+
// Constructing a browser follower starts its init handshake. Do that before
|
|
2654
|
+
// asking whether this is a newly attaching peer.
|
|
831
2655
|
const client = this.getClient(query._schema);
|
|
2656
|
+
// A newly attached browser peer does not yet know whether its worker can
|
|
2657
|
+
// open durable storage. Keep the native subscription installation in the
|
|
2658
|
+
// old immediate order (several hooks may register together), but hold its
|
|
2659
|
+
// public deltas until that one admission succeeds. This makes a corrupt
|
|
2660
|
+
// store fail the subscription that triggered it without publishing a
|
|
2661
|
+
// misleading empty opening or perturbing maintained-view registration.
|
|
2662
|
+
const initialReadiness = this.connection.initialExplicitOfflineState();
|
|
2663
|
+
const manager = new SubscriptionManager();
|
|
832
2664
|
const builderJson = query._build();
|
|
833
|
-
const builtQuery = normalizeBuiltQuery(JSON.parse(builderJson)
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
2665
|
+
const builtQuery = normalizeBuiltQuery(JSON.parse(builderJson));
|
|
2666
|
+
const planningSchema = requireSchemaWithTable(query._schema, builtQuery.table);
|
|
2667
|
+
const outputTable = resolveQueryOutputTable(planningSchema, builtQuery);
|
|
2668
|
+
let prepared = prepareTransformRead(query, builtQuery, outputTable);
|
|
2669
|
+
let wasmQuery = translateQuery(builderJson, planningSchema, prepared.physical);
|
|
2670
|
+
let deliveryReady = initialReadiness === null;
|
|
2671
|
+
const bufferedDeltas = [];
|
|
2672
|
+
const queryOptions = normalizeQueryOptions(query._schema, builtQuery.table, options);
|
|
2673
|
+
if (queryOptions.splices) {
|
|
2674
|
+
assertSpliceableColumns(planningSchema, outputTable, query, queryOptions.splices);
|
|
2675
|
+
assertSplicesReadInPart(builtQuery, prepared.physical, queryOptions.splices);
|
|
2676
|
+
}
|
|
2677
|
+
const readSession = this.getAccessContext()?.readSession ?? session;
|
|
2678
|
+
let activeSubscription = null;
|
|
2679
|
+
let unsubscribed = false;
|
|
2680
|
+
let terminalized = false;
|
|
2681
|
+
const readyAbort = new AbortController();
|
|
2682
|
+
const retireNativeSubscription = (subscription) => {
|
|
2683
|
+
subscription.retired = true;
|
|
2684
|
+
const id = subscription.id;
|
|
2685
|
+
if (id === null || subscription.nativeUnsubscribed)
|
|
2686
|
+
return;
|
|
2687
|
+
subscription.nativeUnsubscribed = true;
|
|
2688
|
+
client.unsubscribe(id);
|
|
2689
|
+
};
|
|
2690
|
+
const notifyTerminalError = (error) => {
|
|
2691
|
+
if (!onError) {
|
|
2692
|
+
console.error("Unhandled Jazz subscription error", error);
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
try {
|
|
2696
|
+
onError(error);
|
|
2697
|
+
}
|
|
2698
|
+
catch (callbackError) {
|
|
2699
|
+
console.error("Jazz subscription error callback failed", callbackError);
|
|
2700
|
+
}
|
|
2701
|
+
};
|
|
2702
|
+
const completeTerminalization = (subscription) => {
|
|
2703
|
+
// A native runtime may fail from inside subscribe(). Record the terminal
|
|
2704
|
+
// outcome immediately, but wait for subscribe() to return its handle
|
|
2705
|
+
// before detaching and notifying the owner.
|
|
2706
|
+
if (subscription.installing)
|
|
2707
|
+
return;
|
|
2708
|
+
const terminalError = subscription.terminalError;
|
|
2709
|
+
if (terminalError === null || subscription.terminalDelivered || terminalized)
|
|
2710
|
+
return;
|
|
2711
|
+
subscription.terminalDelivered = true;
|
|
2712
|
+
terminalized = true;
|
|
2713
|
+
deliveryReady = false;
|
|
2714
|
+
bufferedDeltas.length = 0;
|
|
2715
|
+
if (activeSubscription === subscription) {
|
|
2716
|
+
activeSubscription = null;
|
|
2717
|
+
}
|
|
2718
|
+
retireNativeSubscription(subscription);
|
|
2719
|
+
if (subscription.predecessor !== null) {
|
|
2720
|
+
retireNativeSubscription(subscription.predecessor);
|
|
2721
|
+
subscription.predecessor = null;
|
|
2722
|
+
}
|
|
2723
|
+
readyAbort.abort();
|
|
2724
|
+
this.liveSubscriptionEnders.delete(endLive);
|
|
2725
|
+
this.unregisterActiveQuerySubscriptionTrace(traceId);
|
|
2726
|
+
manager.clear();
|
|
2727
|
+
notifyTerminalError(terminalError);
|
|
2728
|
+
};
|
|
2729
|
+
const terminalizeSubscription = (subscription, error) => {
|
|
2730
|
+
if (unsubscribed ||
|
|
2731
|
+
terminalized ||
|
|
2732
|
+
activeSubscription !== subscription ||
|
|
2733
|
+
subscription.terminalDelivered) {
|
|
2734
|
+
return;
|
|
2735
|
+
}
|
|
2736
|
+
subscription.terminalError ??= toError(error);
|
|
2737
|
+
completeTerminalization(subscription);
|
|
2738
|
+
};
|
|
2739
|
+
const createSubscriptionGeneration = (predecessor = null) => {
|
|
2740
|
+
const subscription = {
|
|
2741
|
+
id: null,
|
|
2742
|
+
installing: false,
|
|
2743
|
+
terminalError: null,
|
|
2744
|
+
terminalDelivered: false,
|
|
2745
|
+
retired: false,
|
|
2746
|
+
nativeUnsubscribed: false,
|
|
2747
|
+
predecessor,
|
|
2748
|
+
};
|
|
2749
|
+
activeSubscription = subscription;
|
|
2750
|
+
return subscription;
|
|
2751
|
+
};
|
|
2752
|
+
const deliver = (delta) => {
|
|
2753
|
+
if (unsubscribed || terminalized || activeSubscription === null)
|
|
2754
|
+
return;
|
|
2755
|
+
if (!deliveryReady) {
|
|
2756
|
+
bufferedDeltas.push(delta);
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
try {
|
|
2760
|
+
onDelta(delta);
|
|
2761
|
+
}
|
|
2762
|
+
catch (error) {
|
|
2763
|
+
const subscription = activeSubscription;
|
|
2764
|
+
if (subscription !== null)
|
|
2765
|
+
terminalizeSubscription(subscription, error);
|
|
2766
|
+
}
|
|
2767
|
+
};
|
|
2768
|
+
const handleDelta = (delta) => {
|
|
2769
|
+
if (unsubscribed || terminalized || activeSubscription === null)
|
|
2770
|
+
return;
|
|
2771
|
+
try {
|
|
2772
|
+
deliver(manager.handleDelta(delta, prepared.transform));
|
|
2773
|
+
}
|
|
2774
|
+
catch (error) {
|
|
2775
|
+
if (!(error instanceof MissingComputedDependency) ||
|
|
2776
|
+
!prepared.computedState ||
|
|
2777
|
+
prepared.computedState.version === prepared.version)
|
|
2778
|
+
throw error;
|
|
2779
|
+
prepared = prepareTransformRead(query, builtQuery, outputTable, prepared.computedState);
|
|
2780
|
+
// A dependency found only now may make a splice column read whole.
|
|
2781
|
+
if (queryOptions.splices)
|
|
2782
|
+
assertSplicesReadInPart(builtQuery, prepared.physical, queryOptions.splices);
|
|
2783
|
+
wasmQuery = translateQuery(builderJson, planningSchema, prepared.physical);
|
|
2784
|
+
retireNativeSubscription(activeSubscription);
|
|
2785
|
+
const replacement = createSubscriptionGeneration();
|
|
2786
|
+
manager.clear();
|
|
2787
|
+
bufferedDeltas.length = 0;
|
|
2788
|
+
this.unregisterActiveQuerySubscriptionTrace(traceId);
|
|
2789
|
+
traceId = this.registerActiveQuerySubscriptionTrace(wasmQuery, builtQuery.table, queryOptions);
|
|
2790
|
+
// Native initial snapshots may arrive synchronously. Defer the next
|
|
2791
|
+
// generation to avoid recursive installation as new inputs are found.
|
|
2792
|
+
queueMicrotask(() => {
|
|
2793
|
+
if (!this.shutdownPromise)
|
|
2794
|
+
startNativeSubscription(replacement);
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
const startNativeSubscription = (subscription, subscriptionOptions = queryOptions) => {
|
|
2799
|
+
if (unsubscribed ||
|
|
2800
|
+
activeSubscription !== subscription ||
|
|
2801
|
+
subscription.retired ||
|
|
2802
|
+
subscription.terminalError !== null) {
|
|
2803
|
+
return null;
|
|
2804
|
+
}
|
|
2805
|
+
const openingDeltas = [];
|
|
2806
|
+
subscription.installing = true;
|
|
2807
|
+
try {
|
|
2808
|
+
subscription.id = client.subscribeInternal(wasmQuery, {
|
|
2809
|
+
onUpdate: (delta) => {
|
|
2810
|
+
if (unsubscribed ||
|
|
2811
|
+
activeSubscription !== subscription ||
|
|
2812
|
+
subscription.terminalError !== null) {
|
|
2813
|
+
return;
|
|
2814
|
+
}
|
|
2815
|
+
if (subscription.installing) {
|
|
2816
|
+
openingDeltas.push(delta);
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2819
|
+
try {
|
|
2820
|
+
handleDelta(delta);
|
|
2821
|
+
}
|
|
2822
|
+
catch (error) {
|
|
2823
|
+
terminalizeSubscription(subscription, error);
|
|
2824
|
+
}
|
|
2825
|
+
},
|
|
2826
|
+
onError: (error) => {
|
|
2827
|
+
terminalizeSubscription(subscription, error);
|
|
2828
|
+
},
|
|
2829
|
+
}, subscriptionOptions, readSession);
|
|
2830
|
+
}
|
|
2831
|
+
catch (error) {
|
|
2832
|
+
subscription.installing = false;
|
|
2833
|
+
terminalizeSubscription(subscription, error);
|
|
2834
|
+
return null;
|
|
2835
|
+
}
|
|
2836
|
+
subscription.installing = false;
|
|
2837
|
+
if (unsubscribed || activeSubscription !== subscription || subscription.retired) {
|
|
2838
|
+
retireNativeSubscription(subscription);
|
|
2839
|
+
return null;
|
|
2840
|
+
}
|
|
2841
|
+
if (subscription.terminalError !== null) {
|
|
2842
|
+
completeTerminalization(subscription);
|
|
2843
|
+
return null;
|
|
2844
|
+
}
|
|
2845
|
+
try {
|
|
2846
|
+
for (const delta of openingDeltas) {
|
|
2847
|
+
if (activeSubscription !== subscription || subscription.terminalError !== null)
|
|
2848
|
+
break;
|
|
2849
|
+
handleDelta(delta);
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
catch (error) {
|
|
2853
|
+
terminalizeSubscription(subscription, error);
|
|
2854
|
+
return null;
|
|
2855
|
+
}
|
|
2856
|
+
return unsubscribed || activeSubscription !== subscription || subscription.retired
|
|
2857
|
+
? null
|
|
2858
|
+
: subscription;
|
|
2859
|
+
};
|
|
2860
|
+
let traceId = this.registerActiveQuerySubscriptionTrace(wasmQuery, builtQuery.table, queryOptions);
|
|
2861
|
+
const unsubscribe = () => {
|
|
2862
|
+
if (unsubscribed)
|
|
2863
|
+
return;
|
|
2864
|
+
unsubscribed = true;
|
|
2865
|
+
this.liveSubscriptionEnders.delete(endLive);
|
|
2866
|
+
deliveryReady = false;
|
|
2867
|
+
bufferedDeltas.length = 0;
|
|
2868
|
+
readyAbort.abort();
|
|
2869
|
+
this.unregisterActiveQuerySubscriptionTrace(traceId);
|
|
2870
|
+
if (activeSubscription !== null) {
|
|
2871
|
+
retireNativeSubscription(activeSubscription);
|
|
2872
|
+
if (activeSubscription.predecessor !== null) {
|
|
2873
|
+
retireNativeSubscription(activeSubscription.predecessor);
|
|
2874
|
+
activeSubscription.predecessor = null;
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
activeSubscription = null;
|
|
849
2878
|
manager.clear();
|
|
850
2879
|
};
|
|
2880
|
+
const ready = initialReadiness
|
|
2881
|
+
?.then(() => {
|
|
2882
|
+
if (unsubscribed || terminalized || activeSubscription === null || this.shutdownPromise) {
|
|
2883
|
+
return;
|
|
2884
|
+
}
|
|
2885
|
+
deliveryReady = true;
|
|
2886
|
+
for (const delta of bufferedDeltas.splice(0)) {
|
|
2887
|
+
if (unsubscribed || terminalized || activeSubscription === null)
|
|
2888
|
+
return;
|
|
2889
|
+
deliver(delta);
|
|
2890
|
+
}
|
|
2891
|
+
})
|
|
2892
|
+
.catch((error) => {
|
|
2893
|
+
if (unsubscribed || terminalized || activeSubscription === null || this.shutdownPromise) {
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2896
|
+
// Admission failed after native registration. Terminalize the same
|
|
2897
|
+
// generation before rejecting readiness so public and framework
|
|
2898
|
+
// consumers observe one error and no buffered opening can escape.
|
|
2899
|
+
terminalizeSubscription(activeSubscription, error);
|
|
2900
|
+
throw error;
|
|
2901
|
+
});
|
|
2902
|
+
// The public error callback owns terminal notification. Retain a rejection
|
|
2903
|
+
// handler because the readiness property is an internal orchestration seam
|
|
2904
|
+
// and public Db.subscribe callers are not required to consume it.
|
|
2905
|
+
if (ready)
|
|
2906
|
+
void ready.catch(() => undefined);
|
|
2907
|
+
const initialSubscription = createSubscriptionGeneration();
|
|
2908
|
+
const endLive = (error) => {
|
|
2909
|
+
if (activeSubscription !== null)
|
|
2910
|
+
terminalizeSubscription(activeSubscription, error);
|
|
2911
|
+
};
|
|
2912
|
+
this.liveSubscriptionEnders.add(endLive);
|
|
2913
|
+
// The native maintained stream owns both the opening snapshot and later
|
|
2914
|
+
// changes. Do not fabricate an empty opening or race it with a one-shot
|
|
2915
|
+
// cache read: that snapshot may be older than deltas already delivered.
|
|
2916
|
+
const requirement = queryOptions.tier === "remote" ? "server" : "runtime";
|
|
2917
|
+
if (this.connection.shouldDeferSubscriptionStart(requirement)) {
|
|
2918
|
+
// The worker can only classify the initial authority-tier snapshot as
|
|
2919
|
+
// settled after its own server transport is attached. Delay native
|
|
2920
|
+
// subscription creation until that topology is ready; the native stream
|
|
2921
|
+
// then owns the settled-snapshot gate and remains the sole data source.
|
|
2922
|
+
void this.ensureReady(requirement, readyAbort.signal)
|
|
2923
|
+
.then(() => startNativeSubscription(initialSubscription))
|
|
2924
|
+
.catch((error) => {
|
|
2925
|
+
if (unsubscribed || readyAbort.signal.aborted || this.shutdownPromise)
|
|
2926
|
+
return;
|
|
2927
|
+
terminalizeSubscription(initialSubscription, error);
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
else {
|
|
2931
|
+
startNativeSubscription(initialSubscription);
|
|
2932
|
+
}
|
|
2933
|
+
const handle = unsubscribe;
|
|
2934
|
+
if (ready)
|
|
2935
|
+
Object.defineProperty(handle, "ready", { value: ready });
|
|
2936
|
+
return handle;
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* @internal The session that owned this Db replaced it. Its live queries
|
|
2940
|
+
* end with a {@link DbReplacedError} naming the fix, and its reads, writes
|
|
2941
|
+
* and listeners throw it, so code that kept the handle fails loudly instead
|
|
2942
|
+
* of going silent.
|
|
2943
|
+
*/
|
|
2944
|
+
markReplaced(reason) {
|
|
2945
|
+
this.successor?.markReplaced(reason);
|
|
2946
|
+
if (this.replaced)
|
|
2947
|
+
return;
|
|
2948
|
+
const error = new DbReplacedError(reason);
|
|
2949
|
+
this.replaced = error;
|
|
2950
|
+
for (const end of Array.from(this.liveSubscriptionEnders))
|
|
2951
|
+
end(error);
|
|
2952
|
+
this.liveSubscriptionEnders.clear();
|
|
2953
|
+
}
|
|
2954
|
+
/**
|
|
2955
|
+
* @internal The session upgraded this Db to `next`, the local-first Db of
|
|
2956
|
+
* the same account. This Db becomes a handle on `next`: its live queries
|
|
2957
|
+
* and listeners move there (each query's first result there replaces what
|
|
2958
|
+
* it had, so nothing goes back to loading), and its reads and writes go
|
|
2959
|
+
* there from now on. Only its own runtime stays behind, for the session to
|
|
2960
|
+
* shut down once its writes are uploaded.
|
|
2961
|
+
*/
|
|
2962
|
+
adoptSuccessor(next) {
|
|
2963
|
+
if (this.successor)
|
|
2964
|
+
throw new Error("This Db already has a successor");
|
|
2965
|
+
const own = this.currentRuntime();
|
|
2966
|
+
this.successor = next;
|
|
2967
|
+
// A read still waiting for this runtime's server (the server is down)
|
|
2968
|
+
// asks `next` instead: only the drain below waits for that server.
|
|
2969
|
+
own?.endUnsentReads?.();
|
|
2970
|
+
// Upload what this runtime still holds, then stop it. Until then its
|
|
2971
|
+
// writes count in the sync status and in waitForSync.
|
|
2972
|
+
let draining = true;
|
|
2973
|
+
const drainListeners = new Set();
|
|
2974
|
+
const drained = this.shutdown({ waitForSync: true }).finally(() => {
|
|
2975
|
+
draining = false;
|
|
2976
|
+
for (const listener of Array.from(drainListeners))
|
|
2977
|
+
listener();
|
|
2978
|
+
});
|
|
2979
|
+
void drained.catch(() => { });
|
|
2980
|
+
this.drain = {
|
|
2981
|
+
done: drained,
|
|
2982
|
+
abort: () => {
|
|
2983
|
+
if (draining)
|
|
2984
|
+
this.abortGracefulShutdown();
|
|
2985
|
+
},
|
|
2986
|
+
};
|
|
2987
|
+
let combined = null;
|
|
2988
|
+
const syncStatus = () => {
|
|
2989
|
+
const ahead = next.getSyncStatus();
|
|
2990
|
+
if (!draining)
|
|
2991
|
+
return ahead;
|
|
2992
|
+
const own = Db.prototype.getSyncStatus.call(this);
|
|
2993
|
+
const status = {
|
|
2994
|
+
link: ahead.link,
|
|
2995
|
+
pendingUploads: ahead.pendingUploads + own.pendingUploads,
|
|
2996
|
+
synced: ahead.synced && own.pendingUploads === 0,
|
|
2997
|
+
};
|
|
2998
|
+
if (combined && sameSyncStatus(status, combined))
|
|
2999
|
+
return combined;
|
|
3000
|
+
return (combined = status);
|
|
3001
|
+
};
|
|
3002
|
+
const overrides = {
|
|
3003
|
+
getSyncStatus: syncStatus,
|
|
3004
|
+
syncStatusChangeRegistration: (listener) => {
|
|
3005
|
+
let published = syncStatus();
|
|
3006
|
+
const publish = () => {
|
|
3007
|
+
const status = syncStatus();
|
|
3008
|
+
if (status === published)
|
|
3009
|
+
return;
|
|
3010
|
+
published = status;
|
|
3011
|
+
listener(status);
|
|
3012
|
+
};
|
|
3013
|
+
const stopAhead = next.onSyncStatusChange(publish);
|
|
3014
|
+
const stopOwn = draining ? this.onSyncStatusChangeHere(publish) : () => { };
|
|
3015
|
+
drainListeners.add(publish);
|
|
3016
|
+
return () => {
|
|
3017
|
+
stopAhead();
|
|
3018
|
+
stopOwn();
|
|
3019
|
+
drainListeners.delete(publish);
|
|
3020
|
+
};
|
|
3021
|
+
},
|
|
3022
|
+
waitForSync: async (options = {}) => {
|
|
3023
|
+
await Promise.all([
|
|
3024
|
+
next.waitForSync(options),
|
|
3025
|
+
draining ? this.waitForOwnSync(options, drained) : undefined,
|
|
3026
|
+
]);
|
|
3027
|
+
},
|
|
3028
|
+
// The app's offline toggle covers both runtimes while the thin one
|
|
3029
|
+
// still uploads.
|
|
3030
|
+
disconnect: async () => {
|
|
3031
|
+
await Promise.all([next.disconnect(), draining ? this.connection.disconnect() : undefined]);
|
|
3032
|
+
},
|
|
3033
|
+
reconnect: async () => {
|
|
3034
|
+
await Promise.all([next.reconnect(), draining ? this.connection.reconnect() : undefined]);
|
|
3035
|
+
},
|
|
3036
|
+
};
|
|
3037
|
+
for (const name of FORWARDED_TO_SUCCESSOR) {
|
|
3038
|
+
Object.defineProperty(this, name, {
|
|
3039
|
+
configurable: true,
|
|
3040
|
+
value: overrides[name] ??
|
|
3041
|
+
((...args) => next[name](...args)),
|
|
3042
|
+
});
|
|
3043
|
+
}
|
|
3044
|
+
Object.defineProperty(this, "syncStatusChangeRegistration", {
|
|
3045
|
+
configurable: true,
|
|
3046
|
+
value: overrides.syncStatusChangeRegistration,
|
|
3047
|
+
});
|
|
3048
|
+
// An app that took the thin Db offline keeps the local-first one offline.
|
|
3049
|
+
// The last toggle the app asked for counts, even while it is in flight.
|
|
3050
|
+
if (this.offlineRequested ?? this.connection.isExplicitlyOffline())
|
|
3051
|
+
void next.disconnect().catch(() => { });
|
|
3052
|
+
// Rejections this Db reported before anyone listened go to the listeners
|
|
3053
|
+
// on the successor (already logged here as unhandled).
|
|
3054
|
+
for (const event of this.pendingMutationErrorEvents.splice(0))
|
|
3055
|
+
next.handleMutationError(event, true);
|
|
3056
|
+
for (const entry of Array.from(this.movable))
|
|
3057
|
+
entry.move(next);
|
|
3058
|
+
this.movable.clear();
|
|
3059
|
+
}
|
|
3060
|
+
/**
|
|
3061
|
+
* Wait for this Db's own runtime's writes, as {@link waitForSync} does
|
|
3062
|
+
* (rejecting with the server's error for a rejected one), while it drains
|
|
3063
|
+
* after the upgrade. The drain ending is the wait ending.
|
|
3064
|
+
*/
|
|
3065
|
+
async waitForOwnSync(options, drained) {
|
|
3066
|
+
const { timeoutMs, signal } = options;
|
|
3067
|
+
validateWriteWaitTimeout(timeoutMs);
|
|
3068
|
+
signal?.throwIfAborted();
|
|
3069
|
+
const control = new AbortController();
|
|
3070
|
+
const forward = () => control.abort(signal.reason);
|
|
3071
|
+
signal?.addEventListener("abort", forward, { once: true });
|
|
3072
|
+
const timer = timeoutMs === undefined
|
|
3073
|
+
? undefined
|
|
3074
|
+
: setTimeout(() => control.abort(new WriteWaitTimeoutError("global", timeoutMs)), timeoutMs);
|
|
3075
|
+
try {
|
|
3076
|
+
// The thin runtime's writes are answered (a rejection fails the wait),
|
|
3077
|
+
// or its drain ends: then it has nothing left to wait for.
|
|
3078
|
+
await Promise.race([this.connection.waitForSync(control.signal), drained]);
|
|
3079
|
+
}
|
|
3080
|
+
finally {
|
|
3081
|
+
if (timer !== undefined)
|
|
3082
|
+
clearTimeout(timer);
|
|
3083
|
+
signal?.removeEventListener("abort", forward);
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
/** The app's last {@link disconnect} (true) or {@link reconnect} (false). */
|
|
3087
|
+
offlineRequested;
|
|
3088
|
+
/** Set once this Db adopted a successor: its own runtime's last uploads. */
|
|
3089
|
+
drain = null;
|
|
3090
|
+
/**
|
|
3091
|
+
* @internal Stop this Db's own runtime after the upgrade. With
|
|
3092
|
+
* `waitForSync`, its writes upload first, the way a local-first client's
|
|
3093
|
+
* do when it shuts down; without, they are dropped, as when a thin client
|
|
3094
|
+
* closes.
|
|
3095
|
+
*/
|
|
3096
|
+
async stopOwnRuntime(options = {}) {
|
|
3097
|
+
const drain = this.drain;
|
|
3098
|
+
if (!drain)
|
|
3099
|
+
return this.shutdown(options);
|
|
3100
|
+
if (!options.waitForSync)
|
|
3101
|
+
drain.abort();
|
|
3102
|
+
await drain.done.catch(() => { });
|
|
3103
|
+
// An aborted or failed drain leaves the runtime open: stop it now.
|
|
3104
|
+
await Db.prototype.shutdown.call(this);
|
|
3105
|
+
}
|
|
3106
|
+
/** @internal The Db that does this one's work now: itself, or its successor. */
|
|
3107
|
+
current() {
|
|
3108
|
+
return this.successor?.current() ?? this;
|
|
851
3109
|
}
|
|
852
3110
|
/**
|
|
853
3111
|
* Shutdown the Db and release all resources.
|
|
854
|
-
* Closes
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (this.
|
|
886
|
-
|
|
887
|
-
|
|
3112
|
+
* Closes the Db's runtime client.
|
|
3113
|
+
*
|
|
3114
|
+
* Idempotent: concurrent or repeated calls share the same in-flight promise.
|
|
3115
|
+
*/
|
|
3116
|
+
shutdown(options = {}) {
|
|
3117
|
+
if (this.shutdownPromise)
|
|
3118
|
+
return this.shutdownPromise;
|
|
3119
|
+
// Publish the promise before teardown can synchronously call back into Db.
|
|
3120
|
+
let resolveShutdown;
|
|
3121
|
+
const shutdown = new Promise((resolve) => {
|
|
3122
|
+
resolveShutdown = resolve;
|
|
3123
|
+
});
|
|
3124
|
+
this.shutdownPromise = shutdown;
|
|
3125
|
+
resolveShutdown(this.runShutdown(options));
|
|
3126
|
+
return shutdown;
|
|
3127
|
+
}
|
|
3128
|
+
cancelSyncShutdown;
|
|
3129
|
+
/** @internal Credential invalidation must interrupt a graceful sync wait. */
|
|
3130
|
+
abortGracefulShutdown() {
|
|
3131
|
+
this.cancelSyncShutdown?.();
|
|
3132
|
+
}
|
|
3133
|
+
assertOpen() {
|
|
3134
|
+
if (this.replaced)
|
|
3135
|
+
throw this.replaced;
|
|
3136
|
+
if (this.shutdownPromise) {
|
|
3137
|
+
throw new Error("Cannot operate on a Db that is shutting down or closed.");
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
shutdownListeners = new Set();
|
|
3141
|
+
/** @internal Dispose account refresh and invalidation observers with the context. */
|
|
3142
|
+
onShutdown(listener) {
|
|
3143
|
+
if (this.shutdownPromise)
|
|
3144
|
+
listener();
|
|
3145
|
+
else
|
|
3146
|
+
this.shutdownListeners.add(listener);
|
|
3147
|
+
return () => this.shutdownListeners.delete(listener);
|
|
3148
|
+
}
|
|
3149
|
+
async runShutdown(options) {
|
|
3150
|
+
if (options.waitForSync) {
|
|
3151
|
+
const syncAbort = new AbortController();
|
|
3152
|
+
const cancelled = new Promise((_resolve, reject) => {
|
|
3153
|
+
this.cancelSyncShutdown = () => {
|
|
3154
|
+
syncAbort.abort();
|
|
3155
|
+
reject(new Error("Graceful shutdown cancelled"));
|
|
3156
|
+
};
|
|
3157
|
+
});
|
|
3158
|
+
try {
|
|
3159
|
+
await Promise.race([
|
|
3160
|
+
this.runtimeSource.waitForPendingWrites?.(syncAbort.signal) ??
|
|
3161
|
+
this.connection.waitForPendingWrites(),
|
|
3162
|
+
cancelled,
|
|
3163
|
+
]);
|
|
3164
|
+
}
|
|
3165
|
+
catch (error) {
|
|
3166
|
+
syncAbort.abort();
|
|
3167
|
+
this.shutdownPromise = null;
|
|
3168
|
+
throw new GracefulShutdownSyncError(error);
|
|
3169
|
+
}
|
|
3170
|
+
finally {
|
|
3171
|
+
this.cancelSyncShutdown = undefined;
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
for (const listener of this.shutdownListeners) {
|
|
3175
|
+
try {
|
|
3176
|
+
listener();
|
|
3177
|
+
}
|
|
3178
|
+
catch (error) {
|
|
3179
|
+
console.error("Context cleanup failed", error);
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
this.shutdownListeners.clear();
|
|
3183
|
+
this.shutdownAbort.abort();
|
|
3184
|
+
if (this.localFirstRefreshTimer) {
|
|
3185
|
+
clearTimeout(this.localFirstRefreshTimer);
|
|
3186
|
+
this.localFirstRefreshTimer = null;
|
|
3187
|
+
}
|
|
3188
|
+
this.clearActiveQuerySubscriptionTraces();
|
|
3189
|
+
this.mutationErrorListeners.clear();
|
|
3190
|
+
try {
|
|
3191
|
+
await this.connection.shutdown();
|
|
3192
|
+
}
|
|
3193
|
+
finally {
|
|
3194
|
+
await this.runtimeSource.shutdown();
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
notifyActiveQuerySubscriptionTraceListeners() {
|
|
3198
|
+
if (this.activeQuerySubscriptionTraceListeners.size === 0) {
|
|
3199
|
+
return;
|
|
3200
|
+
}
|
|
3201
|
+
const snapshot = this.getActiveQuerySubscriptions();
|
|
3202
|
+
for (const listener of this.activeQuerySubscriptionTraceListeners) {
|
|
3203
|
+
listener(snapshot);
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
registerActiveQuerySubscriptionTrace(queryJson, _queryTable, options) {
|
|
3207
|
+
if (!this.config.devMode) {
|
|
3208
|
+
return null;
|
|
3209
|
+
}
|
|
3210
|
+
const resolvedOptions = resolveEffectiveQueryExecutionOptions(this.config, options);
|
|
3211
|
+
// Inspector-only reads must not recursively appear in the inspector's
|
|
3212
|
+
// own subscription list. Public local-first still propagates and is listed.
|
|
3213
|
+
if (resolvedOptions.tier === "local-only")
|
|
3214
|
+
return null;
|
|
3215
|
+
const payload = this.parseRuntimeQueryTracePayload(queryJson);
|
|
3216
|
+
const traceId = `sub-${this.nextActiveQuerySubscriptionTraceId++}`;
|
|
3217
|
+
this.activeQuerySubscriptionTraces.set(traceId, {
|
|
3218
|
+
id: traceId,
|
|
3219
|
+
query: queryJson,
|
|
3220
|
+
table: payload.table,
|
|
3221
|
+
branches: payload.branches,
|
|
3222
|
+
tier: resolvedOptions.tier,
|
|
3223
|
+
createdAt: new Date().toISOString(),
|
|
3224
|
+
stack: trimSubscriptionTraceStack(new Error().stack),
|
|
3225
|
+
visibility: resolvedOptions.visibility ?? "public",
|
|
3226
|
+
});
|
|
3227
|
+
this.notifyActiveQuerySubscriptionTraceListeners();
|
|
3228
|
+
return traceId;
|
|
3229
|
+
}
|
|
3230
|
+
unregisterActiveQuerySubscriptionTrace(traceId) {
|
|
3231
|
+
if (!traceId) {
|
|
3232
|
+
return;
|
|
3233
|
+
}
|
|
3234
|
+
if (!this.activeQuerySubscriptionTraces.delete(traceId)) {
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
this.notifyActiveQuerySubscriptionTraceListeners();
|
|
3238
|
+
}
|
|
3239
|
+
clearActiveQuerySubscriptionTraces() {
|
|
3240
|
+
if (this.activeQuerySubscriptionTraces.size === 0) {
|
|
3241
|
+
return;
|
|
3242
|
+
}
|
|
3243
|
+
this.activeQuerySubscriptionTraces.clear();
|
|
3244
|
+
this.notifyActiveQuerySubscriptionTraceListeners();
|
|
3245
|
+
}
|
|
3246
|
+
parseRuntimeQueryTracePayload(queryJson) {
|
|
3247
|
+
try {
|
|
3248
|
+
const parsed = JSON.parse(queryJson);
|
|
3249
|
+
const table = typeof parsed.table === "string" ? parsed.table : "unknown";
|
|
3250
|
+
const branches = Array.isArray(parsed.branches)
|
|
3251
|
+
? parsed.branches.filter((branch) => typeof branch === "string")
|
|
3252
|
+
: [];
|
|
3253
|
+
return {
|
|
3254
|
+
table,
|
|
3255
|
+
branches,
|
|
3256
|
+
};
|
|
3257
|
+
}
|
|
3258
|
+
catch {
|
|
3259
|
+
return {
|
|
3260
|
+
table: "unknown",
|
|
3261
|
+
branches: [],
|
|
3262
|
+
};
|
|
888
3263
|
}
|
|
889
3264
|
}
|
|
890
3265
|
}
|
|
891
3266
|
/**
|
|
892
|
-
*
|
|
3267
|
+
* Generate a 32-byte ephemeral seed for anonymous auth.
|
|
3268
|
+
*
|
|
3269
|
+
* Uses Web Crypto or the installed native host's OS entropy.
|
|
893
3270
|
*/
|
|
894
|
-
function
|
|
895
|
-
|
|
3271
|
+
function generateEphemeralSeedBase64Url() {
|
|
3272
|
+
const bytes = runtimeRandomBytes(32);
|
|
3273
|
+
let binary = "";
|
|
3274
|
+
for (const b of bytes)
|
|
3275
|
+
binary += String.fromCharCode(b);
|
|
3276
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
896
3277
|
}
|
|
897
3278
|
/**
|
|
898
3279
|
* Create a new Db instance with the given configuration.
|
|
899
3280
|
*
|
|
900
|
-
* This is an **async** factory function that pre-loads the
|
|
901
|
-
* After creation, mutations (insert
|
|
3281
|
+
* This is an **async** factory function that pre-loads the runtime source.
|
|
3282
|
+
* After creation, local-first mutations (`insert`/`update`/`delete`) are synchronous.
|
|
3283
|
+
* Use the `wait` method when you need a Promise that resolves at a durability tier.
|
|
902
3284
|
*
|
|
903
|
-
*
|
|
904
|
-
* OPFS persistence. In Node.js, uses in-memory storage.
|
|
3285
|
+
* Browser and backend runtimes open the native runtime in-process.
|
|
905
3286
|
*
|
|
906
3287
|
* @param config Database configuration
|
|
907
3288
|
* @returns Promise resolving to Db instance ready for queries and mutations
|
|
@@ -914,11 +3295,190 @@ function isBrowser() {
|
|
|
914
3295
|
* });
|
|
915
3296
|
* ```
|
|
916
3297
|
*/
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
3298
|
+
function createRuntimeTokenOptions(secret, audience, ttlSeconds) {
|
|
3299
|
+
return {
|
|
3300
|
+
secret,
|
|
3301
|
+
audience,
|
|
3302
|
+
ttlSeconds,
|
|
3303
|
+
nowSeconds: BigInt(Math.floor(Date.now() / 1000)),
|
|
3304
|
+
};
|
|
3305
|
+
}
|
|
3306
|
+
/**
|
|
3307
|
+
* @internal Start the persistent browser worker for an account context before
|
|
3308
|
+
* its runtime and credential are ready. An account's browser root and worker
|
|
3309
|
+
* are named by its account id and registry alone, so the SharedWorker can boot
|
|
3310
|
+
* and compile its WASM while the page loads its own runtime and resolves auth.
|
|
3311
|
+
* Returns undefined when the root depends on a credential or no worker is used.
|
|
3312
|
+
*/
|
|
3313
|
+
export function startBrowserWorkerLease(config, runtimeSource) {
|
|
3314
|
+
if (!runtimeSource.supportsBrowserWorker ||
|
|
3315
|
+
!isBrowserRuntime() ||
|
|
3316
|
+
resolveStorageDriver(config.driver).type !== "persistent" ||
|
|
3317
|
+
!config.accountId ||
|
|
3318
|
+
!config.accountRegistryAuthority ||
|
|
3319
|
+
config.adminSecret ||
|
|
3320
|
+
config.runtimeSources?.browserWorkerPort)
|
|
3321
|
+
return undefined;
|
|
3322
|
+
const lease = runtimeSource.acquireBrowserForegroundNodeLease(config);
|
|
3323
|
+
// Observed by the Db that adopts it, or returned by releaseUnusedLease.
|
|
3324
|
+
void lease.catch(() => undefined);
|
|
3325
|
+
leaseRoots.set(lease, browserLeaseRoot(config));
|
|
3326
|
+
return lease;
|
|
3327
|
+
}
|
|
3328
|
+
/** The worker realm, physical root and owner a lease was acquired for. */
|
|
3329
|
+
const leaseRoots = new WeakMap();
|
|
3330
|
+
function browserLeaseRoot(config) {
|
|
3331
|
+
try {
|
|
3332
|
+
const sources = config.runtimeSources;
|
|
3333
|
+
return JSON.stringify([
|
|
3334
|
+
resolveDefaultPersistentDbName(config),
|
|
3335
|
+
createBrowserStorageOwner(config),
|
|
3336
|
+
sources?.wasmUrl ?? null,
|
|
3337
|
+
sources?.baseUrl ?? null,
|
|
3338
|
+
sources?.brokerWorkerUrl ?? null,
|
|
3339
|
+
sources?.wasmVersion ?? null,
|
|
3340
|
+
Boolean(sources?.wasmModule || sources?.wasmSource),
|
|
3341
|
+
]);
|
|
3342
|
+
}
|
|
3343
|
+
catch {
|
|
3344
|
+
return undefined;
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
/**
|
|
3348
|
+
* An early lease is only adopted for the exact root it was acquired for; a
|
|
3349
|
+
* config whose principal or assets changed while it resolved gets its own.
|
|
3350
|
+
*/
|
|
3351
|
+
function leaseMatches(lease, config) {
|
|
3352
|
+
const root = leaseRoots.get(lease);
|
|
3353
|
+
return root !== undefined && root === browserLeaseRoot(config);
|
|
3354
|
+
}
|
|
3355
|
+
/**
|
|
3356
|
+
* @internal Return a lease that no Db adopted, keeping its node reusable.
|
|
3357
|
+
* Resolves once the worker has the lease back (or it never issued one), so a
|
|
3358
|
+
* replacement acquired afterwards never queues behind it.
|
|
3359
|
+
*/
|
|
3360
|
+
export async function releaseUnusedLease(lease) {
|
|
3361
|
+
if (!lease || leaseClaimed.has(lease))
|
|
3362
|
+
return;
|
|
3363
|
+
leaseClaimed.add(lease);
|
|
3364
|
+
try {
|
|
3365
|
+
const acquired = await lease;
|
|
3366
|
+
await acquired.returnWithHighWater(acquired.confirmedTxTime);
|
|
3367
|
+
}
|
|
3368
|
+
catch {
|
|
3369
|
+
// A lease that failed to arrive, or could not be returned, holds nothing.
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
export async function createDbWithRuntimeSource(config, runtimeSource, earlyLease) {
|
|
3373
|
+
let lease = earlyLease;
|
|
3374
|
+
try {
|
|
3375
|
+
return await openDbWithRuntimeSource(config, runtimeSource, () => {
|
|
3376
|
+
lease ??= startBrowserWorkerLease(config, runtimeSource);
|
|
3377
|
+
return lease;
|
|
3378
|
+
});
|
|
3379
|
+
}
|
|
3380
|
+
finally {
|
|
3381
|
+
void releaseUnusedLease(lease);
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
/** Leases already adopted by a Db or released; neither may happen twice. */
|
|
3385
|
+
const leaseClaimed = new WeakSet();
|
|
3386
|
+
async function openDbWithRuntimeSource(config, runtimeSource, startLease) {
|
|
3387
|
+
assertAccountConfig(config);
|
|
3388
|
+
assertNoClientBackendSecret(config);
|
|
3389
|
+
if (config.secret && config.cookieSession) {
|
|
3390
|
+
throw new Error("DbConfig error: secret and cookieSession are mutually exclusive");
|
|
3391
|
+
}
|
|
3392
|
+
if (config.secret && config.jwtToken) {
|
|
3393
|
+
throw new Error("DbConfig error: secret and jwtToken are mutually exclusive");
|
|
3394
|
+
}
|
|
3395
|
+
if (config.jwtToken && config.cookieSession) {
|
|
3396
|
+
throw new Error("DbConfig error: jwtToken and cookieSession are mutually exclusive");
|
|
3397
|
+
}
|
|
3398
|
+
// Validate a durable root before loading a runtime or creating any author-
|
|
3399
|
+
// adjacent state. This makes malformed/legacy input fail deterministically
|
|
3400
|
+
// even when a platform artifact cannot be loaded.
|
|
3401
|
+
const parsedLocalFirstSeed = config.secret ? authSecretSeedForMinting(config.secret) : null;
|
|
3402
|
+
let resolvedConfig = { ...config };
|
|
3403
|
+
setTrustedReservedSession(resolvedConfig, getTrustedReservedSession(config));
|
|
3404
|
+
// Boot the worker while this page loads its own runtime.
|
|
3405
|
+
const earlyLease = startLease();
|
|
3406
|
+
await runtimeSource.load(config);
|
|
3407
|
+
const { secret: _secret, jwtToken: _jwtToken, cookieSession: _cookieSession, ...configWithoutAuth } = config;
|
|
3408
|
+
// Local-first auth: resolve seed and mint a JWT
|
|
3409
|
+
const localFirstSecret = parsedLocalFirstSeed;
|
|
3410
|
+
if (localFirstSecret) {
|
|
3411
|
+
const secret = localFirstSecret;
|
|
3412
|
+
if (!config.jwtToken) {
|
|
3413
|
+
const jwtToken = runtimeSource.mintLocalFirstToken(createRuntimeTokenOptions(secret, clientScope(config), 3600));
|
|
3414
|
+
const trustedReservedSession = internalSessionFromVerifiedReservedJwtPayload(parseJwtPayload(jwtToken) ?? {}, "local-first");
|
|
3415
|
+
resolvedConfig = { ...configWithoutAuth, jwtToken };
|
|
3416
|
+
setTrustedReservedSession(resolvedConfig, trustedReservedSession);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
else if (!config.jwtToken && !config.cookieSession && !config.adminSecret) {
|
|
3420
|
+
// Anonymous: mint an ephemeral keypair + anonymous JWT.
|
|
3421
|
+
// Admin-secret clients intentionally stay sessionless so local policy
|
|
3422
|
+
// evaluation does not preempt backend-authorized transport writes.
|
|
3423
|
+
const ephemeralSeed = generateEphemeralSeedBase64Url();
|
|
3424
|
+
const jwtToken = runtimeSource.mintAnonymousToken(createRuntimeTokenOptions(ephemeralSeed, clientScope(config), 3600));
|
|
3425
|
+
const trustedReservedSession = internalSessionFromVerifiedReservedJwtPayload(parseJwtPayload(jwtToken) ?? {}, "anonymous");
|
|
3426
|
+
resolvedConfig = { ...configWithoutAuth, jwtToken };
|
|
3427
|
+
setTrustedReservedSession(resolvedConfig, trustedReservedSession);
|
|
3428
|
+
}
|
|
3429
|
+
copyAccountConfigAdmission(config, resolvedConfig);
|
|
3430
|
+
runtimeSource.admitConfig(resolvedConfig);
|
|
3431
|
+
const driver = resolveStorageDriver(resolvedConfig.driver);
|
|
3432
|
+
const browserWorker = runtimeSource.supportsBrowserWorker && isBrowserRuntime() && driver.type === "persistent";
|
|
3433
|
+
const adoptedLease = earlyLease && browserWorker && leaseMatches(earlyLease, resolvedConfig)
|
|
3434
|
+
? earlyLease
|
|
3435
|
+
: undefined;
|
|
3436
|
+
if (adoptedLease) {
|
|
3437
|
+
leaseClaimed.add(adoptedLease);
|
|
3438
|
+
}
|
|
3439
|
+
else if (earlyLease) {
|
|
3440
|
+
// Hand a lease for some other root back before this Db acquires its own,
|
|
3441
|
+
// so the two are never held, or queued behind each other, at once.
|
|
3442
|
+
await releaseUnusedLease(earlyLease);
|
|
3443
|
+
}
|
|
3444
|
+
const db = browserWorker
|
|
3445
|
+
? await Db.createWithBrowserWorker(resolvedConfig, runtimeSource, adoptedLease)
|
|
3446
|
+
: await Db.createWithDirectConnection(resolvedConfig, runtimeSource);
|
|
3447
|
+
if (localFirstSecret) {
|
|
3448
|
+
db.initLocalFirstAuth(localFirstSecret, 3600, !config.jwtToken);
|
|
3449
|
+
}
|
|
3450
|
+
return db;
|
|
3451
|
+
}
|
|
3452
|
+
/** Keep server-only admission credentials out of every client runtime factory. */
|
|
3453
|
+
export function assertNoClientBackendSecret(config) {
|
|
3454
|
+
if (Object.hasOwn(config, "backendSecret")) {
|
|
3455
|
+
throw new Error("DbConfig does not accept backendSecret. Run Jazz in your backend with createJazz() from jazz-tools/backend instead.");
|
|
921
3456
|
}
|
|
922
|
-
|
|
3457
|
+
}
|
|
3458
|
+
function isBrowserRuntime() {
|
|
3459
|
+
return typeof window !== "undefined" && typeof Worker !== "undefined";
|
|
3460
|
+
}
|
|
3461
|
+
const credentialRenewers = new WeakMap();
|
|
3462
|
+
/**
|
|
3463
|
+
* @internal Declare that the caller renews this Db's credential whenever the
|
|
3464
|
+
* server refuses it, until the returned release is called. Global write waits
|
|
3465
|
+
* then outlast a renewable refusal instead of failing (#3923).
|
|
3466
|
+
*/
|
|
3467
|
+
export function holdCredentialRenewal(db) {
|
|
3468
|
+
credentialRenewers.set(db, (credentialRenewers.get(db) ?? 0) + 1);
|
|
3469
|
+
let released = false;
|
|
3470
|
+
return () => {
|
|
3471
|
+
if (released)
|
|
3472
|
+
return;
|
|
3473
|
+
released = true;
|
|
3474
|
+
credentialRenewers.set(db, (credentialRenewers.get(db) ?? 1) - 1);
|
|
3475
|
+
};
|
|
3476
|
+
}
|
|
3477
|
+
/** `error` says the runtime closed, also when a connection wrapped it as its cause. */
|
|
3478
|
+
function isRuntimeClosed(error) {
|
|
3479
|
+
for (let current = error; current instanceof Error; current = current.cause)
|
|
3480
|
+
if (current instanceof RuntimeClosedError)
|
|
3481
|
+
return true;
|
|
3482
|
+
return false;
|
|
923
3483
|
}
|
|
924
3484
|
//# sourceMappingURL=db.js.map
|