@mostra/runtime 0.0.0-stage → 0.1.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 +39 -2
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +236 -0
- package/dist/bin.js.map +1 -0
- package/dist/builder/child/main.d.ts +1 -0
- package/dist/builder/child/main.js +1408 -0
- package/dist/builder/child/main.js.map +1 -0
- package/dist/child-xrHmytks.js +49 -0
- package/dist/child-xrHmytks.js.map +1 -0
- package/dist/deps/child/install.d.ts +1 -0
- package/dist/deps/child/install.js +33 -0
- package/dist/deps/child/install.js.map +1 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/instance-D7_UVdoN.js +15752 -0
- package/dist/instance-D7_UVdoN.js.map +1 -0
- package/dist/types-NjNy7gXX.js +57 -0
- package/dist/types-NjNy7gXX.js.map +1 -0
- package/package.json +87 -3
- package/src/actions/index.ts +622 -0
- package/src/addressing/index.ts +281 -0
- package/src/bin.ts +240 -0
- package/src/builder/child/dev.ts +383 -0
- package/src/builder/child/fields.ts +363 -0
- package/src/builder/child/main.ts +47 -0
- package/src/builder/child/plugins.ts +195 -0
- package/src/builder/child/scan.ts +459 -0
- package/src/builder/child/spa.ts +348 -0
- package/src/builder/coverage.ts +72 -0
- package/src/builder/index.ts +406 -0
- package/src/builder/types.ts +180 -0
- package/src/deps/child/install.ts +30 -0
- package/src/deps/index.ts +918 -0
- package/src/deps/installer.ts +321 -0
- package/src/deps/lock.ts +82 -0
- package/src/deps/scan.ts +266 -0
- package/src/deps/specifier.ts +64 -0
- package/src/deps/warm.ts +57 -0
- package/src/dev/index.ts +518 -0
- package/src/faults.ts +65 -0
- package/src/gate.ts +55 -0
- package/src/gateway/actions.ts +268 -0
- package/src/gateway/browser.ts +650 -0
- package/src/gateway/capabilities.ts +739 -0
- package/src/gateway/controls.ts +91 -0
- package/src/gateway/dev.ts +119 -0
- package/src/gateway/http.ts +229 -0
- package/src/gateway/index.ts +1209 -0
- package/src/gateway/integrity.ts +117 -0
- package/src/gateway/listener.ts +217 -0
- package/src/gateway/routes.ts +197 -0
- package/src/gateway/serve.ts +138 -0
- package/src/gc/index.ts +451 -0
- package/src/home/acquire.ts +276 -0
- package/src/home/index.ts +16 -0
- package/src/home/paths.ts +192 -0
- package/src/home/platform.ts +34 -0
- package/src/home/record.ts +76 -0
- package/src/home/settings.ts +113 -0
- package/src/index.ts +30 -0
- package/src/instance/index.ts +942 -0
- package/src/interaction/ephemeral.ts +300 -0
- package/src/interaction/events.ts +355 -0
- package/src/interaction/fields.ts +392 -0
- package/src/interaction/index.ts +1009 -0
- package/src/interaction/outbox.ts +493 -0
- package/src/interaction/policy.ts +26 -0
- package/src/interaction/results.ts +341 -0
- package/src/interaction/runs.ts +313 -0
- package/src/interaction/signals.ts +120 -0
- package/src/interaction/submissions.ts +585 -0
- package/src/interaction/subscriptions.ts +258 -0
- package/src/interaction/viewers.ts +173 -0
- package/src/interaction/wait.ts +201 -0
- package/src/ledger/index.ts +442 -0
- package/src/ledger/migrations.ts +583 -0
- package/src/ledger/requests.ts +105 -0
- package/src/ledger/types.ts +28 -0
- package/src/live/index.ts +573 -0
- package/src/log.ts +316 -0
- package/src/processes/child.ts +67 -0
- package/src/processes/environment.ts +64 -0
- package/src/processes/identity.ts +191 -0
- package/src/processes/index.ts +19 -0
- package/src/processes/manager.ts +543 -0
- package/src/protocol-server/client.ts +94 -0
- package/src/protocol-server/index.ts +91 -0
- package/src/protocol-server/server.ts +509 -0
- package/src/protocol-server/streams.ts +81 -0
- package/src/publish/checks.ts +92 -0
- package/src/publish/digest.ts +87 -0
- package/src/publish/index.ts +23 -0
- package/src/publish/manifest.ts +409 -0
- package/src/publish/methods.ts +96 -0
- package/src/publish/publisher.ts +913 -0
- package/src/publish/source.ts +272 -0
- package/src/publish/tar.ts +110 -0
- package/src/registry/index.ts +481 -0
- package/src/registry/store.ts +136 -0
- package/src/secrets/index.ts +223 -0
- package/src/service/idle.ts +64 -0
- package/src/service/index.ts +3 -0
- package/src/service/unit.ts +250 -0
- package/src/verify/fields.ts +125 -0
- package/src/verify/index.ts +913 -0
- package/src/verify/regression.ts +157 -0
- package/src/verify/runner.ts +230 -0
- package/src/verify/sandbox.ts +407 -0
- package/src/verify/typecheck.ts +371 -0
- package/src/workers/index.ts +17 -0
- package/src/workers/launcher.ts +260 -0
- package/src/workers/pool.ts +708 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authoring methods of the host protocol (INTERFACES §6): `artifact/create`,
|
|
3
|
+
* `artifact/publish`, `artifact/list`, `artifact/get` and `deps/add`.
|
|
4
|
+
*/
|
|
5
|
+
import { realpathSync } from "node:fs";
|
|
6
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
7
|
+
import {
|
|
8
|
+
ARTIFACT_PROGRESS,
|
|
9
|
+
type ArtifactRef,
|
|
10
|
+
artifactCreateMethod,
|
|
11
|
+
artifactGetMethod,
|
|
12
|
+
artifactListMethod,
|
|
13
|
+
artifactPublishMethod,
|
|
14
|
+
artifactVerifyMethod,
|
|
15
|
+
depsAddMethod,
|
|
16
|
+
type SourceRef,
|
|
17
|
+
} from "@mostra/protocol";
|
|
18
|
+
import { handler, type MethodHandler } from "../protocol-server/index.ts";
|
|
19
|
+
import type { Registry } from "../registry/index.ts";
|
|
20
|
+
import type { Publisher } from "./publisher.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A path as bindings store it (D51): its real path, or, for a path that no longer exists, the real
|
|
24
|
+
* path of its nearest existing ancestor joined with the rest.
|
|
25
|
+
*/
|
|
26
|
+
function canonical(path: string): string {
|
|
27
|
+
const absolute = resolve(path);
|
|
28
|
+
try {
|
|
29
|
+
// The native realpath(3), as `resolveSource` uses: on a case- or normalization-insensitive
|
|
30
|
+
// file system it returns the on-disk spelling the binding was stored with.
|
|
31
|
+
return realpathSync.native(absolute);
|
|
32
|
+
} catch {
|
|
33
|
+
const parent = dirname(absolute);
|
|
34
|
+
return parent === absolute ? absolute : join(canonical(parent), basename(absolute));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A path as an `ArtifactRef` names it: canonical, so a moved or deleted source still names its
|
|
40
|
+
* artifact (INTERFACES §6).
|
|
41
|
+
*/
|
|
42
|
+
export function canonicalRef(ref: ArtifactRef): ArtifactRef {
|
|
43
|
+
return "path" in ref ? { path: canonical(ref.path) } : ref;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The handlers of the authoring methods. `publisher` is called on first use, so an instance
|
|
48
|
+
* whose runtime lacks the warm set still starts and reports `MOSTRA_ENV_WARM_MISSING` per call.
|
|
49
|
+
*/
|
|
50
|
+
export function artifactMethods(options: {
|
|
51
|
+
readonly registry: Registry;
|
|
52
|
+
readonly publisher: () => Publisher;
|
|
53
|
+
/**
|
|
54
|
+
* The artifact's default capability link (D90, D97 item 3), added to every receipt, replays
|
|
55
|
+
* included. Recorded receipts never hold it: the ledger keeps no link's secret.
|
|
56
|
+
*/
|
|
57
|
+
readonly link?: (artifactId: string) => { readonly url: string; readonly tokenId: string };
|
|
58
|
+
/**
|
|
59
|
+
* Hears every publish that succeeded, a reused version too: a publish clears the artifact's
|
|
60
|
+
* parked workers (FAILURE_MODEL §2).
|
|
61
|
+
*/
|
|
62
|
+
readonly published?: (artifactId: string) => void;
|
|
63
|
+
/** `deps/add` changed an artifact's working lockfile: its `mostra dev` sessions resolve again. */
|
|
64
|
+
readonly dependenciesAdded?: (artifact: SourceRef) => void;
|
|
65
|
+
/** Sends a notification on a session's connection (`artifact/progress`). */
|
|
66
|
+
readonly notify?: (session: number, method: string, params: Record<string, unknown>) => void;
|
|
67
|
+
}): MethodHandler[] {
|
|
68
|
+
const { registry } = options;
|
|
69
|
+
return [
|
|
70
|
+
handler(artifactCreateMethod, (params) => options.publisher().create(params)),
|
|
71
|
+
handler(artifactPublishMethod, async (params) => {
|
|
72
|
+
const receipt = await options.publisher().publish(params);
|
|
73
|
+
options.published?.(receipt.artifactId);
|
|
74
|
+
return options.link ? { ...receipt, ...options.link(receipt.artifactId) } : receipt;
|
|
75
|
+
}),
|
|
76
|
+
handler(depsAddMethod, async (params) => {
|
|
77
|
+
const added = await options.publisher().addDependencies(params);
|
|
78
|
+
options.dependenciesAdded?.(params.artifact);
|
|
79
|
+
return added;
|
|
80
|
+
}),
|
|
81
|
+
handler(artifactVerifyMethod, (params, session) => {
|
|
82
|
+
const token = params.progressToken;
|
|
83
|
+
// Progress only to a client that asked for it and accepts the notification (D84).
|
|
84
|
+
const progress =
|
|
85
|
+
token !== undefined && session.notifications.has(ARTIFACT_PROGRESS) && options.notify
|
|
86
|
+
? (stage: string) =>
|
|
87
|
+
options.notify?.(session.id, ARTIFACT_PROGRESS, { progressToken: token, stage })
|
|
88
|
+
: undefined;
|
|
89
|
+
return options.publisher().verify(params, progress);
|
|
90
|
+
}),
|
|
91
|
+
handler(artifactListMethod, (params) => ({ artifacts: registry.list(params.filter ?? {}) })),
|
|
92
|
+
handler(artifactGetMethod, (params) => {
|
|
93
|
+
return registry.get(canonicalRef(params.artifact));
|
|
94
|
+
}),
|
|
95
|
+
];
|
|
96
|
+
}
|