@telorun/sdk 0.11.1 → 0.13.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/LICENSE +2 -2
- package/README.md +0 -10
- package/dist/capabilities/provider.d.ts +2 -2
- package/dist/capabilities/provider.d.ts.map +1 -1
- package/dist/capability-definition.d.ts +8 -0
- package/dist/capability-definition.d.ts.map +1 -0
- package/dist/capability-definition.js +21 -0
- package/dist/cel-environment.d.ts +3 -0
- package/dist/cel-environment.d.ts.map +1 -0
- package/dist/cel-environment.js +13 -0
- package/dist/evaluation-context.d.ts +4 -2
- package/dist/evaluation-context.d.ts.map +1 -1
- package/dist/execution-context.d.ts +13 -0
- package/dist/execution-context.d.ts.map +1 -0
- package/dist/execution-context.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/invoke-step.d.ts +78 -0
- package/dist/invoke-step.d.ts.map +1 -0
- package/dist/invoke-step.js +38 -0
- package/dist/module-context.d.ts +12 -1
- package/dist/module-context.d.ts.map +1 -1
- package/dist/ref.d.ts +11 -3
- package/dist/ref.d.ts.map +1 -1
- package/dist/resource-instance.d.ts +2 -1
- package/dist/resource-instance.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/provider.ts +2 -2
- package/src/index.ts +1 -0
- package/src/invoke-step.ts +105 -0
- package/src/module-context.ts +2 -1
- package/src/resource-instance.ts +3 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SUSTAINABLE USE LICENSE (Fair-code)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026
|
|
3
|
+
Copyright (c) 2026 CodeNet Sp. z o.o.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and distribute the Software for any purpose—including commercial purposes—subject to the following conditions:
|
|
6
6
|
|
|
@@ -14,4 +14,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
14
14
|
|
|
15
15
|
5. DISCLAIMER: The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
|
|
16
16
|
|
|
17
|
-
For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact
|
|
17
|
+
For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact <contact@codenet.pl>.
|
package/README.md
CHANGED
|
@@ -8,10 +8,6 @@ The Node.js SDK provides the authoring surface for Telo modules. It defines the
|
|
|
8
8
|
- **Context types** for accessing the kernel, registry, and events.
|
|
9
9
|
- **Shared primitives** used by Telo modules and tooling.
|
|
10
10
|
|
|
11
|
-
## Status
|
|
12
|
-
|
|
13
|
-
Early prototype. APIs and contracts are still evolving. The API surface - including YAML shapes - may change at any time without notice.
|
|
14
|
-
|
|
15
11
|
## When to Use It
|
|
16
12
|
|
|
17
13
|
Use the SDK when building or extending Telo modules. It is not the kernel itself; it is the contract layer that keeps module behavior consistent and predictable.
|
|
@@ -69,9 +65,3 @@ throws:
|
|
|
69
65
|
```
|
|
70
66
|
|
|
71
67
|
`inherit` is driven by the analyzer's dataflow pass over `x-telo-step-context` arrays; future composers opt in by declaring both the annotation and `inherit: true`. See [modules/run/docs/structured-errors.md](../../modules/run/docs/structured-errors.md) for the end-to-end flow.
|
|
72
|
-
|
|
73
|
-
## Related Docs
|
|
74
|
-
|
|
75
|
-
- Kernel overview: [kernel/README.md](../../kernel/README.md)
|
|
76
|
-
- Built‑in modules: [modules/](../../modules/)
|
|
77
|
-
- SDKs index: [sdk/README.md](../README.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/capabilities/provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/capabilities/provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ,CAAC,OAAO,GAAG,OAAO;IACzC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CapabilityDefinition } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Factory that wires the declarative `expand` config on a CapabilityDefinition
|
|
4
|
+
* into the `onManifest` and `onInvoke` lifecycle hooks. The kernel only ever
|
|
5
|
+
* calls these hooks — it has no knowledge of the `expand` config.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCapability(def: CapabilityDefinition): CapabilityDefinition;
|
|
8
|
+
//# sourceMappingURL=capability-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability-definition.d.ts","sourceRoot":"","sources":["../src/capability-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGvD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,oBAAoB,GAAG,oBAAoB,CAwBhF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory that wires the declarative `expand` config on a CapabilityDefinition
|
|
3
|
+
* into the `onManifest` and `onInvoke` lifecycle hooks. The kernel only ever
|
|
4
|
+
* calls these hooks — it has no knowledge of the `expand` config.
|
|
5
|
+
*/
|
|
6
|
+
export function createCapability(def) {
|
|
7
|
+
const compile = def.expand?.compile ?? [];
|
|
8
|
+
const runtime = def.expand?.runtime ?? [];
|
|
9
|
+
return {
|
|
10
|
+
...def,
|
|
11
|
+
onManifest: compile.length
|
|
12
|
+
? (manifest, ctx) => ctx.expandPaths(manifest, compile, runtime)
|
|
13
|
+
: def.onManifest,
|
|
14
|
+
onInvoke: runtime.length
|
|
15
|
+
? async (instance, inputs, ctx) => {
|
|
16
|
+
const expanded = ctx.moduleContext.expandPaths(inputs, runtime);
|
|
17
|
+
return instance.invoke(expanded);
|
|
18
|
+
}
|
|
19
|
+
: def.onInvoke,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cel-environment.d.ts","sourceRoot":"","sources":["../src/cel-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,eAAO,MAAM,cAAc,aAWvB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Environment } from "@marcbachmann/cel-js";
|
|
2
|
+
export const celEnvironment = new Environment({ unlistedVariablesAreDyn: true })
|
|
3
|
+
.registerFunction("join(list, string): string", (list, sep) => list.map(String).join(sep))
|
|
4
|
+
.registerFunction("keys(map): list", (map) => {
|
|
5
|
+
if (map instanceof Map)
|
|
6
|
+
return [...map.keys()];
|
|
7
|
+
return Object.keys(map);
|
|
8
|
+
})
|
|
9
|
+
.registerFunction("values(map): list", (map) => {
|
|
10
|
+
if (map instanceof Map)
|
|
11
|
+
return [...map.values()];
|
|
12
|
+
return Object.values(map);
|
|
13
|
+
});
|
|
@@ -27,10 +27,12 @@ export type InstanceFactory = (context: EvaluationContext, resource: ResourceMan
|
|
|
27
27
|
* fields of the resource config before the controller sees them in init().
|
|
28
28
|
*
|
|
29
29
|
* @param resource The resource manifest whose config fields may be mutated in-place.
|
|
30
|
-
* @param getInstance Looks up an already-initialized instance by resource name.
|
|
30
|
+
* @param getInstance Looks up an already-initialized instance by resource name. With a
|
|
31
|
+
* non-`Self` `alias`, resolves a cross-module reference into that
|
|
32
|
+
* import's published exported instances instead of the local context.
|
|
31
33
|
* Returns undefined when the named resource is not yet initialized.
|
|
32
34
|
*/
|
|
33
|
-
export type PreInitHook = (resource: ResourceManifest, getInstance: (name: string) => ResourceInstance | undefined) => void;
|
|
35
|
+
export type PreInitHook = (resource: ResourceManifest, getInstance: (name: string, alias?: string) => ResourceInstance | undefined) => void;
|
|
34
36
|
/** Canonical key for a resource instance: "<module>.<kind>.<name>" */
|
|
35
37
|
export declare function resourceKey(r: ResourceManifest): string;
|
|
36
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/E,qEAAqE;AACrE,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,GAAG,UAAU,GAAG,UAAU,CAAC;AAE/F;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,gBAAgB,KACvB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,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,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,GAAG,CAAC,CAAC;IAChB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,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,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EvaluationContext } from "./evaluation-context.js";
|
|
2
|
+
import { ModuleContext } from "./module-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* The ephemeral, per-trigger context layer. Merges a ModuleContext with
|
|
5
|
+
* arbitrary execution-time properties (e.g. { request, inputs } for HTTP;
|
|
6
|
+
* any shape is valid — determined by the trigger type).
|
|
7
|
+
*
|
|
8
|
+
* Execution props overlay the module namespaces on key conflict.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ExecutionContext extends EvaluationContext {
|
|
11
|
+
constructor(moduleCtx: ModuleContext, execProps: Record<string, unknown>);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=execution-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../src/execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB;gBACzC,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASzE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EvaluationContext } from "./evaluation-context.js";
|
|
2
|
+
/**
|
|
3
|
+
* The ephemeral, per-trigger context layer. Merges a ModuleContext with
|
|
4
|
+
* arbitrary execution-time properties (e.g. { request, inputs } for HTTP;
|
|
5
|
+
* any shape is valid — determined by the trigger type).
|
|
6
|
+
*
|
|
7
|
+
* Execution props overlay the module namespaces on key conflict.
|
|
8
|
+
*/
|
|
9
|
+
export class ExecutionContext extends EvaluationContext {
|
|
10
|
+
constructor(moduleCtx, execProps) {
|
|
11
|
+
super(moduleCtx.source, Object.assign(Object.create(null), moduleCtx.context, execProps), moduleCtx.createInstance, moduleCtx.secretValues, moduleCtx.emit);
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./compiled-value.js";
|
|
2
2
|
export * from "./capabilities/invokable.js";
|
|
3
3
|
export * from "./ref.js";
|
|
4
|
+
export * from "./invoke-step.js";
|
|
4
5
|
export * from "./capabilities/provider.js";
|
|
5
6
|
export * from "./capabilities/runnable.js";
|
|
6
7
|
export * from "./context-provider.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,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,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,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,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,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./compiled-value.js";
|
|
2
2
|
export * from "./capabilities/invokable.js";
|
|
3
3
|
export * from "./ref.js";
|
|
4
|
+
export * from "./invoke-step.js";
|
|
4
5
|
export * from "./capabilities/provider.js";
|
|
5
6
|
export * from "./capabilities/runnable.js";
|
|
6
7
|
export * from "./context-provider.js";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
|
+
import type { KindRef, ScopeContext } from "./ref.js";
|
|
3
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
4
|
+
/** Retry policy for a single invoke step, passed through to `ctx.invoke`. */
|
|
5
|
+
export interface InvokeStepRetry {
|
|
6
|
+
attempts?: number;
|
|
7
|
+
delay?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The canonical leaf step shared by the kernel's boot `targets` runner and the
|
|
11
|
+
* `Run.Sequence` controller. `invoke` carries a resolved `{ kind, name }` ref
|
|
12
|
+
* (or a pre-resolved instance once Phase 5 injection / inline resolution ran).
|
|
13
|
+
*/
|
|
14
|
+
export interface InvokeStep {
|
|
15
|
+
name: string;
|
|
16
|
+
when?: string;
|
|
17
|
+
invoke: KindRef<Invocable> | Invocable;
|
|
18
|
+
inputs?: Record<string, unknown>;
|
|
19
|
+
retry?: InvokeStepRetry;
|
|
20
|
+
}
|
|
21
|
+
/** An inline flat invoke step on an Application's `targets`. Same as an
|
|
22
|
+
* `InvokeStep` but `name` is optional (only needed for `steps.<name>.result`
|
|
23
|
+
* plumbing; the boot runner synthesizes one when omitted) and `retry` is not
|
|
24
|
+
* supported — the boot invoke path takes no retry options, so it is omitted
|
|
25
|
+
* from the surface rather than silently ignored. */
|
|
26
|
+
export interface InlineInvokeTarget {
|
|
27
|
+
name?: string;
|
|
28
|
+
when?: string;
|
|
29
|
+
invoke: KindRef<Invocable> | Invocable;
|
|
30
|
+
inputs?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/** A single Application `targets` entry. The kernel boot runner dispatches by
|
|
33
|
+
* shape: a bare string or resolved `{ kind, name }` runs a Runnable/Service;
|
|
34
|
+
* `{ ref, when? }` is a guarded run (ref a bare name or a resolved `!ref`);
|
|
35
|
+
* `{ invoke, ... }` is an inline invoke step executed via `executeInvokeStep`. */
|
|
36
|
+
export type BootTarget = string | {
|
|
37
|
+
kind: string;
|
|
38
|
+
name: string;
|
|
39
|
+
} | {
|
|
40
|
+
ref: string | {
|
|
41
|
+
kind: string;
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
|
44
|
+
when?: string;
|
|
45
|
+
} | InlineInvokeTarget;
|
|
46
|
+
/**
|
|
47
|
+
* The context methods the leaf composes. Satisfied structurally by
|
|
48
|
+
* `ResourceContext` (Run.Sequence) and by a kernel-side adapter over the root
|
|
49
|
+
* module context (boot `targets`). The leaf needs nothing else from the kernel.
|
|
50
|
+
*/
|
|
51
|
+
export interface InvokeStepContext {
|
|
52
|
+
expandValue(value: any, context: Record<string, any>): any;
|
|
53
|
+
invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
|
|
54
|
+
invokeResolved<TInputs>(kind: string, name: string, instance: ResourceInstance, inputs: TInputs): Promise<any>;
|
|
55
|
+
/** Resolve a cross-module exported instance (`!ref Alias.name`) to its live instance.
|
|
56
|
+
* Optional — providers that pre-resolve cross-module refs before reaching the leaf
|
|
57
|
+
* (e.g. the boot-target runner) may omit it. */
|
|
58
|
+
resolveImportedInstance?(alias: string, name: string): ResourceInstance | undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Per-run state threaded through the leaf. `steps` is the result accumulator
|
|
62
|
+
* (mutated in place); `cel` carries extra CEL variables (e.g. `error` inside a
|
|
63
|
+
* Run.Sequence catch) and is empty at boot; `scope` is present only inside a
|
|
64
|
+
* Run.Sequence `with:` scope.
|
|
65
|
+
*/
|
|
66
|
+
export interface InvokeStepState {
|
|
67
|
+
steps: Record<string, unknown>;
|
|
68
|
+
cel?: Record<string, unknown>;
|
|
69
|
+
scope?: ScopeContext;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
|
|
73
|
+
* and invoke the target, then record `steps[step.name] = { result }`. Knows
|
|
74
|
+
* nothing about control flow — `if`/`while`/`switch`/`try` are the caller's
|
|
75
|
+
* concern.
|
|
76
|
+
*/
|
|
77
|
+
export declare function executeInvokeStep(step: InvokeStep, ctx: InvokeStepContext, state: InvokeStepState): Promise<void>;
|
|
78
|
+
//# sourceMappingURL=invoke-step.d.ts.map
|
|
@@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ACH,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;IAC3D,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1F,cAAc,CAAC,OAAO,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,GAAG,CAAC,CAAC;IAChB;;qDAEiD;IACjD,uBAAuB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;CACrF;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,IAAI,CAAC,CAgCf"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
|
|
3
|
+
* and invoke the target, then record `steps[step.name] = { result }`. Knows
|
|
4
|
+
* nothing about control flow — `if`/`while`/`switch`/`try` are the caller's
|
|
5
|
+
* concern.
|
|
6
|
+
*/
|
|
7
|
+
export async function executeInvokeStep(step, ctx, state) {
|
|
8
|
+
const cel = { steps: state.steps, ...state.cel };
|
|
9
|
+
if (step.when !== undefined && !ctx.expandValue(step.when, cel))
|
|
10
|
+
return;
|
|
11
|
+
const inputs = ctx.expandValue(step.inputs ?? {}, cel);
|
|
12
|
+
const raw = step.invoke;
|
|
13
|
+
let result;
|
|
14
|
+
if (raw && typeof raw.invoke === "function") {
|
|
15
|
+
result = await raw.invoke(inputs);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const ref = raw;
|
|
19
|
+
if (ref.alias && ref.alias !== "Self") {
|
|
20
|
+
// Cross-module exported instance: resolve into the owning import's context and invoke
|
|
21
|
+
// the live instance directly — works whether or not the step runs inside a `with:`
|
|
22
|
+
// scope (a plain `steps` list has no scope, so name lookup in the local context fails).
|
|
23
|
+
const instance = ctx.resolveImportedInstance?.(ref.alias, ref.name);
|
|
24
|
+
if (!instance) {
|
|
25
|
+
throw new Error(`Cross-module reference '${ref.alias}.${ref.name}' did not resolve to an exported instance.`);
|
|
26
|
+
}
|
|
27
|
+
result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
|
|
28
|
+
}
|
|
29
|
+
else if (state.scope) {
|
|
30
|
+
const instance = state.scope.getInstance(ref.name);
|
|
31
|
+
result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result = await ctx.invoke(ref.kind, ref.name, inputs, { retry: step.retry });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
state.steps[step.name] = { result };
|
|
38
|
+
}
|
package/dist/module-context.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
2
|
import type { ControllerPolicy } from "./controller-policy.js";
|
|
3
3
|
import type { EvaluationContext } from "./evaluation-context.js";
|
|
4
|
+
import type { BootTarget } from "./invoke-step.js";
|
|
5
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
4
6
|
/**
|
|
5
7
|
* Public contract for a persistent, module-scoped context.
|
|
6
8
|
*
|
|
@@ -18,12 +20,21 @@ export interface ModuleContext extends EvaluationContext {
|
|
|
18
20
|
/** True if `alias` was registered via `registerImport()` on this module. */
|
|
19
21
|
hasImport(alias: string): boolean;
|
|
20
22
|
setVariables(vars: Record<string, unknown>): void;
|
|
21
|
-
setTargets(vars:
|
|
23
|
+
setTargets(vars: BootTarget[]): void;
|
|
22
24
|
setSecrets(secrets: Record<string, unknown>): void;
|
|
23
25
|
setResource(name: string, props: Record<string, unknown>): void;
|
|
24
26
|
setControllerPolicy(policy: ControllerPolicy | undefined): void;
|
|
25
27
|
getControllerPolicy(): ControllerPolicy | undefined;
|
|
26
28
|
registerImport(alias: string, targetModule: string, kinds: string[]): void;
|
|
29
|
+
/** Resolve a cross-module exported-instance reference `Alias.name` to its `{kind, name}`
|
|
30
|
+
* ref (canonical kind), gated by the import's `exports.resources`. Returns undefined when
|
|
31
|
+
* the alias is unknown, the name isn't exported, or the import hasn't initialized yet. */
|
|
32
|
+
resolveImportedRef(alias: string, name: string): {
|
|
33
|
+
kind: string;
|
|
34
|
+
name: string;
|
|
35
|
+
} | undefined;
|
|
36
|
+
/** Resolve a cross-module exported-instance reference `Alias.name` to its live instance. */
|
|
37
|
+
resolveImportedInstance(alias: string, name: string): ResourceInstance | undefined;
|
|
27
38
|
getInstance(name: string): unknown;
|
|
28
39
|
getInvocable<TInput = Record<string, any>, TOutput = any>(name: string): Invocable<TInput, TOutput>;
|
|
29
40
|
resolveKind(kind: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-context.d.ts","sourceRoot":"","sources":["../src/module-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"module-context.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M,EAAE,GAAG,IAAI,CAAC;IAC3E;;+FAE2F;IAC3F,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC5F,4FAA4F;IAC5F,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IACnF,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,EACtD,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B"}
|
package/dist/ref.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { ResourceInstance } from "./resource-instance.js";
|
|
2
2
|
/** Marker type for x-telo-ref fields. Carries the live instance type at the TypeScript level;
|
|
3
3
|
* at runtime this field holds `{ kind, name }` until Phase 5 injection replaces it.
|
|
4
|
-
* T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance.
|
|
4
|
+
* T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance.
|
|
5
|
+
*
|
|
6
|
+
* `alias` is set only for cross-module references resolved from `!ref Alias.name` against an
|
|
7
|
+
* imported library's `exports.resources`. It names the import alias whose child context owns
|
|
8
|
+
* the target instance, so Phase 5 injection can resolve into that context rather than the
|
|
9
|
+
* referencing resource's own. Absent (or `"Self"`) means a local reference. */
|
|
5
10
|
export interface KindRef<T = ResourceInstance> {
|
|
6
11
|
readonly kind: string;
|
|
7
12
|
readonly name: string;
|
|
13
|
+
readonly alias?: string;
|
|
8
14
|
readonly __type?: T;
|
|
9
15
|
}
|
|
10
16
|
/** Marker type for x-telo-scope fields. Has no runtime value — used only as a discriminant
|
|
@@ -14,11 +20,13 @@ export interface ScopeRef {
|
|
|
14
20
|
}
|
|
15
21
|
/** Gives a controller access to the resources initialized within a scope. */
|
|
16
22
|
export interface ScopeContext {
|
|
17
|
-
/** Returns the initialized instance for the given name.
|
|
23
|
+
/** Returns the initialized instance for the given name. With a non-`Self` `alias`,
|
|
24
|
+
* resolves a cross-module exported instance (`!ref Alias.name`) into the owning
|
|
25
|
+
* import's child context instead of the scope-local / outer resources.
|
|
18
26
|
* Throws synchronously if the name was not declared in the scope —
|
|
19
27
|
* this is always a programming error; all scope members are statically
|
|
20
28
|
* validated in Phase 3 before the kernel ever reaches runtime. */
|
|
21
|
-
getInstance(name: string): ResourceInstance;
|
|
29
|
+
getInstance(name: string, alias?: string): ResourceInstance;
|
|
22
30
|
}
|
|
23
31
|
/** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
|
|
24
32
|
* The controller calls run() to open the scope, execute work, and tear it down. */
|
package/dist/ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;;;;;;gFAOgF;AAChF,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,gBAAgB;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,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import type { Runnable } from "./capabilities/runnable.js";
|
|
3
4
|
import type { ResourceContext } from "./resource-context.js";
|
|
4
|
-
export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<Invocable<TInput, TOutput>> & Partial<Runnable> & {
|
|
5
|
+
export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<Invocable<TInput, TOutput>> & Partial<Runnable> & Partial<Provider<TOutput>> & {
|
|
5
6
|
init?(ctx?: ResourceContext): Promise<void>;
|
|
6
7
|
teardown?(): void | Promise<void>;
|
|
7
8
|
snapshot?(): Record<string, any> | Promise<Record<string, any>>;
|
|
@@ -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,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,CACjF,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3B,GACC,OAAO,CAAC,QAAQ,CAAC,GAAG;
|
|
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,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,CACjF,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3B,GACC,OAAO,CAAC,QAAQ,CAAC,GACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG;IAC3B,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export interface Provider {
|
|
2
|
-
|
|
1
|
+
export interface Provider<TOutput = unknown> {
|
|
2
|
+
provide(): Promise<TOutput>;
|
|
3
3
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./compiled-value.js";
|
|
2
2
|
export * from "./capabilities/invokable.js";
|
|
3
3
|
export * from "./ref.js";
|
|
4
|
+
export * from "./invoke-step.js";
|
|
4
5
|
export * from "./capabilities/provider.js";
|
|
5
6
|
export * from "./capabilities/runnable.js";
|
|
6
7
|
export * from "./context-provider.js";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
|
+
import type { KindRef, ScopeContext } from "./ref.js";
|
|
3
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
4
|
+
|
|
5
|
+
/** Retry policy for a single invoke step, passed through to `ctx.invoke`. */
|
|
6
|
+
export interface InvokeStepRetry {
|
|
7
|
+
attempts?: number;
|
|
8
|
+
delay?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The canonical leaf step shared by the kernel's boot `targets` runner and the
|
|
13
|
+
* `Run.Sequence` controller. `invoke` carries a resolved `{ kind, name }` ref
|
|
14
|
+
* (or a pre-resolved instance once Phase 5 injection / inline resolution ran).
|
|
15
|
+
*/
|
|
16
|
+
export interface InvokeStep {
|
|
17
|
+
name: string;
|
|
18
|
+
when?: string;
|
|
19
|
+
invoke: KindRef<Invocable> | Invocable;
|
|
20
|
+
inputs?: Record<string, unknown>;
|
|
21
|
+
retry?: InvokeStepRetry;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** An inline flat invoke step on an Application's `targets`. Same as an
|
|
25
|
+
* `InvokeStep` but `name` is optional (only needed for `steps.<name>.result`
|
|
26
|
+
* plumbing; the boot runner synthesizes one when omitted) and `retry` is not
|
|
27
|
+
* supported — the boot invoke path takes no retry options, so it is omitted
|
|
28
|
+
* from the surface rather than silently ignored. */
|
|
29
|
+
export interface InlineInvokeTarget {
|
|
30
|
+
name?: string;
|
|
31
|
+
when?: string;
|
|
32
|
+
invoke: KindRef<Invocable> | Invocable;
|
|
33
|
+
inputs?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A single Application `targets` entry. The kernel boot runner dispatches by
|
|
37
|
+
* shape: a bare string or resolved `{ kind, name }` runs a Runnable/Service;
|
|
38
|
+
* `{ ref, when? }` is a guarded run (ref a bare name or a resolved `!ref`);
|
|
39
|
+
* `{ invoke, ... }` is an inline invoke step executed via `executeInvokeStep`. */
|
|
40
|
+
export type BootTarget =
|
|
41
|
+
| string
|
|
42
|
+
| { kind: string; name: string }
|
|
43
|
+
| { ref: string | { kind: string; name: string }; when?: string }
|
|
44
|
+
| InlineInvokeTarget;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The context methods the leaf composes. Satisfied structurally by
|
|
48
|
+
* `ResourceContext` (Run.Sequence) and by a kernel-side adapter over the root
|
|
49
|
+
* module context (boot `targets`). The leaf needs nothing else from the kernel.
|
|
50
|
+
*/
|
|
51
|
+
export interface InvokeStepContext {
|
|
52
|
+
expandValue(value: any, context: Record<string, any>): any;
|
|
53
|
+
invoke<TInputs>(kind: string, name: string, inputs: TInputs, options?: any): Promise<any>;
|
|
54
|
+
invokeResolved<TInputs>(
|
|
55
|
+
kind: string,
|
|
56
|
+
name: string,
|
|
57
|
+
instance: ResourceInstance,
|
|
58
|
+
inputs: TInputs,
|
|
59
|
+
): Promise<any>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Per-run state threaded through the leaf. `steps` is the result accumulator
|
|
64
|
+
* (mutated in place); `cel` carries extra CEL variables (e.g. `error` inside a
|
|
65
|
+
* Run.Sequence catch) and is empty at boot; `scope` is present only inside a
|
|
66
|
+
* Run.Sequence `with:` scope.
|
|
67
|
+
*/
|
|
68
|
+
export interface InvokeStepState {
|
|
69
|
+
steps: Record<string, unknown>;
|
|
70
|
+
cel?: Record<string, unknown>;
|
|
71
|
+
scope?: ScopeContext;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Execute one invoke step: evaluate the `when` guard, expand `inputs`, resolve
|
|
76
|
+
* and invoke the target, then record `steps[step.name] = { result }`. Knows
|
|
77
|
+
* nothing about control flow — `if`/`while`/`switch`/`try` are the caller's
|
|
78
|
+
* concern.
|
|
79
|
+
*/
|
|
80
|
+
export async function executeInvokeStep(
|
|
81
|
+
step: InvokeStep,
|
|
82
|
+
ctx: InvokeStepContext,
|
|
83
|
+
state: InvokeStepState,
|
|
84
|
+
): Promise<void> {
|
|
85
|
+
const cel = { steps: state.steps, ...state.cel };
|
|
86
|
+
if (step.when !== undefined && !ctx.expandValue(step.when, cel)) return;
|
|
87
|
+
|
|
88
|
+
const inputs = ctx.expandValue(step.inputs ?? {}, cel) as Record<string, unknown>;
|
|
89
|
+
const raw = step.invoke as unknown;
|
|
90
|
+
let result: unknown;
|
|
91
|
+
|
|
92
|
+
if (raw && typeof (raw as Invocable).invoke === "function") {
|
|
93
|
+
result = await (raw as Invocable).invoke(inputs);
|
|
94
|
+
} else {
|
|
95
|
+
const ref = raw as KindRef<Invocable>;
|
|
96
|
+
if (state.scope) {
|
|
97
|
+
const instance = state.scope.getInstance(ref.name) as unknown as ResourceInstance;
|
|
98
|
+
result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
|
|
99
|
+
} else {
|
|
100
|
+
result = await ctx.invoke(ref.kind, ref.name, inputs, { retry: step.retry });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
state.steps[step.name] = { result };
|
|
105
|
+
}
|
package/src/module-context.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
2
|
import type { ControllerPolicy } from "./controller-policy.js";
|
|
3
3
|
import type { EvaluationContext } from "./evaluation-context.js";
|
|
4
|
+
import type { BootTarget } from "./invoke-step.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Public contract for a persistent, module-scoped context.
|
|
@@ -21,7 +22,7 @@ export interface ModuleContext extends EvaluationContext {
|
|
|
21
22
|
hasImport(alias: string): boolean;
|
|
22
23
|
|
|
23
24
|
setVariables(vars: Record<string, unknown>): void;
|
|
24
|
-
setTargets(vars:
|
|
25
|
+
setTargets(vars: BootTarget[]): void;
|
|
25
26
|
setSecrets(secrets: Record<string, unknown>): void;
|
|
26
27
|
setResource(name: string, props: Record<string, unknown>): void;
|
|
27
28
|
setControllerPolicy(policy: ControllerPolicy | undefined): void;
|
package/src/resource-instance.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Invocable } from "./capabilities/invokable.js";
|
|
2
|
+
import type { Provider } from "./capabilities/provider.js";
|
|
2
3
|
import type { Runnable } from "./capabilities/runnable.js";
|
|
3
4
|
import type { ResourceContext } from "./resource-context.js";
|
|
4
5
|
|
|
5
6
|
export type ResourceInstance<TInput = Record<string, any>, TOutput = any> = Partial<
|
|
6
7
|
Invocable<TInput, TOutput>
|
|
7
8
|
> &
|
|
8
|
-
Partial<Runnable> &
|
|
9
|
+
Partial<Runnable> &
|
|
10
|
+
Partial<Provider<TOutput>> & {
|
|
9
11
|
init?(ctx?: ResourceContext): Promise<void>;
|
|
10
12
|
teardown?(): void | Promise<void>;
|
|
11
13
|
snapshot?(): Record<string, any> | Promise<Record<string, any>>;
|