@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,537 @@
|
|
|
1
|
+
// A hold arriving on a link and served here (§7, §22, W1): where it goes once the host published (waiting in the
|
|
2
|
+
// unbound index until then), why it is unbound (refused: kept in the index while it waits for a name, dependency
|
|
3
|
+
// model §1), the object it keeps, the notices of its object's failures and new attempts, the snapshot and subscription
|
|
4
|
+
// taken in one synchronous step when a slot of the window is free, and the ops of its members per batch (sent at
|
|
5
|
+
// once, or pending while the window is full), each member with its own Delta encoder. Across a reload (slice 7b §6) a
|
|
6
|
+
// bound hold is kept: a swap in place sends it a fresh `bound` once the new instance is live (it answers calls
|
|
7
|
+
// meanwhile), an object leaving `live` unbinds it (`loading` or `failed`, then a fresh `bound`), a version no longer
|
|
8
|
+
// bound or a removed type leaves it waiting unbound. A hold of an older version follows its object's adapted members
|
|
9
|
+
// (Q10).
|
|
10
|
+
import { encoder, PendingOps } from "../../delta/index.js";
|
|
11
|
+
import { variantNames, variantOrder, variantsAt } from "../contracts/internal.js";
|
|
12
|
+
import { ChordError, isChordError } from "../data/index.js";
|
|
13
|
+
import { asChordError } from "../data/internal.js";
|
|
14
|
+
import { retryWalk, } from "../host/internal.js";
|
|
15
|
+
import { jsonPart, NO_RETIRED, oversized, parsePart, wireError, } from "../link/internal.js";
|
|
16
|
+
import { Source } from "../state/internal.js";
|
|
17
|
+
import { RelayedHold } from "./relay.js";
|
|
18
|
+
const PENDING = { kind: "pending", toldFailed: false };
|
|
19
|
+
const BINDING = { kind: "binding" };
|
|
20
|
+
/**
|
|
21
|
+
* One hold served here: a reference to its object acting as its caller (the hold's principal). While pending, each
|
|
22
|
+
* failure of its object is sent as `failed` (with the rest of its backoff window) and the next attempt as `loading`; a
|
|
23
|
+
* hold that cannot be taken holds nothing: `failed { waiting }` (not served, another version) until a publication
|
|
24
|
+
* re-runs its start, `failed { broken }` (invalid params, a cycle) until a `retry` does. Once live it binds when its
|
|
25
|
+
* link's window has a slot, then sends a part per batch that changed its members (or keeps their ops pending while the
|
|
26
|
+
* window is full), and `gone` when its object ends. It counts as one of the host's references from its arrival to its
|
|
27
|
+
* end, bound or not.
|
|
28
|
+
*/
|
|
29
|
+
export class Hold {
|
|
30
|
+
kind = "served";
|
|
31
|
+
id;
|
|
32
|
+
/** A hold is declared by no object on this host. */
|
|
33
|
+
dependent = undefined;
|
|
34
|
+
/** Whom the hold acts for: its calls run as it, with its origin's incarnation. */
|
|
35
|
+
caller;
|
|
36
|
+
/** The limits per part of its params and its calls' arguments: its link's, the decoded one smaller when stamped (Q2). */
|
|
37
|
+
limits;
|
|
38
|
+
#provider;
|
|
39
|
+
#state = PENDING;
|
|
40
|
+
/** What it asks for (its params owned), once it started: it is placed again after a reload left it unbound. */
|
|
41
|
+
#request;
|
|
42
|
+
/** The held object, from its binding until the hold is released. */
|
|
43
|
+
#object;
|
|
44
|
+
/** The members the current batch changed, with their ops, in order. */
|
|
45
|
+
#changes = [];
|
|
46
|
+
/** The members that failed since the last message that carried this hold. */
|
|
47
|
+
#failed = [];
|
|
48
|
+
/** The members whose document was retired since the last message that carried this hold (ORed while it waits). */
|
|
49
|
+
#retired = NO_RETIRED;
|
|
50
|
+
#touched = false;
|
|
51
|
+
/** Whether the hold counts as one of the host's references (`host.activity`): from its arrival until it ends. */
|
|
52
|
+
#counted = true;
|
|
53
|
+
constructor(id, provider, caller, limits) {
|
|
54
|
+
this.id = id;
|
|
55
|
+
this.#provider = provider;
|
|
56
|
+
this.caller = caller;
|
|
57
|
+
this.limits = limits;
|
|
58
|
+
provider.link.host.count("references", 1);
|
|
59
|
+
}
|
|
60
|
+
/** Whether the hold is bound: its members' changes are sent. */
|
|
61
|
+
get bound() {
|
|
62
|
+
return this.#state.kind === "bound";
|
|
63
|
+
}
|
|
64
|
+
/** Whether calls on it reach its object: bound, or binding afresh after a swap in place (its `bound` not sent yet). */
|
|
65
|
+
get callable() {
|
|
66
|
+
const state = this.#state;
|
|
67
|
+
return state.kind === "bound" || (state.kind === "binding" && state.previous !== undefined);
|
|
68
|
+
}
|
|
69
|
+
/** Whom it acts for (the unbound index's revocation). */
|
|
70
|
+
get principal() {
|
|
71
|
+
return this.caller.principal;
|
|
72
|
+
}
|
|
73
|
+
/** Its consumer's contract version and fingerprint (its request's): the provider binds them or it waits. */
|
|
74
|
+
get contract() {
|
|
75
|
+
return this.#request;
|
|
76
|
+
}
|
|
77
|
+
/** Whether the hold holds no object: before the publication, or refused (revocation ends it, §4). */
|
|
78
|
+
get unbound() {
|
|
79
|
+
return this.#object === undefined && this.#state.kind !== "released";
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Admits the hold: before the host's publication it waits in the unbound index, placed by the publication.
|
|
83
|
+
* Then its params within the link's part limit (`too_large/part`), then relayed (it is replaced by a relayed hold),
|
|
84
|
+
* or served here, its params opened and parsed (a malformed part is a protocol error), its object taken and followed
|
|
85
|
+
* (`moved`) in the turn it arrived. A hold that cannot be served here waits refused (`#refuse`).
|
|
86
|
+
*/
|
|
87
|
+
start(request) {
|
|
88
|
+
const { link } = this.#provider;
|
|
89
|
+
if (!link.host.published) {
|
|
90
|
+
this.#state = { kind: "unplaced", request: owned(request) };
|
|
91
|
+
link.host.index(request.type, this);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
let served;
|
|
95
|
+
try {
|
|
96
|
+
const oversize = oversized(request.params, link.limits.part);
|
|
97
|
+
if (oversize !== undefined)
|
|
98
|
+
throw oversize;
|
|
99
|
+
const placed = link.host.place(request, link, this.caller, link.context);
|
|
100
|
+
if (placed.kind === "path") {
|
|
101
|
+
// Counted where it is served: a relayed hold is not this host's reference.
|
|
102
|
+
this.drop();
|
|
103
|
+
new RelayedHold(this.id, this.#provider, request, this.caller, placed.path).start();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let params;
|
|
107
|
+
try {
|
|
108
|
+
params = parsePart(link.openPart(request.params, this.limits, link.context));
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// Past its limits: the hold's \`too_large/part\`. No JSON: a protocol error, reported, and the link closes.
|
|
112
|
+
if (isChordError(error, "too_large"))
|
|
113
|
+
throw error;
|
|
114
|
+
link.host.report({ kind: "protocol_error", error });
|
|
115
|
+
link.close();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
served = link.host.serving(request, params, this.caller.principal, link.context);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
this.#refuse(request, { kind: "broken", error: asChordError(error, request.type) });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (served.kind === "waiting") {
|
|
125
|
+
this.#refuse(request, served.cause);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.#request = owned(request);
|
|
129
|
+
const { object } = served;
|
|
130
|
+
this.#object = object;
|
|
131
|
+
object.hold(this);
|
|
132
|
+
this.moved();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Woken by the unbound index (out of it already): before the publication, placed now; refused `waiting`, its start
|
|
136
|
+
* runs again, announced with `loading` (then `bound` or `failed`).
|
|
137
|
+
*/
|
|
138
|
+
wake() {
|
|
139
|
+
const state = this.#state;
|
|
140
|
+
if (state.kind === "unplaced") {
|
|
141
|
+
this.#state = PENDING;
|
|
142
|
+
this.start(state.request);
|
|
143
|
+
}
|
|
144
|
+
else if (state.kind === "refused") {
|
|
145
|
+
this.#restart(state.request);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The object's state changed, or the hold took it: a pending hold binds once it is live (when a slot is free),
|
|
150
|
+
* sends each failure, and announces the attempt after a failure with `loading`. A bound hold (or one whose `bound`
|
|
151
|
+
* waits for a slot) whose object leaves `live` goes back to pending (slice 7b §6), except while a reload's swap runs
|
|
152
|
+
* in place; a bound one whose object went live with another attempt (a swap) gets a fresh `bound` (audit A9).
|
|
153
|
+
*/
|
|
154
|
+
moved() {
|
|
155
|
+
const current = this.#state;
|
|
156
|
+
const object = this.#object;
|
|
157
|
+
if (object === undefined)
|
|
158
|
+
return;
|
|
159
|
+
if (current.kind === "bound" || current.kind === "binding") {
|
|
160
|
+
const { kind } = object.state;
|
|
161
|
+
if (kind === "live") {
|
|
162
|
+
if (current.kind === "bound" && object.instance !== current.instance)
|
|
163
|
+
this.#rebind(current);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Its instance still changes (a swap's old one, a restart's drain, a live failure's admitted commits): it follows
|
|
167
|
+
// it on until it stopped (slice 7b, decision "References are the only indirection").
|
|
168
|
+
if (current.kind === "bound" && object.attachable === current.instance)
|
|
169
|
+
return;
|
|
170
|
+
if (current.kind === "binding" && kind === "loading" && object.swapsInPlace)
|
|
171
|
+
return;
|
|
172
|
+
this.#unbind(object.state.kind === "failed" ? object.state.cause.error : undefined);
|
|
173
|
+
}
|
|
174
|
+
this.#pending(object);
|
|
175
|
+
}
|
|
176
|
+
/** Member `followed` failed with `error`: its failure waits to be sent, replacing one still waiting. */
|
|
177
|
+
#memberFailed(followed, error) {
|
|
178
|
+
followed.pending.take();
|
|
179
|
+
const failure = { member: followed.index, error: wireError(error) };
|
|
180
|
+
const at = this.#failed.findIndex(({ member }) => member === followed.index);
|
|
181
|
+
// A new list when one is replaced (rare): a list handed to an entry is never written to.
|
|
182
|
+
if (at === -1)
|
|
183
|
+
this.#failed.push(failure);
|
|
184
|
+
else
|
|
185
|
+
this.#failed = this.#failed.map((pending, i) => (i === at ? failure : pending));
|
|
186
|
+
}
|
|
187
|
+
/** Member `index` has a value again: a failure of it still waiting to be sent (rare) is not sent. */
|
|
188
|
+
#memberHealed(index) {
|
|
189
|
+
if (this.#failed.length > 0)
|
|
190
|
+
this.#failed = this.#failed.filter(({ member }) => member !== index);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Its object left `live` (a restart, a parked swap, a live failure): no longer subscribed or waiting for a slot, its
|
|
194
|
+
* calls in flight rejected (`error`, or `unavailable`), pending again; a `loading` tells the consumer it rebinds
|
|
195
|
+
* (a failure is sent by `#pending`, which a consumer applies to a bound hold as a rebinding too, model §5).
|
|
196
|
+
*/
|
|
197
|
+
#unbind(error) {
|
|
198
|
+
const state = this.#state;
|
|
199
|
+
if (state.kind === "bound")
|
|
200
|
+
unfollow(state);
|
|
201
|
+
this.#changes = [];
|
|
202
|
+
this.#failed = [];
|
|
203
|
+
this.#retired = NO_RETIRED;
|
|
204
|
+
this.#touched = false;
|
|
205
|
+
const reason = error ?? new ChordError({ code: "unavailable", message: `hold ${this.id}: its object rebinds` });
|
|
206
|
+
this.#provider.unbound(this, reason);
|
|
207
|
+
this.#state = PENDING;
|
|
208
|
+
if (error === undefined)
|
|
209
|
+
this.#provider.send({ kind: "loading", hold: this.id });
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A swap of its object went live in place (slice 7b §5, audit A9): no longer subscribed to the old instance, it gets
|
|
213
|
+
* a fresh `bound` of the new one's members (as a restart, a variant or a version change does), answering calls by
|
|
214
|
+
* its old names until that is sent.
|
|
215
|
+
*/
|
|
216
|
+
#rebind(state) {
|
|
217
|
+
unfollow(state);
|
|
218
|
+
// Its ops still waiting for a slot are the old instance's: the `bound` replaces them.
|
|
219
|
+
this.#provider.unbind(this);
|
|
220
|
+
this.#state = { kind: "binding", previous: { variant: state.variant, names: state.names } };
|
|
221
|
+
this.#provider.bind(this, this.#provider.link.context);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* A `retry` message with `hops` left of its budget: the object is asked for an attempt now (it ignores this unless
|
|
225
|
+
* failed; parked, it passes it on, to other hosts with one hop less); a refused hold is started again (a route's
|
|
226
|
+
* `authorize` may admit it now).
|
|
227
|
+
*/
|
|
228
|
+
retry({ hops }) {
|
|
229
|
+
const state = this.#state;
|
|
230
|
+
if (state.kind !== "refused") {
|
|
231
|
+
this.#object?.retry(retryWalk(hops - 1));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (state.cause.kind === "waiting")
|
|
235
|
+
this.#provider.link.host.unindex(state.request.type, this);
|
|
236
|
+
this.#restart(state.request);
|
|
237
|
+
}
|
|
238
|
+
/** The pending hold's part of `moved`: binds once live, sends each failure, announces the next attempt. */
|
|
239
|
+
#pending(object) {
|
|
240
|
+
const current = this.#state;
|
|
241
|
+
if (current.kind !== "pending")
|
|
242
|
+
return;
|
|
243
|
+
const state = object.state;
|
|
244
|
+
if (state.kind === "live") {
|
|
245
|
+
this.#state = BINDING;
|
|
246
|
+
this.#provider.bind(this, this.#provider.link.context);
|
|
247
|
+
}
|
|
248
|
+
else if (state.kind === "failed") {
|
|
249
|
+
// Each failure and each new cause (a parked object's blocker changed) is a message of its own.
|
|
250
|
+
const { cause, retryAt } = state;
|
|
251
|
+
const retryIn = retryAt === undefined ? {} : { retryIn: Math.max(0, retryAt - Date.now()) };
|
|
252
|
+
const failed = { kind: cause.kind, error: wireError(cause.error) };
|
|
253
|
+
this.#provider.send({ kind: "failed", hold: this.id, cause: failed, ...retryIn });
|
|
254
|
+
this.#state = { kind: "pending", toldFailed: true };
|
|
255
|
+
}
|
|
256
|
+
else if (state.kind === "loading" && current.toldFailed) {
|
|
257
|
+
this.#provider.send({ kind: "loading", hold: this.id });
|
|
258
|
+
this.#state = PENDING;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/** Starts a refused hold again, announced with `loading`. */
|
|
262
|
+
#restart(request) {
|
|
263
|
+
this.#state = PENDING;
|
|
264
|
+
this.#provider.send({ kind: "loading", hold: this.id });
|
|
265
|
+
this.start(request);
|
|
266
|
+
}
|
|
267
|
+
/** Calls a method of the held object as the hold's caller. */
|
|
268
|
+
call(method, args, context) {
|
|
269
|
+
return this.#object.call(method, args, context, this.caller, this.contract.version);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The method at `index` of the bound variant and whether its result carries byte segments (its schema has a
|
|
273
|
+
* `bytes()` leaf). Throws on an index outside the variant (a protocol error); a hold that is not bound has none.
|
|
274
|
+
*/
|
|
275
|
+
method(index) {
|
|
276
|
+
const state = this.#state;
|
|
277
|
+
// Binding afresh after a swap: by the names the consumer still has (the new instance answers by name).
|
|
278
|
+
const bound = state.kind === "bound" ? state : state.kind === "binding" ? state.previous : undefined;
|
|
279
|
+
const name = bound?.names.methods[index];
|
|
280
|
+
if (name === undefined)
|
|
281
|
+
throw new Error(`hold ${this.id}: no method ${index}`);
|
|
282
|
+
return { name, resultBytes: bound.variant.methods.get(name).result.bytes };
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The hold's binding, sent when a slot is free. The snapshot of every member, as a value or failed, and the
|
|
286
|
+
* subscription are taken in this synchronous step (race 2), so each member's next ops continue exactly from it.
|
|
287
|
+
* Names travel as indexes into the bound version (2b). Counts one encode (`chord.link.encodes`).
|
|
288
|
+
*/
|
|
289
|
+
boundEntry(context) {
|
|
290
|
+
const object = this.#object;
|
|
291
|
+
const { contract } = object.served;
|
|
292
|
+
// A live remote object has its variant.
|
|
293
|
+
const variant = object.variant;
|
|
294
|
+
const state = this.#bindTo(object);
|
|
295
|
+
const members = [];
|
|
296
|
+
const failed = [];
|
|
297
|
+
const { version } = this.contract;
|
|
298
|
+
const current = version === contract.version;
|
|
299
|
+
for (const [index, member] of state.names.state.entries()) {
|
|
300
|
+
// An older version's members are its instance's mapping (its refusals unbound it before: `ChordObject`).
|
|
301
|
+
const source = current ? object.stateMembers.get(member) : object.liveMember(member, version);
|
|
302
|
+
let value;
|
|
303
|
+
try {
|
|
304
|
+
value = source.value;
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
// A failed member (a derive whose compute throws) is followed: it recovers with a root replacement.
|
|
308
|
+
failed.push({ member: index, error: wireError(error) });
|
|
309
|
+
if (source instanceof Source)
|
|
310
|
+
this.#follow(state, index, source);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
members.push({ member: index, value: this.#provider.link.part(jsonPart(value), context) });
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
// A value past the link's limits: failed for this hold, which takes no more of it.
|
|
318
|
+
failed.push({ member: index, error: wireError(error) });
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
// A constant never changes: nothing to follow.
|
|
322
|
+
if (source instanceof Source)
|
|
323
|
+
this.#follow(state, index, source);
|
|
324
|
+
}
|
|
325
|
+
this.#changes = [];
|
|
326
|
+
this.#failed = [];
|
|
327
|
+
this.#retired = NO_RETIRED;
|
|
328
|
+
context.telemetry.metrics?.counter("chord.link.encodes").add(1);
|
|
329
|
+
return { hold: this.id, variant: variantOrder(contract).indexOf(variant), members, failed };
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* This batch's entry of the `state` message: the members it changed with their ops, each encoded once with its
|
|
333
|
+
* member's encoder, and the members that failed; resets both. Counts one encode per hold (`chord.link.encodes`).
|
|
334
|
+
*/
|
|
335
|
+
entry(context) {
|
|
336
|
+
const { link } = this.#provider;
|
|
337
|
+
const members = this.#take().map(([{ index, encoder }, ops]) => ({
|
|
338
|
+
member: index,
|
|
339
|
+
ops: link.part(jsonPart(encoder.encode(ops)), context),
|
|
340
|
+
}));
|
|
341
|
+
return this.#entry(members, context);
|
|
342
|
+
}
|
|
343
|
+
/** The window is full: this batch's ops join the members' pending queues (raw, never mutated). */
|
|
344
|
+
queue() {
|
|
345
|
+
for (const [{ pending }, ops] of this.#take())
|
|
346
|
+
pending.push(ops);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* The entry of a freed slot's `state` message: each member's pending ops encoded once, or `[["r", value]]` after an
|
|
350
|
+
* overflow, all reflecting the latest commit; and the members that failed meanwhile. Counts one encode per hold.
|
|
351
|
+
*/
|
|
352
|
+
pendingEntry(context) {
|
|
353
|
+
const { link } = this.#provider;
|
|
354
|
+
const members = [];
|
|
355
|
+
// Only a bound hold has pending ops.
|
|
356
|
+
for (const { index, source, encoder, pending } of this.#state.followed) {
|
|
357
|
+
if (pending.size === 0)
|
|
358
|
+
continue;
|
|
359
|
+
const taken = pending.take();
|
|
360
|
+
const ops = taken.kind === "replace" ? [["r", source.value]] : taken.ops;
|
|
361
|
+
if (ops.length > 0)
|
|
362
|
+
members.push({ member: index, ops: link.part(jsonPart(encoder.encode(ops)), context) });
|
|
363
|
+
}
|
|
364
|
+
return this.#entry(members, context);
|
|
365
|
+
}
|
|
366
|
+
/** The consumer released the hold, or its link closed: its waits stop and its object loses this reference. */
|
|
367
|
+
release() {
|
|
368
|
+
this.drop();
|
|
369
|
+
this.#object?.unhold(this);
|
|
370
|
+
this.#object = undefined;
|
|
371
|
+
}
|
|
372
|
+
/** Ends the hold without releasing its object (the host closes and ends its objects itself). */
|
|
373
|
+
drop() {
|
|
374
|
+
const state = this.#state;
|
|
375
|
+
const { host } = this.#provider.link;
|
|
376
|
+
if (state.kind === "bound") {
|
|
377
|
+
unfollow(state);
|
|
378
|
+
}
|
|
379
|
+
else if (state.kind === "unplaced" || (state.kind === "refused" && state.cause.kind === "waiting")) {
|
|
380
|
+
host.unindex(state.request.type, this);
|
|
381
|
+
}
|
|
382
|
+
this.#state = { kind: "released" };
|
|
383
|
+
if (this.#counted)
|
|
384
|
+
host.count("references", -1);
|
|
385
|
+
this.#counted = false;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The object ended while held (revocation; a reload, slice 7b), or the hold was revoked (or its host closed) while it
|
|
389
|
+
* held no object: the hold sends `gone` with `error`.
|
|
390
|
+
*/
|
|
391
|
+
end(error) {
|
|
392
|
+
if (this.#state.kind === "released")
|
|
393
|
+
return;
|
|
394
|
+
this.#provider.forget(this, error);
|
|
395
|
+
this.drop();
|
|
396
|
+
this.#object = undefined;
|
|
397
|
+
this.#provider.send({ kind: "gone", hold: this.id, error: wireError(error) });
|
|
398
|
+
}
|
|
399
|
+
/** The binding: its variant and names at the hold's version, with no member followed yet. */
|
|
400
|
+
#bindTo(object) {
|
|
401
|
+
const variant = variantsAt(object.served.contract, this.contract.version).get(object.variant);
|
|
402
|
+
const state = {
|
|
403
|
+
kind: "bound",
|
|
404
|
+
variant,
|
|
405
|
+
names: variantNames(variant),
|
|
406
|
+
followed: [],
|
|
407
|
+
instance: object.instance,
|
|
408
|
+
};
|
|
409
|
+
this.#state = state;
|
|
410
|
+
return state;
|
|
411
|
+
}
|
|
412
|
+
/** A hold over a link follows its object's instances in `moved` (a fresh `bound` for a new one). */
|
|
413
|
+
retarget() { }
|
|
414
|
+
/** It moves nothing in `retarget`. */
|
|
415
|
+
following = false;
|
|
416
|
+
/**
|
|
417
|
+
* Its object left it (slice 7b §6): its type was removed (`not_served`) or its provider no longer binds the hold's
|
|
418
|
+
* version (`version`): no longer subscribed, its calls in flight rejected, it waits refused with `removal.cause` in
|
|
419
|
+
* the host's index (a publication starts it again) and the consumer is sent `failed`, which unbinds a bound hold.
|
|
420
|
+
*/
|
|
421
|
+
removed(removal) {
|
|
422
|
+
const state = this.#state;
|
|
423
|
+
if (state.kind === "released" || this.#object === undefined)
|
|
424
|
+
return;
|
|
425
|
+
if (state.kind === "bound")
|
|
426
|
+
unfollow(state);
|
|
427
|
+
this.#changes = [];
|
|
428
|
+
this.#failed = [];
|
|
429
|
+
this.#retired = NO_RETIRED;
|
|
430
|
+
this.#touched = false;
|
|
431
|
+
this.#provider.unbound(this, removal.cause.error);
|
|
432
|
+
this.#object = undefined;
|
|
433
|
+
this.#refuse(this.contract, removal.cause);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Follows member `index` from its snapshot on (a failed one too: it may recover in this hold): its own encoder and
|
|
437
|
+
* pending queue, and a subscription feeding its calls into this hold's batch. Failures fold per member: a failure
|
|
438
|
+
* drops what was pending for it and replaces a failure not sent yet (one at most per member, however long the
|
|
439
|
+
* consumer stalls); the value after it (a root replacement) replaces the failure. A retirement waits for a value.
|
|
440
|
+
*/
|
|
441
|
+
#follow(state, index, source) {
|
|
442
|
+
const followed = {
|
|
443
|
+
index,
|
|
444
|
+
source,
|
|
445
|
+
subscriber: {
|
|
446
|
+
advance: (call) => {
|
|
447
|
+
this.#touch();
|
|
448
|
+
if (call.kind === "failed") {
|
|
449
|
+
this.#memberFailed(followed, call.error);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this.#memberHealed(index);
|
|
453
|
+
const { ops, retired } = call;
|
|
454
|
+
// A retired derive's frame may carry no ops (rule 21): only the flag travels.
|
|
455
|
+
if (ops.length > 0)
|
|
456
|
+
this.#changes.push([followed, ops]);
|
|
457
|
+
// A new list per retirement (rare): the shared empty one is never written to.
|
|
458
|
+
if (retired && !this.#retired.includes(index))
|
|
459
|
+
this.#retired = [...this.#retired, index];
|
|
460
|
+
},
|
|
461
|
+
// The member's source ended with its object, which ends this hold.
|
|
462
|
+
end: () => { },
|
|
463
|
+
endAfterDelivery: () => { },
|
|
464
|
+
},
|
|
465
|
+
encoder: encoder(),
|
|
466
|
+
pending: new PendingOps(),
|
|
467
|
+
};
|
|
468
|
+
// A constant never changes: nothing to subscribe to.
|
|
469
|
+
if (source instanceof Source)
|
|
470
|
+
source.subscribe(followed.subscriber);
|
|
471
|
+
state.followed.push(followed);
|
|
472
|
+
}
|
|
473
|
+
/** Takes the current batch's changes; the hold is untouched again. */
|
|
474
|
+
#take() {
|
|
475
|
+
const changes = this.#changes;
|
|
476
|
+
this.#changes = [];
|
|
477
|
+
this.#touched = false;
|
|
478
|
+
return changes;
|
|
479
|
+
}
|
|
480
|
+
/** A state entry with `members` and the failures and retirements since the last one; counts one encode. */
|
|
481
|
+
#entry(members, context) {
|
|
482
|
+
const failed = this.#failed;
|
|
483
|
+
let retired = this.#retired;
|
|
484
|
+
this.#failed = [];
|
|
485
|
+
this.#retired = NO_RETIRED;
|
|
486
|
+
if (retired.length > 0 && failed.length > 0) {
|
|
487
|
+
// A failed member's retirement travels with its next value, never with its failure.
|
|
488
|
+
const kept = retired.filter((index) => failed.some(({ member }) => member === index));
|
|
489
|
+
if (kept.length > 0) {
|
|
490
|
+
this.#retired = kept;
|
|
491
|
+
retired = retired.filter((index) => !kept.includes(index));
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
context.telemetry.metrics?.counter("chord.link.encodes").add(1);
|
|
495
|
+
return { hold: this.id, members, failed, retired };
|
|
496
|
+
}
|
|
497
|
+
#touch() {
|
|
498
|
+
if (this.#touched)
|
|
499
|
+
return;
|
|
500
|
+
this.#touched = true;
|
|
501
|
+
this.#provider.touched(this);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Refuses the hold with `cause`, holding nothing: it keeps `request`, indexed under its type while `waiting` (a
|
|
505
|
+
* publication starts it again), for a `retry` otherwise.
|
|
506
|
+
*/
|
|
507
|
+
#refuse(request, cause) {
|
|
508
|
+
this.#state = { kind: "refused", request: owned(request), cause };
|
|
509
|
+
if (cause.kind === "waiting")
|
|
510
|
+
this.#provider.link.host.index(request.type, this);
|
|
511
|
+
this.#provider.send({
|
|
512
|
+
kind: "failed",
|
|
513
|
+
hold: this.id,
|
|
514
|
+
cause: { kind: cause.kind, error: wireError(cause.error) },
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
/** Stops following every member of a bound hold. */
|
|
519
|
+
function unfollow(state) {
|
|
520
|
+
for (const { source, subscriber } of state.followed)
|
|
521
|
+
if (source instanceof Source)
|
|
522
|
+
source.unsubscribe(subscriber);
|
|
523
|
+
}
|
|
524
|
+
/** `request` with its params owned, not a view of the message they came in (which the link's buffers may hold). */
|
|
525
|
+
function owned(request) {
|
|
526
|
+
const { params } = request;
|
|
527
|
+
return typeof params === "string" ? request : { ...request, params: params.slice() };
|
|
528
|
+
}
|
|
529
|
+
const NOBODY = {};
|
|
530
|
+
/**
|
|
531
|
+
* The fields of a `hold` message naming whom it acts for (`caller`): sent only on a route link, whose child honours
|
|
532
|
+
* them (§4); none elsewhere.
|
|
533
|
+
*/
|
|
534
|
+
export function actingFor(link, { principal, incarnation }) {
|
|
535
|
+
return link.role === "route" && principal !== undefined ? { principal, incarnation } : NOBODY;
|
|
536
|
+
}
|
|
537
|
+
//# sourceMappingURL=hold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hold.js","sourceRoot":"","sources":["../../../src/next/remote/hold.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,iHAAiH;AACjH,uHAAuH;AACvH,iHAAiH;AACjH,sHAAsH;AACtH,+GAA+G;AAC/G,qHAAqH;AACrH,qHAAqH;AACrH,SAAS;AAGT,OAAO,EAAgB,OAAO,EAAW,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElF,OAAO,EAAuC,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACvH,OAAO,EAAE,UAAU,EAAqB,YAAY,EAAkB,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAKN,SAAS,GAGT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGN,QAAQ,EAGR,UAAU,EACV,SAAS,EACT,SAAS,EAET,SAAS,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAqB,MAAM,EAAmB,MAAM,sBAAsB,CAAC;AAGlF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA8DzC,MAAM,OAAO,GAAc,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AAElE,MAAM,OAAO,GAAc,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,OAAO,IAAI;IACP,IAAI,GAAG,QAAQ,CAAC;IAChB,EAAE,CAAS;IACpB,oDAAoD;IAC3C,SAAS,GAAG,SAAS,CAAC;IAC/B,kFAAkF;IACzE,MAAM,CAAS;IACxB,yHAAyH;IAChH,MAAM,CAAS;IACf,SAAS,C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OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAG,MAAqB,CAAC,KAAK,EAAE,EAAE,CAAC;AACtG,CAAC;AAKD,MAAM,MAAM,GAAc,EAAE,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,EAAE,SAAS,EAAE,WAAW,EAAU;IAC3E,OAAO,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC/F,CAAC","sourcesContent":["// A hold arriving on a link and served here (§7, §22, W1): where it goes once the host published (waiting in the\n// unbound index until then), why it is unbound (refused: kept in the index while it waits for a name, dependency\n// model §1), the object it keeps, the notices of its object's failures and new attempts, the snapshot and subscription\n// taken in one synchronous step when a slot of the window is free, and the ops of its members per batch (sent at\n// once, or pending while the window is full), each member with its own Delta encoder. Across a reload (slice 7b §6) a\n// bound hold is kept: a swap in place sends it a fresh `bound` once the new instance is live (it answers calls\n// meanwhile), an object leaving `live` unbinds it (`loading` or `failed`, then a fresh `bound`), a version no longer\n// bound or a removed type leaves it waiting unbound. A hold of an older version follows its object's adapted members\n// (Q10).\n\nimport type { Context } from \"../../context/index.ts\";\nimport { type Encoder, encoder, type Op, PendingOps } from \"../../delta/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport { type VariantData, type VariantNames, variantNames, variantOrder, variantsAt } from \"../contracts/internal.ts\";\nimport { ChordError, type FailureCause, isChordError, type Principal } from \"../data/index.ts\";\nimport { asChordError } from \"../data/internal.ts\";\nimport {\n\ttype Caller,\n\ttype ChordObject,\n\ttype Holder,\n\ttype Removal,\n\tretryWalk,\n\ttype Serving,\n\ttype UnboundRequest,\n} from \"../host/internal.ts\";\nimport {\n\ttype BoundEntry,\n\ttype FailedMember,\n\tjsonPart,\n\ttype Limits,\n\ttype Message,\n\tNO_RETIRED,\n\toversized,\n\tparsePart,\n\ttype StateEntry,\n\twireError,\n} from \"../link/internal.ts\";\nimport { type DeriveSource, Source, type Subscriber } from \"../state/internal.ts\";\nimport type { HostLink } from \"./host-link.ts\";\nimport type { ProviderSide } from \"./provider.ts\";\nimport { RelayedHold } from \"./relay.ts\";\n\n/** A `hold` message. */\ntype HoldMessage = Extract<Message, { readonly kind: \"hold\" }>;\n\n/**\n * What a `hold` message asks for. Whom it acts for is not part of it: a host takes that from the message once, as its\n * link allows (`ProviderSide`), and names it again only on a route link (`actingFor`). Its `chain` and `limit` are the\n * ones this host honours, sent on as they are when it relays the hold.\n */\nexport type HoldRequest = Omit<HoldMessage, \"kind\" | \"origin\" | \"hold\" | \"principal\" | \"incarnation\">;\n\n/**\n * A state member a bound hold follows: its index in the bound version, its source and subscription (which feeds this\n * record), its own encoder (R1, path interning) and the ops waiting for a slot of the window.\n */\ntype Followed = {\n\treadonly index: number;\n\t/** Its source (subscribed when it changes, a constant's never). */\n\treadonly source: DeriveSource;\n\treadonly subscriber: Subscriber;\n\treadonly encoder: Encoder;\n\treadonly pending: PendingOps;\n};\n\n/**\n * Where a hold stands: `unplaced` in the unbound index until the host's publication places it; `pending` until its\n * object is live (the activation, parking and retries; `toldFailed` once the consumer was told of a failure, so the\n * next attempt is announced with `loading`); `binding` while its object is live and its `bound` waits for a slot\n * (after a swap in place with the names it was bound with, `previous`: the consumer still holds it bound, so its calls\n * are answered by those names, design §22; only contract data, so the old instance and its sources go meanwhile);\n * `bound` with the object's variant and the members it follows.\n */\ntype HoldState =\n\t| { readonly kind: \"unplaced\"; readonly request: HoldRequest }\n\t| { readonly kind: \"pending\"; readonly toldFailed: boolean }\n\t| { readonly kind: \"binding\"; readonly previous?: BoundNames }\n\t| {\n\t\t\treadonly kind: \"bound\";\n\t\t\t/** The bound variant's data at the hold's version. */\n\t\t\treadonly variant: VariantData;\n\t\t\t/** The bound version's names of the variant, which the wire's indexes point into. */\n\t\t\treadonly names: VariantNames;\n\t\t\t/** The members it follows, in the order they were subscribed. */\n\t\t\treadonly followed: Followed[];\n\t\t\t/** The instance it was bound to: a swap brings another, which it binds to afresh. */\n\t\t\treadonly instance: unknown;\n\t }\n\t/**\n\t * Refused where it arrived, with `cause`: `waiting` (not served here, another version, placed elsewhere by the\n\t * provider's code) in the unbound index until a publication wakes it; `broken` (invalid params, a cycle, a route that\n\t * refused, a part past the limits) until a `retry` restarts it.\n\t */\n\t| { readonly kind: \"refused\"; readonly request: HoldRequest; readonly cause: FailureCause }\n\t| { readonly kind: \"released\" };\n\n/** A bound hold's state. */\ntype Bound = Extract<HoldState, { readonly kind: \"bound\" }>;\n\n/** What calls need of a binding: its variant's data at the hold's version and the names the wire's indexes point into. */\ntype BoundNames = { readonly variant: VariantData; readonly names: VariantNames };\n\nconst PENDING: HoldState = { kind: \"pending\", toldFailed: false };\n\nconst BINDING: HoldState = { kind: \"binding\" };\n\n/**\n * One hold served here: a reference to its object acting as its caller (the hold's principal). While pending, each\n * failure of its object is sent as `failed` (with the rest of its backoff window) and the next attempt as `loading`; a\n * hold that cannot be taken holds nothing: `failed { waiting }` (not served, another version) until a publication\n * re-runs its start, `failed { broken }` (invalid params, a cycle) until a `retry` does. Once live it binds when its\n * link's window has a slot, then sends a part per batch that changed its members (or keeps their ops pending while the\n * window is full), and `gone` when its object ends. It counts as one of the host's references from its arrival to its\n * end, bound or not.\n */\nexport class Hold implements Holder, UnboundRequest {\n\treadonly kind = \"served\";\n\treadonly id: number;\n\t/** A hold is declared by no object on this host. */\n\treadonly dependent = undefined;\n\t/** Whom the hold acts for: its calls run as it, with its origin's incarnation. */\n\treadonly caller: Caller;\n\t/** The limits per part of its params and its calls' arguments: its link's, the decoded one smaller when stamped (Q2). */\n\treadonly limits: Limits;\n\treadonly #provider: ProviderSide;\n\t#state: HoldState = PENDING;\n\t/** What it asks for (its params owned), once it started: it is placed again after a reload left it unbound. */\n\t#request: HoldRequest | undefined;\n\t/** The held object, from its binding until the hold is released. */\n\t#object: ChordObject | undefined;\n\t/** The members the current batch changed, with their ops, in order. */\n\t#changes: (readonly [Followed, readonly Op[]])[] = [];\n\t/** The members that failed since the last message that carried this hold. */\n\t#failed: FailedMember[] = [];\n\t/** The members whose document was retired since the last message that carried this hold (ORed while it waits). */\n\t#retired: readonly number[] = NO_RETIRED;\n\t#touched = false;\n\t/** Whether the hold counts as one of the host's references (`host.activity`): from its arrival until it ends. */\n\t#counted = true;\n\n\tconstructor(id: number, provider: ProviderSide, caller: Caller, limits: Limits) {\n\t\tthis.id = id;\n\t\tthis.#provider = provider;\n\t\tthis.caller = caller;\n\t\tthis.limits = limits;\n\t\tprovider.link.host.count(\"references\", 1);\n\t}\n\n\t/** Whether the hold is bound: its members' changes are sent. */\n\tget bound(): boolean {\n\t\treturn this.#state.kind === \"bound\";\n\t}\n\n\t/** Whether calls on it reach its object: bound, or binding afresh after a swap in place (its `bound` not sent yet). */\n\tget callable(): boolean {\n\t\tconst state = this.#state;\n\t\treturn state.kind === \"bound\" || (state.kind === \"binding\" && state.previous !== undefined);\n\t}\n\n\t/** Whom it acts for (the unbound index's revocation). */\n\tget principal(): Principal | undefined {\n\t\treturn this.caller.principal;\n\t}\n\n\t/** Its consumer's contract version and fingerprint (its request's): the provider binds them or it waits. */\n\tget contract(): HoldRequest {\n\t\treturn this.#request!;\n\t}\n\n\t/** Whether the hold holds no object: before the publication, or refused (revocation ends it, §4). */\n\tget unbound(): boolean {\n\t\treturn this.#object === undefined && this.#state.kind !== \"released\";\n\t}\n\n\t/**\n\t * Admits the hold: before the host's publication it waits in the unbound index, placed by the publication.\n\t * Then its params within the link's part limit (`too_large/part`), then relayed (it is replaced by a relayed hold),\n\t * or served here, its params opened and parsed (a malformed part is a protocol error), its object taken and followed\n\t * (`moved`) in the turn it arrived. A hold that cannot be served here waits refused (`#refuse`).\n\t */\n\tstart(request: HoldRequest): void {\n\t\tconst { link } = this.#provider;\n\t\tif (!link.host.published) {\n\t\t\tthis.#state = { kind: \"unplaced\", request: owned(request) };\n\t\t\tlink.host.index(request.type, this);\n\t\t\treturn;\n\t\t}\n\t\tlet served: Serving;\n\t\ttry {\n\t\t\tconst oversize = oversized(request.params, link.limits.part);\n\t\t\tif (oversize !== undefined) throw oversize;\n\t\t\tconst placed = link.host.place(request, link, this.caller, link.context);\n\t\t\tif (placed.kind === \"path\") {\n\t\t\t\t// Counted where it is served: a relayed hold is not this host's reference.\n\t\t\t\tthis.drop();\n\t\t\t\tnew RelayedHold(this.id, this.#provider, request, this.caller, placed.path).start();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet params: unknown;\n\t\t\ttry {\n\t\t\t\tparams = parsePart(link.openPart(request.params, this.limits, link.context));\n\t\t\t} catch (error) {\n\t\t\t\t// Past its limits: the hold's \\`too_large/part\\`. No JSON: a protocol error, reported, and the link closes.\n\t\t\t\tif (isChordError(error, \"too_large\")) throw error;\n\t\t\t\tlink.host.report({ kind: \"protocol_error\", error });\n\t\t\t\tlink.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserved = link.host.serving(request, params, this.caller.principal!, link.context);\n\t\t} catch (error) {\n\t\t\tthis.#refuse(request, { kind: \"broken\", error: asChordError(error, request.type) });\n\t\t\treturn;\n\t\t}\n\t\tif (served.kind === \"waiting\") {\n\t\t\tthis.#refuse(request, served.cause);\n\t\t\treturn;\n\t\t}\n\t\tthis.#request = owned(request);\n\t\tconst { object } = served;\n\t\tthis.#object = object;\n\t\tobject.hold(this);\n\t\tthis.moved();\n\t}\n\n\t/**\n\t * Woken by the unbound index (out of it already): before the publication, placed now; refused `waiting`, its start\n\t * runs again, announced with `loading` (then `bound` or `failed`).\n\t */\n\twake(): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"unplaced\") {\n\t\t\tthis.#state = PENDING;\n\t\t\tthis.start(state.request);\n\t\t} else if (state.kind === \"refused\") {\n\t\t\tthis.#restart(state.request);\n\t\t}\n\t}\n\n\t/**\n\t * The object's state changed, or the hold took it: a pending hold binds once it is live (when a slot is free),\n\t * sends each failure, and announces the attempt after a failure with `loading`. A bound hold (or one whose `bound`\n\t * waits for a slot) whose object leaves `live` goes back to pending (slice 7b §6), except while a reload's swap runs\n\t * in place; a bound one whose object went live with another attempt (a swap) gets a fresh `bound` (audit A9).\n\t */\n\tmoved(): void {\n\t\tconst current = this.#state;\n\t\tconst object = this.#object;\n\t\tif (object === undefined) return;\n\t\tif (current.kind === \"bound\" || current.kind === \"binding\") {\n\t\t\tconst { kind } = object.state;\n\t\t\tif (kind === \"live\") {\n\t\t\t\tif (current.kind === \"bound\" && object.instance !== current.instance) this.#rebind(current);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Its instance still changes (a swap's old one, a restart's drain, a live failure's admitted commits): it follows\n\t\t\t// it on until it stopped (slice 7b, decision \"References are the only indirection\").\n\t\t\tif (current.kind === \"bound\" && object.attachable === current.instance) return;\n\t\t\tif (current.kind === \"binding\" && kind === \"loading\" && object.swapsInPlace) return;\n\t\t\tthis.#unbind(object.state.kind === \"failed\" ? object.state.cause.error : undefined);\n\t\t}\n\t\tthis.#pending(object);\n\t}\n\n\t/** Member `followed` failed with `error`: its failure waits to be sent, replacing one still waiting. */\n\t#memberFailed(followed: Followed, error: unknown): void {\n\t\tfollowed.pending.take();\n\t\tconst failure = { member: followed.index, error: wireError(error) };\n\t\tconst at = this.#failed.findIndex(({ member }) => member === followed.index);\n\t\t// A new list when one is replaced (rare): a list handed to an entry is never written to.\n\t\tif (at === -1) this.#failed.push(failure);\n\t\telse this.#failed = this.#failed.map((pending, i) => (i === at ? failure : pending));\n\t}\n\n\t/** Member `index` has a value again: a failure of it still waiting to be sent (rare) is not sent. */\n\t#memberHealed(index: number): void {\n\t\tif (this.#failed.length > 0) this.#failed = this.#failed.filter(({ member }) => member !== index);\n\t}\n\n\t/**\n\t * Its object left `live` (a restart, a parked swap, a live failure): no longer subscribed or waiting for a slot, its\n\t * calls in flight rejected (`error`, or `unavailable`), pending again; a `loading` tells the consumer it rebinds\n\t * (a failure is sent by `#pending`, which a consumer applies to a bound hold as a rebinding too, model §5).\n\t */\n\t#unbind(error: ChordError | undefined): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"bound\") unfollow(state);\n\t\tthis.#changes = [];\n\t\tthis.#failed = [];\n\t\tthis.#retired = NO_RETIRED;\n\t\tthis.#touched = false;\n\t\tconst reason = error ?? new ChordError({ code: \"unavailable\", message: `hold ${this.id}: its object rebinds` });\n\t\tthis.#provider.unbound(this, reason);\n\t\tthis.#state = PENDING;\n\t\tif (error === undefined) this.#provider.send({ kind: \"loading\", hold: this.id });\n\t}\n\n\t/**\n\t * A swap of its object went live in place (slice 7b §5, audit A9): no longer subscribed to the old instance, it gets\n\t * a fresh `bound` of the new one's members (as a restart, a variant or a version change does), answering calls by\n\t * its old names until that is sent.\n\t */\n\t#rebind(state: Bound): void {\n\t\tunfollow(state);\n\t\t// Its ops still waiting for a slot are the old instance's: the `bound` replaces them.\n\t\tthis.#provider.unbind(this);\n\t\tthis.#state = { kind: \"binding\", previous: { variant: state.variant, names: state.names } };\n\t\tthis.#provider.bind(this, this.#provider.link.context);\n\t}\n\n\t/**\n\t * A `retry` message with `hops` left of its budget: the object is asked for an attempt now (it ignores this unless\n\t * failed; parked, it passes it on, to other hosts with one hop less); a refused hold is started again (a route's\n\t * `authorize` may admit it now).\n\t */\n\tretry({ hops }: Extract<Message, { readonly kind: \"retry\" }>): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind !== \"refused\") {\n\t\t\tthis.#object?.retry(retryWalk(hops - 1));\n\t\t\treturn;\n\t\t}\n\t\tif (state.cause.kind === \"waiting\") this.#provider.link.host.unindex(state.request.type, this);\n\t\tthis.#restart(state.request);\n\t}\n\n\t/** The pending hold's part of `moved`: binds once live, sends each failure, announces the next attempt. */\n\t#pending(object: ChordObject): void {\n\t\tconst current = this.#state;\n\t\tif (current.kind !== \"pending\") return;\n\t\tconst state = object.state;\n\t\tif (state.kind === \"live\") {\n\t\t\tthis.#state = BINDING;\n\t\t\tthis.#provider.bind(this, this.#provider.link.context);\n\t\t} else if (state.kind === \"failed\") {\n\t\t\t// Each failure and each new cause (a parked object's blocker changed) is a message of its own.\n\t\t\tconst { cause, retryAt } = state;\n\t\t\tconst retryIn = retryAt === undefined ? {} : { retryIn: Math.max(0, retryAt - Date.now()) };\n\t\t\tconst failed = { kind: cause.kind, error: wireError(cause.error) };\n\t\t\tthis.#provider.send({ kind: \"failed\", hold: this.id, cause: failed, ...retryIn });\n\t\t\tthis.#state = { kind: \"pending\", toldFailed: true };\n\t\t} else if (state.kind === \"loading\" && current.toldFailed) {\n\t\t\tthis.#provider.send({ kind: \"loading\", hold: this.id });\n\t\t\tthis.#state = PENDING;\n\t\t}\n\t}\n\n\t/** Starts a refused hold again, announced with `loading`. */\n\t#restart(request: HoldRequest): void {\n\t\tthis.#state = PENDING;\n\t\tthis.#provider.send({ kind: \"loading\", hold: this.id });\n\t\tthis.start(request);\n\t}\n\n\t/** Calls a method of the held object as the hold's caller. */\n\tcall(method: string, args: unknown, context: Context): Promise<unknown> {\n\t\treturn this.#object!.call(method, args, context, this.caller, this.contract.version);\n\t}\n\n\t/**\n\t * The method at `index` of the bound variant and whether its result carries byte segments (its schema has a\n\t * `bytes()` leaf). Throws on an index outside the variant (a protocol error); a hold that is not bound has none.\n\t */\n\tmethod(index: number): { readonly name: string; readonly resultBytes: boolean } {\n\t\tconst state = this.#state;\n\t\t// Binding afresh after a swap: by the names the consumer still has (the new instance answers by name).\n\t\tconst bound = state.kind === \"bound\" ? state : state.kind === \"binding\" ? state.previous : undefined;\n\t\tconst name = bound?.names.methods[index];\n\t\tif (name === undefined) throw new Error(`hold ${this.id}: no method ${index}`);\n\t\treturn { name, resultBytes: bound!.variant.methods.get(name)!.result.bytes };\n\t}\n\n\t/**\n\t * The hold's binding, sent when a slot is free. The snapshot of every member, as a value or failed, and the\n\t * subscription are taken in this synchronous step (race 2), so each member's next ops continue exactly from it.\n\t * Names travel as indexes into the bound version (2b). Counts one encode (`chord.link.encodes`).\n\t */\n\tboundEntry(context: Context): BoundEntry {\n\t\tconst object = this.#object!;\n\t\tconst { contract } = object.served;\n\t\t// A live remote object has its variant.\n\t\tconst variant = object.variant!;\n\t\tconst state = this.#bindTo(object);\n\t\tconst members: BoundEntry[\"members\"][number][] = [];\n\t\tconst failed: FailedMember[] = [];\n\t\tconst { version } = this.contract;\n\t\tconst current = version === contract.version;\n\t\tfor (const [index, member] of state.names.state.entries()) {\n\t\t\t// An older version's members are its instance's mapping (its refusals unbound it before: `ChordObject`).\n\t\t\tconst source = current ? object.stateMembers.get(member)! : object.liveMember(member, version);\n\t\t\tlet value: JsonValue;\n\t\t\ttry {\n\t\t\t\tvalue = source.value;\n\t\t\t} catch (error) {\n\t\t\t\t// A failed member (a derive whose compute throws) is followed: it recovers with a root replacement.\n\t\t\t\tfailed.push({ member: index, error: wireError(error) });\n\t\t\t\tif (source instanceof Source) this.#follow(state, index, source);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tmembers.push({ member: index, value: this.#provider.link.part(jsonPart(value), context) });\n\t\t\t} catch (error) {\n\t\t\t\t// A value past the link's limits: failed for this hold, which takes no more of it.\n\t\t\t\tfailed.push({ member: index, error: wireError(error) });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// A constant never changes: nothing to follow.\n\t\t\tif (source instanceof Source) this.#follow(state, index, source);\n\t\t}\n\t\tthis.#changes = [];\n\t\tthis.#failed = [];\n\t\tthis.#retired = NO_RETIRED;\n\t\tcontext.telemetry.metrics?.counter(\"chord.link.encodes\").add(1);\n\t\treturn { hold: this.id, variant: variantOrder(contract).indexOf(variant), members, failed };\n\t}\n\n\t/**\n\t * This batch's entry of the `state` message: the members it changed with their ops, each encoded once with its\n\t * member's encoder, and the members that failed; resets both. Counts one encode per hold (`chord.link.encodes`).\n\t */\n\tentry(context: Context): StateEntry {\n\t\tconst { link } = this.#provider;\n\t\tconst members = this.#take().map(([{ index, encoder }, ops]) => ({\n\t\t\tmember: index,\n\t\t\tops: link.part(jsonPart(encoder.encode(ops)), context),\n\t\t}));\n\t\treturn this.#entry(members, context);\n\t}\n\n\t/** The window is full: this batch's ops join the members' pending queues (raw, never mutated). */\n\tqueue(): void {\n\t\tfor (const [{ pending }, ops] of this.#take()) pending.push(ops);\n\t}\n\n\t/**\n\t * The entry of a freed slot's `state` message: each member's pending ops encoded once, or `[[\"r\", value]]` after an\n\t * overflow, all reflecting the latest commit; and the members that failed meanwhile. Counts one encode per hold.\n\t */\n\tpendingEntry(context: Context): StateEntry {\n\t\tconst { link } = this.#provider;\n\t\tconst members: StateEntry[\"members\"][number][] = [];\n\t\t// Only a bound hold has pending ops.\n\t\tfor (const { index, source, encoder, pending } of (this.#state as Bound).followed) {\n\t\t\tif (pending.size === 0) continue;\n\t\t\tconst taken = pending.take();\n\t\t\tconst ops = taken.kind === \"replace\" ? [[\"r\", source.value] as const] : taken.ops;\n\t\t\tif (ops.length > 0) members.push({ member: index, ops: link.part(jsonPart(encoder.encode(ops)), context) });\n\t\t}\n\t\treturn this.#entry(members, context);\n\t}\n\n\t/** The consumer released the hold, or its link closed: its waits stop and its object loses this reference. */\n\trelease(): void {\n\t\tthis.drop();\n\t\tthis.#object?.unhold(this);\n\t\tthis.#object = undefined;\n\t}\n\n\t/** Ends the hold without releasing its object (the host closes and ends its objects itself). */\n\tdrop(): void {\n\t\tconst state = this.#state;\n\t\tconst { host } = this.#provider.link;\n\t\tif (state.kind === \"bound\") {\n\t\t\tunfollow(state);\n\t\t} else if (state.kind === \"unplaced\" || (state.kind === \"refused\" && state.cause.kind === \"waiting\")) {\n\t\t\thost.unindex(state.request.type, this);\n\t\t}\n\t\tthis.#state = { kind: \"released\" };\n\t\tif (this.#counted) host.count(\"references\", -1);\n\t\tthis.#counted = false;\n\t}\n\n\t/**\n\t * The object ended while held (revocation; a reload, slice 7b), or the hold was revoked (or its host closed) while it\n\t * held no object: the hold sends `gone` with `error`.\n\t */\n\tend(error: ChordError): void {\n\t\tif (this.#state.kind === \"released\") return;\n\t\tthis.#provider.forget(this, error);\n\t\tthis.drop();\n\t\tthis.#object = undefined;\n\t\tthis.#provider.send({ kind: \"gone\", hold: this.id, error: wireError(error) });\n\t}\n\n\t/** The binding: its variant and names at the hold's version, with no member followed yet. */\n\t#bindTo(object: ChordObject): Bound {\n\t\tconst variant = variantsAt(object.served.contract, this.contract.version).get(object.variant!)!;\n\t\tconst state: Bound = {\n\t\t\tkind: \"bound\",\n\t\t\tvariant,\n\t\t\tnames: variantNames(variant),\n\t\t\tfollowed: [],\n\t\t\tinstance: object.instance,\n\t\t};\n\t\tthis.#state = state;\n\t\treturn state;\n\t}\n\n\t/** A hold over a link follows its object's instances in `moved` (a fresh `bound` for a new one). */\n\tretarget(): void {}\n\n\t/** It moves nothing in `retarget`. */\n\treadonly following = false;\n\n\t/**\n\t * Its object left it (slice 7b §6): its type was removed (`not_served`) or its provider no longer binds the hold's\n\t * version (`version`): no longer subscribed, its calls in flight rejected, it waits refused with `removal.cause` in\n\t * the host's index (a publication starts it again) and the consumer is sent `failed`, which unbinds a bound hold.\n\t */\n\tremoved(removal: Removal): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"released\" || this.#object === undefined) return;\n\t\tif (state.kind === \"bound\") unfollow(state);\n\t\tthis.#changes = [];\n\t\tthis.#failed = [];\n\t\tthis.#retired = NO_RETIRED;\n\t\tthis.#touched = false;\n\t\tthis.#provider.unbound(this, removal.cause.error);\n\t\tthis.#object = undefined;\n\t\tthis.#refuse(this.contract, removal.cause);\n\t}\n\n\t/**\n\t * Follows member `index` from its snapshot on (a failed one too: it may recover in this hold): its own encoder and\n\t * pending queue, and a subscription feeding its calls into this hold's batch. Failures fold per member: a failure\n\t * drops what was pending for it and replaces a failure not sent yet (one at most per member, however long the\n\t * consumer stalls); the value after it (a root replacement) replaces the failure. A retirement waits for a value.\n\t */\n\t#follow(state: Bound, index: number, source: DeriveSource): void {\n\t\tconst followed: Followed = {\n\t\t\tindex,\n\t\t\tsource,\n\t\t\tsubscriber: {\n\t\t\t\tadvance: (call) => {\n\t\t\t\t\tthis.#touch();\n\t\t\t\t\tif (call.kind === \"failed\") {\n\t\t\t\t\t\tthis.#memberFailed(followed, call.error);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.#memberHealed(index);\n\t\t\t\t\tconst { ops, retired } = call;\n\t\t\t\t\t// A retired derive's frame may carry no ops (rule 21): only the flag travels.\n\t\t\t\t\tif (ops.length > 0) this.#changes.push([followed, ops]);\n\t\t\t\t\t// A new list per retirement (rare): the shared empty one is never written to.\n\t\t\t\t\tif (retired && !this.#retired.includes(index)) this.#retired = [...this.#retired, index];\n\t\t\t\t},\n\t\t\t\t// The member's source ended with its object, which ends this hold.\n\t\t\t\tend: () => {},\n\t\t\t\tendAfterDelivery: () => {},\n\t\t\t},\n\t\t\tencoder: encoder(),\n\t\t\tpending: new PendingOps(),\n\t\t};\n\t\t// A constant never changes: nothing to subscribe to.\n\t\tif (source instanceof Source) source.subscribe(followed.subscriber);\n\t\tstate.followed.push(followed);\n\t}\n\n\t/** Takes the current batch's changes; the hold is untouched again. */\n\t#take(): (readonly [Followed, readonly Op[]])[] {\n\t\tconst changes = this.#changes;\n\t\tthis.#changes = [];\n\t\tthis.#touched = false;\n\t\treturn changes;\n\t}\n\n\t/** A state entry with `members` and the failures and retirements since the last one; counts one encode. */\n\t#entry(members: StateEntry[\"members\"], context: Context): StateEntry {\n\t\tconst failed = this.#failed;\n\t\tlet retired = this.#retired;\n\t\tthis.#failed = [];\n\t\tthis.#retired = NO_RETIRED;\n\t\tif (retired.length > 0 && failed.length > 0) {\n\t\t\t// A failed member's retirement travels with its next value, never with its failure.\n\t\t\tconst kept = retired.filter((index) => failed.some(({ member }) => member === index));\n\t\t\tif (kept.length > 0) {\n\t\t\t\tthis.#retired = kept;\n\t\t\t\tretired = retired.filter((index) => !kept.includes(index));\n\t\t\t}\n\t\t}\n\t\tcontext.telemetry.metrics?.counter(\"chord.link.encodes\").add(1);\n\t\treturn { hold: this.id, members, failed, retired };\n\t}\n\n\t#touch(): void {\n\t\tif (this.#touched) return;\n\t\tthis.#touched = true;\n\t\tthis.#provider.touched(this);\n\t}\n\n\t/**\n\t * Refuses the hold with `cause`, holding nothing: it keeps `request`, indexed under its type while `waiting` (a\n\t * publication starts it again), for a `retry` otherwise.\n\t */\n\t#refuse(request: HoldRequest, cause: FailureCause): void {\n\t\tthis.#state = { kind: \"refused\", request: owned(request), cause };\n\t\tif (cause.kind === \"waiting\") this.#provider.link.host.index(request.type, this);\n\t\tthis.#provider.send({\n\t\t\tkind: \"failed\",\n\t\t\thold: this.id,\n\t\t\tcause: { kind: cause.kind, error: wireError(cause.error) },\n\t\t});\n\t}\n}\n\n/** Stops following every member of a bound hold. */\nfunction unfollow(state: Bound): void {\n\tfor (const { source, subscriber } of state.followed) if (source instanceof Source) source.unsubscribe(subscriber);\n}\n\n/** `request` with its params owned, not a view of the message they came in (which the link's buffers may hold). */\nfunction owned(request: HoldRequest): HoldRequest {\n\tconst { params } = request;\n\treturn typeof params === \"string\" ? request : { ...request, params: (params as Uint8Array).slice() };\n}\n\n/** A `hold` message's fields naming whom it acts for. */\ntype ActingFor = Pick<HoldMessage, \"principal\" | \"incarnation\">;\n\nconst NOBODY: ActingFor = {};\n\n/**\n * The fields of a `hold` message naming whom it acts for (`caller`): sent only on a route link, whose child honours\n * them (§4); none elsewhere.\n */\nexport function actingFor(link: HostLink, { principal, incarnation }: Caller): ActingFor {\n\treturn link.role === \"route\" && principal !== undefined ? { principal, incarnation } : NOBODY;\n}\n"]}
|