@telorun/sdk 0.2.7 → 0.2.8
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/dist/evaluation-context.d.ts +11 -102
- package/dist/evaluation-context.d.ts.map +1 -1
- package/dist/evaluation-context.js +0 -390
- package/dist/module-context.d.ts +12 -36
- package/dist/module-context.d.ts.map +1 -1
- package/dist/module-context.js +1 -177
- package/package.json +19 -1
- package/src/evaluation-context.ts +34 -461
- package/src/module-context.ts +22 -203
- package/src/execution-context.ts +0 -21
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import { ResourceInstance } from "./resource-instance.js";
|
|
5
|
-
import { ResourceManifest } from "./resource-manifest.js";
|
|
6
|
-
import { RuntimeDiagnostic } from "./runtime-error.js";
|
|
7
|
-
import { RuntimeError } from "./types.js";
|
|
1
|
+
import type { ScopeHandle } from "./ref.js";
|
|
2
|
+
import type { ResourceInstance } from "./resource-instance.js";
|
|
3
|
+
import type { ResourceManifest } from "./resource-manifest.js";
|
|
8
4
|
|
|
9
5
|
export type EmitEvent = (event: string, payload?: any) => void | Promise<void>;
|
|
10
6
|
|
|
@@ -25,7 +21,7 @@ export type CreatedResource = { instance: ResourceInstance; ctx: any };
|
|
|
25
21
|
* init() separately in a second phase.
|
|
26
22
|
*/
|
|
27
23
|
export type InstanceFactory = (
|
|
28
|
-
|
|
24
|
+
context: EvaluationContext,
|
|
29
25
|
resource: ResourceManifest,
|
|
30
26
|
) => Promise<CreatedResource | null>;
|
|
31
27
|
|
|
@@ -49,471 +45,48 @@ export function resourceKey(r: ResourceManifest): string {
|
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
/**
|
|
52
|
-
*
|
|
53
|
-
* expansion, secrets redaction, and the generic resource lifecycle tree.
|
|
48
|
+
* Public contract for the base evaluation context.
|
|
54
49
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* - Queue resources for initialization (pendingResources)
|
|
58
|
-
* - Spawn child contexts (spawnChild) forming a lifecycle tree
|
|
59
|
-
* - Run a multi-pass initialization loop (initializeResources)
|
|
60
|
-
* - Cascade teardown depth-first through the tree (teardownResources)
|
|
50
|
+
* Owns template expansion, secrets redaction, and the generic resource lifecycle tree.
|
|
51
|
+
* The class implementation lives in `@telorun/kernel`.
|
|
61
52
|
*/
|
|
62
|
-
export
|
|
63
|
-
readonly id
|
|
64
|
-
|
|
65
|
-
protected _secretValues: Set<string>;
|
|
66
|
-
protected _createInstance: InstanceFactory;
|
|
53
|
+
export interface EvaluationContext {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly source: string;
|
|
67
56
|
readonly emit: EmitEvent;
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
readonly children: EvaluationContext[] = [];
|
|
58
|
+
parent: EvaluationContext | undefined;
|
|
59
|
+
readonly children: EvaluationContext[];
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
state: LifecycleState = "Pending";
|
|
61
|
+
state: LifecycleState;
|
|
75
62
|
|
|
76
|
-
|
|
77
|
-
readonly resourceInstances = new Map<
|
|
63
|
+
readonly resourceInstances: Map<
|
|
78
64
|
string,
|
|
79
65
|
{ resource: ResourceManifest; instance: ResourceInstance }
|
|
80
|
-
|
|
66
|
+
>;
|
|
81
67
|
|
|
82
|
-
/** Resources that have been created but not yet initialized (between phases). */
|
|
83
|
-
protected readonly createdInstances = new Map<
|
|
84
|
-
string,
|
|
85
|
-
{ resource: ResourceManifest; instance: ResourceInstance; ctx: any }
|
|
86
|
-
>();
|
|
87
|
-
|
|
88
|
-
/** Resources queued for initialization on this context node. */
|
|
89
|
-
private pendingResources: ResourceManifest[] = [];
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Optional hook called between create() and init() for each resource.
|
|
93
|
-
* Set by the kernel to inject live instances into reference fields.
|
|
94
|
-
*/
|
|
95
68
|
preInitHook?: PreInitHook;
|
|
96
69
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
/** Called after init() when a resource snapshot is available. Overridden by ModuleContext. */
|
|
115
|
-
protected onResourceSnapshotted(_name: string, _snap: Record<string, unknown>): void {}
|
|
116
|
-
|
|
117
|
-
get context(): Record<string, unknown> {
|
|
118
|
-
return this._context;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
get secretValues(): Set<string> {
|
|
122
|
-
return this._secretValues;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Reorder pending resources to match the given name sequence (topo order from Phase 4).
|
|
127
|
-
* Resources not present in `names` are left at the end in their original order.
|
|
128
|
-
* Call before initializeResources() so the create/init sub-phases run in dependency order,
|
|
129
|
-
* guaranteeing that Phase 5 injection always finds initialized dependencies.
|
|
130
|
-
*/
|
|
131
|
-
setInitOrder(names: string[]): void {
|
|
132
|
-
const rank = new Map(names.map((n, i) => [n, i]));
|
|
133
|
-
this.pendingResources.sort((a, b) => {
|
|
134
|
-
const ra = rank.get(a.metadata.name as string) ?? Infinity;
|
|
135
|
-
const rb = rank.get(b.metadata.name as string) ?? Infinity;
|
|
136
|
-
return ra - rb;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Queue a resource manifest for initialization on this context.
|
|
142
|
-
*/
|
|
143
|
-
hasManifest(name: string): boolean {
|
|
144
|
-
return (
|
|
145
|
-
this.resourceInstances.has(name) ||
|
|
146
|
-
this.createdInstances.has(name) ||
|
|
147
|
-
this.pendingResources.some((r) => r.metadata.name === name)
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
registerManifest(resource: ResourceManifest): void {
|
|
152
|
-
if (!resource.metadata) {
|
|
153
|
-
resource.metadata = { name: `__unnamed_${Math.random().toString(16).slice(2, 8)}` };
|
|
154
|
-
}
|
|
155
|
-
const name = resource.metadata.name;
|
|
156
|
-
if (this.hasManifest(name)) {
|
|
157
|
-
throw new RuntimeError("ERR_DUPLICATE_RESOURCE", `Resource '${name}' is already registered`);
|
|
158
|
-
}
|
|
159
|
-
this.pendingResources.push(resource);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Attach a child context to this node. The child's parent is set to this
|
|
164
|
-
* context and the child is registered under the given name.
|
|
165
|
-
*/
|
|
166
|
-
spawnChild<T extends EvaluationContext>(child: T): T {
|
|
167
|
-
child.parent = this;
|
|
168
|
-
this.children.push(child);
|
|
169
|
-
// Propagate injection hook so all child contexts (module imports, scopes) participate
|
|
170
|
-
// in Phase 5 injection. createScopeHandle overrides this with an extended version.
|
|
171
|
-
if (this.preInitHook && !child.preInitHook) {
|
|
172
|
-
child.preInitHook = this.preInitHook;
|
|
173
|
-
}
|
|
174
|
-
return child;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Interleaved create/init loop.
|
|
179
|
-
*
|
|
180
|
-
* Each pass has two sub-phases run back-to-back:
|
|
181
|
-
* 1. Create sub-phase: call controller.create() for each pending resource that
|
|
182
|
-
* hasn't been created yet. Successful results go into createdInstances.
|
|
183
|
-
* 2. Init sub-phase: call instance.init(ctx) for each created-but-not-inited
|
|
184
|
-
* resource. Successful results go into resourceInstances.
|
|
185
|
-
*
|
|
186
|
-
* Interleaving is necessary because some resources' create() depends on effects
|
|
187
|
-
* produced by other resources' init() (e.g. Kernel.Import.init() runs
|
|
188
|
-
* child.initializeResources() which registers controllers needed by sibling
|
|
189
|
-
* resources' create()). Running both sub-phases each pass lets those effects
|
|
190
|
-
* propagate before the next create attempt.
|
|
191
|
-
*
|
|
192
|
-
* Each resource is created at most once and inited at most once.
|
|
193
|
-
* ERR_VISIBILITY_DENIED is fatal and re-thrown immediately.
|
|
194
|
-
* All other errors are tracked and retried until no progress is made.
|
|
195
|
-
*/
|
|
196
|
-
async initializeResources(): Promise<void> {
|
|
197
|
-
const MAX_PASSES = 10;
|
|
198
|
-
const errors = new Map<string, string>();
|
|
199
|
-
|
|
200
|
-
let pass = 1;
|
|
201
|
-
do {
|
|
202
|
-
let progress = false;
|
|
203
|
-
|
|
204
|
-
// Create sub-phase
|
|
205
|
-
for (const resource of [...this.pendingResources]) {
|
|
206
|
-
const name = resource.metadata.name;
|
|
207
|
-
if (this.createdInstances.has(name)) continue;
|
|
208
|
-
try {
|
|
209
|
-
// const expanded = this.expand(resource) as ResourceManifest;
|
|
210
|
-
// FIXME: Cannot expand it for all resources, needs to be selective
|
|
211
|
-
const created = await this._createInstance(this as any, resource);
|
|
212
|
-
if (created) {
|
|
213
|
-
this.createdInstances.set(name, {
|
|
214
|
-
resource,
|
|
215
|
-
instance: created.instance,
|
|
216
|
-
ctx: created.ctx,
|
|
217
|
-
});
|
|
218
|
-
const idx = this.pendingResources.findIndex((m) => m.metadata.name === name);
|
|
219
|
-
if (idx >= 0) this.pendingResources.splice(idx, 1);
|
|
220
|
-
errors.delete(name);
|
|
221
|
-
progress = true;
|
|
222
|
-
}
|
|
223
|
-
} catch (error) {
|
|
224
|
-
if (error instanceof RuntimeError && error.code === "ERR_VISIBILITY_DENIED") throw error;
|
|
225
|
-
errors.set(name, error instanceof Error ? error.message : String(error));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Init sub-phase
|
|
230
|
-
for (const [name, { resource, instance, ctx }] of [...this.createdInstances]) {
|
|
231
|
-
if (this.resourceInstances.has(name)) continue;
|
|
232
|
-
try {
|
|
233
|
-
if (this.preInitHook) {
|
|
234
|
-
this.preInitHook(resource, (n) => this.resourceInstances.get(n)?.instance);
|
|
235
|
-
}
|
|
236
|
-
if (instance.init) await instance.init(ctx);
|
|
237
|
-
if (instance.snapshot) {
|
|
238
|
-
const snap = await Promise.resolve(instance.snapshot()).catch(() => ({}));
|
|
239
|
-
this.onResourceSnapshotted(name, (snap as Record<string, unknown>) ?? {});
|
|
240
|
-
}
|
|
241
|
-
this.resourceInstances.set(name, { resource, instance });
|
|
242
|
-
this.createdInstances.delete(name);
|
|
243
|
-
errors.delete(name);
|
|
244
|
-
progress = true;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
if (error instanceof RuntimeError && error.code === "ERR_VISIBILITY_DENIED") throw error;
|
|
247
|
-
errors.set(name, error instanceof Error ? error.message : String(error));
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
pass++;
|
|
252
|
-
if (!progress) break;
|
|
253
|
-
} while (pass <= MAX_PASSES);
|
|
254
|
-
|
|
255
|
-
if (this.pendingResources.length > 0 || this.createdInstances.size > 0) {
|
|
256
|
-
const diagnostics: RuntimeDiagnostic[] = [
|
|
257
|
-
...this.pendingResources.map((r) => ({
|
|
258
|
-
resource: r.metadata.name,
|
|
259
|
-
message: errors.get(r.metadata.name) ?? "Unknown error",
|
|
260
|
-
})),
|
|
261
|
-
...[...this.createdInstances.keys()].map((name) => ({
|
|
262
|
-
resource: name,
|
|
263
|
-
message: errors.get(name) ?? "Unknown error",
|
|
264
|
-
})),
|
|
265
|
-
];
|
|
266
|
-
throw new RuntimeError(
|
|
267
|
-
"ERR_RESOURCE_INITIALIZATION_FAILED",
|
|
268
|
-
"Unable to process resources",
|
|
269
|
-
diagnostics,
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
this.state = "Initialized";
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
withManifests<T>(manifests: any[], fn: () => T): T {
|
|
277
|
-
const child = this.spawnChild(
|
|
278
|
-
new EvaluationContext(
|
|
279
|
-
this.source,
|
|
280
|
-
this._context,
|
|
281
|
-
this._createInstance,
|
|
282
|
-
this._secretValues,
|
|
283
|
-
this.emit,
|
|
284
|
-
),
|
|
285
|
-
);
|
|
286
|
-
try {
|
|
287
|
-
for (const manifest of manifests) {
|
|
288
|
-
child.registerManifest(manifest);
|
|
289
|
-
}
|
|
290
|
-
return fn();
|
|
291
|
-
} finally {
|
|
292
|
-
// Tear down child context and its resources immediately after fn() completes.
|
|
293
|
-
// Note that this does NOT emit Kernel-level events (e.g. Teardown events) —
|
|
294
|
-
// they remain the Kernel's responsibility.
|
|
295
|
-
child.teardownResources();
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Returns a ScopeHandle that initializes `manifests` in a fresh child context each time
|
|
301
|
-
* `run()` is called, executes the callback with a ScopeContext, and tears down when done.
|
|
302
|
-
*
|
|
303
|
-
* The child inherits the parent's preInitHook (if any), extended so that `getInstance`
|
|
304
|
-
* also checks the parent's already-initialized singleton instances. This lets scoped
|
|
305
|
-
* resources hold x-telo-ref slots pointing to outer resources — those deps are already
|
|
306
|
-
* live when the scope opens.
|
|
307
|
-
*/
|
|
308
|
-
createScopeHandle(manifests: ResourceManifest[]): ScopeHandle {
|
|
309
|
-
const parent = this;
|
|
310
|
-
return {
|
|
311
|
-
async run<T>(fn: (scope: ScopeContext) => Promise<T>): Promise<T> {
|
|
312
|
-
const child = parent.spawnChild(
|
|
313
|
-
new EvaluationContext(
|
|
314
|
-
parent.source,
|
|
315
|
-
parent._context,
|
|
316
|
-
parent._createInstance,
|
|
317
|
-
parent._secretValues,
|
|
318
|
-
parent.emit,
|
|
319
|
-
),
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
// Propagate injection hook: extend getInstance to also resolve parent singleton instances.
|
|
323
|
-
if (parent.preInitHook) {
|
|
324
|
-
const parentHook = parent.preInitHook;
|
|
325
|
-
child.preInitHook = (resource, childGetInstance) => {
|
|
326
|
-
parentHook(
|
|
327
|
-
resource,
|
|
328
|
-
(name) => childGetInstance(name) ?? parent.resourceInstances.get(name)?.instance,
|
|
329
|
-
);
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
try {
|
|
334
|
-
for (const manifest of manifests) {
|
|
335
|
-
child.registerManifest(manifest);
|
|
336
|
-
}
|
|
337
|
-
await child.initializeResources();
|
|
338
|
-
const scope: ScopeContext = {
|
|
339
|
-
getInstance(name: string): ResourceInstance {
|
|
340
|
-
const childEntry = child.resourceInstances.get(name);
|
|
341
|
-
if (childEntry) return childEntry.instance;
|
|
342
|
-
const parentEntry = parent.resourceInstances.get(name);
|
|
343
|
-
if (parentEntry) return parentEntry.instance;
|
|
344
|
-
throw new RuntimeError(
|
|
345
|
-
"ERR_SCOPE_RESOURCE_NOT_FOUND",
|
|
346
|
-
`Resource '${name}' not found in scope or outer context. Available scoped: ${[...child.resourceInstances.keys()].join(", ")}`,
|
|
347
|
-
);
|
|
348
|
-
},
|
|
349
|
-
};
|
|
350
|
-
return await fn(scope);
|
|
351
|
-
} finally {
|
|
352
|
-
await child.teardownResources();
|
|
353
|
-
const idx = parent.children.indexOf(child);
|
|
354
|
-
if (idx >= 0) parent.children.splice(idx, 1);
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Cascade teardown depth-first through the tree:
|
|
362
|
-
* 1. Tear down child contexts in reverse registration order.
|
|
363
|
-
* 2. Tear down own resource instances in reverse registration order,
|
|
364
|
-
* emitting a Teardown event for each via the injected emit callback.
|
|
365
|
-
*/
|
|
366
|
-
async teardownResources(): Promise<void> {
|
|
367
|
-
this.state = "Draining";
|
|
368
|
-
for (const child of [...this.children].reverse()) {
|
|
369
|
-
await child.teardownResources();
|
|
370
|
-
}
|
|
371
|
-
const entries = [...this.resourceInstances.entries()].reverse();
|
|
372
|
-
for (const [key, { resource, instance }] of entries) {
|
|
373
|
-
if (instance.teardown) await instance.teardown();
|
|
374
|
-
await this.emit(`${resource.kind}.${resource.metadata.name}.Teardown`, {
|
|
375
|
-
resource: { kind: resource.kind, name: resource.metadata.name },
|
|
376
|
-
});
|
|
377
|
-
this.resourceInstances.delete(key);
|
|
378
|
-
}
|
|
379
|
-
this.state = "Teardown";
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
transientChild(context: Record<string, any>): EvaluationContext {
|
|
383
|
-
return new EvaluationContext(
|
|
384
|
-
this.source,
|
|
385
|
-
{ ...this.context, ...context },
|
|
386
|
-
this._createInstance,
|
|
387
|
-
this._secretValues,
|
|
388
|
-
this.emit,
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Invoke a resource by kind and name within this context's resourceInstances.
|
|
394
|
-
* Emits a scoped Invoked event via the injected emit callback after invocation.
|
|
395
|
-
*/
|
|
396
|
-
async invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any> {
|
|
397
|
-
const entry = this.resourceInstances.get(name);
|
|
398
|
-
|
|
399
|
-
if (entry) {
|
|
400
|
-
if (typeof entry.instance.invoke !== "function") {
|
|
401
|
-
throw new RuntimeError(
|
|
402
|
-
"ERR_RESOURCE_NOT_INVOKABLE",
|
|
403
|
-
`Resource ${kind}.${name} does not have an invoke method`,
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
const outputs = await entry.instance.invoke(inputs as any);
|
|
407
|
-
await this.emit(`${kind}.${name}.Invoked`, { outputs });
|
|
408
|
-
return outputs;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
throw new RuntimeError(
|
|
412
|
-
"ERR_RESOURCE_NOT_FOUND",
|
|
413
|
-
`Resource not found for invocation: ${kind}.${name}. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`,
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async run(name: string): Promise<void> {
|
|
418
|
-
const entry = this.resourceInstances.get(name);
|
|
419
|
-
if (entry && typeof entry.instance.run === "function") {
|
|
420
|
-
return entry.instance.run();
|
|
421
|
-
}
|
|
422
|
-
throw new RuntimeError(
|
|
423
|
-
"ERR_RESOURCE_NOT_RUNNABLE",
|
|
424
|
-
`Resource ${name} is not runnable or not found. Available resources: ${[...this.resourceInstances.keys()].join(", ")}`,
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Expand a value that may contain precompiled ${{ }} templates.
|
|
430
|
-
* Works recursively over CompiledValues, arrays, and objects.
|
|
431
|
-
*/
|
|
432
|
-
expand(value: unknown): unknown {
|
|
433
|
-
if (isCompiledValue(value)) {
|
|
434
|
-
return value.call(this._context);
|
|
435
|
-
}
|
|
436
|
-
if (Array.isArray(value)) {
|
|
437
|
-
return value.map((entry) => this.expand(entry));
|
|
438
|
-
}
|
|
439
|
-
if (value !== null && typeof value === "object") {
|
|
440
|
-
const resolved: Record<string, unknown> = {};
|
|
441
|
-
for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
|
|
442
|
-
resolved[key] = this.expand(entry);
|
|
443
|
-
}
|
|
444
|
-
return resolved;
|
|
445
|
-
}
|
|
446
|
-
return value;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Expand a value using this context merged with additional properties.
|
|
451
|
-
* Equivalent to merge(extraContext).expand(value) without allocating a context object.
|
|
452
|
-
*/
|
|
453
|
-
expandWith(value: unknown, extraContext: Record<string, unknown>): unknown {
|
|
454
|
-
const saved = this._context;
|
|
455
|
-
this._context = Object.assign(Object.create(null), saved, extraContext) as Record<
|
|
456
|
-
string,
|
|
457
|
-
unknown
|
|
458
|
-
>;
|
|
459
|
-
try {
|
|
460
|
-
return this.expand(value);
|
|
461
|
-
} finally {
|
|
462
|
-
this._context = saved;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Expand specific dot-paths within an object. '**' expands the entire object.
|
|
468
|
-
* Paths listed in excludePaths are left untouched (runtime takes precedence).
|
|
469
|
-
* Always throws if an expression cannot be resolved.
|
|
470
|
-
*/
|
|
70
|
+
readonly createInstance: InstanceFactory;
|
|
71
|
+
readonly context: Record<string, unknown>;
|
|
72
|
+
readonly secretValues: Set<string>;
|
|
73
|
+
|
|
74
|
+
setInitOrder(names: string[]): void;
|
|
75
|
+
hasManifest(name: string): boolean;
|
|
76
|
+
registerManifest(resource: ResourceManifest): void;
|
|
77
|
+
spawnChild<T extends EvaluationContext>(child: T): T;
|
|
78
|
+
initializeResources(): Promise<void>;
|
|
79
|
+
withManifests<T>(manifests: any[], fn: () => T): T;
|
|
80
|
+
createScopeHandle(manifests: ResourceManifest[]): ScopeHandle;
|
|
81
|
+
teardownResources(): Promise<void>;
|
|
82
|
+
transientChild(context: Record<string, any>): EvaluationContext;
|
|
83
|
+
invoke<TInputs>(kind: string, name: string, inputs: TInputs): Promise<any>;
|
|
84
|
+
run(name: string): Promise<void>;
|
|
85
|
+
expand(value: unknown): unknown;
|
|
86
|
+
expandWith(value: unknown, extraContext: Record<string, unknown>): unknown;
|
|
471
87
|
expandPaths(
|
|
472
88
|
value: Record<string, unknown>,
|
|
473
89
|
paths: string[],
|
|
474
|
-
excludePaths
|
|
475
|
-
): Record<string, unknown
|
|
476
|
-
if (paths.includes("**")) {
|
|
477
|
-
const result: Record<string, unknown> = {};
|
|
478
|
-
for (const [key, v] of Object.entries(value)) {
|
|
479
|
-
result[key] = isExcluded(key, excludePaths) ? v : this.expand(v);
|
|
480
|
-
}
|
|
481
|
-
return result;
|
|
482
|
-
}
|
|
483
|
-
const result = { ...value };
|
|
484
|
-
for (const path of paths) {
|
|
485
|
-
if (isExcluded(path, excludePaths)) continue;
|
|
486
|
-
const parts = path.split(".");
|
|
487
|
-
const current = getNestedValue(result, parts);
|
|
488
|
-
if (current !== undefined) {
|
|
489
|
-
setNestedValue(result, parts, this.expand(current));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
return result;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
function isExcluded(path: string, excludePaths: string[]): boolean {
|
|
497
|
-
return excludePaths.some(
|
|
498
|
-
(ep) => ep === path || ep === "**" || path.startsWith(ep + ".") || ep.startsWith(path + "."),
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
function getNestedValue(obj: Record<string, unknown>, parts: string[]): unknown {
|
|
503
|
-
let current: unknown = obj;
|
|
504
|
-
for (const part of parts) {
|
|
505
|
-
if (current === null || typeof current !== "object") return undefined;
|
|
506
|
-
current = (current as Record<string, unknown>)[part];
|
|
507
|
-
}
|
|
508
|
-
return current;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function setNestedValue(obj: Record<string, unknown>, parts: string[], value: unknown): void {
|
|
512
|
-
let current: Record<string, unknown> = obj;
|
|
513
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
514
|
-
const next = current[parts[i]];
|
|
515
|
-
if (next === null || typeof next !== "object") return;
|
|
516
|
-
current = next as Record<string, unknown>;
|
|
517
|
-
}
|
|
518
|
-
current[parts[parts.length - 1]] = value;
|
|
90
|
+
excludePaths?: string[],
|
|
91
|
+
): Record<string, unknown>;
|
|
519
92
|
}
|