@telorun/kernel 0.2.7 → 0.2.9
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 +100 -0
- package/dist/controllers/module/import-controller.d.ts.map +1 -1
- package/dist/controllers/module/import-controller.js +18 -9
- package/dist/controllers/module/import-controller.js.map +1 -1
- package/dist/evaluation-context.d.ts +76 -38
- package/dist/evaluation-context.d.ts.map +1 -1
- package/dist/evaluation-context.js +254 -89
- package/dist/evaluation-context.js.map +1 -1
- package/dist/execution-context.d.ts +1 -1
- package/dist/execution-context.d.ts.map +1 -1
- package/dist/execution-context.js +1 -1
- package/dist/execution-context.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/kernel.d.ts +7 -1
- package/dist/kernel.d.ts.map +1 -1
- package/dist/kernel.js +54 -11
- package/dist/kernel.js.map +1 -1
- package/dist/manifest-adapters/local-file-adapter.d.ts +3 -1
- package/dist/manifest-adapters/local-file-adapter.d.ts.map +1 -1
- package/dist/manifest-adapters/local-file-adapter.js +54 -14
- package/dist/manifest-adapters/local-file-adapter.js.map +1 -1
- package/dist/manifest-adapters/manifest-adapter.d.ts +1 -1
- package/dist/module-context.d.ts +28 -5
- package/dist/module-context.d.ts.map +1 -1
- package/dist/module-context.js +107 -4
- package/dist/module-context.js.map +1 -1
- package/dist/resource-context.d.ts +6 -6
- package/dist/resource-context.d.ts.map +1 -1
- package/dist/resource-context.js +5 -4
- package/dist/resource-context.js.map +1 -1
- package/dist/schema-valiator.d.ts +1 -0
- package/dist/schema-valiator.d.ts.map +1 -1
- package/dist/schema-valiator.js +11 -1
- package/dist/schema-valiator.js.map +1 -1
- package/dist/schema-validator.d.ts +15 -0
- package/dist/schema-validator.d.ts.map +1 -0
- package/dist/schema-validator.js +127 -0
- package/dist/schema-validator.js.map +1 -0
- package/package.json +23 -11
- package/src/controllers/module/import-controller.ts +27 -11
- package/src/evaluation-context.ts +490 -0
- package/src/execution-context.ts +21 -0
- package/src/index.ts +4 -0
- package/src/kernel.ts +70 -13
- package/src/manifest-adapters/local-file-adapter.ts +56 -15
- package/src/manifest-adapters/manifest-adapter.ts +1 -1
- package/src/module-context.ts +211 -0
- package/src/resource-context.ts +8 -7
- package/src/{schema-valiator.ts → schema-validator.ts} +13 -1
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Telo Kernel
|
|
2
|
+
|
|
3
|
+
**Target:** Node.js (Rust/Go ports planned)
|
|
4
|
+
|
|
5
|
+
**Input:** A module manifest YAML file or a directory of YAML files
|
|
6
|
+
|
|
7
|
+
## 1. Core Concepts
|
|
8
|
+
|
|
9
|
+
The Telo Kernel is a **declarative execution host**. You describe resources in YAML; the kernel loads them, wires up controllers, and keeps the process alive until all work is done.
|
|
10
|
+
|
|
11
|
+
The kernel performs three functions:
|
|
12
|
+
|
|
13
|
+
- **Loader:** Reads YAML files, compiles them through the CEL-YAML templating engine, and resolves controller entrypoints.
|
|
14
|
+
- **Registry:** Indexes resource instances by a composite key of `module.Kind.name`.
|
|
15
|
+
- **Kernel:** Orchestrates the boot sequence, manages the event bus, and routes invocations.
|
|
16
|
+
|
|
17
|
+
**Module loading and resource discovery** happen during the load phase, before any resource is initialized.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. Resource Definitions
|
|
22
|
+
|
|
23
|
+
Every resource in a manifest is an instance of a `Kernel.Definition`. A definition declares several orthogonal facets:
|
|
24
|
+
|
|
25
|
+
| Facet | Field | Purpose |
|
|
26
|
+
| ------------- | -------------- | ----------------------------------------------------------------------------------- |
|
|
27
|
+
| `capability` | Lifecycle role | One of `Runnable`, `Service`, `Invocable`, `Mount`, `Provider` — mutually exclusive |
|
|
28
|
+
| `topology` | Composition | How the kind is structured internally: `Sequence`, `Router`, `Workflow` |
|
|
29
|
+
| `extends` | Inheritance | Abstract interface this kind fulfills (cross-module plugin pattern) |
|
|
30
|
+
| `controllers` | Execution | PURL-referenced controller implementations |
|
|
31
|
+
|
|
32
|
+
### Capability
|
|
33
|
+
|
|
34
|
+
`capability` assigns a single lifecycle role. The kernel uses it to determine when to call `init()`, `run()`, or `invoke()` on the controller. A definition declares exactly one capability.
|
|
35
|
+
|
|
36
|
+
→ [docs/capabilities.md](docs/capabilities.md)
|
|
37
|
+
|
|
38
|
+
### Topology
|
|
39
|
+
|
|
40
|
+
`topology` names the structural composition pattern of a kind — how it is assembled internally from steps, routes, or nodes. It drives built-in execution when no controller is declared, structural validation in the analyzer, and canvas rendering in the editor.
|
|
41
|
+
|
|
42
|
+
→ [docs/topology.md](docs/topology.md) _(design proposal — not yet implemented)_
|
|
43
|
+
|
|
44
|
+
### Inheritance
|
|
45
|
+
|
|
46
|
+
`extends` declares that a definition fulfills an abstract interface (`Kernel.Abstract`) declared by another module. This is the plugin pattern for subsystems like workflow backends.
|
|
47
|
+
|
|
48
|
+
→ [docs/inheritance.md](docs/inheritance.md)
|
|
49
|
+
|
|
50
|
+
For the complete `Kernel.Definition` field reference, see [docs/resource-definition.md](docs/resource-definition.md).
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 3. CEL-YAML Templating
|
|
55
|
+
|
|
56
|
+
Before a manifest object is processed, it is compiled by the **CEL-YAML templating engine** (`@telorun/yaml-cel-templating`). This runs as part of loading — any compilation error halts the boot sequence immediately.
|
|
57
|
+
|
|
58
|
+
The compile step provides `{ env: process.env }` as the initial context, so environment variables are available everywhere:
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
resources:
|
|
62
|
+
- ${{ env.MY_MANIFEST_PATH }}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Interpolation
|
|
66
|
+
|
|
67
|
+
- `${{ expr }}` — the interpolation syntax used throughout Telo
|
|
68
|
+
|
|
69
|
+
When the entire string is a single interpolation, the result preserves the CEL type (integer, boolean, etc.). Mixed strings are coerced to string.
|
|
70
|
+
|
|
71
|
+
**See [../yaml-cel-templating/README.md](../yaml-cel-templating/README.md) for full directive reference.**
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 4. Kernel.Definition
|
|
76
|
+
|
|
77
|
+
Modules declare the resource kinds they handle using `Kernel.Definition`:
|
|
78
|
+
|
|
79
|
+
```yaml
|
|
80
|
+
kind: Kernel.Definition
|
|
81
|
+
metadata:
|
|
82
|
+
name: Server # fully-qualified kind: Http.Server
|
|
83
|
+
module: Http
|
|
84
|
+
capability: Service # one of: Runnable, Service, Invocable, Mount, Provider, Template
|
|
85
|
+
schema: # JSON Schema — validated against each resource before create()
|
|
86
|
+
type: object
|
|
87
|
+
properties:
|
|
88
|
+
port: { type: integer }
|
|
89
|
+
host: { type: string }
|
|
90
|
+
required: [port]
|
|
91
|
+
controllers:
|
|
92
|
+
# Ordered list of Package URL (PURL) candidates — first match for the current runtime is used
|
|
93
|
+
- pkg:npm/@telorun/run@>=1.0.0?local_path=./nodejs#sequence
|
|
94
|
+
- pkg:cargo/telorun-run@>=1.0.0?local_path=./rust#sequence
|
|
95
|
+
- pkg:golang/github.com/telorun/run@>=1.0.0?local_path=./go#sequence
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
When a `Kernel.Definition` instance initializes, it resolves and loads the controller module
|
|
99
|
+
and registers it with the kernel. For the full resolution algorithm (local path, host
|
|
100
|
+
node_modules, registry cache) and PURL format, see [controllers.md](docs/controllers.md).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/module/import-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"import-controller.d.ts","sourceRoot":"","sources":["../../../src/controllers/module/import-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUtE,wBAAsB,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAiH3F;AAeD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmBlB,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DiagnosticSeverity, Loader, StaticAnalyzer } from "@telorun/analyzer";
|
|
2
|
-
import {
|
|
2
|
+
import { RuntimeError } from "@telorun/sdk";
|
|
3
|
+
import { ModuleContext } from "../../module-context.js";
|
|
3
4
|
import { LocalFileAdapter } from "../../manifest-adapters/local-file-adapter.js";
|
|
5
|
+
const importAnalysisCache = new Map();
|
|
4
6
|
export async function create(resource, ctx) {
|
|
5
7
|
const alias = resource.metadata.name;
|
|
6
8
|
const loader = new Loader([new LocalFileAdapter()]);
|
|
@@ -10,10 +12,21 @@ export async function create(resource, ctx) {
|
|
|
10
12
|
// preventing false UNDEFINED_KIND errors for kinds that come from the module's own imports.
|
|
11
13
|
const resolvedUrl = new URL(moduleSource, ctx.moduleContext.source).toString();
|
|
12
14
|
const analysisManifests = await loader.loadManifests(resolvedUrl);
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
+
const signature = JSON.stringify(analysisManifests);
|
|
16
|
+
const cached = importAnalysisCache.get(resolvedUrl);
|
|
17
|
+
let errors;
|
|
18
|
+
if (cached && cached.signature === signature) {
|
|
19
|
+
errors = cached.errors;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const diagnostics = new StaticAnalyzer().analyze(analysisManifests);
|
|
23
|
+
errors = diagnostics
|
|
24
|
+
.filter((d) => d.severity === DiagnosticSeverity.Error)
|
|
25
|
+
.map((d) => d.message);
|
|
26
|
+
importAnalysisCache.set(resolvedUrl, { signature, errors });
|
|
27
|
+
}
|
|
15
28
|
if (errors.length > 0) {
|
|
16
|
-
throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", errors.
|
|
29
|
+
throw new RuntimeError("ERR_MANIFEST_VALIDATION_FAILED", errors.join("\n"));
|
|
17
30
|
}
|
|
18
31
|
// Load target module manifests for runtime. Inject variables/secrets as compile context so
|
|
19
32
|
// that ${{ variables.x }} / ${{ secrets.y }} templates in the child module resolve correctly.
|
|
@@ -32,11 +45,7 @@ export async function create(resource, ctx) {
|
|
|
32
45
|
validateRequiredInputs(moduleManifest.secrets ?? {}, resource.secrets ?? {}, "secrets");
|
|
33
46
|
// Create child context with the imported variables/secrets baked in, so that
|
|
34
47
|
// ${{ variables.x }} / ${{ secrets.y }} templates resolve correctly at runtime.
|
|
35
|
-
const child = ctx.moduleContext.spawnChild(new
|
|
36
|
-
variables: resource.variables ?? {},
|
|
37
|
-
secrets: resource.secrets ?? {},
|
|
38
|
-
resources: {},
|
|
39
|
-
}, ctx.moduleContext.createInstance, ctx.moduleContext.secretValues, ctx.moduleContext.emit));
|
|
48
|
+
const child = ctx.moduleContext.spawnChild(new ModuleContext(ctx.moduleContext.source, resource.variables ?? {}, resource.secrets ?? {}, {}, [], ctx.moduleContext.createInstance, ctx.moduleContext.emit));
|
|
40
49
|
for (const manifest of manifests) {
|
|
41
50
|
child.registerManifest(manifest);
|
|
42
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-controller.js","sourceRoot":"","sources":["../../../src/controllers/module/import-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"import-controller.js","sourceRoot":"","sources":["../../../src/controllers/module/import-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aA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Q,CAAC;IAChC,oBAAoB,EAAE,KAAK;CAC5B,CAAC"}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
export type LifecycleState = "Pending" | "Validated" | "Initialized" | "Draining" | "Teardown";
|
|
1
|
+
import { resourceKey, type EvaluationContext as IEvaluationContext, type EmitEvent, type InstanceFactory, type LifecycleState, type PreInitHook, type ResourceInstance, type ResourceManifest, type ScopeHandle } from "@telorun/sdk";
|
|
2
|
+
export { resourceKey };
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
* ready (e.g. a dependency is still initializing). Injected at construction so
|
|
7
|
-
* every EvaluationContext node owns its full resource lifecycle.
|
|
8
|
-
*/
|
|
9
|
-
export type InstanceFactory = (resource: ResourceManifest) => Promise<ResourceInstance | null>;
|
|
10
|
-
/** Canonical key for a resource instance: "<module>.<kind>.<name>" */
|
|
11
|
-
export declare function resourceKey(r: ResourceManifest): string;
|
|
12
|
-
/**
|
|
13
|
-
* Base class for all evaluation contexts. Owns CEL evaluation, template
|
|
4
|
+
* Base class for all evaluation contexts. Owns template
|
|
14
5
|
* expansion, secrets redaction, and the generic resource lifecycle tree.
|
|
15
6
|
*
|
|
16
7
|
* Every EvaluationContext node can:
|
|
@@ -20,13 +11,16 @@ export declare function resourceKey(r: ResourceManifest): string;
|
|
|
20
11
|
* - Run a multi-pass initialization loop (initializeResources)
|
|
21
12
|
* - Cascade teardown depth-first through the tree (teardownResources)
|
|
22
13
|
*/
|
|
23
|
-
export declare class EvaluationContext {
|
|
14
|
+
export declare class EvaluationContext implements IEvaluationContext {
|
|
15
|
+
readonly source: string;
|
|
16
|
+
readonly id: string;
|
|
24
17
|
protected _context: Record<string, unknown>;
|
|
25
18
|
protected _secretValues: Set<string>;
|
|
26
19
|
protected _createInstance: InstanceFactory;
|
|
20
|
+
readonly emit: EmitEvent;
|
|
27
21
|
/** Position in the lifecycle tree. */
|
|
28
|
-
parent:
|
|
29
|
-
readonly children:
|
|
22
|
+
parent: IEvaluationContext | undefined;
|
|
23
|
+
readonly children: IEvaluationContext[];
|
|
30
24
|
/** Current lifecycle state of this context node. */
|
|
31
25
|
state: LifecycleState;
|
|
32
26
|
/** Resource instances owned by this context node, keyed by resourceKey(). */
|
|
@@ -34,58 +28,102 @@ export declare class EvaluationContext {
|
|
|
34
28
|
resource: ResourceManifest;
|
|
35
29
|
instance: ResourceInstance;
|
|
36
30
|
}>;
|
|
31
|
+
/** Resources that have been created but not yet initialized (between phases). */
|
|
32
|
+
protected readonly createdInstances: Map<string, {
|
|
33
|
+
resource: ResourceManifest;
|
|
34
|
+
instance: ResourceInstance;
|
|
35
|
+
ctx: any;
|
|
36
|
+
}>;
|
|
37
37
|
/** Resources queued for initialization on this context node. */
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
private pendingResources;
|
|
39
|
+
/**
|
|
40
|
+
* Optional hook called between create() and init() for each resource.
|
|
41
|
+
* Set by the kernel to inject live instances into reference fields.
|
|
42
|
+
*/
|
|
43
|
+
preInitHook?: PreInitHook;
|
|
44
|
+
constructor(source: string, context: Record<string, unknown>, createInstance: InstanceFactory | undefined, secretValues: Set<string>, emit: EmitEvent);
|
|
40
45
|
get createInstance(): InstanceFactory;
|
|
46
|
+
/** Called after init() when a resource snapshot is available. Overridden by ModuleContext. */
|
|
47
|
+
protected onResourceSnapshotted(_name: string, _snap: Record<string, unknown>): void;
|
|
41
48
|
get context(): Record<string, unknown>;
|
|
42
49
|
get secretValues(): Set<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Reorder pending resources to match the given name sequence (topo order from Phase 4).
|
|
52
|
+
* Resources not present in `names` are left at the end in their original order.
|
|
53
|
+
* Call before initializeResources() so the create/init sub-phases run in dependency order,
|
|
54
|
+
* guaranteeing that Phase 5 injection always finds initialized dependencies.
|
|
55
|
+
*/
|
|
56
|
+
setInitOrder(names: string[]): void;
|
|
43
57
|
/**
|
|
44
58
|
* Queue a resource manifest for initialization on this context.
|
|
45
59
|
*/
|
|
60
|
+
hasManifest(name: string): boolean;
|
|
46
61
|
registerManifest(resource: ResourceManifest): void;
|
|
47
62
|
/**
|
|
48
63
|
* Attach a child context to this node. The child's parent is set to this
|
|
49
64
|
* context and the child is registered under the given name.
|
|
50
65
|
*/
|
|
51
|
-
spawnChild<T extends
|
|
66
|
+
spawnChild<T extends IEvaluationContext>(child: T): T;
|
|
52
67
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
68
|
+
* Interleaved create/init loop.
|
|
69
|
+
*
|
|
70
|
+
* Each pass has two sub-phases run back-to-back:
|
|
71
|
+
* 1. Create sub-phase: call controller.create() for each pending resource that
|
|
72
|
+
* hasn't been created yet. Successful results go into createdInstances.
|
|
73
|
+
* 2. Init sub-phase: call instance.init(ctx) for each created-but-not-inited
|
|
74
|
+
* resource. Successful results go into resourceInstances.
|
|
56
75
|
*
|
|
57
|
-
*
|
|
76
|
+
* Interleaving is necessary because some resources' create() depends on effects
|
|
77
|
+
* produced by other resources' init() (e.g. Kernel.Import.init() runs
|
|
78
|
+
* child.initializeResources() which registers controllers needed by sibling
|
|
79
|
+
* resources' create()). Running both sub-phases each pass lets those effects
|
|
80
|
+
* propagate before the next create attempt.
|
|
81
|
+
*
|
|
82
|
+
* Each resource is created at most once and inited at most once.
|
|
83
|
+
* ERR_VISIBILITY_DENIED is fatal and re-thrown immediately.
|
|
58
84
|
* All other errors are tracked and retried until no progress is made.
|
|
59
85
|
*/
|
|
60
86
|
initializeResources(): Promise<void>;
|
|
61
87
|
withManifests<T>(manifests: any[], fn: () => T): T;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a ScopeHandle that initializes `manifests` in a fresh child context each time
|
|
90
|
+
* `run()` is called, executes the callback with a ScopeContext, and tears down when done.
|
|
91
|
+
*
|
|
92
|
+
* The child inherits the parent's preInitHook (if any), extended so that `getInstance`
|
|
93
|
+
* also checks the parent's already-initialized singleton instances. This lets scoped
|
|
94
|
+
* resources hold x-telo-ref slots pointing to outer resources — those deps are already
|
|
95
|
+
* live when the scope opens.
|
|
96
|
+
*/
|
|
97
|
+
createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
|
|
62
98
|
/**
|
|
63
99
|
* Cascade teardown depth-first through the tree:
|
|
64
100
|
* 1. Tear down child contexts in reverse registration order.
|
|
65
|
-
* 2. Tear down own resource instances in reverse registration order
|
|
66
|
-
*
|
|
67
|
-
* Note: Kernel-level events (e.g. Teardown events) are NOT emitted here —
|
|
68
|
-
* they remain the Kernel's responsibility.
|
|
101
|
+
* 2. Tear down own resource instances in reverse registration order,
|
|
102
|
+
* emitting a Teardown event for each via the injected emit callback.
|
|
69
103
|
*/
|
|
70
104
|
teardownResources(): Promise<void>;
|
|
105
|
+
transientChild(context: Record<string, any>): EvaluationContext;
|
|
71
106
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
107
|
+
* Invoke a resource by kind and name within this context's resourceInstances.
|
|
108
|
+
* Emits a scoped Invoked event via the injected emit callback after invocation.
|
|
74
109
|
*/
|
|
75
|
-
|
|
110
|
+
invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any>;
|
|
111
|
+
run(name: string): Promise<void>;
|
|
76
112
|
/**
|
|
77
|
-
* Expand a value that may contain ${{ }} templates.
|
|
78
|
-
* Works recursively over
|
|
79
|
-
* Templates whose identifiers are not present in the context are left
|
|
80
|
-
* unchanged (deferred) — they will be resolved at execution time when a
|
|
81
|
-
* richer ExecutionContext is available. All other CEL errors are propagated.
|
|
113
|
+
* Expand a value that may contain precompiled ${{ }} templates.
|
|
114
|
+
* Works recursively over CompiledValues, arrays, and objects.
|
|
82
115
|
*/
|
|
83
116
|
expand(value: unknown): unknown;
|
|
84
117
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
118
|
+
* Expand a value using this context merged with additional properties.
|
|
119
|
+
* Equivalent to merge(extraContext).expand(value) without allocating a context object.
|
|
87
120
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
121
|
+
expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
|
|
122
|
+
/**
|
|
123
|
+
* Expand specific dot-paths within an object. '**' expands the entire object.
|
|
124
|
+
* Paths listed in excludePaths are left untouched (runtime takes precedence).
|
|
125
|
+
* Always throws if an expression cannot be resolved.
|
|
126
|
+
*/
|
|
127
|
+
expandPaths(value: Record<string, unknown>, paths: string[], excludePaths?: string[]): Record<string, unknown>;
|
|
90
128
|
}
|
|
91
129
|
//# sourceMappingURL=evaluation-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"evaluation-context.d.ts","sourceRoot":"","sources":["../src/evaluation-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,KAAK,iBAAiB,IAAI,kBAAkB,EAC5C,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAGrB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAoCxD,QAAQ,CAAC,MAAM,EAAE,MAAM;IAnCzB,QAAQ,CAAC,EAAE,SAA0C;IACrD,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,SAAS,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB,sCAAsC;IACtC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAa;IACnD,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,EAAE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