@earendil-works/chord 1.4.0 → 1.5.0
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/CHANGELOG.md +41 -0
- package/README.md +79 -14
- package/dist/cell.d.ts +7 -7
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js.map +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/contract.d.ts +51 -52
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +19 -24
- package/dist/contract.js.map +1 -1
- package/dist/delta/apply-immutable-trusted.js +3 -4
- package/dist/delta/apply-immutable-trusted.js.map +1 -1
- package/dist/delta/diff.d.ts.map +1 -1
- package/dist/delta/diff.js +5 -3
- package/dist/delta/diff.js.map +1 -1
- package/dist/delta/index.d.ts +9 -1
- package/dist/delta/index.d.ts.map +1 -1
- package/dist/delta/index.js +15 -11
- package/dist/delta/index.js.map +1 -1
- package/dist/delta/pending.d.ts +36 -0
- package/dist/delta/pending.d.ts.map +1 -0
- package/dist/delta/pending.js +143 -0
- package/dist/delta/pending.js.map +1 -0
- package/dist/delta/tracker.d.ts +12 -0
- package/dist/delta/tracker.d.ts.map +1 -1
- package/dist/delta/tracker.js +109 -39
- package/dist/delta/tracker.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +9 -7
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/next/contracts/accepts.d.ts +81 -0
- package/dist/next/contracts/accepts.d.ts.map +1 -0
- package/dist/next/contracts/accepts.js +123 -0
- package/dist/next/contracts/accepts.js.map +1 -0
- package/dist/next/contracts/contract.d.ts +121 -0
- package/dist/next/contracts/contract.d.ts.map +1 -0
- package/dist/next/contracts/contract.js +50 -0
- package/dist/next/contracts/contract.js.map +1 -0
- package/dist/next/contracts/declare.d.ts +107 -0
- package/dist/next/contracts/declare.d.ts.map +1 -0
- package/dist/next/contracts/declare.js +136 -0
- package/dist/next/contracts/declare.js.map +1 -0
- package/dist/next/contracts/evolve.d.ts +92 -0
- package/dist/next/contracts/evolve.d.ts.map +1 -0
- package/dist/next/contracts/evolve.js +179 -0
- package/dist/next/contracts/evolve.js.map +1 -0
- package/dist/next/contracts/fingerprint.d.ts +16 -0
- package/dist/next/contracts/fingerprint.d.ts.map +1 -0
- package/dist/next/contracts/fingerprint.js +50 -0
- package/dist/next/contracts/fingerprint.js.map +1 -0
- package/dist/next/contracts/history.d.ts +71 -0
- package/dist/next/contracts/history.d.ts.map +1 -0
- package/dist/next/contracts/history.js +3 -0
- package/dist/next/contracts/history.js.map +1 -0
- package/dist/next/contracts/host-kind.d.ts +40 -0
- package/dist/next/contracts/host-kind.d.ts.map +1 -0
- package/dist/next/contracts/host-kind.js +37 -0
- package/dist/next/contracts/host-kind.js.map +1 -0
- package/dist/next/contracts/index.d.ts +7 -0
- package/dist/next/contracts/index.d.ts.map +1 -0
- package/dist/next/contracts/index.js +6 -0
- package/dist/next/contracts/index.js.map +1 -0
- package/dist/next/contracts/internal.d.ts +10 -0
- package/dist/next/contracts/internal.d.ts.map +1 -0
- package/dist/next/contracts/internal.js +9 -0
- package/dist/next/contracts/internal.js.map +1 -0
- package/dist/next/contracts/names.d.ts +3 -0
- package/dist/next/contracts/names.d.ts.map +1 -0
- package/dist/next/contracts/names.js +13 -0
- package/dist/next/contracts/names.js.map +1 -0
- package/dist/next/contracts/params.d.ts +28 -0
- package/dist/next/contracts/params.d.ts.map +1 -0
- package/dist/next/contracts/params.js +50 -0
- package/dist/next/contracts/params.js.map +1 -0
- package/dist/next/contracts/schema.d.ts +102 -0
- package/dist/next/contracts/schema.d.ts.map +1 -0
- package/dist/next/contracts/schema.js +103 -0
- package/dist/next/contracts/schema.js.map +1 -0
- package/dist/next/contracts/snapshot.d.ts +16 -0
- package/dist/next/contracts/snapshot.d.ts.map +1 -0
- package/dist/next/contracts/snapshot.js +167 -0
- package/dist/next/contracts/snapshot.js.map +1 -0
- package/dist/next/data/args.d.ts +50 -0
- package/dist/next/data/args.d.ts.map +1 -0
- package/dist/next/data/args.js +83 -0
- package/dist/next/data/args.js.map +1 -0
- package/dist/next/data/errors.d.ts +73 -0
- package/dist/next/data/errors.d.ts.map +1 -0
- package/dist/next/data/errors.js +107 -0
- package/dist/next/data/errors.js.map +1 -0
- package/dist/next/data/failure.d.ts +26 -0
- package/dist/next/data/failure.d.ts.map +1 -0
- package/dist/next/data/failure.js +72 -0
- package/dist/next/data/failure.js.map +1 -0
- package/dist/next/data/index.d.ts +4 -0
- package/dist/next/data/index.d.ts.map +1 -0
- package/dist/next/data/index.js +4 -0
- package/dist/next/data/index.js.map +1 -0
- package/dist/next/data/internal.d.ts +7 -0
- package/dist/next/data/internal.d.ts.map +1 -0
- package/dist/next/data/internal.js +8 -0
- package/dist/next/data/internal.js.map +1 -0
- package/dist/next/data/params.d.ts +20 -0
- package/dist/next/data/params.d.ts.map +1 -0
- package/dist/next/data/params.js +31 -0
- package/dist/next/data/params.js.map +1 -0
- package/dist/next/data/principal.d.ts +17 -0
- package/dist/next/data/principal.d.ts.map +1 -0
- package/dist/next/data/principal.js +41 -0
- package/dist/next/data/principal.js.map +1 -0
- package/dist/next/data/validator.d.ts +12 -0
- package/dist/next/data/validator.d.ts.map +1 -0
- package/dist/next/data/validator.js +34 -0
- package/dist/next/data/validator.js.map +1 -0
- package/dist/next/documents/address-source.d.ts +20 -0
- package/dist/next/documents/address-source.d.ts.map +1 -0
- package/dist/next/documents/address-source.js +44 -0
- package/dist/next/documents/address-source.js.map +1 -0
- package/dist/next/documents/definition.d.ts +84 -0
- package/dist/next/documents/definition.d.ts.map +1 -0
- package/dist/next/documents/definition.js +73 -0
- package/dist/next/documents/definition.js.map +1 -0
- package/dist/next/documents/documents.d.ts +106 -0
- package/dist/next/documents/documents.d.ts.map +1 -0
- package/dist/next/documents/documents.js +224 -0
- package/dist/next/documents/documents.js.map +1 -0
- package/dist/next/documents/fence.d.ts +9 -0
- package/dist/next/documents/fence.d.ts.map +1 -0
- package/dist/next/documents/fence.js +15 -0
- package/dist/next/documents/fence.js.map +1 -0
- package/dist/next/documents/handles.d.ts +76 -0
- package/dist/next/documents/handles.d.ts.map +1 -0
- package/dist/next/documents/handles.js +66 -0
- package/dist/next/documents/handles.js.map +1 -0
- package/dist/next/documents/index.d.ts +4 -0
- package/dist/next/documents/index.d.ts.map +1 -0
- package/dist/next/documents/index.js +3 -0
- package/dist/next/documents/index.js.map +1 -0
- package/dist/next/documents/internal.d.ts +9 -0
- package/dist/next/documents/internal.d.ts.map +1 -0
- package/dist/next/documents/internal.js +9 -0
- package/dist/next/documents/internal.js.map +1 -0
- package/dist/next/documents/keyed-slot.d.ts +103 -0
- package/dist/next/documents/keyed-slot.d.ts.map +1 -0
- package/dist/next/documents/keyed-slot.js +395 -0
- package/dist/next/documents/keyed-slot.js.map +1 -0
- package/dist/next/documents/line.d.ts +7 -0
- package/dist/next/documents/line.d.ts.map +1 -0
- package/dist/next/documents/line.js +14 -0
- package/dist/next/documents/line.js.map +1 -0
- package/dist/next/documents/persistence.d.ts +104 -0
- package/dist/next/documents/persistence.d.ts.map +1 -0
- package/dist/next/documents/persistence.js +128 -0
- package/dist/next/documents/persistence.js.map +1 -0
- package/dist/next/documents/residency.d.ts +31 -0
- package/dist/next/documents/residency.d.ts.map +1 -0
- package/dist/next/documents/residency.js +93 -0
- package/dist/next/documents/residency.js.map +1 -0
- package/dist/next/documents/slot.d.ts +109 -0
- package/dist/next/documents/slot.d.ts.map +1 -0
- package/dist/next/documents/slot.js +181 -0
- package/dist/next/documents/slot.js.map +1 -0
- package/dist/next/documents/transaction.d.ts +133 -0
- package/dist/next/documents/transaction.d.ts.map +1 -0
- package/dist/next/documents/transaction.js +409 -0
- package/dist/next/documents/transaction.js.map +1 -0
- package/dist/next/host/activity.d.ts +31 -0
- package/dist/next/host/activity.d.ts.map +1 -0
- package/dist/next/host/activity.js +40 -0
- package/dist/next/host/activity.js.map +1 -0
- package/dist/next/host/adapted.d.ts +49 -0
- package/dist/next/host/adapted.d.ts.map +1 -0
- package/dist/next/host/adapted.js +214 -0
- package/dist/next/host/adapted.js.map +1 -0
- package/dist/next/host/attempt.d.ts +278 -0
- package/dist/next/host/attempt.d.ts.map +1 -0
- package/dist/next/host/attempt.js +1072 -0
- package/dist/next/host/attempt.js.map +1 -0
- package/dist/next/host/backoff.d.ts +29 -0
- package/dist/next/host/backoff.d.ts.map +1 -0
- package/dist/next/host/backoff.js +69 -0
- package/dist/next/host/backoff.js.map +1 -0
- package/dist/next/host/ctx.d.ts +47 -0
- package/dist/next/host/ctx.d.ts.map +1 -0
- package/dist/next/host/ctx.js +108 -0
- package/dist/next/host/ctx.js.map +1 -0
- package/dist/next/host/deadline.d.ts +12 -0
- package/dist/next/host/deadline.d.ts.map +1 -0
- package/dist/next/host/deadline.js +40 -0
- package/dist/next/host/deadline.js.map +1 -0
- package/dist/next/host/dependencies.d.ts +65 -0
- package/dist/next/host/dependencies.d.ts.map +1 -0
- package/dist/next/host/dependencies.js +115 -0
- package/dist/next/host/dependencies.js.map +1 -0
- package/dist/next/host/destination.d.ts +48 -0
- package/dist/next/host/destination.d.ts.map +1 -0
- package/dist/next/host/destination.js +101 -0
- package/dist/next/host/destination.js.map +1 -0
- package/dist/next/host/facet.d.ts +79 -0
- package/dist/next/host/facet.d.ts.map +1 -0
- package/dist/next/host/facet.js +55 -0
- package/dist/next/host/facet.js.map +1 -0
- package/dist/next/host/follow.d.ts +52 -0
- package/dist/next/host/follow.d.ts.map +1 -0
- package/dist/next/host/follow.js +207 -0
- package/dist/next/host/follow.js.map +1 -0
- package/dist/next/host/host.d.ts +495 -0
- package/dist/next/host/host.d.ts.map +1 -0
- package/dist/next/host/host.js +1075 -0
- package/dist/next/host/host.js.map +1 -0
- package/dist/next/host/index.d.ts +17 -0
- package/dist/next/host/index.d.ts.map +1 -0
- package/dist/next/host/index.js +6 -0
- package/dist/next/host/index.js.map +1 -0
- package/dist/next/host/internal.d.ts +10 -0
- package/dist/next/host/internal.d.ts.map +1 -0
- package/dist/next/host/internal.js +8 -0
- package/dist/next/host/internal.js.map +1 -0
- package/dist/next/host/members.d.ts +50 -0
- package/dist/next/host/members.d.ts.map +1 -0
- package/dist/next/host/members.js +107 -0
- package/dist/next/host/members.js.map +1 -0
- package/dist/next/host/native.d.ts +55 -0
- package/dist/next/host/native.d.ts.map +1 -0
- package/dist/next/host/native.js +92 -0
- package/dist/next/host/native.js.map +1 -0
- package/dist/next/host/object.d.ts +290 -0
- package/dist/next/host/object.d.ts.map +1 -0
- package/dist/next/host/object.js +1127 -0
- package/dist/next/host/object.js.map +1 -0
- package/dist/next/host/parked.d.ts +23 -0
- package/dist/next/host/parked.d.ts.map +1 -0
- package/dist/next/host/parked.js +79 -0
- package/dist/next/host/parked.js.map +1 -0
- package/dist/next/host/presence.d.ts +34 -0
- package/dist/next/host/presence.d.ts.map +1 -0
- package/dist/next/host/presence.js +117 -0
- package/dist/next/host/presence.js.map +1 -0
- package/dist/next/host/ref-state.d.ts +53 -0
- package/dist/next/host/ref-state.d.ts.map +1 -0
- package/dist/next/host/ref-state.js +83 -0
- package/dist/next/host/ref-state.js.map +1 -0
- package/dist/next/host/reference-keys.d.ts +36 -0
- package/dist/next/host/reference-keys.d.ts.map +1 -0
- package/dist/next/host/reference-keys.js +168 -0
- package/dist/next/host/reference-keys.js.map +1 -0
- package/dist/next/host/reference-source.d.ts +65 -0
- package/dist/next/host/reference-source.d.ts.map +1 -0
- package/dist/next/host/reference-source.js +285 -0
- package/dist/next/host/reference-source.js.map +1 -0
- package/dist/next/host/reference.d.ts +308 -0
- package/dist/next/host/reference.d.ts.map +1 -0
- package/dist/next/host/reference.js +775 -0
- package/dist/next/host/reference.js.map +1 -0
- package/dist/next/host/retry-on.d.ts +28 -0
- package/dist/next/host/retry-on.d.ts.map +1 -0
- package/dist/next/host/retry-on.js +52 -0
- package/dist/next/host/retry-on.js.map +1 -0
- package/dist/next/host/revocation.d.ts +16 -0
- package/dist/next/host/revocation.d.ts.map +1 -0
- package/dist/next/host/revocation.js +27 -0
- package/dist/next/host/revocation.js.map +1 -0
- package/dist/next/host/root.d.ts +27 -0
- package/dist/next/host/root.d.ts.map +1 -0
- package/dist/next/host/root.js +68 -0
- package/dist/next/host/root.js.map +1 -0
- package/dist/next/host/route.d.ts +64 -0
- package/dist/next/host/route.d.ts.map +1 -0
- package/dist/next/host/route.js +190 -0
- package/dist/next/host/route.js.map +1 -0
- package/dist/next/host/routines.d.ts +76 -0
- package/dist/next/host/routines.d.ts.map +1 -0
- package/dist/next/host/routines.js +350 -0
- package/dist/next/host/routines.js.map +1 -0
- package/dist/next/host/sleep.d.ts +9 -0
- package/dist/next/host/sleep.d.ts.map +1 -0
- package/dist/next/host/sleep.js +40 -0
- package/dist/next/host/sleep.js.map +1 -0
- package/dist/next/host/staging.d.ts +94 -0
- package/dist/next/host/staging.d.ts.map +1 -0
- package/dist/next/host/staging.js +302 -0
- package/dist/next/host/staging.js.map +1 -0
- package/dist/next/host/unbound.d.ts +30 -0
- package/dist/next/host/unbound.d.ts.map +1 -0
- package/dist/next/host/unbound.js +67 -0
- package/dist/next/host/unbound.js.map +1 -0
- package/dist/next/host/uuid.d.ts +3 -0
- package/dist/next/host/uuid.d.ts.map +1 -0
- package/dist/next/host/uuid.js +38 -0
- package/dist/next/host/uuid.js.map +1 -0
- package/dist/next/index.d.ts +28 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +18 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/jobs/definition.d.ts +96 -0
- package/dist/next/jobs/definition.d.ts.map +1 -0
- package/dist/next/jobs/definition.js +83 -0
- package/dist/next/jobs/definition.js.map +1 -0
- package/dist/next/jobs/index.d.ts +5 -0
- package/dist/next/jobs/index.d.ts.map +1 -0
- package/dist/next/jobs/index.js +3 -0
- package/dist/next/jobs/index.js.map +1 -0
- package/dist/next/jobs/internal.d.ts +3 -0
- package/dist/next/jobs/internal.d.ts.map +1 -0
- package/dist/next/jobs/internal.js +4 -0
- package/dist/next/jobs/internal.js.map +1 -0
- package/dist/next/jobs/job.d.ts +152 -0
- package/dist/next/jobs/job.d.ts.map +1 -0
- package/dist/next/jobs/job.js +320 -0
- package/dist/next/jobs/job.js.map +1 -0
- package/dist/next/jobs/persisted.d.ts +38 -0
- package/dist/next/jobs/persisted.d.ts.map +1 -0
- package/dist/next/jobs/persisted.js +95 -0
- package/dist/next/jobs/persisted.js.map +1 -0
- package/dist/next/jobs/records.d.ts +231 -0
- package/dist/next/jobs/records.d.ts.map +1 -0
- package/dist/next/jobs/records.js +869 -0
- package/dist/next/jobs/records.js.map +1 -0
- package/dist/next/jobs/run-states.d.ts +69 -0
- package/dist/next/jobs/run-states.d.ts.map +1 -0
- package/dist/next/jobs/run-states.js +228 -0
- package/dist/next/jobs/run-states.js.map +1 -0
- package/dist/next/jobs/run.d.ts +113 -0
- package/dist/next/jobs/run.d.ts.map +1 -0
- package/dist/next/jobs/run.js +200 -0
- package/dist/next/jobs/run.js.map +1 -0
- package/dist/next/jobs/running.d.ts +44 -0
- package/dist/next/jobs/running.d.ts.map +1 -0
- package/dist/next/jobs/running.js +117 -0
- package/dist/next/jobs/running.js.map +1 -0
- package/dist/next/jobs/stored.d.ts +63 -0
- package/dist/next/jobs/stored.d.ts.map +1 -0
- package/dist/next/jobs/stored.js +55 -0
- package/dist/next/jobs/stored.js.map +1 -0
- package/dist/next/link/binary.d.ts +4 -0
- package/dist/next/link/binary.d.ts.map +1 -0
- package/dist/next/link/binary.js +534 -0
- package/dist/next/link/binary.js.map +1 -0
- package/dist/next/link/channel.d.ts +63 -0
- package/dist/next/link/channel.d.ts.map +1 -0
- package/dist/next/link/channel.js +202 -0
- package/dist/next/link/channel.js.map +1 -0
- package/dist/next/link/errors.d.ts +7 -0
- package/dist/next/link/errors.d.ts.map +1 -0
- package/dist/next/link/errors.js +21 -0
- package/dist/next/link/errors.js.map +1 -0
- package/dist/next/link/index.d.ts +8 -0
- package/dist/next/link/index.d.ts.map +1 -0
- package/dist/next/link/index.js +8 -0
- package/dist/next/link/index.js.map +1 -0
- package/dist/next/link/internal.d.ts +9 -0
- package/dist/next/link/internal.d.ts.map +1 -0
- package/dist/next/link/internal.js +10 -0
- package/dist/next/link/internal.js.map +1 -0
- package/dist/next/link/ipc.d.ts +22 -0
- package/dist/next/link/ipc.d.ts.map +1 -0
- package/dist/next/link/ipc.js +64 -0
- package/dist/next/link/ipc.js.map +1 -0
- package/dist/next/link/link.d.ts +34 -0
- package/dist/next/link/link.d.ts.map +1 -0
- package/dist/next/link/link.js +87 -0
- package/dist/next/link/link.js.map +1 -0
- package/dist/next/link/message.d.ts +249 -0
- package/dist/next/link/message.d.ts.map +1 -0
- package/dist/next/link/message.js +123 -0
- package/dist/next/link/message.js.map +1 -0
- package/dist/next/link/part.d.ts +80 -0
- package/dist/next/link/part.d.ts.map +1 -0
- package/dist/next/link/part.js +164 -0
- package/dist/next/link/part.js.map +1 -0
- package/dist/next/link/text.d.ts +6 -0
- package/dist/next/link/text.d.ts.map +1 -0
- package/dist/next/link/text.js +335 -0
- package/dist/next/link/text.js.map +1 -0
- package/dist/next/link/values.d.ts +40 -0
- package/dist/next/link/values.d.ts.map +1 -0
- package/dist/next/link/values.js +117 -0
- package/dist/next/link/values.js.map +1 -0
- package/dist/next/link/websocket.d.ts +26 -0
- package/dist/next/link/websocket.d.ts.map +1 -0
- package/dist/next/link/websocket.js +91 -0
- package/dist/next/link/websocket.js.map +1 -0
- package/dist/next/registries/contribution.d.ts +50 -0
- package/dist/next/registries/contribution.d.ts.map +1 -0
- package/dist/next/registries/contribution.js +129 -0
- package/dist/next/registries/contribution.js.map +1 -0
- package/dist/next/registries/entries.d.ts +18 -0
- package/dist/next/registries/entries.d.ts.map +1 -0
- package/dist/next/registries/entries.js +42 -0
- package/dist/next/registries/entries.js.map +1 -0
- package/dist/next/registries/index.d.ts +3 -0
- package/dist/next/registries/index.d.ts.map +1 -0
- package/dist/next/registries/index.js +5 -0
- package/dist/next/registries/index.js.map +1 -0
- package/dist/next/registries/internal.d.ts +4 -0
- package/dist/next/registries/internal.d.ts.map +1 -0
- package/dist/next/registries/internal.js +5 -0
- package/dist/next/registries/internal.js.map +1 -0
- package/dist/next/registries/record.d.ts +94 -0
- package/dist/next/registries/record.d.ts.map +1 -0
- package/dist/next/registries/record.js +253 -0
- package/dist/next/registries/record.js.map +1 -0
- package/dist/next/registries/registry.d.ts +74 -0
- package/dist/next/registries/registry.d.ts.map +1 -0
- package/dist/next/registries/registry.js +14 -0
- package/dist/next/registries/registry.js.map +1 -0
- package/dist/next/registries/value.d.ts +48 -0
- package/dist/next/registries/value.d.ts.map +1 -0
- package/dist/next/registries/value.js +199 -0
- package/dist/next/registries/value.js.map +1 -0
- package/dist/next/remote/calls.d.ts +25 -0
- package/dist/next/remote/calls.d.ts.map +1 -0
- package/dist/next/remote/calls.js +62 -0
- package/dist/next/remote/calls.js.map +1 -0
- package/dist/next/remote/consumer.d.ts +42 -0
- package/dist/next/remote/consumer.d.ts.map +1 -0
- package/dist/next/remote/consumer.js +343 -0
- package/dist/next/remote/consumer.js.map +1 -0
- package/dist/next/remote/hold.d.ts +130 -0
- package/dist/next/remote/hold.d.ts.map +1 -0
- package/dist/next/remote/hold.js +537 -0
- package/dist/next/remote/hold.js.map +1 -0
- package/dist/next/remote/host-link.d.ts +77 -0
- package/dist/next/remote/host-link.d.ts.map +1 -0
- package/dist/next/remote/host-link.js +182 -0
- package/dist/next/remote/host-link.js.map +1 -0
- package/dist/next/remote/internal.d.ts +6 -0
- package/dist/next/remote/internal.d.ts.map +1 -0
- package/dist/next/remote/internal.js +6 -0
- package/dist/next/remote/internal.js.map +1 -0
- package/dist/next/remote/path.d.ts +46 -0
- package/dist/next/remote/path.d.ts.map +1 -0
- package/dist/next/remote/path.js +73 -0
- package/dist/next/remote/path.js.map +1 -0
- package/dist/next/remote/provider.d.ts +76 -0
- package/dist/next/remote/provider.d.ts.map +1 -0
- package/dist/next/remote/provider.js +506 -0
- package/dist/next/remote/provider.js.map +1 -0
- package/dist/next/remote/relay.d.ts +58 -0
- package/dist/next/remote/relay.d.ts.map +1 -0
- package/dist/next/remote/relay.js +117 -0
- package/dist/next/remote/relay.js.map +1 -0
- package/dist/next/remote/remote-object.d.ts +133 -0
- package/dist/next/remote/remote-object.d.ts.map +1 -0
- package/dist/next/remote/remote-object.js +411 -0
- package/dist/next/remote/remote-object.js.map +1 -0
- package/dist/next/remote/replica.d.ts +59 -0
- package/dist/next/remote/replica.d.ts.map +1 -0
- package/dist/next/remote/replica.js +125 -0
- package/dist/next/remote/replica.js.map +1 -0
- package/dist/next/state/batch.d.ts +64 -0
- package/dist/next/state/batch.d.ts.map +1 -0
- package/dist/next/state/batch.js +163 -0
- package/dist/next/state/batch.js.map +1 -0
- package/dist/next/state/derive.d.ts +52 -0
- package/dist/next/state/derive.d.ts.map +1 -0
- package/dist/next/state/derive.js +182 -0
- package/dist/next/state/derive.js.map +1 -0
- package/dist/next/state/index.d.ts +6 -0
- package/dist/next/state/index.d.ts.map +1 -0
- package/dist/next/state/index.js +4 -0
- package/dist/next/state/index.js.map +1 -0
- package/dist/next/state/internal.d.ts +6 -0
- package/dist/next/state/internal.d.ts.map +1 -0
- package/dist/next/state/internal.js +8 -0
- package/dist/next/state/internal.js.map +1 -0
- package/dist/next/state/native-source.d.ts +106 -0
- package/dist/next/state/native-source.d.ts.map +1 -0
- package/dist/next/state/native-source.js +240 -0
- package/dist/next/state/native-source.js.map +1 -0
- package/dist/next/state/watchable.d.ts +114 -0
- package/dist/next/state/watchable.d.ts.map +1 -0
- package/dist/next/state/watchable.js +156 -0
- package/dist/next/state/watchable.js.map +1 -0
- package/dist/next/state/writable.d.ts +32 -0
- package/dist/next/state/writable.d.ts.map +1 -0
- package/dist/next/state/writable.js +49 -0
- package/dist/next/state/writable.js.map +1 -0
- package/dist/next/store/adapter.d.ts +67 -0
- package/dist/next/store/adapter.d.ts.map +1 -0
- package/dist/next/store/adapter.js +118 -0
- package/dist/next/store/adapter.js.map +1 -0
- package/dist/next/store/allocator.d.ts +17 -0
- package/dist/next/store/allocator.d.ts.map +1 -0
- package/dist/next/store/allocator.js +30 -0
- package/dist/next/store/allocator.js.map +1 -0
- package/dist/next/store/applier.d.ts +8 -0
- package/dist/next/store/applier.d.ts.map +1 -0
- package/dist/next/store/applier.js +375 -0
- package/dist/next/store/applier.js.map +1 -0
- package/dist/next/store/apply-batch.d.ts +12 -0
- package/dist/next/store/apply-batch.d.ts.map +1 -0
- package/dist/next/store/apply-batch.js +83 -0
- package/dist/next/store/apply-batch.js.map +1 -0
- package/dist/next/store/archive.d.ts +32 -0
- package/dist/next/store/archive.d.ts.map +1 -0
- package/dist/next/store/archive.js +129 -0
- package/dist/next/store/archive.js.map +1 -0
- package/dist/next/store/backend.d.ts +10 -0
- package/dist/next/store/backend.d.ts.map +1 -0
- package/dist/next/store/backend.js +15 -0
- package/dist/next/store/backend.js.map +1 -0
- package/dist/next/store/catalog.d.ts +24 -0
- package/dist/next/store/catalog.d.ts.map +1 -0
- package/dist/next/store/catalog.js +17 -0
- package/dist/next/store/catalog.js.map +1 -0
- package/dist/next/store/claims.d.ts +23 -0
- package/dist/next/store/claims.d.ts.map +1 -0
- package/dist/next/store/claims.js +65 -0
- package/dist/next/store/claims.js.map +1 -0
- package/dist/next/store/columns.d.ts +77 -0
- package/dist/next/store/columns.d.ts.map +1 -0
- package/dist/next/store/columns.js +77 -0
- package/dist/next/store/columns.js.map +1 -0
- package/dist/next/store/engine.d.ts +176 -0
- package/dist/next/store/engine.d.ts.map +1 -0
- package/dist/next/store/engine.js +283 -0
- package/dist/next/store/engine.js.map +1 -0
- package/dist/next/store/evaluate.d.ts +17 -0
- package/dist/next/store/evaluate.d.ts.map +1 -0
- package/dist/next/store/evaluate.js +128 -0
- package/dist/next/store/evaluate.js.map +1 -0
- package/dist/next/store/export.d.ts +17 -0
- package/dist/next/store/export.d.ts.map +1 -0
- package/dist/next/store/export.js +200 -0
- package/dist/next/store/export.js.map +1 -0
- package/dist/next/store/expression.d.ts +150 -0
- package/dist/next/store/expression.d.ts.map +1 -0
- package/dist/next/store/expression.js +268 -0
- package/dist/next/store/expression.js.map +1 -0
- package/dist/next/store/import.d.ts +10 -0
- package/dist/next/store/import.d.ts.map +1 -0
- package/dist/next/store/import.js +276 -0
- package/dist/next/store/import.js.map +1 -0
- package/dist/next/store/index.d.ts +16 -0
- package/dist/next/store/index.d.ts.map +1 -0
- package/dist/next/store/index.js +13 -0
- package/dist/next/store/index.js.map +1 -0
- package/dist/next/store/json-column.d.ts +33 -0
- package/dist/next/store/json-column.d.ts.map +1 -0
- package/dist/next/store/json-column.js +61 -0
- package/dist/next/store/json-column.js.map +1 -0
- package/dist/next/store/jsonl.d.ts +9 -0
- package/dist/next/store/jsonl.d.ts.map +1 -0
- package/dist/next/store/jsonl.js +61 -0
- package/dist/next/store/jsonl.js.map +1 -0
- package/dist/next/store/outbox.d.ts +26 -0
- package/dist/next/store/outbox.d.ts.map +1 -0
- package/dist/next/store/outbox.js +80 -0
- package/dist/next/store/outbox.js.map +1 -0
- package/dist/next/store/query.d.ts +39 -0
- package/dist/next/store/query.d.ts.map +1 -0
- package/dist/next/store/query.js +97 -0
- package/dist/next/store/query.js.map +1 -0
- package/dist/next/store/refusal.d.ts +15 -0
- package/dist/next/store/refusal.d.ts.map +1 -0
- package/dist/next/store/refusal.js +36 -0
- package/dist/next/store/refusal.js.map +1 -0
- package/dist/next/store/rows.d.ts +80 -0
- package/dist/next/store/rows.d.ts.map +1 -0
- package/dist/next/store/rows.js +183 -0
- package/dist/next/store/rows.js.map +1 -0
- package/dist/next/store/schema.d.ts +25 -0
- package/dist/next/store/schema.d.ts.map +1 -0
- package/dist/next/store/schema.js +115 -0
- package/dist/next/store/schema.js.map +1 -0
- package/dist/next/store/sql.d.ts +73 -0
- package/dist/next/store/sql.d.ts.map +1 -0
- package/dist/next/store/sql.js +234 -0
- package/dist/next/store/sql.js.map +1 -0
- package/dist/next/store/step.d.ts +48 -0
- package/dist/next/store/step.d.ts.map +1 -0
- package/dist/next/store/step.js +50 -0
- package/dist/next/store/step.js.map +1 -0
- package/dist/next/store/store.d.ts +161 -0
- package/dist/next/store/store.d.ts.map +1 -0
- package/dist/next/store/store.js +627 -0
- package/dist/next/store/store.js.map +1 -0
- package/dist/next/store/table-changes.d.ts +29 -0
- package/dist/next/store/table-changes.d.ts.map +1 -0
- package/dist/next/store/table-changes.js +102 -0
- package/dist/next/store/table-changes.js.map +1 -0
- package/dist/next/store/table-evolve.d.ts +74 -0
- package/dist/next/store/table-evolve.d.ts.map +1 -0
- package/dist/next/store/table-evolve.js +201 -0
- package/dist/next/store/table-evolve.js.map +1 -0
- package/dist/next/store/table-handle.d.ts +67 -0
- package/dist/next/store/table-handle.d.ts.map +1 -0
- package/dist/next/store/table-handle.js +101 -0
- package/dist/next/store/table-handle.js.map +1 -0
- package/dist/next/store/table-history.d.ts +75 -0
- package/dist/next/store/table-history.d.ts.map +1 -0
- package/dist/next/store/table-history.js +42 -0
- package/dist/next/store/table-history.js.map +1 -0
- package/dist/next/store/table-migration.d.ts +16 -0
- package/dist/next/store/table-migration.d.ts.map +1 -0
- package/dist/next/store/table-migration.js +202 -0
- package/dist/next/store/table-migration.js.map +1 -0
- package/dist/next/store/table-writes.d.ts +125 -0
- package/dist/next/store/table-writes.d.ts.map +1 -0
- package/dist/next/store/table-writes.js +165 -0
- package/dist/next/store/table-writes.js.map +1 -0
- package/dist/next/store/table.d.ts +80 -0
- package/dist/next/store/table.d.ts.map +1 -0
- package/dist/next/store/table.js +103 -0
- package/dist/next/store/table.js.map +1 -0
- package/dist/next/store/text.d.ts +14 -0
- package/dist/next/store/text.d.ts.map +1 -0
- package/dist/next/store/text.js +51 -0
- package/dist/next/store/text.js.map +1 -0
- package/dist/next/store/writes.d.ts +5 -0
- package/dist/next/store/writes.d.ts.map +1 -0
- package/dist/next/store/writes.js +4 -0
- package/dist/next/store/writes.js.map +1 -0
- package/dist/next-node/compression.d.ts +7 -0
- package/dist/next-node/compression.d.ts.map +1 -0
- package/dist/next-node/compression.js +24 -0
- package/dist/next-node/compression.js.map +1 -0
- package/dist/next-node/http/admission.d.ts +63 -0
- package/dist/next-node/http/admission.d.ts.map +1 -0
- package/dist/next-node/http/admission.js +134 -0
- package/dist/next-node/http/admission.js.map +1 -0
- package/dist/next-node/http/authenticate.d.ts +21 -0
- package/dist/next-node/http/authenticate.d.ts.map +1 -0
- package/dist/next-node/http/authenticate.js +34 -0
- package/dist/next-node/http/authenticate.js.map +1 -0
- package/dist/next-node/http/cookies.d.ts +24 -0
- package/dist/next-node/http/cookies.d.ts.map +1 -0
- package/dist/next-node/http/cookies.js +62 -0
- package/dist/next-node/http/cookies.js.map +1 -0
- package/dist/next-node/http/file.d.ts +23 -0
- package/dist/next-node/http/file.d.ts.map +1 -0
- package/dist/next-node/http/file.js +94 -0
- package/dist/next-node/http/file.js.map +1 -0
- package/dist/next-node/http/headers.d.ts +37 -0
- package/dist/next-node/http/headers.d.ts.map +1 -0
- package/dist/next-node/http/headers.js +129 -0
- package/dist/next-node/http/headers.js.map +1 -0
- package/dist/next-node/http/http.d.ts +100 -0
- package/dist/next-node/http/http.d.ts.map +1 -0
- package/dist/next-node/http/http.js +462 -0
- package/dist/next-node/http/http.js.map +1 -0
- package/dist/next-node/http/incoming.d.ts +19 -0
- package/dist/next-node/http/incoming.d.ts.map +1 -0
- package/dist/next-node/http/incoming.js +31 -0
- package/dist/next-node/http/incoming.js.map +1 -0
- package/dist/next-node/http/index.d.ts +11 -0
- package/dist/next-node/http/index.d.ts.map +1 -0
- package/dist/next-node/http/index.js +12 -0
- package/dist/next-node/http/index.js.map +1 -0
- package/dist/next-node/http/node.d.ts +78 -0
- package/dist/next-node/http/node.d.ts.map +1 -0
- package/dist/next-node/http/node.js +291 -0
- package/dist/next-node/http/node.js.map +1 -0
- package/dist/next-node/http/request.d.ts +54 -0
- package/dist/next-node/http/request.d.ts.map +1 -0
- package/dist/next-node/http/request.js +116 -0
- package/dist/next-node/http/request.js.map +1 -0
- package/dist/next-node/http/response.d.ts +63 -0
- package/dist/next-node/http/response.d.ts.map +1 -0
- package/dist/next-node/http/response.js +202 -0
- package/dist/next-node/http/response.js.map +1 -0
- package/dist/next-node/http/router.d.ts +114 -0
- package/dist/next-node/http/router.d.ts.map +1 -0
- package/dist/next-node/http/router.js +261 -0
- package/dist/next-node/http/router.js.map +1 -0
- package/dist/next-node/http/upgrades.d.ts +58 -0
- package/dist/next-node/http/upgrades.d.ts.map +1 -0
- package/dist/next-node/http/upgrades.js +184 -0
- package/dist/next-node/http/upgrades.js.map +1 -0
- package/dist/next-node/plugins/build.d.ts +57 -0
- package/dist/next-node/plugins/build.d.ts.map +1 -0
- package/dist/next-node/plugins/build.js +334 -0
- package/dist/next-node/plugins/build.js.map +1 -0
- package/dist/next-node/plugins/discover.d.ts +36 -0
- package/dist/next-node/plugins/discover.d.ts.map +1 -0
- package/dist/next-node/plugins/discover.js +91 -0
- package/dist/next-node/plugins/discover.js.map +1 -0
- package/dist/next-node/plugins/evaluate.d.ts +33 -0
- package/dist/next-node/plugins/evaluate.d.ts.map +1 -0
- package/dist/next-node/plugins/evaluate.js +98 -0
- package/dist/next-node/plugins/evaluate.js.map +1 -0
- package/dist/next-node/plugins/index.d.ts +9 -0
- package/dist/next-node/plugins/index.d.ts.map +1 -0
- package/dist/next-node/plugins/index.js +11 -0
- package/dist/next-node/plugins/index.js.map +1 -0
- package/dist/next-node/plugins/install.d.ts +13 -0
- package/dist/next-node/plugins/install.d.ts.map +1 -0
- package/dist/next-node/plugins/install.js +37 -0
- package/dist/next-node/plugins/install.js.map +1 -0
- package/dist/next-node/plugins/plugins.d.ts +135 -0
- package/dist/next-node/plugins/plugins.d.ts.map +1 -0
- package/dist/next-node/plugins/plugins.js +206 -0
- package/dist/next-node/plugins/plugins.js.map +1 -0
- package/dist/next-node/plugins/runtime.d.ts +41 -0
- package/dist/next-node/plugins/runtime.d.ts.map +1 -0
- package/dist/next-node/plugins/runtime.js +136 -0
- package/dist/next-node/plugins/runtime.js.map +1 -0
- package/dist/next-node/plugins/stack.d.ts +16 -0
- package/dist/next-node/plugins/stack.d.ts.map +1 -0
- package/dist/next-node/plugins/stack.js +61 -0
- package/dist/next-node/plugins/stack.js.map +1 -0
- package/dist/next-node/plugins/watcher.d.ts +58 -0
- package/dist/next-node/plugins/watcher.d.ts.map +1 -0
- package/dist/next-node/plugins/watcher.js +281 -0
- package/dist/next-node/plugins/watcher.js.map +1 -0
- package/dist/next-node/workers/control.d.ts +83 -0
- package/dist/next-node/workers/control.d.ts.map +1 -0
- package/dist/next-node/workers/control.js +77 -0
- package/dist/next-node/workers/control.js.map +1 -0
- package/dist/next-node/workers/index.d.ts +5 -0
- package/dist/next-node/workers/index.d.ts.map +1 -0
- package/dist/next-node/workers/index.js +7 -0
- package/dist/next-node/workers/index.js.map +1 -0
- package/dist/next-node/workers/lock.d.ts +21 -0
- package/dist/next-node/workers/lock.d.ts.map +1 -0
- package/dist/next-node/workers/lock.js +137 -0
- package/dist/next-node/workers/lock.js.map +1 -0
- package/dist/next-node/workers/main.d.ts +46 -0
- package/dist/next-node/workers/main.d.ts.map +1 -0
- package/dist/next-node/workers/main.js +230 -0
- package/dist/next-node/workers/main.js.map +1 -0
- package/dist/next-node/workers/process.d.ts +42 -0
- package/dist/next-node/workers/process.d.ts.map +1 -0
- package/dist/next-node/workers/process.js +125 -0
- package/dist/next-node/workers/process.js.map +1 -0
- package/dist/next-node/workers/workers.d.ts +80 -0
- package/dist/next-node/workers/workers.d.ts.map +1 -0
- package/dist/next-node/workers/workers.js +572 -0
- package/dist/next-node/workers/workers.js.map +1 -0
- package/dist/object.d.ts +4 -4
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +3 -4
- package/dist/object.js.map +1 -1
- package/dist/output.d.ts +1 -1
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +4 -2
- package/dist/output.js.map +1 -1
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +2 -2
- package/dist/remote.js.map +1 -1
- package/dist/schema.d.ts +8 -4
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +180 -5
- package/dist/schema.js.map +1 -1
- package/dist/sqlite/cloudflare.d.ts +2 -0
- package/dist/sqlite/cloudflare.d.ts.map +1 -1
- package/dist/sqlite/cloudflare.js +10 -0
- package/dist/sqlite/cloudflare.js.map +1 -1
- package/dist/sqlite/database.d.ts +5 -2
- package/dist/sqlite/database.d.ts.map +1 -1
- package/dist/sqlite/database.js.map +1 -1
- package/dist/sqlite/node.d.ts +4 -1
- package/dist/sqlite/node.d.ts.map +1 -1
- package/dist/sqlite/node.js +22 -5
- package/dist/sqlite/node.js.map +1 -1
- package/dist/watch.d.ts +194 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +383 -0
- package/dist/watch.js.map +1 -0
- package/dist/wire.d.ts +174 -193
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +81 -80
- package/dist/wire.js.map +1 -1
- package/docs/guide.md +15 -15
- package/docs/next/benchmarks.md +959 -0
- package/docs/next/decisions.md +2957 -0
- package/docs/next/dependencies/book.md +1671 -0
- package/docs/next/dependencies/index.html +2641 -0
- package/docs/next/dependencies/model.md +330 -0
- package/docs/next/design.md +2554 -0
- package/docs/next/durable-observers/book.md +432 -0
- package/docs/next/durable-observers/index.html +517 -0
- package/docs/next/flow-control/book.md +333 -0
- package/docs/next/flow-control/fold/index.html +265 -0
- package/docs/next/flow-control/index.html +548 -0
- package/docs/next/flow-control/window/index.html +228 -0
- package/docs/next/guide-plugins-hosts/book.md +607 -0
- package/docs/next/guide-plugins-hosts/index.html +652 -0
- package/docs/next/http-workers/book.md +378 -0
- package/docs/next/http-workers/index.html +515 -0
- package/docs/next/layer-1.md +311 -0
- package/docs/next/layer-2.md +216 -0
- package/docs/next/plugin-model/book.md +186 -0
- package/docs/next/plugin-model/index.html +310 -0
- package/docs/next/plugin-primer/book.md +273 -0
- package/docs/next/plugin-primer/index.html +430 -0
- package/docs/next/slice-1.md +236 -0
- package/docs/next/slice-10.md +285 -0
- package/docs/next/slice-11.md +93 -0
- package/docs/next/slice-2.md +174 -0
- package/docs/next/slice-3a.md +296 -0
- package/docs/next/slice-3b.md +197 -0
- package/docs/next/slice-4.md +146 -0
- package/docs/next/slice-4a.md +418 -0
- package/docs/next/slice-4b.md +208 -0
- package/docs/next/slice-5.md +281 -0
- package/docs/next/slice-6a.md +676 -0
- package/docs/next/slice-6b.md +332 -0
- package/docs/next/slice-7a.md +130 -0
- package/docs/next/slice-7b/book.md +608 -0
- package/docs/next/slice-7b/index.html +842 -0
- package/docs/next/slice-7b.md +255 -0
- package/docs/next/slice-7c.md +165 -0
- package/docs/next/slice-8.md +194 -0
- package/docs/next/slices.md +230 -0
- package/docs/next/store/book.md +665 -0
- package/docs/next/store/index.html +861 -0
- package/docs/next/store/walkthrough.md +193 -0
- package/docs/spec.md +9 -9
- package/docs/tutorial.md +26 -25
- package/package.json +22 -6
- package/src/delta/README.md +69 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// SQL of declared tables (slice 6a §5, §6, §7): the DDL a table definition renders, and the statements of its reads
|
|
2
|
+
// and writes, generated from the compiled vocabulary with every value bound and every identifier quoted. Names were
|
|
3
|
+
// checked at declaration (and at import), so no `"` occurs in them and quoting is always safe.
|
|
4
|
+
import { physicalColumns, ROW_VERSION, toSqlite, versionColumn } from "./rows.js";
|
|
5
|
+
import { prefixUpperBound } from "./text.js";
|
|
6
|
+
/** A quoted SQL identifier. */
|
|
7
|
+
export function quote(name) {
|
|
8
|
+
return `"${name}"`;
|
|
9
|
+
}
|
|
10
|
+
/** The SQL name of an owner's table: `<owner>:<table>` (R2), injective since neither part contains `:`. */
|
|
11
|
+
export function tableSqlName(owner, table) {
|
|
12
|
+
return `${owner}:${table}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `CREATE TABLE` for `columns` (as recorded) and `key`: `STRICT`, the key as primary key (`WITHOUT ROWID`, except
|
|
16
|
+
* for a single `int` key, which becomes the rowid: the fastest point lookups, and rows of any size), an `int`
|
|
17
|
+
* column checked within ±(2^53 - 1) (rule 10), a `bool` one within 0 and 1, a `json(...)` one as `TEXT` with its
|
|
18
|
+
* version column, and the row's `$v`.
|
|
19
|
+
*/
|
|
20
|
+
export function createTableSql(table, columns, key) {
|
|
21
|
+
const definitions = Object.entries(columns).flatMap(([name, column]) => columnSql(name, column));
|
|
22
|
+
definitions.push(`${quote(ROW_VERSION)} INTEGER NOT NULL`);
|
|
23
|
+
definitions.push(`PRIMARY KEY (${key.map(quote).join(", ")})`);
|
|
24
|
+
const rowid = key.length === 1 && columns[key[0]].type === "int";
|
|
25
|
+
return `CREATE TABLE ${quote(table)} (${definitions.join(", ")}) STRICT${rowid ? "" : ", WITHOUT ROWID"}`;
|
|
26
|
+
}
|
|
27
|
+
const SAFE = Number.MAX_SAFE_INTEGER;
|
|
28
|
+
/** The definitions of one column: itself, and a `json(...)` column's version column. */
|
|
29
|
+
export function columnSql(name, column) {
|
|
30
|
+
const nullability = column.optional ? "" : " NOT NULL";
|
|
31
|
+
const defaulted = column.default === undefined ? "" : ` DEFAULT ${literal(column.default)}`;
|
|
32
|
+
const id = quote(name);
|
|
33
|
+
switch (column.type) {
|
|
34
|
+
case "str":
|
|
35
|
+
return [`${id} TEXT${nullability}${defaulted}`];
|
|
36
|
+
case "int":
|
|
37
|
+
return [`${id} INTEGER${nullability}${defaulted} CHECK (${id} BETWEEN ${-SAFE} AND ${SAFE})`];
|
|
38
|
+
case "num":
|
|
39
|
+
return [`${id} REAL${nullability}${defaulted}`];
|
|
40
|
+
case "bool":
|
|
41
|
+
return [`${id} INTEGER${nullability}${defaulted} CHECK (${id} IN (0, 1))`];
|
|
42
|
+
case "json":
|
|
43
|
+
return [`${id} TEXT${nullability}`, `${quote(versionColumn(name))} INTEGER${nullability}`];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** A default as a SQL literal: declaration data (checked), which DDL cannot bind. */
|
|
47
|
+
function literal(value) {
|
|
48
|
+
if (typeof value === "string")
|
|
49
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
50
|
+
return typeof value === "boolean" ? (value ? "1" : "0") : String(value);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The physical columns of a recorded table in the order `RowCodec.physical` uses (`physicalColumns`), and its
|
|
54
|
+
* whole-row `INSERT OR REPLACE` over them.
|
|
55
|
+
*/
|
|
56
|
+
export function recordedPut(table, columns) {
|
|
57
|
+
const physical = physicalColumns(Object.entries(columns).map(([name, { type }]) => ({ name, type })));
|
|
58
|
+
return { physical, sql: putSql(table, physical) };
|
|
59
|
+
}
|
|
60
|
+
/** `INSERT OR REPLACE` of a whole row over `physical` (`put` is an upsert). */
|
|
61
|
+
function putSql(table, physical) {
|
|
62
|
+
return `INSERT OR REPLACE INTO ${quote(table)} (${physical.map(quote).join(", ")}) VALUES (${physical.map(() => "?").join(", ")})`;
|
|
63
|
+
}
|
|
64
|
+
/** `CREATE INDEX` named `<table>:<index>` over `columns`, the key appended (every index ends with it). */
|
|
65
|
+
export function createIndexSql(table, index, columns, key) {
|
|
66
|
+
const all = [...columns, ...key.filter((column) => !columns.includes(column))];
|
|
67
|
+
return `CREATE INDEX ${quote(`${table}:${index}`)} ON ${quote(table)} (${all.map(quote).join(", ")})`;
|
|
68
|
+
}
|
|
69
|
+
/** `DROP INDEX` of `<table>:<index>`. */
|
|
70
|
+
export function dropIndexSql(table, index) {
|
|
71
|
+
return `DROP INDEX ${quote(`${table}:${index}`)}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The statements of one table at one version, rendered once per table handle: the fixed ones as texts, the ones
|
|
75
|
+
* over compiled conditions and `set`s on demand.
|
|
76
|
+
*/
|
|
77
|
+
export class TableSql {
|
|
78
|
+
table;
|
|
79
|
+
/** The columns a read selects: the declared ones and each `json(...)` column's version. */
|
|
80
|
+
#select;
|
|
81
|
+
#byKey;
|
|
82
|
+
/** `INSERT OR REPLACE` of a whole row, in `RowCodec.physical`'s order (`put` is an upsert). */
|
|
83
|
+
put;
|
|
84
|
+
get;
|
|
85
|
+
delete;
|
|
86
|
+
constructor(table, columns, physical, key) {
|
|
87
|
+
this.table = table;
|
|
88
|
+
const id = quote(table);
|
|
89
|
+
this.#select = [
|
|
90
|
+
...columns.map(({ name }) => quote(name)),
|
|
91
|
+
...columns.filter(({ type }) => type === "json").map(({ name }) => quote(versionColumn(name))),
|
|
92
|
+
].join(", ");
|
|
93
|
+
this.#byKey = key.map((column) => `${quote(column)} = ?`).join(" AND ");
|
|
94
|
+
this.put = putSql(table, physical);
|
|
95
|
+
this.get = `SELECT ${this.#select} FROM ${id} WHERE ${this.#byKey}`;
|
|
96
|
+
this.delete = `DELETE FROM ${id} WHERE ${this.#byKey}`;
|
|
97
|
+
}
|
|
98
|
+
/** `SELECT` of `columns` of one row by key: a point lookup, without the `ORDER BY` and `LIMIT` of a page. */
|
|
99
|
+
getColumns(columns) {
|
|
100
|
+
return `SELECT ${columns.map(quote).join(", ")} FROM ${quote(this.table)} WHERE ${this.#byKey}`;
|
|
101
|
+
}
|
|
102
|
+
/** `UPDATE` of one row by key; `versions` gives each `json(...)` column's version to stamp. */
|
|
103
|
+
update(set, key, versions) {
|
|
104
|
+
const params = [];
|
|
105
|
+
const assignments = setSql(set, versions, params);
|
|
106
|
+
params.push(...key);
|
|
107
|
+
return { sql: `UPDATE ${quote(this.table)} SET ${assignments} WHERE ${this.#byKey}`, params };
|
|
108
|
+
}
|
|
109
|
+
/** `UPDATE` of every row matching `where`. */
|
|
110
|
+
updateWhere(where, set, versions) {
|
|
111
|
+
const params = [];
|
|
112
|
+
const assignments = setSql(set, versions, params);
|
|
113
|
+
const condition = whereSql(where, params);
|
|
114
|
+
return { sql: `UPDATE ${quote(this.table)} SET ${assignments} WHERE ${condition}`, params };
|
|
115
|
+
}
|
|
116
|
+
/** `DELETE` of every row matching `where`. */
|
|
117
|
+
deleteWhere(where) {
|
|
118
|
+
const params = [];
|
|
119
|
+
return { sql: `DELETE FROM ${quote(this.table)} WHERE ${whereSql(where, params)}`, params };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A page: rows matching `where` in `order`, after the order values `after` (row-value comparison; the key in the
|
|
123
|
+
* order makes it total), at most `limit` (bound); every column, or only `columns`.
|
|
124
|
+
*/
|
|
125
|
+
select(where, order, after, limit, columns) {
|
|
126
|
+
const params = [];
|
|
127
|
+
const conditions = [];
|
|
128
|
+
if (where !== undefined)
|
|
129
|
+
conditions.push(whereSql(where, params));
|
|
130
|
+
if (after !== undefined) {
|
|
131
|
+
const columns = order.columns.map(quote).join(", ");
|
|
132
|
+
conditions.push(`(${columns}) ${order.direction === "asc" ? ">" : "<"} (${after.map(() => "?").join(", ")})`);
|
|
133
|
+
params.push(...after);
|
|
134
|
+
}
|
|
135
|
+
const filter = conditions.length === 0 ? "" : ` WHERE ${conditions.join(" AND ")}`;
|
|
136
|
+
const direction = order.direction === "asc" ? "ASC" : "DESC";
|
|
137
|
+
const sorting = order.columns.map((column) => `${quote(column)} ${direction}`).join(", ");
|
|
138
|
+
params.push(limit);
|
|
139
|
+
const select = columns === undefined ? this.#select : columns.map(quote).join(", ");
|
|
140
|
+
return { sql: `SELECT ${select} FROM ${quote(this.table)}${filter} ORDER BY ${sorting} LIMIT ?`, params };
|
|
141
|
+
}
|
|
142
|
+
/** `count(*)` of the rows matching `where`. */
|
|
143
|
+
count(where) {
|
|
144
|
+
const params = [];
|
|
145
|
+
const filter = where === undefined ? "" : ` WHERE ${whereSql(where, params)}`;
|
|
146
|
+
return { sql: `SELECT count(*) AS count FROM ${quote(this.table)}${filter}`, params };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** The assignments of `set`; a written `json(...)` column also stamps its version (a clear stamps `NULL`). */
|
|
150
|
+
function setSql(set, versions, params) {
|
|
151
|
+
const assignments = [];
|
|
152
|
+
for (const [column, node] of Object.entries(set)) {
|
|
153
|
+
assignments.push(`${quote(column)} = ${exprSql(node, params)}`);
|
|
154
|
+
const version = versions.get(column);
|
|
155
|
+
if (version !== undefined) {
|
|
156
|
+
assignments.push(`${quote(versionColumn(column))} = ?`);
|
|
157
|
+
params.push(node === null ? null : version);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return assignments.join(", ");
|
|
161
|
+
}
|
|
162
|
+
function exprSql(node, params) {
|
|
163
|
+
if (node === null)
|
|
164
|
+
return "NULL";
|
|
165
|
+
if (typeof node !== "object") {
|
|
166
|
+
params.push(toSqlite(node));
|
|
167
|
+
return "?";
|
|
168
|
+
}
|
|
169
|
+
if ("col" in node)
|
|
170
|
+
return quote(node.col);
|
|
171
|
+
if ("json" in node) {
|
|
172
|
+
// Serialized once at staging already (rule 8): this cannot throw.
|
|
173
|
+
params.push(JSON.stringify(node.json));
|
|
174
|
+
return "?";
|
|
175
|
+
}
|
|
176
|
+
if ("when" in node) {
|
|
177
|
+
const [condition, a, b] = node.when;
|
|
178
|
+
return `(CASE WHEN ${whereSql(condition, params)} THEN ${exprSql(a, params)} ELSE ${exprSql(b, params)} END)`;
|
|
179
|
+
}
|
|
180
|
+
if ("replacePrefix" in node) {
|
|
181
|
+
const [subject, from, to] = node.replacePrefix;
|
|
182
|
+
const length = [...from].length;
|
|
183
|
+
// SQLite's `substr` counts characters of UTF-8 text: code points, as the prefix's length does.
|
|
184
|
+
// Parameters in the order their `?` occur in the text.
|
|
185
|
+
const value = exprSql(subject, params);
|
|
186
|
+
params.push(length, from, to);
|
|
187
|
+
const rest = exprSql(subject, params);
|
|
188
|
+
params.push(length + 1);
|
|
189
|
+
const unchanged = exprSql(subject, params);
|
|
190
|
+
return `(CASE WHEN substr(${value}, 1, ?) = ? THEN ? || substr(${rest}, ?) ELSE ${unchanged} END)`;
|
|
191
|
+
}
|
|
192
|
+
if ("coalesce" in node)
|
|
193
|
+
return `coalesce(${exprSql(node.coalesce[0], params)}, ${exprSql(node.coalesce[1], params)})`;
|
|
194
|
+
if ("add" in node)
|
|
195
|
+
return `(${exprSql(node.add[0], params)} + ${exprSql(node.add[1], params)})`;
|
|
196
|
+
if ("sub" in node)
|
|
197
|
+
return `(${exprSql(node.sub[0], params)} - ${exprSql(node.sub[1], params)})`;
|
|
198
|
+
if ("max" in node)
|
|
199
|
+
return `max(${exprSql(node.max[0], params)}, ${exprSql(node.max[1], params)})`;
|
|
200
|
+
if ("min" in node)
|
|
201
|
+
return `min(${exprSql(node.min[0], params)}, ${exprSql(node.min[1], params)})`;
|
|
202
|
+
return `(${exprSql(node.concat[0], params)} || ${exprSql(node.concat[1], params)})`;
|
|
203
|
+
}
|
|
204
|
+
const COMPARISONS = { eq: "=", ne: "<>", lt: "<", lte: "<=", gt: ">", gte: ">=" };
|
|
205
|
+
/** A condition with its operands bound; SQL's `NULL` rules are the vocabulary's. */
|
|
206
|
+
export function whereSql(node, params) {
|
|
207
|
+
if ("and" in node)
|
|
208
|
+
return node.and.length === 0 ? "1" : `(${node.and.map((each) => whereSql(each, params)).join(" AND ")})`;
|
|
209
|
+
if ("or" in node)
|
|
210
|
+
return node.or.length === 0 ? "0" : `(${node.or.map((each) => whereSql(each, params)).join(" OR ")})`;
|
|
211
|
+
if ("not" in node)
|
|
212
|
+
return `(NOT ${whereSql(node.not, params)})`;
|
|
213
|
+
if ("isNull" in node)
|
|
214
|
+
return `${quote(node.isNull)} IS NULL`;
|
|
215
|
+
if ("inArray" in node) {
|
|
216
|
+
const [column, values] = node.inArray;
|
|
217
|
+
params.push(JSON.stringify(values.map(toSqlite)));
|
|
218
|
+
return `${quote(column)} IN (SELECT value FROM json_each(?))`;
|
|
219
|
+
}
|
|
220
|
+
if ("prefix" in node) {
|
|
221
|
+
const [column, prefix] = node.prefix;
|
|
222
|
+
const upper = prefixUpperBound(prefix);
|
|
223
|
+
params.push(prefix);
|
|
224
|
+
if (upper === undefined)
|
|
225
|
+
return `${quote(column)} >= ?`;
|
|
226
|
+
params.push(upper);
|
|
227
|
+
return `(${quote(column)} >= ? AND ${quote(column)} < ?)`;
|
|
228
|
+
}
|
|
229
|
+
// The remaining nodes are the comparisons, one entry each; `Object.entries` loses that.
|
|
230
|
+
const [op, [column, value]] = Object.entries(node)[0];
|
|
231
|
+
params.push(toSqlite(value));
|
|
232
|
+
return `${quote(column)} ${COMPARISONS[op]} ?`;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=sql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../../../src/next/store/sql.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,oHAAoH;AACpH,+FAA+F;AAK/F,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAQ7C,+BAA+B;AAC/B,MAAM,UAAU,KAAK,CAAC,IAAY;IACjC,OAAO,IAAI,IAAI,GAAG,CAAC;AACpB,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa;IACxD,OAAO,GAAG,KAAK,IAAI,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAa,EACb,OAAkD,EAClD,GAAsB;IAEtB,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACjG,WAAW,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;IAC3D,WAAW,CAAC,IAAI,CAAC,gBA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C,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;IAC3D,CAAC;IACD,wFAAwF;IACxF,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAGnD,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7B,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC;AAChD,CAAC","sourcesContent":["// SQL of declared tables (slice 6a §5, §6, §7): the DDL a table definition renders, and the statements of its reads\n// and writes, generated from the compiled vocabulary with every value bound and every identifier quoted. Names were\n// checked at declaration (and at import), so no `\"` occurs in them and quoting is always safe.\n\nimport type { SqliteValue } from \"../../sqlite/index.ts\";\nimport type { Column, ColumnRecord } from \"./columns.ts\";\nimport type { ExprNode, SetNode, WhereNode } from \"./expression.ts\";\nimport { physicalColumns, ROW_VERSION, toSqlite, versionColumn } from \"./rows.ts\";\nimport { prefixUpperBound } from \"./text.ts\";\n\n/** A statement and its parameters. */\nexport type Statement = { readonly sql: string; readonly params: SqliteValue[] };\n\n/** An order of rows: the order columns (the key appended as the tie-break) and one direction. */\nexport type Order = { readonly columns: readonly string[]; readonly direction: \"asc\" | \"desc\" };\n\n/** A quoted SQL identifier. */\nexport function quote(name: string): string {\n\treturn `\"${name}\"`;\n}\n\n/** The SQL name of an owner's table: `<owner>:<table>` (R2), injective since neither part contains `:`. */\nexport function tableSqlName(owner: string, table: string): string {\n\treturn `${owner}:${table}`;\n}\n\n/**\n * `CREATE TABLE` for `columns` (as recorded) and `key`: `STRICT`, the key as primary key (`WITHOUT ROWID`, except\n * for a single `int` key, which becomes the rowid: the fastest point lookups, and rows of any size), an `int`\n * column checked within ±(2^53 - 1) (rule 10), a `bool` one within 0 and 1, a `json(...)` one as `TEXT` with its\n * version column, and the row's `$v`.\n */\nexport function createTableSql(\n\ttable: string,\n\tcolumns: { readonly [name: string]: ColumnRecord },\n\tkey: readonly string[],\n): string {\n\tconst definitions = Object.entries(columns).flatMap(([name, column]) => columnSql(name, column));\n\tdefinitions.push(`${quote(ROW_VERSION)} INTEGER NOT NULL`);\n\tdefinitions.push(`PRIMARY KEY (${key.map(quote).join(\", \")})`);\n\tconst rowid = key.length === 1 && columns[key[0]!]!.type === \"int\";\n\treturn `CREATE TABLE ${quote(table)} (${definitions.join(\", \")}) STRICT${rowid ? \"\" : \", WITHOUT ROWID\"}`;\n}\n\nconst SAFE = Number.MAX_SAFE_INTEGER;\n\n/** The definitions of one column: itself, and a `json(...)` column's version column. */\nexport function columnSql(name: string, column: ColumnRecord): string[] {\n\tconst nullability = column.optional ? \"\" : \" NOT NULL\";\n\tconst defaulted = column.default === undefined ? \"\" : ` DEFAULT ${literal(column.default)}`;\n\tconst id = quote(name);\n\tswitch (column.type) {\n\t\tcase \"str\":\n\t\t\treturn [`${id} TEXT${nullability}${defaulted}`];\n\t\tcase \"int\":\n\t\t\treturn [`${id} INTEGER${nullability}${defaulted} CHECK (${id} BETWEEN ${-SAFE} AND ${SAFE})`];\n\t\tcase \"num\":\n\t\t\treturn [`${id} REAL${nullability}${defaulted}`];\n\t\tcase \"bool\":\n\t\t\treturn [`${id} INTEGER${nullability}${defaulted} CHECK (${id} IN (0, 1))`];\n\t\tcase \"json\":\n\t\t\treturn [`${id} TEXT${nullability}`, `${quote(versionColumn(name))} INTEGER${nullability}`];\n\t}\n}\n\n/** A default as a SQL literal: declaration data (checked), which DDL cannot bind. */\nfunction literal(value: string | number | boolean): string {\n\tif (typeof value === \"string\") return `'${value.replaceAll(\"'\", \"''\")}'`;\n\treturn typeof value === \"boolean\" ? (value ? \"1\" : \"0\") : String(value);\n}\n\n/**\n * The physical columns of a recorded table in the order `RowCodec.physical` uses (`physicalColumns`), and its\n * whole-row `INSERT OR REPLACE` over them.\n */\nexport function recordedPut(\n\ttable: string,\n\tcolumns: { readonly [name: string]: ColumnRecord },\n): { readonly physical: readonly string[]; readonly sql: string } {\n\tconst physical = physicalColumns(Object.entries(columns).map(([name, { type }]) => ({ name, type })));\n\treturn { physical, sql: putSql(table, physical) };\n}\n\n/** `INSERT OR REPLACE` of a whole row over `physical` (`put` is an upsert). */\nfunction putSql(table: string, physical: readonly string[]): string {\n\treturn `INSERT OR REPLACE INTO ${quote(table)} (${physical.map(quote).join(\", \")}) VALUES (${physical.map(() => \"?\").join(\", \")})`;\n}\n\n/** `CREATE INDEX` named `<table>:<index>` over `columns`, the key appended (every index ends with it). */\nexport function createIndexSql(\n\ttable: string,\n\tindex: string,\n\tcolumns: readonly string[],\n\tkey: readonly string[],\n): string {\n\tconst all = [...columns, ...key.filter((column) => !columns.includes(column))];\n\treturn `CREATE INDEX ${quote(`${table}:${index}`)} ON ${quote(table)} (${all.map(quote).join(\", \")})`;\n}\n\n/** `DROP INDEX` of `<table>:<index>`. */\nexport function dropIndexSql(table: string, index: string): string {\n\treturn `DROP INDEX ${quote(`${table}:${index}`)}`;\n}\n\n/**\n * The statements of one table at one version, rendered once per table handle: the fixed ones as texts, the ones\n * over compiled conditions and `set`s on demand.\n */\nexport class TableSql {\n\treadonly table: string;\n\t/** The columns a read selects: the declared ones and each `json(...)` column's version. */\n\treadonly #select: string;\n\treadonly #byKey: string;\n\t/** `INSERT OR REPLACE` of a whole row, in `RowCodec.physical`'s order (`put` is an upsert). */\n\treadonly put: string;\n\treadonly get: string;\n\treadonly delete: string;\n\n\tconstructor(\n\t\ttable: string,\n\t\tcolumns: readonly Pick<Column, \"name\" | \"type\">[],\n\t\tphysical: readonly string[],\n\t\tkey: readonly string[],\n\t) {\n\t\tthis.table = table;\n\t\tconst id = quote(table);\n\t\tthis.#select = [\n\t\t\t...columns.map(({ name }) => quote(name)),\n\t\t\t...columns.filter(({ type }) => type === \"json\").map(({ name }) => quote(versionColumn(name))),\n\t\t].join(\", \");\n\t\tthis.#byKey = key.map((column) => `${quote(column)} = ?`).join(\" AND \");\n\t\tthis.put = putSql(table, physical);\n\t\tthis.get = `SELECT ${this.#select} FROM ${id} WHERE ${this.#byKey}`;\n\t\tthis.delete = `DELETE FROM ${id} WHERE ${this.#byKey}`;\n\t}\n\n\t/** `SELECT` of `columns` of one row by key: a point lookup, without the `ORDER BY` and `LIMIT` of a page. */\n\tgetColumns(columns: readonly string[]): string {\n\t\treturn `SELECT ${columns.map(quote).join(\", \")} FROM ${quote(this.table)} WHERE ${this.#byKey}`;\n\t}\n\n\t/** `UPDATE` of one row by key; `versions` gives each `json(...)` column's version to stamp. */\n\tupdate(set: SetNode, key: readonly SqliteValue[], versions: ReadonlyMap<string, number>): Statement {\n\t\tconst params: SqliteValue[] = [];\n\t\tconst assignments = setSql(set, versions, params);\n\t\tparams.push(...key);\n\t\treturn { sql: `UPDATE ${quote(this.table)} SET ${assignments} WHERE ${this.#byKey}`, params };\n\t}\n\n\t/** `UPDATE` of every row matching `where`. */\n\tupdateWhere(where: WhereNode, set: SetNode, versions: ReadonlyMap<string, number>): Statement {\n\t\tconst params: SqliteValue[] = [];\n\t\tconst assignments = setSql(set, versions, params);\n\t\tconst condition = whereSql(where, params);\n\t\treturn { sql: `UPDATE ${quote(this.table)} SET ${assignments} WHERE ${condition}`, params };\n\t}\n\n\t/** `DELETE` of every row matching `where`. */\n\tdeleteWhere(where: WhereNode): Statement {\n\t\tconst params: SqliteValue[] = [];\n\t\treturn { sql: `DELETE FROM ${quote(this.table)} WHERE ${whereSql(where, params)}`, params };\n\t}\n\n\t/**\n\t * A page: rows matching `where` in `order`, after the order values `after` (row-value comparison; the key in the\n\t * order makes it total), at most `limit` (bound); every column, or only `columns`.\n\t */\n\tselect(\n\t\twhere: WhereNode | undefined,\n\t\torder: Order,\n\t\tafter: readonly SqliteValue[] | undefined,\n\t\tlimit: number,\n\t\tcolumns?: readonly string[],\n\t): Statement {\n\t\tconst params: SqliteValue[] = [];\n\t\tconst conditions: string[] = [];\n\t\tif (where !== undefined) conditions.push(whereSql(where, params));\n\t\tif (after !== undefined) {\n\t\t\tconst columns = order.columns.map(quote).join(\", \");\n\t\t\tconditions.push(`(${columns}) ${order.direction === \"asc\" ? \">\" : \"<\"} (${after.map(() => \"?\").join(\", \")})`);\n\t\t\tparams.push(...after);\n\t\t}\n\t\tconst filter = conditions.length === 0 ? \"\" : ` WHERE ${conditions.join(\" AND \")}`;\n\t\tconst direction = order.direction === \"asc\" ? \"ASC\" : \"DESC\";\n\t\tconst sorting = order.columns.map((column) => `${quote(column)} ${direction}`).join(\", \");\n\t\tparams.push(limit);\n\t\tconst select = columns === undefined ? this.#select : columns.map(quote).join(\", \");\n\t\treturn { sql: `SELECT ${select} FROM ${quote(this.table)}${filter} ORDER BY ${sorting} LIMIT ?`, params };\n\t}\n\n\t/** `count(*)` of the rows matching `where`. */\n\tcount(where: WhereNode | undefined): Statement {\n\t\tconst params: SqliteValue[] = [];\n\t\tconst filter = where === undefined ? \"\" : ` WHERE ${whereSql(where, params)}`;\n\t\treturn { sql: `SELECT count(*) AS count FROM ${quote(this.table)}${filter}`, params };\n\t}\n}\n\n/** The assignments of `set`; a written `json(...)` column also stamps its version (a clear stamps `NULL`). */\nfunction setSql(set: SetNode, versions: ReadonlyMap<string, number>, params: SqliteValue[]): string {\n\tconst assignments: string[] = [];\n\tfor (const [column, node] of Object.entries(set)) {\n\t\tassignments.push(`${quote(column)} = ${exprSql(node, params)}`);\n\t\tconst version = versions.get(column);\n\t\tif (version !== undefined) {\n\t\t\tassignments.push(`${quote(versionColumn(column))} = ?`);\n\t\t\tparams.push(node === null ? null : version);\n\t\t}\n\t}\n\treturn assignments.join(\", \");\n}\n\nfunction exprSql(node: ExprNode, params: SqliteValue[]): string {\n\tif (node === null) return \"NULL\";\n\tif (typeof node !== \"object\") {\n\t\tparams.push(toSqlite(node));\n\t\treturn \"?\";\n\t}\n\tif (\"col\" in node) return quote(node.col);\n\tif (\"json\" in node) {\n\t\t// Serialized once at staging already (rule 8): this cannot throw.\n\t\tparams.push(JSON.stringify(node.json));\n\t\treturn \"?\";\n\t}\n\tif (\"when\" in node) {\n\t\tconst [condition, a, b] = node.when;\n\t\treturn `(CASE WHEN ${whereSql(condition, params)} THEN ${exprSql(a, params)} ELSE ${exprSql(b, params)} END)`;\n\t}\n\tif (\"replacePrefix\" in node) {\n\t\tconst [subject, from, to] = node.replacePrefix;\n\t\tconst length = [...from].length;\n\t\t// SQLite's `substr` counts characters of UTF-8 text: code points, as the prefix's length does.\n\t\t// Parameters in the order their `?` occur in the text.\n\t\tconst value = exprSql(subject, params);\n\t\tparams.push(length, from, to);\n\t\tconst rest = exprSql(subject, params);\n\t\tparams.push(length + 1);\n\t\tconst unchanged = exprSql(subject, params);\n\t\treturn `(CASE WHEN substr(${value}, 1, ?) = ? THEN ? || substr(${rest}, ?) ELSE ${unchanged} END)`;\n\t}\n\tif (\"coalesce\" in node)\n\t\treturn `coalesce(${exprSql(node.coalesce[0], params)}, ${exprSql(node.coalesce[1], params)})`;\n\tif (\"add\" in node) return `(${exprSql(node.add[0], params)} + ${exprSql(node.add[1], params)})`;\n\tif (\"sub\" in node) return `(${exprSql(node.sub[0], params)} - ${exprSql(node.sub[1], params)})`;\n\tif (\"max\" in node) return `max(${exprSql(node.max[0], params)}, ${exprSql(node.max[1], params)})`;\n\tif (\"min\" in node) return `min(${exprSql(node.min[0], params)}, ${exprSql(node.min[1], params)})`;\n\treturn `(${exprSql(node.concat[0], params)} || ${exprSql(node.concat[1], params)})`;\n}\n\nconst COMPARISONS = { eq: \"=\", ne: \"<>\", lt: \"<\", lte: \"<=\", gt: \">\", gte: \">=\" } as const;\n\n/** A condition with its operands bound; SQL's `NULL` rules are the vocabulary's. */\nexport function whereSql(node: WhereNode, params: SqliteValue[]): string {\n\tif (\"and\" in node)\n\t\treturn node.and.length === 0 ? \"1\" : `(${node.and.map((each) => whereSql(each, params)).join(\" AND \")})`;\n\tif (\"or\" in node)\n\t\treturn node.or.length === 0 ? \"0\" : `(${node.or.map((each) => whereSql(each, params)).join(\" OR \")})`;\n\tif (\"not\" in node) return `(NOT ${whereSql(node.not, params)})`;\n\tif (\"isNull\" in node) return `${quote(node.isNull)} IS NULL`;\n\tif (\"inArray\" in node) {\n\t\tconst [column, values] = node.inArray;\n\t\tparams.push(JSON.stringify(values.map(toSqlite)));\n\t\treturn `${quote(column)} IN (SELECT value FROM json_each(?))`;\n\t}\n\tif (\"prefix\" in node) {\n\t\tconst [column, prefix] = node.prefix;\n\t\tconst upper = prefixUpperBound(prefix);\n\t\tparams.push(prefix);\n\t\tif (upper === undefined) return `${quote(column)} >= ?`;\n\t\tparams.push(upper);\n\t\treturn `(${quote(column)} >= ? AND ${quote(column)} < ?)`;\n\t}\n\t// The remaining nodes are the comparisons, one entry each; `Object.entries` loses that.\n\tconst [op, [column, value]] = Object.entries(node)[0] as [\n\t\tkeyof typeof COMPARISONS,\n\t\treadonly [string, string | number | boolean],\n\t];\n\tparams.push(toSqlite(value));\n\treturn `${quote(column)} ${COMPARISONS[op]} ?`;\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SqliteExecutor, SqliteValue } from "../../sqlite/index.ts";
|
|
2
|
+
import type { IdAllocator } from "./allocator.ts";
|
|
3
|
+
import type { TableRecord } from "./catalog.ts";
|
|
4
|
+
import type { StoreWrite } from "./writes.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Where a staged write goes in its commit: retirements, creations, then everything else, each phase in staging order.
|
|
7
|
+
* A retirement frees a live address before a creation takes it (the partial unique index); an adapter's composite
|
|
8
|
+
* write orders its own parts inside `write`.
|
|
9
|
+
*/
|
|
10
|
+
export type WriteOrder = "retire" | "create" | "write";
|
|
11
|
+
/** A write staged for the commit step: its order and what it does there, returning the writes as recorded. */
|
|
12
|
+
export type StagedWrite = {
|
|
13
|
+
readonly order: WriteOrder;
|
|
14
|
+
/**
|
|
15
|
+
* Applies the write inside the step's backend transaction; resolves with the writes as the outbox records them, in
|
|
16
|
+
* the order applied, with what only the step knows resolved (its seq, a record's revision).
|
|
17
|
+
*/
|
|
18
|
+
apply(step: Step): Promise<readonly StoreWrite[]>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* One commit step: its backend transaction, its seq, the store's id allocator (D3: ids are taken from it as the
|
|
22
|
+
* writes apply, never copied), the ids of the documents it created, the table records it changed (the store's catalog
|
|
23
|
+
* takes them after `COMMIT`) and the statements it ran (`chord.store.statements`). Its reads are the step reader of
|
|
24
|
+
* adapters: they see the step's own writes.
|
|
25
|
+
*/
|
|
26
|
+
export declare class Step {
|
|
27
|
+
#private;
|
|
28
|
+
readonly executor: SqliteExecutor;
|
|
29
|
+
readonly seq: number;
|
|
30
|
+
readonly ids: IdAllocator;
|
|
31
|
+
/** The ids of the commit's created documents, in the order of their writes. */
|
|
32
|
+
readonly created: number[];
|
|
33
|
+
/** The table records this step changed, by SQL name. */
|
|
34
|
+
readonly tables: Map<string, TableRecord>;
|
|
35
|
+
statements: number;
|
|
36
|
+
constructor(executor: SqliteExecutor, seq: number, ids: IdAllocator, catalog: ReadonlyMap<string, TableRecord>);
|
|
37
|
+
/** The record of table `name` as this step leaves it so far. */
|
|
38
|
+
table(name: string): TableRecord | undefined;
|
|
39
|
+
/** Runs one statement. */
|
|
40
|
+
run(sql: string, ...params: SqliteValue[]): Promise<void>;
|
|
41
|
+
/** Runs one statement and resolves with the rows it changed. */
|
|
42
|
+
runCounted(sql: string, ...params: SqliteValue[]): Promise<number>;
|
|
43
|
+
/** Runs one query for its first row. */
|
|
44
|
+
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
45
|
+
/** Runs one query. */
|
|
46
|
+
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AED,gEAAgE;IAChE,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAGjE;IAED,wCAAwC;IACxC,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAGnF;IAED,sBAAsB;IACtB,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAGzE;CACD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The commit step's working state (slice 6a §3, slice 6b §1.3) and the shape every write takes into it: a write staged
|
|
2
|
+
// before the queue (serialized, rule 8), applied inside the step, returning the writes it recorded.
|
|
3
|
+
/**
|
|
4
|
+
* One commit step: its backend transaction, its seq, the store's id allocator (D3: ids are taken from it as the
|
|
5
|
+
* writes apply, never copied), the ids of the documents it created, the table records it changed (the store's catalog
|
|
6
|
+
* takes them after `COMMIT`) and the statements it ran (`chord.store.statements`). Its reads are the step reader of
|
|
7
|
+
* adapters: they see the step's own writes.
|
|
8
|
+
*/
|
|
9
|
+
export class Step {
|
|
10
|
+
executor;
|
|
11
|
+
seq;
|
|
12
|
+
ids;
|
|
13
|
+
/** The ids of the commit's created documents, in the order of their writes. */
|
|
14
|
+
created = [];
|
|
15
|
+
/** The table records this step changed, by SQL name. */
|
|
16
|
+
tables = new Map();
|
|
17
|
+
#catalog;
|
|
18
|
+
statements = 0;
|
|
19
|
+
constructor(executor, seq, ids, catalog) {
|
|
20
|
+
this.executor = executor;
|
|
21
|
+
this.seq = seq;
|
|
22
|
+
this.ids = ids;
|
|
23
|
+
this.#catalog = catalog;
|
|
24
|
+
}
|
|
25
|
+
/** The record of table `name` as this step leaves it so far. */
|
|
26
|
+
table(name) {
|
|
27
|
+
return this.tables.get(name) ?? this.#catalog.get(name);
|
|
28
|
+
}
|
|
29
|
+
/** Runs one statement. */
|
|
30
|
+
run(sql, ...params) {
|
|
31
|
+
this.statements++;
|
|
32
|
+
return this.executor.run(sql, ...params);
|
|
33
|
+
}
|
|
34
|
+
/** Runs one statement and resolves with the rows it changed. */
|
|
35
|
+
runCounted(sql, ...params) {
|
|
36
|
+
this.statements++;
|
|
37
|
+
return this.executor.runCounted(sql, ...params);
|
|
38
|
+
}
|
|
39
|
+
/** Runs one query for its first row. */
|
|
40
|
+
get(sql, ...params) {
|
|
41
|
+
this.statements++;
|
|
42
|
+
return this.executor.get(sql, ...params);
|
|
43
|
+
}
|
|
44
|
+
/** Runs one query. */
|
|
45
|
+
all(sql, ...params) {
|
|
46
|
+
this.statements++;
|
|
47
|
+
return this.executor.all(sql, ...params);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.js","sourceRoot":"","sources":["../../../src/next/store/step.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,oGAAoG;AAwBpG;;;;;GAKG;AACH,MAAM,OAAO,IAAI;IACP,QAAQ,CAAiB;IACzB,GAAG,CAAS;IACZ,GAAG,CAAc;IAC1B,+EAA+E;IACtE,OAAO,GAAa,EAAE,CAAC;IAChC,wDAAwD;IAC/C,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IACxC,QAAQ,CAAmC;IACpD,UAAU,GAAG,CAAC,CAAC;IAEf,YAAY,QAAwB,EAAE,GAAW,EAAE,GAAgB,EAAE,OAAyC;QAC7G,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,gEAAgE;IAChE,KAAK,CAAC,IAAY;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,0BAA0B;IAC1B,GAAG,CAAC,GAAW,EAAE,GAAG,MAAqB;QACxC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,gEAAgE;IAChE,UAAU,CAAC,GAAW,EAAE,GAAG,MAAqB;QAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,wCAAwC;IACxC,GAAG,CAAmB,GAAW,EAAE,GAAG,MAAqB;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAI,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,sBAAsB;IACtB,GAAG,CAAmB,GAAW,EAAE,GAAG,MAAqB;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAI,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["// The commit step's working state (slice 6a §3, slice 6b §1.3) and the shape every write takes into it: a write staged\n// before the queue (serialized, rule 8), applied inside the step, returning the writes it recorded.\n\nimport type { SqliteExecutor, SqliteValue } from \"../../sqlite/index.ts\";\nimport type { IdAllocator } from \"./allocator.ts\";\nimport type { TableRecord } from \"./catalog.ts\";\nimport type { StoreWrite } from \"./writes.ts\";\n\n/**\n * Where a staged write goes in its commit: retirements, creations, then everything else, each phase in staging order.\n * A retirement frees a live address before a creation takes it (the partial unique index); an adapter's composite\n * write orders its own parts inside `write`.\n */\nexport type WriteOrder = \"retire\" | \"create\" | \"write\";\n\n/** A write staged for the commit step: its order and what it does there, returning the writes as recorded. */\nexport type StagedWrite = {\n\treadonly order: WriteOrder;\n\t/**\n\t * Applies the write inside the step's backend transaction; resolves with the writes as the outbox records them, in\n\t * the order applied, with what only the step knows resolved (its seq, a record's revision).\n\t */\n\tapply(step: Step): Promise<readonly StoreWrite[]>;\n};\n\n/**\n * One commit step: its backend transaction, its seq, the store's id allocator (D3: ids are taken from it as the\n * writes apply, never copied), the ids of the documents it created, the table records it changed (the store's catalog\n * takes them after `COMMIT`) and the statements it ran (`chord.store.statements`). Its reads are the step reader of\n * adapters: they see the step's own writes.\n */\nexport class Step {\n\treadonly executor: SqliteExecutor;\n\treadonly seq: number;\n\treadonly ids: IdAllocator;\n\t/** The ids of the commit's created documents, in the order of their writes. */\n\treadonly created: number[] = [];\n\t/** The table records this step changed, by SQL name. */\n\treadonly tables = new Map<string, TableRecord>();\n\treadonly #catalog: ReadonlyMap<string, TableRecord>;\n\tstatements = 0;\n\n\tconstructor(executor: SqliteExecutor, seq: number, ids: IdAllocator, catalog: ReadonlyMap<string, TableRecord>) {\n\t\tthis.executor = executor;\n\t\tthis.seq = seq;\n\t\tthis.ids = ids;\n\t\tthis.#catalog = catalog;\n\t}\n\n\t/** The record of table `name` as this step leaves it so far. */\n\ttable(name: string): TableRecord | undefined {\n\t\treturn this.tables.get(name) ?? this.#catalog.get(name);\n\t}\n\n\t/** Runs one statement. */\n\trun(sql: string, ...params: SqliteValue[]): Promise<void> {\n\t\tthis.statements++;\n\t\treturn this.executor.run(sql, ...params);\n\t}\n\n\t/** Runs one statement and resolves with the rows it changed. */\n\trunCounted(sql: string, ...params: SqliteValue[]): Promise<number> {\n\t\tthis.statements++;\n\t\treturn this.executor.runCounted(sql, ...params);\n\t}\n\n\t/** Runs one query for its first row. */\n\tget<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined> {\n\t\tthis.statements++;\n\t\treturn this.executor.get<T>(sql, ...params);\n\t}\n\n\t/** Runs one query. */\n\tall<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]> {\n\t\tthis.statements++;\n\t\treturn this.executor.all<T>(sql, ...params);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { type Context } from "../../context/index.ts";
|
|
2
|
+
import type { SqliteDatabase, SqliteExecutor } from "../../sqlite/index.ts";
|
|
3
|
+
import type { Batch } from "../state/internal.ts";
|
|
4
|
+
import { IdAllocator } from "./allocator.ts";
|
|
5
|
+
import type { ArchivePart } from "./archive.ts";
|
|
6
|
+
import type { Backend } from "./backend.ts";
|
|
7
|
+
import { type TableRecord } from "./catalog.ts";
|
|
8
|
+
import { Claims } from "./claims.ts";
|
|
9
|
+
import { Outbox } from "./outbox.ts";
|
|
10
|
+
import { type MetaRow } from "./schema.ts";
|
|
11
|
+
import { type StagedWrite, Step } from "./step.ts";
|
|
12
|
+
/** A store as apps hold it: opened by `openStore`, owned and closed by the app. */
|
|
13
|
+
export interface Store {
|
|
14
|
+
/** The seq of the store's last commit (0 for a new store). */
|
|
15
|
+
readonly lastSeq: number;
|
|
16
|
+
/** The outbox the sync layer reads; `undefined` without one. */
|
|
17
|
+
readonly outbox: Outbox | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The store's state after its `lastSeq` as archive parts (slice 6a §13), holding the commit queue from the first
|
|
20
|
+
* `next()` until the iteration ends, throws, is closed or `context` aborts.
|
|
21
|
+
*/
|
|
22
|
+
export(context: Context): AsyncIterableIterator<ArchivePart>;
|
|
23
|
+
/**
|
|
24
|
+
* Closes the store: waits for a running commit step, rejects queued commits and reads `released`, closes the
|
|
25
|
+
* backend. Idempotent, also after `storage_failed`; `context` ends only this caller's wait (the close goes on).
|
|
26
|
+
*/
|
|
27
|
+
close(context: Context): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/** What `openStore` takes besides the backend. */
|
|
30
|
+
export type StoreOptions = {
|
|
31
|
+
/** Turns the outbox on (`true`) or off (`false`); omitted, the persisted setting stays (a new store: off). */
|
|
32
|
+
readonly outbox?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Opens a store over `backend`: the store's schema migrations, the UTF-8 check, the metadata read once, the outbox
|
|
36
|
+
* switched when asked. A failure closes the backend and rejects (rule 12).
|
|
37
|
+
*/
|
|
38
|
+
export declare function openStore(backend: Backend, context: Context, options?: StoreOptions): Promise<Store>;
|
|
39
|
+
/** The seal fence's two checks of a commit (§1.3), as the commit step calls them. */
|
|
40
|
+
export type CommitFence = {
|
|
41
|
+
/** At the step's entry: `false` rejects the commit `released` and writes nothing. */
|
|
42
|
+
admit(): boolean;
|
|
43
|
+
/** After `COMMIT`: adopts the commit, `ids` being its created documents' ids in the order of their writes. */
|
|
44
|
+
adopt(seq: number, ids: readonly number[]): void;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* One commit of a series (`ChordStore.commitSeries`): its own checks, which write nothing, and its writes. The checks
|
|
48
|
+
* read through the commit's step, which sees what the series' earlier commits wrote.
|
|
49
|
+
*/
|
|
50
|
+
export type SeriesCommit = {
|
|
51
|
+
/** Throws to refuse the commit: the series stops before it, the commits before it stand. */
|
|
52
|
+
check(step: Step): Promise<void>;
|
|
53
|
+
readonly writes: readonly StagedWrite[];
|
|
54
|
+
};
|
|
55
|
+
/** What a series stored: how many of its commits, and why the next one was refused, if one was. */
|
|
56
|
+
export type SeriesResult = {
|
|
57
|
+
readonly stored: number;
|
|
58
|
+
readonly refused?: unknown;
|
|
59
|
+
};
|
|
60
|
+
/** What the open host gives the store: its `storage_failed` listener and its batch, in which adapters publish (§1.3). */
|
|
61
|
+
export type Attachment = {
|
|
62
|
+
readonly failed: (error: unknown) => void;
|
|
63
|
+
readonly batch: Batch;
|
|
64
|
+
};
|
|
65
|
+
/** Where a replayed batch leaves the store: its last commit's seq and allocator value, the tables it changed. */
|
|
66
|
+
export type Replayed = {
|
|
67
|
+
readonly lastSeq: number;
|
|
68
|
+
readonly nextId: number;
|
|
69
|
+
readonly tables: ReadonlyMap<string, TableRecord>;
|
|
70
|
+
};
|
|
71
|
+
/** The store behind `Store`, with what Chord's layers use: commits, guarded reads, the host's failure listener. */
|
|
72
|
+
export declare class ChordStore implements Store {
|
|
73
|
+
#private;
|
|
74
|
+
/** The claims of its tables and documents (slice 6b). */
|
|
75
|
+
readonly claims: Claims;
|
|
76
|
+
constructor(db: SqliteDatabase, meta: MetaRow, catalog: Map<string, TableRecord>);
|
|
77
|
+
get lastSeq(): number;
|
|
78
|
+
get outbox(): Outbox | undefined;
|
|
79
|
+
/** The allocator's value as the last commit persisted it. */
|
|
80
|
+
get nextId(): number;
|
|
81
|
+
/** The id allocator: `mint` takes the next id, `raise` makes room above an explicit one (D3). */
|
|
82
|
+
get ids(): IdAllocator;
|
|
83
|
+
/** Takes the next id from the allocator (Durable's `mintId`); refused once the store stopped or closed. */
|
|
84
|
+
mintId(): number;
|
|
85
|
+
/** The open host's batch, in which an adapter publishes its commits; `undefined` without a host. */
|
|
86
|
+
get batch(): Batch | undefined;
|
|
87
|
+
/** Every recorded table, by SQL name, as of the last commit. */
|
|
88
|
+
get tables(): ReadonlyMap<string, TableRecord>;
|
|
89
|
+
export(context: Context): AsyncIterableIterator<ArchivePart>;
|
|
90
|
+
/**
|
|
91
|
+
* Takes the commit queue (an export): resolves once every earlier commit settled, with the release that lets the
|
|
92
|
+
* later ones run (idempotent). Closing the store calls `end` (from the call on, also while waiting, and at once for a
|
|
93
|
+
* store closed before the call took the queue), which must release.
|
|
94
|
+
*/
|
|
95
|
+
take(end: () => void): Promise<() => void>;
|
|
96
|
+
/** The recorded table `name` (its SQL name), as of the last commit. */
|
|
97
|
+
table(name: string): TableRecord | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* The version table `name` is at or is being migrated to: the recorded one, or a higher one a migration announced
|
|
100
|
+
* before its first commit (`announceTable`), so an old handle is refused before its SQL could queue behind the
|
|
101
|
+
* migration's DDL (fix round 1, Sol 8).
|
|
102
|
+
*/
|
|
103
|
+
tableVersion(name: string): number | undefined;
|
|
104
|
+
/** Announces a migration of table `name` to `version` until the returned withdrawal (after its last commit). */
|
|
105
|
+
announceTable(name: string, version: number): () => void;
|
|
106
|
+
/** Attaches the open host; a store attached to an open host is refused (rule 7). */
|
|
107
|
+
attach(attachment: Attachment): void;
|
|
108
|
+
/** The host closed: the store may serve another one. */
|
|
109
|
+
detach(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Commits `writes` as one seq when the commit queue reaches it: `fence.admit()` at the step's entry, the writes in
|
|
112
|
+
* their order (retirements, creations, the rest), the outbox commit, `lastSeq` and the allocator's value, `COMMIT`,
|
|
113
|
+
* then `fence.adopt` before the next step starts. Resolves with the seq. A refused admission rejects `released`. A
|
|
114
|
+
* step the backend rolled back after the step's own code threw (a refusal, D4) rejects with that error unchanged and
|
|
115
|
+
* the store goes on; any other failure (`BEGIN`, `COMMIT`, `ROLLBACK`, a throwing `adopt`) is an unknown outcome
|
|
116
|
+
* that stops the store (`storage_failed`). `context` counts the step (no abort once queued).
|
|
117
|
+
*/
|
|
118
|
+
commit(writes: readonly StagedWrite[], fence: CommitFence, context: Context): Promise<number>;
|
|
119
|
+
/**
|
|
120
|
+
* Commits `commits` in one backend transaction when the commit queue reaches them, one seq each, in order: each
|
|
121
|
+
* commit's `check`, which writes nothing, then its writes as `commit` writes them, with its own outbox commit and the
|
|
122
|
+
* metadata (a commit without writes takes no seq: it stands at the one before). A `check` that throws refuses its
|
|
123
|
+
* commit: the series stops there and the transaction commits the ones before it. A check whose backend statement
|
|
124
|
+
* failed, and a throw of a commit's writes, roll the whole series back and reject with that error, the store going
|
|
125
|
+
* on (D4); any other failure is an unknown outcome that stops the store, as for `commit`. After `COMMIT`,
|
|
126
|
+
* `receive(index, seq, ids)` is called per stored commit, in order, before the next step starts (`ids`: its created
|
|
127
|
+
* documents). Resolves with what it stored.
|
|
128
|
+
*/
|
|
129
|
+
commitSeries(commits: readonly SeriesCommit[], receive: (index: number, seq: number, ids: readonly number[]) => void, context: Context): Promise<SeriesResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Runs `read` on the backend under the guard (rule 11, Durable's `GuardedStorage`): refused once the store stopped
|
|
132
|
+
* or closed; a backend error fails the store unless `context` was aborted (then `aborted`); a read settling after
|
|
133
|
+
* the store stopped rejects `unavailable/storage_failed`. `read` returns data and never throws for a request: an
|
|
134
|
+
* adapter checks a request from what it returned, after the guard (slice 6b §1.4).
|
|
135
|
+
*/
|
|
136
|
+
read<T>(read: (executor: SqliteExecutor) => Promise<T>, context: Context): Promise<T>;
|
|
137
|
+
/**
|
|
138
|
+
* `read` for several queries that must see one state (S4, a document from its record and revisions): one backend
|
|
139
|
+
* transaction, guarded as `read`.
|
|
140
|
+
*/
|
|
141
|
+
readTransaction<T>(read: (executor: SqliteExecutor) => Promise<T>, context: Context): Promise<T>;
|
|
142
|
+
/**
|
|
143
|
+
* Runs `write` on the backend outside the commit queue (the outbox's `trim`), in a backend transaction, guarded as
|
|
144
|
+
* a read without a context: any error stops the store.
|
|
145
|
+
*/
|
|
146
|
+
maintain(write: (executor: SqliteExecutor) => Promise<void>): Promise<void>;
|
|
147
|
+
close(context: Context): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Batch apply's turn (slice 6b §1.6, S5): refused (`invalid/args`) while an owner holds a claim (its memory would
|
|
150
|
+
* go stale) and once the store diverged; otherwise `apply` runs in the commit queue, in one backend transaction, and
|
|
151
|
+
* returns the position its last commit leaves (`lastSeq`, the allocator's value) and the tables it changed, which
|
|
152
|
+
* memory takes after `COMMIT`. `apply`'s own error rolls back and rejects as a refusal (a `Diverged` one marks the
|
|
153
|
+
* store diverged); any other failure stops the store.
|
|
154
|
+
*/
|
|
155
|
+
replay(apply: (executor: SqliteExecutor, catalog: ReadonlyMap<string, TableRecord>) => Promise<Replayed>, isDivergence: (error: unknown) => boolean): Promise<void>;
|
|
156
|
+
/** Whether the store has an outbox, which a replayed batch writes too. */
|
|
157
|
+
get recordsOutbox(): boolean;
|
|
158
|
+
/** Throws `unavailable/storage_failed` once the store stopped, `released` once it closed. */
|
|
159
|
+
assertUsable(): void;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/next/store/store.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAe,KAAK,WAAW,EAAgB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAiB,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAoB,KAAK,OAAO,EAAU,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,KAAK,WAAW,EAAE,IAAI,EAAmB,MAAM,WAAW,CAAC;AAGpE,mFAAmF;AACnF,MAAM,WAAW,KAAK;IACrB,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAC7D;;;OAGG;IACH,KAAK,CAAC,OAAO,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