@volter/world-runtime 2.0.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/dist/known-external-services.json +1108 -0
- package/dist/src/ancestry.d.ts +2 -0
- package/dist/src/ancestry.js +42 -0
- package/dist/src/app-url.d.ts +47 -0
- package/dist/src/app-url.js +239 -0
- package/dist/src/attach.d.ts +48 -0
- package/dist/src/attach.js +87 -0
- package/dist/src/branch.d.ts +20 -0
- package/dist/src/branch.js +65 -0
- package/dist/src/browser-proxy-cli.d.ts +2 -0
- package/dist/src/browser-proxy-cli.js +41 -0
- package/dist/src/ca-trust.d.ts +5 -0
- package/dist/src/ca-trust.js +64 -0
- package/dist/src/catalog.d.ts +31 -0
- package/dist/src/catalog.js +148 -0
- package/dist/src/changeset.d.ts +142 -0
- package/dist/src/changeset.js +570 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +1262 -0
- package/dist/src/command-lifetime.d.ts +15 -0
- package/dist/src/command-lifetime.js +98 -0
- package/dist/src/configs.d.ts +18 -0
- package/dist/src/configs.js +119 -0
- package/dist/src/console-apart.d.ts +38 -0
- package/dist/src/console-apart.js +107 -0
- package/dist/src/consumers.d.ts +46 -0
- package/dist/src/consumers.js +200 -0
- package/dist/src/covers.d.ts +183 -0
- package/dist/src/covers.js +800 -0
- package/dist/src/fixture-env.d.ts +42 -0
- package/dist/src/fixture-env.js +221 -0
- package/dist/src/host-cli.d.ts +2 -0
- package/dist/src/host-cli.js +92 -0
- package/dist/src/host-fault-fixture.d.ts +32 -0
- package/dist/src/host-fault-fixture.js +100 -0
- package/dist/src/host-worker.d.ts +1 -0
- package/dist/src/host-worker.js +23 -0
- package/dist/src/host.d.ts +38 -0
- package/dist/src/host.js +135 -0
- package/dist/src/index.d.ts +48 -0
- package/dist/src/index.js +35 -0
- package/dist/src/infra-cli.d.ts +2 -0
- package/dist/src/infra-cli.js +136 -0
- package/dist/src/init.d.ts +227 -0
- package/dist/src/init.js +1117 -0
- package/dist/src/inject-map.d.ts +34 -0
- package/dist/src/inject-map.js +56 -0
- package/dist/src/lifecycle-record.d.ts +47 -0
- package/dist/src/lifecycle-record.js +196 -0
- package/dist/src/origin.d.ts +31 -0
- package/dist/src/origin.js +139 -0
- package/dist/src/pack-facts.d.ts +75 -0
- package/dist/src/pack-facts.js +98 -0
- package/dist/src/pglite-backing.d.ts +21 -0
- package/dist/src/pglite-backing.js +158 -0
- package/dist/src/pglite-host.mjs +147 -0
- package/dist/src/placeholder.d.ts +20 -0
- package/dist/src/placeholder.js +100 -0
- package/dist/src/prerequisites.d.ts +21 -0
- package/dist/src/prerequisites.js +49 -0
- package/dist/src/process-groups.d.ts +4 -0
- package/dist/src/process-groups.js +49 -0
- package/dist/src/project-inspect.d.ts +109 -0
- package/dist/src/project-inspect.js +827 -0
- package/dist/src/proxy-daemon.d.ts +2 -0
- package/dist/src/proxy-daemon.js +18 -0
- package/dist/src/redirect-proxy.d.ts +105 -0
- package/dist/src/redirect-proxy.js +665 -0
- package/dist/src/reflect.d.ts +74 -0
- package/dist/src/reflect.js +392 -0
- package/dist/src/resources.d.ts +26 -0
- package/dist/src/resources.js +22 -0
- package/dist/src/root.d.ts +114 -0
- package/dist/src/root.js +312 -0
- package/dist/src/run-task-worker.d.ts +1 -0
- package/dist/src/run-task-worker.js +38 -0
- package/dist/src/run-task.d.ts +18 -0
- package/dist/src/run-task.js +48 -0
- package/dist/src/runtime-test-support.d.ts +59 -0
- package/dist/src/runtime-test-support.js +205 -0
- package/dist/src/runtime.d.ts +256 -0
- package/dist/src/runtime.js +3502 -0
- package/dist/src/schema.d.ts +449 -0
- package/dist/src/schema.js +605 -0
- package/dist/src/serve.d.ts +30 -0
- package/dist/src/serve.js +82 -0
- package/dist/src/served-world.d.ts +194 -0
- package/dist/src/served-world.js +986 -0
- package/dist/src/service-exit.d.ts +46 -0
- package/dist/src/service-exit.js +195 -0
- package/dist/src/service-recorder.d.ts +1 -0
- package/dist/src/service-recorder.js +121 -0
- package/dist/src/sibling.d.ts +1 -0
- package/dist/src/sibling.js +9 -0
- package/dist/src/signals.d.ts +1 -0
- package/dist/src/signals.js +11 -0
- package/dist/src/storage-capacity.d.ts +8 -0
- package/dist/src/storage-capacity.js +61 -0
- package/dist/src/tail.d.ts +30 -0
- package/dist/src/tail.js +160 -0
- package/dist/src/tcp-port.d.ts +2 -0
- package/dist/src/tcp-port.js +36 -0
- package/dist/src/up-task-worker.d.ts +1 -0
- package/dist/src/up-task-worker.js +61 -0
- package/dist/src/up-task.d.ts +17 -0
- package/dist/src/up-task.js +49 -0
- package/dist/src/websocket-relay.d.ts +3 -0
- package/dist/src/websocket-relay.js +40 -0
- package/known-external-services.json +1108 -0
- package/package.json +83 -0
- package/src/ancestry.ts +36 -0
- package/src/app-url.ts +253 -0
- package/src/attach.ts +117 -0
- package/src/branch.ts +63 -0
- package/src/browser-proxy-cli.ts +44 -0
- package/src/ca-trust.ts +57 -0
- package/src/catalog.ts +156 -0
- package/src/changeset.ts +627 -0
- package/src/cli.ts +1111 -0
- package/src/command-lifetime.ts +79 -0
- package/src/configs.ts +110 -0
- package/src/console-apart.ts +90 -0
- package/src/consumers.ts +185 -0
- package/src/covers.ts +934 -0
- package/src/fixture-env.ts +230 -0
- package/src/host-cli.ts +90 -0
- package/src/host-worker.ts +23 -0
- package/src/host.ts +169 -0
- package/src/index.ts +171 -0
- package/src/infra-cli.ts +133 -0
- package/src/init.ts +1316 -0
- package/src/inject-map.ts +72 -0
- package/src/lifecycle-record.ts +168 -0
- package/src/origin.ts +134 -0
- package/src/pack-facts.ts +128 -0
- package/src/pglite-backing.ts +141 -0
- package/src/pglite-host.mjs +147 -0
- package/src/placeholder.ts +89 -0
- package/src/prerequisites.ts +66 -0
- package/src/process-groups.ts +33 -0
- package/src/project-inspect.ts +770 -0
- package/src/proxy-daemon.ts +21 -0
- package/src/redirect-proxy.ts +684 -0
- package/src/reflect.ts +440 -0
- package/src/resources.ts +22 -0
- package/src/root.ts +290 -0
- package/src/run-task-worker.ts +27 -0
- package/src/run-task.ts +44 -0
- package/src/runtime-test-support.ts +208 -0
- package/src/runtime.ts +3357 -0
- package/src/schema.ts +922 -0
- package/src/serve.ts +102 -0
- package/src/served-world.ts +812 -0
- package/src/service-exit.ts +175 -0
- package/src/service-recorder.ts +89 -0
- package/src/sibling.ts +10 -0
- package/src/signals.ts +10 -0
- package/src/storage-capacity.ts +60 -0
- package/src/tail.ts +205 -0
- package/src/tcp-port.ts +35 -0
- package/src/up-task-worker.ts +40 -0
- package/src/up-task.ts +45 -0
- package/src/websocket-relay.ts +32 -0
package/src/catalog.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// The catalog — where the twins a world can run come from (docs/concepts/worlds.md
|
|
2
|
+
// #the-config-and-the-running-world). Two sources answer one interface: this CHECKOUT (`packages/twin/<vendor>/`, the
|
|
3
|
+
// catalog as the repo holds it) and an INSTALLED catalog (`@volter/twin-<vendor>` packages under
|
|
4
|
+
// `node_modules`, walked up from the world root — hoisting-proof, and independent of the
|
|
5
|
+
// packages' `exports` maps, which do not expose `package.json`). A world born in an app repo
|
|
6
|
+
// names its twins as packages and the runtime resolves them at boot; a world born here names the
|
|
7
|
+
// checkout-relative paths, as before.
|
|
8
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
import { dirname, join, resolve } from 'node:path';
|
|
11
|
+
|
|
12
|
+
export const TWIN_PACKAGE_PREFIX = '@volter/twin-';
|
|
13
|
+
|
|
14
|
+
/** Packages under the `@volter/twin-` prefix that are NOT twins. */
|
|
15
|
+
|
|
16
|
+
export function twinPackageName(vendor: string): string { return `${TWIN_PACKAGE_PREFIX}${vendor}`; }
|
|
17
|
+
|
|
18
|
+
export type CatalogKind = 'checkout' | 'installed';
|
|
19
|
+
|
|
20
|
+
export type Catalog = {
|
|
21
|
+
kind: CatalogKind;
|
|
22
|
+
/** The world root the catalog was resolved for. */
|
|
23
|
+
root: string;
|
|
24
|
+
/** Every vendor the catalog can run, sorted — a deterministic input to `init`. */
|
|
25
|
+
vendors(): string[];
|
|
26
|
+
/** The pack's directory (holds `src/cli.ts`, `src/index.ts`, `defaults/`, `package.json`), or undefined. */
|
|
27
|
+
packDir(vendor: string): string | undefined;
|
|
28
|
+
/** The pack's own version, from its package.json — the value a world's pin carries. */
|
|
29
|
+
version(vendor: string): string | undefined;
|
|
30
|
+
/** The birth stamp: the checkout's git sha, or a digest of the installed versions. */
|
|
31
|
+
sha(): string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function packageVersion(dir: string): string | undefined {
|
|
35
|
+
const p = join(dir, 'package.json');
|
|
36
|
+
if (!existsSync(p)) return undefined;
|
|
37
|
+
try { const v = (JSON.parse(readFileSync(p, 'utf8')) as { version?: unknown }).version; return typeof v === 'string' ? v : undefined; } catch { return undefined; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isPackDir(dir: string): boolean { return packCli(dir) !== undefined; }
|
|
41
|
+
|
|
42
|
+
type Manifest = { name?: string; exports?: unknown; main?: string; bin?: Record<string, string> | string };
|
|
43
|
+
function manifest(dir: string): Manifest | undefined { const p = join(dir, 'package.json'); if (!existsSync(p)) return undefined; try { return JSON.parse(readFileSync(p, 'utf8')) as Manifest; } catch { return undefined; } }
|
|
44
|
+
|
|
45
|
+
/** The pack's module entry, FROM ITS MANIFEST (docs/contributing/architecture.md#the-publishing-pipeline): `exports['.']`
|
|
46
|
+
* — `src/index.ts` in the checkout, `dist/src/index.js` once published — so the same resolution
|
|
47
|
+
* serves both; `main` behind it; the checkout convention last. */
|
|
48
|
+
export function packEntry(dir: string): string {
|
|
49
|
+
const m = manifest(dir);
|
|
50
|
+
const dot = m?.exports === undefined ? undefined : typeof m.exports === 'string' ? m.exports : (m.exports as Record<string, unknown>)['.'];
|
|
51
|
+
const value = typeof dot === 'string' ? dot : dot && typeof dot === 'object' ? ((dot as Record<string, unknown>).default ?? (dot as Record<string, unknown>).import) : undefined;
|
|
52
|
+
const rel = typeof value === 'string' ? value : typeof m?.main === 'string' ? m.main : 'src/index.ts';
|
|
53
|
+
return join(dir, rel);
|
|
54
|
+
}
|
|
55
|
+
/** The pack's cli, from its manifest's `bin` (`world-<vendor>` when named, else the first), or undefined when the directory is no pack. */
|
|
56
|
+
export function packCli(dir: string): string | undefined {
|
|
57
|
+
const m = manifest(dir);
|
|
58
|
+
const bins = m === undefined ? {} : typeof m.bin === 'string' ? { [m.name ?? 'cli']: m.bin } : m.bin ?? {};
|
|
59
|
+
const named = Object.entries(bins).find(([n]) => n.startsWith('world-'))?.[1] ?? Object.values(bins)[0];
|
|
60
|
+
if (named) return join(dir, named);
|
|
61
|
+
return existsSync(join(dir, 'src', 'cli.ts')) ? join(dir, 'src', 'cli.ts') : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The nearest `node_modules/<name>` above `from` that holds a package.json — node's own walk. */
|
|
65
|
+
export function findInstalledPackage(from: string, name: string): string | undefined {
|
|
66
|
+
let dir = resolve(from);
|
|
67
|
+
for (;;) {
|
|
68
|
+
const candidate = join(dir, 'node_modules', ...name.split('/'));
|
|
69
|
+
if (existsSync(join(candidate, 'package.json'))) return candidate;
|
|
70
|
+
const up = dirname(dir);
|
|
71
|
+
if (up === dir) return undefined;
|
|
72
|
+
dir = up;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Every installed `@volter/twin-<vendor>` visible from `from`, nearest wins. */
|
|
77
|
+
function installedTwins(from: string): Map<string, string> {
|
|
78
|
+
const found = new Map<string, string>();
|
|
79
|
+
let dir = resolve(from);
|
|
80
|
+
for (;;) {
|
|
81
|
+
const scope = join(dir, 'node_modules', '@volter');
|
|
82
|
+
if (existsSync(scope)) {
|
|
83
|
+
for (const entry of readdirSync(scope, { withFileTypes: true })) {
|
|
84
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
85
|
+
const name = `@volter/${entry.name}`;
|
|
86
|
+
if (!name.startsWith(TWIN_PACKAGE_PREFIX)) continue; // the platform's packages are `@volter/world-*`: outside the prefix by name
|
|
87
|
+
const vendor = name.slice(TWIN_PACKAGE_PREFIX.length);
|
|
88
|
+
const packDir = join(scope, entry.name);
|
|
89
|
+
if (!found.has(vendor) && isPackDir(packDir)) found.set(vendor, packDir);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const up = dirname(dir);
|
|
93
|
+
if (up === dir) break;
|
|
94
|
+
dir = up;
|
|
95
|
+
}
|
|
96
|
+
return found;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function fnv1a(text: string): string {
|
|
100
|
+
let h = 0x811c9dc5;
|
|
101
|
+
for (let i = 0; i < text.length; i += 1) { h ^= text.charCodeAt(i); h = Math.imul(h, 0x01000193) >>> 0; }
|
|
102
|
+
return h.toString(16).padStart(8, '0');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function checkoutCatalog(root: string): Catalog {
|
|
106
|
+
const packsDir = resolve(root, 'packages', 'twin');
|
|
107
|
+
const vendors = (): string[] => readdirSync(packsDir, { withFileTypes: true })
|
|
108
|
+
.filter((entry) => entry.isDirectory() && isPackDir(join(packsDir, entry.name)))
|
|
109
|
+
.map((entry) => entry.name)
|
|
110
|
+
.sort();
|
|
111
|
+
return {
|
|
112
|
+
kind: 'checkout',
|
|
113
|
+
root: resolve(root),
|
|
114
|
+
vendors,
|
|
115
|
+
packDir: (vendor) => (isPackDir(join(packsDir, vendor)) ? join(packsDir, vendor) : undefined),
|
|
116
|
+
version: (vendor) => packageVersion(join(packsDir, vendor)),
|
|
117
|
+
sha: () => {
|
|
118
|
+
const proc = spawnSync('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8' });
|
|
119
|
+
const sha = proc.status === 0 ? proc.stdout.trim() : '';
|
|
120
|
+
return /^[0-9a-f]{40}$/.test(sha) ? sha : 'unknown';
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function installedCatalog(root: string): Catalog {
|
|
126
|
+
const twins = installedTwins(root);
|
|
127
|
+
return {
|
|
128
|
+
kind: 'installed',
|
|
129
|
+
root: resolve(root),
|
|
130
|
+
vendors: () => [...twins.keys()].sort(),
|
|
131
|
+
packDir: (vendor) => twins.get(vendor),
|
|
132
|
+
version: (vendor) => { const dir = twins.get(vendor); return dir === undefined ? undefined : packageVersion(dir); },
|
|
133
|
+
sha: () => `installed-${fnv1a([...twins.keys()].sort().map((v) => `${v}@${packageVersion(twins.get(v)!) ?? '?'}`).join(','))}`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The catalog for a world root: the checkout when `packages/twin` is there, else what is installed. */
|
|
138
|
+
export function resolveCatalog(root: string): Catalog {
|
|
139
|
+
const resolved = resolve(root);
|
|
140
|
+
if (existsSync(join(resolved, 'packages', 'twin'))) return checkoutCatalog(resolved);
|
|
141
|
+
const installed = installedCatalog(resolved);
|
|
142
|
+
if (installed.vendors().length === 0) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`No twins found for ${resolved}: no \`packages/twin\` catalog here and no \`@volter/twin-<vendor>\` package installed above it. `
|
|
145
|
+
+ `Install the twins your app needs (e.g. \`bun add -d @volter/twin-stripe\`) and run init again.`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return installed;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The pack directory a service boots from: its `package` resolved from the world root at boot. */
|
|
152
|
+
export function resolveServicePackage(root: string, pkg: string): string {
|
|
153
|
+
const dir = findInstalledPackage(root, pkg);
|
|
154
|
+
if (dir === undefined) throw new Error(`Twin package ${pkg} is not installed above ${root} — \`bun add -d ${pkg}\` (or npm/pnpm) and run up again`);
|
|
155
|
+
return dir;
|
|
156
|
+
}
|