passport-bridge 0.55.0 → 0.56.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/dist/cliHookDecide.d.ts +4 -2
- package/dist/cliHookDecide.js +24 -11
- package/dist/connectorKit/callEffects.generated.js +3 -1
- package/dist/connectorKit/containers.generated.d.ts +46 -0
- package/dist/connectorKit/containers.generated.js +202 -0
- package/dist/connectorKit/engine.generated.d.ts +6 -14
- package/dist/connectorKit/engine.generated.js +35 -103
- package/dist/connectorKit/links.generated.d.ts +14 -0
- package/dist/connectorKit/links.generated.js +146 -0
- package/dist/connectorKit/manifests/railway.generated.js +3 -1
- package/dist/connectorKit/manifests/railwayCapture.generated.js +2 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.js +16 -7
- package/dist/connectorKit/nodeChain.generated.d.ts +22 -0
- package/dist/connectorKit/nodeChain.generated.js +90 -0
- package/dist/connectorKit/scripts.generated.d.ts +72 -0
- package/dist/connectorKit/scripts.generated.js +282 -0
- package/dist/connectorKit/shell.generated.d.ts +29 -31
- package/dist/connectorKit/shell.generated.js +179 -184
- package/dist/connectorKit/shellFed.generated.d.ts +7 -1
- package/dist/connectorKit/shellFed.generated.js +111 -14
- package/dist/connectorKit/shellRuns.generated.d.ts +104 -0
- package/dist/connectorKit/shellRuns.generated.js +301 -0
- package/dist/connectorKit/sources/railway/cli-tree.generated.d.ts +0 -17
- package/dist/connectorKit/sources/railway/cli-tree.generated.js +1 -1
- package/dist/connectorKit/spawns.generated.d.ts +3 -0
- package/dist/connectorKit/spawns.generated.js +66 -9
- package/dist/connectorKit/template.generated.d.ts +12 -0
- package/dist/connectorKit/template.generated.js +19 -0
- package/dist/connectorKit/unread.generated.d.ts +40 -0
- package/dist/connectorKit/unread.generated.js +92 -0
- package/dist/controlPlane.generated.d.ts +3 -2
- package/dist/controlPlaneCloudflare.js +5 -3
- package/dist/controlPlaneGuard.js +1 -5
- package/dist/controlPlaneRailwayGuard.d.ts +26 -34
- package/dist/controlPlaneRailwayGuard.js +131 -116
- package/dist/controlPlaneRoutes.generated.d.ts +13 -0
- package/dist/controlPlaneRoutes.generated.js +9 -0
- package/dist/controlPlaneSentry.js +5 -3
- package/dist/controlPlaneSupabase.js +5 -3
- package/dist/controlPlaneTerraform.js +7 -4
- package/dist/controlPlaneUnnamed.generated.d.ts +17 -0
- package/dist/controlPlaneUnnamed.generated.js +20 -1
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/scriptReader.d.ts +20 -0
- package/dist/scriptReader.js +52 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/connectorKit/shadow.generated.d.ts +0 -52
- package/dist/connectorKit/shadow.generated.js +0 -148
- package/dist/controlPlaneRailway.generated.d.ts +0 -30
- package/dist/controlPlaneRailway.generated.js +0 -217
- package/dist/controlPlaneRailwayCli.generated.d.ts +0 -11
- package/dist/controlPlaneRailwayCli.generated.js +0 -455
- package/dist/kitShadow.d.ts +0 -81
- package/dist/kitShadow.js +0 -256
- package/dist/kitShadowBudget.d.ts +0 -10
- package/dist/kitShadowBudget.js +0 -15
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Folders and link files for the guard-side resolver (`shell.ts`): a path joined onto a folder, and a folder's link
|
|
4
|
+
* (the manifest's link file in the folder or the nearest parent), read through the guard's file reader.
|
|
5
|
+
*/
|
|
6
|
+
/** A path joined onto a folder, with "." and ".." resolved; posix. */
|
|
7
|
+
export function joinPath(folder, path) {
|
|
8
|
+
const parts = [];
|
|
9
|
+
for (const part of `${path.startsWith("/") ? "" : folder}/${path}`.split("/")) {
|
|
10
|
+
if (part === "" || part === ".")
|
|
11
|
+
continue;
|
|
12
|
+
if (part === "..")
|
|
13
|
+
parts.pop();
|
|
14
|
+
else
|
|
15
|
+
parts.push(part);
|
|
16
|
+
}
|
|
17
|
+
return `/${parts.join("/")}`;
|
|
18
|
+
}
|
|
19
|
+
/** An INI file's "section.key" values the link names, as params: `[defaults]` then `org = acme`. */
|
|
20
|
+
function iniFields(text, fields) {
|
|
21
|
+
const out = {};
|
|
22
|
+
let section = "";
|
|
23
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
24
|
+
const line = raw.trim();
|
|
25
|
+
if (!line || line.startsWith(";") || line.startsWith("#"))
|
|
26
|
+
continue;
|
|
27
|
+
const header = /^\[([^\]]+)\]$/.exec(line);
|
|
28
|
+
if (header) {
|
|
29
|
+
section = header[1].trim().toLowerCase();
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const eq = line.indexOf("=");
|
|
33
|
+
if (eq <= 0)
|
|
34
|
+
continue;
|
|
35
|
+
const param = fields[`${section}.${line.slice(0, eq).trim().toLowerCase()}`];
|
|
36
|
+
const value = line.slice(eq + 1).trim();
|
|
37
|
+
if (param && value)
|
|
38
|
+
out[param] = value;
|
|
39
|
+
}
|
|
40
|
+
return Object.keys(out).length ? out : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** A link file's text as params, or undefined when it can't be read. */
|
|
43
|
+
function linkParams(link, text) {
|
|
44
|
+
if (link.format === "text")
|
|
45
|
+
return text.trim() ? { [link.param]: text.trim() } : undefined;
|
|
46
|
+
if (link.format === "ini")
|
|
47
|
+
return iniFields(text, link.fields);
|
|
48
|
+
const parsed = link.format === "toml" ? tomlTop(text) : jsonTop(link.format === "jsonc" ? withoutComments(text) : text);
|
|
49
|
+
if (!parsed)
|
|
50
|
+
return undefined;
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [field, param] of Object.entries(link.fields))
|
|
53
|
+
if (typeof parsed[field] === "string")
|
|
54
|
+
out[param] = parsed[field];
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function jsonTop(text) {
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(text);
|
|
60
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
61
|
+
? parsed
|
|
62
|
+
: undefined;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** JSONC as JSON: line and block comments outside strings, and trailing commas, removed. */
|
|
69
|
+
function withoutComments(text) {
|
|
70
|
+
let out = "";
|
|
71
|
+
for (let i = 0; i < text.length; i++) {
|
|
72
|
+
const ch = text[i];
|
|
73
|
+
if (ch === '"') {
|
|
74
|
+
const end = /"(?:[^"\\]|\\.)*"/y;
|
|
75
|
+
end.lastIndex = i;
|
|
76
|
+
const found = end.exec(text);
|
|
77
|
+
if (!found)
|
|
78
|
+
return out + text.slice(i);
|
|
79
|
+
out += found[0];
|
|
80
|
+
i += found[0].length - 1;
|
|
81
|
+
}
|
|
82
|
+
else if (ch === "/" && text[i + 1] === "/") {
|
|
83
|
+
while (i < text.length && text[i] !== "\n")
|
|
84
|
+
i++;
|
|
85
|
+
out += "\n";
|
|
86
|
+
}
|
|
87
|
+
else if (ch === "/" && text[i + 1] === "*") {
|
|
88
|
+
const close = text.indexOf("*/", i + 2);
|
|
89
|
+
i = close < 0 ? text.length : close + 1;
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
out += ch;
|
|
93
|
+
}
|
|
94
|
+
return out.replace(/,(\s*[}\]])/g, "$1");
|
|
95
|
+
}
|
|
96
|
+
/** A TOML file's top-level string keys (`name = "api"`), up to its first table header; nothing else is read. */
|
|
97
|
+
function tomlTop(text) {
|
|
98
|
+
const out = {};
|
|
99
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
100
|
+
const line = raw.trim();
|
|
101
|
+
if (line.startsWith("["))
|
|
102
|
+
break;
|
|
103
|
+
const found = /^([A-Za-z0-9_-]+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|'([^']*)')\s*(?:#.*)?$/.exec(line);
|
|
104
|
+
if (found)
|
|
105
|
+
out[found[1]] = found[2] ?? found[3] ?? "";
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** A path that names a link file itself (Wrangler's `--config staging.toml`): read as the link spec of its format, never
|
|
110
|
+
* a parent's. Undefined when the path isn't one (a folder) or the file can't be read; null when nothing can name it. */
|
|
111
|
+
function readLinkFile(links, path, guard) {
|
|
112
|
+
const format = /\.toml$/i.test(path)
|
|
113
|
+
? "toml"
|
|
114
|
+
: /\.jsonc$/i.test(path)
|
|
115
|
+
? "jsonc"
|
|
116
|
+
: /\.json$/i.test(path)
|
|
117
|
+
? "json"
|
|
118
|
+
: null;
|
|
119
|
+
if (!format)
|
|
120
|
+
return undefined;
|
|
121
|
+
const link = links.find((spec) => spec.format === format);
|
|
122
|
+
const text = link ? guard.readFile?.(path) : undefined;
|
|
123
|
+
return link && text !== undefined ? (linkParams(link, text) ?? null) : null;
|
|
124
|
+
}
|
|
125
|
+
/** A folder's link: the manifest's link file (the first of several it names) in the folder or the nearest parent
|
|
126
|
+
* that has one. */
|
|
127
|
+
export function folderLink(m, folder, guard) {
|
|
128
|
+
const spec = m.capture.cli.link;
|
|
129
|
+
if (!spec || !guard.readFile)
|
|
130
|
+
return undefined;
|
|
131
|
+
const links = Array.isArray(spec) ? spec : [spec];
|
|
132
|
+
const file = readLinkFile(links, folder, guard);
|
|
133
|
+
if (file !== undefined)
|
|
134
|
+
return file ?? undefined;
|
|
135
|
+
for (let dir = folder, guardDepth = 0; guardDepth < 64; guardDepth++) {
|
|
136
|
+
for (const link of links) {
|
|
137
|
+
const text = guard.readFile(joinPath(dir, link.file));
|
|
138
|
+
if (text !== undefined)
|
|
139
|
+
return linkParams(link, text);
|
|
140
|
+
}
|
|
141
|
+
if (dir === "/")
|
|
142
|
+
return undefined;
|
|
143
|
+
dir = joinPath(dir, "..");
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { MANIFEST_SCHEMA } from "../manifest.generated.js";
|
|
2
2
|
import { RAILWAY_CAPTURE } from "./railwayCapture.generated.js";
|
|
3
3
|
/**
|
|
4
|
-
* Railway at Level 1
|
|
4
|
+
* Railway at Level 1: it decides every `railway` command line on this computer (docs/design/zero-unknowns.md,
|
|
5
|
+
* follow-up 2, 2026-11-28); Railway's MCP tools at the gateway still run in its shadow (integrations spike,
|
|
6
|
+
* 2026-11-14). Derived from today's classifier
|
|
5
7
|
* (`shared/controlPlaneRailway*.ts`) and its tests: the same action keys (including the ones the catalog
|
|
6
8
|
* folded into others on 2026-11-13, which the server still maps: `removed.ts`), node ids and targets. Every
|
|
7
9
|
* node is placed from the inventory (an environment or service by id or name, the folder's link, the
|
|
@@ -370,6 +370,8 @@ export const RAILWAY_CAPTURE = {
|
|
|
370
370
|
framework: "arg",
|
|
371
371
|
infoFlags: ["help", "version"],
|
|
372
372
|
unknownFlags: "keep",
|
|
373
|
+
// Commands that change the folder's link: later commands in the line run on a link the guard can't read.
|
|
374
|
+
linkCommands: ["link", "unlink", "init", "environment", "environment link", "service", "service link"],
|
|
373
375
|
aliases: mergeAliases(tables.aliases ?? {}, {
|
|
374
376
|
env: "environment",
|
|
375
377
|
variable: "variables",
|
|
@@ -154,6 +154,7 @@ const idTarget = (type, id) => id ? { type, key: id, name: id } : undefined;
|
|
|
154
154
|
/* ------------------------------------------------------------------ */
|
|
155
155
|
export function railwayHooks(m, inventory) {
|
|
156
156
|
const known = new Set(m.capture.mcp.rules.map((rule) => rule.match));
|
|
157
|
+
const kinds = new Map(m.actions.map((action) => [action.key, action.kind]));
|
|
157
158
|
const contextOf = (context) => {
|
|
158
159
|
const linked = context.linked
|
|
159
160
|
? Object.fromEntries(["projectId", "environmentId", "serviceId"].flatMap((key) => context.linked?.[key] ? [[key, context.linked[key]]] : []))
|
|
@@ -204,6 +205,12 @@ export function railwayHooks(m, inventory) {
|
|
|
204
205
|
};
|
|
205
206
|
/** A command's environment: `-e`, else the folder's link, else the project's default. */
|
|
206
207
|
const cliEnv = (n, rc) => resolveEnv(projectOf(str(n.params.project), rc), str(n.params.environment), rc);
|
|
208
|
+
/**
|
|
209
|
+
* A command whose project, environment or service can't be read (no link, a `RAILWAY_TOKEN`, a hidden value): a
|
|
210
|
+
* change fails closed, the Unclassified action marked Couldn't read; a read stays a read
|
|
211
|
+
* (docs/design/zero-unknowns.md, decision 8). Railway's MCP tools keep their own fallbacks.
|
|
212
|
+
*/
|
|
213
|
+
const unread = (n, rule) => n.iface === "cli" && kinds.get(rule.action) !== "read" ? "unclassified" : "read";
|
|
207
214
|
const hooks = {
|
|
208
215
|
normalize: (request) => {
|
|
209
216
|
if (request.interface !== "mcp")
|
|
@@ -225,7 +232,7 @@ export function railwayHooks(m, inventory) {
|
|
|
225
232
|
if (n.iface === "cli") {
|
|
226
233
|
const env = cliEnv(n, rc);
|
|
227
234
|
if (!env)
|
|
228
|
-
return
|
|
235
|
+
return unread(n, rule);
|
|
229
236
|
const service = resolveService(env, str(n.params.service) ?? str(p.positional), rc);
|
|
230
237
|
const value = param ? str(p[param] ?? n.params[param]) : null;
|
|
231
238
|
const on = rule.target ? (s) => onServiceTarget(s, rule.target.type, value) : undefined;
|
|
@@ -255,7 +262,7 @@ export function railwayHooks(m, inventory) {
|
|
|
255
262
|
? str(n.params.duplicate)
|
|
256
263
|
: (str(p.positional) ?? str(n.params.environment));
|
|
257
264
|
const env = resolveEnv(projectId, ref, rc);
|
|
258
|
-
return env ? [at(env, rule.action, say(rule, { env: env.name }))] :
|
|
265
|
+
return env ? [at(env, rule.action, say(rule, { env: env.name }))] : unread(n, rule);
|
|
259
266
|
},
|
|
260
267
|
project: (n, p, context, rule) => {
|
|
261
268
|
const rc = contextOf(context);
|
|
@@ -264,7 +271,9 @@ export function railwayHooks(m, inventory) {
|
|
|
264
271
|
if (projectId === null) {
|
|
265
272
|
if (n.iface === "mcp")
|
|
266
273
|
return other(n, rc);
|
|
267
|
-
return rule.action === OTHER
|
|
274
|
+
return rule.action === OTHER
|
|
275
|
+
? [at(PROJECTS, OTHER, say(rule, { positional: str(p.positional) }))]
|
|
276
|
+
: unread(n, rule);
|
|
268
277
|
}
|
|
269
278
|
const project = projectTarget(projectId, rc);
|
|
270
279
|
return [at(project, rule.action, say(rule, { project: project.name, positional: str(p.positional) }))];
|
|
@@ -278,7 +287,7 @@ export function railwayHooks(m, inventory) {
|
|
|
278
287
|
const ref = str(n.params[volume ? "volume" : "bucket"]) ?? str(p.positional);
|
|
279
288
|
const env = cliEnv(n, rc);
|
|
280
289
|
if (ref === null || env === null)
|
|
281
|
-
return
|
|
290
|
+
return unread(n, rule);
|
|
282
291
|
const projectId = projectOf(str(n.params.project), rc);
|
|
283
292
|
return answer(n, rc, targetsOf(env, projectId, ref, rc).map((t) => at(t, rule.action, say(rule, { name: t.name, env: t.environment }))));
|
|
284
293
|
}
|
|
@@ -324,7 +333,7 @@ export function railwayHooks(m, inventory) {
|
|
|
324
333
|
.filter(Boolean);
|
|
325
334
|
const env = cliEnv(n, rc);
|
|
326
335
|
if (!env)
|
|
327
|
-
return
|
|
336
|
+
return unread(n, rule);
|
|
328
337
|
const service = resolveService(env, str(n.params.service), rc);
|
|
329
338
|
const on = (s) => onServiceTarget(s, "variable", onlyOne(names));
|
|
330
339
|
const summary = say(rule, { names: listNames(names), where: where(env, service) });
|
|
@@ -335,7 +344,7 @@ export function railwayHooks(m, inventory) {
|
|
|
335
344
|
if (n.iface === "cli") {
|
|
336
345
|
const env = cliEnv(n, rc);
|
|
337
346
|
if (!env)
|
|
338
|
-
return
|
|
347
|
+
return unread(n, rule);
|
|
339
348
|
const named = list(n.op === "deploy" ? n.params.template : n.params.database);
|
|
340
349
|
return [
|
|
341
350
|
at(env, rule.action, say(rule, { names: named.length ? listNames(named) : "a service", env: env.name }))
|
|
@@ -356,7 +365,7 @@ export function railwayHooks(m, inventory) {
|
|
|
356
365
|
? cliEnv(n, rc)
|
|
357
366
|
: resolveEnv(projectOf(str(args.projectId), rc), str(args.environmentId), rc);
|
|
358
367
|
if (!env)
|
|
359
|
-
return n.iface === "mcp" ? other(n, rc) :
|
|
368
|
+
return n.iface === "mcp" ? other(n, rc) : unread(n, rule);
|
|
360
369
|
return [at(env, rule.action, say(rule, { env: env.name }))];
|
|
361
370
|
},
|
|
362
371
|
staged: (n, _p, context) => {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a request lands: the node its params name and the chain from the app's service down to it (the engine's
|
|
3
|
+
* nodes, Part 2 section 5). Pure.
|
|
4
|
+
*/
|
|
5
|
+
import { type DiscoveredNode } from "../controlPlane.generated.js";
|
|
6
|
+
import type { Manifest } from "./manifest.generated.js";
|
|
7
|
+
import type { ClassifyContext, ConnectorHooks } from "./types.generated.js";
|
|
8
|
+
export type Chain = {
|
|
9
|
+
nodeId: string;
|
|
10
|
+
chain: DiscoveredNode[];
|
|
11
|
+
unresolved?: string;
|
|
12
|
+
};
|
|
13
|
+
/** The node types from the service down to `type`. */
|
|
14
|
+
export declare function typeChain(m: Manifest, type: string): string[];
|
|
15
|
+
/**
|
|
16
|
+
* The node a request lands on and its chain from the service down. The
|
|
17
|
+
* requested type, or its nearest ancestor the params can name; every
|
|
18
|
+
* ancestor above it must be named by the params or found in the inventory
|
|
19
|
+
* (context.parents, hooks.resolveParent), or the chain is `unresolved` and
|
|
20
|
+
* the caller fails closed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function nodeChain(m: Manifest, type: string, params: Readonly<Record<string, unknown>>, context?: ClassifyContext, hooks?: ConnectorHooks): Chain;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Generated by scripts/generate-control-plane-classifier.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Where a request lands: the node its params name and the chain from the app's service down to it (the engine's
|
|
4
|
+
* nodes, Part 2 section 5). Pure.
|
|
5
|
+
*/
|
|
6
|
+
import { nodeId } from "../controlPlane.generated.js";
|
|
7
|
+
import { fill } from "./template.generated.js";
|
|
8
|
+
/** A node the inventory knows, and its ancestors up to the service, as discovered nodes (service first). */
|
|
9
|
+
function inventoryChain(id, context, serviceId) {
|
|
10
|
+
const out = [];
|
|
11
|
+
for (let current = id, guard = 0; current && current !== serviceId && guard < 8; guard++) {
|
|
12
|
+
const parentId = context.parents?.[current] ?? serviceId;
|
|
13
|
+
const tail = current.slice(current.lastIndexOf("/") + 1);
|
|
14
|
+
const type = tail.slice(0, tail.indexOf(":"));
|
|
15
|
+
const key = current.slice(current.indexOf(":") + 1);
|
|
16
|
+
out.unshift({ id: current, parentId, type, name: context.names?.[current] ?? key, externalKey: key });
|
|
17
|
+
current = parentId;
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
/** The node types from the service down to `type`. */
|
|
22
|
+
export function typeChain(m, type) {
|
|
23
|
+
const specs = [];
|
|
24
|
+
for (let t = type, guard = 0; t && guard < 8; guard++) {
|
|
25
|
+
const spec = m.nodes[t];
|
|
26
|
+
if (!spec)
|
|
27
|
+
break;
|
|
28
|
+
specs.unshift(t);
|
|
29
|
+
t = spec.parent === "service" ? null : spec.parent.type;
|
|
30
|
+
}
|
|
31
|
+
return specs;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The node a request lands on and its chain from the service down. The
|
|
35
|
+
* requested type, or its nearest ancestor the params can name; every
|
|
36
|
+
* ancestor above it must be named by the params or found in the inventory
|
|
37
|
+
* (context.parents, hooks.resolveParent), or the chain is `unresolved` and
|
|
38
|
+
* the caller fails closed.
|
|
39
|
+
*/
|
|
40
|
+
export function nodeChain(m, type, params, context = {}, hooks = {}) {
|
|
41
|
+
const specs = typeChain(m, type);
|
|
42
|
+
const service = m.types.find((def) => def.type === type)?.service ?? m.services[0].key;
|
|
43
|
+
const serviceId = nodeId(m.platform, service);
|
|
44
|
+
const aliases = context.aliases ?? {};
|
|
45
|
+
const idOf = (t, key) => {
|
|
46
|
+
const named = nodeId(m.platform, service, t, key);
|
|
47
|
+
return aliases[named] ?? named;
|
|
48
|
+
};
|
|
49
|
+
const keys = specs.map((t) => fill(m.nodes[t].key, params));
|
|
50
|
+
// The deepest type the params name.
|
|
51
|
+
let deepest = specs.length - 1;
|
|
52
|
+
while (deepest >= 0 && keys[deepest] === null)
|
|
53
|
+
deepest -= 1;
|
|
54
|
+
if (deepest < 0)
|
|
55
|
+
return { nodeId: serviceId, chain: [], unresolved: type };
|
|
56
|
+
const chain = [];
|
|
57
|
+
let parentId = serviceId;
|
|
58
|
+
for (let i = 0; i <= deepest; i++) {
|
|
59
|
+
const t = specs[i];
|
|
60
|
+
const key = keys[i] ?? null;
|
|
61
|
+
if (key === null) {
|
|
62
|
+
// An ancestor the request doesn't name: the inventory may know the child's parent.
|
|
63
|
+
const childIndex = keys.findIndex((k, index) => index > i && index <= deepest && k !== null);
|
|
64
|
+
const childKey = keys[childIndex];
|
|
65
|
+
const childType = specs[childIndex];
|
|
66
|
+
const childId = idOf(childType, childKey);
|
|
67
|
+
const found = context.parents?.[childId] ?? hooks.resolveParent?.(childType, childId, context) ?? null;
|
|
68
|
+
if (!found)
|
|
69
|
+
return { nodeId: serviceId, chain: [], unresolved: t };
|
|
70
|
+
chain.push(...inventoryChain(found, context, serviceId));
|
|
71
|
+
parentId = found;
|
|
72
|
+
// Skip the other ancestors the request doesn't name: the inventory chain covers them.
|
|
73
|
+
while (i + 1 <= deepest && keys[i + 1] === null)
|
|
74
|
+
i += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const id = idOf(t, key);
|
|
78
|
+
// The inventory knows this node's parent: it wins over a parent the request claims.
|
|
79
|
+
const known = context.parents?.[id];
|
|
80
|
+
if (known && known !== parentId && i === deepest) {
|
|
81
|
+
chain.splice(0, chain.length, ...inventoryChain(known, context, serviceId));
|
|
82
|
+
parentId = known;
|
|
83
|
+
}
|
|
84
|
+
const spec = m.nodes[t];
|
|
85
|
+
const name = context.names?.[id] ?? (spec.name ? fill(spec.name, params) : null) ?? key.split("/").pop();
|
|
86
|
+
chain.push({ id, parentId, type: t, name, externalKey: id.slice(id.indexOf(":") + 1) });
|
|
87
|
+
parentId = id;
|
|
88
|
+
}
|
|
89
|
+
return { nodeId: parentId, chain };
|
|
90
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts a command runs from a file the guard can read (docs/design/zero-unknowns.md, follow-up 4): a shell script
|
|
3
|
+
* (`./deploy.sh`, `bash deploy.sh`, `source env.sh`), an interpreter's script file (`node deploy.mjs`), a Makefile
|
|
4
|
+
* target's recipe (`make deploy`), and a package.json script (`npm run deploy`, `pnpm deploy`, `yarn deploy`). Pure:
|
|
5
|
+
* `shell.ts` reads each file through the guard's bounded reader and reads what it runs like any other line.
|
|
6
|
+
*
|
|
7
|
+
* Bounds: a file bigger than `MAX_SCRIPT_BYTES` isn't read for commands, and a script runs scripts of its own only
|
|
8
|
+
* `MAX_SCRIPT_DEPTH` deep. What is past a bound and names the CLI is "Couldn't read".
|
|
9
|
+
*/
|
|
10
|
+
/** A script file read for its commands at most this big. */
|
|
11
|
+
export declare const MAX_SCRIPT_BYTES: number;
|
|
12
|
+
/** Scripts that run scripts: read this many levels deep (the line's own script is level 1). */
|
|
13
|
+
export declare const MAX_SCRIPT_DEPTH = 2;
|
|
14
|
+
/** Files read for one line, at most (latency). */
|
|
15
|
+
export declare const MAX_SCRIPT_FILES = 8;
|
|
16
|
+
/** What a file runs when it is executed: shell lines, or code for an interpreter (its shebang names it). Null for a
|
|
17
|
+
* file that isn't a script (binary). */
|
|
18
|
+
export declare function scriptKind(text: string): {
|
|
19
|
+
shell: true;
|
|
20
|
+
} | {
|
|
21
|
+
interpreter: string;
|
|
22
|
+
} | null;
|
|
23
|
+
export type PackageScriptCall = {
|
|
24
|
+
/** The script's name in package.json. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** Words after it, which the runner appends to the script's line. */
|
|
27
|
+
args: string[];
|
|
28
|
+
/** Folder the runner starts from: a path relative to the line's folder; null when the guard can't name it. */
|
|
29
|
+
dir?: string | null;
|
|
30
|
+
/** Whether npm runs `pre<name>` and `post<name>` around it. */
|
|
31
|
+
hooks: boolean;
|
|
32
|
+
/** Whether the name must be a script (`npm run x`), or may be the runner's own command or a file (`yarn x`). */
|
|
33
|
+
explicit: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** `npm run deploy -- --prod`, `npm test`, `pnpm run build`, `pnpm deploy`, `yarn deploy`, `bun run deploy`: the
|
|
36
|
+
* package.json script a runner runs, or null when the words aren't one. */
|
|
37
|
+
export declare function packageScriptCall(words: readonly string[]): PackageScriptCall | null;
|
|
38
|
+
/** A package.json's scripts, or undefined when it can't be read. */
|
|
39
|
+
export declare function packageScripts(text: string): Record<string, string> | undefined;
|
|
40
|
+
/** A word as the shell reads it back: quoted unless it is plainly safe. */
|
|
41
|
+
export declare const shellQuote: (word: string) => string;
|
|
42
|
+
/** The lines a package script call runs, in order: `pre<name>`, the script with the call's arguments, `post<name>`.
|
|
43
|
+
* Null when package.json names no such script. */
|
|
44
|
+
export declare function scriptLines(scripts: Readonly<Record<string, string>>, call: PackageScriptCall): string[] | null;
|
|
45
|
+
export type MakeCall = {
|
|
46
|
+
/** The folder make runs in, relative to the line's folder (`-C`); undefined when it doesn't move. */
|
|
47
|
+
dir?: string;
|
|
48
|
+
/** The makefile, relative to `dir` (`-f`); undefined for make's own search. */
|
|
49
|
+
file?: string;
|
|
50
|
+
targets: string[];
|
|
51
|
+
/** `NAME=value` given on the line. */
|
|
52
|
+
vars: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
/** `make [-C dir] [-f file] [NAME=value] [targets]`: what it runs, or null when it isn't make or runs no recipe. */
|
|
55
|
+
export declare function makeCall(words: readonly string[]): MakeCall | null;
|
|
56
|
+
/** make's own search, in order. */
|
|
57
|
+
export declare const MAKEFILES: string[];
|
|
58
|
+
type Rule = {
|
|
59
|
+
prereqs: string[];
|
|
60
|
+
recipe: string[];
|
|
61
|
+
};
|
|
62
|
+
/** A makefile's variables and rules (`target: prereqs` and the tab-indented recipe after it); the first target that
|
|
63
|
+
* isn't special is the default. Includes, conditionals and pattern rules aren't read. */
|
|
64
|
+
export declare function parseMakefile(text: string): {
|
|
65
|
+
vars: Record<string, string>;
|
|
66
|
+
rules: Map<string, Rule>;
|
|
67
|
+
first?: string;
|
|
68
|
+
};
|
|
69
|
+
/** The shell lines `make` runs for its targets (prerequisites first, each target once), each recipe line on its own
|
|
70
|
+
* (make runs each in a shell of its own). `@`, `-` and `+` prefixes are dropped. Null when a target has no rule. */
|
|
71
|
+
export declare function makeLines(text: string, call: MakeCall, limit?: number): string[] | null;
|
|
72
|
+
export {};
|