@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,156 @@
|
|
|
1
|
+
// Chord's JSON watchables: sources (documents and derives, with their watches and dependent derives) and constants.
|
|
2
|
+
import { Watch } from "../../watch.js";
|
|
3
|
+
/**
|
|
4
|
+
* An error Chord hands to apps (a failure call, a report), its stack made text first: until then V8 keeps the frames'
|
|
5
|
+
* receivers, which would keep the host behind the throw alive for as long as an app keeps the error.
|
|
6
|
+
*/
|
|
7
|
+
export function handedOut(error) {
|
|
8
|
+
if (error instanceof Error)
|
|
9
|
+
void error.stack;
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
const ENDED = { kind: "ended" };
|
|
13
|
+
/**
|
|
14
|
+
* A changing value on a host (a singleton document, a derive, a replica): its watches and subscribers get one frame
|
|
15
|
+
* per batch that changed it, and the derives reading it are marked dirty when it changes.
|
|
16
|
+
*/
|
|
17
|
+
export class Source {
|
|
18
|
+
/** Derives reading this source (and references' members forwarding to some); each removes itself when it stops. */
|
|
19
|
+
dependents = new Set();
|
|
20
|
+
batch;
|
|
21
|
+
/** Its watches and subscribers, each made by its first: most sources (a reference's members) never have one. */
|
|
22
|
+
#watches;
|
|
23
|
+
#subscribers;
|
|
24
|
+
constructor(batch) {
|
|
25
|
+
this.batch = batch;
|
|
26
|
+
}
|
|
27
|
+
/** Whether a watch or a subscriber follows this source. */
|
|
28
|
+
get watched() {
|
|
29
|
+
return (this.#watches?.size ?? 0) > 0 || (this.#subscribers?.size ?? 0) > 0;
|
|
30
|
+
}
|
|
31
|
+
async watch(context) {
|
|
32
|
+
return this.openWatch(context);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `watch` without the Promise, for references, which must register the watch before anything else runs. On a failed
|
|
36
|
+
* source it opens at the last good value and its first call is the failure; with no value to start at it throws the
|
|
37
|
+
* failure.
|
|
38
|
+
*/
|
|
39
|
+
openWatch(context) {
|
|
40
|
+
this.batch.assertOutside("watch");
|
|
41
|
+
const start = this.start();
|
|
42
|
+
if (start.kind === "failed" && start.last === undefined)
|
|
43
|
+
throw start.error;
|
|
44
|
+
const value = start.kind === "value" ? start.value : start.last;
|
|
45
|
+
this.#watches ??= new Set();
|
|
46
|
+
const watches = this.#watches;
|
|
47
|
+
const watch = new Watch(value, () => watches.delete(watch), this.batch.reportListener);
|
|
48
|
+
watches.add(watch);
|
|
49
|
+
if (context.abortSignal !== undefined)
|
|
50
|
+
watch.observeAbort(context.abortSignal);
|
|
51
|
+
if (start.kind === "failed")
|
|
52
|
+
watch.fail(start.error, context);
|
|
53
|
+
return watch;
|
|
54
|
+
}
|
|
55
|
+
/** What a new watch starts at; a source that can fail and recover tells its failure (`WatchStart`). */
|
|
56
|
+
start() {
|
|
57
|
+
return { kind: "value", value: this.value };
|
|
58
|
+
}
|
|
59
|
+
/** Feeds `subscriber` every frame from now on, inside each batch; the caller took the current value first. */
|
|
60
|
+
subscribe(subscriber) {
|
|
61
|
+
this.#subscribers ??= new Set();
|
|
62
|
+
this.#subscribers.add(subscriber);
|
|
63
|
+
}
|
|
64
|
+
unsubscribe(subscriber) {
|
|
65
|
+
this.#subscribers?.delete(subscriber);
|
|
66
|
+
}
|
|
67
|
+
/** Records a change in the current batch: listed for a frame when watched, and every dependent marked dirty. */
|
|
68
|
+
changed() {
|
|
69
|
+
if (this.watched)
|
|
70
|
+
this.batch.changed(this);
|
|
71
|
+
for (const derive of this.dependents)
|
|
72
|
+
derive.invalidate();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Records a retirement of this source's document in the current batch: every derive reading it, directly or
|
|
76
|
+
* through other derives, carries the flag on in its frame (rule 21). Called after `changed`.
|
|
77
|
+
*/
|
|
78
|
+
retiredInBatch() {
|
|
79
|
+
// Allocated only for a retirement, which is rare.
|
|
80
|
+
const visited = new Set();
|
|
81
|
+
for (const derive of this.dependents)
|
|
82
|
+
derive.sourceRetired(visited);
|
|
83
|
+
}
|
|
84
|
+
/** Queues one frame on every watch and feeds it to every subscriber. */
|
|
85
|
+
publish(value, ops, retired, context) {
|
|
86
|
+
this.forward({ kind: "value", value, ops, retired }, context);
|
|
87
|
+
}
|
|
88
|
+
/** Queues `call` on every watch and feeds it to every subscriber, as it is (a reference's member passes one on). */
|
|
89
|
+
forward(call, context) {
|
|
90
|
+
if (this.#watches !== undefined)
|
|
91
|
+
for (const watch of this.#watches)
|
|
92
|
+
watch.advance(call, context);
|
|
93
|
+
if (this.#subscribers !== undefined)
|
|
94
|
+
for (const subscriber of this.#subscribers)
|
|
95
|
+
subscriber.advance(call, context);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Gives every watch and subscriber one failure call (design §11): the source cannot compute its value now and may
|
|
99
|
+
* recover; they stay open, and its next value is `[["r", value]]`.
|
|
100
|
+
*/
|
|
101
|
+
failWatches(error, context) {
|
|
102
|
+
this.forward({ kind: "failed", error: handedOut(error) }, context);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Ends every watch and subscriber for good once what they were given is delivered (a followed runtime ended after a
|
|
106
|
+
* last call, Durable's `endAfterDelivery`): `ended`; nothing follows.
|
|
107
|
+
*/
|
|
108
|
+
endWatchesAfterDelivery() {
|
|
109
|
+
if (this.#watches !== undefined)
|
|
110
|
+
for (const watch of [...this.#watches])
|
|
111
|
+
watch.endAfterDelivery();
|
|
112
|
+
if (this.#subscribers === undefined || this.#subscribers.size === 0)
|
|
113
|
+
return;
|
|
114
|
+
const subscribers = [...this.#subscribers];
|
|
115
|
+
this.#subscribers.clear();
|
|
116
|
+
for (const subscriber of subscribers)
|
|
117
|
+
subscriber.endAfterDelivery();
|
|
118
|
+
}
|
|
119
|
+
/** Ends every watch and subscriber for good (its owner ended): `ended`; nothing follows. */
|
|
120
|
+
endWatches() {
|
|
121
|
+
// Ending detaches, which deletes the current entry (safe while iterating) and runs no listener.
|
|
122
|
+
if (this.#watches !== undefined)
|
|
123
|
+
for (const watch of this.#watches)
|
|
124
|
+
watch.end(ENDED);
|
|
125
|
+
if (this.#subscribers === undefined || this.#subscribers.size === 0)
|
|
126
|
+
return;
|
|
127
|
+
// A copy: a subscriber may unsubscribe as it ends.
|
|
128
|
+
const subscribers = [...this.#subscribers];
|
|
129
|
+
this.#subscribers.clear();
|
|
130
|
+
for (const subscriber of subscribers)
|
|
131
|
+
subscriber.end(ENDED);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** A watchable that never changes (start data, §18); usable as a state member and as a derive source. */
|
|
135
|
+
export function constant(value) {
|
|
136
|
+
// The constant holds `value` as it was given.
|
|
137
|
+
return new Constant(value);
|
|
138
|
+
}
|
|
139
|
+
/** The watchable behind `constant(value)`: its watches never get a frame and end only by stop or cancellation. */
|
|
140
|
+
export class Constant {
|
|
141
|
+
value;
|
|
142
|
+
constructor(value) {
|
|
143
|
+
this.value = value;
|
|
144
|
+
}
|
|
145
|
+
async watch(context) {
|
|
146
|
+
return this.openWatch(context);
|
|
147
|
+
}
|
|
148
|
+
/** As `Source.openWatch`; nothing is delivered, so nothing is reported. */
|
|
149
|
+
openWatch(context) {
|
|
150
|
+
const watch = new Watch(this.value, () => { }, () => { });
|
|
151
|
+
if (context.abortSignal !== undefined)
|
|
152
|
+
watch.observeAbort(context.abortSignal);
|
|
153
|
+
return watch;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=watchable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchable.js","sourceRoot":"","sources":["../../../src/next/state/watchable.ts"],"names":[],"mappings":"AAAA,oHAAoH;AAKpH,OAAO,EAAE,KAAK,EAAiD,MAAM,gBAAgB,CAAC;AAgCtF;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAI,KAAQ;IACpC,IAAI,KAAK,YAAY,KAAK;QAAE,KAAK,KAAK,CAAC,KAAK,CAAC;IAC7C,OAAO,KAAK,CAAC;AACd,CAAC;AAaD,MAAM,KAAK,GAAa,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAE1C;;;GAGG;AACH,MAAM,OAAgB,MAAM;IAC3B,mHAAmH;IAC1G,UAAU,GAAG,IAAI,GAAG,EAAa,CAAC;IACxB,KAAK,CAAQ;IAChC,gHAAgH;IAChH,QAAQ,CAAoC;IAC5C,YAAY,CAA8B;IAE1C,YAAY,KAAY;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAID,2DAA2D;IAC3D,IAAI,OAAO;QACV,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAgB;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC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AAClH,MAAM,OAAO,QAAQ;IACX,KAAK,CAAY;IAE1B,YAAY,KAAgB;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAgB;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,2EAA2E;IAC3E,SAAS,CAAC,OAAgB;QACzB,MAAM,KAAK,GAAG,IAAI,KAAK,CACtB,IAAI,CAAC,KAAK,EACV,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,CACR,CAAC;QACF,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;YAAE,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC/E,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["// Chord's JSON watchables: sources (documents and derives, with their watches and dependent derives) and constants.\n\nimport type { Context } from \"../../context/index.ts\";\nimport type { Op } from \"../../delta/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport { Watch, type Watchable, type WatchCall, type WatchEnd } from \"../../watch.ts\";\nimport type { Batch } from \"./batch.ts\";\n\n/**\n * A synchronous subscriber of a source (a hold over a link, a reference's member): fed the source's call inside the batch\n * that made it, before the batch ends, so everything one commit changed can leave in one message. The watch's own sink\n * shape (`Watch.advance`, `Watch.end`).\n */\nexport interface Subscriber {\n\t/**\n\t * The source's call of this batch, in its batch's `context`: a value (the ops from the previous one, and whether its\n\t * document was retired in it, or for a derive one of its sources' documents), or a failure it may recover from; the\n\t * next value after a failure is `[[\"r\", value]]`.\n\t */\n\tadvance(call: WatchCall<JsonValue>, context: Context): void;\n\t/** The source ended for good with `end`; nothing follows, and the subscriber is dropped. */\n\tend(end: WatchEnd): void;\n\t/**\n\t * The source ended for good after its last call (a followed runtime ended): a subscriber delivering later (a watch)\n\t * ends `ended` once it delivered what it was given, others end now.\n\t */\n\tendAfterDelivery(): void;\n}\n\n/**\n * What a new watch of a source starts at (design §11): its value, or, while it is failed, the failure and its last good\n * value (`undefined` when it never had one: a watch cannot start then, there is nothing to start at).\n */\nexport type WatchStart =\n\t| { readonly kind: \"value\"; readonly value: JsonValue }\n\t| { readonly kind: \"failed\"; readonly error: unknown; readonly last: JsonValue | undefined };\n\n/**\n * An error Chord hands to apps (a failure call, a report), its stack made text first: until then V8 keeps the frames'\n * receivers, which would keep the host behind the throw alive for as long as an app keeps the error.\n */\nexport function handedOut<E>(error: E): E {\n\tif (error instanceof Error) void error.stack;\n\treturn error;\n}\n\n/**\n * What reads a source and is marked by its changes: a derive, or a reference's member forwarding to derives (`Source.\n * dependents`).\n */\nexport interface Dependent {\n\t/** The source changed in the current batch: flags only, no compute. */\n\tinvalidate(): void;\n\t/** A source's document was retired in the current batch (rule 21); `visited` keeps a diamond walked once. */\n\tsourceRetired(visited: Set<Dependent>): void;\n}\n\nconst ENDED: WatchEnd = { kind: \"ended\" };\n\n/**\n * A changing value on a host (a singleton document, a derive, a replica): its watches and subscribers get one frame\n * per batch that changed it, and the derives reading it are marked dirty when it changes.\n */\nexport abstract class Source implements Watchable<JsonValue> {\n\t/** Derives reading this source (and references' members forwarding to some); each removes itself when it stops. */\n\treadonly dependents = new Set<Dependent>();\n\tprotected readonly batch: Batch;\n\t/** Its watches and subscribers, each made by its first: most sources (a reference's members) never have one. */\n\t#watches: Set<Watch<JsonValue>> | undefined;\n\t#subscribers: Set<Subscriber> | undefined;\n\n\tconstructor(batch: Batch) {\n\t\tthis.batch = batch;\n\t}\n\n\tabstract get value(): JsonValue;\n\n\t/** Whether a watch or a subscriber follows this source. */\n\tget watched(): boolean {\n\t\treturn (this.#watches?.size ?? 0) > 0 || (this.#subscribers?.size ?? 0) > 0;\n\t}\n\n\tasync watch(context: Context): Promise<Watch<JsonValue>> {\n\t\treturn this.openWatch(context);\n\t}\n\n\t/**\n\t * `watch` without the Promise, for references, which must register the watch before anything else runs. On a failed\n\t * source it opens at the last good value and its first call is the failure; with no value to start at it throws the\n\t * failure.\n\t */\n\topenWatch(context: Context): Watch<JsonValue> {\n\t\tthis.batch.assertOutside(\"watch\");\n\t\tconst start = this.start();\n\t\tif (start.kind === \"failed\" && start.last === undefined) throw start.error;\n\t\tconst value = start.kind === \"value\" ? start.value : start.last!;\n\t\tthis.#watches ??= new Set();\n\t\tconst watches = this.#watches;\n\t\tconst watch: Watch<JsonValue> = new Watch(value, () => watches.delete(watch), this.batch.reportListener);\n\t\twatches.add(watch);\n\t\tif (context.abortSignal !== undefined) watch.observeAbort(context.abortSignal);\n\t\tif (start.kind === \"failed\") watch.fail(start.error, context);\n\t\treturn watch;\n\t}\n\n\t/** What a new watch starts at; a source that can fail and recover tells its failure (`WatchStart`). */\n\tstart(): WatchStart {\n\t\treturn { kind: \"value\", value: this.value };\n\t}\n\n\t/** Feeds `subscriber` every frame from now on, inside each batch; the caller took the current value first. */\n\tsubscribe(subscriber: Subscriber): void {\n\t\tthis.#subscribers ??= new Set();\n\t\tthis.#subscribers.add(subscriber);\n\t}\n\n\tunsubscribe(subscriber: Subscriber): void {\n\t\tthis.#subscribers?.delete(subscriber);\n\t}\n\n\t/** Delivers this batch's frame to its watches; called once per batch that listed it with `changed`. */\n\tabstract deliver(context: Context): void;\n\n\t/** Records a change in the current batch: listed for a frame when watched, and every dependent marked dirty. */\n\tprotected changed(): void {\n\t\tif (this.watched) this.batch.changed(this);\n\t\tfor (const derive of this.dependents) derive.invalidate();\n\t}\n\n\t/**\n\t * Records a retirement of this source's document in the current batch: every derive reading it, directly or\n\t * through other derives, carries the flag on in its frame (rule 21). Called after `changed`.\n\t */\n\tprotected retiredInBatch(): void {\n\t\t// Allocated only for a retirement, which is rare.\n\t\tconst visited = new Set<Dependent>();\n\t\tfor (const derive of this.dependents) derive.sourceRetired(visited);\n\t}\n\n\t/** Queues one frame on every watch and feeds it to every subscriber. */\n\tprotected publish(value: JsonValue, ops: readonly Op[], retired: boolean, context: Context): void {\n\t\tthis.forward({ kind: \"value\", value, ops, retired }, context);\n\t}\n\n\t/** Queues `call` on every watch and feeds it to every subscriber, as it is (a reference's member passes one on). */\n\tprotected forward(call: WatchCall<JsonValue>, context: Context): void {\n\t\tif (this.#watches !== undefined) for (const watch of this.#watches) watch.advance(call, context);\n\t\tif (this.#subscribers !== undefined)\n\t\t\tfor (const subscriber of this.#subscribers) subscriber.advance(call, context);\n\t}\n\n\t/**\n\t * Gives every watch and subscriber one failure call (design §11): the source cannot compute its value now and may\n\t * recover; they stay open, and its next value is `[[\"r\", value]]`.\n\t */\n\tprotected failWatches(error: unknown, context: Context): void {\n\t\tthis.forward({ kind: \"failed\", error: handedOut(error) }, context);\n\t}\n\n\t/**\n\t * Ends every watch and subscriber for good once what they were given is delivered (a followed runtime ended after a\n\t * last call, Durable's `endAfterDelivery`): `ended`; nothing follows.\n\t */\n\tprotected endWatchesAfterDelivery(): void {\n\t\tif (this.#watches !== undefined) for (const watch of [...this.#watches]) watch.endAfterDelivery();\n\t\tif (this.#subscribers === undefined || this.#subscribers.size === 0) return;\n\t\tconst subscribers = [...this.#subscribers];\n\t\tthis.#subscribers.clear();\n\t\tfor (const subscriber of subscribers) subscriber.endAfterDelivery();\n\t}\n\n\t/** Ends every watch and subscriber for good (its owner ended): `ended`; nothing follows. */\n\tprotected endWatches(): void {\n\t\t// Ending detaches, which deletes the current entry (safe while iterating) and runs no listener.\n\t\tif (this.#watches !== undefined) for (const watch of this.#watches) watch.end(ENDED);\n\t\tif (this.#subscribers === undefined || this.#subscribers.size === 0) return;\n\t\t// A copy: a subscriber may unsubscribe as it ends.\n\t\tconst subscribers = [...this.#subscribers];\n\t\tthis.#subscribers.clear();\n\t\tfor (const subscriber of subscribers) subscriber.end(ENDED);\n\t}\n}\n\n/** A watchable that never changes (start data, §18); usable as a state member and as a derive source. */\nexport function constant<const T extends JsonValue>(value: T): Watchable<T> {\n\t// The constant holds `value` as it was given.\n\treturn new Constant(value) as unknown as Watchable<T>;\n}\n\n/** The watchable behind `constant(value)`: its watches never get a frame and end only by stop or cancellation. */\nexport class Constant implements Watchable<JsonValue> {\n\treadonly value: JsonValue;\n\n\tconstructor(value: JsonValue) {\n\t\tthis.value = value;\n\t}\n\n\tasync watch(context: Context): Promise<Watch<JsonValue>> {\n\t\treturn this.openWatch(context);\n\t}\n\n\t/** As `Source.openWatch`; nothing is delivered, so nothing is reported. */\n\topenWatch(context: Context): Watch<JsonValue> {\n\t\tconst watch = new Watch<JsonValue>(\n\t\t\tthis.value,\n\t\t\t() => {},\n\t\t\t() => {},\n\t\t);\n\t\tif (context.abortSignal !== undefined) watch.observeAbort(context.abortSignal);\n\t\treturn watch;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
import type { NativeWatchable } from "../../watch.ts";
|
|
3
|
+
import type { Batch } from "./batch.ts";
|
|
4
|
+
import { FollowedSource } from "./native-source.ts";
|
|
5
|
+
/** An in-process value that changes when its owner sets it; `set` of the same value notifies nobody. */
|
|
6
|
+
export interface Writable<T> extends NativeWatchable<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Sets the value: a new value (by identity) is a new frame for its watches and marks the derives and registry
|
|
9
|
+
* tables reading it, in the batch running now or in one of its own. Throws `released` once its attempt ended, and
|
|
10
|
+
* `invalid/reentrant` inside a derive compute or a `compose`.
|
|
11
|
+
*/
|
|
12
|
+
set(value: T): void;
|
|
13
|
+
}
|
|
14
|
+
/** Who owns a writable: the context its own batches run in, and the check that its attempt still runs. */
|
|
15
|
+
export type WritableOwner = {
|
|
16
|
+
readonly context: Context;
|
|
17
|
+
/** Throws `released` once the attempt that made it was sealed. */
|
|
18
|
+
assertUsable(): void;
|
|
19
|
+
};
|
|
20
|
+
/** A writable: its value, set by its owner's code, delivered through the host's batch. */
|
|
21
|
+
export declare class WritableSource<T> extends FollowedSource<T> implements Writable<T> {
|
|
22
|
+
#private;
|
|
23
|
+
constructor(initial: T, owner: WritableOwner, batch: Batch);
|
|
24
|
+
get value(): T;
|
|
25
|
+
set(value: T): void;
|
|
26
|
+
/**
|
|
27
|
+
* Its attempt ended with `error`: its watches end `ended`, `set` throws `error`, its value stays readable; it keeps
|
|
28
|
+
* neither its attempt nor the host.
|
|
29
|
+
*/
|
|
30
|
+
detach(error: Error): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=writable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writable.d.ts","sourceRoot":"","sources":["../../../src/next/state/writable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wGAAwG;AACxG,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACtD;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CACpB;AAED,0GAA0G;AAC1G,MAAM,MAAM,aAAa,GAAG;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,kEAAkE;IAClE,YAAY,IAAI,IAAI,CAAC;CACrB,CAAC;AAOF,0FAA0F;AAC1F,qBAAa,cAAc,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;;IAI9E,YAAY,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAIzD;IAED,IAAI,KAAK,IAAI,CAAC,CAEb;IAED,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CASlB;IAaD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAKzB;CACD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Writables (slice 8 §2, design §17): `self.writable(initial)`, an in-process value its attempt sets, identity
|
|
2
|
+
// compared; a contribution, a derive source and an `on` source, never a state member.
|
|
3
|
+
import { FollowedSource } from "./native-source.js";
|
|
4
|
+
/** A writable: its value, set by its owner's code, delivered through the host's batch. */
|
|
5
|
+
export class WritableSource extends FollowedSource {
|
|
6
|
+
#value;
|
|
7
|
+
#ownership;
|
|
8
|
+
constructor(initial, owner, batch) {
|
|
9
|
+
super(batch);
|
|
10
|
+
this.#value = initial;
|
|
11
|
+
this.#ownership = { kind: "owned", owner };
|
|
12
|
+
}
|
|
13
|
+
get value() {
|
|
14
|
+
return this.#value;
|
|
15
|
+
}
|
|
16
|
+
set(value) {
|
|
17
|
+
const ownership = this.#ownership;
|
|
18
|
+
if (ownership.kind === "ended")
|
|
19
|
+
throw ownership.error;
|
|
20
|
+
ownership.owner.assertUsable();
|
|
21
|
+
// The cost guard: setting the value it has costs one comparison past the seal check.
|
|
22
|
+
if (value === this.#value)
|
|
23
|
+
return;
|
|
24
|
+
const batch = this.batch;
|
|
25
|
+
batch.assertNotComputing("writable.set");
|
|
26
|
+
this.#change(value, batch, ownership.owner.context);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adopts `value` in the batch running now, or in one of its own. Apart from `set`: a closure there would make every
|
|
30
|
+
* `set` allocate its context, the same value's too.
|
|
31
|
+
*/
|
|
32
|
+
#change(value, batch, context) {
|
|
33
|
+
batch.within(() => {
|
|
34
|
+
this.#value = value;
|
|
35
|
+
this.changed();
|
|
36
|
+
}, context);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Its attempt ended with `error`: its watches end `ended`, `set` throws `error`, its value stays readable; it keeps
|
|
40
|
+
* neither its attempt nor the host.
|
|
41
|
+
*/
|
|
42
|
+
detach(error) {
|
|
43
|
+
// Kept by `set`: its stack is made text now, so it holds none of the frames' objects.
|
|
44
|
+
void error.stack;
|
|
45
|
+
this.#ownership = { kind: "ended", error };
|
|
46
|
+
this.end();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=writable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writable.js","sourceRoot":"","sources":["../../../src/next/state/writable.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,sFAAsF;AAKtF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAwBpD,0FAA0F;AAC1F,MAAM,OAAO,cAAkB,SAAQ,cAAiB;IACvD,MAAM,CAAI;IACV,UAAU,CAAY;IAEtB,YAAY,OAAU,EAAE,KAAoB,EAAE,KAAY;QACzD,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5C,CAAC;IAED,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,GAAG,CAAC,KAAQ;QACX,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;YAAE,MAAM,SAAS,CAAC,KAAK,CAAC;QACtD,SAAS,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QAC/B,qFAAqF;QACrF,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM;YAAE,OAAO;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAM,CAAC;QAC1B,KAAK,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAQ,EAAE,KAAY,EAAE,OAAgB;QAC/C,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE;YACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC,EAAE,OAAO,CAAC,CAAC;IACb,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAY;QAClB,sFAAsF;QACtF,KAAK,KAAK,CAAC,KAAK,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC;CACD","sourcesContent":["// Writables (slice 8 §2, design §17): `self.writable(initial)`, an in-process value its attempt sets, identity\n// compared; a contribution, a derive source and an `on` source, never a state member.\n\nimport type { Context } from \"../../context/index.ts\";\nimport type { NativeWatchable } from \"../../watch.ts\";\nimport type { Batch } from \"./batch.ts\";\nimport { FollowedSource } from \"./native-source.ts\";\n\n/** An in-process value that changes when its owner sets it; `set` of the same value notifies nobody. */\nexport interface Writable<T> extends NativeWatchable<T> {\n\t/**\n\t * Sets the value: a new value (by identity) is a new frame for its watches and marks the derives and registry\n\t * tables reading it, in the batch running now or in one of its own. Throws `released` once its attempt ended, and\n\t * `invalid/reentrant` inside a derive compute or a `compose`.\n\t */\n\tset(value: T): void;\n}\n\n/** Who owns a writable: the context its own batches run in, and the check that its attempt still runs. */\nexport type WritableOwner = {\n\treadonly context: Context;\n\t/** Throws `released` once the attempt that made it was sealed. */\n\tassertUsable(): void;\n};\n\n/** Whom a writable belongs to: its running attempt, or nothing once that attempt ended (its error kept). */\ntype Ownership =\n\t| { readonly kind: \"owned\"; readonly owner: WritableOwner }\n\t| { readonly kind: \"ended\"; readonly error: Error };\n\n/** A writable: its value, set by its owner's code, delivered through the host's batch. */\nexport class WritableSource<T> extends FollowedSource<T> implements Writable<T> {\n\t#value: T;\n\t#ownership: Ownership;\n\n\tconstructor(initial: T, owner: WritableOwner, batch: Batch) {\n\t\tsuper(batch);\n\t\tthis.#value = initial;\n\t\tthis.#ownership = { kind: \"owned\", owner };\n\t}\n\n\tget value(): T {\n\t\treturn this.#value;\n\t}\n\n\tset(value: T): void {\n\t\tconst ownership = this.#ownership;\n\t\tif (ownership.kind === \"ended\") throw ownership.error;\n\t\townership.owner.assertUsable();\n\t\t// The cost guard: setting the value it has costs one comparison past the seal check.\n\t\tif (value === this.#value) return;\n\t\tconst batch = this.batch!;\n\t\tbatch.assertNotComputing(\"writable.set\");\n\t\tthis.#change(value, batch, ownership.owner.context);\n\t}\n\n\t/**\n\t * Adopts `value` in the batch running now, or in one of its own. Apart from `set`: a closure there would make every\n\t * `set` allocate its context, the same value's too.\n\t */\n\t#change(value: T, batch: Batch, context: Context): void {\n\t\tbatch.within(() => {\n\t\t\tthis.#value = value;\n\t\t\tthis.changed();\n\t\t}, context);\n\t}\n\n\t/**\n\t * Its attempt ended with `error`: its watches end `ended`, `set` throws `error`, its value stays readable; it keeps\n\t * neither its attempt nor the host.\n\t */\n\tdetach(error: Error): void {\n\t\t// Kept by `set`: its stack is made text now, so it holds none of the frames' objects.\n\t\tvoid error.stack;\n\t\tthis.#ownership = { kind: \"ended\", error };\n\t\tthis.end();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
import type { SqliteExecutor, SqliteValue } from "../../sqlite/index.ts";
|
|
3
|
+
import type { Claimant } from "./claims.ts";
|
|
4
|
+
import type { WhereNode } from "./expression.ts";
|
|
5
|
+
import type { EncodedRow } from "./rows.ts";
|
|
6
|
+
import { type Order, TableSql } from "./sql.ts";
|
|
7
|
+
import type { Step } from "./step.ts";
|
|
8
|
+
import type { ChordStore } from "./store.ts";
|
|
9
|
+
import type { TableDefinition } from "./table.ts";
|
|
10
|
+
import type { TableWrite } from "./table-writes.ts";
|
|
11
|
+
/** A stored row as reads decode it. */
|
|
12
|
+
export type DecodedRow = {
|
|
13
|
+
readonly [column: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The tables of one owner name in a store: each declared once (its SQL name `"<owner>:<table>"` claimed for
|
|
17
|
+
* `claimant`), then prepared together (created at their newest version or migrated, as `self.table`'s are).
|
|
18
|
+
*/
|
|
19
|
+
export declare class StoreOwnerTables {
|
|
20
|
+
#private;
|
|
21
|
+
readonly store: ChordStore;
|
|
22
|
+
readonly owner: string;
|
|
23
|
+
/** `owner` is a restricted name (lowercase `[a-z0-9@/._~-]`): it becomes the first part of SQL names. */
|
|
24
|
+
constructor(store: ChordStore, owner: string, claimant: Claimant);
|
|
25
|
+
/** Declares `definition` under the owner, claiming its SQL name (held by another: `invalid/args`). */
|
|
26
|
+
declare(definition: TableDefinition): OwnerTable;
|
|
27
|
+
/** Brings every declared table to its definition: created fresh, or migrated eagerly in their commits. */
|
|
28
|
+
prepare(context: Context): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** One declared table of an owner: its rows encoded and written in a step, its reads by key and by query. */
|
|
31
|
+
export declare class OwnerTable {
|
|
32
|
+
readonly definition: TableDefinition;
|
|
33
|
+
readonly sql: TableSql;
|
|
34
|
+
constructor(definition: TableDefinition, table: string);
|
|
35
|
+
/** `row` checked and encoded for a `put` (a trust boundary, rule 8: at staging, before the queue). */
|
|
36
|
+
encode(row: unknown): EncodedRow;
|
|
37
|
+
/**
|
|
38
|
+
* Writes `encoded` in `step` (an upsert) and returns the `put` as recorded; `stamp` names an `int` column that takes
|
|
39
|
+
* the step's seq (Durable's `entries.commit_seq`), in the row and in the record.
|
|
40
|
+
*/
|
|
41
|
+
put(step: Step, encoded: EncodedRow, stamp?: string): Promise<TableWrite>;
|
|
42
|
+
/** The row with the key `params` (in key order), decoded. */
|
|
43
|
+
get(executor: Pick<SqliteExecutor, "get">, params: readonly SqliteValue[], context: Context): Promise<DecodedRow | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* A read compiled once (the store's query vocabulary rendered to SQL): `columns` of the rows `where` matches in
|
|
46
|
+
* `order`. The values in `where` only shape it: each is a `?` the caller binds in the order the conditions take
|
|
47
|
+
* them, then the limit. Adapters keep their fixed reads so: no SQL is rendered per call.
|
|
48
|
+
*/
|
|
49
|
+
prepare(columns: readonly string[], where: WhereNode | undefined, order: Order): string;
|
|
50
|
+
/** `prepare` for the first row only: the limit is a literal `1` (a bound one costs SQLite a plan step per call). */
|
|
51
|
+
prepareFirst(columns: readonly string[], where: WhereNode | undefined, order: Order): string;
|
|
52
|
+
/**
|
|
53
|
+
* The version of `json(...)` column `column`: at 1 every stored cell is at 1 (none is older, a newer one fails the
|
|
54
|
+
* owner when its table is prepared), so a read may leave the version column out.
|
|
55
|
+
*/
|
|
56
|
+
jsonVersion(column: string): number;
|
|
57
|
+
/** A point lookup compiled once: `columns` of the row whose key the caller binds, in key order. */
|
|
58
|
+
prepareGet(columns: readonly string[]): string;
|
|
59
|
+
/**
|
|
60
|
+
* The read of `json(...)` column `column`'s stored cells (`text` written at `version`, migrated on access), made
|
|
61
|
+
* once: an adapter selecting the cell itself reads it so.
|
|
62
|
+
*/
|
|
63
|
+
reader(column: string): (text: string, version: number, context: Context) => unknown;
|
|
64
|
+
/** Up to `limit` rows matching `where` in `order`, decoded. */
|
|
65
|
+
select(executor: Pick<SqliteExecutor, "all">, where: WhereNode | undefined, order: Order, limit: number, context: Context): Promise<DecodedRow[]>;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/next/store/adapter.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iB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C,UAAU,CAAC,CAW9E;IAED,6DAA6D;IACvD,GAAG,CACR,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,EACrC,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAGjC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAEtF;IAED,oHAAoH;IACpH,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAE3F;IAED;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIlC;IAED,mGAAmG;IACnG,UAAU,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAE7C;IAED;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAOnF;IAED,+DAA+D;IACzD,MAAM,CACX,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,EACrC,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,UAAU,EAAE,CAAC,CAIvB;CACD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// The store for adapters (slice 6b §2.1, D1, D2): what an owner outside Chord's objects (Durable's `StoreStorage`) uses
|
|
2
|
+
// to keep its data in the store as declared tables and engine documents: its tables declared and prepared under its
|
|
3
|
+
// owner name (claimed, the path `self.table` takes), rows encoded at staging and written in a step with what only the
|
|
4
|
+
// step knows, and its reads. Internal for adapters; apps use `openStore` and objects.
|
|
5
|
+
import { checkName } from "../contracts/internal.js";
|
|
6
|
+
import { TableSql, tableSqlName } from "./sql.js";
|
|
7
|
+
import { prepareTables } from "./table-migration.js";
|
|
8
|
+
/**
|
|
9
|
+
* The tables of one owner name in a store: each declared once (its SQL name `"<owner>:<table>"` claimed for
|
|
10
|
+
* `claimant`), then prepared together (created at their newest version or migrated, as `self.table`'s are).
|
|
11
|
+
*/
|
|
12
|
+
export class StoreOwnerTables {
|
|
13
|
+
store;
|
|
14
|
+
owner;
|
|
15
|
+
#claimant;
|
|
16
|
+
#tables = [];
|
|
17
|
+
/** `owner` is a restricted name (lowercase `[a-z0-9@/._~-]`): it becomes the first part of SQL names. */
|
|
18
|
+
constructor(store, owner, claimant) {
|
|
19
|
+
checkName(owner, "An owner name");
|
|
20
|
+
this.store = store;
|
|
21
|
+
this.owner = owner;
|
|
22
|
+
this.#claimant = claimant;
|
|
23
|
+
}
|
|
24
|
+
/** Declares `definition` under the owner, claiming its SQL name (held by another: `invalid/args`). */
|
|
25
|
+
declare(definition) {
|
|
26
|
+
const table = new OwnerTable(definition, tableSqlName(this.owner, definition.name));
|
|
27
|
+
this.store.claims.table(table.sql.table, this.#claimant);
|
|
28
|
+
this.#tables.push(table);
|
|
29
|
+
return table;
|
|
30
|
+
}
|
|
31
|
+
/** Brings every declared table to its definition: created fresh, or migrated eagerly in their commits. */
|
|
32
|
+
prepare(context) {
|
|
33
|
+
const tables = this.#tables.map(({ definition, sql }) => ({ definition, table: sql.table }));
|
|
34
|
+
const fence = { admit: () => true, adopt: () => { } };
|
|
35
|
+
return prepareTables(tables, this.store, fence, this.owner, context);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** One declared table of an owner: its rows encoded and written in a step, its reads by key and by query. */
|
|
39
|
+
export class OwnerTable {
|
|
40
|
+
definition;
|
|
41
|
+
sql;
|
|
42
|
+
constructor(definition, table) {
|
|
43
|
+
this.definition = definition;
|
|
44
|
+
this.sql = new TableSql(table, definition.columns, definition.rows.physical, definition.key);
|
|
45
|
+
}
|
|
46
|
+
/** `row` checked and encoded for a `put` (a trust boundary, rule 8: at staging, before the queue). */
|
|
47
|
+
encode(row) {
|
|
48
|
+
return this.definition.rows.put(row, this.definition.version);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Writes `encoded` in `step` (an upsert) and returns the `put` as recorded; `stamp` names an `int` column that takes
|
|
52
|
+
* the step's seq (Durable's `entries.commit_seq`), in the row and in the record.
|
|
53
|
+
*/
|
|
54
|
+
async put(step, encoded, stamp) {
|
|
55
|
+
const { version } = this.definition;
|
|
56
|
+
const { table } = this.sql;
|
|
57
|
+
if (stamp === undefined) {
|
|
58
|
+
await step.run(this.sql.put, ...encoded.params);
|
|
59
|
+
return { kind: "put", table, row: encoded.row, version, columns: encoded.columns };
|
|
60
|
+
}
|
|
61
|
+
const params = [...encoded.params];
|
|
62
|
+
params[this.definition.rows.physical.indexOf(stamp)] = step.seq;
|
|
63
|
+
await step.run(this.sql.put, ...params);
|
|
64
|
+
return { kind: "put", table, row: { ...encoded.row, [stamp]: step.seq }, version, columns: encoded.columns };
|
|
65
|
+
}
|
|
66
|
+
/** The row with the key `params` (in key order), decoded. */
|
|
67
|
+
async get(executor, params, context) {
|
|
68
|
+
const stored = await executor.get(this.sql.get, ...params);
|
|
69
|
+
return stored === undefined ? undefined : this.definition.rows.decode(stored, context);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A read compiled once (the store's query vocabulary rendered to SQL): `columns` of the rows `where` matches in
|
|
73
|
+
* `order`. The values in `where` only shape it: each is a `?` the caller binds in the order the conditions take
|
|
74
|
+
* them, then the limit. Adapters keep their fixed reads so: no SQL is rendered per call.
|
|
75
|
+
*/
|
|
76
|
+
prepare(columns, where, order) {
|
|
77
|
+
return this.sql.select(where, order, undefined, 0, columns).sql;
|
|
78
|
+
}
|
|
79
|
+
/** `prepare` for the first row only: the limit is a literal `1` (a bound one costs SQLite a plan step per call). */
|
|
80
|
+
prepareFirst(columns, where, order) {
|
|
81
|
+
return this.sql.select(where, order, undefined, 1, columns).sql.replace(/LIMIT \?$/, "LIMIT 1");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The version of `json(...)` column `column`: at 1 every stored cell is at 1 (none is older, a newer one fails the
|
|
85
|
+
* owner when its table is prepared), so a read may leave the version column out.
|
|
86
|
+
*/
|
|
87
|
+
jsonVersion(column) {
|
|
88
|
+
const found = this.definition.column(column, "jsonVersion");
|
|
89
|
+
if (found.type !== "json")
|
|
90
|
+
throw new Error(`${this.definition.name}: column "${column}" is no json(...) column`);
|
|
91
|
+
return found.json.version;
|
|
92
|
+
}
|
|
93
|
+
/** A point lookup compiled once: `columns` of the row whose key the caller binds, in key order. */
|
|
94
|
+
prepareGet(columns) {
|
|
95
|
+
return this.sql.getColumns(columns);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The read of `json(...)` column `column`'s stored cells (`text` written at `version`, migrated on access), made
|
|
99
|
+
* once: an adapter selecting the cell itself reads it so.
|
|
100
|
+
*/
|
|
101
|
+
reader(column) {
|
|
102
|
+
const found = this.definition.column(column, "reader");
|
|
103
|
+
if (found.type !== "json")
|
|
104
|
+
throw new Error(`${this.definition.name}: column "${column}" is no json(...) column`);
|
|
105
|
+
// At version 1 a cell is the JSON it was written as: no version to compare, nothing to migrate.
|
|
106
|
+
if (found.json.version === 1)
|
|
107
|
+
return (text) => JSON.parse(text);
|
|
108
|
+
const what = `${this.sql.table}.${column}`;
|
|
109
|
+
return (text, version, context) => found.json.read(text, version, what, context);
|
|
110
|
+
}
|
|
111
|
+
/** Up to `limit` rows matching `where` in `order`, decoded. */
|
|
112
|
+
async select(executor, where, order, limit, context) {
|
|
113
|
+
const statement = this.sql.select(where, order, undefined, limit);
|
|
114
|
+
const stored = await executor.all(statement.sql, ...statement.params);
|
|
115
|
+
return stored.map((row) => this.definition.rows.decode(row, context));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/next/store/adapter.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,oHAAoH;AACpH,sHAAsH;AACtH,sFAAsF;AAItF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAIrD,OAAO,EAAc,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI9D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAMrD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,KAAK,CAAa;IAClB,KAAK,CAAS;IACd,SAAS,CAAW;IACpB,OAAO,GAAiB,EAAE,CAAC;IAEpC,yGAAyG;IACzG,YAAY,KAAiB,EAAE,KAAa,EAAE,QAAkB;QAC/D,SAAS,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,sGAAsG;IACtG,OAAO,CAAC,UAA2B;QAClC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,0GAA0G;IAC1G,OAAO,CAAC,OAAgB;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,OA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AAO,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClF,CAAC;IAED,+DAA+D;IAC/D,KAAK,CAAC,MAAM,CACX,QAAqC,EACrC,KAA4B,EAC5B,KAAY,EACZ,KAAa,EACb,OAAgB;QAEhB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAoC,SAAS,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QACzG,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IACvE,CAAC;CACD","sourcesContent":["// The store for adapters (slice 6b §2.1, D1, D2): what an owner outside Chord's objects (Durable's `StoreStorage`) uses\n// to keep its data in the store as declared tables and engine documents: its tables declared and prepared under its\n// owner name (claimed, the path `self.table` takes), rows encoded at staging and written in a step with what only the\n// step knows, and its reads. Internal for adapters; apps use `openStore` and objects.\n\nimport type { Context } from \"../../context/index.ts\";\nimport type { SqliteExecutor, SqliteValue } from \"../../sqlite/index.ts\";\nimport { checkName } from \"../contracts/internal.ts\";\nimport type { Claimant } from \"./claims.ts\";\nimport type { WhereNode } from \"./expression.ts\";\nimport type { EncodedRow } from \"./rows.ts\";\nimport { type Order, TableSql, tableSqlName } from \"./sql.ts\";\nimport type { Step } from \"./step.ts\";\nimport type { ChordStore } from \"./store.ts\";\nimport type { TableDefinition } from \"./table.ts\";\nimport { prepareTables } from \"./table-migration.ts\";\nimport type { TableWrite } from \"./table-writes.ts\";\n\n/** A stored row as reads decode it. */\nexport type DecodedRow = { readonly [column: string]: unknown };\n\n/**\n * The tables of one owner name in a store: each declared once (its SQL name `\"<owner>:<table>\"` claimed for\n * `claimant`), then prepared together (created at their newest version or migrated, as `self.table`'s are).\n */\nexport class StoreOwnerTables {\n\treadonly store: ChordStore;\n\treadonly owner: string;\n\treadonly #claimant: Claimant;\n\treadonly #tables: OwnerTable[] = [];\n\n\t/** `owner` is a restricted name (lowercase `[a-z0-9@/._~-]`): it becomes the first part of SQL names. */\n\tconstructor(store: ChordStore, owner: string, claimant: Claimant) {\n\t\tcheckName(owner, \"An owner name\");\n\t\tthis.store = store;\n\t\tthis.owner = owner;\n\t\tthis.#claimant = claimant;\n\t}\n\n\t/** Declares `definition` under the owner, claiming its SQL name (held by another: `invalid/args`). */\n\tdeclare(definition: TableDefinition): OwnerTable {\n\t\tconst table = new OwnerTable(definition, tableSqlName(this.owner, definition.name));\n\t\tthis.store.claims.table(table.sql.table, this.#claimant);\n\t\tthis.#tables.push(table);\n\t\treturn table;\n\t}\n\n\t/** Brings every declared table to its definition: created fresh, or migrated eagerly in their commits. */\n\tprepare(context: Context): Promise<void> {\n\t\tconst tables = this.#tables.map(({ definition, sql }) => ({ definition, table: sql.table }));\n\t\tconst fence = { admit: () => true, adopt: () => {} };\n\t\treturn prepareTables(tables, this.store, fence, this.owner, context);\n\t}\n}\n\n/** One declared table of an owner: its rows encoded and written in a step, its reads by key and by query. */\nexport class OwnerTable {\n\treadonly definition: TableDefinition;\n\treadonly sql: TableSql;\n\n\tconstructor(definition: TableDefinition, table: string) {\n\t\tthis.definition = definition;\n\t\tthis.sql = new TableSql(table, definition.columns, definition.rows.physical, definition.key);\n\t}\n\n\t/** `row` checked and encoded for a `put` (a trust boundary, rule 8: at staging, before the queue). */\n\tencode(row: unknown): EncodedRow {\n\t\treturn this.definition.rows.put(row, this.definition.version);\n\t}\n\n\t/**\n\t * Writes `encoded` in `step` (an upsert) and returns the `put` as recorded; `stamp` names an `int` column that takes\n\t * the step's seq (Durable's `entries.commit_seq`), in the row and in the record.\n\t */\n\tasync put(step: Step, encoded: EncodedRow, stamp?: string): Promise<TableWrite> {\n\t\tconst { version } = this.definition;\n\t\tconst { table } = this.sql;\n\t\tif (stamp === undefined) {\n\t\t\tawait step.run(this.sql.put, ...encoded.params);\n\t\t\treturn { kind: \"put\", table, row: encoded.row, version, columns: encoded.columns };\n\t\t}\n\t\tconst params = [...encoded.params];\n\t\tparams[this.definition.rows.physical.indexOf(stamp)] = step.seq;\n\t\tawait step.run(this.sql.put, ...params);\n\t\treturn { kind: \"put\", table, row: { ...encoded.row, [stamp]: step.seq }, version, columns: encoded.columns };\n\t}\n\n\t/** The row with the key `params` (in key order), decoded. */\n\tasync get(\n\t\texecutor: Pick<SqliteExecutor, \"get\">,\n\t\tparams: readonly SqliteValue[],\n\t\tcontext: Context,\n\t): Promise<DecodedRow | undefined> {\n\t\tconst stored = await executor.get<{ [column: string]: SqliteValue }>(this.sql.get, ...params);\n\t\treturn stored === undefined ? undefined : this.definition.rows.decode(stored, context);\n\t}\n\n\t/**\n\t * A read compiled once (the store's query vocabulary rendered to SQL): `columns` of the rows `where` matches in\n\t * `order`. The values in `where` only shape it: each is a `?` the caller binds in the order the conditions take\n\t * them, then the limit. Adapters keep their fixed reads so: no SQL is rendered per call.\n\t */\n\tprepare(columns: readonly string[], where: WhereNode | undefined, order: Order): string {\n\t\treturn this.sql.select(where, order, undefined, 0, columns).sql;\n\t}\n\n\t/** `prepare` for the first row only: the limit is a literal `1` (a bound one costs SQLite a plan step per call). */\n\tprepareFirst(columns: readonly string[], where: WhereNode | undefined, order: Order): string {\n\t\treturn this.sql.select(where, order, undefined, 1, columns).sql.replace(/LIMIT \\?$/, \"LIMIT 1\");\n\t}\n\n\t/**\n\t * The version of `json(...)` column `column`: at 1 every stored cell is at 1 (none is older, a newer one fails the\n\t * owner when its table is prepared), so a read may leave the version column out.\n\t */\n\tjsonVersion(column: string): number {\n\t\tconst found = this.definition.column(column, \"jsonVersion\");\n\t\tif (found.type !== \"json\") throw new Error(`${this.definition.name}: column \"${column}\" is no json(...) column`);\n\t\treturn found.json.version;\n\t}\n\n\t/** A point lookup compiled once: `columns` of the row whose key the caller binds, in key order. */\n\tprepareGet(columns: readonly string[]): string {\n\t\treturn this.sql.getColumns(columns);\n\t}\n\n\t/**\n\t * The read of `json(...)` column `column`'s stored cells (`text` written at `version`, migrated on access), made\n\t * once: an adapter selecting the cell itself reads it so.\n\t */\n\treader(column: string): (text: string, version: number, context: Context) => unknown {\n\t\tconst found = this.definition.column(column, \"reader\");\n\t\tif (found.type !== \"json\") throw new Error(`${this.definition.name}: column \"${column}\" is no json(...) column`);\n\t\t// At version 1 a cell is the JSON it was written as: no version to compare, nothing to migrate.\n\t\tif (found.json.version === 1) return (text) => JSON.parse(text) as unknown;\n\t\tconst what = `${this.sql.table}.${column}`;\n\t\treturn (text, version, context) => found.json.read(text, version, what, context);\n\t}\n\n\t/** Up to `limit` rows matching `where` in `order`, decoded. */\n\tasync select(\n\t\texecutor: Pick<SqliteExecutor, \"all\">,\n\t\twhere: WhereNode | undefined,\n\t\torder: Order,\n\t\tlimit: number,\n\t\tcontext: Context,\n\t): Promise<DecodedRow[]> {\n\t\tconst statement = this.sql.select(where, order, undefined, limit);\n\t\tconst stored = await executor.all<{ [column: string]: SqliteValue }>(statement.sql, ...statement.params);\n\t\treturn stored.map((row) => this.definition.rows.decode(row, context));\n\t}\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The first id the allocator gives: id 1 is Durable's root conversation. */
|
|
2
|
+
export declare const FIRST_ID = 2;
|
|
3
|
+
/**
|
|
4
|
+
* The allocator: `value` is the next id it gives. An id raised to `Number.MAX_SAFE_INTEGER` is accepted, the value
|
|
5
|
+
* stays there, and every later `mint` throws: no id past the safe range (it would stop counting exactly and repeat).
|
|
6
|
+
*/
|
|
7
|
+
export declare class IdAllocator {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(next: number);
|
|
10
|
+
/** The next id `mint` gives; what each commit persists. */
|
|
11
|
+
get value(): number;
|
|
12
|
+
/** Takes the next id; throws "ID space is exhausted" once saturated (Durable's message). */
|
|
13
|
+
mint(): number;
|
|
14
|
+
/** Raises the counter above `id`, an id written explicitly (Durable mints ahead), saturating. */
|
|
15
|
+
raise(id: number): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=allocator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allocator.d.ts","sourceRoot":"","sources":["../../../src/next/store/allocator.ts"],"names":[],"mappings":"AAGA,6EAA6E;AAC7E,eAAO,MAAM,QAAQ,IAAI,CAAC;AAE1B;;;GAGG;AACH,qBAAa,WAAW;;IAGvB,YAAY,IAAI,EAAE,MAAM,EAEvB;IAED,2DAA2D;IAC3D,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,4FAA4F;IAC5F,IAAI,IAAI,MAAM,CAGb;IAED,iGAAiG;IACjG,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAEtB;CACD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The store's id allocator (slice 6b D3, §1.2): one counter for every id in the store (Durable's `mintId`, Chord's
|
|
2
|
+
// document ids), synchronous, raised by explicit ids, saturating at `Number.MAX_SAFE_INTEGER`.
|
|
3
|
+
/** The first id the allocator gives: id 1 is Durable's root conversation. */
|
|
4
|
+
export const FIRST_ID = 2;
|
|
5
|
+
/**
|
|
6
|
+
* The allocator: `value` is the next id it gives. An id raised to `Number.MAX_SAFE_INTEGER` is accepted, the value
|
|
7
|
+
* stays there, and every later `mint` throws: no id past the safe range (it would stop counting exactly and repeat).
|
|
8
|
+
*/
|
|
9
|
+
export class IdAllocator {
|
|
10
|
+
#next;
|
|
11
|
+
constructor(next) {
|
|
12
|
+
this.#next = next;
|
|
13
|
+
}
|
|
14
|
+
/** The next id `mint` gives; what each commit persists. */
|
|
15
|
+
get value() {
|
|
16
|
+
return this.#next;
|
|
17
|
+
}
|
|
18
|
+
/** Takes the next id; throws "ID space is exhausted" once saturated (Durable's message). */
|
|
19
|
+
mint() {
|
|
20
|
+
if (this.#next >= Number.MAX_SAFE_INTEGER)
|
|
21
|
+
throw new Error("ID space is exhausted");
|
|
22
|
+
return this.#next++;
|
|
23
|
+
}
|
|
24
|
+
/** Raises the counter above `id`, an id written explicitly (Durable mints ahead), saturating. */
|
|
25
|
+
raise(id) {
|
|
26
|
+
if (id >= this.#next)
|
|
27
|
+
this.#next = Math.min(id + 1, Number.MAX_SAFE_INTEGER);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=allocator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allocator.js","sourceRoot":"","sources":["../../../src/next/store/allocator.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,+FAA+F;AAE/F,6EAA6E;AAC7E,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC;AAE1B;;;GAGG;AACH,MAAM,OAAO,WAAW;IACvB,KAAK,CAAS;IAEd,YAAY,IAAY;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,2DAA2D;IAC3D,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,4FAA4F;IAC5F,IAAI;QACH,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,gBAAgB;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QACpF,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,iGAAiG;IACjG,KAAK,CAAC,EAAU;QACf,IAAI,EAAE,IAAI,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC9E,CAAC;CACD","sourcesContent":["// The store's id allocator (slice 6b D3, §1.2): one counter for every id in the store (Durable's `mintId`, Chord's\n// document ids), synchronous, raised by explicit ids, saturating at `Number.MAX_SAFE_INTEGER`.\n\n/** The first id the allocator gives: id 1 is Durable's root conversation. */\nexport const FIRST_ID = 2;\n\n/**\n * The allocator: `value` is the next id it gives. An id raised to `Number.MAX_SAFE_INTEGER` is accepted, the value\n * stays there, and every later `mint` throws: no id past the safe range (it would stop counting exactly and repeat).\n */\nexport class IdAllocator {\n\t#next: number;\n\n\tconstructor(next: number) {\n\t\tthis.#next = next;\n\t}\n\n\t/** The next id `mint` gives; what each commit persists. */\n\tget value(): number {\n\t\treturn this.#next;\n\t}\n\n\t/** Takes the next id; throws \"ID space is exhausted\" once saturated (Durable's message). */\n\tmint(): number {\n\t\tif (this.#next >= Number.MAX_SAFE_INTEGER) throw new Error(\"ID space is exhausted\");\n\t\treturn this.#next++;\n\t}\n\n\t/** Raises the counter above `id`, an id written explicitly (Durable mints ahead), saturating. */\n\traise(id: number): void {\n\t\tif (id >= this.#next) this.#next = Math.min(id + 1, Number.MAX_SAFE_INTEGER);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Step } from "./step.ts";
|
|
2
|
+
import type { StoreWrite } from "./writes.ts";
|
|
3
|
+
/** A recorded write the store does not reproduce (a count, a revision): applying stops, the store diverged (S17). */
|
|
4
|
+
export declare class Diverged extends Error {
|
|
5
|
+
}
|
|
6
|
+
/** Applies `write` in `step`; a write the records refuse throws `invalid/args`, one they do not reproduce `Diverged`. */
|
|
7
|
+
export declare function applyWrite(step: Step, write: StoreWrite, what: string): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=applier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applier.d.ts","sourceRoot":"","sources":["../../../src/next/store/applier.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,qHAAqH;AACrH,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAEtC,yHAAyH;AACzH,wBAAsB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC3F"}
|