@telorun/sdk 0.38.0 → 0.41.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,8 +1,9 @@
1
+ import type { InvokeContext } from "./cancellation.js";
1
2
  import type { ModuleContext } from "./module-context.js";
2
3
  import { type ResourceInstance } from "./resource-instance.js";
3
4
  /** The context a decorator kind composes to dispatch its wrapped target. */
4
5
  export interface DispatchContext {
5
- invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs): Promise<unknown>;
6
+ invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs, ctx?: InvokeContext): Promise<unknown>;
6
7
  readonly moduleContext: ModuleContext;
7
8
  }
8
9
  /**
@@ -12,6 +13,9 @@ export interface DispatchContext {
12
13
  * against the module context. Resolution is eager (fail-fast on a bad ref);
13
14
  * dispatch is deferred, so a caller can run it synchronously (Cache.View) or
14
15
  * detached (Run.Detach). `describe` labels the error with the owning resource.
16
+ * The thunk's optional second argument seeds the dispatch's {@link InvokeContext}
17
+ * (e.g. a decorator-owned cancellation scope); when omitted the ambient
18
+ * invocation context applies unchanged.
15
19
  */
16
- export declare function resolveInvocableDispatcher(field: unknown, ctx: DispatchContext, describe: () => string): (inputs: Record<string, unknown>) => Promise<unknown>;
20
+ export declare function resolveInvocableDispatcher(field: unknown, ctx: DispatchContext, describe: () => string): (inputs: Record<string, unknown>, invokeCtx?: InvokeContext) => Promise<unknown>;
17
21
  //# sourceMappingURL=dispatch-invoke-ref.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-invoke-ref.d.ts","sourceRoot":"","sources":["../src/dispatch-invoke-ref.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,c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17 @@ import { getRefIdentity } from "./resource-instance.js";
6
6
  * against the module context. Resolution is eager (fail-fast on a bad ref);
7
7
  * dispatch is deferred, so a caller can run it synchronously (Cache.View) or
8
8
  * detached (Run.Detach). `describe` labels the error with the owning resource.
9
+ * The thunk's optional second argument seeds the dispatch's {@link InvokeContext}
10
+ * (e.g. a decorator-owned cancellation scope); when omitted the ambient
11
+ * invocation context applies unchanged.
9
12
  */
10
13
  export function resolveInvocableDispatcher(field, ctx, describe) {
11
14
  if (field && typeof field.invoke === "function") {
12
15
  const instance = field;
13
16
  const id = getRefIdentity(field);
14
- return (inputs) => id ? ctx.invokeResolved(id.kind, id.name, instance, inputs) : instance.invoke(inputs);
17
+ return (inputs, invokeCtx) => id
18
+ ? ctx.invokeResolved(id.kind, id.name, instance, inputs, invokeCtx)
19
+ : instance.invoke(inputs, invokeCtx);
15
20
  }
16
21
  const ref = field;
17
22
  if (!ref || typeof ref.name !== "string") {
@@ -23,5 +28,5 @@ export function resolveInvocableDispatcher(field, ctx, describe) {
23
28
  if (!resolved || typeof resolved.invoke !== "function") {
24
29
  throw new Error(`${describe()}: 'invoke' reference '${ref.name}' did not resolve to an invocable.`);
25
30
  }
26
- return (inputs) => ctx.invokeResolved(ref.kind, ref.name, resolved, inputs);
31
+ return (inputs, invokeCtx) => ctx.invokeResolved(ref.kind, ref.name, resolved, inputs, invokeCtx);
27
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/sdk",
3
- "version": "0.38.0",
3
+ "version": "0.41.0",
4
4
  "description": "Telo SDK - Public API for Telo module authors.",
5
5
  "keywords": [
6
6
  "telo",
@@ -1,3 +1,4 @@
1
+ import type { InvokeContext } from "./cancellation.js";
1
2
  import type { Invocable } from "./capabilities/invokable.js";
2
3
  import type { ModuleContext } from "./module-context.js";
3
4
  import { getRefIdentity, type ResourceInstance } from "./resource-instance.js";
@@ -9,6 +10,7 @@ export interface DispatchContext {
9
10
  name: string,
10
11
  instance: ResourceInstance,
11
12
  inputs: TInputs,
13
+ ctx?: InvokeContext,
12
14
  ): Promise<unknown>;
13
15
  readonly moduleContext: ModuleContext;
14
16
  }
@@ -20,17 +22,22 @@ export interface DispatchContext {
20
22
  * against the module context. Resolution is eager (fail-fast on a bad ref);
21
23
  * dispatch is deferred, so a caller can run it synchronously (Cache.View) or
22
24
  * detached (Run.Detach). `describe` labels the error with the owning resource.
25
+ * The thunk's optional second argument seeds the dispatch's {@link InvokeContext}
26
+ * (e.g. a decorator-owned cancellation scope); when omitted the ambient
27
+ * invocation context applies unchanged.
23
28
  */
24
29
  export function resolveInvocableDispatcher(
25
30
  field: unknown,
26
31
  ctx: DispatchContext,
27
32
  describe: () => string,
28
- ): (inputs: Record<string, unknown>) => Promise<unknown> {
33
+ ): (inputs: Record<string, unknown>, invokeCtx?: InvokeContext) => Promise<unknown> {
29
34
  if (field && typeof (field as Invocable).invoke === "function") {
30
35
  const instance = field as ResourceInstance & Invocable;
31
36
  const id = getRefIdentity(field as object);
32
- return (inputs) =>
33
- id ? ctx.invokeResolved(id.kind, id.name, instance, inputs) : instance.invoke(inputs);
37
+ return (inputs, invokeCtx) =>
38
+ id
39
+ ? ctx.invokeResolved(id.kind, id.name, instance, inputs, invokeCtx)
40
+ : instance.invoke(inputs, invokeCtx);
34
41
  }
35
42
  const ref = field as { kind: string; name: string; alias?: string } | undefined;
36
43
  if (!ref || typeof ref.name !== "string") {
@@ -44,5 +51,5 @@ export function resolveInvocableDispatcher(
44
51
  if (!resolved || typeof resolved.invoke !== "function") {
45
52
  throw new Error(`${describe()}: 'invoke' reference '${ref.name}' did not resolve to an invocable.`);
46
53
  }
47
- return (inputs) => ctx.invokeResolved(ref.kind, ref.name, resolved, inputs);
54
+ return (inputs, invokeCtx) => ctx.invokeResolved(ref.kind, ref.name, resolved, inputs, invokeCtx);
48
55
  }