@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 @@
|
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../../src/next/state/derive.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,qEAAqE;AAGrE,OAAO,EAAE,aAAa,EAAW,MAAM,sBAAsB,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAiC,SAAS,EAAE,MAAM,EAAmB,MAAM,gBAAgB,CAAC;AAmBnG,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAE7C,MAAM,MAAM,GAAkB,EAAE,CAAC;AAEjC,sGAAsG;AACtG,MAAM,QAAQ,GAAkB,MAAM,CAAC,UAAU,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,MAAO,S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S,CAAyB,CAAoB;IACrE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAa,CAAC;IACzC,OAAO,CAAC,QAAQ,EAAE,EAAE,CACnB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACxB,uDAAuD;QACvD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;QACvE,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Derives (§12): values computed from watchables, pulled when read and marked dirty by commits; and `mapShared`, which\n// keeps unchanged elements identical so a derive's diff stays cheap.\n\nimport type { Context } from \"../../context/index.ts\";\nimport { diffRevisions, type Op } from \"../../delta/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport type { Batch } from \"./batch.ts\";\nimport { NativeSource } from \"./native-source.ts\";\nimport { type Constant, type Dependent, handedOut, Source, type WatchStart } from \"./watchable.ts\";\n\n/** A JSON watchable as Chord follows it (a state member, a JSON derive source): a source, or a constant. */\nexport type DeriveSource = Source | Constant;\n\n/** What a derive reads: a JSON source or constant, or a native source (a `writable`, a registry value, `ref.state`). */\nexport type DeriveInput = DeriveSource | NativeSource;\n\n/**\n * Where a derive stands. `dirty`: a source changed since the last compute (or there was none). A failed derive (its\n * compute threw) throws its error until a source it reads changes or is re-bound, then recomputes (self-healing, design\n * §11); a detached one (its object ended) throws its object's error for good.\n */\ntype DeriveState =\n\t| { readonly kind: \"dirty\" }\n\t| { readonly kind: \"clean\"; readonly value: JsonValue }\n\t| { readonly kind: \"failed\"; readonly error: unknown }\n\t| { readonly kind: \"detached\"; readonly error: unknown };\n\nconst DIRTY: DeriveState = { kind: \"dirty\" };\n\nconst NO_OPS: readonly Op[] = [];\n\n/** What a failed derive's watches had: no value, so its next value frame replaces the value whole. */\nconst NO_VALUE: unique symbol = Symbol(\"no value\");\n\n/**\n * A derive: `compute` over its sources' values, recomputed on read when dirty, so each compute runs at most once per\n * batch and after its sources. A commit only marks it; the batch recomputes it only when something watched depends on\n * it.\n */\nexport class Derive extends Source implements Dependent {\n\treadonly #compute: (values: readonly unknown[]) => JsonValue;\n\t/** The sources as declared, until `attach` resolves them. */\n\t#declared: readonly unknown[] | undefined;\n\t#sources: readonly DeriveInput[] = [];\n\t#state: DeriveState = { kind: \"dirty\" };\n\t/** The value this derive's watches have, kept from its marking to its frame in the batch. */\n\t#framed: JsonValue | typeof NO_VALUE | undefined;\n\t/** Whether a source's document was retired in the current batch while this derive is watched (rule 21). */\n\t#retired = false;\n\t/** Reports a failure of its compute to its owner (`attach`); once per failure episode, which a value ends. */\n\t#report: ((error: unknown) => void) | undefined;\n\t#failing = false;\n\t/** Its last good value, which a watch opened while it is failed starts at (`NO_VALUE` before the first). */\n\t#good: JsonValue | typeof NO_VALUE = NO_VALUE;\n\n\tconstructor(sources: readonly unknown[], compute: (values: readonly unknown[]) => JsonValue, batch: Batch) {\n\t\tsuper(batch);\n\t\tthis.#declared = sources;\n\t\tthis.#compute = compute;\n\t}\n\n\tget value(): JsonValue {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"clean\") return state.value;\n\t\tif (state.kind === \"dirty\") return this.#recompute();\n\t\tthrow state.error;\n\t}\n\n\t/** Its value, or while failed its failure and last good value (a detached derive throws). */\n\tstart(): WatchStart {\n\t\ttry {\n\t\t\treturn { kind: \"value\", value: this.value };\n\t\t} catch (error) {\n\t\t\tif (this.#state.kind !== \"failed\") throw error;\n\t\t\treturn { kind: \"failed\", error, last: this.#good === NO_VALUE ? undefined : this.#good };\n\t\t}\n\t}\n\n\t/**\n\t * Starts reading its sources, as `resolve` maps the declared ones (at activation); the first read computes.\n\t * `report` gets a throw of its compute, once per failure episode (a value ends it); a failing source's error is its\n\t * source's to report.\n\t */\n\tattach(resolve: (source: unknown, index: number) => DeriveInput, report: (error: unknown) => void): void {\n\t\tthis.#report = report;\n\t\tthis.#sources = this.#declared!.map(resolve);\n\t\tthis.#declared = undefined;\n\t\tfor (const source of this.#sources) {\n\t\t\tif (source instanceof Source || source instanceof NativeSource) source.dependents.add(this);\n\t\t}\n\t}\n\n\t/** Its object ended: no source keeps it, its watches end `ended`, reads throw `error` (the object's). */\n\tdetach(error: Error): void {\n\t\tfor (const source of this.#sources) {\n\t\t\tif (source instanceof Source || source instanceof NativeSource) source.dependents.delete(this);\n\t\t}\n\t\tthis.#sources = [];\n\t\tthis.#declared = undefined;\n\t\tthis.#state = { kind: \"detached\", error };\n\t\tthis.#framed = undefined;\n\t\tthis.endWatches();\n\t}\n\n\t/**\n\t * A source changed: mark this derive and its dependents dirty, flags only; a failed one too, which recomputes on its\n\t * next read and heals when its sources give a value it can compute. An already dirty derive has dirty dependents\n\t * (every read recomputes its sources first), so marking stops there.\n\t */\n\tinvalidate(): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"dirty\" || state.kind === \"detached\") return;\n\t\tif (this.watched) this.#framed = state.kind === \"clean\" ? state.value : NO_VALUE;\n\t\tthis.#state = DIRTY;\n\t\tthis.changed();\n\t}\n\n\t/**\n\t * A source's document was retired in this batch (`Source.retiredInBatch`): a watched derive's frame carries the\n\t * flag, and the derives reading this one are told too.\n\t */\n\tsourceRetired(visited: Set<Dependent>): void {\n\t\t// Once per derive per retirement: a diamond of derives is walked in its size, not once per path.\n\t\tif (visited.has(this)) return;\n\t\tvisited.add(this);\n\t\tif (this.watched) this.#retired = true;\n\t\tfor (const derive of this.dependents) derive.sourceRetired(visited);\n\t}\n\n\t/**\n\t * Delivers the frame: the diff from the watches' value, a retirement even without ops (rule 21). A compute that\n\t * throws gives one failure call when the watches had a value (one per failure episode), the watches stay open; a\n\t * retirement waits for the next value.\n\t */\n\tdeliver(context: Context): void {\n\t\tconst before = this.#framed!;\n\t\tconst retired = this.#retired;\n\t\tthis.#framed = undefined;\n\t\tlet after: JsonValue;\n\t\ttry {\n\t\t\tafter = this.value;\n\t\t} catch (error) {\n\t\t\t// Still failed since the last call: nothing new for the watches.\n\t\t\tif (before !== NO_VALUE) this.failWatches(error, context);\n\t\t\treturn;\n\t\t}\n\t\tthis.#retired = false;\n\t\tlet ops: readonly Op[] = NO_OPS;\n\t\tif (after !== before) {\n\t\t\tthis.batch.count(\"chord.derive.diffs\");\n\t\t\tops = before === NO_VALUE ? [[\"r\", after]] : diffRevisions(before, after);\n\t\t}\n\t\tif (ops.length > 0 || retired) this.publish(after, ops, retired, context);\n\t}\n\n\t#recompute(): JsonValue {\n\t\treturn this.batch.compute(() => {\n\t\t\ttry {\n\t\t\t\tthis.batch.count(\"chord.derive.computes\");\n\t\t\t\t// A failing source throws its own error here, so a derive over a failed derive fails with the same error.\n\t\t\t\tconst values = this.#sources.map((source) => source.value);\n\t\t\t\tlet value: JsonValue;\n\t\t\t\ttry {\n\t\t\t\t\tvalue = this.#compute(values);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!this.#failing) this.#report?.(handedOut(error));\n\t\t\t\t\tthis.#failing = true;\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tthis.#failing = false;\n\t\t\t\tthis.#state = { kind: \"clean\", value };\n\t\t\t\tthis.#good = value;\n\t\t\t\treturn value;\n\t\t\t} catch (error) {\n\t\t\t\tthis.#state = { kind: \"failed\", error };\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\t}\n}\n\n/**\n * Maps an array calling `f` only for object elements not seen before (by identity), returning the previous result for\n * the others; primitive elements are mapped every time. The cache is weak: dropped elements take their results along.\n */\nexport function mapShared<E, R extends JsonValue>(f: (element: E) => R): (elements: readonly E[]) => R[] {\n\tconst results = new WeakMap<object, R>();\n\treturn (elements) =>\n\t\telements.map((element) => {\n\t\t\t// The decided rule: identity caching for objects only.\n\t\t\tif (typeof element !== \"object\" || element === null) return f(element);\n\t\t\tlet result = results.get(element);\n\t\t\tif (result === undefined) {\n\t\t\t\tresult = f(element);\n\t\t\t\tresults.set(element, result);\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Watchable } from "../../watch.ts";
|
|
2
|
+
export { mapShared } from "./derive.ts";
|
|
3
|
+
export type { NativeObservation, NativeObserver } from "./native-source.ts";
|
|
4
|
+
export { constant } from "./watchable.ts";
|
|
5
|
+
export type { Writable } from "./writable.ts";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next/state/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next/state/index.ts"],"names":[],"mappings":"AAAA,oHAAoH;AAGpH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["// State for apps: watchables, constants, writables, observers of native sources, and the derive helper `mapShared`.\n\nexport type { Watchable } from \"../../watch.ts\";\nexport { mapShared } from \"./derive.ts\";\nexport type { NativeObservation, NativeObserver } from \"./native-source.ts\";\nexport { constant } from \"./watchable.ts\";\nexport type { Writable } from \"./writable.ts\";\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Batch, type BatchError, type Delivered } from "./batch.ts";
|
|
2
|
+
export { Derive, type DeriveInput, type DeriveSource } from "./derive.ts";
|
|
3
|
+
export { FollowedSource, type NativeObservation, type NativeObserver, NativeSource, type NativeStart, } from "./native-source.ts";
|
|
4
|
+
export { Constant, type Dependent, handedOut, Source, type Subscriber, type WatchStart } from "./watchable.ts";
|
|
5
|
+
export { type WritableOwner, WritableSource } from "./writable.ts";
|
|
6
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/next/state/internal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACN,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,YAAY,EACZ,KAAK,WAAW,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,KAAK,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// State for Chord's layers: the batch, sources (JSON and native), derives, constants and writables behind the
|
|
2
|
+
// app's watchables.
|
|
3
|
+
export { Batch } from "./batch.js";
|
|
4
|
+
export { Derive } from "./derive.js";
|
|
5
|
+
export { FollowedSource, NativeSource, } from "./native-source.js";
|
|
6
|
+
export { Constant, handedOut, Source } from "./watchable.js";
|
|
7
|
+
export { WritableSource } from "./writable.js";
|
|
8
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/next/state/internal.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,oBAAoB;AAEpB,OAAO,EAAE,KAAK,EAAmC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,MAAM,EAAuC,MAAM,aAAa,CAAC;AAC1E,OAAO,EACN,cAAc,EAGd,YAAY,GAEZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAkB,SAAS,EAAE,MAAM,EAAoC,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAsB,cAAc,EAAE,MAAM,eAAe,CAAC","sourcesContent":["// State for Chord's layers: the batch, sources (JSON and native), derives, constants and writables behind the\n// app's watchables.\n\nexport { Batch, type BatchError, type Delivered } from \"./batch.ts\";\nexport { Derive, type DeriveInput, type DeriveSource } from \"./derive.ts\";\nexport {\n\tFollowedSource,\n\ttype NativeObservation,\n\ttype NativeObserver,\n\tNativeSource,\n\ttype NativeStart,\n} from \"./native-source.ts\";\nexport { Constant, type Dependent, handedOut, Source, type Subscriber, type WatchStart } from \"./watchable.ts\";\nexport { type WritableOwner, WritableSource } from \"./writable.ts\";\n"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
import { NativeWatch, type NativeWatchable, type NativeWatchCall, type NativeWatchHandle, type WatchEnd } from "../../watch.ts";
|
|
3
|
+
import type { Batch } from "./batch.ts";
|
|
4
|
+
import { type Dependent } from "./watchable.ts";
|
|
5
|
+
/**
|
|
6
|
+
* A synchronous observer of a native source (Durable's observer shape): `advance` is called inside the batch that
|
|
7
|
+
* changed the source, so it only records; `end` once, when the source ended (`ended`) or the observer's context was
|
|
8
|
+
* aborted (`aborted`).
|
|
9
|
+
*/
|
|
10
|
+
export interface NativeObserver<T> {
|
|
11
|
+
/** The source's call of this batch: its new value, or a failure it may recover from. */
|
|
12
|
+
advance(call: NativeWatchCall<T>, context: Context): void;
|
|
13
|
+
/** The observer is detached for good with `end`. */
|
|
14
|
+
end(end: WatchEnd): void;
|
|
15
|
+
}
|
|
16
|
+
/** What `observe` gives: the value the observer starts at, and how to detach it (Durable's `Observation`). */
|
|
17
|
+
export type NativeObservation<T> = {
|
|
18
|
+
readonly value: T;
|
|
19
|
+
detach(): void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* What a new watch of a native source starts at: its value, or while it is failed, the failure and its last good value
|
|
23
|
+
* (`last` undefined when it never had one: a watch cannot start then).
|
|
24
|
+
*/
|
|
25
|
+
export type NativeStart<T> = {
|
|
26
|
+
readonly kind: "value";
|
|
27
|
+
readonly value: T;
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: "failed";
|
|
30
|
+
readonly error: unknown;
|
|
31
|
+
readonly last: {
|
|
32
|
+
readonly value: T;
|
|
33
|
+
} | undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A native source as derives and registry tables read it: its value (`start()` while it may fail), the dependents a
|
|
37
|
+
* change marks (`changed()`, inside a batch), and the host's batch until it ended. How its watches get their calls is
|
|
38
|
+
* the subclass's (`FollowedSource` for writables and registry values; `ref.state` gives each state to its watches).
|
|
39
|
+
*/
|
|
40
|
+
export declare abstract class NativeSource<T = unknown> implements NativeWatchable<T> {
|
|
41
|
+
#private;
|
|
42
|
+
/** Derives and registry tables reading this source; each removes itself when it stops. */
|
|
43
|
+
readonly dependents: Set<Dependent>;
|
|
44
|
+
/** `batch` undefined: made ended (a released reference's state). */
|
|
45
|
+
constructor(batch: Batch | undefined);
|
|
46
|
+
abstract get value(): T;
|
|
47
|
+
abstract watch(context: Context): Promise<NativeWatchHandle<T>>;
|
|
48
|
+
/** What a new watch starts at; a source that can fail and recover tells its failure. */
|
|
49
|
+
start(): NativeStart<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Its value now as a contribution reads it: throws its failure while it is failed, where `.value` keeps the last good
|
|
52
|
+
* value for readers (a registry whose `compose` threw).
|
|
53
|
+
*/
|
|
54
|
+
current(): T;
|
|
55
|
+
/** The host's batch, `undefined` once the source ended. */
|
|
56
|
+
protected get batch(): Batch | undefined;
|
|
57
|
+
/** Records a change inside the current batch: every dependent marked. */
|
|
58
|
+
protected changed(): void;
|
|
59
|
+
/** Ends the source for good: its dependents dropped, the batch let go. */
|
|
60
|
+
protected end(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A native source its followers get through the batch (a writable, a registry value): a change lists it for one frame
|
|
64
|
+
* when someone follows it; the frame is its value then, delivered only when it is another value (identity) than the
|
|
65
|
+
* one its followers have, or after a failure, whose call comes once per episode.
|
|
66
|
+
*/
|
|
67
|
+
export declare abstract class FollowedSource<T = unknown> extends NativeSource<T> {
|
|
68
|
+
#private;
|
|
69
|
+
/** Whether a watch or an observer follows it (a registry value also while readers wait for its first value). */
|
|
70
|
+
get watched(): boolean;
|
|
71
|
+
watch(context: Context): Promise<NativeWatch<T>>;
|
|
72
|
+
/**
|
|
73
|
+
* `watch` without the Promise. On a failed source it opens at the last good value and its first call is the
|
|
74
|
+
* failure; with no value to start at it throws the failure. An ended source gives a watch that has ended.
|
|
75
|
+
*/
|
|
76
|
+
openWatch(context: Context): NativeWatch<T>;
|
|
77
|
+
/**
|
|
78
|
+
* Attaches a synchronous observer at the current value (Durable's `observeXXX`); it counts as following, so a lazy
|
|
79
|
+
* value is computed in the batch that changed it. Throws the failure when there is no value to start at; aborting
|
|
80
|
+
* `context` detaches it (`aborted`); the source's end detaches it too (`ended`), its abort listener removed.
|
|
81
|
+
*/
|
|
82
|
+
observe(observer: NativeObserver<T>, context: Context): NativeObservation<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Feeds `observer` every call from now on, inside each batch, also while the source has no value (Chord's own
|
|
85
|
+
* followers: `retryOn`). Nothing is delivered for the current value.
|
|
86
|
+
*/
|
|
87
|
+
subscribe(observer: NativeObserver<T>): void;
|
|
88
|
+
unsubscribe(observer: NativeObserver<T>): void;
|
|
89
|
+
/** Delivers this batch's frame: the new value when the followers have another, or a failure once per episode. */
|
|
90
|
+
deliver(context: Context): void;
|
|
91
|
+
/**
|
|
92
|
+
* Records a change inside the current batch: every dependent marked, and the source listed for a frame when someone
|
|
93
|
+
* follows it (or `watched` says so).
|
|
94
|
+
*/
|
|
95
|
+
protected changed(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Lists the source for a frame in the current batch when someone follows it (or `watched` says so), its dependents
|
|
98
|
+
* left as they are (marked already).
|
|
99
|
+
*/
|
|
100
|
+
protected list(): void;
|
|
101
|
+
/** Nothing follows it any more (no watch, no observer): a subclass drops what it kept for followers. */
|
|
102
|
+
protected unfollowed(): void;
|
|
103
|
+
/** Ends the source for good: watches and observers end `ended` (their abort listeners removed). */
|
|
104
|
+
protected end(): void;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=native-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-source.d.ts","sourceRoot":"","sources":["../../../src/next/state/native-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACN,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,gBAAgB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAChC,wFAAwF;IACxF,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1D,oDAAoD;IACpD,GAAG,CAAC,GAAG,EAAE,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C,GAAG,OAAO,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;;IASxE,gHAAgH;IAChH,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAErD;IAED;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAiB1C;IAED;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAwB3E;IAED;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAI3C;IAED,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAM7C;IAED,iHAAiH;IACjH,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAO9B;IAED;;;OAGG;IACH,UAAmB,OAAO,IAAI,IAAI,CAGjC;IAED;;;OAGG;IACH,SAAS,CAAC,IAAI,IAAI,IAAI,CAOrB;IAED,wGAAwG;IACxG,SAAS,CAAC,UAAU,IAAI,IAAI,CAAG;IAE/B,mGAAmG;IACnG,UAAmB,GAAG,IAAI,IAAI,CAW7B;CA4CD"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Native sources (W4, slice 8 §2): in-process values that change, compared by identity (a `writable`, a registry's
|
|
2
|
+
// composed value, `ref.state`). Derives and registry tables depend on them and the batch marks them; the followed
|
|
3
|
+
// ones (writables, registry values) give their watches and observers one call per batch that changed them.
|
|
4
|
+
import { NativeWatch, } from "../../watch.js";
|
|
5
|
+
import { handedOut } from "./watchable.js";
|
|
6
|
+
/**
|
|
7
|
+
* A native source as derives and registry tables read it: its value (`start()` while it may fail), the dependents a
|
|
8
|
+
* change marks (`changed()`, inside a batch), and the host's batch until it ended. How its watches get their calls is
|
|
9
|
+
* the subclass's (`FollowedSource` for writables and registry values; `ref.state` gives each state to its watches).
|
|
10
|
+
*/
|
|
11
|
+
export class NativeSource {
|
|
12
|
+
/** Derives and registry tables reading this source; each removes itself when it stops. */
|
|
13
|
+
dependents = new Set();
|
|
14
|
+
/** The host's batch; dropped when the source ended, so an ended source keeps no host. */
|
|
15
|
+
#batch;
|
|
16
|
+
/** `batch` undefined: made ended (a released reference's state). */
|
|
17
|
+
constructor(batch) {
|
|
18
|
+
this.#batch = batch;
|
|
19
|
+
}
|
|
20
|
+
/** What a new watch starts at; a source that can fail and recover tells its failure. */
|
|
21
|
+
start() {
|
|
22
|
+
return { kind: "value", value: this.value };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Its value now as a contribution reads it: throws its failure while it is failed, where `.value` keeps the last good
|
|
26
|
+
* value for readers (a registry whose `compose` threw).
|
|
27
|
+
*/
|
|
28
|
+
current() {
|
|
29
|
+
return this.value;
|
|
30
|
+
}
|
|
31
|
+
/** The host's batch, `undefined` once the source ended. */
|
|
32
|
+
get batch() {
|
|
33
|
+
return this.#batch;
|
|
34
|
+
}
|
|
35
|
+
/** Records a change inside the current batch: every dependent marked. */
|
|
36
|
+
changed() {
|
|
37
|
+
for (const dependent of this.dependents)
|
|
38
|
+
dependent.invalidate();
|
|
39
|
+
}
|
|
40
|
+
/** Ends the source for good: its dependents dropped, the batch let go. */
|
|
41
|
+
end() {
|
|
42
|
+
this.#batch = undefined;
|
|
43
|
+
this.dependents.clear();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const ENDED = { kind: "ended" };
|
|
47
|
+
const ABORTED = { kind: "aborted" };
|
|
48
|
+
const FAILED = { kind: "failed" };
|
|
49
|
+
const NONE = { kind: "none" };
|
|
50
|
+
const NOTHING = () => { };
|
|
51
|
+
/**
|
|
52
|
+
* A native source its followers get through the batch (a writable, a registry value): a change lists it for one frame
|
|
53
|
+
* when someone follows it; the frame is its value then, delivered only when it is another value (identity) than the
|
|
54
|
+
* one its followers have, or after a failure, whose call comes once per episode.
|
|
55
|
+
*/
|
|
56
|
+
export class FollowedSource extends NativeSource {
|
|
57
|
+
#watches = new Set();
|
|
58
|
+
/** Synchronous observers and Chord's own subscribers (`retryOn`), fed inside the batch, each with its cleanup. */
|
|
59
|
+
#observers = new Map();
|
|
60
|
+
/** What the followers have; `undefined` while nobody follows (so no old value is kept). */
|
|
61
|
+
#shown;
|
|
62
|
+
/** Listed for a frame in the current batch. */
|
|
63
|
+
#listed = false;
|
|
64
|
+
/** Whether a watch or an observer follows it (a registry value also while readers wait for its first value). */
|
|
65
|
+
get watched() {
|
|
66
|
+
return this.#watches.size > 0 || this.#observers.size > 0;
|
|
67
|
+
}
|
|
68
|
+
async watch(context) {
|
|
69
|
+
return this.openWatch(context);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `watch` without the Promise. On a failed source it opens at the last good value and its first call is the
|
|
73
|
+
* failure; with no value to start at it throws the failure. An ended source gives a watch that has ended.
|
|
74
|
+
*/
|
|
75
|
+
openWatch(context) {
|
|
76
|
+
const batch = this.batch;
|
|
77
|
+
if (batch === undefined) {
|
|
78
|
+
const ended = new NativeWatch(this.value, NOTHING, NOTHING);
|
|
79
|
+
ended.end(ENDED);
|
|
80
|
+
return ended;
|
|
81
|
+
}
|
|
82
|
+
batch.assertOutside("watch");
|
|
83
|
+
const start = this.start();
|
|
84
|
+
if (start.kind === "failed" && start.last === undefined)
|
|
85
|
+
throw start.error;
|
|
86
|
+
const value = start.kind === "value" ? start.value : start.last.value;
|
|
87
|
+
this.#follow(start);
|
|
88
|
+
const watch = new NativeWatch(value, () => this.#unfollow(watch), batch.reportListener);
|
|
89
|
+
this.#watches.add(watch);
|
|
90
|
+
if (context.abortSignal !== undefined)
|
|
91
|
+
watch.observeAbort(context.abortSignal);
|
|
92
|
+
if (start.kind === "failed")
|
|
93
|
+
watch.fail(handedOut(start.error), context);
|
|
94
|
+
return watch;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Attaches a synchronous observer at the current value (Durable's `observeXXX`); it counts as following, so a lazy
|
|
98
|
+
* value is computed in the batch that changed it. Throws the failure when there is no value to start at; aborting
|
|
99
|
+
* `context` detaches it (`aborted`); the source's end detaches it too (`ended`), its abort listener removed.
|
|
100
|
+
*/
|
|
101
|
+
observe(observer, context) {
|
|
102
|
+
this.batch?.assertOutside("observe");
|
|
103
|
+
const start = this.start();
|
|
104
|
+
if (start.kind === "failed" && start.last === undefined)
|
|
105
|
+
throw start.error;
|
|
106
|
+
const value = start.kind === "value" ? start.value : start.last.value;
|
|
107
|
+
if (this.batch === undefined) {
|
|
108
|
+
observer.end(ENDED);
|
|
109
|
+
return { value, detach: NOTHING };
|
|
110
|
+
}
|
|
111
|
+
const signal = context.abortSignal;
|
|
112
|
+
if (signal?.aborted) {
|
|
113
|
+
observer.end(ABORTED);
|
|
114
|
+
return { value, detach: NOTHING };
|
|
115
|
+
}
|
|
116
|
+
const aborted = () => {
|
|
117
|
+
if (!this.#observers.has(observer))
|
|
118
|
+
return;
|
|
119
|
+
this.unsubscribe(observer);
|
|
120
|
+
observer.end(ABORTED);
|
|
121
|
+
};
|
|
122
|
+
const cleanup = signal === undefined ? NOTHING : () => signal.removeEventListener("abort", aborted);
|
|
123
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
124
|
+
this.#follow(start);
|
|
125
|
+
this.#observers.set(observer, cleanup);
|
|
126
|
+
return { value, detach: () => this.unsubscribe(observer) };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Feeds `observer` every call from now on, inside each batch, also while the source has no value (Chord's own
|
|
130
|
+
* followers: `retryOn`). Nothing is delivered for the current value.
|
|
131
|
+
*/
|
|
132
|
+
subscribe(observer) {
|
|
133
|
+
if (this.batch === undefined)
|
|
134
|
+
return;
|
|
135
|
+
this.#follow(this.#startOrNone());
|
|
136
|
+
this.#observers.set(observer, NOTHING);
|
|
137
|
+
}
|
|
138
|
+
unsubscribe(observer) {
|
|
139
|
+
const cleanup = this.#observers.get(observer);
|
|
140
|
+
if (cleanup === undefined)
|
|
141
|
+
return;
|
|
142
|
+
this.#observers.delete(observer);
|
|
143
|
+
cleanup();
|
|
144
|
+
this.#settleFollowers();
|
|
145
|
+
}
|
|
146
|
+
/** Delivers this batch's frame: the new value when the followers have another, or a failure once per episode. */
|
|
147
|
+
deliver(context) {
|
|
148
|
+
this.#listed = false;
|
|
149
|
+
const shown = this.#shown;
|
|
150
|
+
if (shown === undefined)
|
|
151
|
+
return;
|
|
152
|
+
this.#deliver(shown, context);
|
|
153
|
+
// Readers waiting for a first value pulled it through this delivery: nothing is kept for them.
|
|
154
|
+
this.#settleFollowers();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Records a change inside the current batch: every dependent marked, and the source listed for a frame when someone
|
|
158
|
+
* follows it (or `watched` says so).
|
|
159
|
+
*/
|
|
160
|
+
changed() {
|
|
161
|
+
super.changed();
|
|
162
|
+
this.list();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Lists the source for a frame in the current batch when someone follows it (or `watched` says so), its dependents
|
|
166
|
+
* left as they are (marked already).
|
|
167
|
+
*/
|
|
168
|
+
list() {
|
|
169
|
+
if (this.#listed || !this.watched || this.batch === undefined)
|
|
170
|
+
return;
|
|
171
|
+
this.#listed = true;
|
|
172
|
+
// Only readers waiting for a first value follow it without a follower's record: they have none. Not computed
|
|
173
|
+
// here: marking runs inside adoptions, the value is pulled in the delivery.
|
|
174
|
+
this.#shown ??= NONE;
|
|
175
|
+
this.batch.changed(this);
|
|
176
|
+
}
|
|
177
|
+
/** Nothing follows it any more (no watch, no observer): a subclass drops what it kept for followers. */
|
|
178
|
+
unfollowed() { }
|
|
179
|
+
/** Ends the source for good: watches and observers end `ended` (their abort listeners removed). */
|
|
180
|
+
end() {
|
|
181
|
+
super.end();
|
|
182
|
+
this.#shown = undefined;
|
|
183
|
+
// Ending detaches, which deletes the current entry (safe while iterating) and runs no listener.
|
|
184
|
+
for (const watch of this.#watches)
|
|
185
|
+
watch.end(ENDED);
|
|
186
|
+
const observers = [...this.#observers];
|
|
187
|
+
this.#observers.clear();
|
|
188
|
+
for (const [observer, cleanup] of observers) {
|
|
189
|
+
cleanup();
|
|
190
|
+
observer.end(ENDED);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
#deliver(shown, context) {
|
|
194
|
+
const start = this.#startOrNone();
|
|
195
|
+
if (start.kind === "failed") {
|
|
196
|
+
// A failure reaches followers that had a value: those without one wait for the first.
|
|
197
|
+
if (shown.kind !== "value")
|
|
198
|
+
return;
|
|
199
|
+
this.#shown = FAILED;
|
|
200
|
+
const error = handedOut(start.error);
|
|
201
|
+
for (const watch of this.#watches)
|
|
202
|
+
watch.fail(error, context);
|
|
203
|
+
for (const observer of [...this.#observers.keys()])
|
|
204
|
+
observer.advance({ kind: "failed", error }, context);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (start.kind !== "value" || (shown.kind === "value" && shown.value === start.value))
|
|
208
|
+
return;
|
|
209
|
+
const { value } = start;
|
|
210
|
+
this.#shown = start;
|
|
211
|
+
for (const watch of this.#watches)
|
|
212
|
+
watch.advance(value, context);
|
|
213
|
+
// A copy: an observer may detach itself in its call.
|
|
214
|
+
for (const observer of [...this.#observers.keys()])
|
|
215
|
+
observer.advance({ kind: "value", value }, context);
|
|
216
|
+
}
|
|
217
|
+
/** Its start, `none` while it has no value. */
|
|
218
|
+
#startOrNone() {
|
|
219
|
+
const start = this.start();
|
|
220
|
+
return start.kind === "failed" && start.last === undefined ? NONE : start;
|
|
221
|
+
}
|
|
222
|
+
/** A follower comes: the first one records what followers have (a later one opened at the same current value). */
|
|
223
|
+
#follow(start) {
|
|
224
|
+
if (this.#shown !== undefined)
|
|
225
|
+
return;
|
|
226
|
+
this.#shown = start.kind === "failed" ? FAILED : start;
|
|
227
|
+
}
|
|
228
|
+
#unfollow(watch) {
|
|
229
|
+
this.#watches.delete(watch);
|
|
230
|
+
this.#settleFollowers();
|
|
231
|
+
}
|
|
232
|
+
/** No follower left: nothing is shown any more, so no old value is kept. */
|
|
233
|
+
#settleFollowers() {
|
|
234
|
+
if (this.#watches.size > 0 || this.#observers.size > 0)
|
|
235
|
+
return;
|
|
236
|
+
this.#shown = undefined;
|
|
237
|
+
this.unfollowed();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=native-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-source.js","sourceRoot":"","sources":["../../../src/next/state/native-source.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,kHAAkH;AAClH,2GAA2G;AAG3G,OAAO,EACN,WAAW,GAKX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAyB3D;;;;GAIG;AACH,MAAM,OAAgB,YAAY;IACjC,0FAA0F;IACjF,UAAU,GAAG,IAAI,GAAG,EAAa,CAAC;IAC3C,yFAAyF;IACzF,MAAM,CAAoB;IAE1B,oEAAoE;IACpE,YAAY,KAAwB;QACnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACrB,CAAC;IAMD,wFAAwF;IACxF,KAAK;QACJ,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,OAAO;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,2DAA2D;IAC3D,IAAc,KAAK;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,yEAAyE;IAC/D,OAAO;QAChB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU;YAAE,SAAS,CAAC,UAAU,EAAE,CAAC;IACjE,CAAC;IAED,0EAA0E;IAChE,GAAG;QACZ,IAAI,CAAC,MAAM,GAAG,S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SAAS,CAAC;QACxB,IAAI,CAAC,UAAU,EAAE,CAAC;IACnB,CAAC;CACD","sourcesContent":["// Native sources (W4, slice 8 §2): in-process values that change, compared by identity (a `writable`, a registry's\n// composed value, `ref.state`). Derives and registry tables depend on them and the batch marks them; the followed\n// ones (writables, registry values) give their watches and observers one call per batch that changed them.\n\nimport type { Context } from \"../../context/index.ts\";\nimport {\n\tNativeWatch,\n\ttype NativeWatchable,\n\ttype NativeWatchCall,\n\ttype NativeWatchHandle,\n\ttype WatchEnd,\n} from \"../../watch.ts\";\nimport type { Batch } from \"./batch.ts\";\nimport { type Dependent, handedOut } from \"./watchable.ts\";\n\n/**\n * A synchronous observer of a native source (Durable's observer shape): `advance` is called inside the batch that\n * changed the source, so it only records; `end` once, when the source ended (`ended`) or the observer's context was\n * aborted (`aborted`).\n */\nexport interface NativeObserver<T> {\n\t/** The source's call of this batch: its new value, or a failure it may recover from. */\n\tadvance(call: NativeWatchCall<T>, context: Context): void;\n\t/** The observer is detached for good with `end`. */\n\tend(end: WatchEnd): void;\n}\n\n/** What `observe` gives: the value the observer starts at, and how to detach it (Durable's `Observation`). */\nexport type NativeObservation<T> = { readonly value: T; detach(): void };\n\n/**\n * What a new watch of a native source starts at: its value, or while it is failed, the failure and its last good value\n * (`last` undefined when it never had one: a watch cannot start then).\n */\nexport type NativeStart<T> =\n\t| { readonly kind: \"value\"; readonly value: T }\n\t| { readonly kind: \"failed\"; readonly error: unknown; readonly last: { readonly value: T } | undefined };\n\n/**\n * A native source as derives and registry tables read it: its value (`start()` while it may fail), the dependents a\n * change marks (`changed()`, inside a batch), and the host's batch until it ended. How its watches get their calls is\n * the subclass's (`FollowedSource` for writables and registry values; `ref.state` gives each state to its watches).\n */\nexport abstract class NativeSource<T = unknown> implements NativeWatchable<T> {\n\t/** Derives and registry tables reading this source; each removes itself when it stops. */\n\treadonly dependents = new Set<Dependent>();\n\t/** The host's batch; dropped when the source ended, so an ended source keeps no host. */\n\t#batch: Batch | undefined;\n\n\t/** `batch` undefined: made ended (a released reference's state). */\n\tconstructor(batch: Batch | undefined) {\n\t\tthis.#batch = batch;\n\t}\n\n\tabstract get value(): T;\n\n\tabstract watch(context: Context): Promise<NativeWatchHandle<T>>;\n\n\t/** What a new watch starts at; a source that can fail and recover tells its failure. */\n\tstart(): NativeStart<T> {\n\t\treturn { kind: \"value\", value: this.value };\n\t}\n\n\t/**\n\t * Its value now as a contribution reads it: throws its failure while it is failed, where `.value` keeps the last good\n\t * value for readers (a registry whose `compose` threw).\n\t */\n\tcurrent(): T {\n\t\treturn this.value;\n\t}\n\n\t/** The host's batch, `undefined` once the source ended. */\n\tprotected get batch(): Batch | undefined {\n\t\treturn this.#batch;\n\t}\n\n\t/** Records a change inside the current batch: every dependent marked. */\n\tprotected changed(): void {\n\t\tfor (const dependent of this.dependents) dependent.invalidate();\n\t}\n\n\t/** Ends the source for good: its dependents dropped, the batch let go. */\n\tprotected end(): void {\n\t\tthis.#batch = undefined;\n\t\tthis.dependents.clear();\n\t}\n}\n\n/**\n * What the watches and observers were last given: a value, a failure (one call per failure episode), or nothing yet\n * (a source with no value, followed for its first one).\n */\ntype Shown<T> = { readonly kind: \"value\"; readonly value: T } | { readonly kind: \"failed\" } | { readonly kind: \"none\" };\n\nconst ENDED: WatchEnd = { kind: \"ended\" };\n\nconst ABORTED: WatchEnd = { kind: \"aborted\" };\n\nconst FAILED: Shown<never> = { kind: \"failed\" };\n\nconst NONE = { kind: \"none\" } as const;\n\nconst NOTHING = (): void => {};\n\n/**\n * A native source its followers get through the batch (a writable, a registry value): a change lists it for one frame\n * when someone follows it; the frame is its value then, delivered only when it is another value (identity) than the\n * one its followers have, or after a failure, whose call comes once per episode.\n */\nexport abstract class FollowedSource<T = unknown> extends NativeSource<T> {\n\treadonly #watches = new Set<NativeWatch<T>>();\n\t/** Synchronous observers and Chord's own subscribers (`retryOn`), fed inside the batch, each with its cleanup. */\n\treadonly #observers = new Map<NativeObserver<T>, () => void>();\n\t/** What the followers have; `undefined` while nobody follows (so no old value is kept). */\n\t#shown: Shown<T> | undefined;\n\t/** Listed for a frame in the current batch. */\n\t#listed = false;\n\n\t/** Whether a watch or an observer follows it (a registry value also while readers wait for its first value). */\n\tget watched(): boolean {\n\t\treturn this.#watches.size > 0 || this.#observers.size > 0;\n\t}\n\n\tasync watch(context: Context): Promise<NativeWatch<T>> {\n\t\treturn this.openWatch(context);\n\t}\n\n\t/**\n\t * `watch` without the Promise. On a failed source it opens at the last good value and its first call is the\n\t * failure; with no value to start at it throws the failure. An ended source gives a watch that has ended.\n\t */\n\topenWatch(context: Context): NativeWatch<T> {\n\t\tconst batch = this.batch;\n\t\tif (batch === undefined) {\n\t\t\tconst ended = new NativeWatch<T>(this.value, NOTHING, NOTHING);\n\t\t\tended.end(ENDED);\n\t\t\treturn ended;\n\t\t}\n\t\tbatch.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!.value;\n\t\tthis.#follow(start);\n\t\tconst watch: NativeWatch<T> = new NativeWatch(value, () => this.#unfollow(watch), batch.reportListener);\n\t\tthis.#watches.add(watch);\n\t\tif (context.abortSignal !== undefined) watch.observeAbort(context.abortSignal);\n\t\tif (start.kind === \"failed\") watch.fail(handedOut(start.error), context);\n\t\treturn watch;\n\t}\n\n\t/**\n\t * Attaches a synchronous observer at the current value (Durable's `observeXXX`); it counts as following, so a lazy\n\t * value is computed in the batch that changed it. Throws the failure when there is no value to start at; aborting\n\t * `context` detaches it (`aborted`); the source's end detaches it too (`ended`), its abort listener removed.\n\t */\n\tobserve(observer: NativeObserver<T>, context: Context): NativeObservation<T> {\n\t\tthis.batch?.assertOutside(\"observe\");\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!.value;\n\t\tif (this.batch === undefined) {\n\t\t\tobserver.end(ENDED);\n\t\t\treturn { value, detach: NOTHING };\n\t\t}\n\t\tconst signal = context.abortSignal;\n\t\tif (signal?.aborted) {\n\t\t\tobserver.end(ABORTED);\n\t\t\treturn { value, detach: NOTHING };\n\t\t}\n\t\tconst aborted = (): void => {\n\t\t\tif (!this.#observers.has(observer)) return;\n\t\t\tthis.unsubscribe(observer);\n\t\t\tobserver.end(ABORTED);\n\t\t};\n\t\tconst cleanup = signal === undefined ? NOTHING : () => signal.removeEventListener(\"abort\", aborted);\n\t\tsignal?.addEventListener(\"abort\", aborted, { once: true });\n\t\tthis.#follow(start);\n\t\tthis.#observers.set(observer, cleanup);\n\t\treturn { value, detach: () => this.unsubscribe(observer) };\n\t}\n\n\t/**\n\t * Feeds `observer` every call from now on, inside each batch, also while the source has no value (Chord's own\n\t * followers: `retryOn`). Nothing is delivered for the current value.\n\t */\n\tsubscribe(observer: NativeObserver<T>): void {\n\t\tif (this.batch === undefined) return;\n\t\tthis.#follow(this.#startOrNone());\n\t\tthis.#observers.set(observer, NOTHING);\n\t}\n\n\tunsubscribe(observer: NativeObserver<T>): void {\n\t\tconst cleanup = this.#observers.get(observer);\n\t\tif (cleanup === undefined) return;\n\t\tthis.#observers.delete(observer);\n\t\tcleanup();\n\t\tthis.#settleFollowers();\n\t}\n\n\t/** Delivers this batch's frame: the new value when the followers have another, or a failure once per episode. */\n\tdeliver(context: Context): void {\n\t\tthis.#listed = false;\n\t\tconst shown = this.#shown;\n\t\tif (shown === undefined) return;\n\t\tthis.#deliver(shown, context);\n\t\t// Readers waiting for a first value pulled it through this delivery: nothing is kept for them.\n\t\tthis.#settleFollowers();\n\t}\n\n\t/**\n\t * Records a change inside the current batch: every dependent marked, and the source listed for a frame when someone\n\t * follows it (or `watched` says so).\n\t */\n\tprotected override changed(): void {\n\t\tsuper.changed();\n\t\tthis.list();\n\t}\n\n\t/**\n\t * Lists the source for a frame in the current batch when someone follows it (or `watched` says so), its dependents\n\t * left as they are (marked already).\n\t */\n\tprotected list(): void {\n\t\tif (this.#listed || !this.watched || this.batch === undefined) return;\n\t\tthis.#listed = true;\n\t\t// Only readers waiting for a first value follow it without a follower's record: they have none. Not computed\n\t\t// here: marking runs inside adoptions, the value is pulled in the delivery.\n\t\tthis.#shown ??= NONE;\n\t\tthis.batch.changed(this);\n\t}\n\n\t/** Nothing follows it any more (no watch, no observer): a subclass drops what it kept for followers. */\n\tprotected unfollowed(): void {}\n\n\t/** Ends the source for good: watches and observers end `ended` (their abort listeners removed). */\n\tprotected override end(): void {\n\t\tsuper.end();\n\t\tthis.#shown = undefined;\n\t\t// Ending detaches, which deletes the current entry (safe while iterating) and runs no listener.\n\t\tfor (const watch of this.#watches) watch.end(ENDED);\n\t\tconst observers = [...this.#observers];\n\t\tthis.#observers.clear();\n\t\tfor (const [observer, cleanup] of observers) {\n\t\t\tcleanup();\n\t\t\tobserver.end(ENDED);\n\t\t}\n\t}\n\n\t#deliver(shown: Shown<T>, context: Context): void {\n\t\tconst start = this.#startOrNone();\n\t\tif (start.kind === \"failed\") {\n\t\t\t// A failure reaches followers that had a value: those without one wait for the first.\n\t\t\tif (shown.kind !== \"value\") return;\n\t\t\tthis.#shown = FAILED;\n\t\t\tconst error = handedOut(start.error);\n\t\t\tfor (const watch of this.#watches) watch.fail(error, context);\n\t\t\tfor (const observer of [...this.#observers.keys()]) observer.advance({ kind: \"failed\", error }, context);\n\t\t\treturn;\n\t\t}\n\t\tif (start.kind !== \"value\" || (shown.kind === \"value\" && shown.value === start.value)) return;\n\t\tconst { value } = start;\n\t\tthis.#shown = start;\n\t\tfor (const watch of this.#watches) watch.advance(value, context);\n\t\t// A copy: an observer may detach itself in its call.\n\t\tfor (const observer of [...this.#observers.keys()]) observer.advance({ kind: \"value\", value }, context);\n\t}\n\n\t/** Its start, `none` while it has no value. */\n\t#startOrNone(): NativeStart<T> | { readonly kind: \"none\" } {\n\t\tconst start = this.start();\n\t\treturn start.kind === \"failed\" && start.last === undefined ? NONE : start;\n\t}\n\n\t/** A follower comes: the first one records what followers have (a later one opened at the same current value). */\n\t#follow(start: NativeStart<T> | { readonly kind: \"none\" }): void {\n\t\tif (this.#shown !== undefined) return;\n\t\tthis.#shown = start.kind === \"failed\" ? FAILED : start;\n\t}\n\n\t#unfollow(watch: NativeWatch<T>): void {\n\t\tthis.#watches.delete(watch);\n\t\tthis.#settleFollowers();\n\t}\n\n\t/** No follower left: nothing is shown any more, so no old value is kept. */\n\t#settleFollowers(): void {\n\t\tif (this.#watches.size > 0 || this.#observers.size > 0) return;\n\t\tthis.#shown = undefined;\n\t\tthis.unfollowed();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
import type { Op } from "../../delta/index.ts";
|
|
3
|
+
import type { JsonValue } from "../../json.ts";
|
|
4
|
+
import { Watch, type Watchable, type WatchCall, type WatchEnd } from "../../watch.ts";
|
|
5
|
+
import type { Batch } from "./batch.ts";
|
|
6
|
+
/**
|
|
7
|
+
* A synchronous subscriber of a source (a hold over a link, a reference's member): fed the source's call inside the batch
|
|
8
|
+
* that made it, before the batch ends, so everything one commit changed can leave in one message. The watch's own sink
|
|
9
|
+
* shape (`Watch.advance`, `Watch.end`).
|
|
10
|
+
*/
|
|
11
|
+
export interface Subscriber {
|
|
12
|
+
/**
|
|
13
|
+
* The source's call of this batch, in its batch's `context`: a value (the ops from the previous one, and whether its
|
|
14
|
+
* document was retired in it, or for a derive one of its sources' documents), or a failure it may recover from; the
|
|
15
|
+
* next value after a failure is `[["r", value]]`.
|
|
16
|
+
*/
|
|
17
|
+
advance(call: WatchCall<JsonValue>, context: Context): void;
|
|
18
|
+
/** The source ended for good with `end`; nothing follows, and the subscriber is dropped. */
|
|
19
|
+
end(end: WatchEnd): void;
|
|
20
|
+
/**
|
|
21
|
+
* The source ended for good after its last call (a followed runtime ended): a subscriber delivering later (a watch)
|
|
22
|
+
* ends `ended` once it delivered what it was given, others end now.
|
|
23
|
+
*/
|
|
24
|
+
endAfterDelivery(): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What a new watch of a source starts at (design §11): its value, or, while it is failed, the failure and its last good
|
|
28
|
+
* value (`undefined` when it never had one: a watch cannot start then, there is nothing to start at).
|
|
29
|
+
*/
|
|
30
|
+
export type WatchStart = {
|
|
31
|
+
readonly kind: "value";
|
|
32
|
+
readonly value: JsonValue;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: "failed";
|
|
35
|
+
readonly error: unknown;
|
|
36
|
+
readonly last: JsonValue | undefined;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* An error Chord hands to apps (a failure call, a report), its stack made text first: until then V8 keeps the frames'
|
|
40
|
+
* receivers, which would keep the host behind the throw alive for as long as an app keeps the error.
|
|
41
|
+
*/
|
|
42
|
+
export declare function handedOut<E>(error: E): E;
|
|
43
|
+
/**
|
|
44
|
+
* What reads a source and is marked by its changes: a derive, or a reference's member forwarding to derives (`Source.
|
|
45
|
+
* dependents`).
|
|
46
|
+
*/
|
|
47
|
+
export interface Dependent {
|
|
48
|
+
/** The source changed in the current batch: flags only, no compute. */
|
|
49
|
+
invalidate(): void;
|
|
50
|
+
/** A source's document was retired in the current batch (rule 21); `visited` keeps a diamond walked once. */
|
|
51
|
+
sourceRetired(visited: Set<Dependent>): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A changing value on a host (a singleton document, a derive, a replica): its watches and subscribers get one frame
|
|
55
|
+
* per batch that changed it, and the derives reading it are marked dirty when it changes.
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class Source implements Watchable<JsonValue> {
|
|
58
|
+
#private;
|
|
59
|
+
/** Derives reading this source (and references' members forwarding to some); each removes itself when it stops. */
|
|
60
|
+
readonly dependents: Set<Dependent>;
|
|
61
|
+
protected readonly batch: Batch;
|
|
62
|
+
constructor(batch: Batch);
|
|
63
|
+
abstract get value(): JsonValue;
|
|
64
|
+
/** Whether a watch or a subscriber follows this source. */
|
|
65
|
+
get watched(): boolean;
|
|
66
|
+
watch(context: Context): Promise<Watch<JsonValue>>;
|
|
67
|
+
/**
|
|
68
|
+
* `watch` without the Promise, for references, which must register the watch before anything else runs. On a failed
|
|
69
|
+
* source it opens at the last good value and its first call is the failure; with no value to start at it throws the
|
|
70
|
+
* failure.
|
|
71
|
+
*/
|
|
72
|
+
openWatch(context: Context): Watch<JsonValue>;
|
|
73
|
+
/** What a new watch starts at; a source that can fail and recover tells its failure (`WatchStart`). */
|
|
74
|
+
start(): WatchStart;
|
|
75
|
+
/** Feeds `subscriber` every frame from now on, inside each batch; the caller took the current value first. */
|
|
76
|
+
subscribe(subscriber: Subscriber): void;
|
|
77
|
+
unsubscribe(subscriber: Subscriber): void;
|
|
78
|
+
/** Delivers this batch's frame to its watches; called once per batch that listed it with `changed`. */
|
|
79
|
+
abstract deliver(context: Context): void;
|
|
80
|
+
/** Records a change in the current batch: listed for a frame when watched, and every dependent marked dirty. */
|
|
81
|
+
protected changed(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Records a retirement of this source's document in the current batch: every derive reading it, directly or
|
|
84
|
+
* through other derives, carries the flag on in its frame (rule 21). Called after `changed`.
|
|
85
|
+
*/
|
|
86
|
+
protected retiredInBatch(): void;
|
|
87
|
+
/** Queues one frame on every watch and feeds it to every subscriber. */
|
|
88
|
+
protected publish(value: JsonValue, ops: readonly Op[], retired: boolean, context: Context): void;
|
|
89
|
+
/** Queues `call` on every watch and feeds it to every subscriber, as it is (a reference's member passes one on). */
|
|
90
|
+
protected forward(call: WatchCall<JsonValue>, context: Context): void;
|
|
91
|
+
/**
|
|
92
|
+
* Gives every watch and subscriber one failure call (design §11): the source cannot compute its value now and may
|
|
93
|
+
* recover; they stay open, and its next value is `[["r", value]]`.
|
|
94
|
+
*/
|
|
95
|
+
protected failWatches(error: unknown, context: Context): void;
|
|
96
|
+
/**
|
|
97
|
+
* Ends every watch and subscriber for good once what they were given is delivered (a followed runtime ended after a
|
|
98
|
+
* last call, Durable's `endAfterDelivery`): `ended`; nothing follows.
|
|
99
|
+
*/
|
|
100
|
+
protected endWatchesAfterDelivery(): void;
|
|
101
|
+
/** Ends every watch and subscriber for good (its owner ended): `ended`; nothing follows. */
|
|
102
|
+
protected endWatches(): void;
|
|
103
|
+
}
|
|
104
|
+
/** A watchable that never changes (start data, §18); usable as a state member and as a derive source. */
|
|
105
|
+
export declare function constant<const T extends JsonValue>(value: T): Watchable<T>;
|
|
106
|
+
/** The watchable behind `constant(value)`: its watches never get a frame and end only by stop or cancellation. */
|
|
107
|
+
export declare class Constant implements Watchable<JsonValue> {
|
|
108
|
+
readonly value: JsonValue;
|
|
109
|
+
constructor(value: JsonValue);
|
|
110
|
+
watch(context: Context): Promise<Watch<JsonValue>>;
|
|
111
|
+
/** As `Source.openWatch`; nothing is delivered, so nothing is reported. */
|
|
112
|
+
openWatch(context: Context): Watch<JsonValue>;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=watchable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchable.d.ts","sourceRoot":"","sources":["../../../src/next/state/watchable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,WAAW,UAAU;IAC1B;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5D,4FAA4F;IAC5F,GAAG,CAAC,GAAG,EAAE,QAAQ,G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