@earendil-works/chord 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +79 -14
- package/dist/cell.d.ts +7 -7
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js.map +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/contract.d.ts +51 -52
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +19 -24
- package/dist/contract.js.map +1 -1
- package/dist/delta/apply-immutable-trusted.js +3 -4
- package/dist/delta/apply-immutable-trusted.js.map +1 -1
- package/dist/delta/diff.d.ts.map +1 -1
- package/dist/delta/diff.js +5 -3
- package/dist/delta/diff.js.map +1 -1
- package/dist/delta/index.d.ts +9 -1
- package/dist/delta/index.d.ts.map +1 -1
- package/dist/delta/index.js +15 -11
- package/dist/delta/index.js.map +1 -1
- package/dist/delta/pending.d.ts +36 -0
- package/dist/delta/pending.d.ts.map +1 -0
- package/dist/delta/pending.js +143 -0
- package/dist/delta/pending.js.map +1 -0
- package/dist/delta/tracker.d.ts +12 -0
- package/dist/delta/tracker.d.ts.map +1 -1
- package/dist/delta/tracker.js +109 -39
- package/dist/delta/tracker.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +9 -7
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/next/contracts/accepts.d.ts +81 -0
- package/dist/next/contracts/accepts.d.ts.map +1 -0
- package/dist/next/contracts/accepts.js +123 -0
- package/dist/next/contracts/accepts.js.map +1 -0
- package/dist/next/contracts/contract.d.ts +121 -0
- package/dist/next/contracts/contract.d.ts.map +1 -0
- package/dist/next/contracts/contract.js +50 -0
- package/dist/next/contracts/contract.js.map +1 -0
- package/dist/next/contracts/declare.d.ts +107 -0
- package/dist/next/contracts/declare.d.ts.map +1 -0
- package/dist/next/contracts/declare.js +136 -0
- package/dist/next/contracts/declare.js.map +1 -0
- package/dist/next/contracts/evolve.d.ts +92 -0
- package/dist/next/contracts/evolve.d.ts.map +1 -0
- package/dist/next/contracts/evolve.js +179 -0
- package/dist/next/contracts/evolve.js.map +1 -0
- package/dist/next/contracts/fingerprint.d.ts +16 -0
- package/dist/next/contracts/fingerprint.d.ts.map +1 -0
- package/dist/next/contracts/fingerprint.js +50 -0
- package/dist/next/contracts/fingerprint.js.map +1 -0
- package/dist/next/contracts/history.d.ts +71 -0
- package/dist/next/contracts/history.d.ts.map +1 -0
- package/dist/next/contracts/history.js +3 -0
- package/dist/next/contracts/history.js.map +1 -0
- package/dist/next/contracts/host-kind.d.ts +40 -0
- package/dist/next/contracts/host-kind.d.ts.map +1 -0
- package/dist/next/contracts/host-kind.js +37 -0
- package/dist/next/contracts/host-kind.js.map +1 -0
- package/dist/next/contracts/index.d.ts +7 -0
- package/dist/next/contracts/index.d.ts.map +1 -0
- package/dist/next/contracts/index.js +6 -0
- package/dist/next/contracts/index.js.map +1 -0
- package/dist/next/contracts/internal.d.ts +10 -0
- package/dist/next/contracts/internal.d.ts.map +1 -0
- package/dist/next/contracts/internal.js +9 -0
- package/dist/next/contracts/internal.js.map +1 -0
- package/dist/next/contracts/names.d.ts +3 -0
- package/dist/next/contracts/names.d.ts.map +1 -0
- package/dist/next/contracts/names.js +13 -0
- package/dist/next/contracts/names.js.map +1 -0
- package/dist/next/contracts/params.d.ts +28 -0
- package/dist/next/contracts/params.d.ts.map +1 -0
- package/dist/next/contracts/params.js +50 -0
- package/dist/next/contracts/params.js.map +1 -0
- package/dist/next/contracts/schema.d.ts +102 -0
- package/dist/next/contracts/schema.d.ts.map +1 -0
- package/dist/next/contracts/schema.js +103 -0
- package/dist/next/contracts/schema.js.map +1 -0
- package/dist/next/contracts/snapshot.d.ts +16 -0
- package/dist/next/contracts/snapshot.d.ts.map +1 -0
- package/dist/next/contracts/snapshot.js +167 -0
- package/dist/next/contracts/snapshot.js.map +1 -0
- package/dist/next/data/args.d.ts +50 -0
- package/dist/next/data/args.d.ts.map +1 -0
- package/dist/next/data/args.js +83 -0
- package/dist/next/data/args.js.map +1 -0
- package/dist/next/data/errors.d.ts +73 -0
- package/dist/next/data/errors.d.ts.map +1 -0
- package/dist/next/data/errors.js +107 -0
- package/dist/next/data/errors.js.map +1 -0
- package/dist/next/data/failure.d.ts +26 -0
- package/dist/next/data/failure.d.ts.map +1 -0
- package/dist/next/data/failure.js +72 -0
- package/dist/next/data/failure.js.map +1 -0
- package/dist/next/data/index.d.ts +4 -0
- package/dist/next/data/index.d.ts.map +1 -0
- package/dist/next/data/index.js +4 -0
- package/dist/next/data/index.js.map +1 -0
- package/dist/next/data/internal.d.ts +7 -0
- package/dist/next/data/internal.d.ts.map +1 -0
- package/dist/next/data/internal.js +8 -0
- package/dist/next/data/internal.js.map +1 -0
- package/dist/next/data/params.d.ts +20 -0
- package/dist/next/data/params.d.ts.map +1 -0
- package/dist/next/data/params.js +31 -0
- package/dist/next/data/params.js.map +1 -0
- package/dist/next/data/principal.d.ts +17 -0
- package/dist/next/data/principal.d.ts.map +1 -0
- package/dist/next/data/principal.js +41 -0
- package/dist/next/data/principal.js.map +1 -0
- package/dist/next/data/validator.d.ts +12 -0
- package/dist/next/data/validator.d.ts.map +1 -0
- package/dist/next/data/validator.js +34 -0
- package/dist/next/data/validator.js.map +1 -0
- package/dist/next/documents/address-source.d.ts +20 -0
- package/dist/next/documents/address-source.d.ts.map +1 -0
- package/dist/next/documents/address-source.js +44 -0
- package/dist/next/documents/address-source.js.map +1 -0
- package/dist/next/documents/definition.d.ts +84 -0
- package/dist/next/documents/definition.d.ts.map +1 -0
- package/dist/next/documents/definition.js +73 -0
- package/dist/next/documents/definition.js.map +1 -0
- package/dist/next/documents/documents.d.ts +106 -0
- package/dist/next/documents/documents.d.ts.map +1 -0
- package/dist/next/documents/documents.js +224 -0
- package/dist/next/documents/documents.js.map +1 -0
- package/dist/next/documents/fence.d.ts +9 -0
- package/dist/next/documents/fence.d.ts.map +1 -0
- package/dist/next/documents/fence.js +15 -0
- package/dist/next/documents/fence.js.map +1 -0
- package/dist/next/documents/handles.d.ts +76 -0
- package/dist/next/documents/handles.d.ts.map +1 -0
- package/dist/next/documents/handles.js +66 -0
- package/dist/next/documents/handles.js.map +1 -0
- package/dist/next/documents/index.d.ts +4 -0
- package/dist/next/documents/index.d.ts.map +1 -0
- package/dist/next/documents/index.js +3 -0
- package/dist/next/documents/index.js.map +1 -0
- package/dist/next/documents/internal.d.ts +9 -0
- package/dist/next/documents/internal.d.ts.map +1 -0
- package/dist/next/documents/internal.js +9 -0
- package/dist/next/documents/internal.js.map +1 -0
- package/dist/next/documents/keyed-slot.d.ts +103 -0
- package/dist/next/documents/keyed-slot.d.ts.map +1 -0
- package/dist/next/documents/keyed-slot.js +395 -0
- package/dist/next/documents/keyed-slot.js.map +1 -0
- package/dist/next/documents/line.d.ts +7 -0
- package/dist/next/documents/line.d.ts.map +1 -0
- package/dist/next/documents/line.js +14 -0
- package/dist/next/documents/line.js.map +1 -0
- package/dist/next/documents/persistence.d.ts +104 -0
- package/dist/next/documents/persistence.d.ts.map +1 -0
- package/dist/next/documents/persistence.js +128 -0
- package/dist/next/documents/persistence.js.map +1 -0
- package/dist/next/documents/residency.d.ts +31 -0
- package/dist/next/documents/residency.d.ts.map +1 -0
- package/dist/next/documents/residency.js +93 -0
- package/dist/next/documents/residency.js.map +1 -0
- package/dist/next/documents/slot.d.ts +109 -0
- package/dist/next/documents/slot.d.ts.map +1 -0
- package/dist/next/documents/slot.js +181 -0
- package/dist/next/documents/slot.js.map +1 -0
- package/dist/next/documents/transaction.d.ts +133 -0
- package/dist/next/documents/transaction.d.ts.map +1 -0
- package/dist/next/documents/transaction.js +409 -0
- package/dist/next/documents/transaction.js.map +1 -0
- package/dist/next/host/activity.d.ts +31 -0
- package/dist/next/host/activity.d.ts.map +1 -0
- package/dist/next/host/activity.js +40 -0
- package/dist/next/host/activity.js.map +1 -0
- package/dist/next/host/adapted.d.ts +49 -0
- package/dist/next/host/adapted.d.ts.map +1 -0
- package/dist/next/host/adapted.js +214 -0
- package/dist/next/host/adapted.js.map +1 -0
- package/dist/next/host/attempt.d.ts +278 -0
- package/dist/next/host/attempt.d.ts.map +1 -0
- package/dist/next/host/attempt.js +1072 -0
- package/dist/next/host/attempt.js.map +1 -0
- package/dist/next/host/backoff.d.ts +29 -0
- package/dist/next/host/backoff.d.ts.map +1 -0
- package/dist/next/host/backoff.js +69 -0
- package/dist/next/host/backoff.js.map +1 -0
- package/dist/next/host/ctx.d.ts +47 -0
- package/dist/next/host/ctx.d.ts.map +1 -0
- package/dist/next/host/ctx.js +108 -0
- package/dist/next/host/ctx.js.map +1 -0
- package/dist/next/host/deadline.d.ts +12 -0
- package/dist/next/host/deadline.d.ts.map +1 -0
- package/dist/next/host/deadline.js +40 -0
- package/dist/next/host/deadline.js.map +1 -0
- package/dist/next/host/dependencies.d.ts +65 -0
- package/dist/next/host/dependencies.d.ts.map +1 -0
- package/dist/next/host/dependencies.js +115 -0
- package/dist/next/host/dependencies.js.map +1 -0
- package/dist/next/host/destination.d.ts +48 -0
- package/dist/next/host/destination.d.ts.map +1 -0
- package/dist/next/host/destination.js +101 -0
- package/dist/next/host/destination.js.map +1 -0
- package/dist/next/host/facet.d.ts +79 -0
- package/dist/next/host/facet.d.ts.map +1 -0
- package/dist/next/host/facet.js +55 -0
- package/dist/next/host/facet.js.map +1 -0
- package/dist/next/host/follow.d.ts +52 -0
- package/dist/next/host/follow.d.ts.map +1 -0
- package/dist/next/host/follow.js +207 -0
- package/dist/next/host/follow.js.map +1 -0
- package/dist/next/host/host.d.ts +495 -0
- package/dist/next/host/host.d.ts.map +1 -0
- package/dist/next/host/host.js +1075 -0
- package/dist/next/host/host.js.map +1 -0
- package/dist/next/host/index.d.ts +17 -0
- package/dist/next/host/index.d.ts.map +1 -0
- package/dist/next/host/index.js +6 -0
- package/dist/next/host/index.js.map +1 -0
- package/dist/next/host/internal.d.ts +10 -0
- package/dist/next/host/internal.d.ts.map +1 -0
- package/dist/next/host/internal.js +8 -0
- package/dist/next/host/internal.js.map +1 -0
- package/dist/next/host/members.d.ts +50 -0
- package/dist/next/host/members.d.ts.map +1 -0
- package/dist/next/host/members.js +107 -0
- package/dist/next/host/members.js.map +1 -0
- package/dist/next/host/native.d.ts +55 -0
- package/dist/next/host/native.d.ts.map +1 -0
- package/dist/next/host/native.js +92 -0
- package/dist/next/host/native.js.map +1 -0
- package/dist/next/host/object.d.ts +290 -0
- package/dist/next/host/object.d.ts.map +1 -0
- package/dist/next/host/object.js +1127 -0
- package/dist/next/host/object.js.map +1 -0
- package/dist/next/host/parked.d.ts +23 -0
- package/dist/next/host/parked.d.ts.map +1 -0
- package/dist/next/host/parked.js +79 -0
- package/dist/next/host/parked.js.map +1 -0
- package/dist/next/host/presence.d.ts +34 -0
- package/dist/next/host/presence.d.ts.map +1 -0
- package/dist/next/host/presence.js +117 -0
- package/dist/next/host/presence.js.map +1 -0
- package/dist/next/host/ref-state.d.ts +53 -0
- package/dist/next/host/ref-state.d.ts.map +1 -0
- package/dist/next/host/ref-state.js +83 -0
- package/dist/next/host/ref-state.js.map +1 -0
- package/dist/next/host/reference-keys.d.ts +36 -0
- package/dist/next/host/reference-keys.d.ts.map +1 -0
- package/dist/next/host/reference-keys.js +168 -0
- package/dist/next/host/reference-keys.js.map +1 -0
- package/dist/next/host/reference-source.d.ts +65 -0
- package/dist/next/host/reference-source.d.ts.map +1 -0
- package/dist/next/host/reference-source.js +285 -0
- package/dist/next/host/reference-source.js.map +1 -0
- package/dist/next/host/reference.d.ts +308 -0
- package/dist/next/host/reference.d.ts.map +1 -0
- package/dist/next/host/reference.js +775 -0
- package/dist/next/host/reference.js.map +1 -0
- package/dist/next/host/retry-on.d.ts +28 -0
- package/dist/next/host/retry-on.d.ts.map +1 -0
- package/dist/next/host/retry-on.js +52 -0
- package/dist/next/host/retry-on.js.map +1 -0
- package/dist/next/host/revocation.d.ts +16 -0
- package/dist/next/host/revocation.d.ts.map +1 -0
- package/dist/next/host/revocation.js +27 -0
- package/dist/next/host/revocation.js.map +1 -0
- package/dist/next/host/root.d.ts +27 -0
- package/dist/next/host/root.d.ts.map +1 -0
- package/dist/next/host/root.js +68 -0
- package/dist/next/host/root.js.map +1 -0
- package/dist/next/host/route.d.ts +64 -0
- package/dist/next/host/route.d.ts.map +1 -0
- package/dist/next/host/route.js +190 -0
- package/dist/next/host/route.js.map +1 -0
- package/dist/next/host/routines.d.ts +76 -0
- package/dist/next/host/routines.d.ts.map +1 -0
- package/dist/next/host/routines.js +350 -0
- package/dist/next/host/routines.js.map +1 -0
- package/dist/next/host/sleep.d.ts +9 -0
- package/dist/next/host/sleep.d.ts.map +1 -0
- package/dist/next/host/sleep.js +40 -0
- package/dist/next/host/sleep.js.map +1 -0
- package/dist/next/host/staging.d.ts +94 -0
- package/dist/next/host/staging.d.ts.map +1 -0
- package/dist/next/host/staging.js +302 -0
- package/dist/next/host/staging.js.map +1 -0
- package/dist/next/host/unbound.d.ts +30 -0
- package/dist/next/host/unbound.d.ts.map +1 -0
- package/dist/next/host/unbound.js +67 -0
- package/dist/next/host/unbound.js.map +1 -0
- package/dist/next/host/uuid.d.ts +3 -0
- package/dist/next/host/uuid.d.ts.map +1 -0
- package/dist/next/host/uuid.js +38 -0
- package/dist/next/host/uuid.js.map +1 -0
- package/dist/next/index.d.ts +28 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +18 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/jobs/definition.d.ts +96 -0
- package/dist/next/jobs/definition.d.ts.map +1 -0
- package/dist/next/jobs/definition.js +83 -0
- package/dist/next/jobs/definition.js.map +1 -0
- package/dist/next/jobs/index.d.ts +5 -0
- package/dist/next/jobs/index.d.ts.map +1 -0
- package/dist/next/jobs/index.js +3 -0
- package/dist/next/jobs/index.js.map +1 -0
- package/dist/next/jobs/internal.d.ts +3 -0
- package/dist/next/jobs/internal.d.ts.map +1 -0
- package/dist/next/jobs/internal.js +4 -0
- package/dist/next/jobs/internal.js.map +1 -0
- package/dist/next/jobs/job.d.ts +152 -0
- package/dist/next/jobs/job.d.ts.map +1 -0
- package/dist/next/jobs/job.js +320 -0
- package/dist/next/jobs/job.js.map +1 -0
- package/dist/next/jobs/persisted.d.ts +38 -0
- package/dist/next/jobs/persisted.d.ts.map +1 -0
- package/dist/next/jobs/persisted.js +95 -0
- package/dist/next/jobs/persisted.js.map +1 -0
- package/dist/next/jobs/records.d.ts +231 -0
- package/dist/next/jobs/records.d.ts.map +1 -0
- package/dist/next/jobs/records.js +869 -0
- package/dist/next/jobs/records.js.map +1 -0
- package/dist/next/jobs/run-states.d.ts +69 -0
- package/dist/next/jobs/run-states.d.ts.map +1 -0
- package/dist/next/jobs/run-states.js +228 -0
- package/dist/next/jobs/run-states.js.map +1 -0
- package/dist/next/jobs/run.d.ts +113 -0
- package/dist/next/jobs/run.d.ts.map +1 -0
- package/dist/next/jobs/run.js +200 -0
- package/dist/next/jobs/run.js.map +1 -0
- package/dist/next/jobs/running.d.ts +44 -0
- package/dist/next/jobs/running.d.ts.map +1 -0
- package/dist/next/jobs/running.js +117 -0
- package/dist/next/jobs/running.js.map +1 -0
- package/dist/next/jobs/stored.d.ts +63 -0
- package/dist/next/jobs/stored.d.ts.map +1 -0
- package/dist/next/jobs/stored.js +55 -0
- package/dist/next/jobs/stored.js.map +1 -0
- package/dist/next/link/binary.d.ts +4 -0
- package/dist/next/link/binary.d.ts.map +1 -0
- package/dist/next/link/binary.js +534 -0
- package/dist/next/link/binary.js.map +1 -0
- package/dist/next/link/channel.d.ts +63 -0
- package/dist/next/link/channel.d.ts.map +1 -0
- package/dist/next/link/channel.js +202 -0
- package/dist/next/link/channel.js.map +1 -0
- package/dist/next/link/errors.d.ts +7 -0
- package/dist/next/link/errors.d.ts.map +1 -0
- package/dist/next/link/errors.js +21 -0
- package/dist/next/link/errors.js.map +1 -0
- package/dist/next/link/index.d.ts +8 -0
- package/dist/next/link/index.d.ts.map +1 -0
- package/dist/next/link/index.js +8 -0
- package/dist/next/link/index.js.map +1 -0
- package/dist/next/link/internal.d.ts +9 -0
- package/dist/next/link/internal.d.ts.map +1 -0
- package/dist/next/link/internal.js +10 -0
- package/dist/next/link/internal.js.map +1 -0
- package/dist/next/link/ipc.d.ts +22 -0
- package/dist/next/link/ipc.d.ts.map +1 -0
- package/dist/next/link/ipc.js +64 -0
- package/dist/next/link/ipc.js.map +1 -0
- package/dist/next/link/link.d.ts +34 -0
- package/dist/next/link/link.d.ts.map +1 -0
- package/dist/next/link/link.js +87 -0
- package/dist/next/link/link.js.map +1 -0
- package/dist/next/link/message.d.ts +249 -0
- package/dist/next/link/message.d.ts.map +1 -0
- package/dist/next/link/message.js +123 -0
- package/dist/next/link/message.js.map +1 -0
- package/dist/next/link/part.d.ts +80 -0
- package/dist/next/link/part.d.ts.map +1 -0
- package/dist/next/link/part.js +164 -0
- package/dist/next/link/part.js.map +1 -0
- package/dist/next/link/text.d.ts +6 -0
- package/dist/next/link/text.d.ts.map +1 -0
- package/dist/next/link/text.js +335 -0
- package/dist/next/link/text.js.map +1 -0
- package/dist/next/link/values.d.ts +40 -0
- package/dist/next/link/values.d.ts.map +1 -0
- package/dist/next/link/values.js +117 -0
- package/dist/next/link/values.js.map +1 -0
- package/dist/next/link/websocket.d.ts +26 -0
- package/dist/next/link/websocket.d.ts.map +1 -0
- package/dist/next/link/websocket.js +91 -0
- package/dist/next/link/websocket.js.map +1 -0
- package/dist/next/registries/contribution.d.ts +50 -0
- package/dist/next/registries/contribution.d.ts.map +1 -0
- package/dist/next/registries/contribution.js +129 -0
- package/dist/next/registries/contribution.js.map +1 -0
- package/dist/next/registries/entries.d.ts +18 -0
- package/dist/next/registries/entries.d.ts.map +1 -0
- package/dist/next/registries/entries.js +42 -0
- package/dist/next/registries/entries.js.map +1 -0
- package/dist/next/registries/index.d.ts +3 -0
- package/dist/next/registries/index.d.ts.map +1 -0
- package/dist/next/registries/index.js +5 -0
- package/dist/next/registries/index.js.map +1 -0
- package/dist/next/registries/internal.d.ts +4 -0
- package/dist/next/registries/internal.d.ts.map +1 -0
- package/dist/next/registries/internal.js +5 -0
- package/dist/next/registries/internal.js.map +1 -0
- package/dist/next/registries/record.d.ts +94 -0
- package/dist/next/registries/record.d.ts.map +1 -0
- package/dist/next/registries/record.js +253 -0
- package/dist/next/registries/record.js.map +1 -0
- package/dist/next/registries/registry.d.ts +74 -0
- package/dist/next/registries/registry.d.ts.map +1 -0
- package/dist/next/registries/registry.js +14 -0
- package/dist/next/registries/registry.js.map +1 -0
- package/dist/next/registries/value.d.ts +48 -0
- package/dist/next/registries/value.d.ts.map +1 -0
- package/dist/next/registries/value.js +199 -0
- package/dist/next/registries/value.js.map +1 -0
- package/dist/next/remote/calls.d.ts +25 -0
- package/dist/next/remote/calls.d.ts.map +1 -0
- package/dist/next/remote/calls.js +62 -0
- package/dist/next/remote/calls.js.map +1 -0
- package/dist/next/remote/consumer.d.ts +42 -0
- package/dist/next/remote/consumer.d.ts.map +1 -0
- package/dist/next/remote/consumer.js +343 -0
- package/dist/next/remote/consumer.js.map +1 -0
- package/dist/next/remote/hold.d.ts +130 -0
- package/dist/next/remote/hold.d.ts.map +1 -0
- package/dist/next/remote/hold.js +537 -0
- package/dist/next/remote/hold.js.map +1 -0
- package/dist/next/remote/host-link.d.ts +77 -0
- package/dist/next/remote/host-link.d.ts.map +1 -0
- package/dist/next/remote/host-link.js +182 -0
- package/dist/next/remote/host-link.js.map +1 -0
- package/dist/next/remote/internal.d.ts +6 -0
- package/dist/next/remote/internal.d.ts.map +1 -0
- package/dist/next/remote/internal.js +6 -0
- package/dist/next/remote/internal.js.map +1 -0
- package/dist/next/remote/path.d.ts +46 -0
- package/dist/next/remote/path.d.ts.map +1 -0
- package/dist/next/remote/path.js +73 -0
- package/dist/next/remote/path.js.map +1 -0
- package/dist/next/remote/provider.d.ts +76 -0
- package/dist/next/remote/provider.d.ts.map +1 -0
- package/dist/next/remote/provider.js +506 -0
- package/dist/next/remote/provider.js.map +1 -0
- package/dist/next/remote/relay.d.ts +58 -0
- package/dist/next/remote/relay.d.ts.map +1 -0
- package/dist/next/remote/relay.js +117 -0
- package/dist/next/remote/relay.js.map +1 -0
- package/dist/next/remote/remote-object.d.ts +133 -0
- package/dist/next/remote/remote-object.d.ts.map +1 -0
- package/dist/next/remote/remote-object.js +411 -0
- package/dist/next/remote/remote-object.js.map +1 -0
- package/dist/next/remote/replica.d.ts +59 -0
- package/dist/next/remote/replica.d.ts.map +1 -0
- package/dist/next/remote/replica.js +125 -0
- package/dist/next/remote/replica.js.map +1 -0
- package/dist/next/state/batch.d.ts +64 -0
- package/dist/next/state/batch.d.ts.map +1 -0
- package/dist/next/state/batch.js +163 -0
- package/dist/next/state/batch.js.map +1 -0
- package/dist/next/state/derive.d.ts +52 -0
- package/dist/next/state/derive.d.ts.map +1 -0
- package/dist/next/state/derive.js +182 -0
- package/dist/next/state/derive.js.map +1 -0
- package/dist/next/state/index.d.ts +6 -0
- package/dist/next/state/index.d.ts.map +1 -0
- package/dist/next/state/index.js +4 -0
- package/dist/next/state/index.js.map +1 -0
- package/dist/next/state/internal.d.ts +6 -0
- package/dist/next/state/internal.d.ts.map +1 -0
- package/dist/next/state/internal.js +8 -0
- package/dist/next/state/internal.js.map +1 -0
- package/dist/next/state/native-source.d.ts +106 -0
- package/dist/next/state/native-source.d.ts.map +1 -0
- package/dist/next/state/native-source.js +240 -0
- package/dist/next/state/native-source.js.map +1 -0
- package/dist/next/state/watchable.d.ts +114 -0
- package/dist/next/state/watchable.d.ts.map +1 -0
- package/dist/next/state/watchable.js +156 -0
- package/dist/next/state/watchable.js.map +1 -0
- package/dist/next/state/writable.d.ts +32 -0
- package/dist/next/state/writable.d.ts.map +1 -0
- package/dist/next/state/writable.js +49 -0
- package/dist/next/state/writable.js.map +1 -0
- package/dist/next/store/adapter.d.ts +67 -0
- package/dist/next/store/adapter.d.ts.map +1 -0
- package/dist/next/store/adapter.js +118 -0
- package/dist/next/store/adapter.js.map +1 -0
- package/dist/next/store/allocator.d.ts +17 -0
- package/dist/next/store/allocator.d.ts.map +1 -0
- package/dist/next/store/allocator.js +30 -0
- package/dist/next/store/allocator.js.map +1 -0
- package/dist/next/store/applier.d.ts +8 -0
- package/dist/next/store/applier.d.ts.map +1 -0
- package/dist/next/store/applier.js +375 -0
- package/dist/next/store/applier.js.map +1 -0
- package/dist/next/store/apply-batch.d.ts +12 -0
- package/dist/next/store/apply-batch.d.ts.map +1 -0
- package/dist/next/store/apply-batch.js +83 -0
- package/dist/next/store/apply-batch.js.map +1 -0
- package/dist/next/store/archive.d.ts +32 -0
- package/dist/next/store/archive.d.ts.map +1 -0
- package/dist/next/store/archive.js +129 -0
- package/dist/next/store/archive.js.map +1 -0
- package/dist/next/store/backend.d.ts +10 -0
- package/dist/next/store/backend.d.ts.map +1 -0
- package/dist/next/store/backend.js +15 -0
- package/dist/next/store/backend.js.map +1 -0
- package/dist/next/store/catalog.d.ts +24 -0
- package/dist/next/store/catalog.d.ts.map +1 -0
- package/dist/next/store/catalog.js +17 -0
- package/dist/next/store/catalog.js.map +1 -0
- package/dist/next/store/claims.d.ts +23 -0
- package/dist/next/store/claims.d.ts.map +1 -0
- package/dist/next/store/claims.js +65 -0
- package/dist/next/store/claims.js.map +1 -0
- package/dist/next/store/columns.d.ts +77 -0
- package/dist/next/store/columns.d.ts.map +1 -0
- package/dist/next/store/columns.js +77 -0
- package/dist/next/store/columns.js.map +1 -0
- package/dist/next/store/engine.d.ts +176 -0
- package/dist/next/store/engine.d.ts.map +1 -0
- package/dist/next/store/engine.js +283 -0
- package/dist/next/store/engine.js.map +1 -0
- package/dist/next/store/evaluate.d.ts +17 -0
- package/dist/next/store/evaluate.d.ts.map +1 -0
- package/dist/next/store/evaluate.js +128 -0
- package/dist/next/store/evaluate.js.map +1 -0
- package/dist/next/store/export.d.ts +17 -0
- package/dist/next/store/export.d.ts.map +1 -0
- package/dist/next/store/export.js +200 -0
- package/dist/next/store/export.js.map +1 -0
- package/dist/next/store/expression.d.ts +150 -0
- package/dist/next/store/expression.d.ts.map +1 -0
- package/dist/next/store/expression.js +268 -0
- package/dist/next/store/expression.js.map +1 -0
- package/dist/next/store/import.d.ts +10 -0
- package/dist/next/store/import.d.ts.map +1 -0
- package/dist/next/store/import.js +276 -0
- package/dist/next/store/import.js.map +1 -0
- package/dist/next/store/index.d.ts +16 -0
- package/dist/next/store/index.d.ts.map +1 -0
- package/dist/next/store/index.js +13 -0
- package/dist/next/store/index.js.map +1 -0
- package/dist/next/store/json-column.d.ts +33 -0
- package/dist/next/store/json-column.d.ts.map +1 -0
- package/dist/next/store/json-column.js +61 -0
- package/dist/next/store/json-column.js.map +1 -0
- package/dist/next/store/jsonl.d.ts +9 -0
- package/dist/next/store/jsonl.d.ts.map +1 -0
- package/dist/next/store/jsonl.js +61 -0
- package/dist/next/store/jsonl.js.map +1 -0
- package/dist/next/store/outbox.d.ts +26 -0
- package/dist/next/store/outbox.d.ts.map +1 -0
- package/dist/next/store/outbox.js +80 -0
- package/dist/next/store/outbox.js.map +1 -0
- package/dist/next/store/query.d.ts +39 -0
- package/dist/next/store/query.d.ts.map +1 -0
- package/dist/next/store/query.js +97 -0
- package/dist/next/store/query.js.map +1 -0
- package/dist/next/store/refusal.d.ts +15 -0
- package/dist/next/store/refusal.d.ts.map +1 -0
- package/dist/next/store/refusal.js +36 -0
- package/dist/next/store/refusal.js.map +1 -0
- package/dist/next/store/rows.d.ts +80 -0
- package/dist/next/store/rows.d.ts.map +1 -0
- package/dist/next/store/rows.js +183 -0
- package/dist/next/store/rows.js.map +1 -0
- package/dist/next/store/schema.d.ts +25 -0
- package/dist/next/store/schema.d.ts.map +1 -0
- package/dist/next/store/schema.js +115 -0
- package/dist/next/store/schema.js.map +1 -0
- package/dist/next/store/sql.d.ts +73 -0
- package/dist/next/store/sql.d.ts.map +1 -0
- package/dist/next/store/sql.js +234 -0
- package/dist/next/store/sql.js.map +1 -0
- package/dist/next/store/step.d.ts +48 -0
- package/dist/next/store/step.d.ts.map +1 -0
- package/dist/next/store/step.js +50 -0
- package/dist/next/store/step.js.map +1 -0
- package/dist/next/store/store.d.ts +161 -0
- package/dist/next/store/store.d.ts.map +1 -0
- package/dist/next/store/store.js +627 -0
- package/dist/next/store/store.js.map +1 -0
- package/dist/next/store/table-changes.d.ts +29 -0
- package/dist/next/store/table-changes.d.ts.map +1 -0
- package/dist/next/store/table-changes.js +102 -0
- package/dist/next/store/table-changes.js.map +1 -0
- package/dist/next/store/table-evolve.d.ts +74 -0
- package/dist/next/store/table-evolve.d.ts.map +1 -0
- package/dist/next/store/table-evolve.js +201 -0
- package/dist/next/store/table-evolve.js.map +1 -0
- package/dist/next/store/table-handle.d.ts +67 -0
- package/dist/next/store/table-handle.d.ts.map +1 -0
- package/dist/next/store/table-handle.js +101 -0
- package/dist/next/store/table-handle.js.map +1 -0
- package/dist/next/store/table-history.d.ts +75 -0
- package/dist/next/store/table-history.d.ts.map +1 -0
- package/dist/next/store/table-history.js +42 -0
- package/dist/next/store/table-history.js.map +1 -0
- package/dist/next/store/table-migration.d.ts +16 -0
- package/dist/next/store/table-migration.d.ts.map +1 -0
- package/dist/next/store/table-migration.js +202 -0
- package/dist/next/store/table-migration.js.map +1 -0
- package/dist/next/store/table-writes.d.ts +125 -0
- package/dist/next/store/table-writes.d.ts.map +1 -0
- package/dist/next/store/table-writes.js +165 -0
- package/dist/next/store/table-writes.js.map +1 -0
- package/dist/next/store/table.d.ts +80 -0
- package/dist/next/store/table.d.ts.map +1 -0
- package/dist/next/store/table.js +103 -0
- package/dist/next/store/table.js.map +1 -0
- package/dist/next/store/text.d.ts +14 -0
- package/dist/next/store/text.d.ts.map +1 -0
- package/dist/next/store/text.js +51 -0
- package/dist/next/store/text.js.map +1 -0
- package/dist/next/store/writes.d.ts +5 -0
- package/dist/next/store/writes.d.ts.map +1 -0
- package/dist/next/store/writes.js +4 -0
- package/dist/next/store/writes.js.map +1 -0
- package/dist/next-node/compression.d.ts +7 -0
- package/dist/next-node/compression.d.ts.map +1 -0
- package/dist/next-node/compression.js +24 -0
- package/dist/next-node/compression.js.map +1 -0
- package/dist/next-node/http/admission.d.ts +63 -0
- package/dist/next-node/http/admission.d.ts.map +1 -0
- package/dist/next-node/http/admission.js +134 -0
- package/dist/next-node/http/admission.js.map +1 -0
- package/dist/next-node/http/authenticate.d.ts +21 -0
- package/dist/next-node/http/authenticate.d.ts.map +1 -0
- package/dist/next-node/http/authenticate.js +34 -0
- package/dist/next-node/http/authenticate.js.map +1 -0
- package/dist/next-node/http/cookies.d.ts +24 -0
- package/dist/next-node/http/cookies.d.ts.map +1 -0
- package/dist/next-node/http/cookies.js +62 -0
- package/dist/next-node/http/cookies.js.map +1 -0
- package/dist/next-node/http/file.d.ts +23 -0
- package/dist/next-node/http/file.d.ts.map +1 -0
- package/dist/next-node/http/file.js +94 -0
- package/dist/next-node/http/file.js.map +1 -0
- package/dist/next-node/http/headers.d.ts +37 -0
- package/dist/next-node/http/headers.d.ts.map +1 -0
- package/dist/next-node/http/headers.js +129 -0
- package/dist/next-node/http/headers.js.map +1 -0
- package/dist/next-node/http/http.d.ts +100 -0
- package/dist/next-node/http/http.d.ts.map +1 -0
- package/dist/next-node/http/http.js +462 -0
- package/dist/next-node/http/http.js.map +1 -0
- package/dist/next-node/http/incoming.d.ts +19 -0
- package/dist/next-node/http/incoming.d.ts.map +1 -0
- package/dist/next-node/http/incoming.js +31 -0
- package/dist/next-node/http/incoming.js.map +1 -0
- package/dist/next-node/http/index.d.ts +11 -0
- package/dist/next-node/http/index.d.ts.map +1 -0
- package/dist/next-node/http/index.js +12 -0
- package/dist/next-node/http/index.js.map +1 -0
- package/dist/next-node/http/node.d.ts +78 -0
- package/dist/next-node/http/node.d.ts.map +1 -0
- package/dist/next-node/http/node.js +291 -0
- package/dist/next-node/http/node.js.map +1 -0
- package/dist/next-node/http/request.d.ts +54 -0
- package/dist/next-node/http/request.d.ts.map +1 -0
- package/dist/next-node/http/request.js +116 -0
- package/dist/next-node/http/request.js.map +1 -0
- package/dist/next-node/http/response.d.ts +63 -0
- package/dist/next-node/http/response.d.ts.map +1 -0
- package/dist/next-node/http/response.js +202 -0
- package/dist/next-node/http/response.js.map +1 -0
- package/dist/next-node/http/router.d.ts +114 -0
- package/dist/next-node/http/router.d.ts.map +1 -0
- package/dist/next-node/http/router.js +261 -0
- package/dist/next-node/http/router.js.map +1 -0
- package/dist/next-node/http/upgrades.d.ts +58 -0
- package/dist/next-node/http/upgrades.d.ts.map +1 -0
- package/dist/next-node/http/upgrades.js +184 -0
- package/dist/next-node/http/upgrades.js.map +1 -0
- package/dist/next-node/plugins/build.d.ts +57 -0
- package/dist/next-node/plugins/build.d.ts.map +1 -0
- package/dist/next-node/plugins/build.js +334 -0
- package/dist/next-node/plugins/build.js.map +1 -0
- package/dist/next-node/plugins/discover.d.ts +36 -0
- package/dist/next-node/plugins/discover.d.ts.map +1 -0
- package/dist/next-node/plugins/discover.js +91 -0
- package/dist/next-node/plugins/discover.js.map +1 -0
- package/dist/next-node/plugins/evaluate.d.ts +33 -0
- package/dist/next-node/plugins/evaluate.d.ts.map +1 -0
- package/dist/next-node/plugins/evaluate.js +98 -0
- package/dist/next-node/plugins/evaluate.js.map +1 -0
- package/dist/next-node/plugins/index.d.ts +9 -0
- package/dist/next-node/plugins/index.d.ts.map +1 -0
- package/dist/next-node/plugins/index.js +11 -0
- package/dist/next-node/plugins/index.js.map +1 -0
- package/dist/next-node/plugins/install.d.ts +13 -0
- package/dist/next-node/plugins/install.d.ts.map +1 -0
- package/dist/next-node/plugins/install.js +37 -0
- package/dist/next-node/plugins/install.js.map +1 -0
- package/dist/next-node/plugins/plugins.d.ts +135 -0
- package/dist/next-node/plugins/plugins.d.ts.map +1 -0
- package/dist/next-node/plugins/plugins.js +206 -0
- package/dist/next-node/plugins/plugins.js.map +1 -0
- package/dist/next-node/plugins/runtime.d.ts +41 -0
- package/dist/next-node/plugins/runtime.d.ts.map +1 -0
- package/dist/next-node/plugins/runtime.js +136 -0
- package/dist/next-node/plugins/runtime.js.map +1 -0
- package/dist/next-node/plugins/stack.d.ts +16 -0
- package/dist/next-node/plugins/stack.d.ts.map +1 -0
- package/dist/next-node/plugins/stack.js +61 -0
- package/dist/next-node/plugins/stack.js.map +1 -0
- package/dist/next-node/plugins/watcher.d.ts +58 -0
- package/dist/next-node/plugins/watcher.d.ts.map +1 -0
- package/dist/next-node/plugins/watcher.js +281 -0
- package/dist/next-node/plugins/watcher.js.map +1 -0
- package/dist/next-node/workers/control.d.ts +83 -0
- package/dist/next-node/workers/control.d.ts.map +1 -0
- package/dist/next-node/workers/control.js +77 -0
- package/dist/next-node/workers/control.js.map +1 -0
- package/dist/next-node/workers/index.d.ts +5 -0
- package/dist/next-node/workers/index.d.ts.map +1 -0
- package/dist/next-node/workers/index.js +7 -0
- package/dist/next-node/workers/index.js.map +1 -0
- package/dist/next-node/workers/lock.d.ts +21 -0
- package/dist/next-node/workers/lock.d.ts.map +1 -0
- package/dist/next-node/workers/lock.js +137 -0
- package/dist/next-node/workers/lock.js.map +1 -0
- package/dist/next-node/workers/main.d.ts +46 -0
- package/dist/next-node/workers/main.d.ts.map +1 -0
- package/dist/next-node/workers/main.js +230 -0
- package/dist/next-node/workers/main.js.map +1 -0
- package/dist/next-node/workers/process.d.ts +42 -0
- package/dist/next-node/workers/process.d.ts.map +1 -0
- package/dist/next-node/workers/process.js +125 -0
- package/dist/next-node/workers/process.js.map +1 -0
- package/dist/next-node/workers/workers.d.ts +80 -0
- package/dist/next-node/workers/workers.d.ts.map +1 -0
- package/dist/next-node/workers/workers.js +572 -0
- package/dist/next-node/workers/workers.js.map +1 -0
- package/dist/object.d.ts +4 -4
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +3 -4
- package/dist/object.js.map +1 -1
- package/dist/output.d.ts +1 -1
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +4 -2
- package/dist/output.js.map +1 -1
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +2 -2
- package/dist/remote.js.map +1 -1
- package/dist/schema.d.ts +8 -4
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +180 -5
- package/dist/schema.js.map +1 -1
- package/dist/sqlite/cloudflare.d.ts +2 -0
- package/dist/sqlite/cloudflare.d.ts.map +1 -1
- package/dist/sqlite/cloudflare.js +10 -0
- package/dist/sqlite/cloudflare.js.map +1 -1
- package/dist/sqlite/database.d.ts +5 -2
- package/dist/sqlite/database.d.ts.map +1 -1
- package/dist/sqlite/database.js.map +1 -1
- package/dist/sqlite/node.d.ts +4 -1
- package/dist/sqlite/node.d.ts.map +1 -1
- package/dist/sqlite/node.js +22 -5
- package/dist/sqlite/node.js.map +1 -1
- package/dist/watch.d.ts +194 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +383 -0
- package/dist/watch.js.map +1 -0
- package/dist/wire.d.ts +174 -193
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +81 -80
- package/dist/wire.js.map +1 -1
- package/docs/guide.md +15 -15
- package/docs/next/benchmarks.md +959 -0
- package/docs/next/decisions.md +2957 -0
- package/docs/next/dependencies/book.md +1671 -0
- package/docs/next/dependencies/index.html +2641 -0
- package/docs/next/dependencies/model.md +330 -0
- package/docs/next/design.md +2554 -0
- package/docs/next/durable-observers/book.md +432 -0
- package/docs/next/durable-observers/index.html +517 -0
- package/docs/next/flow-control/book.md +333 -0
- package/docs/next/flow-control/fold/index.html +265 -0
- package/docs/next/flow-control/index.html +548 -0
- package/docs/next/flow-control/window/index.html +228 -0
- package/docs/next/guide-plugins-hosts/book.md +607 -0
- package/docs/next/guide-plugins-hosts/index.html +652 -0
- package/docs/next/http-workers/book.md +378 -0
- package/docs/next/http-workers/index.html +515 -0
- package/docs/next/layer-1.md +311 -0
- package/docs/next/layer-2.md +216 -0
- package/docs/next/plugin-model/book.md +186 -0
- package/docs/next/plugin-model/index.html +310 -0
- package/docs/next/plugin-primer/book.md +273 -0
- package/docs/next/plugin-primer/index.html +430 -0
- package/docs/next/slice-1.md +236 -0
- package/docs/next/slice-10.md +285 -0
- package/docs/next/slice-11.md +93 -0
- package/docs/next/slice-2.md +174 -0
- package/docs/next/slice-3a.md +296 -0
- package/docs/next/slice-3b.md +197 -0
- package/docs/next/slice-4.md +146 -0
- package/docs/next/slice-4a.md +418 -0
- package/docs/next/slice-4b.md +208 -0
- package/docs/next/slice-5.md +281 -0
- package/docs/next/slice-6a.md +676 -0
- package/docs/next/slice-6b.md +332 -0
- package/docs/next/slice-7a.md +130 -0
- package/docs/next/slice-7b/book.md +608 -0
- package/docs/next/slice-7b/index.html +842 -0
- package/docs/next/slice-7b.md +255 -0
- package/docs/next/slice-7c.md +165 -0
- package/docs/next/slice-8.md +194 -0
- package/docs/next/slices.md +230 -0
- package/docs/next/store/book.md +665 -0
- package/docs/next/store/index.html +861 -0
- package/docs/next/store/walkthrough.md +193 -0
- package/docs/spec.md +9 -9
- package/docs/tutorial.md +26 -25
- package/package.json +22 -6
- package/src/delta/README.md +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routines.js","sourceRoot":"","sources":["../../../src/next/host/routines.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,sHAAsH;AACtH,+FAA+F;AAG/F,OAAO,EAAW,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EACN,WAAW,GAMX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAyB,MAAM,UAAU,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAy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EAAE,CAAC;YAC/B,OAAO;QACR,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,QAAQ,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC1C,CAAC;IAED,6GAA6G;IAC7G,IAAI,CAAC,GAAa;QACjB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QAChC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrF,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IACrG,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D,CAAC;CACD","sourcesContent":["// Routines (§14): the standing behaviour an object or a facet declares, `self.on(source, fn)` and `self.onLive(fn)`.\n// They start once their owner went live and stop when it ends (their ctx aborted, the drain waits for running calls);\n// each call gets its own ctx; a call that throws is reported and called again after a backoff.\n\nimport type { Context } from \"../../context/index.ts\";\nimport { type Op, PendingOps } from \"../../delta/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport {\n\tNativeWatch,\n\ttype NativeWatchable,\n\ttype NativeWatchCall,\n\ttype Watchable,\n\ttype WatchCall,\n\ttype WatchEnd,\n} from \"../../watch.ts\";\nimport type { Principal } from \"../data/index.ts\";\nimport { NativeSource, Source } from \"../state/internal.ts\";\nimport { nextDelay } from \"./backoff.ts\";\nimport { CallContext, type Caller, type Ctx } from \"./ctx.ts\";\nimport type { AnyHost, Position } from \"./host.ts\";\nimport { resolveWatchable } from \"./reference.ts\";\nimport { sleep } from \"./sleep.ts\";\n\n/**\n * Where routines run: their owner's label (for reports), its host, whom their calls act for, and the context of their\n * calls, aborted when the owner ends. `admit` adds a running call to the owner's drain.\n */\nexport type RoutineOwner = {\n\treadonly label: string;\n\treadonly host: AnyHost;\n\treadonly caller: Caller;\n\treadonly context: Context;\n\t/**\n\t * Adds a running call to the drain; `cleanup` (its bookkeeping) runs once, when it settles or when the attempt ends\n\t * with it still running.\n\t */\n\tadmit(running: Promise<unknown>, cleanup: () => void): void;\n};\n\n/**\n * A routine's handler of a JSON source: the value call (the value, the ops since the previous call, whether the\n * source's document was retired since then) and the call's ctx. Failures are not calls of a handler (design §11): the\n * routine waits for the next value.\n */\nexport type OnHandler<T, C extends Ctx = Ctx> = (call: WatchValueCall<T>, ctx: C) => void | Promise<void>;\n\n/** A JSON watch's value call: what an `on` handler gets. */\nexport type WatchValueCall<T> = Extract<WatchCall<T>, { readonly kind: \"value\" }>;\n\n/** A native watch's value call. */\nexport type NativeWatchValueCall<T> = Extract<NativeWatchCall<T>, { readonly kind: \"value\" }>;\n\n/** A routine's handler of a native source: the value call (the value) and the call's ctx. */\nexport type OnNativeHandler<T, C extends Ctx = Ctx> = (call: NativeWatchValueCall<T>, ctx: C) => void | Promise<void>;\n\n/** An `onLive` routine: called once its owner is live. */\nexport type OnLiveHandler<C extends Ctx = Ctx> = (ctx: C) => void | Promise<void>;\n\n/** What the declarations of an owner (`on`, `onLive`) take; part of the factory's `self` and the facet's. */\nexport interface RoutineDeclarations<P extends Principal = Principal> {\n\t/**\n\t * A routine over `source`: `fn` gets its current value first (ops `[[\"r\", value]]`), then one call per change,\n\t * never overlapping: changes during a call fold into one next call (the newest value, the ops since the previous\n\t * call, `retired` when any of them was a retirement). After a call that threw, it is called again with the whole\n\t * newest value (`retired` again if the call that threw had it) after a backoff (1 s doubling to 60 s), or at once on\n\t * a change during the backoff. Ends with its source. A JSON watchable is one whose watch is Chord's shared `Watch`\n\t * (every Chord and Durable source).\n\t */\n\ton<T>(source: Watchable<T>, fn: OnHandler<T, Ctx<P>>): void;\n\t/**\n\t * A routine over a native source (a registry value, `ref.state`): one whose watch is Chord's shared `NativeWatch`.\n\t * As above without ops: after a busy call, one call with the newest value.\n\t */\n\ton<T>(source: NativeWatchable<T>, fn: OnNativeHandler<T, Ctx<P>>): void;\n\t/**\n\t * A routine called once its owner is live. Returning ends it; a throw is reported and restarts it after a backoff\n\t * (1 s doubling to 60 s, reset after a run of a minute); the owner's end aborts its ctx.\n\t */\n\tonLive(fn: OnLiveHandler<Ctx<P>>): void;\n}\n\n/** A declared routine: its kind and position in reports (`{ kind: \"on\", position: 2 }`), its source and its handler. */\ntype Declaration =\n\t| {\n\t\t\treadonly kind: \"on\";\n\t\t\treadonly at: Position;\n\t\t\treadonly source: Watchable<unknown> | NativeWatchable<unknown>;\n\t\t\treadonly fn: (...args: never[]) => void | Promise<void>;\n\t }\n\t| { readonly kind: \"onLive\"; readonly at: Position; readonly fn: OnLiveHandler };\n\n/** How one routine call ended. */\ntype Called = { readonly kind: \"done\" } | { readonly kind: \"failed\"; readonly error: unknown };\n\nconst DONE: Called = { kind: \"done\" };\n\n/** What `#failing` says of a source failed now. */\nconst FAILING = { kind: \"failed\" } as const;\n\n/** One run of an `onLive` that lasted this long resets its backoff. */\nconst LONG_RUN = 60_000;\n\n/** An owner's routines: declared while its factory (or setup) runs, started once when it went live. */\nexport class Routines {\n\treadonly #declared: Declaration[] = [];\n\t#ons = 0;\n\t#lives = 0;\n\n\t/** Declares `on(source, fn)`; whether the source is JSON or native is decided by its watch (`OnRoutine`). */\n\ton(source: Watchable<unknown> | NativeWatchable<unknown>, fn: (...args: never[]) => void | Promise<void>): void {\n\t\tthis.#declared.push({ kind: \"on\", at: { kind: \"on\", position: ++this.#ons }, source, fn });\n\t}\n\n\t/** Whether nothing was declared. */\n\tget empty(): boolean {\n\t\treturn this.#declared.length === 0;\n\t}\n\n\t/** Declares `onLive(fn)`. */\n\tonLive(fn: OnLiveHandler): void {\n\t\tthis.#declared.push({ kind: \"onLive\", at: { kind: \"onLive\", position: ++this.#lives }, fn });\n\t}\n\n\t/**\n\t * Starts every routine for `owner`, which went live; they stop when its context is aborted. A routine whose\n\t * synchronous start ends the owner (an `onLive` releasing its last reference) starts none of the later ones.\n\t */\n\tstart(owner: RoutineOwner): void {\n\t\tfor (const declaration of this.#declared) {\n\t\t\tif (owner.context.abortSignal?.aborted) return;\n\t\t\tif (declaration.kind === \"on\") void new OnRoutine(owner, declaration).start();\n\t\t\telse void live(owner, declaration);\n\t\t}\n\t}\n}\n\n/**\n * Runs `onLive`'s handler until it returns or its owner ends; a throw is reported and the handler restarts after the\n * backoff.\n */\nasync function live(owner: RoutineOwner, { at, fn }: Extract<Declaration, { kind: \"onLive\" }>): Promise<void> {\n\tlet delay: number | undefined;\n\twhile (!owner.context.abortSignal?.aborted) {\n\t\tconst started = Date.now();\n\t\tconst called = await call(owner, fn);\n\t\tif (called.kind === \"done\" || owner.context.abortSignal?.aborted) return;\n\t\tfailed(owner, at, called.error);\n\t\tdelay = nextDelay(Date.now() - started >= LONG_RUN ? undefined : delay);\n\t\ttry {\n\t\t\tawait sleep(delay, owner.context);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n/**\n * Runs one routine call under its own ctx (its `ctx.get` references released when it settles), admitted to the owner's\n * drain before the handler runs: a handler may end its own owner before its first await. Resolves with how it ended;\n * never rejects.\n */\nfunction call(owner: RoutineOwner, invoke: (ctx: Ctx) => void | Promise<void>): Promise<Called> {\n\tconst ctx = new CallContext(owner.context, owner.caller, owner.host);\n\tconst settled = Promise.withResolvers<Called>();\n\towner.admit(settled.promise, () => ctx.settle());\n\tconst finish = (called: Called): void => {\n\t\tctx.settle();\n\t\tsettled.resolve(called);\n\t};\n\t// Plugin code: a synchronous throw becomes the rejection.\n\t(async () => invoke(ctx))().then(\n\t\t() => finish(DONE),\n\t\t(error: unknown) => finish({ kind: \"failed\", error }),\n\t);\n\treturn settled.promise;\n}\n\n/** Reports a failed routine call or source. */\nfunction failed(owner: RoutineOwner, routine: Position, error: unknown): void {\n\towner.host.report({ kind: \"routine_failed\", object: owner.label, routine, error });\n}\n\n/**\n * Where an `on` routine stands. `starting`: taking its watch; `idle`: waiting for a change; `calling`: a call runs\n * (changes meanwhile wait, folded, for the next); `settling`: a call succeeded while changes arrived, and the next one\n * waits for one macrotask, so every value its watch still buffers (a native watch replays them one per microtask) is\n * taken first; `backoff`: the last call threw and its timer calls again, unless a change during the backoff calls\n * first; `ended`: its watch ended (the owner ended, or the source ended or failed).\n */\ntype OnState =\n\t| { readonly kind: \"starting\" | \"idle\" | \"calling\" | \"ended\" }\n\t| { readonly kind: \"settling\" | \"backoff\"; readonly timer: ReturnType<typeof setTimeout> };\n\n/**\n * What the next call's ops are relative to: `none` before the first call and after a throw (the handler may not have\n * applied what it got: the next call gets the whole value), `last` after a call that succeeded.\n */\ntype Basis = \"none\" | \"last\";\n\n/**\n * One `on` routine. Its watch's listener never throws (a throwing listener would end the watch) and never waits: it\n * keeps the newest frame, folding JSON ops, and the routine makes one call at a time from it, the first call and the\n * retries after a throw through the same pending frame.\n */\nclass OnRoutine {\n\treadonly #owner: RoutineOwner;\n\treadonly #declaration: Extract<Declaration, { kind: \"on\" }>;\n\t#state: OnState = { kind: \"starting\" };\n\t/** A native source's watch yields values without ops; decided by its watch's class. */\n\t#native = false;\n\t/** The newest value no call got yet. */\n\t#pending: { readonly value: unknown } | undefined;\n\t/** The ops of the frames since the last call (JSON sources), folded. */\n\treadonly #ops = new PendingOps();\n\t/** One of the frames since the last call was a retirement (JSON sources). */\n\t#retired = false;\n\t#basis: Basis = \"none\";\n\t/** The value of the last call: a retry after a throw calls with it. */\n\t#last: unknown;\n\t/** The last call reported a retirement: a retry after a throw reports it again. */\n\t#lastRetired = false;\n\t#delay: number | undefined;\n\t/** The source failed after its last value: no call until its next value (a retry waits too). */\n\t#failed = false;\n\n\tconstructor(owner: RoutineOwner, declaration: Extract<Declaration, { kind: \"on\" }>) {\n\t\tthis.#owner = owner;\n\t\tthis.#declaration = declaration;\n\t}\n\n\t/**\n\t * Takes the watch and calls with its value. On a failed Chord source it waits for its first good value instead (a\n\t * source that never had one is followed until it has). A source that cannot be watched otherwise is reported; an\n\t * owner or source that ended meanwhile ends the routine. Never rejects.\n\t */\n\tasync start(): Promise<void> {\n\t\tconst { source, at } = this.#declaration;\n\t\tlet failing = this.#failing();\n\t\twhile (failing?.kind === \"no_value\") {\n\t\t\tif (!(await this.#firstValue(failing.source))) {\n\t\t\t\tthis.#state = { kind: \"ended\" };\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Asked again: a failure may have followed the first value before this resumed (one receive turn).\n\t\t\tfailing = this.#failing();\n\t\t}\n\t\tlet watch: Awaited<ReturnType<typeof source.watch>>;\n\t\ttry {\n\t\t\twatch = await source.watch(this.#owner.context);\n\t\t} catch (error) {\n\t\t\tthis.#state = { kind: \"ended\" };\n\t\t\tif (!this.#aborted()) failed(this.#owner, at, error);\n\t\t\treturn;\n\t\t}\n\t\tthis.#native = watch instanceof NativeWatch;\n\t\tvoid watch.closed.then((end) => this.#end(end));\n\t\ttry {\n\t\t\t// Both listeners return at once.\n\t\t\twatch.start((call: WatchCall<unknown> | NativeWatchCall<unknown>) => {\n\t\t\t\tif (call.kind === \"value\") this.#frame(call);\n\t\t\t\telse this.#failure();\n\t\t\t\treturn Promise.resolve();\n\t\t\t});\n\t\t} catch {\n\t\t\t// The watch ended while it was taken (the owner or the source ended): `closed` says how.\n\t\t\treturn;\n\t\t}\n\t\t// A watch opened on a failed source holds its last good value, a stale one: its first call is the failure.\n\t\tif (failing?.kind === \"failed\") {\n\t\t\tthis.#state = { kind: \"idle\" };\n\t\t\treturn;\n\t\t}\n\t\tthis.#pending = { value: watch.value };\n\t\tthis.#next();\n\t}\n\n\t/**\n\t * Whether the source is a Chord source failed now (`failed`), or a JSON one with no value yet (`no_value`, with the\n\t * source to follow); `undefined` otherwise (Durable's views tell their failures through their watches).\n\t */\n\t#failing(): { readonly kind: \"failed\" } | { readonly kind: \"no_value\"; readonly source: Source } | undefined {\n\t\tconst declared = this.#declaration.source;\n\t\t// A native source opens its watch at its last good value while failed (a registry whose `compose` threw): its\n\t\t// first call is the failure, not that stale value.\n\t\tif (declared instanceof NativeSource) return declared.start().kind === \"failed\" ? FAILING : undefined;\n\t\tlet source: unknown;\n\t\ttry {\n\t\t\tsource = resolveWatchable(this.#declaration.source);\n\t\t} catch {\n\t\t\t// Not bound or ended: the watch says so.\n\t\t\treturn undefined;\n\t\t}\n\t\tif (!(source instanceof Source)) return undefined;\n\t\tlet start: ReturnType<Source[\"start\"]>;\n\t\ttry {\n\t\t\tstart = source.start();\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (start.kind === \"value\") return undefined;\n\t\treturn start.last === undefined ? { kind: \"no_value\", source } : { kind: \"failed\" };\n\t}\n\n\t/**\n\t * Follows `source`, failed with no value, until its first good value (`true`), or until it or the owner ends\n\t * (`false`): a subscriber of its own, since a watch has nothing to start at.\n\t */\n\t#firstValue(source: Source): Promise<boolean> {\n\t\tconst signal = this.#owner.context.abortSignal;\n\t\treturn new Promise((resolve) => {\n\t\t\tconst done = (got: boolean): void => {\n\t\t\t\tsource.unsubscribe(subscriber);\n\t\t\t\tsignal?.removeEventListener(\"abort\", aborted);\n\t\t\t\tresolve(got);\n\t\t\t};\n\t\t\tconst subscriber = {\n\t\t\t\tadvance: (call: WatchCall<JsonValue>) => {\n\t\t\t\t\tif (call.kind === \"value\") done(true);\n\t\t\t\t},\n\t\t\t\tend: () => done(false),\n\t\t\t\tendAfterDelivery: () => done(false),\n\t\t\t};\n\t\t\tconst aborted = (): void => done(false);\n\t\t\tsignal?.addEventListener(\"abort\", aborted, { once: true });\n\t\t\tif (signal?.aborted) aborted();\n\t\t\telse source.subscribe(subscriber);\n\t\t});\n\t}\n\n\t/**\n\t * The source failed: what was pending goes (a value a failure followed is stale), a pending retry or settle is\n\t * dropped, and the next call waits for the next value, as a whole value; a running call runs on.\n\t */\n\t#failure(): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"ended\") return;\n\t\tthis.#failed = true;\n\t\tthis.#pending = undefined;\n\t\tthis.#ops.take();\n\t\tthis.#basis = \"none\";\n\t\tif (state.kind === \"backoff\" || state.kind === \"settling\") {\n\t\t\tclearTimeout(state.timer);\n\t\t\tthis.#state = { kind: \"idle\" };\n\t\t}\n\t}\n\n\t/**\n\t * A frame of the watch: kept as the newest; it is called at once when nothing runs or waits, during a backoff too\n\t * (the backoff ends); while a call runs or settles it waits for the next call.\n\t */\n\t#frame(call: WatchValueCall<unknown> | NativeWatchValueCall<unknown>): void {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"ended\") return;\n\t\tthis.#failed = false;\n\t\tthis.#pending = { value: call.value };\n\t\tif (!this.#native) {\n\t\t\t// A JSON watch's call, as its class decided.\n\t\t\tconst { ops, retired } = call as WatchValueCall<unknown>;\n\t\t\tthis.#ops.push(ops);\n\t\t\tif (retired) this.#retired = true;\n\t\t}\n\t\tif (state.kind === \"backoff\") clearTimeout(state.timer);\n\t\tif (state.kind === \"backoff\" || state.kind === \"idle\") this.#next();\n\t}\n\n\t/** Makes the next call from the pending frame, if there is one and the owner still runs; otherwise idles. */\n\t#next(): void {\n\t\tconst pending = this.#pending;\n\t\tif (pending === undefined || this.#aborted()) {\n\t\t\tthis.#state = { kind: \"idle\" };\n\t\t\treturn;\n\t\t}\n\t\tthis.#pending = undefined;\n\t\tconst { value } = pending;\n\t\tthis.#state = { kind: \"calling\" };\n\t\tthis.#last = value;\n\t\tvoid call(this.#owner, this.#invocation(value)).then((called) => this.#called(called));\n\t}\n\n\t/**\n\t * The handler's call with `value`: a native one with the value alone, a JSON one with the folded ops or the whole\n\t * value, and whether a retirement came since the last call.\n\t */\n\t#invocation(value: unknown): (ctx: Ctx) => void | Promise<void> {\n\t\tconst { fn } = this.#declaration;\n\t\t// The overloads typed `fn` for its source's kind, which the watch decided.\n\t\tif (this.#native) return (ctx) => (fn as OnNativeHandler<unknown>)({ kind: \"value\", value }, ctx);\n\t\tconst taken = this.#ops.take();\n\t\t// A JSON source's values are JSON.\n\t\tconst ops: readonly Op[] =\n\t\t\tthis.#basis === \"none\" || taken.kind === \"replace\" ? [[\"r\", value as JsonValue]] : taken.ops;\n\t\tconst retired = this.#retired;\n\t\tthis.#retired = false;\n\t\tthis.#lastRetired = retired;\n\t\treturn (ctx) => (fn as OnHandler<unknown>)({ kind: \"value\", value, ops, retired }, ctx);\n\t}\n\n\t/**\n\t * A call settled. After a success the next frame's ops build on it, and changes that arrived during the call are\n\t * called after one macrotask (`settling`). After a throw (reported) the backoff always starts, also when changes\n\t * arrived during the call (a handler that changes its own source and throws would feed itself otherwise); its timer\n\t * calls with the newest value, or the last call's, as a whole value.\n\t */\n\t#called(called: Called): void {\n\t\tif (this.#state.kind === \"ended\") return;\n\t\tif (called.kind === \"done\") {\n\t\t\tthis.#basis = \"last\";\n\t\t\tthis.#delay = undefined;\n\t\t\tif (this.#pending === undefined) this.#state = { kind: \"idle\" };\n\t\t\telse this.#state = { kind: \"settling\", timer: setTimeout(() => this.#next(), 0) };\n\t\t\treturn;\n\t\t}\n\t\tif (this.#aborted()) return;\n\t\tfailed(this.#owner, this.#declaration.at, called.error);\n\t\tthis.#basis = \"none\";\n\t\t// The handler may not have applied the retirement either.\n\t\tif (this.#lastRetired) this.#retired = true;\n\t\tthis.#delay = nextDelay(this.#delay);\n\t\t// The source failed meanwhile: the retry waits for its next value, never the stale last one.\n\t\tif (this.#failed) {\n\t\t\tthis.#state = { kind: \"idle\" };\n\t\t\treturn;\n\t\t}\n\t\tconst timer = setTimeout(() => {\n\t\t\tthis.#pending ??= { value: this.#last };\n\t\t\tthis.#next();\n\t\t}, this.#delay);\n\t\tthis.#state = { kind: \"backoff\", timer };\n\t}\n\n\t/** The watch ended: the owner ended (aborted), or the source ended (no report) or failed (reported once). */\n\t#end(end: WatchEnd): void {\n\t\tconst state = this.#state;\n\t\tthis.#state = { kind: \"ended\" };\n\t\tif (state.kind === \"settling\" || state.kind === \"backoff\") clearTimeout(state.timer);\n\t\tthis.#pending = undefined;\n\t\tthis.#ops.take();\n\t\tthis.#retired = false;\n\t\tif (end.kind === \"failed\" && !this.#aborted()) failed(this.#owner, this.#declaration.at, end.error);\n\t}\n\n\t#aborted(): boolean {\n\t\treturn this.#owner.context.abortSignal?.aborted === true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves after `ms` milliseconds; rejects with the abort reason once `context` is aborted, clearing its timer and
|
|
4
|
+
* listener. Delays above the timer limit (2^31-1 ms) are chained timers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function sleep(ms: number, context: Context): Promise<void>;
|
|
7
|
+
/** Resolves once `context` is aborted (never without an abort signal); leaves no listener behind. */
|
|
8
|
+
export declare function untilAborted(context: Context): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=sleep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../src/next/host/sleep.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAKtD;;;GAGG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBjE;AAED,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5D"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Waiting helpers for routines, jobs and handlers (§14): `sleep(ms, ctx)` and `untilAborted(ctx)`, which end with
|
|
2
|
+
// their context, leaving no timer or listener behind. Portable: timers and `AbortSignal` only.
|
|
3
|
+
/** The longest delay one timer takes (a longer one fires at once). */
|
|
4
|
+
const MAX_TIMER = 2 ** 31 - 1;
|
|
5
|
+
/**
|
|
6
|
+
* Resolves after `ms` milliseconds; rejects with the abort reason once `context` is aborted, clearing its timer and
|
|
7
|
+
* listener. Delays above the timer limit (2^31-1 ms) are chained timers.
|
|
8
|
+
*/
|
|
9
|
+
export function sleep(ms, context) {
|
|
10
|
+
const signal = context.abortSignal;
|
|
11
|
+
if (signal?.aborted)
|
|
12
|
+
return Promise.reject(signal.reason);
|
|
13
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
14
|
+
let timer;
|
|
15
|
+
const abort = () => {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
reject(signal?.reason);
|
|
18
|
+
};
|
|
19
|
+
const wait = (left) => {
|
|
20
|
+
timer = setTimeout(() => {
|
|
21
|
+
if (left > MAX_TIMER)
|
|
22
|
+
return wait(left - MAX_TIMER);
|
|
23
|
+
signal?.removeEventListener("abort", abort);
|
|
24
|
+
resolve();
|
|
25
|
+
}, Math.min(left, MAX_TIMER));
|
|
26
|
+
};
|
|
27
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
28
|
+
wait(ms);
|
|
29
|
+
return promise;
|
|
30
|
+
}
|
|
31
|
+
/** Resolves once `context` is aborted (never without an abort signal); leaves no listener behind. */
|
|
32
|
+
export function untilAborted(context) {
|
|
33
|
+
const signal = context.abortSignal;
|
|
34
|
+
if (signal === undefined)
|
|
35
|
+
return new Promise(() => { });
|
|
36
|
+
if (signal.aborted)
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
return new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../../src/next/host/sleep.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,+FAA+F;AAI/F,sEAAsE;AACtE,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,EAAU,EAAE,OAAgB;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IACnC,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAC;IACnE,IAAI,KAAgD,CAAC;IACrD,MAAM,KAAK,GAAG,GAAS,EAAE;QACxB,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,CAAC,IAAY,EAAQ,EAAE;QACnC,KAAK,GAAG,UAAU,CACjB,GAAG,EAAE;YACJ,IAAI,IAAI,GAAG,SAAS;gBAAE,OAAO,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;YACpD,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC;QACX,CAAC,EACD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CACzB,CAAC;IACH,CAAC,CAAC;IACF,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACpG,CAAC","sourcesContent":["// Waiting helpers for routines, jobs and handlers (§14): `sleep(ms, ctx)` and `untilAborted(ctx)`, which end with\n// their context, leaving no timer or listener behind. Portable: timers and `AbortSignal` only.\n\nimport type { Context } from \"../../context/index.ts\";\n\n/** The longest delay one timer takes (a longer one fires at once). */\nconst MAX_TIMER = 2 ** 31 - 1;\n\n/**\n * Resolves after `ms` milliseconds; rejects with the abort reason once `context` is aborted, clearing its timer and\n * listener. Delays above the timer limit (2^31-1 ms) are chained timers.\n */\nexport function sleep(ms: number, context: Context): Promise<void> {\n\tconst signal = context.abortSignal;\n\tif (signal?.aborted) return Promise.reject(signal.reason);\n\tconst { promise, resolve, reject } = Promise.withResolvers<void>();\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst abort = (): void => {\n\t\tclearTimeout(timer);\n\t\treject(signal?.reason);\n\t};\n\tconst wait = (left: number): void => {\n\t\ttimer = setTimeout(\n\t\t\t() => {\n\t\t\t\tif (left > MAX_TIMER) return wait(left - MAX_TIMER);\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\tMath.min(left, MAX_TIMER),\n\t\t);\n\t};\n\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\twait(ms);\n\treturn promise;\n}\n\n/** Resolves once `context` is aborted (never without an abort signal); leaves no listener behind. */\nexport function untilAborted(context: Context): Promise<void> {\n\tconst signal = context.abortSignal;\n\tif (signal === undefined) return new Promise(() => {});\n\tif (signal.aborted) return Promise.resolve();\n\treturn new Promise((resolve) => signal.addEventListener(\"abort\", () => resolve(), { once: true }));\n}\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Context } from "../../context/index.ts";
|
|
2
|
+
import type { Watchable } from "../../watch.ts";
|
|
3
|
+
import type { Contract, ParamsOf } from "../contracts/index.ts";
|
|
4
|
+
import type { Principal } from "../data/index.ts";
|
|
5
|
+
import type { AnyDefinition } from "../documents/internal.ts";
|
|
6
|
+
import type { JobDefinition } from "../jobs/index.ts";
|
|
7
|
+
import type { Registry, RegistryProvider } from "../registries/index.ts";
|
|
8
|
+
import type { TableDefinition } from "../store/table.ts";
|
|
9
|
+
import { type Facet, type FacetContribution } from "./facet.ts";
|
|
10
|
+
import type { ChordObject, Served } from "./object.ts";
|
|
11
|
+
import type { Presence } from "./presence.ts";
|
|
12
|
+
/** A plugin's facet as `load` and `reload` take it: its name (its `package.json` name) and its facet. */
|
|
13
|
+
export type PluginFacet<P extends Principal = Principal> = {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly facet: Facet<P>;
|
|
16
|
+
};
|
|
17
|
+
/** A registry a staged plugin serves: the defining plugin, the token and its provider. */
|
|
18
|
+
export type StagedRegistry = {
|
|
19
|
+
readonly plugin: string;
|
|
20
|
+
readonly registry: Registry<unknown, unknown>;
|
|
21
|
+
readonly provider: RegistryProvider<unknown, unknown>;
|
|
22
|
+
};
|
|
23
|
+
/** One plugin's setup, run and checked: what it serves and contributes, nothing published yet. */
|
|
24
|
+
export type StagedPlugin = {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** The served types by name, each with its plugin, factory, provider (its `accepts` checked) and `linger`. */
|
|
27
|
+
readonly types: ReadonlyMap<string, Served>;
|
|
28
|
+
/** The served registries by name. */
|
|
29
|
+
readonly registries: ReadonlyMap<string, StagedRegistry>;
|
|
30
|
+
/** The facet contributions, in the setup's order. */
|
|
31
|
+
readonly contributions: readonly FacetContribution[];
|
|
32
|
+
};
|
|
33
|
+
/** A plugin set's staged plugins, merged: what they serve, by name, and each plugin's own table. */
|
|
34
|
+
export type Staged = {
|
|
35
|
+
readonly types: Map<string, Served>;
|
|
36
|
+
readonly registries: Map<string, StagedRegistry>;
|
|
37
|
+
readonly plugins: Map<string, StagedPlugin>;
|
|
38
|
+
};
|
|
39
|
+
/** What staging needs of its host: whom it acts as, where it lives, and its presence lists for setups. */
|
|
40
|
+
export type StagingHost = {
|
|
41
|
+
readonly principal: Principal | undefined;
|
|
42
|
+
readonly address: unknown;
|
|
43
|
+
references<C extends Contract>(Type: C): Watchable<readonly Presence<C, Principal>[]>;
|
|
44
|
+
};
|
|
45
|
+
/** Whether `name` is a valid plugin name: an npm package name, scoped or not (the plugins component checks it too). */
|
|
46
|
+
export declare function isPluginName(name: string): boolean;
|
|
47
|
+
/** A staged table with nothing in it. */
|
|
48
|
+
export declare function emptyStaged(): Staged;
|
|
49
|
+
/**
|
|
50
|
+
* Runs one plugin's setup and checks what it declared: its name (an npm name), a type or registry it serves twice, a
|
|
51
|
+
* remote type on a host without a principal or address, every provider's `accepts` (`checkAccepts`) and every registry
|
|
52
|
+
* provider's shape. Throws the first error, naming the plugin.
|
|
53
|
+
*/
|
|
54
|
+
export declare function stagePlugin<P extends Principal>({ name, facet }: PluginFacet<P>, host: StagingHost): StagedPlugin;
|
|
55
|
+
/**
|
|
56
|
+
* Merges `plugin` into `staged`; a type or registry another plugin serves there already refuses it (its error
|
|
57
|
+
* returned, nothing merged).
|
|
58
|
+
*/
|
|
59
|
+
export declare function addStaged(staged: Staged, plugin: StagedPlugin): Error | undefined;
|
|
60
|
+
/** What a recorded factory declared: what a reload's fate and checks need, nothing activated. */
|
|
61
|
+
export type Recorded = {
|
|
62
|
+
/** How many natives it opens (`self.open`). */
|
|
63
|
+
readonly natives: number;
|
|
64
|
+
readonly documents: readonly AnyDefinition[];
|
|
65
|
+
readonly tables: readonly TableDefinition[];
|
|
66
|
+
readonly jobs: readonly JobDefinition<unknown, unknown, unknown>[];
|
|
67
|
+
readonly contributions: readonly Registry<unknown, unknown>[];
|
|
68
|
+
/** Its requests: the types it gets (`self.get`, with their checked params) and the registries it reads (`self.registry`). */
|
|
69
|
+
readonly requests: readonly Request[];
|
|
70
|
+
};
|
|
71
|
+
/** A recorded request, with the contract version it was made at: a type and its params, or a registry. */
|
|
72
|
+
export type Request = {
|
|
73
|
+
readonly kind: "type";
|
|
74
|
+
readonly contract: Contract;
|
|
75
|
+
readonly params: ParamsOf<Contract>;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: "registry";
|
|
78
|
+
readonly registry: Registry<unknown, unknown>;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Runs `served`'s factory for `object` (its params and principal) against a recording `self` and returns what it
|
|
82
|
+
* declared. Every declaration check an attempt makes runs, without effects (declared twice; persisted data in a type
|
|
83
|
+
* without a stable identity, on a host without a store, or claimed by another owner; contributions outside
|
|
84
|
+
* host-lifetime objects, or twice; `retryOn` sources that do not outlive the attempt; params; a document or job
|
|
85
|
+
* declared at an older version than the object's, or at its version with another schema); a throw is the factory's.
|
|
86
|
+
* Handles it hands out are inert, except registry values (the host's own, which `retryOn` checks by kind).
|
|
87
|
+
*/
|
|
88
|
+
export declare function recordFactory(object: ChordObject, served: Served, context: Context): Recorded;
|
|
89
|
+
/**
|
|
90
|
+
* Whether `recorded`'s tables are at a version newer than `object`'s store has them: their eager migration runs at an
|
|
91
|
+
* activation, so the object restarts instead of swapping (§4).
|
|
92
|
+
*/
|
|
93
|
+
export declare function migratesTables(object: ChordObject, recorded: Recorded): boolean;
|
|
94
|
+
//# sourceMappingURL=staging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.d.ts","sourceRoot":"","sources":["../../../src/next/host/staging.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAIzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,iBAAiB,EAA2B,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EAAE,WAAW,EAAiC,MAAM,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,yGAAyG;AACzG,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAE/G,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OA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M,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAQ/E"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// Staging (slice 7b §2; per plugin, decision "Per plugin at startup and reload"): each plugin's setup runs into a table of
|
|
2
|
+
// its own (the types it serves with their providers, the registries it serves, its facet contributions) with `load`'s
|
|
3
|
+
// checks, merged into the staged table beside the live one, where a type or registry another plugin serves already
|
|
4
|
+
// fails the plugin; and an object's new factory run against a recording `self`, which keeps what the factory declares
|
|
5
|
+
// (natives, documents, tables, jobs, contributions, requests with their contract versions) and activates, binds and
|
|
6
|
+
// opens nothing, so a reload decides each object's fate, and which plugins keep their old code, before its commit.
|
|
7
|
+
// `load` stages its facets the same way and publishes them.
|
|
8
|
+
import { contractData } from "../contracts/internal.js";
|
|
9
|
+
import { bindProvider, checkParams } from "../data/internal.js";
|
|
10
|
+
import { checkProvider } from "../registries/internal.js";
|
|
11
|
+
import { tableSqlName } from "../store/sql.js";
|
|
12
|
+
import { setUp } from "./facet.js";
|
|
13
|
+
import { retrySource } from "./retry-on.js";
|
|
14
|
+
/** An npm package name, scoped or not. */
|
|
15
|
+
const PLUGIN_NAME = /^(?:@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/;
|
|
16
|
+
/** Whether `name` is a valid plugin name: an npm package name, scoped or not (the plugins component checks it too). */
|
|
17
|
+
export function isPluginName(name) {
|
|
18
|
+
return PLUGIN_NAME.test(name);
|
|
19
|
+
}
|
|
20
|
+
/** A staged table with nothing in it. */
|
|
21
|
+
export function emptyStaged() {
|
|
22
|
+
return { types: new Map(), registries: new Map(), plugins: new Map() };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Runs one plugin's setup and checks what it declared: its name (an npm name), a type or registry it serves twice, a
|
|
26
|
+
* remote type on a host without a principal or address, every provider's `accepts` (`checkAccepts`) and every registry
|
|
27
|
+
* provider's shape. Throws the first error, naming the plugin.
|
|
28
|
+
*/
|
|
29
|
+
export function stagePlugin({ name, facet }, host) {
|
|
30
|
+
if (!isPluginName(name))
|
|
31
|
+
throw new Error(`"${name}" is not a valid plugin name`);
|
|
32
|
+
// The host's presence lists are typed for its `P`.
|
|
33
|
+
const references = host.references;
|
|
34
|
+
const types = new Map();
|
|
35
|
+
const registries = new Map();
|
|
36
|
+
try {
|
|
37
|
+
const { served, contributions } = setUp(name, facet, references);
|
|
38
|
+
for (const entry of served)
|
|
39
|
+
stageEntry(name, entry, types, registries, host);
|
|
40
|
+
return { name, types, registries, contributions };
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw named(error, `plugin "${name}"`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Merges `plugin` into `staged`; a type or registry another plugin serves there already refuses it (its error
|
|
48
|
+
* returned, nothing merged).
|
|
49
|
+
*/
|
|
50
|
+
export function addStaged(staged, plugin) {
|
|
51
|
+
for (const name of plugin.types.keys()) {
|
|
52
|
+
const other = staged.types.get(name);
|
|
53
|
+
if (other !== undefined)
|
|
54
|
+
return new Error(`plugin "${plugin.name}": ${name} is served twice (plugin "${other.plugin}")`);
|
|
55
|
+
}
|
|
56
|
+
for (const name of plugin.registries.keys()) {
|
|
57
|
+
const other = staged.registries.get(name);
|
|
58
|
+
if (other !== undefined) {
|
|
59
|
+
return new Error(`plugin "${plugin.name}": registry ${name} is served twice (plugin "${other.plugin}")`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const [name, served] of plugin.types)
|
|
63
|
+
staged.types.set(name, served);
|
|
64
|
+
for (const [name, registry] of plugin.registries)
|
|
65
|
+
staged.registries.set(name, registry);
|
|
66
|
+
staged.plugins.set(plugin.name, plugin);
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/** Stages one served entry of `plugin` into its tables: a registry's provider, or a type as `Served`. */
|
|
70
|
+
function stageEntry(plugin, entry, types, registries, host) {
|
|
71
|
+
if (entry.kind === "registry") {
|
|
72
|
+
const { registry, provider } = entry;
|
|
73
|
+
if (registries.has(registry.name))
|
|
74
|
+
throw new Error(`registry ${registry.name} is served twice`);
|
|
75
|
+
checkProvider(registry.name, provider);
|
|
76
|
+
registries.set(registry.name, { plugin, registry, provider });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const { contract, factory, options } = entry;
|
|
80
|
+
if (types.has(contract.name))
|
|
81
|
+
throw new Error(`${contract.name} is served twice`);
|
|
82
|
+
// A client serves only local types (§3): a remote object is owned by a principal of the host serving it.
|
|
83
|
+
if (contract.kind === "remote" && host.principal === undefined) {
|
|
84
|
+
throw new Error(`${contract.name}: a host without a principal serves only local types`);
|
|
85
|
+
}
|
|
86
|
+
// A remote object lives on the host its `hostAddress` names: only a host with an address can be that host.
|
|
87
|
+
if (contract.kind === "remote" && host.address === undefined) {
|
|
88
|
+
throw new Error(`${contract.name}: a host without an address serves only local types`);
|
|
89
|
+
}
|
|
90
|
+
const provider = bindProvider(contract, options.accepts ?? {});
|
|
91
|
+
const common = { plugin, provider, linger: options.linger ?? 0 };
|
|
92
|
+
// The contract's kind decides the factory's signature and the contract's shape.
|
|
93
|
+
const served = contract.kind === "local"
|
|
94
|
+
? {
|
|
95
|
+
...common,
|
|
96
|
+
kind: "local",
|
|
97
|
+
contract: contract,
|
|
98
|
+
factory: factory,
|
|
99
|
+
hostLifetime: contractData(contract).params.fields.length === 0,
|
|
100
|
+
}
|
|
101
|
+
: {
|
|
102
|
+
...common,
|
|
103
|
+
kind: "remote",
|
|
104
|
+
contract: contract,
|
|
105
|
+
factory: factory,
|
|
106
|
+
};
|
|
107
|
+
types.set(contract.name, served);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Runs `served`'s factory for `object` (its params and principal) against a recording `self` and returns what it
|
|
111
|
+
* declared. Every declaration check an attempt makes runs, without effects (declared twice; persisted data in a type
|
|
112
|
+
* without a stable identity, on a host without a store, or claimed by another owner; contributions outside
|
|
113
|
+
* host-lifetime objects, or twice; `retryOn` sources that do not outlive the attempt; params; a document or job
|
|
114
|
+
* declared at an older version than the object's, or at its version with another schema); a throw is the factory's.
|
|
115
|
+
* Handles it hands out are inert, except registry values (the host's own, which `retryOn` checks by kind).
|
|
116
|
+
*/
|
|
117
|
+
export function recordFactory(object, served, context) {
|
|
118
|
+
const recording = new RecordingSelf(object, served, context);
|
|
119
|
+
// A recording `self` takes every declaration a factory makes, its handles inert.
|
|
120
|
+
const self = recording;
|
|
121
|
+
try {
|
|
122
|
+
if (served.kind === "local")
|
|
123
|
+
served.factory(object.params, self);
|
|
124
|
+
// A remote object's identity has its principal.
|
|
125
|
+
else
|
|
126
|
+
served.factory(object.params, object.principal, self);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throw named(error, `plugin "${served.plugin}", ${object.label}`);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
recording.declaring = false;
|
|
133
|
+
}
|
|
134
|
+
return recording.recorded;
|
|
135
|
+
}
|
|
136
|
+
/** A staging error naming where it happened (`what`): its message prefixed, the error itself its cause. */
|
|
137
|
+
function named(error, what) {
|
|
138
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
139
|
+
return new Error(`${what}: ${message}`, { cause: error });
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The value of every handle a recording `self` hands out: any property or call gives it again, and it is never a
|
|
143
|
+
* thenable. Typed `never` (a cast: it stands for every handle type, and nothing reads it as one).
|
|
144
|
+
*/
|
|
145
|
+
const INERT = new Proxy(() => { }, {
|
|
146
|
+
get: (_target, property) => (property === "then" ? undefined : INERT),
|
|
147
|
+
apply: () => INERT,
|
|
148
|
+
});
|
|
149
|
+
/** A factory's `self` during staging: it records declarations and checks them; it activates nothing. */
|
|
150
|
+
class RecordingSelf {
|
|
151
|
+
declaring = true;
|
|
152
|
+
#object;
|
|
153
|
+
#served;
|
|
154
|
+
#context;
|
|
155
|
+
#natives = 0;
|
|
156
|
+
#documents = new Map();
|
|
157
|
+
#tables = new Map();
|
|
158
|
+
#jobs = new Map();
|
|
159
|
+
#contributions = new Map();
|
|
160
|
+
#requests = [];
|
|
161
|
+
constructor(object, served, context) {
|
|
162
|
+
this.#object = object;
|
|
163
|
+
this.#served = served;
|
|
164
|
+
this.#context = context;
|
|
165
|
+
}
|
|
166
|
+
get recorded() {
|
|
167
|
+
return {
|
|
168
|
+
natives: this.#natives,
|
|
169
|
+
documents: [...this.#documents.values()],
|
|
170
|
+
tables: [...this.#tables.values()],
|
|
171
|
+
jobs: [...this.#jobs.values()],
|
|
172
|
+
contributions: [...this.#contributions.values()],
|
|
173
|
+
requests: this.#requests,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
state(definition) {
|
|
177
|
+
this.#assertDeclaring("state");
|
|
178
|
+
const what = `state "${definition.name}"`;
|
|
179
|
+
if (this.#documents.has(definition.name))
|
|
180
|
+
throw new Error(`${this.#object.label}: ${what} is declared twice`);
|
|
181
|
+
if (definition.persist)
|
|
182
|
+
this.#assertClaimable(what, ["chord"]);
|
|
183
|
+
this.#object.documents.check(definition);
|
|
184
|
+
this.#documents.set(definition.name, definition);
|
|
185
|
+
return INERT;
|
|
186
|
+
}
|
|
187
|
+
table(definition) {
|
|
188
|
+
this.#assertDeclaring("table");
|
|
189
|
+
const store = this.#assertPersistable(`table "${definition.name}"`);
|
|
190
|
+
if (this.#tables.has(definition.name)) {
|
|
191
|
+
throw new Error(`${this.#object.label}: table "${definition.name}" is declared twice`);
|
|
192
|
+
}
|
|
193
|
+
const object = this.#object;
|
|
194
|
+
store.claims.assertTable(tableSqlName(object.served.contract.name, definition.name), object);
|
|
195
|
+
this.#tables.set(definition.name, definition);
|
|
196
|
+
return INERT;
|
|
197
|
+
}
|
|
198
|
+
derive() {
|
|
199
|
+
this.#assertDeclaring("derive");
|
|
200
|
+
return INERT;
|
|
201
|
+
}
|
|
202
|
+
get(Type, params) {
|
|
203
|
+
this.#assertDeclaring("get");
|
|
204
|
+
const checked = checkParams(Type, params, this.#context);
|
|
205
|
+
this.#requests.push({ kind: "type", contract: Type, params: checked.params });
|
|
206
|
+
return INERT;
|
|
207
|
+
}
|
|
208
|
+
registry(R) {
|
|
209
|
+
this.#assertDeclaring("registry");
|
|
210
|
+
this.#requests.push({ kind: "registry", registry: R });
|
|
211
|
+
// The host's own value (an attempt declares the same one): `retryOn` checks its kind.
|
|
212
|
+
return this.#object.host.registryRecord(R.name).value(R.version);
|
|
213
|
+
}
|
|
214
|
+
writable() {
|
|
215
|
+
this.#assertDeclaring("writable");
|
|
216
|
+
return INERT;
|
|
217
|
+
}
|
|
218
|
+
retryOn(...sources) {
|
|
219
|
+
this.#assertDeclaring("retryOn");
|
|
220
|
+
for (const source of sources)
|
|
221
|
+
retrySource(source, this.#object.label);
|
|
222
|
+
}
|
|
223
|
+
contribute(R) {
|
|
224
|
+
this.#assertDeclaring("contribute");
|
|
225
|
+
const served = this.#served;
|
|
226
|
+
const { label } = this.#object;
|
|
227
|
+
// R21: plugin code is bundled without type checks.
|
|
228
|
+
if (served.kind !== "local" || !served.hostLifetime) {
|
|
229
|
+
throw new Error(`${label}: self.contribute is valid only in a local type with empty params`);
|
|
230
|
+
}
|
|
231
|
+
if (this.#contributions.has(R.name))
|
|
232
|
+
throw new Error(`${label}: registry ${R.name} is contributed to twice`);
|
|
233
|
+
this.#contributions.set(R.name, R);
|
|
234
|
+
}
|
|
235
|
+
open() {
|
|
236
|
+
this.#assertDeclaring("open");
|
|
237
|
+
this.#natives++;
|
|
238
|
+
return INERT;
|
|
239
|
+
}
|
|
240
|
+
tx() {
|
|
241
|
+
throw new Error(`${this.#object.label}: self.tx runs in calls, not in a factory`);
|
|
242
|
+
}
|
|
243
|
+
follow() {
|
|
244
|
+
this.#assertDeclaring("follow");
|
|
245
|
+
return INERT;
|
|
246
|
+
}
|
|
247
|
+
on() {
|
|
248
|
+
this.#assertDeclaring("on");
|
|
249
|
+
}
|
|
250
|
+
onLive() {
|
|
251
|
+
this.#assertDeclaring("onLive");
|
|
252
|
+
}
|
|
253
|
+
job(definition) {
|
|
254
|
+
this.#assertDeclaring("job");
|
|
255
|
+
const object = this.#object;
|
|
256
|
+
if (this.#jobs.has(definition.name))
|
|
257
|
+
throw new Error(`${object.label}: job "${definition.name}" is declared twice`);
|
|
258
|
+
if (definition.persist !== undefined) {
|
|
259
|
+
this.#assertClaimable(`job "${definition.name}"`, ["chord.jobs", "chord.job-states"]);
|
|
260
|
+
}
|
|
261
|
+
object.checkJob(definition);
|
|
262
|
+
this.#jobs.set(definition.name, definition);
|
|
263
|
+
return INERT;
|
|
264
|
+
}
|
|
265
|
+
/** Persisted data needs a stable identity (P3) and the host's store, as an attempt checks; returns the store. */
|
|
266
|
+
#assertPersistable(what) {
|
|
267
|
+
const served = this.#served;
|
|
268
|
+
const { host, label } = this.#object;
|
|
269
|
+
if (served.kind !== "local" || contractData(served.contract).params.fields.length > 0) {
|
|
270
|
+
throw new Error(`${label}: ${what}: persist needs a stable identity (a local type with empty params)`);
|
|
271
|
+
}
|
|
272
|
+
if (host.store === undefined)
|
|
273
|
+
throw new Error(`${label}: ${what}: persist needs a store`);
|
|
274
|
+
return host.store;
|
|
275
|
+
}
|
|
276
|
+
/** Persisted documents in `namespaces`: as `#assertPersistable`, and not claimed by another owner. */
|
|
277
|
+
#assertClaimable(what, namespaces) {
|
|
278
|
+
const store = this.#assertPersistable(what);
|
|
279
|
+
const object = this.#object;
|
|
280
|
+
for (const namespace of namespaces)
|
|
281
|
+
store.claims.assertDocuments(object.served.contract.name, namespace, object);
|
|
282
|
+
}
|
|
283
|
+
#assertDeclaring(declaration) {
|
|
284
|
+
if (!this.declaring)
|
|
285
|
+
throw new Error(`${this.#object.label}: self.${declaration} is valid only in the factory`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Whether `recorded`'s tables are at a version newer than `object`'s store has them: their eager migration runs at an
|
|
290
|
+
* activation, so the object restarts instead of swapping (§4).
|
|
291
|
+
*/
|
|
292
|
+
export function migratesTables(object, recorded) {
|
|
293
|
+
const { store } = object.host;
|
|
294
|
+
if (store === undefined)
|
|
295
|
+
return false;
|
|
296
|
+
const owner = object.served.contract.name;
|
|
297
|
+
return recorded.tables.some((table) => {
|
|
298
|
+
const stored = store.table(tableSqlName(owner, table.name));
|
|
299
|
+
return stored !== undefined && stored.version < table.version;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=staging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.js","sourceRoot":"","sources":["../../../src/next/host/staging.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAC3H,sHAAsH;AACtH,mHAAmH;AACnH,sHAAsH;AACtH,oHAAoH;AACpH,mHAAmH;AACnH,4DAA4D;AAK5D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,EAAE,aAAa,EAA4B,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,OAAO,EAAwD,KAAK,EAAE,MAAM,YAAY,CAAC;AAGzF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAqC5C,0CAA0C;AAC1C,MAAM,WAAW,GAAG,0DAA0D,CAAC;AAE/E,uHAAuH;AACvH,MAAM,UAAU,YAAY,CAAC,IAAY;IACxC,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,WAAW;IAC1B,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAA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,CAAC,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,UAAU,WAAW,+BAA+B,CAAC,CAAC;IACjH,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAmB,EAAE,QAAkB;IACrE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;IAC9B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC1C,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC/D,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Staging (slice 7b §2; per plugin, decision \"Per plugin at startup and reload\"): each plugin's setup runs into a table of\n// its own (the types it serves with their providers, the registries it serves, its facet contributions) with `load`'s\n// checks, merged into the staged table beside the live one, where a type or registry another plugin serves already\n// fails the plugin; and an object's new factory run against a recording `self`, which keeps what the factory declares\n// (natives, documents, tables, jobs, contributions, requests with their contract versions) and activates, binds and\n// opens nothing, so a reload decides each object's fate, and which plugins keep their old code, before its commit.\n// `load` stages its facets the same way and publishes them.\n\nimport type { Context } from \"../../context/index.ts\";\nimport type { Watchable } from \"../../watch.ts\";\nimport type { Contract, ParamsOf } from \"../contracts/index.ts\";\nimport { contractData } from \"../contracts/internal.ts\";\nimport type { Principal } from \"../data/index.ts\";\nimport { bindProvider, checkParams } from \"../data/internal.ts\";\nimport type { AnyDefinition } from \"../documents/internal.ts\";\nimport type { JobDefinition } from \"../jobs/index.ts\";\nimport type { Registry, RegistryProvider } from \"../registries/index.ts\";\nimport { checkProvider, type RegistryValueSource } from \"../registries/internal.ts\";\nimport { tableSqlName } from \"../store/sql.ts\";\nimport type { ChordStore } from \"../store/store.ts\";\nimport type { TableDefinition } from \"../store/table.ts\";\nimport type { StoreSelf } from \"./attempt.ts\";\nimport { type Facet, type FacetContribution, type ServedEntry, setUp } from \"./facet.ts\";\nimport type { ChordObject, LocalContract, RemoteContract, Served } from \"./object.ts\";\nimport type { Presence } from \"./presence.ts\";\nimport { retrySource } from \"./retry-on.ts\";\n\n/** A plugin's facet as `load` and `reload` take it: its name (its `package.json` name) and its facet. */\nexport type PluginFacet<P extends Principal = Principal> = { readonly name: string; readonly facet: Facet<P> };\n\n/** A registry a staged plugin serves: the defining plugin, the token and its provider. */\nexport type StagedRegistry = {\n\treadonly plugin: string;\n\treadonly registry: Registry<unknown, unknown>;\n\treadonly provider: RegistryProvider<unknown, unknown>;\n};\n\n/** One plugin's setup, run and checked: what it serves and contributes, nothing published yet. */\nexport type StagedPlugin = {\n\treadonly name: string;\n\t/** The served types by name, each with its plugin, factory, provider (its `accepts` checked) and `linger`. */\n\treadonly types: ReadonlyMap<string, Served>;\n\t/** The served registries by name. */\n\treadonly registries: ReadonlyMap<string, StagedRegistry>;\n\t/** The facet contributions, in the setup's order. */\n\treadonly contributions: readonly FacetContribution[];\n};\n\n/** A plugin set's staged plugins, merged: what they serve, by name, and each plugin's own table. */\nexport type Staged = {\n\treadonly types: Map<string, Served>;\n\treadonly registries: Map<string, StagedRegistry>;\n\treadonly plugins: Map<string, StagedPlugin>;\n};\n\n/** What staging needs of its host: whom it acts as, where it lives, and its presence lists for setups. */\nexport type StagingHost = {\n\treadonly principal: Principal | undefined;\n\treadonly address: unknown;\n\treferences<C extends Contract>(Type: C): Watchable<readonly Presence<C, Principal>[]>;\n};\n\n/** An npm package name, scoped or not. */\nconst PLUGIN_NAME = /^(?:@[a-z0-9~-][a-z0-9._~-]*\\/)?[a-z0-9~-][a-z0-9._~-]*$/;\n\n/** Whether `name` is a valid plugin name: an npm package name, scoped or not (the plugins component checks it too). */\nexport function isPluginName(name: string): boolean {\n\treturn PLUGIN_NAME.test(name);\n}\n\n/** A staged table with nothing in it. */\nexport function emptyStaged(): Staged {\n\treturn { types: new Map(), registries: new Map(), plugins: new Map() };\n}\n\n/**\n * Runs one plugin's setup and checks what it declared: its name (an npm name), a type or registry it serves twice, a\n * remote type on a host without a principal or address, every provider's `accepts` (`checkAccepts`) and every registry\n * provider's shape. Throws the first error, naming the plugin.\n */\nexport function stagePlugin<P extends Principal>({ name, facet }: PluginFacet<P>, host: StagingHost): StagedPlugin {\n\tif (!isPluginName(name)) throw new Error(`\"${name}\" is not a valid plugin name`);\n\t// The host's presence lists are typed for its `P`.\n\tconst references = host.references as <C extends Contract>(Type: C) => Watchable<readonly Presence<C, P>[]>;\n\tconst types = new Map<string, Served>();\n\tconst registries = new Map<string, StagedRegistry>();\n\ttry {\n\t\tconst { served, contributions } = setUp(name, facet, references);\n\t\tfor (const entry of served) stageEntry(name, entry, types, registries, host);\n\t\treturn { name, types, registries, contributions };\n\t} catch (error) {\n\t\tthrow named(error, `plugin \"${name}\"`);\n\t}\n}\n\n/**\n * Merges `plugin` into `staged`; a type or registry another plugin serves there already refuses it (its error\n * returned, nothing merged).\n */\nexport function addStaged(staged: Staged, plugin: StagedPlugin): Error | undefined {\n\tfor (const name of plugin.types.keys()) {\n\t\tconst other = staged.types.get(name);\n\t\tif (other !== undefined)\n\t\t\treturn new Error(`plugin \"${plugin.name}\": ${name} is served twice (plugin \"${other.plugin}\")`);\n\t}\n\tfor (const name of plugin.registries.keys()) {\n\t\tconst other = staged.registries.get(name);\n\t\tif (other !== undefined) {\n\t\t\treturn new Error(`plugin \"${plugin.name}\": registry ${name} is served twice (plugin \"${other.plugin}\")`);\n\t\t}\n\t}\n\tfor (const [name, served] of plugin.types) staged.types.set(name, served);\n\tfor (const [name, registry] of plugin.registries) staged.registries.set(name, registry);\n\tstaged.plugins.set(plugin.name, plugin);\n\treturn undefined;\n}\n\n/** Stages one served entry of `plugin` into its tables: a registry's provider, or a type as `Served`. */\nfunction stageEntry(\n\tplugin: string,\n\tentry: ServedEntry,\n\ttypes: Map<string, Served>,\n\tregistries: Map<string, StagedRegistry>,\n\thost: StagingHost,\n): void {\n\tif (entry.kind === \"registry\") {\n\t\tconst { registry, provider } = entry;\n\t\tif (registries.has(registry.name)) throw new Error(`registry ${registry.name} is served twice`);\n\t\tcheckProvider(registry.name, provider);\n\t\tregistries.set(registry.name, { plugin, registry, provider });\n\t\treturn;\n\t}\n\tconst { contract, factory, options } = entry;\n\tif (types.has(contract.name)) throw new Error(`${contract.name} is served twice`);\n\t// A client serves only local types (§3): a remote object is owned by a principal of the host serving it.\n\tif (contract.kind === \"remote\" && host.principal === undefined) {\n\t\tthrow new Error(`${contract.name}: a host without a principal serves only local types`);\n\t}\n\t// A remote object lives on the host its `hostAddress` names: only a host with an address can be that host.\n\tif (contract.kind === \"remote\" && host.address === undefined) {\n\t\tthrow new Error(`${contract.name}: a host without an address serves only local types`);\n\t}\n\tconst provider = bindProvider(contract, options.accepts ?? {});\n\tconst common = { plugin, provider, linger: options.linger ?? 0 };\n\t// The contract's kind decides the factory's signature and the contract's shape.\n\tconst served: Served =\n\t\tcontract.kind === \"local\"\n\t\t\t? {\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"local\",\n\t\t\t\t\tcontract: contract as LocalContract,\n\t\t\t\t\tfactory: factory as Extract<Served, { kind: \"local\" }>[\"factory\"],\n\t\t\t\t\thostLifetime: contractData(contract).params.fields.length === 0,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\t...common,\n\t\t\t\t\tkind: \"remote\",\n\t\t\t\t\tcontract: contract as RemoteContract,\n\t\t\t\t\tfactory: factory as Extract<Served, { kind: \"remote\" }>[\"factory\"],\n\t\t\t\t};\n\ttypes.set(contract.name, served);\n}\n\n/** What a recorded factory declared: what a reload's fate and checks need, nothing activated. */\nexport type Recorded = {\n\t/** How many natives it opens (`self.open`). */\n\treadonly natives: number;\n\treadonly documents: readonly AnyDefinition[];\n\treadonly tables: readonly TableDefinition[];\n\treadonly jobs: readonly JobDefinition<unknown, unknown, unknown>[];\n\treadonly contributions: readonly Registry<unknown, unknown>[];\n\t/** Its requests: the types it gets (`self.get`, with their checked params) and the registries it reads (`self.registry`). */\n\treadonly requests: readonly Request[];\n};\n\n/** A recorded request, with the contract version it was made at: a type and its params, or a registry. */\nexport type Request =\n\t| { readonly kind: \"type\"; readonly contract: Contract; readonly params: ParamsOf<Contract> }\n\t| { readonly kind: \"registry\"; readonly registry: Registry<unknown, unknown> };\n\n/**\n * Runs `served`'s factory for `object` (its params and principal) against a recording `self` and returns what it\n * declared. Every declaration check an attempt makes runs, without effects (declared twice; persisted data in a type\n * without a stable identity, on a host without a store, or claimed by another owner; contributions outside\n * host-lifetime objects, or twice; `retryOn` sources that do not outlive the attempt; params; a document or job\n * declared at an older version than the object's, or at its version with another schema); a throw is the factory's.\n * Handles it hands out are inert, except registry values (the host's own, which `retryOn` checks by kind).\n */\nexport function recordFactory(object: ChordObject, served: Served, context: Context): Recorded {\n\tconst recording = new RecordingSelf(object, served, context);\n\t// A recording `self` takes every declaration a factory makes, its handles inert.\n\tconst self = recording as unknown as StoreSelf;\n\ttry {\n\t\tif (served.kind === \"local\") served.factory(object.params, self);\n\t\t// A remote object's identity has its principal.\n\t\telse served.factory(object.params, object.principal!, self);\n\t} catch (error) {\n\t\tthrow named(error, `plugin \"${served.plugin}\", ${object.label}`);\n\t} finally {\n\t\trecording.declaring = false;\n\t}\n\treturn recording.recorded;\n}\n\n/** A staging error naming where it happened (`what`): its message prefixed, the error itself its cause. */\nfunction named(error: unknown, what: string): Error {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn new Error(`${what}: ${message}`, { cause: error });\n}\n\n/**\n * The value of every handle a recording `self` hands out: any property or call gives it again, and it is never a\n * thenable. Typed `never` (a cast: it stands for every handle type, and nothing reads it as one).\n */\nconst INERT: never = new Proxy(() => {}, {\n\tget: (_target, property) => (property === \"then\" ? undefined : INERT),\n\tapply: () => INERT,\n}) as never;\n\n/** A factory's `self` during staging: it records declarations and checks them; it activates nothing. */\nclass RecordingSelf {\n\tdeclaring = true;\n\treadonly #object: ChordObject;\n\treadonly #served: Served;\n\treadonly #context: Context;\n\t#natives = 0;\n\treadonly #documents = new Map<string, AnyDefinition>();\n\treadonly #tables = new Map<string, TableDefinition>();\n\treadonly #jobs = new Map<string, JobDefinition<unknown, unknown, unknown>>();\n\treadonly #contributions = new Map<string, Registry<unknown, unknown>>();\n\treadonly #requests: Request[] = [];\n\n\tconstructor(object: ChordObject, served: Served, context: Context) {\n\t\tthis.#object = object;\n\t\tthis.#served = served;\n\t\tthis.#context = context;\n\t}\n\n\tget recorded(): Recorded {\n\t\treturn {\n\t\t\tnatives: this.#natives,\n\t\t\tdocuments: [...this.#documents.values()],\n\t\t\ttables: [...this.#tables.values()],\n\t\t\tjobs: [...this.#jobs.values()],\n\t\t\tcontributions: [...this.#contributions.values()],\n\t\t\trequests: this.#requests,\n\t\t};\n\t}\n\n\tstate(definition: AnyDefinition): never {\n\t\tthis.#assertDeclaring(\"state\");\n\t\tconst what = `state \"${definition.name}\"`;\n\t\tif (this.#documents.has(definition.name)) throw new Error(`${this.#object.label}: ${what} is declared twice`);\n\t\tif (definition.persist) this.#assertClaimable(what, [\"chord\"]);\n\t\tthis.#object.documents.check(definition);\n\t\tthis.#documents.set(definition.name, definition);\n\t\treturn INERT;\n\t}\n\n\ttable(definition: TableDefinition): never {\n\t\tthis.#assertDeclaring(\"table\");\n\t\tconst store = this.#assertPersistable(`table \"${definition.name}\"`);\n\t\tif (this.#tables.has(definition.name)) {\n\t\t\tthrow new Error(`${this.#object.label}: table \"${definition.name}\" is declared twice`);\n\t\t}\n\t\tconst object = this.#object;\n\t\tstore.claims.assertTable(tableSqlName(object.served.contract.name, definition.name), object);\n\t\tthis.#tables.set(definition.name, definition);\n\t\treturn INERT;\n\t}\n\n\tderive(): never {\n\t\tthis.#assertDeclaring(\"derive\");\n\t\treturn INERT;\n\t}\n\n\tget(Type: Contract, params: unknown): never {\n\t\tthis.#assertDeclaring(\"get\");\n\t\tconst checked = checkParams(Type, params, this.#context);\n\t\tthis.#requests.push({ kind: \"type\", contract: Type, params: checked.params });\n\t\treturn INERT;\n\t}\n\n\tregistry(R: Registry<unknown, unknown>): RegistryValueSource {\n\t\tthis.#assertDeclaring(\"registry\");\n\t\tthis.#requests.push({ kind: \"registry\", registry: R });\n\t\t// The host's own value (an attempt declares the same one): `retryOn` checks its kind.\n\t\treturn this.#object.host.registryRecord(R.name).value(R.version);\n\t}\n\n\twritable(): never {\n\t\tthis.#assertDeclaring(\"writable\");\n\t\treturn INERT;\n\t}\n\n\tretryOn(...sources: readonly unknown[]): void {\n\t\tthis.#assertDeclaring(\"retryOn\");\n\t\tfor (const source of sources) retrySource(source, this.#object.label);\n\t}\n\n\tcontribute(R: Registry<unknown, unknown>): void {\n\t\tthis.#assertDeclaring(\"contribute\");\n\t\tconst served = this.#served;\n\t\tconst { label } = this.#object;\n\t\t// R21: plugin code is bundled without type checks.\n\t\tif (served.kind !== \"local\" || !served.hostLifetime) {\n\t\t\tthrow new Error(`${label}: self.contribute is valid only in a local type with empty params`);\n\t\t}\n\t\tif (this.#contributions.has(R.name)) throw new Error(`${label}: registry ${R.name} is contributed to twice`);\n\t\tthis.#contributions.set(R.name, R);\n\t}\n\n\topen(): never {\n\t\tthis.#assertDeclaring(\"open\");\n\t\tthis.#natives++;\n\t\treturn INERT;\n\t}\n\n\ttx(): never {\n\t\tthrow new Error(`${this.#object.label}: self.tx runs in calls, not in a factory`);\n\t}\n\n\tfollow(): never {\n\t\tthis.#assertDeclaring(\"follow\");\n\t\treturn INERT;\n\t}\n\n\ton(): void {\n\t\tthis.#assertDeclaring(\"on\");\n\t}\n\n\tonLive(): void {\n\t\tthis.#assertDeclaring(\"onLive\");\n\t}\n\n\tjob(definition: JobDefinition<unknown, unknown, unknown>): never {\n\t\tthis.#assertDeclaring(\"job\");\n\t\tconst object = this.#object;\n\t\tif (this.#jobs.has(definition.name))\n\t\t\tthrow new Error(`${object.label}: job \"${definition.name}\" is declared twice`);\n\t\tif (definition.persist !== undefined) {\n\t\t\tthis.#assertClaimable(`job \"${definition.name}\"`, [\"chord.jobs\", \"chord.job-states\"]);\n\t\t}\n\t\tobject.checkJob(definition);\n\t\tthis.#jobs.set(definition.name, definition);\n\t\treturn INERT;\n\t}\n\n\t/** Persisted data needs a stable identity (P3) and the host's store, as an attempt checks; returns the store. */\n\t#assertPersistable(what: string): ChordStore {\n\t\tconst served = this.#served;\n\t\tconst { host, label } = this.#object;\n\t\tif (served.kind !== \"local\" || contractData(served.contract).params.fields.length > 0) {\n\t\t\tthrow new Error(`${label}: ${what}: persist needs a stable identity (a local type with empty params)`);\n\t\t}\n\t\tif (host.store === undefined) throw new Error(`${label}: ${what}: persist needs a store`);\n\t\treturn host.store;\n\t}\n\n\t/** Persisted documents in `namespaces`: as `#assertPersistable`, and not claimed by another owner. */\n\t#assertClaimable(what: string, namespaces: readonly string[]): void {\n\t\tconst store = this.#assertPersistable(what);\n\t\tconst object = this.#object;\n\t\tfor (const namespace of namespaces) store.claims.assertDocuments(object.served.contract.name, namespace, object);\n\t}\n\n\t#assertDeclaring(declaration: string): void {\n\t\tif (!this.declaring) throw new Error(`${this.#object.label}: self.${declaration} is valid only in the factory`);\n\t}\n}\n\n/**\n * Whether `recorded`'s tables are at a version newer than `object`'s store has them: their eager migration runs at an\n * activation, so the object restarts instead of swapping (§4).\n */\nexport function migratesTables(object: ChordObject, recorded: Recorded): boolean {\n\tconst { store } = object.host;\n\tif (store === undefined) return false;\n\tconst owner = object.served.contract.name;\n\treturn recorded.tables.some((table) => {\n\t\tconst stored = store.table(tableSqlName(owner, table.name));\n\t\treturn stored !== undefined && stored.version < table.version;\n\t});\n}\n"]}
|