@earendil-works/chord 1.3.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 +54 -0
- package/README.md +129 -10
- 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 +8 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +15 -0
- 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 +9 -3
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +21 -9
- 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 +54 -0
- package/dist/sqlite/cloudflare.d.ts.map +1 -0
- package/dist/sqlite/cloudflare.js +144 -0
- package/dist/sqlite/cloudflare.js.map +1 -0
- package/dist/sqlite/database.d.ts +40 -0
- package/dist/sqlite/database.d.ts.map +1 -0
- package/dist/sqlite/database.js +2 -0
- package/dist/sqlite/database.js.map +1 -0
- package/dist/sqlite/index.d.ts +4 -0
- package/dist/sqlite/index.d.ts.map +1 -0
- package/dist/sqlite/index.js +3 -0
- package/dist/sqlite/index.js.map +1 -0
- package/dist/sqlite/migrations.d.ts +10 -0
- package/dist/sqlite/migrations.d.ts.map +1 -0
- package/dist/sqlite/migrations.js +33 -0
- package/dist/sqlite/migrations.js.map +1 -0
- package/dist/sqlite/node.d.ts +41 -0
- package/dist/sqlite/node.d.ts.map +1 -0
- package/dist/sqlite/node.js +191 -0
- package/dist/sqlite/node.js.map +1 -0
- package/dist/sqlite/schema.d.ts +3 -0
- package/dist/sqlite/schema.d.ts.map +1 -0
- package/dist/sqlite/schema.js +10 -0
- package/dist/sqlite/schema.js.map +1 -0
- package/dist/telemetry-sqlite/index.d.ts +24 -0
- package/dist/telemetry-sqlite/index.d.ts.map +1 -0
- package/dist/telemetry-sqlite/index.js +273 -0
- package/dist/telemetry-sqlite/index.js.map +1 -0
- package/dist/telemetry-sqlite/store.d.ts +9 -0
- package/dist/telemetry-sqlite/store.d.ts.map +1 -0
- package/dist/telemetry-sqlite/store.js +110 -0
- package/dist/telemetry-sqlite/store.js.map +1 -0
- 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 +42 -5
- package/src/delta/README.md +69 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Replicas (§7, §22): a state member of a remote reference on the consumer, built from the snapshot and then changed
|
|
2
|
+
// by the provider's ops, decoded with the member's own Delta decoder and applied without validation or copy
|
|
3
|
+
// (`applyImmutable` shares structure); replaced by the snapshot of each re-hold.
|
|
4
|
+
import { applyImmutable, decoder } from "../../delta/index.js";
|
|
5
|
+
import { handedOut, Source } from "../state/internal.js";
|
|
6
|
+
const NO_OPS = [];
|
|
7
|
+
/** One state member of a hold, as the consumer reads and watches it; changed only inside the consumer's batch. */
|
|
8
|
+
export class Replica extends Source {
|
|
9
|
+
#state;
|
|
10
|
+
/** The member's decoder, started with the snapshot as the provider's encoder was; a new one per snapshot. */
|
|
11
|
+
#decoder = decoder();
|
|
12
|
+
/** The ops of the current batch's frame, and whether the provider's document was retired in it. */
|
|
13
|
+
#ops = NO_OPS;
|
|
14
|
+
#retired = false;
|
|
15
|
+
/** A retirement that reached it while failed: its next value carries the flag. */
|
|
16
|
+
#retiredWhileFailed = false;
|
|
17
|
+
constructor(batch, state) {
|
|
18
|
+
super(batch);
|
|
19
|
+
this.#state = state.kind === "value" ? state : { kind: "failed", error: handedOut(state.error), last: undefined };
|
|
20
|
+
}
|
|
21
|
+
get value() {
|
|
22
|
+
const state = this.#state;
|
|
23
|
+
if (state.kind === "value")
|
|
24
|
+
return state.value;
|
|
25
|
+
throw state.error;
|
|
26
|
+
}
|
|
27
|
+
/** Its value, or while failed its failure and last good value. */
|
|
28
|
+
start() {
|
|
29
|
+
const state = this.#state;
|
|
30
|
+
if (state.kind === "failed")
|
|
31
|
+
return { kind: "failed", error: state.error, last: state.last };
|
|
32
|
+
return { kind: "value", value: this.value };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The value `wire` (this member's wire ops from one state part) makes, and its ops; changes nothing yet. Throws on
|
|
36
|
+
* ops that do not fit (a protocol error): an ended member's, and a failed member's other than its recovery, which
|
|
37
|
+
* the provider sends as `[["r", value]]`.
|
|
38
|
+
*/
|
|
39
|
+
decode(wire) {
|
|
40
|
+
// Trust boundary: fresh JSON from the link; Delta's decoder checks each op.
|
|
41
|
+
if (!Array.isArray(wire))
|
|
42
|
+
throw new Error("part: a member's changes are a list of ops");
|
|
43
|
+
const ops = this.#decoder.decode(wire);
|
|
44
|
+
const state = this.#state;
|
|
45
|
+
if (state.kind === "ended")
|
|
46
|
+
throw state.error;
|
|
47
|
+
if (state.kind === "value")
|
|
48
|
+
return { value: applyImmutable(state.value, ops), ops };
|
|
49
|
+
if (ops[0]?.[0] !== "r")
|
|
50
|
+
throw new Error("part: a failed member recovers with a root replacement");
|
|
51
|
+
return { value: applyImmutable(null, ops), ops };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Adopts the member's new value, the ops that made it and whether the provider's document was retired, in the
|
|
55
|
+
* current batch (one adoption per member and batch).
|
|
56
|
+
*/
|
|
57
|
+
adopt(value, ops, retired) {
|
|
58
|
+
const flagged = retired || this.#retiredWhileFailed;
|
|
59
|
+
this.#state = { kind: "value", value };
|
|
60
|
+
this.#ops = ops;
|
|
61
|
+
this.#retired = flagged;
|
|
62
|
+
this.#retiredWhileFailed = false;
|
|
63
|
+
this.changed();
|
|
64
|
+
if (flagged)
|
|
65
|
+
this.retiredInBatch();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The provider's document was retired with no ops for this member (a derive whose value stayed, rule 21), in the
|
|
69
|
+
* current batch: the flag alone; while failed it waits for the next value (a failed member's value is never read).
|
|
70
|
+
*/
|
|
71
|
+
retireAlone() {
|
|
72
|
+
const state = this.#state;
|
|
73
|
+
if (state.kind === "value")
|
|
74
|
+
this.adopt(state.value, NO_OPS, true);
|
|
75
|
+
else if (state.kind === "failed")
|
|
76
|
+
this.#retiredWhileFailed = true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A re-hold's snapshot of the member, in the batch that applies it, with a fresh decoder (the provider's encoder
|
|
80
|
+
* starts anew with it): a value is one frame `[["r", value]]`, a failed member fails.
|
|
81
|
+
*/
|
|
82
|
+
reset(state) {
|
|
83
|
+
this.#decoder = decoder();
|
|
84
|
+
if (state.kind === "failed")
|
|
85
|
+
this.fail(state.error);
|
|
86
|
+
else
|
|
87
|
+
this.adopt(state.value, [["r", state.value]], false);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The provider's member failed, in the batch that applies it: reads throw `error`, watches get one failure call and
|
|
91
|
+
* stay open, derives over it fail; its recovery is `[["r", value]]`.
|
|
92
|
+
*/
|
|
93
|
+
fail(error) {
|
|
94
|
+
const state = this.#state;
|
|
95
|
+
const last = state.kind === "value" ? state.value : state.kind === "failed" ? state.last : undefined;
|
|
96
|
+
this.#state = { kind: "failed", error: handedOut(error), last };
|
|
97
|
+
// Failed already: its watches and derives have the failure (one call per failure episode).
|
|
98
|
+
if (state.kind !== "failed")
|
|
99
|
+
this.changed();
|
|
100
|
+
}
|
|
101
|
+
deliver(context) {
|
|
102
|
+
const state = this.#state;
|
|
103
|
+
if (state.kind === "failed")
|
|
104
|
+
this.failWatches(state.error, context);
|
|
105
|
+
else if (state.kind === "value")
|
|
106
|
+
this.publish(state.value, this.#ops, this.#retired, context);
|
|
107
|
+
else
|
|
108
|
+
this.endWatches();
|
|
109
|
+
this.#ops = NO_OPS;
|
|
110
|
+
this.#retired = false;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The member is not in a newly bound variant, in the batch that binds it: as a failure (`fail`) with `error`; a later
|
|
114
|
+
* binding of a variant that has it brings it back (`reset`), as on the provider's host.
|
|
115
|
+
*/
|
|
116
|
+
vanish(error) {
|
|
117
|
+
this.fail(error);
|
|
118
|
+
}
|
|
119
|
+
/** Its reference ended (outside a batch): reads throw `error`, watches end `ended`. */
|
|
120
|
+
end(error) {
|
|
121
|
+
this.#state = { kind: "ended", error };
|
|
122
|
+
this.endWatches();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=replica.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replica.js","sourceRoot":"","sources":["../../../src/next/remote/replica.ts"],"names":[],"mappings":"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","sourcesContent":["// Replicas (§7, §22): a state member of a remote reference on the consumer, built from the snapshot and then changed\n// by the provider's ops, decoded with the member's own Delta decoder and applied without validation or copy\n// (`applyImmutable` shares structure); replaced by the snapshot of each re-hold.\n\nimport type { Context } from \"../../context/index.ts\";\nimport { applyImmutable, decoder, type Op } from \"../../delta/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport type { ChordError } from \"../data/index.ts\";\nimport { type Batch, handedOut, Source, type WatchStart } from \"../state/internal.ts\";\n\n/**\n * Where a replica stands: a value, a failed member (reads throw; the provider's member failed, or a newly bound variant\n * lacks it, and either may come back; `last` is its last good value, `undefined` when it had none), or ended with its\n * reference.\n */\ntype ReplicaState =\n\t| { readonly kind: \"value\"; readonly value: JsonValue }\n\t| { readonly kind: \"failed\"; readonly error: unknown; readonly last: JsonValue | undefined }\n\t| { readonly kind: \"ended\"; readonly error: ChordError };\n\n/** A member as a snapshot has it: a value, or failed. */\nexport type MemberSnapshot =\n\t| { readonly kind: \"value\"; readonly value: JsonValue }\n\t| { readonly kind: \"failed\"; readonly error: unknown };\n\nconst NO_OPS: readonly Op[] = [];\n\n/** One state member of a hold, as the consumer reads and watches it; changed only inside the consumer's batch. */\nexport class Replica extends Source {\n\t#state: ReplicaState;\n\t/** The member's decoder, started with the snapshot as the provider's encoder was; a new one per snapshot. */\n\t#decoder = decoder();\n\t/** The ops of the current batch's frame, and whether the provider's document was retired in it. */\n\t#ops = NO_OPS;\n\t#retired = false;\n\t/** A retirement that reached it while failed: its next value carries the flag. */\n\t#retiredWhileFailed = false;\n\n\tconstructor(batch: Batch, state: MemberSnapshot) {\n\t\tsuper(batch);\n\t\tthis.#state = state.kind === \"value\" ? state : { kind: \"failed\", error: handedOut(state.error), last: undefined };\n\t}\n\n\tget value(): JsonValue {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"value\") return state.value;\n\t\tthrow state.error;\n\t}\n\n\t/** Its value, or while failed its failure and last good value. */\n\tstart(): WatchStart {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"failed\") return { kind: \"failed\", error: state.error, last: state.last };\n\t\treturn { kind: \"value\", value: this.value };\n\t}\n\n\t/**\n\t * The value `wire` (this member's wire ops from one state part) makes, and its ops; changes nothing yet. Throws on\n\t * ops that do not fit (a protocol error): an ended member's, and a failed member's other than its recovery, which\n\t * the provider sends as `[[\"r\", value]]`.\n\t */\n\tdecode(wire: unknown): { readonly value: JsonValue; readonly ops: readonly Op[] } {\n\t\t// Trust boundary: fresh JSON from the link; Delta's decoder checks each op.\n\t\tif (!Array.isArray(wire)) throw new Error(\"part: a member's changes are a list of ops\");\n\t\tconst ops = this.#decoder.decode(wire);\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"ended\") throw state.error;\n\t\tif (state.kind === \"value\") return { value: applyImmutable(state.value, ops), ops };\n\t\tif (ops[0]?.[0] !== \"r\") throw new Error(\"part: a failed member recovers with a root replacement\");\n\t\treturn { value: applyImmutable(null, ops), ops };\n\t}\n\n\t/**\n\t * Adopts the member's new value, the ops that made it and whether the provider's document was retired, in the\n\t * current batch (one adoption per member and batch).\n\t */\n\tadopt(value: JsonValue, ops: readonly Op[], retired: boolean): void {\n\t\tconst flagged = retired || this.#retiredWhileFailed;\n\t\tthis.#state = { kind: \"value\", value };\n\t\tthis.#ops = ops;\n\t\tthis.#retired = flagged;\n\t\tthis.#retiredWhileFailed = false;\n\t\tthis.changed();\n\t\tif (flagged) this.retiredInBatch();\n\t}\n\n\t/**\n\t * The provider's document was retired with no ops for this member (a derive whose value stayed, rule 21), in the\n\t * current batch: the flag alone; while failed it waits for the next value (a failed member's value is never read).\n\t */\n\tretireAlone(): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"value\") this.adopt(state.value, NO_OPS, true);\n\t\telse if (state.kind === \"failed\") this.#retiredWhileFailed = true;\n\t}\n\n\t/**\n\t * A re-hold's snapshot of the member, in the batch that applies it, with a fresh decoder (the provider's encoder\n\t * starts anew with it): a value is one frame `[[\"r\", value]]`, a failed member fails.\n\t */\n\treset(state: MemberSnapshot): void {\n\t\tthis.#decoder = decoder();\n\t\tif (state.kind === \"failed\") this.fail(state.error);\n\t\telse this.adopt(state.value, [[\"r\", state.value]], false);\n\t}\n\n\t/**\n\t * The provider's member failed, in the batch that applies it: reads throw `error`, watches get one failure call and\n\t * stay open, derives over it fail; its recovery is `[[\"r\", value]]`.\n\t */\n\tfail(error: unknown): void {\n\t\tconst state = this.#state;\n\t\tconst last = state.kind === \"value\" ? state.value : state.kind === \"failed\" ? state.last : undefined;\n\t\tthis.#state = { kind: \"failed\", error: handedOut(error), last };\n\t\t// Failed already: its watches and derives have the failure (one call per failure episode).\n\t\tif (state.kind !== \"failed\") this.changed();\n\t}\n\n\tdeliver(context: Context): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"failed\") this.failWatches(state.error, context);\n\t\telse if (state.kind === \"value\") this.publish(state.value, this.#ops, this.#retired, context);\n\t\telse this.endWatches();\n\t\tthis.#ops = NO_OPS;\n\t\tthis.#retired = false;\n\t}\n\n\t/**\n\t * The member is not in a newly bound variant, in the batch that binds it: as a failure (`fail`) with `error`; a later\n\t * binding of a variant that has it brings it back (`reset`), as on the provider's host.\n\t */\n\tvanish(error: ChordError): void {\n\t\tthis.fail(error);\n\t}\n\n\t/** Its reference ended (outside a batch): reads throw `error`, watches end `ended`. */\n\tend(error: ChordError): void {\n\t\tthis.#state = { kind: \"ended\", error };\n\t\tthis.endWatches();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { TelemetryMetrics } from "@earendil-works/pi-telemetry";
|
|
2
|
+
import type { Context } from "../../context/index.ts";
|
|
3
|
+
/** What a batch reports: a watch listener that threw, or a frame delivery that threw (a derive's value is no JSON). */
|
|
4
|
+
export type BatchError = {
|
|
5
|
+
readonly kind: "listener_error";
|
|
6
|
+
readonly error: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "delivery_failed";
|
|
9
|
+
readonly error: unknown;
|
|
10
|
+
};
|
|
11
|
+
/** What a commit lists to get its frame delivered: a watched source it changed (JSON or native). */
|
|
12
|
+
export interface Delivered {
|
|
13
|
+
/** Delivers this batch's frame to its watches and subscribers; called once per batch that listed it. */
|
|
14
|
+
deliver(context: Context): void;
|
|
15
|
+
}
|
|
16
|
+
/** A host's batch: the reentrancy flag, the watched sources a commit changed, and where background errors go. */
|
|
17
|
+
export declare class Batch {
|
|
18
|
+
#private;
|
|
19
|
+
/** Reports a throwing watch listener's error (to the host's `onError`); what watches get as their `report`. */
|
|
20
|
+
readonly reportListener: (error: unknown) => void;
|
|
21
|
+
constructor(report: (error: BatchError) => void, metrics: TelemetryMetrics | undefined);
|
|
22
|
+
/** Whether a commit's adoption, a delivery or a derive compute runs now: a change made now lands in this batch. */
|
|
23
|
+
get running(): boolean;
|
|
24
|
+
/** Throws `invalid/reentrant` inside the batch: `operation` may not run during adoptions or derive computes. */
|
|
25
|
+
assertOutside(operation: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Throws `invalid/reentrant` inside a pure compute (a derive's, a registry's `compose`): `operation` would change a
|
|
28
|
+
* source while one is computed from it. Changes inside an adoption are fine (they land in its batch).
|
|
29
|
+
*/
|
|
30
|
+
assertNotComputing(operation: string): void;
|
|
31
|
+
/** Runs the pure compute `work` (`run`, and changes refused: `assertNotComputing`); nests. */
|
|
32
|
+
compute<T>(work: () => T): T;
|
|
33
|
+
/** Runs `work` with reentrant calls refused; nests (a derive compute inside a commit). */
|
|
34
|
+
run<T>(work: () => T): T;
|
|
35
|
+
/**
|
|
36
|
+
* Runs one commit's adoptions, then, still synchronously, delivers a frame for every watched value they changed
|
|
37
|
+
* (watched derives recompute through their reads), then runs the flushes the deliveries listed. A delivery or flush
|
|
38
|
+
* that throws is reported; the others still run. What `within` deferred while the flushes sent runs as the next
|
|
39
|
+
* commit, right after.
|
|
40
|
+
*/
|
|
41
|
+
commit(adopt: () => void, context: Context): void;
|
|
42
|
+
/**
|
|
43
|
+
* Runs `adopt` inside the commit running now, which delivers what it changed; outside one, as a commit of its own;
|
|
44
|
+
* while a commit's flushes send, as the next commit (a link closing while it sends ends its holds: their departure
|
|
45
|
+
* lands in the next batch, so one commit stays one message per link and origin). For changes that happen wherever a
|
|
46
|
+
* reference binds or ends (`host.references`, `host.activity`).
|
|
47
|
+
*/
|
|
48
|
+
within(adopt: () => void, context: Context): void;
|
|
49
|
+
/**
|
|
50
|
+
* Runs `adopt` in one commit on the next microtask, together with every other `soon` until then (changes arriving
|
|
51
|
+
* outside any commit, as a followed runtime's calls off its commit step: one batch for all of them). `context` is
|
|
52
|
+
* the first one's.
|
|
53
|
+
*/
|
|
54
|
+
soon(adopt: () => void, context: Context): void;
|
|
55
|
+
/** Lists a watched source the current commit changed. */
|
|
56
|
+
changed(source: Delivered): void;
|
|
57
|
+
/** Lists `flush` to run at the end of the current commit, after its deliveries (a link sending what they fed it). */
|
|
58
|
+
flushing(flush: (context: Context) => void): void;
|
|
59
|
+
/**
|
|
60
|
+
* Counts one unit of derive or registry work on the host's metrics (a lazy read has no context to count through).
|
|
61
|
+
*/
|
|
62
|
+
count(counter: "chord.derive.computes" | "chord.derive.diffs" | "chord.registry.composes" | "chord.registry.adapts" | "chord.contract.adapts"): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../src/next/state/batch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGtD,uHAAuH;AACvH,MAAM,MAAM,UAAU,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjE,oGAAoG;AACpG,MAAM,WAAW,SAAS;IACzB,wGAAwG;IACxG,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAED,iHAAiH;AACjH,qBAAa,KAAK;;IACjB,+GAA+G;IAC/G,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAkBlD,YAAY,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAIrF;IAED,mHAAmH;IACnH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,gHAAgH;IAChH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAErC;IAED;;;OAGG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE1C;IAED,8FAA8F;IAC9F,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAW3B;IAED,0FAA0F;IAC1F,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAQvB;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CA+BhD;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAIhD;IAED;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAa9C;IAED,yDAAyD;IACzD,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAE/B;IAED,qHAAqH;IACrH,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAEhD;IAED;;OAEG;IACH,KAAK,CACJ,OAAO,EACJ,uBAAuB,GACvB,oBAAoB,GACpB,yBAAyB,GACzB,uBAAuB,GACvB,uBAAuB,GACxB,IAAI,CAEN;CACD"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// The batch (W1), one per host: a commit adopts inside it, then every watched value that changed gets one frame, then
|
|
2
|
+
// the flushes it collected run (a link sends one message); Chord calls that would reenter it are refused while it runs.
|
|
3
|
+
import { invalid } from "../data/internal.js";
|
|
4
|
+
/** A host's batch: the reentrancy flag, the watched sources a commit changed, and where background errors go. */
|
|
5
|
+
export class Batch {
|
|
6
|
+
/** Reports a throwing watch listener's error (to the host's `onError`); what watches get as their `report`. */
|
|
7
|
+
reportListener;
|
|
8
|
+
#report;
|
|
9
|
+
#metrics;
|
|
10
|
+
/** Set while adopting, delivering or computing a derive; one flag per host. */
|
|
11
|
+
#running = false;
|
|
12
|
+
/** Set while a pure compute runs (a derive's, a registry's `compose`): nothing may change a source then. */
|
|
13
|
+
#computing = false;
|
|
14
|
+
/** The watched sources the current commit changed, each listed once by its `changed`. */
|
|
15
|
+
#changed = [];
|
|
16
|
+
/** What runs once the current commit's frames were delivered, each listed once by its `flushing`. */
|
|
17
|
+
#flushes = [];
|
|
18
|
+
/** Set while the current commit's flushes run (its links send). */
|
|
19
|
+
#sending = false;
|
|
20
|
+
/** Changes `within` deferred while the flushes sent, for the next commit. */
|
|
21
|
+
#later = [];
|
|
22
|
+
/** Changes `soon` collected for the commit on the next microtask, while one is queued. */
|
|
23
|
+
#soon;
|
|
24
|
+
constructor(report, metrics) {
|
|
25
|
+
this.#report = report;
|
|
26
|
+
this.reportListener = (error) => report({ kind: "listener_error", error });
|
|
27
|
+
this.#metrics = metrics;
|
|
28
|
+
}
|
|
29
|
+
/** Whether a commit's adoption, a delivery or a derive compute runs now: a change made now lands in this batch. */
|
|
30
|
+
get running() {
|
|
31
|
+
return this.#running;
|
|
32
|
+
}
|
|
33
|
+
/** Throws `invalid/reentrant` inside the batch: `operation` may not run during adoptions or derive computes. */
|
|
34
|
+
assertOutside(operation) {
|
|
35
|
+
if (this.#running)
|
|
36
|
+
throw invalid("reentrant", `${operation} inside a commit or a derive compute`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Throws `invalid/reentrant` inside a pure compute (a derive's, a registry's `compose`): `operation` would change a
|
|
40
|
+
* source while one is computed from it. Changes inside an adoption are fine (they land in its batch).
|
|
41
|
+
*/
|
|
42
|
+
assertNotComputing(operation) {
|
|
43
|
+
if (this.#computing)
|
|
44
|
+
throw invalid("reentrant", `${operation} inside a derive compute or a compose`);
|
|
45
|
+
}
|
|
46
|
+
/** Runs the pure compute `work` (`run`, and changes refused: `assertNotComputing`); nests. */
|
|
47
|
+
compute(work) {
|
|
48
|
+
const running = this.#running;
|
|
49
|
+
const computing = this.#computing;
|
|
50
|
+
this.#running = true;
|
|
51
|
+
this.#computing = true;
|
|
52
|
+
try {
|
|
53
|
+
return work();
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
this.#running = running;
|
|
57
|
+
this.#computing = computing;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Runs `work` with reentrant calls refused; nests (a derive compute inside a commit). */
|
|
61
|
+
run(work) {
|
|
62
|
+
const outer = this.#running;
|
|
63
|
+
this.#running = true;
|
|
64
|
+
try {
|
|
65
|
+
return work();
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.#running = outer;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Runs one commit's adoptions, then, still synchronously, delivers a frame for every watched value they changed
|
|
73
|
+
* (watched derives recompute through their reads), then runs the flushes the deliveries listed. A delivery or flush
|
|
74
|
+
* that throws is reported; the others still run. What `within` deferred while the flushes sent runs as the next
|
|
75
|
+
* commit, right after.
|
|
76
|
+
*/
|
|
77
|
+
commit(adopt, context) {
|
|
78
|
+
this.run(() => {
|
|
79
|
+
try {
|
|
80
|
+
adopt();
|
|
81
|
+
for (const source of this.#changed) {
|
|
82
|
+
try {
|
|
83
|
+
source.deliver(context);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.#report({ kind: "delivery_failed", error });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this.#sending = true;
|
|
90
|
+
for (const flush of this.#flushes) {
|
|
91
|
+
try {
|
|
92
|
+
flush(context);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
this.#report({ kind: "delivery_failed", error });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
this.#sending = false;
|
|
101
|
+
this.#changed = [];
|
|
102
|
+
this.#flushes = [];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const later = this.#later;
|
|
106
|
+
if (later.length === 0)
|
|
107
|
+
return;
|
|
108
|
+
this.#later = [];
|
|
109
|
+
this.commit(() => {
|
|
110
|
+
for (const each of later)
|
|
111
|
+
each();
|
|
112
|
+
}, context);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Runs `adopt` inside the commit running now, which delivers what it changed; outside one, as a commit of its own;
|
|
116
|
+
* while a commit's flushes send, as the next commit (a link closing while it sends ends its holds: their departure
|
|
117
|
+
* lands in the next batch, so one commit stays one message per link and origin). For changes that happen wherever a
|
|
118
|
+
* reference binds or ends (`host.references`, `host.activity`).
|
|
119
|
+
*/
|
|
120
|
+
within(adopt, context) {
|
|
121
|
+
if (this.#sending)
|
|
122
|
+
this.#later.push(adopt);
|
|
123
|
+
else if (this.#running)
|
|
124
|
+
adopt();
|
|
125
|
+
else
|
|
126
|
+
this.commit(adopt, context);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Runs `adopt` in one commit on the next microtask, together with every other `soon` until then (changes arriving
|
|
130
|
+
* outside any commit, as a followed runtime's calls off its commit step: one batch for all of them). `context` is
|
|
131
|
+
* the first one's.
|
|
132
|
+
*/
|
|
133
|
+
soon(adopt, context) {
|
|
134
|
+
if (this.#soon !== undefined) {
|
|
135
|
+
this.#soon.push(adopt);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const soon = [adopt];
|
|
139
|
+
this.#soon = soon;
|
|
140
|
+
queueMicrotask(() => {
|
|
141
|
+
this.#soon = undefined;
|
|
142
|
+
this.commit(() => {
|
|
143
|
+
for (const each of soon)
|
|
144
|
+
each();
|
|
145
|
+
}, context);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/** Lists a watched source the current commit changed. */
|
|
149
|
+
changed(source) {
|
|
150
|
+
this.#changed.push(source);
|
|
151
|
+
}
|
|
152
|
+
/** Lists `flush` to run at the end of the current commit, after its deliveries (a link sending what they fed it). */
|
|
153
|
+
flushing(flush) {
|
|
154
|
+
this.#flushes.push(flush);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Counts one unit of derive or registry work on the host's metrics (a lazy read has no context to count through).
|
|
158
|
+
*/
|
|
159
|
+
count(counter) {
|
|
160
|
+
this.#metrics?.counter(counter).add(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../../src/next/state/batch.ts"],"names":[],"mappings":"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","sourcesContent":["// The batch (W1), one per host: a commit adopts inside it, then every watched value that changed gets one frame, then\n// the flushes it collected run (a link sends one message); Chord calls that would reenter it are refused while it runs.\n\nimport type { TelemetryMetrics } from \"@earendil-works/pi-telemetry\";\nimport type { Context } from \"../../context/index.ts\";\nimport { invalid } from \"../data/internal.ts\";\n\n/** What a batch reports: a watch listener that threw, or a frame delivery that threw (a derive's value is no JSON). */\nexport type BatchError =\n\t| { readonly kind: \"listener_error\"; readonly error: unknown }\n\t| { readonly kind: \"delivery_failed\"; readonly error: unknown };\n\n/** What a commit lists to get its frame delivered: a watched source it changed (JSON or native). */\nexport interface Delivered {\n\t/** Delivers this batch's frame to its watches and subscribers; called once per batch that listed it. */\n\tdeliver(context: Context): void;\n}\n\n/** A host's batch: the reentrancy flag, the watched sources a commit changed, and where background errors go. */\nexport class Batch {\n\t/** Reports a throwing watch listener's error (to the host's `onError`); what watches get as their `report`. */\n\treadonly reportListener: (error: unknown) => void;\n\treadonly #report: (error: BatchError) => void;\n\treadonly #metrics: TelemetryMetrics | undefined;\n\t/** Set while adopting, delivering or computing a derive; one flag per host. */\n\t#running = false;\n\t/** Set while a pure compute runs (a derive's, a registry's `compose`): nothing may change a source then. */\n\t#computing = false;\n\t/** The watched sources the current commit changed, each listed once by its `changed`. */\n\t#changed: Delivered[] = [];\n\t/** What runs once the current commit's frames were delivered, each listed once by its `flushing`. */\n\t#flushes: ((context: Context) => void)[] = [];\n\t/** Set while the current commit's flushes run (its links send). */\n\t#sending = false;\n\t/** Changes `within` deferred while the flushes sent, for the next commit. */\n\t#later: (() => void)[] = [];\n\t/** Changes `soon` collected for the commit on the next microtask, while one is queued. */\n\t#soon: (() => void)[] | undefined;\n\n\tconstructor(report: (error: BatchError) => void, metrics: TelemetryMetrics | undefined) {\n\t\tthis.#report = report;\n\t\tthis.reportListener = (error) => report({ kind: \"listener_error\", error });\n\t\tthis.#metrics = metrics;\n\t}\n\n\t/** Whether a commit's adoption, a delivery or a derive compute runs now: a change made now lands in this batch. */\n\tget running(): boolean {\n\t\treturn this.#running;\n\t}\n\n\t/** Throws `invalid/reentrant` inside the batch: `operation` may not run during adoptions or derive computes. */\n\tassertOutside(operation: string): void {\n\t\tif (this.#running) throw invalid(\"reentrant\", `${operation} inside a commit or a derive compute`);\n\t}\n\n\t/**\n\t * Throws `invalid/reentrant` inside a pure compute (a derive's, a registry's `compose`): `operation` would change a\n\t * source while one is computed from it. Changes inside an adoption are fine (they land in its batch).\n\t */\n\tassertNotComputing(operation: string): void {\n\t\tif (this.#computing) throw invalid(\"reentrant\", `${operation} inside a derive compute or a compose`);\n\t}\n\n\t/** Runs the pure compute `work` (`run`, and changes refused: `assertNotComputing`); nests. */\n\tcompute<T>(work: () => T): T {\n\t\tconst running = this.#running;\n\t\tconst computing = this.#computing;\n\t\tthis.#running = true;\n\t\tthis.#computing = true;\n\t\ttry {\n\t\t\treturn work();\n\t\t} finally {\n\t\t\tthis.#running = running;\n\t\t\tthis.#computing = computing;\n\t\t}\n\t}\n\n\t/** Runs `work` with reentrant calls refused; nests (a derive compute inside a commit). */\n\trun<T>(work: () => T): T {\n\t\tconst outer = this.#running;\n\t\tthis.#running = true;\n\t\ttry {\n\t\t\treturn work();\n\t\t} finally {\n\t\t\tthis.#running = outer;\n\t\t}\n\t}\n\n\t/**\n\t * Runs one commit's adoptions, then, still synchronously, delivers a frame for every watched value they changed\n\t * (watched derives recompute through their reads), then runs the flushes the deliveries listed. A delivery or flush\n\t * that throws is reported; the others still run. What `within` deferred while the flushes sent runs as the next\n\t * commit, right after.\n\t */\n\tcommit(adopt: () => void, context: Context): void {\n\t\tthis.run(() => {\n\t\t\ttry {\n\t\t\t\tadopt();\n\t\t\t\tfor (const source of this.#changed) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tsource.deliver(context);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.#report({ kind: \"delivery_failed\", error });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.#sending = true;\n\t\t\t\tfor (const flush of this.#flushes) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tflush(context);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.#report({ kind: \"delivery_failed\", error });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tthis.#sending = false;\n\t\t\t\tthis.#changed = [];\n\t\t\t\tthis.#flushes = [];\n\t\t\t}\n\t\t});\n\t\tconst later = this.#later;\n\t\tif (later.length === 0) return;\n\t\tthis.#later = [];\n\t\tthis.commit(() => {\n\t\t\tfor (const each of later) each();\n\t\t}, context);\n\t}\n\n\t/**\n\t * Runs `adopt` inside the commit running now, which delivers what it changed; outside one, as a commit of its own;\n\t * while a commit's flushes send, as the next commit (a link closing while it sends ends its holds: their departure\n\t * lands in the next batch, so one commit stays one message per link and origin). For changes that happen wherever a\n\t * reference binds or ends (`host.references`, `host.activity`).\n\t */\n\twithin(adopt: () => void, context: Context): void {\n\t\tif (this.#sending) this.#later.push(adopt);\n\t\telse if (this.#running) adopt();\n\t\telse this.commit(adopt, context);\n\t}\n\n\t/**\n\t * Runs `adopt` in one commit on the next microtask, together with every other `soon` until then (changes arriving\n\t * outside any commit, as a followed runtime's calls off its commit step: one batch for all of them). `context` is\n\t * the first one's.\n\t */\n\tsoon(adopt: () => void, context: Context): void {\n\t\tif (this.#soon !== undefined) {\n\t\t\tthis.#soon.push(adopt);\n\t\t\treturn;\n\t\t}\n\t\tconst soon = [adopt];\n\t\tthis.#soon = soon;\n\t\tqueueMicrotask(() => {\n\t\t\tthis.#soon = undefined;\n\t\t\tthis.commit(() => {\n\t\t\t\tfor (const each of soon) each();\n\t\t\t}, context);\n\t\t});\n\t}\n\n\t/** Lists a watched source the current commit changed. */\n\tchanged(source: Delivered): void {\n\t\tthis.#changed.push(source);\n\t}\n\n\t/** Lists `flush` to run at the end of the current commit, after its deliveries (a link sending what they fed it). */\n\tflushing(flush: (context: Context) => void): void {\n\t\tthis.#flushes.push(flush);\n\t}\n\n\t/**\n\t * Counts one unit of derive or registry work on the host's metrics (a lazy read has no context to count through).\n\t */\n\tcount(\n\t\tcounter:\n\t\t\t| \"chord.derive.computes\"\n\t\t\t| \"chord.derive.diffs\"\n\t\t\t| \"chord.registry.composes\"\n\t\t\t| \"chord.registry.adapts\"\n\t\t\t| \"chord.contract.adapts\",\n\t): void {\n\t\tthis.#metrics?.counter(counter).add(1);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
import type { JsonValue } from "../../json.ts";
|
|
3
|
+
import type { Batch } from "./batch.ts";
|
|
4
|
+
import { NativeSource } from "./native-source.ts";
|
|
5
|
+
import { type Constant, type Dependent, Source, type WatchStart } from "./watchable.ts";
|
|
6
|
+
/** A JSON watchable as Chord follows it (a state member, a JSON derive source): a source, or a constant. */
|
|
7
|
+
export type DeriveSource = Source | Constant;
|
|
8
|
+
/** What a derive reads: a JSON source or constant, or a native source (a `writable`, a registry value, `ref.state`). */
|
|
9
|
+
export type DeriveInput = DeriveSource | NativeSource;
|
|
10
|
+
/**
|
|
11
|
+
* A derive: `compute` over its sources' values, recomputed on read when dirty, so each compute runs at most once per
|
|
12
|
+
* batch and after its sources. A commit only marks it; the batch recomputes it only when something watched depends on
|
|
13
|
+
* it.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Derive extends Source implements Dependent {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(sources: readonly unknown[], compute: (values: readonly unknown[]) => JsonValue, batch: Batch);
|
|
18
|
+
get value(): JsonValue;
|
|
19
|
+
/** Its value, or while failed its failure and last good value (a detached derive throws). */
|
|
20
|
+
start(): WatchStart;
|
|
21
|
+
/**
|
|
22
|
+
* Starts reading its sources, as `resolve` maps the declared ones (at activation); the first read computes.
|
|
23
|
+
* `report` gets a throw of its compute, once per failure episode (a value ends it); a failing source's error is its
|
|
24
|
+
* source's to report.
|
|
25
|
+
*/
|
|
26
|
+
attach(resolve: (source: unknown, index: number) => DeriveInput, report: (error: unknown) => void): void;
|
|
27
|
+
/** Its object ended: no source keeps it, its watches end `ended`, reads throw `error` (the object's). */
|
|
28
|
+
detach(error: Error): void;
|
|
29
|
+
/**
|
|
30
|
+
* A source changed: mark this derive and its dependents dirty, flags only; a failed one too, which recomputes on its
|
|
31
|
+
* next read and heals when its sources give a value it can compute. An already dirty derive has dirty dependents
|
|
32
|
+
* (every read recomputes its sources first), so marking stops there.
|
|
33
|
+
*/
|
|
34
|
+
invalidate(): void;
|
|
35
|
+
/**
|
|
36
|
+
* A source's document was retired in this batch (`Source.retiredInBatch`): a watched derive's frame carries the
|
|
37
|
+
* flag, and the derives reading this one are told too.
|
|
38
|
+
*/
|
|
39
|
+
sourceRetired(visited: Set<Dependent>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Delivers the frame: the diff from the watches' value, a retirement even without ops (rule 21). A compute that
|
|
42
|
+
* throws gives one failure call when the watches had a value (one per failure episode), the watches stay open; a
|
|
43
|
+
* retirement waits for the next value.
|
|
44
|
+
*/
|
|
45
|
+
deliver(context: Context): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Maps an array calling `f` only for object elements not seen before (by identity), returning the previous result for
|
|
49
|
+
* the others; primitive elements are mapped every time. The cache is weak: dropped elements take their results along.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mapShared<E, R extends JsonValue>(f: (element: E) => R): (elements: readonly E[]) => R[];
|
|
52
|
+
//# sourceMappingURL=derive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../../../src/next/state/derive.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAa,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEnG,4GAA4G;AAC5G,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7C,wHAAwH;AACxH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;AAoBtD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,MAAO,YAAW,SAAS;;IAgBtD,YAAY,OAAO,EAAE,SAAS,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,EAAE,KAAK,EAIxG;IAED,IAAI,KAAK,IAAI,SAAS,CAKrB;IAED,6FAA6F;IAC7F,KAAK,IAAI,UAAU,CAOlB;IAED;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAOvG;IAED,yGAAyG;IACzG,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CASzB;IAED;;;;OAIG;IACH,UAAU,IAAI,IAAI,CAMjB;IAED;;;OAGG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,IAAI,CAM3C;IAED;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAmB9B;CA0BD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,CAavG"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Derives (§12): values computed from watchables, pulled when read and marked dirty by commits; and `mapShared`, which
|
|
2
|
+
// keeps unchanged elements identical so a derive's diff stays cheap.
|
|
3
|
+
import { diffRevisions } from "../../delta/index.js";
|
|
4
|
+
import { NativeSource } from "./native-source.js";
|
|
5
|
+
import { handedOut, Source } from "./watchable.js";
|
|
6
|
+
const DIRTY = { kind: "dirty" };
|
|
7
|
+
const NO_OPS = [];
|
|
8
|
+
/** What a failed derive's watches had: no value, so its next value frame replaces the value whole. */
|
|
9
|
+
const NO_VALUE = Symbol("no value");
|
|
10
|
+
/**
|
|
11
|
+
* A derive: `compute` over its sources' values, recomputed on read when dirty, so each compute runs at most once per
|
|
12
|
+
* batch and after its sources. A commit only marks it; the batch recomputes it only when something watched depends on
|
|
13
|
+
* it.
|
|
14
|
+
*/
|
|
15
|
+
export class Derive extends Source {
|
|
16
|
+
#compute;
|
|
17
|
+
/** The sources as declared, until `attach` resolves them. */
|
|
18
|
+
#declared;
|
|
19
|
+
#sources = [];
|
|
20
|
+
#state = { kind: "dirty" };
|
|
21
|
+
/** The value this derive's watches have, kept from its marking to its frame in the batch. */
|
|
22
|
+
#framed;
|
|
23
|
+
/** Whether a source's document was retired in the current batch while this derive is watched (rule 21). */
|
|
24
|
+
#retired = false;
|
|
25
|
+
/** Reports a failure of its compute to its owner (`attach`); once per failure episode, which a value ends. */
|
|
26
|
+
#report;
|
|
27
|
+
#failing = false;
|
|
28
|
+
/** Its last good value, which a watch opened while it is failed starts at (`NO_VALUE` before the first). */
|
|
29
|
+
#good = NO_VALUE;
|
|
30
|
+
constructor(sources, compute, batch) {
|
|
31
|
+
super(batch);
|
|
32
|
+
this.#declared = sources;
|
|
33
|
+
this.#compute = compute;
|
|
34
|
+
}
|
|
35
|
+
get value() {
|
|
36
|
+
const state = this.#state;
|
|
37
|
+
if (state.kind === "clean")
|
|
38
|
+
return state.value;
|
|
39
|
+
if (state.kind === "dirty")
|
|
40
|
+
return this.#recompute();
|
|
41
|
+
throw state.error;
|
|
42
|
+
}
|
|
43
|
+
/** Its value, or while failed its failure and last good value (a detached derive throws). */
|
|
44
|
+
start() {
|
|
45
|
+
try {
|
|
46
|
+
return { kind: "value", value: this.value };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (this.#state.kind !== "failed")
|
|
50
|
+
throw error;
|
|
51
|
+
return { kind: "failed", error, last: this.#good === NO_VALUE ? undefined : this.#good };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Starts reading its sources, as `resolve` maps the declared ones (at activation); the first read computes.
|
|
56
|
+
* `report` gets a throw of its compute, once per failure episode (a value ends it); a failing source's error is its
|
|
57
|
+
* source's to report.
|
|
58
|
+
*/
|
|
59
|
+
attach(resolve, report) {
|
|
60
|
+
this.#report = report;
|
|
61
|
+
this.#sources = this.#declared.map(resolve);
|
|
62
|
+
this.#declared = undefined;
|
|
63
|
+
for (const source of this.#sources) {
|
|
64
|
+
if (source instanceof Source || source instanceof NativeSource)
|
|
65
|
+
source.dependents.add(this);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Its object ended: no source keeps it, its watches end `ended`, reads throw `error` (the object's). */
|
|
69
|
+
detach(error) {
|
|
70
|
+
for (const source of this.#sources) {
|
|
71
|
+
if (source instanceof Source || source instanceof NativeSource)
|
|
72
|
+
source.dependents.delete(this);
|
|
73
|
+
}
|
|
74
|
+
this.#sources = [];
|
|
75
|
+
this.#declared = undefined;
|
|
76
|
+
this.#state = { kind: "detached", error };
|
|
77
|
+
this.#framed = undefined;
|
|
78
|
+
this.endWatches();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A source changed: mark this derive and its dependents dirty, flags only; a failed one too, which recomputes on its
|
|
82
|
+
* next read and heals when its sources give a value it can compute. An already dirty derive has dirty dependents
|
|
83
|
+
* (every read recomputes its sources first), so marking stops there.
|
|
84
|
+
*/
|
|
85
|
+
invalidate() {
|
|
86
|
+
const state = this.#state;
|
|
87
|
+
if (state.kind === "dirty" || state.kind === "detached")
|
|
88
|
+
return;
|
|
89
|
+
if (this.watched)
|
|
90
|
+
this.#framed = state.kind === "clean" ? state.value : NO_VALUE;
|
|
91
|
+
this.#state = DIRTY;
|
|
92
|
+
this.changed();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A source's document was retired in this batch (`Source.retiredInBatch`): a watched derive's frame carries the
|
|
96
|
+
* flag, and the derives reading this one are told too.
|
|
97
|
+
*/
|
|
98
|
+
sourceRetired(visited) {
|
|
99
|
+
// Once per derive per retirement: a diamond of derives is walked in its size, not once per path.
|
|
100
|
+
if (visited.has(this))
|
|
101
|
+
return;
|
|
102
|
+
visited.add(this);
|
|
103
|
+
if (this.watched)
|
|
104
|
+
this.#retired = true;
|
|
105
|
+
for (const derive of this.dependents)
|
|
106
|
+
derive.sourceRetired(visited);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Delivers the frame: the diff from the watches' value, a retirement even without ops (rule 21). A compute that
|
|
110
|
+
* throws gives one failure call when the watches had a value (one per failure episode), the watches stay open; a
|
|
111
|
+
* retirement waits for the next value.
|
|
112
|
+
*/
|
|
113
|
+
deliver(context) {
|
|
114
|
+
const before = this.#framed;
|
|
115
|
+
const retired = this.#retired;
|
|
116
|
+
this.#framed = undefined;
|
|
117
|
+
let after;
|
|
118
|
+
try {
|
|
119
|
+
after = this.value;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// Still failed since the last call: nothing new for the watches.
|
|
123
|
+
if (before !== NO_VALUE)
|
|
124
|
+
this.failWatches(error, context);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.#retired = false;
|
|
128
|
+
let ops = NO_OPS;
|
|
129
|
+
if (after !== before) {
|
|
130
|
+
this.batch.count("chord.derive.diffs");
|
|
131
|
+
ops = before === NO_VALUE ? [["r", after]] : diffRevisions(before, after);
|
|
132
|
+
}
|
|
133
|
+
if (ops.length > 0 || retired)
|
|
134
|
+
this.publish(after, ops, retired, context);
|
|
135
|
+
}
|
|
136
|
+
#recompute() {
|
|
137
|
+
return this.batch.compute(() => {
|
|
138
|
+
try {
|
|
139
|
+
this.batch.count("chord.derive.computes");
|
|
140
|
+
// A failing source throws its own error here, so a derive over a failed derive fails with the same error.
|
|
141
|
+
const values = this.#sources.map((source) => source.value);
|
|
142
|
+
let value;
|
|
143
|
+
try {
|
|
144
|
+
value = this.#compute(values);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (!this.#failing)
|
|
148
|
+
this.#report?.(handedOut(error));
|
|
149
|
+
this.#failing = true;
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
this.#failing = false;
|
|
153
|
+
this.#state = { kind: "clean", value };
|
|
154
|
+
this.#good = value;
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this.#state = { kind: "failed", error };
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Maps an array calling `f` only for object elements not seen before (by identity), returning the previous result for
|
|
166
|
+
* the others; primitive elements are mapped every time. The cache is weak: dropped elements take their results along.
|
|
167
|
+
*/
|
|
168
|
+
export function mapShared(f) {
|
|
169
|
+
const results = new WeakMap();
|
|
170
|
+
return (elements) => elements.map((element) => {
|
|
171
|
+
// The decided rule: identity caching for objects only.
|
|
172
|
+
if (typeof element !== "object" || element === null)
|
|
173
|
+
return f(element);
|
|
174
|
+
let result = results.get(element);
|
|
175
|
+
if (result === undefined) {
|
|
176
|
+
result = f(element);
|
|
177
|
+
results.set(element, result);
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=derive.js.map
|