@sponson/core 0.4.0 → 0.6.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/engine/action.d.ts +22 -0
- package/dist/engine/action.js +55 -0
- package/dist/engine/action.js.map +1 -0
- package/dist/engine/apply.js +203 -22
- package/dist/engine/apply.js.map +1 -1
- package/dist/engine/destroy.js +42 -10
- package/dist/engine/destroy.js.map +1 -1
- package/dist/engine/index.d.ts +1 -1
- package/dist/engine/inspect.d.ts +7 -1
- package/dist/engine/inspect.js +68 -8
- package/dist/engine/inspect.js.map +1 -1
- package/dist/engine/lease.d.ts +39 -7
- package/dist/engine/lease.js +85 -20
- package/dist/engine/lease.js.map +1 -1
- package/dist/engine/manual.d.ts +47 -0
- package/dist/engine/manual.js +124 -0
- package/dist/engine/manual.js.map +1 -0
- package/dist/engine/once.d.ts +26 -0
- package/dist/engine/once.js +48 -0
- package/dist/engine/once.js.map +1 -0
- package/dist/engine/plan.js +24 -5
- package/dist/engine/plan.js.map +1 -1
- package/dist/engine/prepare.d.ts +1 -1
- package/dist/engine/prepare.js +71 -11
- package/dist/engine/prepare.js.map +1 -1
- package/dist/engine/run-context.d.ts +8 -2
- package/dist/engine/run-context.js +11 -2
- package/dist/engine/run-context.js.map +1 -1
- package/dist/engine/types.d.ts +33 -2
- package/dist/errors.d.ts +11 -1
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -1
- package/dist/receipts/git-workdir.d.ts +5 -0
- package/dist/receipts/git-workdir.js +9 -2
- package/dist/receipts/git-workdir.js.map +1 -1
- package/dist/receipts/git.d.ts +4 -0
- package/dist/receipts/git.js +35 -1
- package/dist/receipts/git.js.map +1 -1
- package/dist/receipts/layout.d.ts +8 -0
- package/dist/receipts/layout.js +11 -0
- package/dist/receipts/layout.js.map +1 -1
- package/dist/receipts/local.d.ts +4 -0
- package/dist/receipts/local.js +15 -1
- package/dist/receipts/local.js.map +1 -1
- package/dist/resolve.d.ts +19 -2
- package/dist/resolve.js +12 -3
- package/dist/resolve.js.map +1 -1
- package/dist/testing/fake.d.ts +15 -2
- package/dist/testing/fake.js +69 -3
- package/dist/testing/fake.js.map +1 -1
- package/dist/types.d.ts +190 -8
- package/dist/types.js.map +1 -1
- package/package.json +5 -1
package/dist/resolve.js
CHANGED
|
@@ -35,12 +35,14 @@ export function markerKind(v) {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Replace `{from}` and `{secret}` leaves.
|
|
38
|
-
* `secretValues` is only passed by apply; plan never resolves secrets.
|
|
38
|
+
* `secretValues` is only passed by apply; plan never resolves secrets. `keepSpent` decides, per reference to a spent
|
|
39
|
+
* `once` output, whether it may stand as `{ keep: true }` (by default it may); the engine asks the ledger.
|
|
39
40
|
*/
|
|
40
|
-
export function resolveParams(params, outputs, secretValues) {
|
|
41
|
+
export function resolveParams(params, outputs, secretValues, keepSpent = () => true) {
|
|
41
42
|
const inputs = {};
|
|
42
43
|
const pending = [];
|
|
43
44
|
const secrets = [];
|
|
45
|
+
const spent = [];
|
|
44
46
|
/** An output reference: its value when the line has produced it, else a pending marker. */
|
|
45
47
|
const fromRef = (ref, key) => {
|
|
46
48
|
const [line, ...rest] = ref.split(".");
|
|
@@ -51,6 +53,13 @@ export function resolveParams(params, outputs, secretValues) {
|
|
|
51
53
|
inputs[key] = { state: "resolved", value: sensitive ? null : lo.values[output], ref, sensitive, dependsOn: line };
|
|
52
54
|
return lo.values[output];
|
|
53
55
|
}
|
|
56
|
+
if (lo?.spent && lo.specs[output]?.once) {
|
|
57
|
+
// Shown once, in the run that created it: whoever received it then keeps it.
|
|
58
|
+
const kept = keepSpent(ref, line, output);
|
|
59
|
+
inputs[key] = { state: kept ? "kept" : "pending", value: null, ref, sensitive, dependsOn: line };
|
|
60
|
+
spent.push({ path: key, ref, line, kept });
|
|
61
|
+
return kept ? KEEP_MARKER : pendingMarker(ref);
|
|
62
|
+
}
|
|
54
63
|
inputs[key] = { state: "pending", value: null, ref, dependsOn: line, sensitive };
|
|
55
64
|
pending.push({ path: key, ref, line });
|
|
56
65
|
return pendingMarker(ref);
|
|
@@ -82,7 +91,7 @@ export function resolveParams(params, outputs, secretValues) {
|
|
|
82
91
|
return value;
|
|
83
92
|
};
|
|
84
93
|
const resolved = rebuild(params, []);
|
|
85
|
-
return { params: resolved, inputs, pending, secrets };
|
|
94
|
+
return { params: resolved, inputs, pending, secrets, spent };
|
|
86
95
|
}
|
|
87
96
|
/** All `{secret}` references in a params object. */
|
|
88
97
|
export function secretRefs(params) {
|
package/dist/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAA0E,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAA0E,MAAM,YAAY,CAAC;AAavI,+GAA+G;AAC/G,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,cAAc,GAAG,GAAG,CAAC;AAC9B,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,eAAe,CAAC,CAAU;IACxC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AAC/D,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,OAAO,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,WAAW,GAAG,YAA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G,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC9E,OAAO,GAAG,CAAC;QACb,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,CAAC,EAAE,CAAC;YAC9G,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QACvD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAmB,CAAC;IACvD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC/D,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,UAAU,CAAC,MAA+B;IACxD,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;QAC/B,IAAI,WAAW,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/testing/fake.d.ts
CHANGED
|
@@ -2,8 +2,13 @@ import type { ResourceAdapter, SecretSource } from "../types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* An in-memory provider for engine tests and property tests.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* outputs: id (immediate), secret (immediate, sensitive), url (external: "deploy")
|
|
5
|
+
* `item`, with params `{ name, value }`:
|
|
6
|
+
* outputs: id (immediate), secret (immediate, sensitive), url (external: "deploy"),
|
|
7
|
+
* token (sensitive, once: only in the apply that creates the item)
|
|
8
|
+
* A `{ keep: true }` value is unchanged when the item exists and PARAM_INVALID when it does not.
|
|
9
|
+
* `member`, with params `{ list, value }`: one entry of a list stored on a shared parent object, written by
|
|
10
|
+
* read-modify-write with a pause in between (`listLatencyMs`), like an Auth0 application's callback URLs.
|
|
11
|
+
* `lockOn` names the list (ADR 0019) unless `lockLists` is false, which reproduces the lost update.
|
|
7
12
|
* Chaos knobs let a test fail the n-th write, make the deploy never happen, etc.
|
|
8
13
|
*/
|
|
9
14
|
export interface FakeItem {
|
|
@@ -15,6 +20,12 @@ export interface FakeItem {
|
|
|
15
20
|
type FailKind = "apply" | "create" | "lost" | "destroy" | "read";
|
|
16
21
|
export declare class FakeCloud {
|
|
17
22
|
items: Map<string, FakeItem>;
|
|
23
|
+
/** Lists on shared parent objects, by list name. */
|
|
24
|
+
lists: Map<string, string[]>;
|
|
25
|
+
/** Pause between reading a list and writing it back: the window in which a concurrent writer loses an update. */
|
|
26
|
+
listLatencyMs: number;
|
|
27
|
+
/** Whether `member` declares its parent object (`lockOn`). */
|
|
28
|
+
lockLists: boolean;
|
|
18
29
|
writes: Array<{
|
|
19
30
|
op: "create" | "update" | "delete";
|
|
20
31
|
name: string;
|
|
@@ -35,6 +46,8 @@ export declare class FakeCloud {
|
|
|
35
46
|
reset(): void;
|
|
36
47
|
private maybeFail;
|
|
37
48
|
adapter(name?: string): ResourceAdapter;
|
|
49
|
+
/** One value in a list held by a shared parent object, written by read-modify-write of the whole list. */
|
|
50
|
+
private memberOp;
|
|
38
51
|
}
|
|
39
52
|
/** Secrets from a map; fingerprint changes with the value. */
|
|
40
53
|
export declare function fakeSecretSource(values: Record<string, string>, scheme?: string): SecretSource;
|
package/dist/testing/fake.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { SponsonError } from "../errors.js";
|
|
2
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
1
3
|
import { sha256 } from "../hash.js";
|
|
2
4
|
import { isPendingMarker, markerKind, pendingRef } from "../resolve.js";
|
|
3
5
|
export class FakeCloud {
|
|
4
6
|
items = new Map();
|
|
7
|
+
/** Lists on shared parent objects, by list name. */
|
|
8
|
+
lists = new Map();
|
|
9
|
+
/** Pause between reading a list and writing it back: the window in which a concurrent writer loses an update. */
|
|
10
|
+
listLatencyMs = 0;
|
|
11
|
+
/** Whether `member` declares its parent object (`lockOn`). */
|
|
12
|
+
lockLists = true;
|
|
5
13
|
writes = [];
|
|
6
14
|
reads = 0;
|
|
7
15
|
external = "ok";
|
|
@@ -30,6 +38,7 @@ export class FakeCloud {
|
|
|
30
38
|
}
|
|
31
39
|
reset() {
|
|
32
40
|
this.items.clear();
|
|
41
|
+
this.lists.clear();
|
|
33
42
|
this.writes = [];
|
|
34
43
|
this.reads = 0;
|
|
35
44
|
this.external = "ok";
|
|
@@ -55,9 +64,11 @@ export class FakeCloud {
|
|
|
55
64
|
id: { available: "immediate" },
|
|
56
65
|
secret: { available: "immediate", sensitive: true },
|
|
57
66
|
url: { available: "external", event: "deploy" },
|
|
67
|
+
token: { available: "immediate", sensitive: true, once: true },
|
|
58
68
|
},
|
|
59
69
|
defaults: (p, ctx) => ({ ...p, name: p.name ?? `item-${ctx.scope}` }),
|
|
60
|
-
|
|
70
|
+
// From the line (`target`), or from the provider block (`providers.fake.production: true`).
|
|
71
|
+
writesEnvironment: (p, _ctx, provider) => (typeof p.target === "string" ? p.target : provider?.production === true ? "production" : null),
|
|
61
72
|
async read(_actx, p) {
|
|
62
73
|
cloud.reads++;
|
|
63
74
|
cloud.maybeFail("read", String(p.name));
|
|
@@ -71,6 +82,11 @@ export class FakeCloud {
|
|
|
71
82
|
const want = p.value;
|
|
72
83
|
const current = live?.resources.find((r) => r.key === key(n));
|
|
73
84
|
const marker = markerKind(want);
|
|
85
|
+
if (marker === "keep") {
|
|
86
|
+
if (current)
|
|
87
|
+
return [{ key: key(n), label: n, kind: "unchanged" }];
|
|
88
|
+
throw new SponsonError("PARAM_INVALID", `${n} is declared \`{ keep: true }\` but does not exist`, { key: key(n) });
|
|
89
|
+
}
|
|
74
90
|
const after = marker === "pending" || marker === "secret" ? { state: marker, ref: pendingRef(want) } : { state: "literal", value: String(want) };
|
|
75
91
|
if (!current)
|
|
76
92
|
return [{ key: key(n), label: n, kind: "create", after }];
|
|
@@ -85,7 +101,7 @@ export class FakeCloud {
|
|
|
85
101
|
cloud.maybeFail("apply", n);
|
|
86
102
|
const existing = cloud.items.get(n);
|
|
87
103
|
if (existing) {
|
|
88
|
-
if (existing.value !== String(p.value)) {
|
|
104
|
+
if (markerKind(p.value) !== "keep" && existing.value !== String(p.value)) {
|
|
89
105
|
existing.value = String(p.value);
|
|
90
106
|
cloud.writes.push({ op: "update", name: n });
|
|
91
107
|
}
|
|
@@ -98,7 +114,7 @@ export class FakeCloud {
|
|
|
98
114
|
cloud.writes.push({ op: "create", name: n });
|
|
99
115
|
cloud.maybeFail("lost", n); // the write happened; the response did not arrive
|
|
100
116
|
void live;
|
|
101
|
-
return { resources: [record(it)], outputs: outputsOf(it), created: [key(n)] };
|
|
117
|
+
return { resources: [record(it)], outputs: { ...outputsOf(it), token: `t-${it.id}-${it.name}` }, created: [key(n)] };
|
|
102
118
|
},
|
|
103
119
|
async destroy(_actx, resources) {
|
|
104
120
|
for (const r of resources) {
|
|
@@ -119,6 +135,56 @@ export class FakeCloud {
|
|
|
119
135
|
return [...cloud.items.values()].map(record);
|
|
120
136
|
},
|
|
121
137
|
},
|
|
138
|
+
member: this.memberOp(),
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** One value in a list held by a shared parent object, written by read-modify-write of the whole list. */
|
|
143
|
+
memberOp() {
|
|
144
|
+
const cloud = this;
|
|
145
|
+
const key = (list, v) => `member:${list}:${v}`;
|
|
146
|
+
const record = (list, v) => ({ key: key(list, v), id: `${list}/${v}`, hash: sha256(v), label: `${v} in ${list}` });
|
|
147
|
+
/** Read the list, pause, write the list back changed: the lost-update window of every list-on-parent API. */
|
|
148
|
+
const rewrite = async (list, change) => {
|
|
149
|
+
const before = [...(cloud.lists.get(list) ?? [])];
|
|
150
|
+
if (cloud.listLatencyMs)
|
|
151
|
+
await sleep(Math.random() * cloud.listLatencyMs);
|
|
152
|
+
cloud.lists.set(list, change(before));
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
outputs: {},
|
|
156
|
+
lockOn: (p) => (cloud.lockLists ? `fake:list:${String(p.list)}` : null),
|
|
157
|
+
async read(_actx, p) {
|
|
158
|
+
cloud.reads++;
|
|
159
|
+
const list = String(p.list);
|
|
160
|
+
const v = String(p.value);
|
|
161
|
+
return cloud.lists.get(list)?.includes(v) ? { resources: [record(list, v)], outputs: {} } : null;
|
|
162
|
+
},
|
|
163
|
+
diff(live, p) {
|
|
164
|
+
const v = String(p.value);
|
|
165
|
+
const exists = live?.resources.some((r) => r.key === key(String(p.list), v));
|
|
166
|
+
return [{ key: key(String(p.list), v), label: `${v} in ${String(p.list)}`, kind: exists ? "unchanged" : "create", ...(exists ? {} : { after: { state: "literal", value: v } }) }];
|
|
167
|
+
},
|
|
168
|
+
async apply(actx, p, live) {
|
|
169
|
+
const list = String(p.list);
|
|
170
|
+
const v = String(p.value);
|
|
171
|
+
if (live)
|
|
172
|
+
return { resources: [record(list, v)], outputs: {}, created: [] };
|
|
173
|
+
await actx.intend([key(list, v)]);
|
|
174
|
+
cloud.maybeFail("create", v);
|
|
175
|
+
await rewrite(list, (values) => (values.includes(v) ? values : [...values, v]));
|
|
176
|
+
cloud.writes.push({ op: "create", name: `${list}/${v}` });
|
|
177
|
+
cloud.maybeFail("lost", v); // the write happened; the response did not arrive
|
|
178
|
+
return { resources: [record(list, v)], outputs: {}, created: [key(list, v)] };
|
|
179
|
+
},
|
|
180
|
+
async destroy(_actx, resources) {
|
|
181
|
+
for (const r of resources) {
|
|
182
|
+
const at = r.id.indexOf("/");
|
|
183
|
+
const [list, v] = [r.id.slice(0, at), r.id.slice(at + 1)];
|
|
184
|
+
cloud.maybeFail("destroy", v);
|
|
185
|
+
await rewrite(list, (values) => values.filter((x) => x !== v));
|
|
186
|
+
cloud.writes.push({ op: "delete", name: r.id });
|
|
187
|
+
}
|
|
122
188
|
},
|
|
123
189
|
};
|
|
124
190
|
}
|
package/dist/testing/fake.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake.js","sourceRoot":"","sources":["../../src/testing/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAmBxE,MAAM,OAAO,SAAS;IACpB,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IACpC,MAAM,GAAgE,EAAE,CAAC;IACzE,KAAK,GAAG,CAAC,CAAC;IACV,QAAQ,GAA4B,IAAI,CAAC;IACjC,SAAS,GAA8C,EAAE,CAAC;IAC1D,GAAG,GAAG,CAAC,CAAC;IAEhB,IAAI,CAAC,IAAY,EAAE,KAAa;QAC9B,MAAM,IAAI,GAAa,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAClF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,IAAc,EAAE,KAAc;QACrC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,+BAA+B;IAC/B,KAAK,CAAC,IAAY,EAAE,KAAa;QAC/B,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IA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AAU,gBAAgB,CAAC,MAA8B,EAAE,MAAM,GAAG,MAAM;IAC9E,OAAO;QACL,MAAM;QACN,KAAK,CAAC,OAAO,CAAC,GAAG;YACf,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;YAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,CAAC,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,UAAU,GAAG,YAAY,CAAC,CAAC;YAChE,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -100,6 +100,16 @@ export interface OutputSpec {
|
|
|
100
100
|
event?: string;
|
|
101
101
|
/** Sensitive outputs are never displayed, logged, or written to receipts. */
|
|
102
102
|
sensitive?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* The provider reveals this value only in the response that creates the resource (a database password's
|
|
105
|
+
* plaintext): `read` never returns it and Sponson never stores it, so declare it `sensitive` too. It reaches
|
|
106
|
+
* dependent lines in the run that creates the resource. In any later run, a `from:` reference to it resolves to
|
|
107
|
+
* `{ keep: true }` when the ledger's fingerprints show the dependent already holds the current value; a dependent
|
|
108
|
+
* that would have to write it (or cannot be shown to hold it) is refused with OUTPUT_UNAVAILABLE instead of
|
|
109
|
+
* receiving an empty value. Nothing is re-created to get the value back unless the run asks for it (`recreate`).
|
|
110
|
+
* See docs/adr/0018-once-only-outputs.md.
|
|
111
|
+
*/
|
|
112
|
+
once?: boolean;
|
|
103
113
|
}
|
|
104
114
|
/** One concrete thing in the provider. */
|
|
105
115
|
export interface ResourceRecord {
|
|
@@ -135,8 +145,8 @@ export interface LiveState {
|
|
|
135
145
|
/** Outputs derivable from live state right now. Sensitive ones are still returned here; the engine masks them. */
|
|
136
146
|
outputs: Record<string, Literal>;
|
|
137
147
|
}
|
|
138
|
-
/** What apply would do to one resource. */
|
|
139
|
-
export type DiffKind = "create" | "update" | "unchanged";
|
|
148
|
+
/** What apply would do to one resource; `run`: send a one-off action (`OpSpec.action`, ADR 0022). */
|
|
149
|
+
export type DiffKind = "create" | "update" | "unchanged" | "run";
|
|
140
150
|
/**
|
|
141
151
|
* One side of a diff, as data. Renderers turn it into text; JSON carries it as-is.
|
|
142
152
|
* `value` is present only for non-sensitive literal values; everything else is described by state.
|
|
@@ -191,6 +201,13 @@ export interface AdapterContext {
|
|
|
191
201
|
intend(keys: string[]): Promise<void>;
|
|
192
202
|
/** Mask every known secret (in all its encodings). Call it on provider text BEFORE truncating it. */
|
|
193
203
|
redact(text: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* Register a credential the adapter obtained at run time (an OAuth access token, a token printed by a CLI), so
|
|
206
|
+
* that it is masked in every output, receipt and error from now on, exactly like a resolved secret. Optional: a
|
|
207
|
+
* context without it (an older engine, a test harness) masks nothing more, so adapters also mask such values in
|
|
208
|
+
* their own error text.
|
|
209
|
+
*/
|
|
210
|
+
secret?(value: string): void;
|
|
194
211
|
}
|
|
195
212
|
/**
|
|
196
213
|
* One plan line proposed by `OpSpec.adopt`. The CLI adds `adapter`, `op` and `environments`, and makes `id` unique.
|
|
@@ -219,14 +236,78 @@ export interface AdoptedLine {
|
|
|
219
236
|
*/
|
|
220
237
|
export interface OpSpec {
|
|
221
238
|
outputs: Record<string, OutputSpec>;
|
|
239
|
+
/**
|
|
240
|
+
* For ops whose outputs a line declares in its own params (the generic `http` ops): the outputs of one line,
|
|
241
|
+
* given its params as written (not interpolated, references unresolved). The engine uses them instead of
|
|
242
|
+
* `outputs` for that line, so a `from:` naming an undeclared output still fails before any provider call. Throw
|
|
243
|
+
* PARAM_INVALID for a malformed declaration.
|
|
244
|
+
*/
|
|
245
|
+
outputsFor?(params: Record<string, unknown>): Record<string, OutputSpec>;
|
|
246
|
+
/**
|
|
247
|
+
* For ops whose `providers.<adapter>` block holds several independent configurations (the generic `http`
|
|
248
|
+
* adapter: one per API): the part a line uses, given the whole block and the line's params as written. It
|
|
249
|
+
* becomes `actx.provider` and part of the ledger identity of the line's resources, so editing one API's
|
|
250
|
+
* configuration does not re-identify resources of another. Pure; throw PLAN_INVALID when the line names a
|
|
251
|
+
* configuration the block does not have. Without it the whole block is used.
|
|
252
|
+
*/
|
|
253
|
+
providerFor?(block: Record<string, unknown>, params: Record<string, unknown>): Record<string, unknown>;
|
|
254
|
+
/**
|
|
255
|
+
* The names of the line's params that carry a credential the op authenticates with (the generic `http` adapter's
|
|
256
|
+
* line-level `credential`), given the params as written. The engine checks each before any provider call: it must
|
|
257
|
+
* be a `{ secret: … }` reference, or a `{ from: <line>.<output> }` naming an output declared `sensitive` and not
|
|
258
|
+
* `once` (a once-only value resolves to `{ keep: true }` in later runs, which cannot authenticate a request);
|
|
259
|
+
* anything else, a literal above all, is PARAM_INVALID. The resolved value is masked like any secret. Pure.
|
|
260
|
+
*/
|
|
261
|
+
credentialInputs?(params: Record<string, unknown>): string[];
|
|
222
262
|
/** Fill in defaults (e.g. a branch name) given the context. Returns a new params object. */
|
|
223
263
|
defaults?(params: ResolvedParams, ctx: Ctx): ResolvedParams;
|
|
224
264
|
/**
|
|
225
|
-
* The deployment environment this change writes to, when the op targets one explicitly
|
|
226
|
-
* (Vercel env `target`)
|
|
227
|
-
*
|
|
265
|
+
* The deployment environment this change writes to, when the op targets one explicitly: from the line's params
|
|
266
|
+
* (Vercel env `target`) or from the provider block the line writes through (`provider`, the `providers.<adapter>`
|
|
267
|
+
* block as `providerFor` narrows it: a LaunchDarkly block naming a production environment). The engine requires
|
|
268
|
+
* approval when any line writes to `production`, whatever the run's environment is. Return null when the op is not
|
|
269
|
+
* environment-specific. Pure, called before any provider call; throw PLAN_INVALID for a block it cannot judge.
|
|
270
|
+
* The engine always passes `provider`; it is optional only so that callers written for the two-argument form
|
|
271
|
+
* still compile.
|
|
228
272
|
*/
|
|
229
|
-
writesEnvironment?(params: ResolvedParams, ctx: Ctx): string | null;
|
|
273
|
+
writesEnvironment?(params: ResolvedParams, ctx: Ctx, provider?: Record<string, unknown>): string | null;
|
|
274
|
+
/**
|
|
275
|
+
* The shared provider object this line's resources live in, when its writes are read-modify-write of something
|
|
276
|
+
* other scopes write too: one callback array on an Auth0 application, Supabase's `uri_allow_list`, a Firebase
|
|
277
|
+
* authorized-domains list. Return a stable identity naming the provider, the account and the object, e.g.
|
|
278
|
+
* `auth0:<tenant>:client:<client id>`; null when the line's resources are objects of their own.
|
|
279
|
+
*
|
|
280
|
+
* The engine then holds a lease on that identity (ADR 0019) across scopes and environments around every write the
|
|
281
|
+
* line makes: re-reading live state, `apply`, and the `destroy` of rollback and `apply --destroy` (which use the
|
|
282
|
+
* identity recorded in the ledger, so a line removed from the plan is still locked correctly). The identity is
|
|
283
|
+
* written to receipts and shown in messages: never put a secret in it. Pure: no provider calls.
|
|
284
|
+
*/
|
|
285
|
+
lockOn?(params: ResolvedParams, provider: Record<string, unknown>): string | null;
|
|
286
|
+
/**
|
|
287
|
+
* For an op whose change a person makes, not an API (the built-in `manual.step`, ADR 0021): the step as the human
|
|
288
|
+
* sees it, from resolved params; null while an input is still pending. The engine then owns the line's state:
|
|
289
|
+
* `plan` shows it as `todo` with these instructions until it is done, `apply` records it only when the run
|
|
290
|
+
* confirms it (`RunOptions.confirm`) or `read` observes it (a verify request), and otherwise leaves it waiting
|
|
291
|
+
* with MANUAL_STEP_PENDING; `apply --destroy` shows `undo` and needs the same confirmation. `read` returns the
|
|
292
|
+
* step's resource only when it can observe that the step is done (`observable`), else null; `apply` and
|
|
293
|
+
* `destroy` are never called. Pure: no provider calls.
|
|
294
|
+
*/
|
|
295
|
+
manual?(params: ResolvedParams, ctx: Ctx): ManualStep | null;
|
|
296
|
+
/**
|
|
297
|
+
* For an op that is a one-off action rather than a resource (the built-in `http.action`, ADR 0022: an Inngest
|
|
298
|
+
* sync, a cache purge, a deploy notification): its trigger, from resolved params; null while a trigger value is
|
|
299
|
+
* still pending. The engine then owns the line's state. The ledger key is `action:<line id>` and its hash the
|
|
300
|
+
* keyed `sha256(canonicalJson(trigger))`: `plan` shows `run` when no run of this trigger is recorded and
|
|
301
|
+
* `unchanged` otherwise, with no other drift. `apply` calls `apply` only to run it, passing as `live` one resource
|
|
302
|
+
* (the ledger key, the previous record id or "", and the raw trigger hash, from which the op derives an
|
|
303
|
+
* idempotency key), then records the trigger hash, the record id `apply` returned (`resources[0].id`: how to undo
|
|
304
|
+
* it) and the outputs. Nothing is recorded before the request is sent (at-least-once: a crash in between sends it
|
|
305
|
+
* again with the same idempotency key), `intend` is never called, rollback never undoes it, and another scope's
|
|
306
|
+
* record of the same key does not block it. `apply --destroy` passes the record to `destroy` (send the undo, or
|
|
307
|
+
* nothing) and forgets it. `read` is never called. Outputs must not be sensitive: an unchanged line's outputs come
|
|
308
|
+
* from the ledger. Pure: no provider calls.
|
|
309
|
+
*/
|
|
310
|
+
action?(params: ResolvedParams, ctx: Ctx): ActionTrigger | null;
|
|
230
311
|
/** Find what currently exists for this change. Null when nothing exists. Must not write. */
|
|
231
312
|
read(actx: AdapterContext, params: ResolvedParams): Promise<LiveState | null>;
|
|
232
313
|
/**
|
|
@@ -269,6 +350,27 @@ export interface OpSpec {
|
|
|
269
350
|
id?: string;
|
|
270
351
|
}>, ctx: Ctx): AdoptedLine[];
|
|
271
352
|
}
|
|
353
|
+
/** One step a person must do by hand, as `OpSpec.manual` describes it (ADR 0021). */
|
|
354
|
+
export interface ManualStep {
|
|
355
|
+
/** The resource key: stable for the step, whatever its instructions say (`step:<title>`). */
|
|
356
|
+
key: string;
|
|
357
|
+
title: string;
|
|
358
|
+
/** What to do, as Markdown, with every reference already filled in. */
|
|
359
|
+
instructions: string;
|
|
360
|
+
/** What to do to reverse it when the scope is destroyed, as Markdown; absent when there is nothing to undo. */
|
|
361
|
+
undo?: string;
|
|
362
|
+
/** Hash of what the person is asked to do (`sha256(canonicalJson({ title, instructions }))`): a new one is a new step. */
|
|
363
|
+
hash: string;
|
|
364
|
+
/** Whether `read` can observe that the step is done (a verify request); otherwise only a confirmation can tell. */
|
|
365
|
+
observable: boolean;
|
|
366
|
+
}
|
|
367
|
+
/** The trigger of a one-off action, as `OpSpec.action` describes it (ADR 0022). */
|
|
368
|
+
export interface ActionTrigger {
|
|
369
|
+
/** The values whose change makes the action run again (a commit, a preview URL), resolved; hashed, never stored. */
|
|
370
|
+
trigger: Record<string, unknown>;
|
|
371
|
+
/** What the action does, for display (`PUT https://…/api/inngest`). */
|
|
372
|
+
label: string;
|
|
373
|
+
}
|
|
272
374
|
/**
|
|
273
375
|
* A provider integration: a name (the plan's `adapter:`) and its ops. Register it with `Registry.addAdapter`;
|
|
274
376
|
* see `OpSpec` for the contract and `@sponson/core/testing` for a complete in-memory adapter.
|
|
@@ -317,10 +419,48 @@ export interface ResourceAdapter {
|
|
|
317
419
|
}
|
|
318
420
|
/** The environment an adapter reads: its credential, and the variable that overrides its API base URL. */
|
|
319
421
|
export interface AdapterAbout {
|
|
320
|
-
/**
|
|
422
|
+
/**
|
|
423
|
+
* Environment variable holding the credential, e.g. `NEON_API_KEY`; for an adapter whose plan names the
|
|
424
|
+
* variable per provider block (the generic `http` adapter), where in the plan it is named.
|
|
425
|
+
*/
|
|
321
426
|
credentialEnv: string;
|
|
322
|
-
/** Environment variable that overrides the API base URL (the sim and tests use it), when there is one. */
|
|
427
|
+
/** Environment variable that overrides the API base URL (the sim and tests use it), when there is one; or where the plan names it. */
|
|
323
428
|
baseUrlEnv?: string;
|
|
429
|
+
/** Further variables the credential needs, when one is not enough (PlanetScale: the service token's id). */
|
|
430
|
+
extraCredentialEnv?: readonly string[];
|
|
431
|
+
/**
|
|
432
|
+
* The command whose output is the credential, for an adapter that takes a CLI's access token instead of reading a
|
|
433
|
+
* variable (Cloud Run: `gcloud auth print-access-token`). `credentialEnv` then names the command for people, and no
|
|
434
|
+
* variable is listed as the credential.
|
|
435
|
+
*/
|
|
436
|
+
credentialCommand?: readonly string[];
|
|
437
|
+
/** The provider as people write it (Vercel, Cloudflare Pages): `sponson init`'s summary and the provider catalog. */
|
|
438
|
+
title?: string;
|
|
439
|
+
/** The id of the docs/coverage.yaml category the adapter belongs to (deploy, databases, auth, …). */
|
|
440
|
+
category?: string;
|
|
441
|
+
/**
|
|
442
|
+
* What in a repository's files says it uses this provider. `sponson init` reads it to detect the provider, so an
|
|
443
|
+
* adapter that declares it is detected with no change to the CLI. Absent for adapters no repository file names
|
|
444
|
+
* (the generic `http` adapter, `manual`).
|
|
445
|
+
*/
|
|
446
|
+
detect?: ProviderDetect;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* The signals `sponson init` detects a provider by: names and files only. The value of a variable is never read,
|
|
450
|
+
* except a database URL's host, which is classified against `dbHosts` and dropped.
|
|
451
|
+
*/
|
|
452
|
+
export interface ProviderDetect {
|
|
453
|
+
/** Dependency names in package.json: exact (`stripe`), or a scope or prefix ending in `/` (`@stripe/`). */
|
|
454
|
+
deps?: readonly string[];
|
|
455
|
+
/**
|
|
456
|
+
* Variable names in `.env*` files: exact (`AUTH0_DOMAIN`), or a prefix ending in `*` (`AUTH0_*`). A framework's
|
|
457
|
+
* public prefix (`NEXT_PUBLIC_`, `PUBLIC_`, `VITE_`, …) in front of the name matches too.
|
|
458
|
+
*/
|
|
459
|
+
env?: readonly string[];
|
|
460
|
+
/** Files whose presence is a signal (`fly.toml`), relative to the repository root. */
|
|
461
|
+
files?: readonly string[];
|
|
462
|
+
/** Host suffixes (`.neon.tech`) of a database URL in an `.env*` file that point at this provider. */
|
|
463
|
+
dbHosts?: readonly string[];
|
|
324
464
|
}
|
|
325
465
|
/**
|
|
326
466
|
* Resolves `{ secret: "<scheme>://..." }` references. Register one with `Registry.addSecretSource` to support a
|
|
@@ -391,6 +531,34 @@ export interface LedgerEntry {
|
|
|
391
531
|
orphan?: boolean;
|
|
392
532
|
/** Non-sensitive outputs last seen for the owning line (including external ones like preview_url). */
|
|
393
533
|
outputs?: Record<string, Literal>;
|
|
534
|
+
/** The shared parent object the resource lives in (`OpSpec.lockOn`); rollback and destroy lock it (ADR 0019). */
|
|
535
|
+
parent?: string;
|
|
536
|
+
/**
|
|
537
|
+
* Keyed fingerprints of the `once` outputs (ADR 0018) the line's create returned, by output name: which value is
|
|
538
|
+
* current, never the value.
|
|
539
|
+
*/
|
|
540
|
+
onceFingerprints?: Record<string, string>;
|
|
541
|
+
/**
|
|
542
|
+
* Keyed fingerprints of the `once` values this resource was last written with, by reference (`line.output`). Equal
|
|
543
|
+
* to the producer's `onceFingerprints` entry means it still holds the current value (ADR 0018).
|
|
544
|
+
*/
|
|
545
|
+
onceInputs?: Record<string, string>;
|
|
546
|
+
/**
|
|
547
|
+
* For a manual step (ADR 0021): what it was and how it was found done. `undo` is what `apply --destroy` asks a
|
|
548
|
+
* person to do; `by` and `at` say who confirmed it and when (`how: confirmed`), or when a verify request first
|
|
549
|
+
* saw it done (`how: verified`). Text is stored masked, as every output is.
|
|
550
|
+
*/
|
|
551
|
+
manual?: {
|
|
552
|
+
title: string;
|
|
553
|
+
undo?: string;
|
|
554
|
+
how: "confirmed" | "verified";
|
|
555
|
+
by?: string;
|
|
556
|
+
at: string;
|
|
557
|
+
};
|
|
558
|
+
/** For a one-off action (ADR 0022): when it last ran. `hash` is its trigger's; `id` says how to undo it. */
|
|
559
|
+
action?: {
|
|
560
|
+
at: string;
|
|
561
|
+
};
|
|
394
562
|
}
|
|
395
563
|
/**
|
|
396
564
|
* The record of one run for an environment and scope, and the ledger it leaves behind. Stores persist it; agents
|
|
@@ -463,6 +631,20 @@ export interface ReceiptStore {
|
|
|
463
631
|
/** Current lock, or null. Never throws for a missing/unreadable lock. */
|
|
464
632
|
readLock(environment: string, scope: string): Promise<LockInfo | null>;
|
|
465
633
|
releaseLock(environment: string, scope: string, holder: string): Promise<void>;
|
|
634
|
+
/**
|
|
635
|
+
* Parent-object locks (ADR 0019): a lease on a shared provider object (`OpSpec.lockOn`), one per object across
|
|
636
|
+
* every scope and environment, with the same semantics as the scope lock (`LockHeldError`, expiry and takeover,
|
|
637
|
+
* `LockLostError` on a renewal by someone who lost it). `parent` is the identity the op returned; stores key it by
|
|
638
|
+
* `parentLockScope(parent)`. Optional: the engine falls back to the scope-lock methods under the reserved
|
|
639
|
+
* environment `PARENT_LOCKS_ENVIRONMENT`, which every store supports.
|
|
640
|
+
*/
|
|
641
|
+
acquireParentLock?(parent: string, holder: string, ttlMs: number): Promise<LockInfo | null>;
|
|
642
|
+
/** Extend a parent lock we hold. Throws LockLostError when someone else holds it now. */
|
|
643
|
+
renewParentLock?(parent: string, holder: string, ttlMs: number): Promise<void>;
|
|
644
|
+
/** Current parent lock, or null. Never throws for a missing/unreadable lock. */
|
|
645
|
+
readParentLock?(parent: string): Promise<LockInfo | null>;
|
|
646
|
+
/** Release a parent lock; a no-op when `holder` does not hold it. */
|
|
647
|
+
releaseParentLock?(parent: string, holder: string): Promise<void>;
|
|
466
648
|
/** Release what the store holds locally (a temporary working clone). Whoever constructed the store calls it once done. */
|
|
467
649
|
close?(): Promise<void>;
|
|
468
650
|
}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAgCH,0GAA0G;AAC1G,MAAM,UAAU,SAAS,CAAC,CAAU;IAClC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,MAAM,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC1F,CAAC;AAED,iCAAiC;AACjC,MAAM,UAAU,SAAS,CAAC,CAAU;IAClC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AAC/E,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,OAAO,OAAO,CAA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YAA4B,IAAc;QACxC,KAAK,CAAC,sBAAsB,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QADzC,SAAI,GAAJ,IAAI,CAAU;QAExC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sponson/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Plan model, planner, execution engine, receipt stores and adapter interfaces for Sponson.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sponson",
|
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"README.md",
|
|
48
48
|
"LICENSE"
|
|
49
49
|
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"provenance": true
|
|
53
|
+
},
|
|
50
54
|
"homepage": "https://sponson.mintlify.site",
|
|
51
55
|
"bugs": {
|
|
52
56
|
"url": "https://github.com/MishaBear94/Sponson/issues"
|