@telorun/sdk 0.13.0 → 0.16.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/package.json +1 -1
- package/src/evaluation-context.ts +4 -2
- package/src/invoke-step.ts +16 -1
- package/src/module-context.ts +7 -0
- package/src/ref.ts +11 -3
- package/dist/capability-definition.d.ts +0 -8
- package/dist/capability-definition.d.ts.map +0 -1
- package/dist/capability-definition.js +0 -21
- package/dist/cel-environment.d.ts +0 -3
- package/dist/cel-environment.d.ts.map +0 -1
- package/dist/cel-environment.js +0 -13
- package/dist/execution-context.d.ts +0 -13
- package/dist/execution-context.d.ts.map +0 -1
- package/dist/execution-context.js +0 -13
package/package.json
CHANGED
|
@@ -32,12 +32,14 @@ export type InstanceFactory = (
|
|
|
32
32
|
* fields of the resource config before the controller sees them in init().
|
|
33
33
|
*
|
|
34
34
|
* @param resource The resource manifest whose config fields may be mutated in-place.
|
|
35
|
-
* @param getInstance Looks up an already-initialized instance by resource name.
|
|
35
|
+
* @param getInstance Looks up an already-initialized instance by resource name. With a
|
|
36
|
+
* non-`Self` `alias`, resolves a cross-module reference into that
|
|
37
|
+
* import's published exported instances instead of the local context.
|
|
36
38
|
* Returns undefined when the named resource is not yet initialized.
|
|
37
39
|
*/
|
|
38
40
|
export type PreInitHook = (
|
|
39
41
|
resource: ResourceManifest,
|
|
40
|
-
getInstance: (name: string) => ResourceInstance | undefined,
|
|
42
|
+
getInstance: (name: string, alias?: string) => ResourceInstance | undefined,
|
|
41
43
|
) => void;
|
|
42
44
|
|
|
43
45
|
/** Canonical key for a resource instance: "<module>.<kind>.<name>" */
|
package/src/invoke-step.ts
CHANGED
|
@@ -57,6 +57,10 @@ export interface InvokeStepContext {
|
|
|
57
57
|
instance: ResourceInstance,
|
|
58
58
|
inputs: TInputs,
|
|
59
59
|
): Promise<any>;
|
|
60
|
+
/** Resolve a cross-module exported instance (`!ref Alias.name`) to its live instance.
|
|
61
|
+
* Optional — providers that pre-resolve cross-module refs before reaching the leaf
|
|
62
|
+
* (e.g. the boot-target runner) may omit it. */
|
|
63
|
+
resolveImportedInstance?(alias: string, name: string): ResourceInstance | undefined;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
/**
|
|
@@ -93,7 +97,18 @@ export async function executeInvokeStep(
|
|
|
93
97
|
result = await (raw as Invocable).invoke(inputs);
|
|
94
98
|
} else {
|
|
95
99
|
const ref = raw as KindRef<Invocable>;
|
|
96
|
-
if (
|
|
100
|
+
if (ref.alias && ref.alias !== "Self") {
|
|
101
|
+
// Cross-module exported instance: resolve into the owning import's context and invoke
|
|
102
|
+
// the live instance directly — works whether or not the step runs inside a `with:`
|
|
103
|
+
// scope (a plain `steps` list has no scope, so name lookup in the local context fails).
|
|
104
|
+
const instance = ctx.resolveImportedInstance?.(ref.alias, ref.name);
|
|
105
|
+
if (!instance) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Cross-module reference '${ref.alias}.${ref.name}' did not resolve to an exported instance.`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
|
|
111
|
+
} else if (state.scope) {
|
|
97
112
|
const instance = state.scope.getInstance(ref.name) as unknown as ResourceInstance;
|
|
98
113
|
result = await ctx.invokeResolved(ref.kind, ref.name, instance, inputs);
|
|
99
114
|
} else {
|
package/src/module-context.ts
CHANGED
|
@@ -2,6 +2,7 @@ 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
4
|
import type { BootTarget } from "./invoke-step.js";
|
|
5
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Public contract for a persistent, module-scoped context.
|
|
@@ -29,6 +30,12 @@ export interface ModuleContext extends EvaluationContext {
|
|
|
29
30
|
getControllerPolicy(): ControllerPolicy | undefined;
|
|
30
31
|
|
|
31
32
|
registerImport(alias: string, targetModule: string, kinds: string[]): void;
|
|
33
|
+
/** Resolve a cross-module exported-instance reference `Alias.name` to its `{kind, name}`
|
|
34
|
+
* ref (canonical kind), gated by the import's `exports.resources`. Returns undefined when
|
|
35
|
+
* the alias is unknown, the name isn't exported, or the import hasn't initialized yet. */
|
|
36
|
+
resolveImportedRef(alias: string, name: string): { kind: string; name: string } | undefined;
|
|
37
|
+
/** Resolve a cross-module exported-instance reference `Alias.name` to its live instance. */
|
|
38
|
+
resolveImportedInstance(alias: string, name: string): ResourceInstance | undefined;
|
|
32
39
|
getInstance(name: string): unknown;
|
|
33
40
|
getInvocable<TInput = Record<string, any>, TOutput = any>(
|
|
34
41
|
name: string,
|
package/src/ref.ts
CHANGED
|
@@ -2,10 +2,16 @@ import type { ResourceInstance } from "./resource-instance.js";
|
|
|
2
2
|
|
|
3
3
|
/** Marker type for x-telo-ref fields. Carries the live instance type at the TypeScript level;
|
|
4
4
|
* at runtime this field holds `{ kind, name }` until Phase 5 injection replaces it.
|
|
5
|
-
* T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance.
|
|
5
|
+
* T is a phantom type — any capability interface (Invocable, Runnable, …) or ResourceInstance.
|
|
6
|
+
*
|
|
7
|
+
* `alias` is set only for cross-module references resolved from `!ref Alias.name` against an
|
|
8
|
+
* imported library's `exports.resources`. It names the import alias whose child context owns
|
|
9
|
+
* the target instance, so Phase 5 injection can resolve into that context rather than the
|
|
10
|
+
* referencing resource's own. Absent (or `"Self"`) means a local reference. */
|
|
6
11
|
export interface KindRef<T = ResourceInstance> {
|
|
7
12
|
readonly kind: string;
|
|
8
13
|
readonly name: string;
|
|
14
|
+
readonly alias?: string;
|
|
9
15
|
readonly __type?: T;
|
|
10
16
|
}
|
|
11
17
|
|
|
@@ -17,11 +23,13 @@ export interface ScopeRef {
|
|
|
17
23
|
|
|
18
24
|
/** Gives a controller access to the resources initialized within a scope. */
|
|
19
25
|
export interface ScopeContext {
|
|
20
|
-
/** Returns the initialized instance for the given name.
|
|
26
|
+
/** Returns the initialized instance for the given name. With a non-`Self` `alias`,
|
|
27
|
+
* resolves a cross-module exported instance (`!ref Alias.name`) into the owning
|
|
28
|
+
* import's child context instead of the scope-local / outer resources.
|
|
21
29
|
* Throws synchronously if the name was not declared in the scope —
|
|
22
30
|
* this is always a programming error; all scope members are statically
|
|
23
31
|
* validated in Phase 3 before the kernel ever reaches runtime. */
|
|
24
|
-
getInstance(name: string): ResourceInstance;
|
|
32
|
+
getInstance(name: string, alias?: string): ResourceInstance;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
/** Returned by Phase 5 injection in place of an x-telo-scope manifest array.
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/cel-environment.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|