@mostra/protocol 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/README.md +38 -2
- package/dist/actions.d.ts +273 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +154 -0
- package/dist/actions.js.map +1 -0
- package/dist/artifact.d.ts +113 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +79 -0
- package/dist/artifact.js.map +1 -0
- package/dist/bridge.d.ts +295 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +343 -0
- package/dist/bridge.js.map +1 -0
- package/dist/browser.d.ts +195 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +156 -0
- package/dist/browser.js.map +1 -0
- package/dist/bundle.d.ts +155 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +130 -0
- package/dist/bundle.js.map +1 -0
- package/dist/canonical.d.ts +23 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +45 -0
- package/dist/canonical.js.map +1 -0
- package/dist/capability.d.ts +38 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +61 -0
- package/dist/capability.js.map +1 -0
- package/dist/diagnostics/codes/a11y.d.ts +8 -0
- package/dist/diagnostics/codes/a11y.d.ts.map +1 -0
- package/dist/diagnostics/codes/a11y.js +30 -0
- package/dist/diagnostics/codes/a11y.js.map +1 -0
- package/dist/diagnostics/codes/action.d.ts +8 -0
- package/dist/diagnostics/codes/action.d.ts.map +1 -0
- package/dist/diagnostics/codes/action.js +110 -0
- package/dist/diagnostics/codes/action.js.map +1 -0
- package/dist/diagnostics/codes/artifact.d.ts +8 -0
- package/dist/diagnostics/codes/artifact.d.ts.map +1 -0
- package/dist/diagnostics/codes/artifact.js +121 -0
- package/dist/diagnostics/codes/artifact.js.map +1 -0
- package/dist/diagnostics/codes/build.d.ts +8 -0
- package/dist/diagnostics/codes/build.d.ts.map +1 -0
- package/dist/diagnostics/codes/build.js +55 -0
- package/dist/diagnostics/codes/build.js.map +1 -0
- package/dist/diagnostics/codes/cli.d.ts +8 -0
- package/dist/diagnostics/codes/cli.d.ts.map +1 -0
- package/dist/diagnostics/codes/cli.js +44 -0
- package/dist/diagnostics/codes/cli.js.map +1 -0
- package/dist/diagnostics/codes/console.d.ts +8 -0
- package/dist/diagnostics/codes/console.d.ts.map +1 -0
- package/dist/diagnostics/codes/console.js +30 -0
- package/dist/diagnostics/codes/console.js.map +1 -0
- package/dist/diagnostics/codes/dep.d.ts +8 -0
- package/dist/diagnostics/codes/dep.d.ts.map +1 -0
- package/dist/diagnostics/codes/dep.js +88 -0
- package/dist/diagnostics/codes/dep.js.map +1 -0
- package/dist/diagnostics/codes/env.d.ts +8 -0
- package/dist/diagnostics/codes/env.d.ts.map +1 -0
- package/dist/diagnostics/codes/env.js +132 -0
- package/dist/diagnostics/codes/env.js.map +1 -0
- package/dist/diagnostics/codes/field.d.ts +8 -0
- package/dist/diagnostics/codes/field.d.ts.map +1 -0
- package/dist/diagnostics/codes/field.js +99 -0
- package/dist/diagnostics/codes/field.js.map +1 -0
- package/dist/diagnostics/codes/home.d.ts +8 -0
- package/dist/diagnostics/codes/home.d.ts.map +1 -0
- package/dist/diagnostics/codes/home.js +132 -0
- package/dist/diagnostics/codes/home.js.map +1 -0
- package/dist/diagnostics/codes/host.d.ts +8 -0
- package/dist/diagnostics/codes/host.d.ts.map +1 -0
- package/dist/diagnostics/codes/host.js +187 -0
- package/dist/diagnostics/codes/host.js.map +1 -0
- package/dist/diagnostics/codes/hygiene.d.ts +8 -0
- package/dist/diagnostics/codes/hygiene.d.ts.map +1 -0
- package/dist/diagnostics/codes/hygiene.js +154 -0
- package/dist/diagnostics/codes/hygiene.js.map +1 -0
- package/dist/diagnostics/codes/index.d.ts +51 -0
- package/dist/diagnostics/codes/index.d.ts.map +1 -0
- package/dist/diagnostics/codes/index.js +72 -0
- package/dist/diagnostics/codes/index.js.map +1 -0
- package/dist/diagnostics/codes/live.d.ts +8 -0
- package/dist/diagnostics/codes/live.d.ts.map +1 -0
- package/dist/diagnostics/codes/live.js +30 -0
- package/dist/diagnostics/codes/live.js.map +1 -0
- package/dist/diagnostics/codes/manifest.d.ts +8 -0
- package/dist/diagnostics/codes/manifest.d.ts.map +1 -0
- package/dist/diagnostics/codes/manifest.js +44 -0
- package/dist/diagnostics/codes/manifest.js.map +1 -0
- package/dist/diagnostics/codes/network.d.ts +8 -0
- package/dist/diagnostics/codes/network.d.ts.map +1 -0
- package/dist/diagnostics/codes/network.js +30 -0
- package/dist/diagnostics/codes/network.js.map +1 -0
- package/dist/diagnostics/codes/platform.d.ts +8 -0
- package/dist/diagnostics/codes/platform.d.ts.map +1 -0
- package/dist/diagnostics/codes/platform.js +18 -0
- package/dist/diagnostics/codes/platform.js.map +1 -0
- package/dist/diagnostics/codes/publish.d.ts +8 -0
- package/dist/diagnostics/codes/publish.d.ts.map +1 -0
- package/dist/diagnostics/codes/publish.js +44 -0
- package/dist/diagnostics/codes/publish.js.map +1 -0
- package/dist/diagnostics/codes/regression.d.ts +8 -0
- package/dist/diagnostics/codes/regression.d.ts.map +1 -0
- package/dist/diagnostics/codes/regression.js +77 -0
- package/dist/diagnostics/codes/regression.js.map +1 -0
- package/dist/diagnostics/codes/runtime.d.ts +8 -0
- package/dist/diagnostics/codes/runtime.d.ts.map +1 -0
- package/dist/diagnostics/codes/runtime.js +66 -0
- package/dist/diagnostics/codes/runtime.js.map +1 -0
- package/dist/diagnostics/codes/secret.d.ts +8 -0
- package/dist/diagnostics/codes/secret.d.ts.map +1 -0
- package/dist/diagnostics/codes/secret.js +18 -0
- package/dist/diagnostics/codes/secret.js.map +1 -0
- package/dist/diagnostics/codes/smoke.d.ts +8 -0
- package/dist/diagnostics/codes/smoke.d.ts.map +1 -0
- package/dist/diagnostics/codes/smoke.js +30 -0
- package/dist/diagnostics/codes/smoke.js.map +1 -0
- package/dist/diagnostics/codes/submit.d.ts +8 -0
- package/dist/diagnostics/codes/submit.d.ts.map +1 -0
- package/dist/diagnostics/codes/submit.js +99 -0
- package/dist/diagnostics/codes/submit.js.map +1 -0
- package/dist/diagnostics/codes/target.d.ts +8 -0
- package/dist/diagnostics/codes/target.d.ts.map +1 -0
- package/dist/diagnostics/codes/target.js +18 -0
- package/dist/diagnostics/codes/target.js.map +1 -0
- package/dist/diagnostics/codes/type.d.ts +8 -0
- package/dist/diagnostics/codes/type.d.ts.map +1 -0
- package/dist/diagnostics/codes/type.js +30 -0
- package/dist/diagnostics/codes/type.js.map +1 -0
- package/dist/diagnostics/codes/verify.d.ts +8 -0
- package/dist/diagnostics/codes/verify.d.ts.map +1 -0
- package/dist/diagnostics/codes/verify.js +99 -0
- package/dist/diagnostics/codes/verify.js.map +1 -0
- package/dist/diagnostics/diagnostic.d.ts +79 -0
- package/dist/diagnostics/diagnostic.d.ts.map +1 -0
- package/dist/diagnostics/diagnostic.js +131 -0
- package/dist/diagnostics/diagnostic.js.map +1 -0
- package/dist/diagnostics/spec.d.ts +49 -0
- package/dist/diagnostics/spec.d.ts.map +1 -0
- package/dist/diagnostics/spec.js +31 -0
- package/dist/diagnostics/spec.js.map +1 -0
- package/dist/hygiene.d.ts +66 -0
- package/dist/hygiene.d.ts.map +1 -0
- package/dist/hygiene.js +134 -0
- package/dist/hygiene.js.map +1 -0
- package/dist/ids.d.ts +119 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +135 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +87 -0
- package/dist/interaction.d.ts +391 -0
- package/dist/interaction.d.ts.map +1 -0
- package/dist/interaction.js +306 -0
- package/dist/interaction.js.map +1 -0
- package/dist/manifest.d.ts +97 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +101 -0
- package/dist/manifest.js.map +1 -0
- package/dist/method.d.ts +38 -0
- package/dist/method.d.ts.map +1 -0
- package/dist/method.js +10 -0
- package/dist/method.js.map +1 -0
- package/dist/methods/artifact/create.d.ts +29 -0
- package/dist/methods/artifact/create.d.ts.map +1 -0
- package/dist/methods/artifact/create.js +31 -0
- package/dist/methods/artifact/create.js.map +1 -0
- package/dist/methods/artifact/get.d.ts +17 -0
- package/dist/methods/artifact/get.d.ts.map +1 -0
- package/dist/methods/artifact/get.js +21 -0
- package/dist/methods/artifact/get.js.map +1 -0
- package/dist/methods/artifact/list.d.ts +22 -0
- package/dist/methods/artifact/list.d.ts.map +1 -0
- package/dist/methods/artifact/list.js +19 -0
- package/dist/methods/artifact/list.js.map +1 -0
- package/dist/methods/artifact/publish.d.ts +28 -0
- package/dist/methods/artifact/publish.d.ts.map +1 -0
- package/dist/methods/artifact/publish.js +28 -0
- package/dist/methods/artifact/publish.js.map +1 -0
- package/dist/methods/artifact/verify.d.ts +29 -0
- package/dist/methods/artifact/verify.d.ts.map +1 -0
- package/dist/methods/artifact/verify.js +27 -0
- package/dist/methods/artifact/verify.js.map +1 -0
- package/dist/methods/deps/add.d.ts +43 -0
- package/dist/methods/deps/add.d.ts.map +1 -0
- package/dist/methods/deps/add.js +40 -0
- package/dist/methods/deps/add.js.map +1 -0
- package/dist/methods/dev/start.d.ts +52 -0
- package/dist/methods/dev/start.d.ts.map +1 -0
- package/dist/methods/dev/start.js +56 -0
- package/dist/methods/dev/start.js.map +1 -0
- package/dist/methods/dev/stop.d.ts +16 -0
- package/dist/methods/dev/stop.d.ts.map +1 -0
- package/dist/methods/dev/stop.js +21 -0
- package/dist/methods/dev/stop.js.map +1 -0
- package/dist/methods/events/ack.d.ts +20 -0
- package/dist/methods/events/ack.d.ts.map +1 -0
- package/dist/methods/events/ack.js +26 -0
- package/dist/methods/events/ack.js.map +1 -0
- package/dist/methods/events/read.d.ts +40 -0
- package/dist/methods/events/read.d.ts.map +1 -0
- package/dist/methods/events/read.js +35 -0
- package/dist/methods/events/read.js.map +1 -0
- package/dist/methods/events/subscribe.d.ts +54 -0
- package/dist/methods/events/subscribe.d.ts.map +1 -0
- package/dist/methods/events/subscribe.js +44 -0
- package/dist/methods/events/subscribe.js.map +1 -0
- package/dist/methods/events/unsubscribe.d.ts +16 -0
- package/dist/methods/events/unsubscribe.d.ts.map +1 -0
- package/dist/methods/events/unsubscribe.js +21 -0
- package/dist/methods/events/unsubscribe.js.map +1 -0
- package/dist/methods/gc/run.d.ts +76 -0
- package/dist/methods/gc/run.d.ts.map +1 -0
- package/dist/methods/gc/run.js +56 -0
- package/dist/methods/gc/run.js.map +1 -0
- package/dist/methods/index.d.ts +8 -0
- package/dist/methods/index.d.ts.map +1 -0
- package/dist/methods/index.js +96 -0
- package/dist/methods/index.js.map +1 -0
- package/dist/methods/instance/check.d.ts +30 -0
- package/dist/methods/instance/check.d.ts.map +1 -0
- package/dist/methods/instance/check.js +34 -0
- package/dist/methods/instance/check.js.map +1 -0
- package/dist/methods/instance/status.d.ts +102 -0
- package/dist/methods/instance/status.d.ts.map +1 -0
- package/dist/methods/instance/status.js +83 -0
- package/dist/methods/instance/status.js.map +1 -0
- package/dist/methods/live/push.d.ts +28 -0
- package/dist/methods/live/push.d.ts.map +1 -0
- package/dist/methods/live/push.js +35 -0
- package/dist/methods/live/push.js.map +1 -0
- package/dist/methods/mostra/initialize.d.ts +143 -0
- package/dist/methods/mostra/initialize.d.ts.map +1 -0
- package/dist/methods/mostra/initialize.js +97 -0
- package/dist/methods/mostra/initialize.js.map +1 -0
- package/dist/methods/mostra/shutdown.d.ts +14 -0
- package/dist/methods/mostra/shutdown.d.ts.map +1 -0
- package/dist/methods/mostra/shutdown.js +22 -0
- package/dist/methods/mostra/shutdown.js.map +1 -0
- package/dist/methods/port/drafts-mirror.d.ts +30 -0
- package/dist/methods/port/drafts-mirror.d.ts.map +1 -0
- package/dist/methods/port/drafts-mirror.js +33 -0
- package/dist/methods/port/drafts-mirror.js.map +1 -0
- package/dist/methods/port/identity-resolve.d.ts +36 -0
- package/dist/methods/port/identity-resolve.d.ts.map +1 -0
- package/dist/methods/port/identity-resolve.js +35 -0
- package/dist/methods/port/identity-resolve.js.map +1 -0
- package/dist/methods/port/secrets-get.d.ts +19 -0
- package/dist/methods/port/secrets-get.d.ts.map +1 -0
- package/dist/methods/port/secrets-get.js +31 -0
- package/dist/methods/port/secrets-get.js.map +1 -0
- package/dist/methods/port/submissions-deliver.d.ts +38 -0
- package/dist/methods/port/submissions-deliver.d.ts.map +1 -0
- package/dist/methods/port/submissions-deliver.js +38 -0
- package/dist/methods/port/submissions-deliver.js.map +1 -0
- package/dist/methods/port/trusted-controls-activated.d.ts +27 -0
- package/dist/methods/port/trusted-controls-activated.d.ts.map +1 -0
- package/dist/methods/port/trusted-controls-activated.js +33 -0
- package/dist/methods/port/trusted-controls-activated.js.map +1 -0
- package/dist/methods/port/trusted-controls-policy.d.ts +21 -0
- package/dist/methods/port/trusted-controls-policy.d.ts.map +1 -0
- package/dist/methods/port/trusted-controls-policy.js +27 -0
- package/dist/methods/port/trusted-controls-policy.js.map +1 -0
- package/dist/methods/results/get.d.ts +32 -0
- package/dist/methods/results/get.d.ts.map +1 -0
- package/dist/methods/results/get.js +36 -0
- package/dist/methods/results/get.js.map +1 -0
- package/dist/methods/secret/delete.d.ts +22 -0
- package/dist/methods/secret/delete.d.ts.map +1 -0
- package/dist/methods/secret/delete.js +32 -0
- package/dist/methods/secret/delete.js.map +1 -0
- package/dist/methods/secret/list.d.ts +21 -0
- package/dist/methods/secret/list.d.ts.map +1 -0
- package/dist/methods/secret/list.js +29 -0
- package/dist/methods/secret/list.js.map +1 -0
- package/dist/methods/secret/set.d.ts +37 -0
- package/dist/methods/secret/set.d.ts.map +1 -0
- package/dist/methods/secret/set.js +41 -0
- package/dist/methods/secret/set.js.map +1 -0
- package/dist/methods/state/get.d.ts +25 -0
- package/dist/methods/state/get.d.ts.map +1 -0
- package/dist/methods/state/get.js +29 -0
- package/dist/methods/state/get.js.map +1 -0
- package/dist/methods/state/patch.d.ts +32 -0
- package/dist/methods/state/patch.d.ts.map +1 -0
- package/dist/methods/state/patch.js +29 -0
- package/dist/methods/state/patch.js.map +1 -0
- package/dist/methods/view/default.d.ts +19 -0
- package/dist/methods/view/default.d.ts.map +1 -0
- package/dist/methods/view/default.js +23 -0
- package/dist/methods/view/default.js.map +1 -0
- package/dist/methods/view/launch.d.ts +27 -0
- package/dist/methods/view/launch.d.ts.map +1 -0
- package/dist/methods/view/launch.js +30 -0
- package/dist/methods/view/launch.js.map +1 -0
- package/dist/methods/view/revoke.d.ts +19 -0
- package/dist/methods/view/revoke.d.ts.map +1 -0
- package/dist/methods/view/revoke.js +26 -0
- package/dist/methods/view/revoke.js.map +1 -0
- package/dist/methods/view/rotate.d.ts +21 -0
- package/dist/methods/view/rotate.d.ts.map +1 -0
- package/dist/methods/view/rotate.js +27 -0
- package/dist/methods/view/rotate.js.map +1 -0
- package/dist/methods/view/url.d.ts +52 -0
- package/dist/methods/view/url.d.ts.map +1 -0
- package/dist/methods/view/url.js +43 -0
- package/dist/methods/view/url.js.map +1 -0
- package/dist/methods/wait/wait.d.ts +37 -0
- package/dist/methods/wait/wait.d.ts.map +1 -0
- package/dist/methods/wait/wait.js +39 -0
- package/dist/methods/wait/wait.js.map +1 -0
- package/dist/revision.d.ts +43 -0
- package/dist/revision.d.ts.map +1 -0
- package/dist/revision.js +69 -0
- package/dist/revision.js.map +1 -0
- package/dist/rpc/error.d.ts +47 -0
- package/dist/rpc/error.d.ts.map +1 -0
- package/dist/rpc/error.js +77 -0
- package/dist/rpc/error.js.map +1 -0
- package/dist/rpc/lines.d.ts +30 -0
- package/dist/rpc/lines.d.ts.map +1 -0
- package/dist/rpc/lines.js +63 -0
- package/dist/rpc/lines.js.map +1 -0
- package/dist/rpc/messages.d.ts +92 -0
- package/dist/rpc/messages.d.ts.map +1 -0
- package/dist/rpc/messages.js +133 -0
- package/dist/rpc/messages.js.map +1 -0
- package/dist/rpc/peer.d.ts +81 -0
- package/dist/rpc/peer.d.ts.map +1 -0
- package/dist/rpc/peer.js +208 -0
- package/dist/rpc/peer.js.map +1 -0
- package/dist/serializer.d.ts +178 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +929 -0
- package/dist/serializer.js.map +1 -0
- package/dist/verify.d.ts +254 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +243 -0
- package/dist/verify.js.map +1 -0
- package/dist/view.d.ts +103 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +110 -0
- package/dist/view.js.map +1 -0
- package/dist/wire-registry.js +11 -0
- package/dist/wire-registry.js.map +1 -0
- package/dist/worker.d.ts +249 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +158 -0
- package/dist/worker.js.map +1 -0
- package/package.json +114 -3
- package/schemas/protocol.draft-07.json +5533 -0
- package/schemas/protocol.schema.json +5377 -0
- package/src/actions.ts +418 -0
- package/src/artifact.ts +187 -0
- package/src/bridge.ts +618 -0
- package/src/browser.ts +374 -0
- package/src/bundle.ts +264 -0
- package/src/canonical.ts +49 -0
- package/src/capability.ts +92 -0
- package/src/diagnostics/codes/a11y.ts +41 -0
- package/src/diagnostics/codes/action.ts +125 -0
- package/src/diagnostics/codes/artifact.ts +137 -0
- package/src/diagnostics/codes/build.ts +65 -0
- package/src/diagnostics/codes/cli.ts +53 -0
- package/src/diagnostics/codes/console.ts +41 -0
- package/src/diagnostics/codes/dep.ts +101 -0
- package/src/diagnostics/codes/env.ts +149 -0
- package/src/diagnostics/codes/field.ts +113 -0
- package/src/diagnostics/codes/home.ts +150 -0
- package/src/diagnostics/codes/host.ts +209 -0
- package/src/diagnostics/codes/hygiene.ts +175 -0
- package/src/diagnostics/codes/index.ts +142 -0
- package/src/diagnostics/codes/live.ts +41 -0
- package/src/diagnostics/codes/manifest.ts +53 -0
- package/src/diagnostics/codes/network.ts +41 -0
- package/src/diagnostics/codes/platform.ts +30 -0
- package/src/diagnostics/codes/publish.ts +53 -0
- package/src/diagnostics/codes/regression.ts +89 -0
- package/src/diagnostics/codes/runtime.ts +77 -0
- package/src/diagnostics/codes/secret.ts +29 -0
- package/src/diagnostics/codes/smoke.ts +41 -0
- package/src/diagnostics/codes/submit.ts +113 -0
- package/src/diagnostics/codes/target.ts +29 -0
- package/src/diagnostics/codes/type.ts +41 -0
- package/src/diagnostics/codes/verify.ts +113 -0
- package/src/diagnostics/diagnostic.ts +240 -0
- package/src/diagnostics/spec.ts +90 -0
- package/src/hygiene.ts +224 -0
- package/src/ids.ts +279 -0
- package/src/index.ts +584 -0
- package/src/interaction.ts +728 -0
- package/src/manifest.ts +206 -0
- package/src/method.ts +56 -0
- package/src/methods/artifact/create.ts +56 -0
- package/src/methods/artifact/get.ts +30 -0
- package/src/methods/artifact/list.ts +42 -0
- package/src/methods/artifact/publish.ts +46 -0
- package/src/methods/artifact/verify.ts +46 -0
- package/src/methods/deps/add.ts +72 -0
- package/src/methods/dev/start.ts +84 -0
- package/src/methods/dev/stop.ts +32 -0
- package/src/methods/events/ack.ts +41 -0
- package/src/methods/events/read.ts +67 -0
- package/src/methods/events/subscribe.ts +91 -0
- package/src/methods/events/unsubscribe.ts +35 -0
- package/src/methods/gc/run.ts +125 -0
- package/src/methods/index.ts +91 -0
- package/src/methods/instance/check.ts +61 -0
- package/src/methods/instance/status.ts +172 -0
- package/src/methods/live/push.ts +54 -0
- package/src/methods/mostra/initialize.ts +249 -0
- package/src/methods/mostra/shutdown.ts +31 -0
- package/src/methods/port/drafts-mirror.ts +52 -0
- package/src/methods/port/identity-resolve.ts +67 -0
- package/src/methods/port/secrets-get.ts +40 -0
- package/src/methods/port/submissions-deliver.ts +70 -0
- package/src/methods/port/trusted-controls-activated.ts +51 -0
- package/src/methods/port/trusted-controls-policy.ts +38 -0
- package/src/methods/results/get.ts +59 -0
- package/src/methods/secret/delete.ts +43 -0
- package/src/methods/secret/list.ts +40 -0
- package/src/methods/secret/set.ts +69 -0
- package/src/methods/state/get.ts +44 -0
- package/src/methods/state/patch.ts +51 -0
- package/src/methods/view/default.ts +32 -0
- package/src/methods/view/launch.ts +47 -0
- package/src/methods/view/revoke.ts +39 -0
- package/src/methods/view/rotate.ts +37 -0
- package/src/methods/view/url.ts +84 -0
- package/src/methods/wait/wait.ts +58 -0
- package/src/revision.ts +101 -0
- package/src/rpc/error.ts +107 -0
- package/src/rpc/lines.ts +70 -0
- package/src/rpc/messages.ts +188 -0
- package/src/rpc/peer.ts +341 -0
- package/src/serializer.ts +1217 -0
- package/src/timers.d.ts +8 -0
- package/src/verify.ts +458 -0
- package/src/view.ts +200 -0
- package/src/web-crypto.d.ts +9 -0
- package/src/web-platform.d.ts +35 -0
- package/src/wire-registry.ts +14 -0
- package/src/worker.ts +374 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { wireRegistry } from "../../wire-registry.js";
|
|
2
|
+
import { TokenId, VersionId } from "../../ids.js";
|
|
3
|
+
import { ArtifactRef } from "../../artifact.js";
|
|
4
|
+
import { Viewer, ViewerSpec } from "../../interaction.js";
|
|
5
|
+
import { CapabilityScope, Duration } from "../../capability.js";
|
|
6
|
+
import { defineMethod } from "../../method.js";
|
|
7
|
+
import * as z from "zod";
|
|
8
|
+
//#region src/methods/view/url.ts
|
|
9
|
+
/** The Zod schema of the `CapabilityLink` type. */
|
|
10
|
+
const CapabilityLink = z.object({
|
|
11
|
+
url: z.string().min(1),
|
|
12
|
+
tokenId: TokenId.schema,
|
|
13
|
+
scopes: z.array(CapabilityScope).readonly(),
|
|
14
|
+
expiresAt: z.iso.datetime().exactOptional(),
|
|
15
|
+
viewer: Viewer.exactOptional()
|
|
16
|
+
}).register(wireRegistry, {
|
|
17
|
+
id: "CapabilityLink",
|
|
18
|
+
description: "A capability URL with its token ID, scopes and expiry."
|
|
19
|
+
});
|
|
20
|
+
const params = z.object({
|
|
21
|
+
artifact: ArtifactRef,
|
|
22
|
+
version: z.union([z.int().min(1), VersionId.schema]).exactOptional(),
|
|
23
|
+
scopes: z.array(CapabilityScope).min(1).readonly().exactOptional(),
|
|
24
|
+
ttl: Duration.exactOptional(),
|
|
25
|
+
viewer: ViewerSpec.exactOptional(),
|
|
26
|
+
requestId: z.string().min(1).exactOptional()
|
|
27
|
+
}).register(wireRegistry, { id: "ViewUrlParams" });
|
|
28
|
+
/**
|
|
29
|
+
* `view/url`: mints a new capability link to an artifact, with the scopes and lifetime asked for.
|
|
30
|
+
* Each call mints a separate token that `view/revoke` ends on its own; the artifact's default link
|
|
31
|
+
* is the publish receipt's `url`.
|
|
32
|
+
*/
|
|
33
|
+
const viewUrlMethod = defineMethod({
|
|
34
|
+
method: "view/url",
|
|
35
|
+
direction: "client-to-instance",
|
|
36
|
+
mutating: true,
|
|
37
|
+
params,
|
|
38
|
+
result: CapabilityLink
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { CapabilityLink, viewUrlMethod };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","names":[],"sources":["../../../src/methods/view/url.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { ArtifactRef } from \"../../artifact.ts\";\nimport { CapabilityScope, Duration } from \"../../capability.ts\";\nimport { TokenId, VersionId } from \"../../ids.ts\";\nimport { Viewer, ViewerSpec } from \"../../interaction.ts\";\nimport { defineMethod, type MethodDefinition } from \"../../method.ts\";\nimport { wireRegistry } from \"../../wire-registry.ts\";\n\n/** The params of `view/url` (INTERFACES §6, D97). */\nexport interface ViewUrlParams {\n /** The artifact the link opens. */\n readonly artifact: ArtifactRef;\n /**\n * The version the link opens, by number or ID. Without it the link opens the artifact's latest\n * version whenever it is used.\n */\n readonly version?: number | string;\n /** What the link allows (D97). Default: every scope. `view` is always included. */\n readonly scopes?: readonly CapabilityScope[];\n /** How long the link works, such as `24h` or `7d`. Default: until it is revoked (D63). */\n readonly ttl?: Duration;\n /**\n * The person the link acts for (D104): its sessions draft, submit and sign as that viewer, so\n * `once` per-viewer gives each person one submission. Absent: the home's local user.\n */\n readonly viewer?: ViewerSpec;\n /** Makes retries idempotent: a repeated `requestId` returns the same link (H-03). */\n readonly requestId?: string;\n}\n\n/** A capability link: what `view/url` and `view/rotate` return. */\nexport interface CapabilityLink {\n /** The capability URL. Holding it is the authorization (D06); share it like a password. */\n readonly url: string;\n /** The token's ID, for `view/rotate` and `view/revoke`. Never a secret. */\n readonly tokenId: string;\n /** The scopes the link carries, `view` included. */\n readonly scopes: readonly CapabilityScope[];\n /** When the link stops working; absent when it works until revoked. */\n readonly expiresAt?: string;\n /** The viewer the link acts for, when it was minted with one (D104). */\n readonly viewer?: Viewer;\n}\n\n/** The result of `view/url`. */\nexport type ViewUrlResult = CapabilityLink;\n\n/** The Zod schema of the `CapabilityLink` type. */\nexport const CapabilityLink: z.ZodType<CapabilityLink> = z\n .object({\n url: z.string().min(1),\n tokenId: TokenId.schema,\n scopes: z.array(CapabilityScope).readonly(),\n expiresAt: z.iso.datetime().exactOptional(),\n viewer: Viewer.exactOptional(),\n })\n .register(wireRegistry, {\n id: \"CapabilityLink\",\n description: \"A capability URL with its token ID, scopes and expiry.\",\n });\n\nconst params: z.ZodType<ViewUrlParams> = z\n .object({\n artifact: ArtifactRef,\n version: z.union([z.int().min(1), VersionId.schema]).exactOptional(),\n scopes: z.array(CapabilityScope).min(1).readonly().exactOptional(),\n ttl: Duration.exactOptional(),\n viewer: ViewerSpec.exactOptional(),\n requestId: z.string().min(1).exactOptional(),\n })\n .register(wireRegistry, { id: \"ViewUrlParams\" });\n\n/**\n * `view/url`: mints a new capability link to an artifact, with the scopes and lifetime asked for.\n * Each call mints a separate token that `view/revoke` ends on its own; the artifact's default link\n * is the publish receipt's `url`.\n */\nexport const viewUrlMethod: MethodDefinition<ViewUrlParams, ViewUrlResult> = defineMethod({\n method: \"view/url\",\n direction: \"client-to-instance\",\n mutating: true,\n params,\n result: CapabilityLink,\n});\n"],"mappings":";;;;;;;;;AAgDA,MAAa,iBAA4C,EACtD,OAAO;CACN,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACrB,SAAS,QAAQ;CACjB,QAAQ,EAAE,MAAM,eAAe,CAAC,CAAC,SAAS;CAC1C,WAAW,EAAE,IAAI,SAAS,CAAC,CAAC,cAAc;CAC1C,QAAQ,OAAO,cAAc;AAC/B,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;AAEH,MAAM,SAAmC,EACtC,OAAO;CACN,UAAU;CACV,SAAS,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,MAAM,CAAC,CAAC,CAAC,cAAc;CACnE,QAAQ,EAAE,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc;CACjE,KAAK,SAAS,cAAc;CAC5B,QAAQ,WAAW,cAAc;CACjC,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc;AAC7C,CAAC,CAAC,CACD,SAAS,cAAc,EAAE,IAAI,gBAAgB,CAAC;;;;;;AAOjD,MAAa,gBAAgE,aAAa;CACxF,QAAQ;CACR,WAAW;CACX,UAAU;CACV;CACA,QAAQ;AACV,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ArtifactRef } from "../../artifact.js";
|
|
2
|
+
import { EventRecord, WaitCondition } from "../../interaction.js";
|
|
3
|
+
import { MethodDefinition } from "../../method.js";
|
|
4
|
+
//#region src/methods/wait/wait.d.ts
|
|
5
|
+
/** The longest `wait`, in milliseconds: the longest timer JavaScript keeps (about 24.8 days). */
|
|
6
|
+
export declare const WAIT_MAX_MS = 2147483647;
|
|
7
|
+
/** The params of `wait` (INTERFACES §6, ARCHITECTURE §6, D103). */
|
|
8
|
+
export interface WaitParams {
|
|
9
|
+
/** The artifact to wait on. */
|
|
10
|
+
readonly artifact: ArtifactRef;
|
|
11
|
+
/** `submitted`, `signal:<name>`, `state:<fieldId>` or `event:<type>`. */
|
|
12
|
+
readonly until: WaitCondition;
|
|
13
|
+
/**
|
|
14
|
+
* Wait for what happens after this cursor (edge-triggered conditions, and `submitted` under
|
|
15
|
+
* `epochs`). Default: the cursor of the artifact's latest publish.
|
|
16
|
+
*/
|
|
17
|
+
readonly after?: string;
|
|
18
|
+
/** How long to block, in milliseconds; 0 checks once. */
|
|
19
|
+
readonly timeoutMs: number;
|
|
20
|
+
}
|
|
21
|
+
/** The result of `wait`. */
|
|
22
|
+
export type WaitResult = {
|
|
23
|
+
readonly status: "satisfied";
|
|
24
|
+
readonly event: EventRecord;
|
|
25
|
+
readonly cursor: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly status: "still_waiting";
|
|
28
|
+
readonly cursor: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* `wait`: blocks until a condition holds or the timeout passes (IN-10). `satisfied` carries the
|
|
32
|
+
* event that met it; `still_waiting` carries the newest cursor examined, so a later wait from it
|
|
33
|
+
* misses nothing.
|
|
34
|
+
*/
|
|
35
|
+
export declare const waitMethod: MethodDefinition<WaitParams, WaitResult>;
|
|
36
|
+
//#endregion
|
|
37
|
+
//# sourceMappingURL=wait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.d.ts","names":[],"sources":["../../../src/methods/wait/wait.ts"],"mappings":";;;;;qBAQa;;iBAGI;;WAEN,UAAU;;WAEV,OAAO;;;;;WAKP;;WAEA;;;YAIC;WACG;WAA8B,OAAO;WAAsB;;WAC3D;WAAkC;;;;;;;qBAuBpC,YAAY,iBAAiB,YAAY"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { wireRegistry } from "../../wire-registry.js";
|
|
2
|
+
import { Cursor } from "../../ids.js";
|
|
3
|
+
import { ArtifactRef } from "../../artifact.js";
|
|
4
|
+
import { EventRecord, WaitCondition } from "../../interaction.js";
|
|
5
|
+
import { defineMethod } from "../../method.js";
|
|
6
|
+
import * as z from "zod";
|
|
7
|
+
//#region src/methods/wait/wait.ts
|
|
8
|
+
/** The longest `wait`, in milliseconds: the longest timer JavaScript keeps (about 24.8 days). */
|
|
9
|
+
const WAIT_MAX_MS = 2147483647;
|
|
10
|
+
const params = z.object({
|
|
11
|
+
artifact: ArtifactRef,
|
|
12
|
+
until: WaitCondition,
|
|
13
|
+
after: Cursor.schema.exactOptional(),
|
|
14
|
+
timeoutMs: z.int().min(0).max(WAIT_MAX_MS)
|
|
15
|
+
}).register(wireRegistry, { id: "WaitParams" });
|
|
16
|
+
const result = z.discriminatedUnion("status", [z.object({
|
|
17
|
+
status: z.literal("satisfied"),
|
|
18
|
+
event: EventRecord,
|
|
19
|
+
cursor: Cursor.schema
|
|
20
|
+
}), z.object({
|
|
21
|
+
status: z.literal("still_waiting"),
|
|
22
|
+
cursor: Cursor.schema
|
|
23
|
+
})]).register(wireRegistry, { id: "WaitResult" });
|
|
24
|
+
/**
|
|
25
|
+
* `wait`: blocks until a condition holds or the timeout passes (IN-10). `satisfied` carries the
|
|
26
|
+
* event that met it; `still_waiting` carries the newest cursor examined, so a later wait from it
|
|
27
|
+
* misses nothing.
|
|
28
|
+
*/
|
|
29
|
+
const waitMethod = defineMethod({
|
|
30
|
+
method: "wait",
|
|
31
|
+
direction: "client-to-instance",
|
|
32
|
+
mutating: false,
|
|
33
|
+
params,
|
|
34
|
+
result
|
|
35
|
+
});
|
|
36
|
+
//#endregion
|
|
37
|
+
export { WAIT_MAX_MS, waitMethod };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=wait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.js","names":[],"sources":["../../../src/methods/wait/wait.ts"],"sourcesContent":["import * as z from \"zod\";\nimport { ArtifactRef } from \"../../artifact.ts\";\nimport { Cursor } from \"../../ids.ts\";\nimport { EventRecord, WaitCondition } from \"../../interaction.ts\";\nimport { defineMethod, type MethodDefinition } from \"../../method.ts\";\nimport { wireRegistry } from \"../../wire-registry.ts\";\n\n/** The longest `wait`, in milliseconds: the longest timer JavaScript keeps (about 24.8 days). */\nexport const WAIT_MAX_MS = 2_147_483_647;\n\n/** The params of `wait` (INTERFACES §6, ARCHITECTURE §6, D103). */\nexport interface WaitParams {\n /** The artifact to wait on. */\n readonly artifact: ArtifactRef;\n /** `submitted`, `signal:<name>`, `state:<fieldId>` or `event:<type>`. */\n readonly until: WaitCondition;\n /**\n * Wait for what happens after this cursor (edge-triggered conditions, and `submitted` under\n * `epochs`). Default: the cursor of the artifact's latest publish.\n */\n readonly after?: string;\n /** How long to block, in milliseconds; 0 checks once. */\n readonly timeoutMs: number;\n}\n\n/** The result of `wait`. */\nexport type WaitResult =\n | { readonly status: \"satisfied\"; readonly event: EventRecord; readonly cursor: string }\n | { readonly status: \"still_waiting\"; readonly cursor: string };\n\nconst params: z.ZodType<WaitParams> = z\n .object({\n artifact: ArtifactRef,\n until: WaitCondition,\n after: Cursor.schema.exactOptional(),\n timeoutMs: z.int().min(0).max(WAIT_MAX_MS),\n })\n .register(wireRegistry, { id: \"WaitParams\" });\n\nconst result: z.ZodType<WaitResult> = z\n .discriminatedUnion(\"status\", [\n z.object({ status: z.literal(\"satisfied\"), event: EventRecord, cursor: Cursor.schema }),\n z.object({ status: z.literal(\"still_waiting\"), cursor: Cursor.schema }),\n ])\n .register(wireRegistry, { id: \"WaitResult\" });\n\n/**\n * `wait`: blocks until a condition holds or the timeout passes (IN-10). `satisfied` carries the\n * event that met it; `still_waiting` carries the newest cursor examined, so a later wait from it\n * misses nothing.\n */\nexport const waitMethod: MethodDefinition<WaitParams, WaitResult> = defineMethod({\n method: \"wait\",\n direction: \"client-to-instance\",\n mutating: false,\n params,\n result,\n});\n"],"mappings":";;;;;;;;AAQA,MAAa,cAAc;AAsB3B,MAAM,SAAgC,EACnC,OAAO;CACN,UAAU;CACV,OAAO;CACP,OAAO,OAAO,OAAO,cAAc;CACnC,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,WAAW;AAC3C,CAAC,CAAC,CACD,SAAS,cAAc,EAAE,IAAI,aAAa,CAAC;AAE9C,MAAM,SAAgC,EACnC,mBAAmB,UAAU,CAC5B,EAAE,OAAO;CAAE,QAAQ,EAAE,QAAQ,WAAW;CAAG,OAAO;CAAa,QAAQ,OAAO;AAAO,CAAC,GACtF,EAAE,OAAO;CAAE,QAAQ,EAAE,QAAQ,eAAe;CAAG,QAAQ,OAAO;AAAO,CAAC,CACxE,CAAC,CAAC,CACD,SAAS,cAAc,EAAE,IAAI,aAAa,CAAC;;;;;;AAO9C,MAAa,aAAuD,aAAa;CAC/E,QAAQ;CACR,WAAW;CACX,UAAU;CACV;CACA;AACF,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Diagnostic } from "./diagnostics/diagnostic.js";
|
|
2
|
+
import { CreateDiagnosticOptions } from "./diagnostics/codes/index.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/revision.d.ts
|
|
5
|
+
/** A protocol revision: a calendar date in `YYYY-MM-DD` form. */
|
|
6
|
+
export type Revision = string & {
|
|
7
|
+
readonly __mostraRevision: true;
|
|
8
|
+
};
|
|
9
|
+
/** Protocol revisions. */
|
|
10
|
+
export declare const Revision: {
|
|
11
|
+
/** The textual form. `is` and `parse` also reject impossible dates such as `2026-02-30`. */
|
|
12
|
+
readonly pattern: RegExp;
|
|
13
|
+
readonly schema: z.ZodType<Revision, string>;
|
|
14
|
+
is(value: unknown): value is Revision;
|
|
15
|
+
/** @throws TypeError when `value` is not a real calendar date in `YYYY-MM-DD` form. */
|
|
16
|
+
parse(value: string): Revision;
|
|
17
|
+
/** Orders revisions by date: negative when `a` is older than `b`. */
|
|
18
|
+
compare(a: Revision, b: Revision): number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The host protocol revisions this package's schemas describe, newest first. A runtime built on
|
|
22
|
+
* this package supports exactly these.
|
|
23
|
+
*/
|
|
24
|
+
export declare const HOST_PROTOCOL_REVISIONS: readonly Revision[];
|
|
25
|
+
/** The outcome of {@link negotiateRevision}. */
|
|
26
|
+
export type RevisionNegotiation = {
|
|
27
|
+
readonly ok: true;
|
|
28
|
+
readonly revision: Revision;
|
|
29
|
+
} | {
|
|
30
|
+
readonly ok: false;
|
|
31
|
+
readonly diagnostic: Diagnostic;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Picks the newest host protocol revision that both sides support. When there is none, returns
|
|
35
|
+
* the refusal diagnostic `MOSTRA_HOST_REVISION_UNSUPPORTED`, which the instance sends back as the
|
|
36
|
+
* error of `mostra/initialize`.
|
|
37
|
+
*
|
|
38
|
+
* Offered entries that are not revisions never match, and the message lists only well-formed
|
|
39
|
+
* ones, so a malformed offer can't inject text into the diagnostic.
|
|
40
|
+
*/
|
|
41
|
+
export declare function negotiateRevision(offered: readonly string[], supported?: readonly Revision[], options?: CreateDiagnosticOptions): RevisionNegotiation;
|
|
42
|
+
//#endregion
|
|
43
|
+
//# sourceMappingURL=revision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revision.d.ts","names":[],"sources":["../src/revision.ts"],"mappings":";;;;;YAaY;WAA+B;;;qBAW9B;;WAEF,SAAS;WACT,QAAQ,EAAE,QAAQ;EAC3B,GAAG,iBAAiB,SAAS;;EAE7B,MAAM,gBAAgB;;EAEtB,QAAQ,GAAG,UAAU,GAAG;;;;;;qBAuBb,kCAAkC;;YAGnC;WACG;WAAmB,UAAU;;WAC7B;WAAoB,YAAY;;;;;;;;;;wBAiB/B,kBACd,4BACA,qBAAoB,YACpB,UAAS,0BACR"}
|
package/dist/revision.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { wireRegistry } from "./wire-registry.js";
|
|
2
|
+
import { createDiagnostic } from "./diagnostics/codes/index.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/revision.ts
|
|
5
|
+
/**
|
|
6
|
+
* Dated protocol revisions and their negotiation (INTERFACES §1, STANDARDS versioning, D59).
|
|
7
|
+
*
|
|
8
|
+
* The host protocol and the browser protocol each carry a revision named by a date
|
|
9
|
+
* (`2026-10-10`). A revision only changes additively. A breaking change needs a new revision, and
|
|
10
|
+
* the old one stays supported for at least 12 months.
|
|
11
|
+
*/
|
|
12
|
+
const PATTERN = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
13
|
+
function isRevision(value) {
|
|
14
|
+
if (typeof value !== "string" || !PATTERN.test(value)) return false;
|
|
15
|
+
const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
16
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(value);
|
|
17
|
+
}
|
|
18
|
+
/** Protocol revisions. */
|
|
19
|
+
const Revision = {
|
|
20
|
+
pattern: PATTERN,
|
|
21
|
+
schema: z.iso.date().register(wireRegistry, {
|
|
22
|
+
id: "Revision",
|
|
23
|
+
description: "Protocol revision: a calendar date in YYYY-MM-DD form."
|
|
24
|
+
}),
|
|
25
|
+
is: isRevision,
|
|
26
|
+
parse(value) {
|
|
27
|
+
if (isRevision(value)) return value;
|
|
28
|
+
throw new TypeError("Expected a protocol revision: a calendar date in YYYY-MM-DD form.");
|
|
29
|
+
},
|
|
30
|
+
compare(a, b) {
|
|
31
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The host protocol revisions this package's schemas describe, newest first. A runtime built on
|
|
36
|
+
* this package supports exactly these.
|
|
37
|
+
*/
|
|
38
|
+
const HOST_PROTOCOL_REVISIONS = [Revision.parse("2026-10-10")];
|
|
39
|
+
const LISTED = 8;
|
|
40
|
+
function list(revisions) {
|
|
41
|
+
const shown = revisions.slice(0, LISTED).join(", ");
|
|
42
|
+
return revisions.length > LISTED ? `${shown} and ${revisions.length - LISTED} more` : shown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Picks the newest host protocol revision that both sides support. When there is none, returns
|
|
46
|
+
* the refusal diagnostic `MOSTRA_HOST_REVISION_UNSUPPORTED`, which the instance sends back as the
|
|
47
|
+
* error of `mostra/initialize`.
|
|
48
|
+
*
|
|
49
|
+
* Offered entries that are not revisions never match, and the message lists only well-formed
|
|
50
|
+
* ones, so a malformed offer can't inject text into the diagnostic.
|
|
51
|
+
*/
|
|
52
|
+
function negotiateRevision(offered, supported = HOST_PROTOCOL_REVISIONS, options = {}) {
|
|
53
|
+
const offeredRevisions = [...new Set(offered.filter(isRevision))].sort(Revision.compare);
|
|
54
|
+
const newest = offeredRevisions.filter((revision) => supported.includes(revision)).at(-1);
|
|
55
|
+
if (newest !== void 0) return {
|
|
56
|
+
ok: true,
|
|
57
|
+
revision: newest
|
|
58
|
+
};
|
|
59
|
+
const supportedList = [...supported].sort(Revision.compare).reverse();
|
|
60
|
+
const offeredText = offeredRevisions.length > 0 ? `The client offered host protocol revisions ${list(offeredRevisions.reverse())}` : "The client offered no valid host protocol revision";
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
diagnostic: createDiagnostic("MOSTRA_HOST_REVISION_UNSUPPORTED", { message: `${offeredText}; this instance supports ${list(supportedList)}.` }, options)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { HOST_PROTOCOL_REVISIONS, Revision, negotiateRevision };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=revision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revision.js","names":[],"sources":["../src/revision.ts"],"sourcesContent":["/**\n * Dated protocol revisions and their negotiation (INTERFACES §1, STANDARDS versioning, D59).\n *\n * The host protocol and the browser protocol each carry a revision named by a date\n * (`2026-10-10`). A revision only changes additively. A breaking change needs a new revision, and\n * the old one stays supported for at least 12 months.\n */\nimport * as z from \"zod\";\nimport { type CreateDiagnosticOptions, createDiagnostic } from \"./diagnostics/codes/index.ts\";\nimport type { Diagnostic } from \"./diagnostics/diagnostic.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** A protocol revision: a calendar date in `YYYY-MM-DD` form. */\nexport type Revision = string & { readonly __mostraRevision: true };\n\nconst PATTERN = /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/;\n\nfunction isRevision(value: unknown): value is Revision {\n if (typeof value !== \"string\" || !PATTERN.test(value)) return false;\n const date = new Date(`${value}T00:00:00Z`);\n return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(value);\n}\n\n/** Protocol revisions. */\nexport const Revision: {\n /** The textual form. `is` and `parse` also reject impossible dates such as `2026-02-30`. */\n readonly pattern: RegExp;\n readonly schema: z.ZodType<Revision, string>;\n is(value: unknown): value is Revision;\n /** @throws TypeError when `value` is not a real calendar date in `YYYY-MM-DD` form. */\n parse(value: string): Revision;\n /** Orders revisions by date: negative when `a` is older than `b`. */\n compare(a: Revision, b: Revision): number;\n} = {\n pattern: PATTERN,\n // z.iso.date() checks calendar validity in its emitted pattern, so the published JSON Schema\n // rejects 2026-02-30 just as `parse` does.\n schema: z.iso.date().register(wireRegistry, {\n id: \"Revision\",\n description: \"Protocol revision: a calendar date in YYYY-MM-DD form.\",\n }) as unknown as z.ZodType<Revision, string>,\n is: isRevision,\n parse(value: string): Revision {\n if (isRevision(value)) return value;\n throw new TypeError(\"Expected a protocol revision: a calendar date in YYYY-MM-DD form.\");\n },\n compare(a: Revision, b: Revision): number {\n return a < b ? -1 : a > b ? 1 : 0;\n },\n};\n\n/**\n * The host protocol revisions this package's schemas describe, newest first. A runtime built on\n * this package supports exactly these.\n */\nexport const HOST_PROTOCOL_REVISIONS: readonly Revision[] = [Revision.parse(\"2026-10-10\")];\n\n/** The outcome of {@link negotiateRevision}. */\nexport type RevisionNegotiation =\n | { readonly ok: true; readonly revision: Revision }\n | { readonly ok: false; readonly diagnostic: Diagnostic };\n\nconst LISTED = 8;\n\nfunction list(revisions: readonly string[]): string {\n const shown = revisions.slice(0, LISTED).join(\", \");\n return revisions.length > LISTED ? `${shown} and ${revisions.length - LISTED} more` : shown;\n}\n\n/**\n * Picks the newest host protocol revision that both sides support. When there is none, returns\n * the refusal diagnostic `MOSTRA_HOST_REVISION_UNSUPPORTED`, which the instance sends back as the\n * error of `mostra/initialize`.\n *\n * Offered entries that are not revisions never match, and the message lists only well-formed\n * ones, so a malformed offer can't inject text into the diagnostic.\n */\nexport function negotiateRevision(\n offered: readonly string[],\n supported: readonly Revision[] = HOST_PROTOCOL_REVISIONS,\n options: CreateDiagnosticOptions = {},\n): RevisionNegotiation {\n const offeredRevisions = [...new Set(offered.filter(isRevision))].sort(Revision.compare);\n const common = offeredRevisions.filter((revision) => supported.includes(revision));\n const newest = common.at(-1);\n if (newest !== undefined) return { ok: true, revision: newest };\n\n const supportedList = [...supported].sort(Revision.compare).reverse();\n const offeredText =\n offeredRevisions.length > 0\n ? `The client offered host protocol revisions ${list(offeredRevisions.reverse())}`\n : \"The client offered no valid host protocol revision\";\n return {\n ok: false,\n diagnostic: createDiagnostic(\n \"MOSTRA_HOST_REVISION_UNSUPPORTED\",\n { message: `${offeredText}; this instance supports ${list(supportedList)}.` },\n options,\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,UAAU;AAEhB,SAAS,WAAW,OAAmC;CACrD,IAAI,OAAO,UAAU,YAAY,CAAC,QAAQ,KAAK,KAAK,GAAG,OAAO;CAC9D,MAAM,uBAAO,IAAI,KAAK,GAAG,MAAM,WAAW;CAC1C,OAAO,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,WAAW,KAAK;AAC7E;;AAGA,MAAa,WAST;CACF,SAAS;CAGT,QAAQ,EAAE,IAAI,KAAK,CAAC,CAAC,SAAS,cAAc;EAC1C,IAAI;EACJ,aAAa;CACf,CAAC;CACD,IAAI;CACJ,MAAM,OAAyB;EAC7B,IAAI,WAAW,KAAK,GAAG,OAAO;EAC9B,MAAM,IAAI,UAAU,mEAAmE;CACzF;CACA,QAAQ,GAAa,GAAqB;EACxC,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;CAClC;AACF;;;;;AAMA,MAAa,0BAA+C,CAAC,SAAS,MAAM,YAAY,CAAC;AAOzF,MAAM,SAAS;AAEf,SAAS,KAAK,WAAsC;CAClD,MAAM,QAAQ,UAAU,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,IAAI;CAClD,OAAO,UAAU,SAAS,SAAS,GAAG,MAAM,OAAO,UAAU,SAAS,OAAO,SAAS;AACxF;;;;;;;;;AAUA,SAAgB,kBACd,SACA,YAAiC,yBACjC,UAAmC,CAAC,GACf;CACrB,MAAM,mBAAmB,CAAC,GAAG,IAAI,IAAI,QAAQ,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,OAAO;CAEvF,MAAM,SADS,iBAAiB,QAAQ,aAAa,UAAU,SAAS,QAAQ,CAC5D,CAAC,CAAC,GAAG,EAAE;CAC3B,IAAI,WAAW,KAAA,GAAW,OAAO;EAAE,IAAI;EAAM,UAAU;CAAO;CAE9D,MAAM,gBAAgB,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,SAAS,OAAO,CAAC,CAAC,QAAQ;CACpE,MAAM,cACJ,iBAAiB,SAAS,IACtB,8CAA8C,KAAK,iBAAiB,QAAQ,CAAC,MAC7E;CACN,OAAO;EACL,IAAI;EACJ,YAAY,iBACV,oCACA,EAAE,SAAS,GAAG,YAAY,2BAA2B,KAAK,aAAa,EAAE,GAAG,GAC5E,OACF;CACF;AACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Diagnostic } from "../diagnostics/diagnostic.js";
|
|
2
|
+
import "../diagnostics/spec.js";
|
|
3
|
+
import "../diagnostics/codes/host.js";
|
|
4
|
+
import { JsonRpcErrorObject } from "./messages.js";
|
|
5
|
+
//#region src/rpc/error.d.ts
|
|
6
|
+
/** The JSON-RPC 2.0 error codes Mostra uses (INTERFACES §6). */
|
|
7
|
+
export declare const JSON_RPC_ERROR_CODES: {
|
|
8
|
+
/** The line wasn't valid JSON. */
|
|
9
|
+
readonly parseError: -32700;
|
|
10
|
+
/** The message wasn't a valid request, or was a batch. */
|
|
11
|
+
readonly invalidRequest: -32600;
|
|
12
|
+
/** The method doesn't exist on this side. */
|
|
13
|
+
readonly methodNotFound: -32601;
|
|
14
|
+
/** The params failed the method's schema. */
|
|
15
|
+
readonly invalidParams: -32602;
|
|
16
|
+
/** An unexpected failure. */
|
|
17
|
+
readonly internalError: -32603;
|
|
18
|
+
/** Every other diagnostic. */
|
|
19
|
+
readonly diagnostic: -32000;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* An error that crosses a connection as a JSON-RPC error. Throw it from a request handler to
|
|
23
|
+
* answer with this diagnostic; a request's promise rejects with it when the other side answers
|
|
24
|
+
* with an error, the connection closes or the request times out.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* throw new RpcError(
|
|
28
|
+
* createDiagnostic("MOSTRA_HOME_MISMATCH", { message: "This instance serves /a, not /b." }),
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class RpcError extends Error {
|
|
33
|
+
/** The JSON-RPC error code. */
|
|
34
|
+
readonly code: number;
|
|
35
|
+
/** The diagnostic: what happened and what to do. */
|
|
36
|
+
readonly diagnostic: Diagnostic;
|
|
37
|
+
constructor(diagnostic: Diagnostic, code?: number);
|
|
38
|
+
/** The JSON-RPC error object for a response. */
|
|
39
|
+
toErrorObject(): JsonRpcErrorObject;
|
|
40
|
+
/**
|
|
41
|
+
* Reads a received error object. When its `data` isn't a diagnostic (a peer that isn't Mostra),
|
|
42
|
+
* the result is a `MOSTRA_HOST_MALFORMED` diagnostic that keeps the peer's message.
|
|
43
|
+
*/
|
|
44
|
+
static fromErrorObject(error: JsonRpcErrorObject, docsBase?: string): RpcError;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","names":[],"sources":["../../src/rpc/error.ts"],"mappings":";;;;;;qBAUa;;WAEF;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;;;;;;;qBAoCE,iBAAiB;;WAEnB;;WAEA,YAAY;EAErB,YAAY,YAAY,YAAY;;EAQpC,iBAAiB;;;;;SAQV,gBAAgB,OAAO,oBAAoB,oBAAoB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { hostDiagnostics } from "../diagnostics/codes/host.js";
|
|
2
|
+
import { Diagnostic } from "../diagnostics/diagnostic.js";
|
|
3
|
+
import { buildDiagnostic } from "../diagnostics/spec.js";
|
|
4
|
+
//#region src/rpc/error.ts
|
|
5
|
+
/**
|
|
6
|
+
* Errors on a JSON-RPC connection. Every error carries a diagnostic (INTERFACES §1, §6): the
|
|
7
|
+
* JSON-RPC `error.code` says which kind of failure it is, and `error.data` is the diagnostic.
|
|
8
|
+
*/
|
|
9
|
+
/** The JSON-RPC 2.0 error codes Mostra uses (INTERFACES §6). */
|
|
10
|
+
const JSON_RPC_ERROR_CODES = {
|
|
11
|
+
parseError: -32700,
|
|
12
|
+
invalidRequest: -32600,
|
|
13
|
+
methodNotFound: -32601,
|
|
14
|
+
invalidParams: -32602,
|
|
15
|
+
internalError: -32603,
|
|
16
|
+
diagnostic: -32e3
|
|
17
|
+
};
|
|
18
|
+
function codeFor(diagnostic) {
|
|
19
|
+
switch (diagnostic.code) {
|
|
20
|
+
case "MOSTRA_HOST_MALFORMED": return JSON_RPC_ERROR_CODES.invalidRequest;
|
|
21
|
+
case "MOSTRA_HOST_METHOD_UNKNOWN": return JSON_RPC_ERROR_CODES.methodNotFound;
|
|
22
|
+
case "MOSTRA_HOST_INVALID_PARAMS": return JSON_RPC_ERROR_CODES.invalidParams;
|
|
23
|
+
case "MOSTRA_HOST_INTERNAL_ERROR": return JSON_RPC_ERROR_CODES.internalError;
|
|
24
|
+
default: return JSON_RPC_ERROR_CODES.diagnostic;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An error that crosses a connection as a JSON-RPC error. Throw it from a request handler to
|
|
29
|
+
* answer with this diagnostic; a request's promise rejects with it when the other side answers
|
|
30
|
+
* with an error, the connection closes or the request times out.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* throw new RpcError(
|
|
34
|
+
* createDiagnostic("MOSTRA_HOME_MISMATCH", { message: "This instance serves /a, not /b." }),
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
var RpcError = class RpcError extends Error {
|
|
39
|
+
/** The JSON-RPC error code. */
|
|
40
|
+
code;
|
|
41
|
+
/** The diagnostic: what happened and what to do. */
|
|
42
|
+
diagnostic;
|
|
43
|
+
constructor(diagnostic, code = codeFor(diagnostic)) {
|
|
44
|
+
super(diagnostic.message);
|
|
45
|
+
this.name = "RpcError";
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.diagnostic = diagnostic;
|
|
48
|
+
}
|
|
49
|
+
/** The JSON-RPC error object for a response. */
|
|
50
|
+
toErrorObject() {
|
|
51
|
+
return {
|
|
52
|
+
code: this.code,
|
|
53
|
+
message: this.diagnostic.message,
|
|
54
|
+
data: this.diagnostic
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reads a received error object. When its `data` isn't a diagnostic (a peer that isn't Mostra),
|
|
59
|
+
* the result is a `MOSTRA_HOST_MALFORMED` diagnostic that keeps the peer's message.
|
|
60
|
+
*/
|
|
61
|
+
static fromErrorObject(error, docsBase) {
|
|
62
|
+
const parsed = Diagnostic.safeParse(error.data);
|
|
63
|
+
if (parsed.success) return new RpcError(parsed.data, error.code);
|
|
64
|
+
return new RpcError(hostDiagnostic("MOSTRA_HOST_MALFORMED", { message: `The other side answered with error ${error.code} without a diagnostic: ${error.message.slice(0, 200)}` }, docsBase), error.code);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Builds a HOST-area diagnostic from that area's catalog alone, so the JSON-RPC core doesn't pull
|
|
69
|
+
* every area's text into browser bundles (D83).
|
|
70
|
+
*/
|
|
71
|
+
function hostDiagnostic(code, details, docsBase) {
|
|
72
|
+
return buildDiagnostic(code, hostDiagnostics[code], details, docsBase);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { JSON_RPC_ERROR_CODES, RpcError, hostDiagnostic };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../src/rpc/error.ts"],"sourcesContent":["/**\n * Errors on a JSON-RPC connection. Every error carries a diagnostic (INTERFACES §1, §6): the\n * JSON-RPC `error.code` says which kind of failure it is, and `error.data` is the diagnostic.\n */\nimport { type HostDiagnosticCode, hostDiagnostics } from \"../diagnostics/codes/host.ts\";\nimport { Diagnostic } from \"../diagnostics/diagnostic.ts\";\nimport { buildDiagnostic, type DiagnosticDetails } from \"../diagnostics/spec.ts\";\nimport type { JsonRpcErrorObject } from \"./messages.ts\";\n\n/** The JSON-RPC 2.0 error codes Mostra uses (INTERFACES §6). */\nexport const JSON_RPC_ERROR_CODES: {\n /** The line wasn't valid JSON. */\n readonly parseError: -32700;\n /** The message wasn't a valid request, or was a batch. */\n readonly invalidRequest: -32600;\n /** The method doesn't exist on this side. */\n readonly methodNotFound: -32601;\n /** The params failed the method's schema. */\n readonly invalidParams: -32602;\n /** An unexpected failure. */\n readonly internalError: -32603;\n /** Every other diagnostic. */\n readonly diagnostic: -32000;\n} = {\n parseError: -32700,\n invalidRequest: -32600,\n methodNotFound: -32601,\n invalidParams: -32602,\n internalError: -32603,\n diagnostic: -32000,\n};\n\nfunction codeFor(diagnostic: Diagnostic): number {\n switch (diagnostic.code) {\n case \"MOSTRA_HOST_MALFORMED\":\n return JSON_RPC_ERROR_CODES.invalidRequest;\n case \"MOSTRA_HOST_METHOD_UNKNOWN\":\n return JSON_RPC_ERROR_CODES.methodNotFound;\n case \"MOSTRA_HOST_INVALID_PARAMS\":\n return JSON_RPC_ERROR_CODES.invalidParams;\n case \"MOSTRA_HOST_INTERNAL_ERROR\":\n return JSON_RPC_ERROR_CODES.internalError;\n default:\n return JSON_RPC_ERROR_CODES.diagnostic;\n }\n}\n\n/**\n * An error that crosses a connection as a JSON-RPC error. Throw it from a request handler to\n * answer with this diagnostic; a request's promise rejects with it when the other side answers\n * with an error, the connection closes or the request times out.\n *\n * ```ts\n * throw new RpcError(\n * createDiagnostic(\"MOSTRA_HOME_MISMATCH\", { message: \"This instance serves /a, not /b.\" }),\n * );\n * ```\n */\nexport class RpcError extends Error {\n /** The JSON-RPC error code. */\n readonly code: number;\n /** The diagnostic: what happened and what to do. */\n readonly diagnostic: Diagnostic;\n\n constructor(diagnostic: Diagnostic, code: number = codeFor(diagnostic)) {\n super(diagnostic.message);\n this.name = \"RpcError\";\n this.code = code;\n this.diagnostic = diagnostic;\n }\n\n /** The JSON-RPC error object for a response. */\n toErrorObject(): JsonRpcErrorObject {\n return { code: this.code, message: this.diagnostic.message, data: this.diagnostic };\n }\n\n /**\n * Reads a received error object. When its `data` isn't a diagnostic (a peer that isn't Mostra),\n * the result is a `MOSTRA_HOST_MALFORMED` diagnostic that keeps the peer's message.\n */\n static fromErrorObject(error: JsonRpcErrorObject, docsBase?: string): RpcError {\n const parsed = Diagnostic.safeParse(error.data);\n if (parsed.success) return new RpcError(parsed.data, error.code);\n return new RpcError(\n hostDiagnostic(\n \"MOSTRA_HOST_MALFORMED\",\n {\n message: `The other side answered with error ${error.code} without a diagnostic: ${error.message.slice(0, 200)}`,\n },\n docsBase,\n ),\n error.code,\n );\n }\n}\n\n/**\n * Builds a HOST-area diagnostic from that area's catalog alone, so the JSON-RPC core doesn't pull\n * every area's text into browser bundles (D83).\n */\nexport function hostDiagnostic(\n code: HostDiagnosticCode,\n details: DiagnosticDetails,\n docsBase?: string,\n): Diagnostic {\n return buildDiagnostic(code, hostDiagnostics[code], details, docsBase);\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,uBAaT;CACF,YAAY;CACZ,gBAAgB;CAChB,gBAAgB;CAChB,eAAe;CACf,eAAe;CACf,YAAY;AACd;AAEA,SAAS,QAAQ,YAAgC;CAC/C,QAAQ,WAAW,MAAnB;EACE,KAAK,yBACH,OAAO,qBAAqB;EAC9B,KAAK,8BACH,OAAO,qBAAqB;EAC9B,KAAK,8BACH,OAAO,qBAAqB;EAC9B,KAAK,8BACH,OAAO,qBAAqB;EAC9B,SACE,OAAO,qBAAqB;CAChC;AACF;;;;;;;;;;;;AAaA,IAAa,WAAb,MAAa,iBAAiB,MAAM;;CAElC;;CAEA;CAEA,YAAY,YAAwB,OAAe,QAAQ,UAAU,GAAG;EACtE,MAAM,WAAW,OAAO;EACxB,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;;CAGA,gBAAoC;EAClC,OAAO;GAAE,MAAM,KAAK;GAAM,SAAS,KAAK,WAAW;GAAS,MAAM,KAAK;EAAW;CACpF;;;;;CAMA,OAAO,gBAAgB,OAA2B,UAA6B;EAC7E,MAAM,SAAS,WAAW,UAAU,MAAM,IAAI;EAC9C,IAAI,OAAO,SAAS,OAAO,IAAI,SAAS,OAAO,MAAM,MAAM,IAAI;EAC/D,OAAO,IAAI,SACT,eACE,yBACA,EACE,SAAS,sCAAsC,MAAM,KAAK,yBAAyB,MAAM,QAAQ,MAAM,GAAG,GAAG,IAC/G,GACA,QACF,GACA,MAAM,IACR;CACF;AACF;;;;;AAMA,SAAgB,eACd,MACA,SACA,UACY;CACZ,OAAO,gBAAgB,MAAM,gBAAgB,OAAO,SAAS,QAAQ;AACvE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { JsonRpcMessage } from "./messages.js";
|
|
2
|
+
//#region src/rpc/lines.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The longest line, in UTF-16 code units, either side of a newline-delimited connection accepts:
|
|
5
|
+
* 64 Mi. Writers check it too, so a message that couldn't be read is never sent.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_LINE_LENGTH: number;
|
|
8
|
+
/** Serializes one message as a line, newline included. */
|
|
9
|
+
export declare function encodeLine(message: JsonRpcMessage): string;
|
|
10
|
+
/**
|
|
11
|
+
* Splits decoded text into lines. Feed it chunks as they arrive; it returns the complete lines
|
|
12
|
+
* and keeps the unfinished rest. A line longer than `maxLineLength` characters throws a
|
|
13
|
+
* `RangeError`, so a peer can't make the other side buffer without bound: the transport then
|
|
14
|
+
* answers with `MOSTRA_HOST_MALFORMED` and closes the connection.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LineSplitter {
|
|
17
|
+
#private;
|
|
18
|
+
/** @param maxLineLength - The longest line accepted, in UTF-16 code units. Default 64 Mi. */
|
|
19
|
+
constructor(maxLineLength?: number);
|
|
20
|
+
/**
|
|
21
|
+
* Returns the lines completed by `chunk`, without their newlines (and without a trailing `\r`).
|
|
22
|
+
* Only `chunk` is searched for newlines, so a long line costs time in proportion to its length,
|
|
23
|
+
* however many chunks bring it.
|
|
24
|
+
*/
|
|
25
|
+
push(chunk: string): string[];
|
|
26
|
+
/** The unfinished text after the last newline. A stream that ends with it holds a cut-off message. */
|
|
27
|
+
get rest(): string;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//# sourceMappingURL=lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.d.ts","names":[],"sources":["../../src/rpc/lines.ts"],"mappings":";;;;;;qBAUa;;wBAGG,WAAW,SAAS;;;;;;;qBAUvB;;;EAOX,YAAY;;;;;;EASZ,KAAK;;MAqBD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/rpc/lines.ts
|
|
2
|
+
/**
|
|
3
|
+
* The longest line, in UTF-16 code units, either side of a newline-delimited connection accepts:
|
|
4
|
+
* 64 Mi. Writers check it too, so a message that couldn't be read is never sent.
|
|
5
|
+
*/
|
|
6
|
+
const MAX_LINE_LENGTH = 67108864;
|
|
7
|
+
/** Serializes one message as a line, newline included. */
|
|
8
|
+
function encodeLine(message) {
|
|
9
|
+
return `${JSON.stringify(message)}\n`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Splits decoded text into lines. Feed it chunks as they arrive; it returns the complete lines
|
|
13
|
+
* and keeps the unfinished rest. A line longer than `maxLineLength` characters throws a
|
|
14
|
+
* `RangeError`, so a peer can't make the other side buffer without bound: the transport then
|
|
15
|
+
* answers with `MOSTRA_HOST_MALFORMED` and closes the connection.
|
|
16
|
+
*/
|
|
17
|
+
var LineSplitter = class {
|
|
18
|
+
#maxLineLength;
|
|
19
|
+
/** The unfinished line, in the pieces it arrived in: joined only once its newline comes. */
|
|
20
|
+
#pending = [];
|
|
21
|
+
#pendingLength = 0;
|
|
22
|
+
/** @param maxLineLength - The longest line accepted, in UTF-16 code units. Default 64 Mi. */
|
|
23
|
+
constructor(maxLineLength = MAX_LINE_LENGTH) {
|
|
24
|
+
this.#maxLineLength = maxLineLength;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the lines completed by `chunk`, without their newlines (and without a trailing `\r`).
|
|
28
|
+
* Only `chunk` is searched for newlines, so a long line costs time in proportion to its length,
|
|
29
|
+
* however many chunks bring it.
|
|
30
|
+
*/
|
|
31
|
+
push(chunk) {
|
|
32
|
+
const lines = [];
|
|
33
|
+
let start = 0;
|
|
34
|
+
for (let index = chunk.indexOf("\n"); index >= 0; index = chunk.indexOf("\n", start)) {
|
|
35
|
+
if (this.#pendingLength + index - start > this.#maxLineLength) this.#overflow();
|
|
36
|
+
this.#pending.push(chunk.slice(start, index));
|
|
37
|
+
const line = this.#pending.join("");
|
|
38
|
+
this.#pending = [];
|
|
39
|
+
this.#pendingLength = 0;
|
|
40
|
+
lines.push(line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
41
|
+
start = index + 1;
|
|
42
|
+
}
|
|
43
|
+
if (start < chunk.length) {
|
|
44
|
+
this.#pendingLength += chunk.length - start;
|
|
45
|
+
if (this.#pendingLength > this.#maxLineLength) this.#overflow();
|
|
46
|
+
this.#pending.push(chunk.slice(start));
|
|
47
|
+
}
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
/** The unfinished text after the last newline. A stream that ends with it holds a cut-off message. */
|
|
51
|
+
get rest() {
|
|
52
|
+
return this.#pending.join("");
|
|
53
|
+
}
|
|
54
|
+
#overflow() {
|
|
55
|
+
this.#pending = [];
|
|
56
|
+
this.#pendingLength = 0;
|
|
57
|
+
throw new RangeError(`A message is longer than ${this.#maxLineLength} characters.`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { LineSplitter, MAX_LINE_LENGTH, encodeLine };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.js","names":[],"sources":["../../src/rpc/lines.ts"],"sourcesContent":["/**\n * Newline-delimited JSON framing for byte streams (stdio, Unix sockets): one message per line.\n * JSON text never contains a raw newline, so a newline always ends a message.\n */\nimport type { JsonRpcMessage } from \"./messages.ts\";\n\n/**\n * The longest line, in UTF-16 code units, either side of a newline-delimited connection accepts:\n * 64 Mi. Writers check it too, so a message that couldn't be read is never sent.\n */\nexport const MAX_LINE_LENGTH: number = 64 * 1024 * 1024;\n\n/** Serializes one message as a line, newline included. */\nexport function encodeLine(message: JsonRpcMessage): string {\n return `${JSON.stringify(message)}\\n`;\n}\n\n/**\n * Splits decoded text into lines. Feed it chunks as they arrive; it returns the complete lines\n * and keeps the unfinished rest. A line longer than `maxLineLength` characters throws a\n * `RangeError`, so a peer can't make the other side buffer without bound: the transport then\n * answers with `MOSTRA_HOST_MALFORMED` and closes the connection.\n */\nexport class LineSplitter {\n readonly #maxLineLength: number;\n /** The unfinished line, in the pieces it arrived in: joined only once its newline comes. */\n #pending: string[] = [];\n #pendingLength = 0;\n\n /** @param maxLineLength - The longest line accepted, in UTF-16 code units. Default 64 Mi. */\n constructor(maxLineLength: number = MAX_LINE_LENGTH) {\n this.#maxLineLength = maxLineLength;\n }\n\n /**\n * Returns the lines completed by `chunk`, without their newlines (and without a trailing `\\r`).\n * Only `chunk` is searched for newlines, so a long line costs time in proportion to its length,\n * however many chunks bring it.\n */\n push(chunk: string): string[] {\n const lines: string[] = [];\n let start = 0;\n for (let index = chunk.indexOf(\"\\n\"); index >= 0; index = chunk.indexOf(\"\\n\", start)) {\n if (this.#pendingLength + index - start > this.#maxLineLength) this.#overflow();\n this.#pending.push(chunk.slice(start, index));\n const line = this.#pending.join(\"\");\n this.#pending = [];\n this.#pendingLength = 0;\n lines.push(line.endsWith(\"\\r\") ? line.slice(0, -1) : line);\n start = index + 1;\n }\n if (start < chunk.length) {\n this.#pendingLength += chunk.length - start;\n if (this.#pendingLength > this.#maxLineLength) this.#overflow();\n this.#pending.push(chunk.slice(start));\n }\n return lines;\n }\n\n /** The unfinished text after the last newline. A stream that ends with it holds a cut-off message. */\n get rest(): string {\n return this.#pending.join(\"\");\n }\n\n #overflow(): never {\n this.#pending = [];\n this.#pendingLength = 0;\n throw new RangeError(`A message is longer than ${this.#maxLineLength} characters.`);\n }\n}\n"],"mappings":";;;;;AAUA,MAAa,kBAA0B;;AAGvC,SAAgB,WAAW,SAAiC;CAC1D,OAAO,GAAG,KAAK,UAAU,OAAO,EAAE;AACpC;;;;;;;AAQA,IAAa,eAAb,MAA0B;CACxB;;CAEA,WAAqB,CAAC;CACtB,iBAAiB;;CAGjB,YAAY,gBAAwB,iBAAiB;EACnD,KAAK,iBAAiB;CACxB;;;;;;CAOA,KAAK,OAAyB;EAC5B,MAAM,QAAkB,CAAC;EACzB,IAAI,QAAQ;EACZ,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI,GAAG,SAAS,GAAG,QAAQ,MAAM,QAAQ,MAAM,KAAK,GAAG;GACpF,IAAI,KAAK,iBAAiB,QAAQ,QAAQ,KAAK,gBAAgB,KAAK,UAAU;GAC9E,KAAK,SAAS,KAAK,MAAM,MAAM,OAAO,KAAK,CAAC;GAC5C,MAAM,OAAO,KAAK,SAAS,KAAK,EAAE;GAClC,KAAK,WAAW,CAAC;GACjB,KAAK,iBAAiB;GACtB,MAAM,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,IAAI;GACzD,QAAQ,QAAQ;EAClB;EACA,IAAI,QAAQ,MAAM,QAAQ;GACxB,KAAK,kBAAkB,MAAM,SAAS;GACtC,IAAI,KAAK,iBAAiB,KAAK,gBAAgB,KAAK,UAAU;GAC9D,KAAK,SAAS,KAAK,MAAM,MAAM,KAAK,CAAC;EACvC;EACA,OAAO;CACT;;CAGA,IAAI,OAAe;EACjB,OAAO,KAAK,SAAS,KAAK,EAAE;CAC9B;CAEA,YAAmB;EACjB,KAAK,WAAW,CAAC;EACjB,KAAK,iBAAiB;EACtB,MAAM,IAAI,WAAW,4BAA4B,KAAK,eAAe,aAAa;CACpF;AACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
//#region src/rpc/messages.d.ts
|
|
3
|
+
/** A request ID: a string or a number, chosen by the sender and echoed in the response. */
|
|
4
|
+
export type JsonRpcId = string | number;
|
|
5
|
+
/** Request params: a JSON object (Mostra always uses objects) or an array. */
|
|
6
|
+
export type JsonRpcParams = Readonly<Record<string, unknown>> | readonly unknown[];
|
|
7
|
+
/** A request: the receiver answers with a response carrying the same `id`. */
|
|
8
|
+
export interface JsonRpcRequest {
|
|
9
|
+
/** Always `"2.0"`. */
|
|
10
|
+
readonly jsonrpc: "2.0";
|
|
11
|
+
/** Chosen by the sender; the response carries the same ID. */
|
|
12
|
+
readonly id: JsonRpcId;
|
|
13
|
+
/** The method name, `group/name` or a bare name. */
|
|
14
|
+
readonly method: string;
|
|
15
|
+
/** The method's params. */
|
|
16
|
+
readonly params?: JsonRpcParams;
|
|
17
|
+
}
|
|
18
|
+
/** A notification: a request without an `id`, which is never answered. */
|
|
19
|
+
export interface JsonRpcNotification {
|
|
20
|
+
/** Always `"2.0"`. */
|
|
21
|
+
readonly jsonrpc: "2.0";
|
|
22
|
+
/** The notification's method name. */
|
|
23
|
+
readonly method: string;
|
|
24
|
+
/** The notification's params. */
|
|
25
|
+
readonly params?: JsonRpcParams;
|
|
26
|
+
}
|
|
27
|
+
/** The error member of a failed response. Mostra puts the diagnostic in `data`. */
|
|
28
|
+
export interface JsonRpcErrorObject {
|
|
29
|
+
/** The JSON-RPC error code (INTERFACES §6). */
|
|
30
|
+
readonly code: number;
|
|
31
|
+
/** A short description; clients switch on `data.code`, never on this text. */
|
|
32
|
+
readonly message: string;
|
|
33
|
+
/** The diagnostic (INTERFACES §13). */
|
|
34
|
+
readonly data?: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** A successful response. */
|
|
37
|
+
export interface JsonRpcSuccess {
|
|
38
|
+
/** Always `"2.0"`. */
|
|
39
|
+
readonly jsonrpc: "2.0";
|
|
40
|
+
/** The ID of the request this answers. */
|
|
41
|
+
readonly id: JsonRpcId;
|
|
42
|
+
/** The method's result. */
|
|
43
|
+
readonly result: unknown;
|
|
44
|
+
}
|
|
45
|
+
/** A failed response. `id` is `null` when the request's ID couldn't be read. */
|
|
46
|
+
export interface JsonRpcFailure {
|
|
47
|
+
/** Always `"2.0"`. */
|
|
48
|
+
readonly jsonrpc: "2.0";
|
|
49
|
+
/** The ID of the request this answers, or `null` when it couldn't be read. */
|
|
50
|
+
readonly id: JsonRpcId | null;
|
|
51
|
+
/** What went wrong. */
|
|
52
|
+
readonly error: JsonRpcErrorObject;
|
|
53
|
+
}
|
|
54
|
+
/** A response to a request. */
|
|
55
|
+
export type JsonRpcResponse = JsonRpcSuccess | JsonRpcFailure;
|
|
56
|
+
/** Any message on a Mostra connection. */
|
|
57
|
+
export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
58
|
+
/** The Zod schema of the `JsonRpcRequest` type. */
|
|
59
|
+
export declare const JsonRpcRequest: z.ZodType<JsonRpcRequest>;
|
|
60
|
+
/** The Zod schema of the `JsonRpcNotification` type. */
|
|
61
|
+
export declare const JsonRpcNotification: z.ZodType<JsonRpcNotification>;
|
|
62
|
+
/** The Zod schema of the `JsonRpcErrorObject` type. */
|
|
63
|
+
export declare const JsonRpcErrorObject: z.ZodType<JsonRpcErrorObject>;
|
|
64
|
+
/** The Zod schema of the `JsonRpcSuccess` type. */
|
|
65
|
+
export declare const JsonRpcSuccess: z.ZodType<JsonRpcSuccess>;
|
|
66
|
+
/** The Zod schema of the `JsonRpcFailure` type. */
|
|
67
|
+
export declare const JsonRpcFailure: z.ZodType<JsonRpcFailure>;
|
|
68
|
+
/** A message sorted by kind, or the reason it isn't a valid message. */
|
|
69
|
+
export type ClassifiedMessage = {
|
|
70
|
+
readonly kind: "request";
|
|
71
|
+
readonly message: JsonRpcRequest;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: "notification";
|
|
74
|
+
readonly message: JsonRpcNotification;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "success";
|
|
77
|
+
readonly message: JsonRpcSuccess;
|
|
78
|
+
} | {
|
|
79
|
+
readonly kind: "failure";
|
|
80
|
+
readonly message: JsonRpcFailure;
|
|
81
|
+
} | {
|
|
82
|
+
readonly kind: "invalid";
|
|
83
|
+
readonly reason: string;
|
|
84
|
+
readonly id: JsonRpcId | null;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Sorts a parsed JSON value into a request, notification, success or failure, or explains why it
|
|
88
|
+
* is none of them. A JSON array (a batch) is invalid in revision `2026-10-10` (D83).
|
|
89
|
+
*/
|
|
90
|
+
export declare function classifyMessage(value: unknown): ClassifiedMessage;
|
|
91
|
+
//#endregion
|
|
92
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","names":[],"sources":["../../src/rpc/messages.ts"],"mappings":";;;YASY;;YAGA,gBAAgB,SAAS;;iBAGpB;;WAEN;;WAEA,IAAI;;WAEJ;;WAEA,SAAS;;;iBAIH;;WAEN;;WAEA;;WAEA,SAAS;;;iBAIH;;WAEN;;WAEA;;WAEA;;;iBAIM;;WAEN;;WAEA,IAAI;;WAEJ;;;iBAIM;;WAEN;;WAEA,IAAI;;WAEJ,OAAO;;;YAIN,kBAAkB,iBAAiB;;YAGnC,iBAAiB,iBAAiB,sBAAsB;;qBAUvD,gBAAgB,EAAE,QAAQ;;qBAQ1B,qBAAqB,EAAE,QAAQ;;qBAQ/B,oBAAoB,EAAE,QAAQ;;qBAQ9B,gBAAgB,EAAE,QAAQ;;qBAQ1B,gBAAgB,EAAE,QAAQ;;YAQ3B;WACG;WAA0B,SAAS;;WACnC;WAA+B,SAAS;;WACxC;WAA0B,SAAS;;WACnC;WAA0B,SAAS;;WACnC;WAA0B;WAAyB,IAAI;;;;;;wBAStD,gBAAgB,iBAAiB"}
|