@telorun/sdk 0.80.0 → 0.82.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.
@@ -1,11 +1,19 @@
1
1
  import type { InvokeContext } from "../cancellation.js";
2
+ import type { EffectChain } from "../effect.js";
2
3
  export interface Runnable {
3
4
  /**
5
+ * Perform the resource's work, RETURNING the effects it leaves behind.
6
+ *
7
+ * A one-shot task that allocates nothing returns nothing. A service returns
8
+ * the chain that opened its socket and took its kernel hold, and the runtime
9
+ * unwinds it — at teardown, or immediately if a later step of the same `run()`
10
+ * fails. There is no `teardown()` to keep in step with it.
11
+ *
4
12
  * @param ctx Out-of-band per-run context carrying the cancellation token.
5
13
  * Optional — runnables that ignore it keep working unchanged. Long-lived
6
14
  * targets (servers, loops) observe `ctx.cancellation` to stop early when the
7
15
  * boot run is cancelled (e.g. SIGINT).
8
16
  */
9
- run(ctx?: InvokeContext): Promise<void>;
17
+ run(ctx?: InvokeContext): Promise<EffectChain<unknown> | void> | EffectChain<unknown> | void;
10
18
  }
11
19
  //# sourceMappingURL=runnable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runnable.d.ts","sourceRoot":"","sources":["../../src/capabilities/runnable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,GAAG,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC"}
1
+ {"version":3,"file":"runnable.d.ts","sourceRoot":"","sources":["../../src/capabilities/runnable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC9F"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Revertible effects — the module-author half of the lifecycle.
3
+ *
4
+ * An effect is a forward action paired with the inverse that undoes it.
5
+ * `init()` and `run()` RETURN the effects they perform, as a chain built with
6
+ * `ctx.effect(...)`, and the runtime executes it, keeps the inverses per
7
+ * lifecycle entry, and unwinds them last-in-first-out. There is no `teardown()`:
8
+ * the signature is what stops "what undoes this" from being forgotten, which an
9
+ * optional second method never did.
10
+ *
11
+ * Normative contract: `kernel/specs/revertible-effects.md`.
12
+ */
13
+ /**
14
+ * An action's undo. Runs when its frame unwinds, or early via
15
+ * {@link EffectHandle.dispose}.
16
+ *
17
+ * Returns `unknown` rather than `void`: the runtime awaits whatever it gets and
18
+ * ignores it, and a great many disposal calls return something incidental
19
+ * (`client.quit()` → `"OK"`). Requiring `void` would have every author wrap a
20
+ * one-line inverse in a block for no gain.
21
+ */
22
+ export type Inverse = () => unknown;
23
+ /**
24
+ * What a forward action produces: its value, and what undoes it.
25
+ *
26
+ * `inverse` is OPTIONAL, and omitting it is a statement rather than a shortcut:
27
+ * this step allocated nothing that outlives a failure. A chain is also the
28
+ * sequencing structure for lifecycle work — a step that must run after the one
29
+ * before it — so a step with genuinely nothing to undo is a normal shape, and
30
+ * forcing `() => {}` would make "nothing to undo" indistinguishable from "the
31
+ * author forgot the undo", which is the one thing this mechanism exists to tell
32
+ * apart.
33
+ */
34
+ export interface EffectOutcome<T> {
35
+ result: T;
36
+ inverse?: Inverse;
37
+ }
38
+ /**
39
+ * The forward action, given the previous step's result.
40
+ *
41
+ * Either form is accepted, and the single-outcome case is the degenerate
42
+ * iterator. Reach for the generator when one step allocates several things that
43
+ * can fail between them: each `yield` registers that allocation's inverse the
44
+ * moment it completed, so a body that throws halfway — or is stopped by a
45
+ * teardown at a step boundary — recovers exactly what it did.
46
+ */
47
+ export type EffectBody<TIn, TOut> = ((input: TIn) => Promise<EffectOutcome<TOut>>) | ((input: TIn) => AsyncGenerator<Inverse, TOut, void>);
48
+ /**
49
+ * A lazy, ordered description of the effects a lifecycle entry performs.
50
+ *
51
+ * **Lazy**: nothing runs until the runtime executes what `init()` / `run()`
52
+ * returned, so sequencing and recovery belong to the runtime rather than to each
53
+ * controller — and the chain stays a description, which is what a second runtime
54
+ * can execute rather than reimplement.
55
+ *
56
+ * **Deliberately not a thenable**: an `async` function unwraps a promise-like on
57
+ * the way out, so a thenable chain returned from `async init()` would reach the
58
+ * runtime as its last step's *result*. Keeping it plain means `async init()`
59
+ * works and a controller may `await` freely before returning the chain.
60
+ *
61
+ * A chain is a value, so branches and loops build it like any other:
62
+ *
63
+ * ```ts
64
+ * let chain = ctx.effect("core", …);
65
+ * if (resource.cors) chain = chain.effect("cors", …);
66
+ * for (const mount of mounts) chain = chain.effect(`mount ${mount.path}`, …);
67
+ * return chain;
68
+ * ```
69
+ */
70
+ export interface EffectChain<T> {
71
+ /** Extend the chain. `body` receives the previous step's result — which is how
72
+ * an inverse gets the handle it has to close, without a field on the instance
73
+ * existing only to carry it between the two halves. */
74
+ effect<TNext>(reason: string, body: EffectBody<T, TNext>): EffectChain<TNext>;
75
+ /**
76
+ * Execute the chain NOW against the resource's current frame, instead of
77
+ * returning it for the runtime to execute.
78
+ *
79
+ * The imperative door, and the one spelling for an allocation whose lifetime
80
+ * is an *operation* rather than the resource: `Durable.Workflow` takes a hold
81
+ * inside `invoke()` and releases it when the run settles or parks, which no
82
+ * returned chain can express because `invoke` returns the caller's value.
83
+ * Explicit rather than implicit (a thenable) — laziness is the property the
84
+ * returned form rests on, and a chain that ran when awaited would make "did
85
+ * this execute?" depend on whether someone happened to await it.
86
+ */
87
+ perform(): Promise<EffectResult<T>>;
88
+ }
89
+ export interface EffectHandle {
90
+ /**
91
+ * Run this effect's inverse now and take it off its frame — for an allocation
92
+ * whose lifetime is an *operation* rather than the resource (a hold taken per
93
+ * durable run, released when the run settles or parks).
94
+ *
95
+ * Idempotent, and a disposed effect is skipped when the frame unwinds. Order
96
+ * is unconstrained: a frame is a recovery order, not a dependency graph, so
97
+ * disposing something a later effect still depends on is the author's error —
98
+ * the runtime cannot see inside an inverse, and cascading would defeat the
99
+ * case early disposal exists for.
100
+ */
101
+ dispose(): Promise<void>;
102
+ }
103
+ /** What an imperative `ctx.effect(...)` awaits to: the value, plus the way to
104
+ * end that one allocation early. */
105
+ export interface EffectResult<T> extends EffectHandle {
106
+ readonly result: T;
107
+ }
108
+ //# sourceMappingURL=effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC;AAEpC;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC;IACV,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CAAC,GAAG,EAAE,IAAI,IAC5B,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,GAC9C,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B;;4DAEwD;IACxD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAC9E;;;;;;;;;;;OAWG;IACH,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;OAUG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;qCACqC;AACrC,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,YAAY;IACnD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACpB"}
package/dist/effect.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Revertible effects — the module-author half of the lifecycle.
3
+ *
4
+ * An effect is a forward action paired with the inverse that undoes it.
5
+ * `init()` and `run()` RETURN the effects they perform, as a chain built with
6
+ * `ctx.effect(...)`, and the runtime executes it, keeps the inverses per
7
+ * lifecycle entry, and unwinds them last-in-first-out. There is no `teardown()`:
8
+ * the signature is what stops "what undoes this" from being forgotten, which an
9
+ * optional second method never did.
10
+ *
11
+ * Normative contract: `kernel/specs/revertible-effects.md`.
12
+ */
13
+ export {};
@@ -128,6 +128,9 @@ export interface EvaluationContext {
128
128
  hasManifest(name: string): boolean;
129
129
  registerManifest(resource: ResourceManifest): void;
130
130
  spawnChild<T extends EvaluationContext>(child: T): T;
131
+ /** The inverse of {@link spawnChild}, for a child whose owner is being
132
+ * discarded rather than torn down in place. */
133
+ detachChild(child: EvaluationContext): void;
131
134
  /** Spawn a fresh child context attached to this one — the isolated scope a
132
135
  * templated definition registers its `resources:` into. Rooted here so child
133
136
  * kinds/refs resolve against THIS context's imports (the defining library),
@@ -1 +1 @@
1
- {"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAA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AAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,OAAO,EACf,GAAG,CAAC,EAAE,aAAa,GAClB,OAAO,CAAC,GAAG,CAAC,CAAC;IAChB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpF;;6DAEyD;IACzD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAChC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAC3E;gFAC4E;IAC5E,SAAS,CACP,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,WAAW,CACT,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,MAAM,EAAE,EACf,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5B"}
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from "./controller-context.js";
17
17
  export * from "./controller-policy.js";
18
18
  export * from "./evaluation-context.js";
19
19
  export * from "./module-context.js";
20
+ export * from "./effect.js";
20
21
  export * from "./resource-context.js";
21
22
  export * from "./resource-instance.js";
22
23
  export * from "./resource-manifest.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ export * from "./controller-context.js";
17
17
  export * from "./controller-policy.js";
18
18
  export * from "./evaluation-context.js";
19
19
  export * from "./module-context.js";
20
+ export * from "./effect.js";
20
21
  export * from "./resource-context.js";
21
22
  export * from "./resource-instance.js";
22
23
  export * from "./resource-manifest.js";
@@ -1,4 +1,5 @@
1
1
  import type { CancellationSource, InvokeContext, OpenSpan, OpenSpanOptions, ZoneEntry } from "./cancellation.js";
2
+ import type { EffectBody, EffectChain } from "./effect.js";
2
3
  import type { ResourceHandle } from "./resource-instance.js";
3
4
  import { ControllerContext } from "./controller-context.js";
4
5
  import type { Logger } from "./logger.js";
@@ -70,6 +71,42 @@ export interface ResourceContext extends ControllerContext {
70
71
  * registers them into, so two instances of the same templated kind don't
71
72
  * collide and the children nest under their parent in a debug view. */
72
73
  readonly ownerPrefix: string;
74
+ /**
75
+ * Describe a revertible action: `body` does the work and yields the inverse
76
+ * that undoes it. Returns a LAZY chain — `.effect(...)` extends it, threading
77
+ * each step's result into the next.
78
+ *
79
+ * Return the chain from `init()` / `run()`: the runtime executes it and keeps
80
+ * the inverses on that lifecycle entry's frame, unwinding them newest-first
81
+ * when the resource is torn down or when a later step fails. That is the whole
82
+ * of a controller's cleanup — there is no `teardown()`.
83
+ *
84
+ * Call `.perform()` instead when the allocation belongs to an *operation*
85
+ * rather than to the resource (a hold taken per durable run, released when the
86
+ * run settles or parks): it executes against the resource's current frame and
87
+ * hands back a {@link EffectResult} whose `dispose()` ends that one allocation.
88
+ * Such an effect MUST be disposed when its operation ends, or it accumulates
89
+ * for the resource's lifetime.
90
+ *
91
+ * `reason` names the effect in recovery diagnostics.
92
+ */
93
+ effect<T>(reason: string, body: EffectBody<void, T>): EffectChain<T>;
94
+ /**
95
+ * Hold the kernel open (a listening server, a run in flight); the returned
96
+ * closure releases it.
97
+ *
98
+ * The closure is a bare inverse and is NOT registered for you — which frame
99
+ * owns a hold is a fact only the caller has. Place it in a chain:
100
+ *
101
+ * ```ts
102
+ * ctx.effect("kernel hold", async () => ({ result: undefined, inverse: ctx.acquireHold() }))
103
+ * ```
104
+ *
105
+ * A hold whose lifetime is one *operation* rather than the resource (one per
106
+ * durable run, taken inside `invoke()`) is performed instead and disposed when
107
+ * that operation ends. A hold that is neither placed nor released keeps the
108
+ * process alive.
109
+ */
73
110
  acquireHold(reason?: string): () => void;
74
111
  /**
75
112
  * Report this resource's **observed state** — what it has learned while
@@ -1 +1 @@
1
- {"version":3,"file":"resource-context.d.ts","sourceRoot":"","sources":["../src/resource-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,WAAW,WAAW;IAC1B;gFAC4E;IAC5E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;4EAGwE;IACxE,cAAc,CAA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,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CACxC"}
@@ -1,10 +1,22 @@
1
1
  import type { Invocable } from "./capabilities/invokable.js";
2
2
  import type { Provider } from "./capabilities/provider.js";
3
3
  import type { Runnable } from "./capabilities/runnable.js";
4
+ import type { EffectChain } from "./effect.js";
4
5
  import type { ResourceContext } from "./resource-context.js";
5
6
  export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<Invocable<TInput, TOutput>> & Partial<Runnable> & Partial<Provider<TOutput>> & {
6
- init?(ctx?: ResourceContext): Promise<void>;
7
- teardown?(): void | Promise<void>;
7
+ /**
8
+ * Build the resource, RETURNING the effects that built it.
9
+ *
10
+ * The chain is what undoes this — the runtime executes it, keeps the
11
+ * inverses, and unwinds them when the resource is torn down or when a later
12
+ * step of `init()` itself fails. Returning nothing is legal only for a
13
+ * resource that allocates nothing; there is no `teardown()`, so an
14
+ * allocation with no inverse is one nothing will ever reclaim.
15
+ *
16
+ * The chain is lazy and is not a thenable, so `async init()` may `await`
17
+ * whatever it needs before returning it.
18
+ */
19
+ init?(ctx: ResourceContext): EffectChain<unknown> | void | Promise<EffectChain<unknown> | void>;
8
20
  snapshot?(): Record<string, any> | Promise<Record<string, any>>;
9
21
  /**
10
22
  * Teardown ordering hint. Instances tear down in ascending priority — a
@@ -1 +1 @@
1
- {"version":3,"file":"resource-instance.d.ts","sourceRoot":"","sources":["../src/resource-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,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1
1
  {
2
2
  "name": "@telorun/sdk",
3
- "version": "0.80.0",
3
+ "version": "0.82.0",
4
4
  "description": "Telo SDK - Public API for Telo module authors.",
5
5
  "keywords": [
6
6
  "telo",
@@ -1,11 +1,19 @@
1
1
  import type { InvokeContext } from "../cancellation.js";
2
+ import type { EffectChain } from "../effect.js";
2
3
 
3
4
  export interface Runnable {
4
5
  /**
6
+ * Perform the resource's work, RETURNING the effects it leaves behind.
7
+ *
8
+ * A one-shot task that allocates nothing returns nothing. A service returns
9
+ * the chain that opened its socket and took its kernel hold, and the runtime
10
+ * unwinds it — at teardown, or immediately if a later step of the same `run()`
11
+ * fails. There is no `teardown()` to keep in step with it.
12
+ *
5
13
  * @param ctx Out-of-band per-run context carrying the cancellation token.
6
14
  * Optional — runnables that ignore it keep working unchanged. Long-lived
7
15
  * targets (servers, loops) observe `ctx.cancellation` to stop early when the
8
16
  * boot run is cancelled (e.g. SIGINT).
9
17
  */
10
- run(ctx?: InvokeContext): Promise<void>;
18
+ run(ctx?: InvokeContext): Promise<EffectChain<unknown> | void> | EffectChain<unknown> | void;
11
19
  }
package/src/effect.ts ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Revertible effects — the module-author half of the lifecycle.
3
+ *
4
+ * An effect is a forward action paired with the inverse that undoes it.
5
+ * `init()` and `run()` RETURN the effects they perform, as a chain built with
6
+ * `ctx.effect(...)`, and the runtime executes it, keeps the inverses per
7
+ * lifecycle entry, and unwinds them last-in-first-out. There is no `teardown()`:
8
+ * the signature is what stops "what undoes this" from being forgotten, which an
9
+ * optional second method never did.
10
+ *
11
+ * Normative contract: `kernel/specs/revertible-effects.md`.
12
+ */
13
+
14
+ /**
15
+ * An action's undo. Runs when its frame unwinds, or early via
16
+ * {@link EffectHandle.dispose}.
17
+ *
18
+ * Returns `unknown` rather than `void`: the runtime awaits whatever it gets and
19
+ * ignores it, and a great many disposal calls return something incidental
20
+ * (`client.quit()` → `"OK"`). Requiring `void` would have every author wrap a
21
+ * one-line inverse in a block for no gain.
22
+ */
23
+ export type Inverse = () => unknown;
24
+
25
+ /**
26
+ * What a forward action produces: its value, and what undoes it.
27
+ *
28
+ * `inverse` is OPTIONAL, and omitting it is a statement rather than a shortcut:
29
+ * this step allocated nothing that outlives a failure. A chain is also the
30
+ * sequencing structure for lifecycle work — a step that must run after the one
31
+ * before it — so a step with genuinely nothing to undo is a normal shape, and
32
+ * forcing `() => {}` would make "nothing to undo" indistinguishable from "the
33
+ * author forgot the undo", which is the one thing this mechanism exists to tell
34
+ * apart.
35
+ */
36
+ export interface EffectOutcome<T> {
37
+ result: T;
38
+ inverse?: Inverse;
39
+ }
40
+
41
+ /**
42
+ * The forward action, given the previous step's result.
43
+ *
44
+ * Either form is accepted, and the single-outcome case is the degenerate
45
+ * iterator. Reach for the generator when one step allocates several things that
46
+ * can fail between them: each `yield` registers that allocation's inverse the
47
+ * moment it completed, so a body that throws halfway — or is stopped by a
48
+ * teardown at a step boundary — recovers exactly what it did.
49
+ */
50
+ export type EffectBody<TIn, TOut> =
51
+ | ((input: TIn) => Promise<EffectOutcome<TOut>>)
52
+ | ((input: TIn) => AsyncGenerator<Inverse, TOut, void>);
53
+
54
+ /**
55
+ * A lazy, ordered description of the effects a lifecycle entry performs.
56
+ *
57
+ * **Lazy**: nothing runs until the runtime executes what `init()` / `run()`
58
+ * returned, so sequencing and recovery belong to the runtime rather than to each
59
+ * controller — and the chain stays a description, which is what a second runtime
60
+ * can execute rather than reimplement.
61
+ *
62
+ * **Deliberately not a thenable**: an `async` function unwraps a promise-like on
63
+ * the way out, so a thenable chain returned from `async init()` would reach the
64
+ * runtime as its last step's *result*. Keeping it plain means `async init()`
65
+ * works and a controller may `await` freely before returning the chain.
66
+ *
67
+ * A chain is a value, so branches and loops build it like any other:
68
+ *
69
+ * ```ts
70
+ * let chain = ctx.effect("core", …);
71
+ * if (resource.cors) chain = chain.effect("cors", …);
72
+ * for (const mount of mounts) chain = chain.effect(`mount ${mount.path}`, …);
73
+ * return chain;
74
+ * ```
75
+ */
76
+ export interface EffectChain<T> {
77
+ /** Extend the chain. `body` receives the previous step's result — which is how
78
+ * an inverse gets the handle it has to close, without a field on the instance
79
+ * existing only to carry it between the two halves. */
80
+ effect<TNext>(reason: string, body: EffectBody<T, TNext>): EffectChain<TNext>;
81
+ /**
82
+ * Execute the chain NOW against the resource's current frame, instead of
83
+ * returning it for the runtime to execute.
84
+ *
85
+ * The imperative door, and the one spelling for an allocation whose lifetime
86
+ * is an *operation* rather than the resource: `Durable.Workflow` takes a hold
87
+ * inside `invoke()` and releases it when the run settles or parks, which no
88
+ * returned chain can express because `invoke` returns the caller's value.
89
+ * Explicit rather than implicit (a thenable) — laziness is the property the
90
+ * returned form rests on, and a chain that ran when awaited would make "did
91
+ * this execute?" depend on whether someone happened to await it.
92
+ */
93
+ perform(): Promise<EffectResult<T>>;
94
+ }
95
+
96
+ export interface EffectHandle {
97
+ /**
98
+ * Run this effect's inverse now and take it off its frame — for an allocation
99
+ * whose lifetime is an *operation* rather than the resource (a hold taken per
100
+ * durable run, released when the run settles or parks).
101
+ *
102
+ * Idempotent, and a disposed effect is skipped when the frame unwinds. Order
103
+ * is unconstrained: a frame is a recovery order, not a dependency graph, so
104
+ * disposing something a later effect still depends on is the author's error —
105
+ * the runtime cannot see inside an inverse, and cascading would defeat the
106
+ * case early disposal exists for.
107
+ */
108
+ dispose(): Promise<void>;
109
+ }
110
+
111
+ /** What an imperative `ctx.effect(...)` awaits to: the value, plus the way to
112
+ * end that one allocation early. */
113
+ export interface EffectResult<T> extends EffectHandle {
114
+ readonly result: T;
115
+ }
@@ -162,6 +162,9 @@ export interface EvaluationContext {
162
162
  hasManifest(name: string): boolean;
163
163
  registerManifest(resource: ResourceManifest): void;
164
164
  spawnChild<T extends EvaluationContext>(child: T): T;
165
+ /** The inverse of {@link spawnChild}, for a child whose owner is being
166
+ * discarded rather than torn down in place. */
167
+ detachChild(child: EvaluationContext): void;
165
168
  /** Spawn a fresh child context attached to this one — the isolated scope a
166
169
  * templated definition registers its `resources:` into. Rooted here so child
167
170
  * kinds/refs resolve against THIS context's imports (the defining library),
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export * from "./controller-context.js";
17
17
  export * from "./controller-policy.js";
18
18
  export * from "./evaluation-context.js";
19
19
  export * from "./module-context.js";
20
+ export * from "./effect.js";
20
21
  export * from "./resource-context.js";
21
22
  export * from "./resource-instance.js";
22
23
  export * from "./resource-manifest.js";
@@ -5,6 +5,7 @@ import type {
5
5
  OpenSpanOptions,
6
6
  ZoneEntry,
7
7
  } from "./cancellation.js";
8
+ import type { EffectBody, EffectChain } from "./effect.js";
8
9
  import type { ResourceHandle } from "./resource-instance.js";
9
10
  import { ControllerContext } from "./controller-context.js";
10
11
  import type { Logger } from "./logger.js";
@@ -86,6 +87,42 @@ export interface ResourceContext extends ControllerContext {
86
87
  * registers them into, so two instances of the same templated kind don't
87
88
  * collide and the children nest under their parent in a debug view. */
88
89
  readonly ownerPrefix: string;
90
+ /**
91
+ * Describe a revertible action: `body` does the work and yields the inverse
92
+ * that undoes it. Returns a LAZY chain — `.effect(...)` extends it, threading
93
+ * each step's result into the next.
94
+ *
95
+ * Return the chain from `init()` / `run()`: the runtime executes it and keeps
96
+ * the inverses on that lifecycle entry's frame, unwinding them newest-first
97
+ * when the resource is torn down or when a later step fails. That is the whole
98
+ * of a controller's cleanup — there is no `teardown()`.
99
+ *
100
+ * Call `.perform()` instead when the allocation belongs to an *operation*
101
+ * rather than to the resource (a hold taken per durable run, released when the
102
+ * run settles or parks): it executes against the resource's current frame and
103
+ * hands back a {@link EffectResult} whose `dispose()` ends that one allocation.
104
+ * Such an effect MUST be disposed when its operation ends, or it accumulates
105
+ * for the resource's lifetime.
106
+ *
107
+ * `reason` names the effect in recovery diagnostics.
108
+ */
109
+ effect<T>(reason: string, body: EffectBody<void, T>): EffectChain<T>;
110
+ /**
111
+ * Hold the kernel open (a listening server, a run in flight); the returned
112
+ * closure releases it.
113
+ *
114
+ * The closure is a bare inverse and is NOT registered for you — which frame
115
+ * owns a hold is a fact only the caller has. Place it in a chain:
116
+ *
117
+ * ```ts
118
+ * ctx.effect("kernel hold", async () => ({ result: undefined, inverse: ctx.acquireHold() }))
119
+ * ```
120
+ *
121
+ * A hold whose lifetime is one *operation* rather than the resource (one per
122
+ * durable run, taken inside `invoke()`) is performed instead and disposed when
123
+ * that operation ends. A hold that is neither placed nor released keeps the
124
+ * process alive.
125
+ */
89
126
  acquireHold(reason?: string): () => void;
90
127
  /**
91
128
  * Report this resource's **observed state** — what it has learned while
@@ -1,6 +1,7 @@
1
1
  import type { Invocable } from "./capabilities/invokable.js";
2
2
  import type { Provider } from "./capabilities/provider.js";
3
3
  import type { Runnable } from "./capabilities/runnable.js";
4
+ import type { EffectChain } from "./effect.js";
4
5
  import type { ResourceContext } from "./resource-context.js";
5
6
 
6
7
  export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<
@@ -8,8 +9,19 @@ export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Part
8
9
  > &
9
10
  Partial<Runnable> &
10
11
  Partial<Provider<TOutput>> & {
11
- init?(ctx?: ResourceContext): Promise<void>;
12
- teardown?(): void | Promise<void>;
12
+ /**
13
+ * Build the resource, RETURNING the effects that built it.
14
+ *
15
+ * The chain is what undoes this — the runtime executes it, keeps the
16
+ * inverses, and unwinds them when the resource is torn down or when a later
17
+ * step of `init()` itself fails. Returning nothing is legal only for a
18
+ * resource that allocates nothing; there is no `teardown()`, so an
19
+ * allocation with no inverse is one nothing will ever reclaim.
20
+ *
21
+ * The chain is lazy and is not a thenable, so `async init()` may `await`
22
+ * whatever it needs before returning it.
23
+ */
24
+ init?(ctx: ResourceContext): EffectChain<unknown> | void | Promise<EffectChain<unknown> | void>;
13
25
  snapshot?(): Record<string, any> | Promise<Record<string, any>>;
14
26
  /**
15
27
  * Teardown ordering hint. Instances tear down in ascending priority — a