@michaelrwalker/stagehand 0.4.0 → 0.5.1
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/README.md +105 -2
- package/dist/cache.d.ts +34 -2
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +148 -17
- package/dist/cache.js.map +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +4 -2
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +22 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/script.d.ts +71 -16
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +29 -7
- package/dist/script.js.map +1 -1
- package/dist/types.d.ts +109 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -11
package/README.md
CHANGED
|
@@ -364,6 +364,60 @@ await deploy.run(input, { cache: argv.includes("--no-cache") ? "off" : "on" });
|
|
|
364
364
|
`"refresh"` runs everything and overwrites · `"read-only"` uses hits but never
|
|
365
365
|
writes.
|
|
366
366
|
|
|
367
|
+
### Reaching the cache from a step
|
|
368
|
+
|
|
369
|
+
Every handler and rollback gets a `cache` handle, typed to the cached phases
|
|
370
|
+
declared **before** it:
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
.addPhase("Fetch", { cache: { store } })
|
|
374
|
+
.addStep({ name: "pull orders", handler: … }) // → { orders }
|
|
375
|
+
|
|
376
|
+
.addPhase("Adjust")
|
|
377
|
+
.addStep({
|
|
378
|
+
name: "restock",
|
|
379
|
+
handler: async ({ ctx, cache }) => {
|
|
380
|
+
await cache.clear("Fetch"); // next run refetches
|
|
381
|
+
await cache.write("Fetch", { orders: ctx.orders }, { keepAge: true });
|
|
382
|
+
const age = await cache.ageOf("Fetch");
|
|
383
|
+
},
|
|
384
|
+
})
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Slot names are checked, not stringly-typed. An uncached phase isn't a slot at
|
|
388
|
+
all, and `as` renames a mounted routine's slots along with its phases — so the
|
|
389
|
+
moment you write `.use(pullChannel, { as: "Amazon" })`, every
|
|
390
|
+
`cache.clear("Fetch")` in the script goes red and offers `"Amazon / Fetch"`
|
|
391
|
+
instead. That's the failure a hand-written string can't catch: it would keep
|
|
392
|
+
compiling and silently address nothing.
|
|
393
|
+
|
|
394
|
+
Invalidation flows backwards only — a later step can drop an earlier phase's
|
|
395
|
+
entry, not the reverse.
|
|
396
|
+
|
|
397
|
+
`write` restamps the entry as written *now* unless you pass `keepAge`. Reach
|
|
398
|
+
for it when you are correcting a value rather than refreshing it: restamping
|
|
399
|
+
silently buys another full TTL for data that is exactly as old as it was a
|
|
400
|
+
moment ago, which is the opposite of what you want when the cache is there to
|
|
401
|
+
keep you inside a rate limit.
|
|
402
|
+
|
|
403
|
+
**Values are typed too.** A slot with a `schema` reads back as the schema's
|
|
404
|
+
output, because that is the one thing actually *checked* against the stored
|
|
405
|
+
JSON. Without a schema the phase's own delta stands in, which is convenient and
|
|
406
|
+
true right up until an entry outlives the code that wrote it. For that case
|
|
407
|
+
`read` returns the value behind a guard:
|
|
408
|
+
|
|
409
|
+
```
|
|
410
|
+
CacheShapeError: Read "orders.0.date_fixed" from cache slot "Fetch", but the
|
|
411
|
+
stored value has no such property. The entry was probably written before this
|
|
412
|
+
script's shape changed — drop it with cache.clear("Fetch"), or declare a schema
|
|
413
|
+
on the slot to have mismatches rejected on read.
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
Only reads are trapped; assigning a new property is how you'd patch an entry.
|
|
417
|
+
Missing array indices, `JSON.stringify`, `await` and iteration all behave
|
|
418
|
+
normally. Pass `{ raw: true }` to opt out — do that before putting the value
|
|
419
|
+
into the context, or the guard travels with it into later steps.
|
|
420
|
+
|
|
367
421
|
**Stores** are three methods, so Redis or S3 is a dozen lines:
|
|
368
422
|
|
|
369
423
|
```ts
|
|
@@ -429,6 +483,23 @@ script has actually produced `Ctx` by that point. Dropping a step that needs
|
|
|
429
483
|
`{ user: User }` into a script that has not loaded a user yet is a compile
|
|
430
484
|
error, not a runtime `undefined`.
|
|
431
485
|
|
|
486
|
+
Writing the next step in a chain means restating what the previous one returns.
|
|
487
|
+
`WithStepFor<Step, Rest>` computes that instead — the step's output merged over
|
|
488
|
+
whatever else the context already holds — and nests for longer chains:
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
export const loadRules = stepFor<
|
|
492
|
+
Input,
|
|
493
|
+
WithStepFor<typeof logIntoDb, { conditions: Array<{ name: string }> }>
|
|
494
|
+
>()({
|
|
495
|
+
name: "load rules",
|
|
496
|
+
handler: ({ ctx }) => ({ rules: ctx.conn.query(ctx.conditions) }),
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// longer chains nest, innermost first
|
|
500
|
+
WithStepFor<typeof second, WithStepFor<typeof first, { conditions: string[] }>>
|
|
501
|
+
```
|
|
502
|
+
|
|
432
503
|
## Reusable scripts
|
|
433
504
|
|
|
434
505
|
`routineFor` does for whole phases what `stepFor` does for one step. Declare a
|
|
@@ -541,7 +612,7 @@ fragment someone else's script also mounts.
|
|
|
541
612
|
|
|
542
613
|
## Examples
|
|
543
614
|
|
|
544
|
-
|
|
615
|
+
Ten runnable scripts, each aimed at a different part of the API. Most take a
|
|
545
616
|
flag to switch between the happy path and the interesting one.
|
|
546
617
|
|
|
547
618
|
| | |
|
|
@@ -553,6 +624,7 @@ flag to switch between the happy path and the interesting one.
|
|
|
553
624
|
| [`modular.ts`](examples/modular.ts) | `stepFor` steps living in [`steps/tenancy.ts`](examples/steps/tenancy.ts), shared by two unrelated scripts — the imported rollback compensates in both. `-- --fail` |
|
|
554
625
|
| [`log-placement.ts`](examples/log-placement.ts) | The same script run three times, once per `logPlacement` value, so the difference is visible directly |
|
|
555
626
|
| [`cache.ts`](examples/cache.ts) | A cached `Build` phase and a cached step. Run it twice to watch the second run skip both. `-- --fresh` to rebuild and overwrite |
|
|
627
|
+
| [`invalidate.ts`](examples/invalidate.ts) | `context.cache` from inside a step: correct an entry without refetching, drop one that is beyond saving, and watch the shape guard catch an entry written before the code changed. `-- --patch`, `-- --drop`, `-- --drift` |
|
|
556
628
|
| [`routine.ts`](examples/routine.ts) | One reusable fragment in [`routines/channel.ts`](examples/routines/channel.ts), mounted by a sync script and, months later, a report that maps its own input onto the routine's — and gets the pull from cache. `-- --multi` mounts it twice, one storefront and API key per mount |
|
|
557
629
|
| [`validate.ts`](examples/validate.ts) | The smallest thing that runs: two steps, `rollback: "none"` |
|
|
558
630
|
|
|
@@ -561,6 +633,7 @@ npm run example:checkout -- --ok
|
|
|
561
633
|
npm run example:resilience -- --cancel
|
|
562
634
|
npm run example:intake -- --bad
|
|
563
635
|
npm run example:modular -- --fail
|
|
636
|
+
npm run example:invalidate -- --drift
|
|
564
637
|
npm run example:routine -- --multi
|
|
565
638
|
npm run example:log-placement
|
|
566
639
|
```
|
|
@@ -570,12 +643,42 @@ npm run example:log-placement
|
|
|
570
643
|
```
|
|
571
644
|
npm run build # emit dist/
|
|
572
645
|
npm test # node:test suite
|
|
573
|
-
npm run typecheck # library + examples + tests
|
|
646
|
+
npm run typecheck # library + examples + tests + scripts
|
|
647
|
+
npm run preflight # the release gate (add -- --allow-dirty while working)
|
|
574
648
|
npm run example # the happy path, live
|
|
575
649
|
npm run example:fail
|
|
576
650
|
npm run release # release-it: version, tag, publish
|
|
577
651
|
```
|
|
578
652
|
|
|
653
|
+
## Releasing
|
|
654
|
+
|
|
655
|
+
[`scripts/preflight.ts`](scripts/preflight.ts) is the gate, and it is written
|
|
656
|
+
with this library — so every release exercises phases, tasks, `note`, `clean`,
|
|
657
|
+
`when` and `retry` on real work:
|
|
658
|
+
|
|
659
|
+
```
|
|
660
|
+
› Quality
|
|
661
|
+
✔ typecheck 1.2s
|
|
662
|
+
✔ tests (120 passing in 9 files) 5.1s
|
|
663
|
+
› Package
|
|
664
|
+
✔ build 404ms
|
|
665
|
+
✔ entry point resolves 0ms
|
|
666
|
+
✔ tarball contents (47 files, 66kB) 180ms
|
|
667
|
+
› Registry
|
|
668
|
+
✔ version is unpublished 212ms
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
It checks the working tree is clean, typechecks all four projects separately so
|
|
672
|
+
a failure names the one that broke, runs the suite, then imports `dist/index.js`
|
|
673
|
+
the way a consumer would and asserts the public surface is actually there.
|
|
674
|
+
`npm pack --dry-run` has to contain the entry point, its declarations, LICENSE
|
|
675
|
+
and README — and must not leak `src/`, `test/`, `examples/` or `scripts/`.
|
|
676
|
+
Finally it asks npm whether the version is already published.
|
|
677
|
+
|
|
678
|
+
release-it runs it from `after:bump`, which is the first point at which
|
|
679
|
+
package.json holds the version being released. A failure aborts before anything
|
|
680
|
+
is committed, tagged or published.
|
|
681
|
+
|
|
579
682
|
## TypeScript layout
|
|
580
683
|
|
|
581
684
|
One config per directory, because editors resolve a file's config by finding
|
package/dist/cache.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import type { CacheMode, CacheOptions, CacheSource, CacheStore } from "./types.j
|
|
|
3
3
|
export declare function memoryStore(): CacheStore;
|
|
4
4
|
/**
|
|
5
5
|
* One JSON file, holding every slot that points at it. Several phases may
|
|
6
|
-
* share a path safely.
|
|
6
|
+
* share a path safely, and concurrent writes to one path are serialised.
|
|
7
7
|
*
|
|
8
8
|
* A missing, unreadable or malformed file all mean the same thing — no cache
|
|
9
9
|
* yet — so deleting the file is always a valid way to start over. Values must
|
|
10
10
|
* survive `JSON.stringify`; anything that does not (a `Date`, a class
|
|
11
|
-
* instance) comes back as its JSON shape
|
|
11
|
+
* instance) comes back as its JSON shape.
|
|
12
12
|
*/
|
|
13
13
|
export declare function fileStore(filePath: string): CacheStore;
|
|
14
14
|
/** `cache: someStore` is shorthand for `cache: { store: someStore }`. */
|
|
@@ -30,4 +30,36 @@ export declare function writeCache(cache: CacheOptions, slot: string, value: unk
|
|
|
30
30
|
/** Identifies a phase's entry. Steps hang off their phase to avoid collisions. */
|
|
31
31
|
export declare const phaseSlot: (phase: string) => string;
|
|
32
32
|
export declare const stepSlot: (phase: string, step: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Wrap a value read back from a store so that touching a field it does not
|
|
35
|
+
* have throws {@link CacheShapeError} instead of yielding `undefined`.
|
|
36
|
+
*
|
|
37
|
+
* Only reads are trapped. Assigning a new property is how you'd legitimately
|
|
38
|
+
* patch an entry before writing it back, so it is left alone — the lie is
|
|
39
|
+
* always on the read side, where the type promised something the JSON lacks.
|
|
40
|
+
*
|
|
41
|
+
* Absent array indices pass through too: `orders[9]` on a short list is
|
|
42
|
+
* ordinary JavaScript, not a shape mismatch.
|
|
43
|
+
*/
|
|
44
|
+
export declare function guardShape<T>(value: T, slot: string, path?: string): T;
|
|
45
|
+
/** Which store backs each slot, and whether that slot validates on read. */
|
|
46
|
+
export interface SlotBinding {
|
|
47
|
+
store: CacheStore;
|
|
48
|
+
schema: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build the `cache` handle a handler sees. Slots it does not know about are
|
|
52
|
+
* already unreachable through the types; at runtime they throw rather than
|
|
53
|
+
* silently doing nothing, which is what a plain `store.clear("typo")` does.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createCacheHandle(slots: Map<string, SlotBinding>): {
|
|
56
|
+
read(slot: string, options?: {
|
|
57
|
+
raw?: boolean;
|
|
58
|
+
}): Promise<unknown>;
|
|
59
|
+
write(slot: string, value: unknown, options?: {
|
|
60
|
+
keepAge?: boolean;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
clear(slot: string): Promise<void>;
|
|
63
|
+
ageOf(slot: string): Promise<number | undefined>;
|
|
64
|
+
};
|
|
33
65
|
//# sourceMappingURL=cache.d.ts.map
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EAEX,MAAM,YAAY,CAAC;AAMpB,+EAA+E;AAC/E,wBAAgB,WAAW,IAAI,UAAU,CAWxC;AA2BD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAoEtD;AAgBD,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAMxF;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,GAAG,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,CAAC;AAInB;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,WAAW,CAAC,CAoBtB;AAED,oEAAoE;AACpE,wBAAsB,UAAU,CAC9B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,kFAAkF;AAClF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MAAe,CAAC;AAC1D,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,MAA6B,CAAC;AAqBrF;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,CAAC,CAelE;AAMD,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG;IAClE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAClD,CAoCA"}
|
package/dist/cache.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { CacheShapeError, StepDefinitionError } from "./errors.js";
|
|
3
4
|
/* -------------------------------------------------------------------------- */
|
|
4
5
|
/* Stores */
|
|
5
6
|
/* -------------------------------------------------------------------------- */
|
|
@@ -16,14 +17,31 @@ export function memoryStore() {
|
|
|
16
17
|
},
|
|
17
18
|
};
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* In-process write queues, keyed by resolved path so two `fileStore` calls on
|
|
22
|
+
* the same file share one.
|
|
23
|
+
*
|
|
24
|
+
* Every write is a read-modify-write of the whole file, which is only correct
|
|
25
|
+
* if writes to that file never overlap. They otherwise lose each other's slots
|
|
26
|
+
* and race on the temp file. Cross-process safety is out of scope: two `node`
|
|
27
|
+
* processes writing one cache file can still interleave.
|
|
28
|
+
*/
|
|
29
|
+
const writeQueues = new Map();
|
|
30
|
+
let tempCounter = 0;
|
|
31
|
+
function serialize(key, task) {
|
|
32
|
+
const next = (writeQueues.get(key) ?? Promise.resolve()).then(task, task);
|
|
33
|
+
// A failed write must not poison the writes queued behind it.
|
|
34
|
+
writeQueues.set(key, next.then(() => undefined, () => undefined));
|
|
35
|
+
return next;
|
|
36
|
+
}
|
|
19
37
|
/**
|
|
20
38
|
* One JSON file, holding every slot that points at it. Several phases may
|
|
21
|
-
* share a path safely.
|
|
39
|
+
* share a path safely, and concurrent writes to one path are serialised.
|
|
22
40
|
*
|
|
23
41
|
* A missing, unreadable or malformed file all mean the same thing — no cache
|
|
24
42
|
* yet — so deleting the file is always a valid way to start over. Values must
|
|
25
43
|
* survive `JSON.stringify`; anything that does not (a `Date`, a class
|
|
26
|
-
* instance) comes back as its JSON shape
|
|
44
|
+
* instance) comes back as its JSON shape.
|
|
27
45
|
*/
|
|
28
46
|
export function fileStore(filePath) {
|
|
29
47
|
const target = resolve(filePath);
|
|
@@ -39,29 +57,58 @@ export function fileStore(filePath) {
|
|
|
39
57
|
}
|
|
40
58
|
};
|
|
41
59
|
// Written through a temp file so an interrupted run cannot leave a
|
|
42
|
-
// half-serialised cache behind for the next one to choke on.
|
|
60
|
+
// half-serialised cache behind for the next one to choke on. The temp name
|
|
61
|
+
// carries a counter as well as the pid — the pid alone is shared by every
|
|
62
|
+
// write in the process, which is exactly how concurrent writes used to
|
|
63
|
+
// rename each other's files out from under themselves.
|
|
43
64
|
const writeAll = async (data) => {
|
|
44
65
|
await mkdir(dirname(target), { recursive: true });
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
66
|
+
const payload = `${JSON.stringify(data, null, 2)}\n`;
|
|
67
|
+
const temp = `${target}.${process.pid}.${(tempCounter += 1)}.tmp`;
|
|
68
|
+
try {
|
|
69
|
+
await writeFile(temp, payload, "utf8");
|
|
70
|
+
try {
|
|
71
|
+
await rename(temp, target);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// Windows, antivirus, editors and file watchers can all hold the
|
|
75
|
+
// destination open and refuse the atomic swap. Writing in place gives
|
|
76
|
+
// up atomicity rather than the write.
|
|
77
|
+
const code = error.code;
|
|
78
|
+
if (code !== "EPERM" && code !== "EACCES" && code !== "EBUSY" && code !== "EEXIST") {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
await writeFile(target, payload, "utf8");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await rm(temp, { force: true });
|
|
86
|
+
}
|
|
48
87
|
};
|
|
88
|
+
const update = (mutate) => serialize(target, async () => {
|
|
89
|
+
const data = await readAll();
|
|
90
|
+
if (!mutate(data))
|
|
91
|
+
return;
|
|
92
|
+
await writeAll(data);
|
|
93
|
+
});
|
|
49
94
|
return {
|
|
50
95
|
async read(slot) {
|
|
51
96
|
const entry = (await readAll())[slot];
|
|
52
97
|
return isEntry(entry) ? entry : undefined;
|
|
53
98
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
99
|
+
write(slot, entry) {
|
|
100
|
+
return update((data) => {
|
|
101
|
+
data[slot] = entry;
|
|
102
|
+
return true;
|
|
103
|
+
});
|
|
58
104
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
105
|
+
clear(slot) {
|
|
106
|
+
return update((data) => {
|
|
107
|
+
if (!Object.hasOwn(data, slot))
|
|
108
|
+
return false;
|
|
109
|
+
delete data[slot];
|
|
110
|
+
return true;
|
|
111
|
+
});
|
|
65
112
|
},
|
|
66
113
|
};
|
|
67
114
|
}
|
|
@@ -117,4 +164,88 @@ export async function writeCache(cache, slot, value, mode) {
|
|
|
117
164
|
/** Identifies a phase's entry. Steps hang off their phase to avoid collisions. */
|
|
118
165
|
export const phaseSlot = (phase) => phase;
|
|
119
166
|
export const stepSlot = (phase, step) => `${phase}::${step}`;
|
|
167
|
+
/* -------------------------------------------------------------------------- */
|
|
168
|
+
/* Shape guard */
|
|
169
|
+
/* -------------------------------------------------------------------------- */
|
|
170
|
+
/**
|
|
171
|
+
* Properties every JavaScript runtime reaches for on an arbitrary object.
|
|
172
|
+
* Trapping them breaks `await` (which probes `then`), `JSON.stringify`,
|
|
173
|
+
* `console.log` and template interpolation — so they pass straight through.
|
|
174
|
+
*/
|
|
175
|
+
const PASSTHROUGH = new Set([
|
|
176
|
+
"then",
|
|
177
|
+
"toJSON",
|
|
178
|
+
"constructor",
|
|
179
|
+
"valueOf",
|
|
180
|
+
"toString",
|
|
181
|
+
"inspect",
|
|
182
|
+
"length",
|
|
183
|
+
]);
|
|
184
|
+
/**
|
|
185
|
+
* Wrap a value read back from a store so that touching a field it does not
|
|
186
|
+
* have throws {@link CacheShapeError} instead of yielding `undefined`.
|
|
187
|
+
*
|
|
188
|
+
* Only reads are trapped. Assigning a new property is how you'd legitimately
|
|
189
|
+
* patch an entry before writing it back, so it is left alone — the lie is
|
|
190
|
+
* always on the read side, where the type promised something the JSON lacks.
|
|
191
|
+
*
|
|
192
|
+
* Absent array indices pass through too: `orders[9]` on a short list is
|
|
193
|
+
* ordinary JavaScript, not a shape mismatch.
|
|
194
|
+
*/
|
|
195
|
+
export function guardShape(value, slot, path = "") {
|
|
196
|
+
if (value === null || typeof value !== "object")
|
|
197
|
+
return value;
|
|
198
|
+
return new Proxy(value, {
|
|
199
|
+
get(target, key, receiver) {
|
|
200
|
+
const actual = Reflect.get(target, key, receiver);
|
|
201
|
+
if (typeof key === "symbol" || PASSTHROUGH.has(key))
|
|
202
|
+
return actual;
|
|
203
|
+
const isIndex = Array.isArray(target) && /^(0|[1-9]\d*)$/.test(key);
|
|
204
|
+
const known = Object.hasOwn(target, key) || key in (Object.getPrototypeOf(target) ?? {});
|
|
205
|
+
if (!isIndex && !known)
|
|
206
|
+
throw new CacheShapeError(slot, path ? `${path}.${key}` : key);
|
|
207
|
+
return guardShape(actual, slot, path ? `${path}.${key}` : key);
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Build the `cache` handle a handler sees. Slots it does not know about are
|
|
213
|
+
* already unreachable through the types; at runtime they throw rather than
|
|
214
|
+
* silently doing nothing, which is what a plain `store.clear("typo")` does.
|
|
215
|
+
*/
|
|
216
|
+
export function createCacheHandle(slots) {
|
|
217
|
+
const bindingFor = (slot) => {
|
|
218
|
+
const binding = slots.get(slot);
|
|
219
|
+
if (!binding) {
|
|
220
|
+
const known = [...slots.keys()].map((name) => `"${name}"`).join(", ") || "none";
|
|
221
|
+
throw new StepDefinitionError(slot, `No cached phase named "${slot}" has been declared before this step. Known slots: ${known}.`);
|
|
222
|
+
}
|
|
223
|
+
return binding;
|
|
224
|
+
};
|
|
225
|
+
return {
|
|
226
|
+
async read(slot, options) {
|
|
227
|
+
const binding = bindingFor(slot);
|
|
228
|
+
const entry = await binding.store.read(slot);
|
|
229
|
+
if (!entry)
|
|
230
|
+
return undefined;
|
|
231
|
+
// A slot with a schema was validated on the way in, so its type is
|
|
232
|
+
// already backed by a check; only the inferred kind needs guarding.
|
|
233
|
+
if (options?.raw || binding.schema)
|
|
234
|
+
return entry.value;
|
|
235
|
+
return guardShape(entry.value, slot);
|
|
236
|
+
},
|
|
237
|
+
async write(slot, value, options) {
|
|
238
|
+
const store = bindingFor(slot).store;
|
|
239
|
+
const previous = options?.keepAge ? await store.read(slot) : undefined;
|
|
240
|
+
await store.write(slot, { value, savedAt: previous?.savedAt ?? Date.now() });
|
|
241
|
+
},
|
|
242
|
+
async clear(slot) {
|
|
243
|
+
await bindingFor(slot).store.clear(slot);
|
|
244
|
+
},
|
|
245
|
+
async ageOf(slot) {
|
|
246
|
+
const entry = await bindingFor(slot).store.read(slot);
|
|
247
|
+
return entry ? Math.max(0, Date.now() - entry.savedAt) : undefined;
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
120
251
|
//# sourceMappingURL=cache.js.map
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAUnE,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAEhF,+EAA+E;AAC/E,MAAM,UAAU,WAAW;IACzB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,OAAO;QACL,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAC/B,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACrB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;QACD,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;YACd,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;AAC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CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;YAC9B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;YACrC,MAAM,QAAQ,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACvE,MAAM,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/E,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,IAAI;YACd,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,IAAI;YACd,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtD,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CacheHandle } from "./types.js";
|
|
1
2
|
import type { StepState } from "./state.js";
|
|
2
3
|
import type { Renderer } from "./ui/renderer.js";
|
|
3
4
|
import type { RollbackContext, StepContext } from "./types.js";
|
|
@@ -5,6 +6,8 @@ export interface ContextDeps {
|
|
|
5
6
|
renderer: Renderer;
|
|
6
7
|
step: StepState;
|
|
7
8
|
phaseName: string;
|
|
9
|
+
/** Backs `context.cache`; slots declared before the current step. */
|
|
10
|
+
cache: CacheHandle<Record<string, unknown>>;
|
|
8
11
|
}
|
|
9
12
|
export declare function createStepContext<In, Ctx>(deps: ContextDeps, input: In, ctx: Ctx, signal: AbortSignal, attempt: number): StepContext<In, Ctx>;
|
|
10
13
|
export declare function createRollbackContext<In, Ctx, Out>(deps: ContextDeps, input: In, ctx: Ctx, output: Out, error: unknown, signal: AbortSignal): RollbackContext<In, Ctx, Out>;
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,SAAS,EAAa,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAEV,eAAe,EACf,WAAW,EAGZ,MAAM,YAAY,CAAC;AA6FpB,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAA2B,SAAS,EAAa,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAEV,eAAe,EACf,WAAW,EAGZ,MAAM,YAAY,CAAC;AA6FpB,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC7C;AASD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,GAAG,EACvC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,EAAE,EACT,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,GACd,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CA4BtB;AAED,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAChD,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,EAAE,EACT,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,WAAW,GAClB,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAmB/B"}
|
package/dist/context.js
CHANGED
|
@@ -87,7 +87,7 @@ function annotate(step, renderer, message) {
|
|
|
87
87
|
renderer.refresh();
|
|
88
88
|
}
|
|
89
89
|
export function createStepContext(deps, input, ctx, signal, attempt) {
|
|
90
|
-
const { renderer, step, phaseName } = deps;
|
|
90
|
+
const { renderer, step, phaseName, cache } = deps;
|
|
91
91
|
// `step` is a routing hint: renderers that place logs on the step itself
|
|
92
92
|
// (rather than the scrollback) need to know which one.
|
|
93
93
|
const emit = (level) => (message) => renderer.log({ level, message }, step);
|
|
@@ -96,6 +96,7 @@ export function createStepContext(deps, input, ctx, signal, attempt) {
|
|
|
96
96
|
ctx,
|
|
97
97
|
signal,
|
|
98
98
|
attempt,
|
|
99
|
+
cache,
|
|
99
100
|
phase: phaseName,
|
|
100
101
|
step: step.name,
|
|
101
102
|
log: emit("log"),
|
|
@@ -114,13 +115,14 @@ export function createStepContext(deps, input, ctx, signal, attempt) {
|
|
|
114
115
|
};
|
|
115
116
|
}
|
|
116
117
|
export function createRollbackContext(deps, input, ctx, output, error, signal) {
|
|
117
|
-
const { renderer, step, phaseName } = deps;
|
|
118
|
+
const { renderer, step, phaseName, cache } = deps;
|
|
118
119
|
return {
|
|
119
120
|
input,
|
|
120
121
|
ctx,
|
|
121
122
|
output,
|
|
122
123
|
error,
|
|
123
124
|
signal,
|
|
125
|
+
cache,
|
|
124
126
|
phase: phaseName,
|
|
125
127
|
step: step.name,
|
|
126
128
|
log: (message) => renderer.log({ level: "warn", message }, step),
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAWA,SAAS,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IACpD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,cAAc,CACrB,IAAe,EACf,QAAkB,EAClB,OAA0D;IAE1D,MAAM,GAAG,GAAkB;QACzB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;QACjC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC/D,QAAQ,EAAE,KAAK;KAChB,CAAC;IACF,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC3D,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,CAAC;IAEnB,OAAO;QACL,IAAI,KAAK;YACP,OAAO,GAAG,CAAC,KAAK,CAAC;QACnB,CAAC;QACD,IAAI,KAAK;YACP,OAAO,GAAG,CAAC,KAAK,CAAC;QACnB,CAAC;QACD,MAAM,CAAC,KAAK,EAAE,KAAK;YACjB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAA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AAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;QAC9D,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC;QAClD,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAAiB,EACjB,KAAS,EACT,GAAQ,EACR,MAAW,EACX,KAAc,EACd,MAAmB;IAEnB,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAClD,OAAO;QACL,KAAK;QACL,GAAG;QACH,MAAM;QACN,KAAK;QACL,MAAM;QACN,KAAK;QACL,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC;QAChE,MAAM,CAAC,OAAO;YACZ,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;YAC1B,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;QACpD,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -27,6 +27,20 @@ export declare class DuplicateNameError extends Error {
|
|
|
27
27
|
readonly duplicate: string;
|
|
28
28
|
constructor(kind: "phase" | "step", duplicate: string, message: string);
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A cached value was read for a field it does not have.
|
|
32
|
+
*
|
|
33
|
+
* Without a `schema` a slot's type is inferred from the steps that produce it,
|
|
34
|
+
* which describes *today's* code — while the entry on disk was written by
|
|
35
|
+
* whatever the code looked like when it last ran. This is thrown at the exact
|
|
36
|
+
* property access where those two disagree, rather than letting an `undefined`
|
|
37
|
+
* travel somewhere less obvious.
|
|
38
|
+
*/
|
|
39
|
+
export declare class CacheShapeError extends Error {
|
|
40
|
+
readonly slot: string;
|
|
41
|
+
readonly path: string;
|
|
42
|
+
constructor(slot: string, path: string);
|
|
43
|
+
}
|
|
30
44
|
/** A step's handler threw. `cause` holds whatever it actually threw. */
|
|
31
45
|
export declare class StepFailedError extends Error {
|
|
32
46
|
readonly phase: string;
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,oFAAoF;AACpF,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;gBAE3C,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC;CAgB1D;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMv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C/E,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;gBAEpB,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO;CAOhF;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAK/C"}
|
package/dist/errors.js
CHANGED
|
@@ -46,6 +46,28 @@ export class DuplicateNameError extends Error {
|
|
|
46
46
|
this.duplicate = duplicate;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* A cached value was read for a field it does not have.
|
|
51
|
+
*
|
|
52
|
+
* Without a `schema` a slot's type is inferred from the steps that produce it,
|
|
53
|
+
* which describes *today's* code — while the entry on disk was written by
|
|
54
|
+
* whatever the code looked like when it last ran. This is thrown at the exact
|
|
55
|
+
* property access where those two disagree, rather than letting an `undefined`
|
|
56
|
+
* travel somewhere less obvious.
|
|
57
|
+
*/
|
|
58
|
+
export class CacheShapeError extends Error {
|
|
59
|
+
slot;
|
|
60
|
+
path;
|
|
61
|
+
constructor(slot, path) {
|
|
62
|
+
super(`Read "${path}" from cache slot "${slot}", but the stored value has no such property. ` +
|
|
63
|
+
`The entry was probably written before this script's shape changed — ` +
|
|
64
|
+
`drop it with cache.clear("${slot}"), or declare a schema on the slot to have ` +
|
|
65
|
+
`mismatches rejected on read.`);
|
|
66
|
+
this.name = "CacheShapeError";
|
|
67
|
+
this.slot = slot;
|
|
68
|
+
this.path = path;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
49
71
|
/** A step's handler threw. `cause` holds whatever it actually threw. */
|
|
50
72
|
export class StepFailedError extends Error {
|
|
51
73
|
phase;
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{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,YAAY,kBAAkB;QACnC,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CACxD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { Script, script, stepFor, routineFor, type MountOptions, type Routine, type RunOptions, } from "./script.js";
|
|
1
|
+
export { Script, script, stepFor, routineFor, type CachedPhaseOptions, type ClosedPhase, type Commit, type MountInput, type MountOptions, type Mounted, type OpenPhase, type Routine, type RunOptions, } from "./script.js";
|
|
2
2
|
export { fileStore, memoryStore } from "./cache.js";
|
|
3
|
-
export { DuplicateNameError, RollbackFailedError, SchemaValidationError, ScriptAbortedError, StepDefinitionError, StepFailedError, StepTimeoutError, isAbort, } from "./errors.js";
|
|
4
|
-
export type { Awaitable, CacheMode, CacheOptions, CacheSource, CacheStore, CachedEntry, CleanField, Cleaned, LogPlacement, Merge, PhaseOptions, PhaseStatus, Prettify, ProgressHandle, RetryPolicy, RollbackContext, RollbackData, RollbackReport, RunResult, RunStatus, ScriptOptions, StaleContext, StepContext, StepDef, StepReport, StepStatus, TaskHandle, TaskListHandle, } from "./types.js";
|
|
3
|
+
export { CacheShapeError, DuplicateNameError, RollbackFailedError, SchemaValidationError, ScriptAbortedError, StepDefinitionError, StepFailedError, StepTimeoutError, isAbort, } from "./errors.js";
|
|
4
|
+
export type { Awaitable, CacheHandle, CacheMode, CacheOptions, CacheSource, CacheStore, CachedEntry, CleanField, Cleaned, LogPlacement, Merge, PhaseOptions, PhaseStatus, Prettify, ProgressHandle, RetryPolicy, RollbackContext, RollbackData, RollbackReport, RunResult, RunStatus, ScriptOptions, SlotValue, StaleContext, StepContext, StepDef, StepReport, StepStatus, TaskHandle, TaskListHandle, WithStepFor, } from "./types.js";
|
|
5
5
|
export { formatDuration } from "./state.js";
|
|
6
6
|
export { setColorEnabled, isColorEnabled } from "./ui/ansi.js";
|
|
7
7
|
export { palette, symbols } from "./ui/theme.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,OAAO,GACR,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,eAAe,EACf,YAAY,EACZ,cAAc,EACd,SAAS,EACT,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,UAAU,EACV,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,OAAO,GACR,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,eAAe,EACf,YAAY,EACZ,cAAc,EACd,SAAS,EACT,SAAS,EACT,aAAa,EACb,SAAS,EACT,YAAY,EACZ,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,UAAU,EACV,cAAc,EACd,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Script, script, stepFor, routineFor, } from "./script.js";
|
|
2
2
|
export { fileStore, memoryStore } from "./cache.js";
|
|
3
|
-
export { DuplicateNameError, RollbackFailedError, SchemaValidationError, ScriptAbortedError, StepDefinitionError, StepFailedError, StepTimeoutError, isAbort, } from "./errors.js";
|
|
3
|
+
export { CacheShapeError, DuplicateNameError, RollbackFailedError, SchemaValidationError, ScriptAbortedError, StepDefinitionError, StepFailedError, StepTimeoutError, isAbort, } from "./errors.js";
|
|
4
4
|
export { formatDuration } from "./state.js";
|
|
5
5
|
export { setColorEnabled, isColorEnabled } from "./ui/ansi.js";
|
|
6
6
|
export { palette, symbols } from "./ui/theme.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,UAAU,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,UAAU,GAUX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,OAAO,GACR,MAAM,aAAa,CAAC;AAoCrB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|