footprintjs 0.1.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 +21 -0
- package/README.md +658 -0
- package/dist/advanced.js +84 -0
- package/dist/esm/advanced.js +26 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/lib/builder/FlowChartBuilder.js +809 -0
- package/dist/esm/lib/builder/index.js +12 -0
- package/dist/esm/lib/builder/types.js +9 -0
- package/dist/esm/lib/engine/graph/StageNode.js +38 -0
- package/dist/esm/lib/engine/graph/index.js +2 -0
- package/dist/esm/lib/engine/handlers/ChildrenExecutor.js +116 -0
- package/dist/esm/lib/engine/handlers/ContinuationResolver.js +121 -0
- package/dist/esm/lib/engine/handlers/DeciderHandler.js +78 -0
- package/dist/esm/lib/engine/handlers/ExtractorRunner.js +117 -0
- package/dist/esm/lib/engine/handlers/NodeResolver.js +72 -0
- package/dist/esm/lib/engine/handlers/RuntimeStructureManager.js +154 -0
- package/dist/esm/lib/engine/handlers/SelectorHandler.js +79 -0
- package/dist/esm/lib/engine/handlers/StageRunner.js +86 -0
- package/dist/esm/lib/engine/handlers/SubflowExecutor.js +322 -0
- package/dist/esm/lib/engine/handlers/SubflowInputMapper.js +113 -0
- package/dist/esm/lib/engine/handlers/index.js +23 -0
- package/dist/esm/lib/engine/index.js +18 -0
- package/dist/esm/lib/engine/narrative/CombinedNarrativeBuilder.js +158 -0
- package/dist/esm/lib/engine/narrative/ControlFlowNarrativeGenerator.js +90 -0
- package/dist/esm/lib/engine/narrative/NullControlFlowNarrativeGenerator.js +24 -0
- package/dist/esm/lib/engine/narrative/index.js +4 -0
- package/dist/esm/lib/engine/narrative/types.js +11 -0
- package/dist/esm/lib/engine/traversal/FlowchartTraverser.js +419 -0
- package/dist/esm/lib/engine/traversal/index.js +2 -0
- package/dist/esm/lib/engine/types.js +16 -0
- package/dist/esm/lib/memory/DiagnosticCollector.js +44 -0
- package/dist/esm/lib/memory/EventLog.js +44 -0
- package/dist/esm/lib/memory/SharedMemory.js +53 -0
- package/dist/esm/lib/memory/StageContext.js +221 -0
- package/dist/esm/lib/memory/TransactionBuffer.js +66 -0
- package/dist/esm/lib/memory/index.js +16 -0
- package/dist/esm/lib/memory/types.js +7 -0
- package/dist/esm/lib/memory/utils.js +155 -0
- package/dist/esm/lib/runner/ExecutionRuntime.js +64 -0
- package/dist/esm/lib/runner/FlowChartExecutor.js +108 -0
- package/dist/esm/lib/runner/index.js +3 -0
- package/dist/esm/lib/scope/ScopeFacade.js +175 -0
- package/dist/esm/lib/scope/index.js +19 -0
- package/dist/esm/lib/scope/protection/createProtectedScope.js +59 -0
- package/dist/esm/lib/scope/protection/index.js +3 -0
- package/dist/esm/lib/scope/protection/types.js +8 -0
- package/dist/esm/lib/scope/providers/baseStateCompatible.js +29 -0
- package/dist/esm/lib/scope/providers/guards.js +43 -0
- package/dist/esm/lib/scope/providers/index.js +7 -0
- package/dist/esm/lib/scope/providers/providers.js +18 -0
- package/dist/esm/lib/scope/providers/registry.js +36 -0
- package/dist/esm/lib/scope/providers/resolve.js +11 -0
- package/dist/esm/lib/scope/providers/types.js +8 -0
- package/dist/esm/lib/scope/recorders/DebugRecorder.js +81 -0
- package/dist/esm/lib/scope/recorders/MetricRecorder.js +81 -0
- package/dist/esm/lib/scope/recorders/NarrativeRecorder.js +167 -0
- package/dist/esm/lib/scope/recorders/index.js +4 -0
- package/dist/esm/lib/scope/state/installResolvers.js +15 -0
- package/dist/esm/lib/scope/state/zod/defineScopeFromZod.js +14 -0
- package/dist/esm/lib/scope/state/zod/index.js +5 -0
- package/dist/esm/lib/scope/state/zod/resolver.js +28 -0
- package/dist/esm/lib/scope/state/zod/schema/builder.js +16 -0
- package/dist/esm/lib/scope/state/zod/scopeFactory.js +156 -0
- package/dist/esm/lib/scope/state/zod/utils/validateHelper.js +97 -0
- package/dist/esm/lib/scope/types.js +9 -0
- package/dist/esm/types/advanced.d.ts +35 -0
- package/dist/esm/types/index.d.ts +22 -0
- package/dist/esm/types/lib/builder/FlowChartBuilder.d.ts +121 -0
- package/dist/esm/types/lib/builder/index.d.ts +9 -0
- package/dist/esm/types/lib/builder/types.d.ts +152 -0
- package/dist/esm/types/lib/engine/graph/StageNode.d.ts +78 -0
- package/dist/esm/types/lib/engine/graph/index.d.ts +2 -0
- package/dist/esm/types/lib/engine/handlers/ChildrenExecutor.d.ts +33 -0
- package/dist/esm/types/lib/engine/handlers/ContinuationResolver.d.ts +57 -0
- package/dist/esm/types/lib/engine/handlers/DeciderHandler.d.ts +34 -0
- package/dist/esm/types/lib/engine/handlers/ExtractorRunner.d.ts +41 -0
- package/dist/esm/types/lib/engine/handlers/NodeResolver.d.ts +26 -0
- package/dist/esm/types/lib/engine/handlers/RuntimeStructureManager.d.ts +36 -0
- package/dist/esm/types/lib/engine/handlers/SelectorHandler.d.ts +26 -0
- package/dist/esm/types/lib/engine/handlers/StageRunner.d.ts +17 -0
- package/dist/esm/types/lib/engine/handlers/SubflowExecutor.d.ts +57 -0
- package/dist/esm/types/lib/engine/handlers/SubflowInputMapper.d.ts +40 -0
- package/dist/esm/types/lib/engine/handlers/index.d.ts +15 -0
- package/dist/esm/types/lib/engine/index.d.ts +16 -0
- package/dist/esm/types/lib/engine/narrative/CombinedNarrativeBuilder.d.ts +33 -0
- package/dist/esm/types/lib/engine/narrative/ControlFlowNarrativeGenerator.d.ts +29 -0
- package/dist/esm/types/lib/engine/narrative/NullControlFlowNarrativeGenerator.d.ts +21 -0
- package/dist/esm/types/lib/engine/narrative/index.d.ts +5 -0
- package/dist/esm/types/lib/engine/narrative/types.d.ts +33 -0
- package/dist/esm/types/lib/engine/traversal/FlowchartTraverser.d.ts +87 -0
- package/dist/esm/types/lib/engine/traversal/index.d.ts +2 -0
- package/dist/esm/types/lib/engine/types.d.ts +208 -0
- package/dist/esm/types/lib/memory/DiagnosticCollector.d.ts +33 -0
- package/dist/esm/types/lib/memory/EventLog.d.ts +27 -0
- package/dist/esm/types/lib/memory/SharedMemory.d.ts +34 -0
- package/dist/esm/types/lib/memory/StageContext.d.ts +74 -0
- package/dist/esm/types/lib/memory/TransactionBuffer.d.ts +38 -0
- package/dist/esm/types/lib/memory/index.d.ts +13 -0
- package/dist/esm/types/lib/memory/types.d.ts +60 -0
- package/dist/esm/types/lib/memory/utils.d.ts +67 -0
- package/dist/esm/types/lib/runner/ExecutionRuntime.d.ts +39 -0
- package/dist/esm/types/lib/runner/FlowChartExecutor.d.ts +34 -0
- package/dist/esm/types/lib/runner/index.d.ts +3 -0
- package/dist/esm/types/lib/scope/ScopeFacade.d.ts +47 -0
- package/dist/esm/types/lib/scope/index.d.ts +23 -0
- package/dist/esm/types/lib/scope/protection/createProtectedScope.d.ts +9 -0
- package/dist/esm/types/lib/scope/protection/index.d.ts +2 -0
- package/dist/esm/types/lib/scope/protection/types.d.ts +13 -0
- package/dist/esm/types/lib/scope/providers/baseStateCompatible.d.ts +26 -0
- package/dist/esm/types/lib/scope/providers/guards.d.ts +14 -0
- package/dist/esm/types/lib/scope/providers/index.d.ts +6 -0
- package/dist/esm/types/lib/scope/providers/providers.d.ts +8 -0
- package/dist/esm/types/lib/scope/providers/registry.d.ts +11 -0
- package/dist/esm/types/lib/scope/providers/resolve.d.ts +8 -0
- package/dist/esm/types/lib/scope/providers/types.d.ts +40 -0
- package/dist/esm/types/lib/scope/recorders/DebugRecorder.d.ts +35 -0
- package/dist/esm/types/lib/scope/recorders/MetricRecorder.d.ts +36 -0
- package/dist/esm/types/lib/scope/recorders/NarrativeRecorder.d.ts +45 -0
- package/dist/esm/types/lib/scope/recorders/index.d.ts +7 -0
- package/dist/esm/types/lib/scope/state/installResolvers.d.ts +4 -0
- package/dist/esm/types/lib/scope/state/zod/defineScopeFromZod.d.ts +9 -0
- package/dist/esm/types/lib/scope/state/zod/index.d.ts +5 -0
- package/dist/esm/types/lib/scope/state/zod/resolver.d.ts +5 -0
- package/dist/esm/types/lib/scope/state/zod/schema/builder.d.ts +12 -0
- package/dist/esm/types/lib/scope/state/zod/scopeFactory.d.ts +9 -0
- package/dist/esm/types/lib/scope/state/zod/utils/validateHelper.d.ts +10 -0
- package/dist/esm/types/lib/scope/types.d.ts +53 -0
- package/dist/index.js +42 -0
- package/dist/lib/builder/FlowChartBuilder.js +817 -0
- package/dist/lib/builder/index.js +20 -0
- package/dist/lib/builder/types.js +10 -0
- package/dist/lib/engine/graph/StageNode.js +42 -0
- package/dist/lib/engine/graph/index.js +6 -0
- package/dist/lib/engine/handlers/ChildrenExecutor.js +120 -0
- package/dist/lib/engine/handlers/ContinuationResolver.js +125 -0
- package/dist/lib/engine/handlers/DeciderHandler.js +82 -0
- package/dist/lib/engine/handlers/ExtractorRunner.js +121 -0
- package/dist/lib/engine/handlers/NodeResolver.js +76 -0
- package/dist/lib/engine/handlers/RuntimeStructureManager.js +159 -0
- package/dist/lib/engine/handlers/SelectorHandler.js +83 -0
- package/dist/lib/engine/handlers/StageRunner.js +90 -0
- package/dist/lib/engine/handlers/SubflowExecutor.js +326 -0
- package/dist/lib/engine/handlers/SubflowInputMapper.js +121 -0
- package/dist/lib/engine/handlers/index.js +42 -0
- package/dist/lib/engine/index.js +40 -0
- package/dist/lib/engine/narrative/CombinedNarrativeBuilder.js +162 -0
- package/dist/lib/engine/narrative/ControlFlowNarrativeGenerator.js +94 -0
- package/dist/lib/engine/narrative/NullControlFlowNarrativeGenerator.js +28 -0
- package/dist/lib/engine/narrative/index.js +10 -0
- package/dist/lib/engine/narrative/types.js +12 -0
- package/dist/lib/engine/traversal/FlowchartTraverser.js +423 -0
- package/dist/lib/engine/traversal/index.js +6 -0
- package/dist/lib/engine/types.js +19 -0
- package/dist/lib/memory/DiagnosticCollector.js +48 -0
- package/dist/lib/memory/EventLog.js +48 -0
- package/dist/lib/memory/SharedMemory.js +60 -0
- package/dist/lib/memory/StageContext.js +225 -0
- package/dist/lib/memory/TransactionBuffer.js +73 -0
- package/dist/lib/memory/index.js +34 -0
- package/dist/lib/memory/types.js +8 -0
- package/dist/lib/memory/utils.js +170 -0
- package/dist/lib/runner/ExecutionRuntime.js +68 -0
- package/dist/lib/runner/FlowChartExecutor.js +112 -0
- package/dist/lib/runner/index.js +8 -0
- package/dist/lib/scope/ScopeFacade.js +179 -0
- package/dist/lib/scope/index.js +44 -0
- package/dist/lib/scope/protection/createProtectedScope.js +64 -0
- package/dist/lib/scope/protection/index.js +8 -0
- package/dist/lib/scope/protection/types.js +9 -0
- package/dist/lib/scope/providers/baseStateCompatible.js +33 -0
- package/dist/lib/scope/providers/guards.js +49 -0
- package/dist/lib/scope/providers/index.js +21 -0
- package/dist/lib/scope/providers/providers.js +23 -0
- package/dist/lib/scope/providers/registry.js +42 -0
- package/dist/lib/scope/providers/resolve.js +16 -0
- package/dist/lib/scope/providers/types.js +9 -0
- package/dist/lib/scope/recorders/DebugRecorder.js +85 -0
- package/dist/lib/scope/recorders/MetricRecorder.js +85 -0
- package/dist/lib/scope/recorders/NarrativeRecorder.js +171 -0
- package/dist/lib/scope/recorders/index.js +10 -0
- package/dist/lib/scope/state/installResolvers.js +19 -0
- package/dist/lib/scope/state/zod/defineScopeFromZod.js +18 -0
- package/dist/lib/scope/state/zod/index.js +13 -0
- package/dist/lib/scope/state/zod/resolver.js +31 -0
- package/dist/lib/scope/state/zod/schema/builder.js +21 -0
- package/dist/lib/scope/state/zod/scopeFactory.js +160 -0
- package/dist/lib/scope/state/zod/utils/validateHelper.js +104 -0
- package/dist/lib/scope/types.js +10 -0
- package/dist/types/advanced.d.ts +35 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/lib/builder/FlowChartBuilder.d.ts +121 -0
- package/dist/types/lib/builder/index.d.ts +9 -0
- package/dist/types/lib/builder/types.d.ts +152 -0
- package/dist/types/lib/engine/graph/StageNode.d.ts +78 -0
- package/dist/types/lib/engine/graph/index.d.ts +2 -0
- package/dist/types/lib/engine/handlers/ChildrenExecutor.d.ts +33 -0
- package/dist/types/lib/engine/handlers/ContinuationResolver.d.ts +57 -0
- package/dist/types/lib/engine/handlers/DeciderHandler.d.ts +34 -0
- package/dist/types/lib/engine/handlers/ExtractorRunner.d.ts +41 -0
- package/dist/types/lib/engine/handlers/NodeResolver.d.ts +26 -0
- package/dist/types/lib/engine/handlers/RuntimeStructureManager.d.ts +36 -0
- package/dist/types/lib/engine/handlers/SelectorHandler.d.ts +26 -0
- package/dist/types/lib/engine/handlers/StageRunner.d.ts +17 -0
- package/dist/types/lib/engine/handlers/SubflowExecutor.d.ts +57 -0
- package/dist/types/lib/engine/handlers/SubflowInputMapper.d.ts +40 -0
- package/dist/types/lib/engine/handlers/index.d.ts +15 -0
- package/dist/types/lib/engine/index.d.ts +16 -0
- package/dist/types/lib/engine/narrative/CombinedNarrativeBuilder.d.ts +33 -0
- package/dist/types/lib/engine/narrative/ControlFlowNarrativeGenerator.d.ts +29 -0
- package/dist/types/lib/engine/narrative/NullControlFlowNarrativeGenerator.d.ts +21 -0
- package/dist/types/lib/engine/narrative/index.d.ts +5 -0
- package/dist/types/lib/engine/narrative/types.d.ts +33 -0
- package/dist/types/lib/engine/traversal/FlowchartTraverser.d.ts +87 -0
- package/dist/types/lib/engine/traversal/index.d.ts +2 -0
- package/dist/types/lib/engine/types.d.ts +208 -0
- package/dist/types/lib/memory/DiagnosticCollector.d.ts +33 -0
- package/dist/types/lib/memory/EventLog.d.ts +27 -0
- package/dist/types/lib/memory/SharedMemory.d.ts +34 -0
- package/dist/types/lib/memory/StageContext.d.ts +74 -0
- package/dist/types/lib/memory/TransactionBuffer.d.ts +38 -0
- package/dist/types/lib/memory/index.d.ts +13 -0
- package/dist/types/lib/memory/types.d.ts +60 -0
- package/dist/types/lib/memory/utils.d.ts +67 -0
- package/dist/types/lib/runner/ExecutionRuntime.d.ts +39 -0
- package/dist/types/lib/runner/FlowChartExecutor.d.ts +34 -0
- package/dist/types/lib/runner/index.d.ts +3 -0
- package/dist/types/lib/scope/ScopeFacade.d.ts +47 -0
- package/dist/types/lib/scope/index.d.ts +23 -0
- package/dist/types/lib/scope/protection/createProtectedScope.d.ts +9 -0
- package/dist/types/lib/scope/protection/index.d.ts +2 -0
- package/dist/types/lib/scope/protection/types.d.ts +13 -0
- package/dist/types/lib/scope/providers/baseStateCompatible.d.ts +26 -0
- package/dist/types/lib/scope/providers/guards.d.ts +14 -0
- package/dist/types/lib/scope/providers/index.d.ts +6 -0
- package/dist/types/lib/scope/providers/providers.d.ts +8 -0
- package/dist/types/lib/scope/providers/registry.d.ts +11 -0
- package/dist/types/lib/scope/providers/resolve.d.ts +8 -0
- package/dist/types/lib/scope/providers/types.d.ts +40 -0
- package/dist/types/lib/scope/recorders/DebugRecorder.d.ts +35 -0
- package/dist/types/lib/scope/recorders/MetricRecorder.d.ts +36 -0
- package/dist/types/lib/scope/recorders/NarrativeRecorder.d.ts +45 -0
- package/dist/types/lib/scope/recorders/index.d.ts +7 -0
- package/dist/types/lib/scope/state/installResolvers.d.ts +4 -0
- package/dist/types/lib/scope/state/zod/defineScopeFromZod.d.ts +9 -0
- package/dist/types/lib/scope/state/zod/index.d.ts +5 -0
- package/dist/types/lib/scope/state/zod/resolver.d.ts +5 -0
- package/dist/types/lib/scope/state/zod/schema/builder.d.ts +12 -0
- package/dist/types/lib/scope/state/zod/scopeFactory.d.ts +9 -0
- package/dist/types/lib/scope/state/zod/utils/validateHelper.d.ts +10 -0
- package/dist/types/lib/scope/types.d.ts +53 -0
- package/package.json +148 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SharedMemory — The shared state container for all flowchart execution
|
|
3
|
+
*
|
|
4
|
+
* Like a runtime heap with namespace isolation:
|
|
5
|
+
* - Each run gets its own namespace (runs/{id}/)
|
|
6
|
+
* - Default values can be initialised and preserved
|
|
7
|
+
* - Accepts commit bundles from TransactionBuffer
|
|
8
|
+
*/
|
|
9
|
+
import type { MemoryPatch } from './types';
|
|
10
|
+
export declare class SharedMemory {
|
|
11
|
+
private context;
|
|
12
|
+
private _defaultValues?;
|
|
13
|
+
constructor(defaultValues?: unknown, initialContext?: unknown);
|
|
14
|
+
/** Gets a clone of the default values. */
|
|
15
|
+
getDefaultValues(): {} | undefined;
|
|
16
|
+
/** Gets all run namespaces. */
|
|
17
|
+
getRuns(): any;
|
|
18
|
+
/** Updates a value using merge semantics. */
|
|
19
|
+
updateValue(runId: string, path: string[], key: string, value: unknown): void;
|
|
20
|
+
/** Sets a value using overwrite semantics. */
|
|
21
|
+
setValue(runId: string, path: string[], key: string, value: unknown): void;
|
|
22
|
+
/**
|
|
23
|
+
* Reads a value from the store.
|
|
24
|
+
* Looks up in run namespace first, falls back to global.
|
|
25
|
+
*/
|
|
26
|
+
getValue(runId?: string, path?: string[], key?: string): any;
|
|
27
|
+
/** Gets the entire state as a JSON object. */
|
|
28
|
+
getState(): Record<string, unknown>;
|
|
29
|
+
/** Applies a commit bundle from TransactionBuffer. */
|
|
30
|
+
applyPatch(overwrite: MemoryPatch, updates: MemoryPatch, trace: {
|
|
31
|
+
path: string;
|
|
32
|
+
verb: 'set' | 'merge';
|
|
33
|
+
}[]): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StageContext — Execution context for a single stage in a flowchart run
|
|
3
|
+
*
|
|
4
|
+
* Like a stack frame in a compiler/runtime:
|
|
5
|
+
* - Reference to SharedMemory (accessing heap memory)
|
|
6
|
+
* - TransactionBuffer for staging mutations (transaction buffer)
|
|
7
|
+
* - Links to parent/child/next contexts (call stack frames)
|
|
8
|
+
* - DiagnosticCollector for logs, errors, metrics
|
|
9
|
+
*/
|
|
10
|
+
import { DiagnosticCollector } from './DiagnosticCollector';
|
|
11
|
+
import { EventLog } from './EventLog';
|
|
12
|
+
import { SharedMemory } from './SharedMemory';
|
|
13
|
+
import { TransactionBuffer } from './TransactionBuffer';
|
|
14
|
+
import type { FlowControlType, StageSnapshot } from './types';
|
|
15
|
+
export declare class StageContext {
|
|
16
|
+
private sharedMemory;
|
|
17
|
+
private buffer?;
|
|
18
|
+
private eventLog?;
|
|
19
|
+
stageName: string;
|
|
20
|
+
runId: string;
|
|
21
|
+
branchId?: string;
|
|
22
|
+
isDecider: boolean;
|
|
23
|
+
isFork: boolean;
|
|
24
|
+
parent?: StageContext;
|
|
25
|
+
next?: StageContext;
|
|
26
|
+
children?: StageContext[];
|
|
27
|
+
debug: DiagnosticCollector;
|
|
28
|
+
constructor(runId: string, name: string, sharedMemory: SharedMemory, branchId?: string, eventLog?: EventLog, isDecider?: boolean);
|
|
29
|
+
/** Returns the SharedMemory instance (needed by scope layer). */
|
|
30
|
+
getSharedMemory(): SharedMemory;
|
|
31
|
+
/** Lazily creates the transaction buffer (pay clone cost only if stage writes). */
|
|
32
|
+
getTransactionBuffer(): TransactionBuffer;
|
|
33
|
+
/** Builds an absolute path inside the shared memory (run namespace). */
|
|
34
|
+
private withNamespace;
|
|
35
|
+
patch(path: string[], key: string, value: unknown, shouldRedact?: boolean): void;
|
|
36
|
+
set(path: string[], key: string, value: unknown): void;
|
|
37
|
+
merge(path: string[], key: string, value: unknown): void;
|
|
38
|
+
setObject(path: string[], key: string, value: unknown, shouldRedact?: boolean, description?: string): void;
|
|
39
|
+
updateObject(path: string[], key: string, value: unknown, description?: string): void;
|
|
40
|
+
setRoot(key: string, value: unknown): void;
|
|
41
|
+
setGlobal(key: string, value: unknown, description?: string): void;
|
|
42
|
+
updateGlobalContext(key: string, value: unknown): void;
|
|
43
|
+
appendToArray(path: string[], key: string, items: unknown[], description?: string): void;
|
|
44
|
+
mergeObject(path: string[], key: string, obj: Record<string, unknown>, description?: string): void;
|
|
45
|
+
getValue(path: string[], key?: string, description?: string): any;
|
|
46
|
+
get(path: string[], key?: string): any;
|
|
47
|
+
getRoot(key: string): any;
|
|
48
|
+
getGlobal(key: string): any;
|
|
49
|
+
getFromRoot(key: string): any;
|
|
50
|
+
getFromGlobalContext(key: string): any;
|
|
51
|
+
getScope(): Record<string, unknown>;
|
|
52
|
+
getRunId(): string;
|
|
53
|
+
commit(): void;
|
|
54
|
+
createNext(path: string, stageName: string, isDecider?: boolean): StageContext;
|
|
55
|
+
createChild(runId: string, branchId: string, stageName: string, isDecider?: boolean): StageContext;
|
|
56
|
+
createDecider(path: string, stageName: string): StageContext;
|
|
57
|
+
setAsDecider(): StageContext;
|
|
58
|
+
setAsFork(): StageContext;
|
|
59
|
+
addLog(key: string, value: unknown, path?: string[]): void;
|
|
60
|
+
setLog(key: string, value: unknown, path?: string[]): void;
|
|
61
|
+
addMetric(key: string, value: unknown, path?: string[]): void;
|
|
62
|
+
setMetric(key: string, value: unknown, path?: string[]): void;
|
|
63
|
+
addEval(key: string, value: unknown, path?: string[]): void;
|
|
64
|
+
setEval(key: string, value: unknown, path?: string[]): void;
|
|
65
|
+
addError(key: string, value: unknown, path?: string[]): void;
|
|
66
|
+
addFlowDebugMessage(type: FlowControlType, description: string, options?: {
|
|
67
|
+
targetStage?: string | string[];
|
|
68
|
+
rationale?: string;
|
|
69
|
+
count?: number;
|
|
70
|
+
iteration?: number;
|
|
71
|
+
}): void;
|
|
72
|
+
getStageId(): string;
|
|
73
|
+
getSnapshot(): StageSnapshot;
|
|
74
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TransactionBuffer — Transactional write buffer for stage mutations
|
|
3
|
+
*
|
|
4
|
+
* Collects writes during execution and commits them atomically.
|
|
5
|
+
* Like a database transaction buffer:
|
|
6
|
+
* - Changes staged here before being committed to SharedMemory
|
|
7
|
+
* - Enables read-after-write consistency within a stage
|
|
8
|
+
* - Records operation trace for deterministic replay
|
|
9
|
+
*/
|
|
10
|
+
import type { MemoryPatch } from './types';
|
|
11
|
+
export declare class TransactionBuffer {
|
|
12
|
+
private readonly baseSnapshot;
|
|
13
|
+
private workingCopy;
|
|
14
|
+
private overwritePatch;
|
|
15
|
+
private updatePatch;
|
|
16
|
+
private opTrace;
|
|
17
|
+
private redactedPaths;
|
|
18
|
+
constructor(base: any);
|
|
19
|
+
/** Hard overwrite at the specified path. */
|
|
20
|
+
set(path: (string | number)[], value: any, shouldRedact?: boolean): void;
|
|
21
|
+
/** Deep union merge at the specified path. */
|
|
22
|
+
merge(path: (string | number)[], value: any, shouldRedact?: boolean): void;
|
|
23
|
+
/** Read current value at path (includes uncommitted changes). */
|
|
24
|
+
get(path: (string | number)[], defaultValue?: any): any;
|
|
25
|
+
/**
|
|
26
|
+
* Flush all staged mutations and return the commit bundle.
|
|
27
|
+
* Resets the buffer to empty state after commit.
|
|
28
|
+
*/
|
|
29
|
+
commit(): {
|
|
30
|
+
overwrite: MemoryPatch;
|
|
31
|
+
updates: MemoryPatch;
|
|
32
|
+
redactedPaths: Set<string>;
|
|
33
|
+
trace: {
|
|
34
|
+
path: string;
|
|
35
|
+
verb: 'set' | 'merge';
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory/ — Foundation library (zero external deps beyond lodash)
|
|
3
|
+
*
|
|
4
|
+
* Transactional state management with namespace isolation,
|
|
5
|
+
* atomic commits, and event-sourced time-travel.
|
|
6
|
+
*/
|
|
7
|
+
export { DiagnosticCollector } from './DiagnosticCollector';
|
|
8
|
+
export { EventLog } from './EventLog';
|
|
9
|
+
export { SharedMemory } from './SharedMemory';
|
|
10
|
+
export { StageContext } from './StageContext';
|
|
11
|
+
export { TransactionBuffer } from './TransactionBuffer';
|
|
12
|
+
export type { CommitBundle, FlowControlType, FlowMessage, MemoryPatch, ScopeFactory, StageSnapshot, TraceEntry, } from './types';
|
|
13
|
+
export { applySmartMerge, deepSmartMerge, DELIM, getNestedValue, getRunAndGlobalPaths, normalisePath, redactPatch, setNestedValue, updateNestedValue, updateValue, } from './utils';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — Core type definitions for the memory library
|
|
3
|
+
*
|
|
4
|
+
* Zero dependencies on old code or other libraries in this package.
|
|
5
|
+
*/
|
|
6
|
+
/** A flat key-value bag representing a state patch (overwrite or merge). */
|
|
7
|
+
export interface MemoryPatch {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
/** A single entry in the chronological operation trace. */
|
|
11
|
+
export interface TraceEntry {
|
|
12
|
+
/** Canonical path string (segments joined by DELIM). */
|
|
13
|
+
path: string;
|
|
14
|
+
/** 'set' = hard overwrite, 'merge' = deep union merge. */
|
|
15
|
+
verb: 'set' | 'merge';
|
|
16
|
+
}
|
|
17
|
+
/** The atomic bundle produced by TransactionBuffer.commit(). */
|
|
18
|
+
export interface CommitBundle {
|
|
19
|
+
/** Auto-assigned step index (set by EventLog.record). */
|
|
20
|
+
idx?: number;
|
|
21
|
+
/** Human-readable stage name. */
|
|
22
|
+
stage: string;
|
|
23
|
+
/** Chronological write log for deterministic replay. */
|
|
24
|
+
trace: TraceEntry[];
|
|
25
|
+
/** Paths that should be redacted in UI (sensitive data). */
|
|
26
|
+
redactedPaths: string[];
|
|
27
|
+
/** Hard overwrite patches. */
|
|
28
|
+
overwrite: MemoryPatch;
|
|
29
|
+
/** Deep merge patches. */
|
|
30
|
+
updates: MemoryPatch;
|
|
31
|
+
}
|
|
32
|
+
/** Types of control flow decisions captured by the execution engine. */
|
|
33
|
+
export type FlowControlType = 'next' | 'branch' | 'children' | 'selected' | 'subflow' | 'loop';
|
|
34
|
+
/** A single flow control narrative entry. */
|
|
35
|
+
export interface FlowMessage {
|
|
36
|
+
type: FlowControlType;
|
|
37
|
+
description: string;
|
|
38
|
+
targetStage?: string | string[];
|
|
39
|
+
rationale?: string;
|
|
40
|
+
count?: number;
|
|
41
|
+
iteration?: number;
|
|
42
|
+
timestamp?: number;
|
|
43
|
+
}
|
|
44
|
+
/** Serialisable representation of a stage's state (for debugging / visualisation). */
|
|
45
|
+
export type StageSnapshot = {
|
|
46
|
+
id: string;
|
|
47
|
+
name?: string;
|
|
48
|
+
isDecider?: boolean;
|
|
49
|
+
isFork?: boolean;
|
|
50
|
+
logs: Record<string, unknown>;
|
|
51
|
+
errors: Record<string, unknown>;
|
|
52
|
+
metrics: Record<string, unknown>;
|
|
53
|
+
evals: Record<string, unknown>;
|
|
54
|
+
flowMessages?: FlowMessage[];
|
|
55
|
+
next?: StageSnapshot;
|
|
56
|
+
children?: StageSnapshot[];
|
|
57
|
+
};
|
|
58
|
+
/** Forward-declared so StageContext can accept it without importing scope/. */
|
|
59
|
+
export type ScopeFactory<TScope> = (core: StageContext, stageName: string, readOnlyContext?: unknown) => TScope;
|
|
60
|
+
import type { StageContext } from './StageContext';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* utils.ts — Helper functions for nested object manipulation
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent path traversal and value manipulation for the memory system.
|
|
5
|
+
* Zero external dependencies beyond lodash helpers.
|
|
6
|
+
*/
|
|
7
|
+
import type { MemoryPatch } from './types';
|
|
8
|
+
/** ASCII Unit-Separator — cannot appear in JS identifiers, invisible in logs. */
|
|
9
|
+
export declare const DELIM = "\u001F";
|
|
10
|
+
type NestedObject = {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resolves run-namespaced and global paths.
|
|
15
|
+
* Each flowchart execution (run) stores data under `runs/{id}/` to prevent collisions.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getRunAndGlobalPaths(runId?: string, path?: (string | number)[]): {
|
|
18
|
+
runPath: (string | number)[] | undefined;
|
|
19
|
+
globalPath: (string | number)[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Sets a value at a nested path, creating intermediate objects as needed.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setNestedValue<T>(obj: NestedObject, runId: string, _path: string[], field: string, value: T, defaultValues?: unknown): NestedObject;
|
|
25
|
+
/**
|
|
26
|
+
* Deep-merges a value into the object at the specified path.
|
|
27
|
+
* - Arrays: concatenate
|
|
28
|
+
* - Objects: shallow merge at each level
|
|
29
|
+
* - Primitives: replace
|
|
30
|
+
*/
|
|
31
|
+
export declare function updateNestedValue<T>(obj: any, runId: string | undefined, _path: (string | number)[], field: string | number, value: T, defaultValues?: unknown): any;
|
|
32
|
+
/**
|
|
33
|
+
* In-place value update with merge semantics.
|
|
34
|
+
* - Arrays: concatenate
|
|
35
|
+
* - Objects: shallow merge (spread)
|
|
36
|
+
* - Primitives: direct assignment
|
|
37
|
+
*/
|
|
38
|
+
export declare function updateValue(object: any, key: string | number, value: any): void;
|
|
39
|
+
/**
|
|
40
|
+
* Gets a value at a nested path with prototype-pollution protection.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getNestedValue(root: any, path: (string | number)[], field?: string | number): any;
|
|
43
|
+
/**
|
|
44
|
+
* Redacts sensitive values in a patch for logging/debugging.
|
|
45
|
+
*/
|
|
46
|
+
export declare function redactPatch(patch: MemoryPatch, redactedSet: Set<string>): MemoryPatch;
|
|
47
|
+
/**
|
|
48
|
+
* Normalises an array path into a stable string key using DELIM.
|
|
49
|
+
*/
|
|
50
|
+
export declare function normalisePath(path: (string | number)[]): string;
|
|
51
|
+
/**
|
|
52
|
+
* Deep union merge helper.
|
|
53
|
+
* - Arrays: union without duplicates (encounter order preserved)
|
|
54
|
+
* - Objects: recursive merge
|
|
55
|
+
* - Primitives: source wins
|
|
56
|
+
*/
|
|
57
|
+
export declare function deepSmartMerge(dst: any, src: any): any;
|
|
58
|
+
/**
|
|
59
|
+
* Applies a commit bundle to a base state by replaying operations in order.
|
|
60
|
+
* Two-phase: UPDATE (union-merge) then OVERWRITE (direct set).
|
|
61
|
+
* Guarantees "last writer wins" semantics.
|
|
62
|
+
*/
|
|
63
|
+
export declare function applySmartMerge(base: any, updates: MemoryPatch, overwrite: MemoryPatch, trace: {
|
|
64
|
+
path: string;
|
|
65
|
+
verb: 'set' | 'merge';
|
|
66
|
+
}[]): any;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionRuntime — The runtime environment for one flowchart execution.
|
|
3
|
+
*
|
|
4
|
+
* Wires up the three memory primitives into a single container:
|
|
5
|
+
* - SharedMemory (the heap — shared state across all stages)
|
|
6
|
+
* - StageContext (the call stack — per-stage execution tree)
|
|
7
|
+
* - EventLog (the transaction log — commit history for replay)
|
|
8
|
+
*
|
|
9
|
+
* The engine (FlowchartTraverser) receives this as its runtime parameter.
|
|
10
|
+
* After execution, consumers query it for the full execution state.
|
|
11
|
+
*/
|
|
12
|
+
import { EventLog } from '../memory/EventLog';
|
|
13
|
+
import { SharedMemory } from '../memory/SharedMemory';
|
|
14
|
+
import { StageContext } from '../memory/StageContext';
|
|
15
|
+
import type { CommitBundle, FlowMessage, StageSnapshot } from '../memory/types';
|
|
16
|
+
export interface NarrativeEntry {
|
|
17
|
+
stageId: string;
|
|
18
|
+
stageName: string;
|
|
19
|
+
displayName?: string;
|
|
20
|
+
stageMessages: string[];
|
|
21
|
+
flowMessage?: FlowMessage;
|
|
22
|
+
timeIndex: number;
|
|
23
|
+
}
|
|
24
|
+
export type RuntimeSnapshot = {
|
|
25
|
+
sharedState: Record<string, unknown>;
|
|
26
|
+
executionTree: StageSnapshot;
|
|
27
|
+
commitLog: CommitBundle[];
|
|
28
|
+
};
|
|
29
|
+
export declare class ExecutionRuntime {
|
|
30
|
+
globalStore: SharedMemory;
|
|
31
|
+
rootStageContext: StageContext;
|
|
32
|
+
executionHistory: EventLog;
|
|
33
|
+
constructor(rootName: string, defaultValues?: unknown, initialState?: unknown);
|
|
34
|
+
getPipelines(): string[];
|
|
35
|
+
setRootObject(path: string[], key: string, value: unknown): void;
|
|
36
|
+
getSnapshot(): RuntimeSnapshot;
|
|
37
|
+
getFullNarrative(): NarrativeEntry[];
|
|
38
|
+
private walkContextTree;
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowChartExecutor — Public API for executing a compiled FlowChart.
|
|
3
|
+
*
|
|
4
|
+
* Wraps FlowchartTraverser. Pairs with FlowChartBuilder:
|
|
5
|
+
* const chart = flowChart('entry', entryFn).addFunction('process', processFn).build();
|
|
6
|
+
* const executor = new FlowChartExecutor(chart, scopeFactory);
|
|
7
|
+
* const result = await executor.run();
|
|
8
|
+
*/
|
|
9
|
+
import { type ExtractorError, type FlowChart, type RunOptions, type ScopeFactory, type SerializedPipelineStructure, type StageNode, type StreamHandlers, type SubflowResult, type TraversalResult } from '../engine/types';
|
|
10
|
+
import type { ScopeProtectionMode } from '../scope/protection/types';
|
|
11
|
+
export declare class FlowChartExecutor<TOut = any, TScope = any> {
|
|
12
|
+
private traverser;
|
|
13
|
+
private narrativeEnabled;
|
|
14
|
+
private readonly flowChartArgs;
|
|
15
|
+
constructor(flowChart: FlowChart<TOut, TScope>, scopeFactory: ScopeFactory<TScope>, defaultValuesForContext?: unknown, initialContext?: unknown, readOnlyContext?: unknown, throttlingErrorChecker?: (error: unknown) => boolean, streamHandlers?: StreamHandlers, scopeProtectionMode?: ScopeProtectionMode, enrichSnapshots?: boolean);
|
|
16
|
+
private createTraverser;
|
|
17
|
+
enableNarrative(): void;
|
|
18
|
+
getNarrative(): string[];
|
|
19
|
+
run(options?: RunOptions): Promise<TraversalResult>;
|
|
20
|
+
getSnapshot(): {
|
|
21
|
+
sharedState: Record<string, unknown>;
|
|
22
|
+
executionTree: unknown;
|
|
23
|
+
commitLog: unknown[];
|
|
24
|
+
};
|
|
25
|
+
getRuntime(): import("../engine/types").IExecutionRuntime;
|
|
26
|
+
setRootObject(path: string[], key: string, value: unknown): void;
|
|
27
|
+
getBranchIds(): string[];
|
|
28
|
+
getRuntimeRoot(): StageNode;
|
|
29
|
+
getRuntimeStructure(): SerializedPipelineStructure | undefined;
|
|
30
|
+
getSubflowResults(): Map<string, SubflowResult>;
|
|
31
|
+
getExtractedResults<TResult = unknown>(): Map<string, TResult>;
|
|
32
|
+
getEnrichedResults<TResult = unknown>(): Map<string, TResult>;
|
|
33
|
+
getExtractorErrors(): ExtractorError[];
|
|
34
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScopeFacade — Base class that library consumers extend to create custom scope classes
|
|
3
|
+
*
|
|
4
|
+
* Wraps StageContext (from memory/) to provide a consumer-friendly API for
|
|
5
|
+
* state access, debug logging, metrics, and recorder hooks.
|
|
6
|
+
*
|
|
7
|
+
* Consumers extend this class to add domain-specific properties:
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* class MyScope extends ScopeFacade {
|
|
11
|
+
* get userName(): string { return this.getValue('name') as string; }
|
|
12
|
+
* set userName(value: string) { this.setValue('name', value); }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { StageContext } from '../memory/StageContext';
|
|
17
|
+
import type { CommitEvent, Recorder } from './types';
|
|
18
|
+
export declare class ScopeFacade {
|
|
19
|
+
static readonly BRAND: unique symbol;
|
|
20
|
+
protected _stageContext: StageContext;
|
|
21
|
+
protected _stageName: string;
|
|
22
|
+
protected readonly _readOnlyValues?: unknown;
|
|
23
|
+
private _recorders;
|
|
24
|
+
constructor(context: StageContext, stageName: string, readOnlyValues?: unknown);
|
|
25
|
+
attachRecorder(recorder: Recorder): void;
|
|
26
|
+
detachRecorder(recorderId: string): void;
|
|
27
|
+
getRecorders(): Recorder[];
|
|
28
|
+
notifyStageStart(): void;
|
|
29
|
+
notifyStageEnd(duration?: number): void;
|
|
30
|
+
notifyCommit(mutations: CommitEvent['mutations']): void;
|
|
31
|
+
addDebugInfo(key: string, value: unknown): void;
|
|
32
|
+
addDebugMessage(value: unknown): void;
|
|
33
|
+
addErrorInfo(key: string, value: unknown): void;
|
|
34
|
+
addMetric(metricName: string, value: unknown): void;
|
|
35
|
+
addEval(metricName: string, value: unknown): void;
|
|
36
|
+
getInitialValueFor(key: string): any;
|
|
37
|
+
getValue(key?: string): any;
|
|
38
|
+
setValue(key: string, value: unknown, shouldRedact?: boolean, description?: string): void;
|
|
39
|
+
updateValue(key: string, value: unknown, description?: string): void;
|
|
40
|
+
deleteValue(key: string, description?: string): void;
|
|
41
|
+
setGlobal(key: string, value: unknown, description?: string): void;
|
|
42
|
+
getGlobal(key: string): any;
|
|
43
|
+
setObjectInRoot(key: string, value: unknown): void;
|
|
44
|
+
getReadOnlyValues(): unknown;
|
|
45
|
+
getPipelineId(): string;
|
|
46
|
+
private _invokeHook;
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scope/ — Scope management library
|
|
3
|
+
*
|
|
4
|
+
* Depends on memory/ (Phase 1). Provides ScopeFacade, recorders,
|
|
5
|
+
* providers, protection, and Zod-based scope definitions.
|
|
6
|
+
*/
|
|
7
|
+
export { ScopeFacade } from './ScopeFacade';
|
|
8
|
+
export type { CommitEvent, ErrorEvent, ReadEvent, Recorder, RecorderContext, StageEvent, WriteEvent } from './types';
|
|
9
|
+
export type { DebugEntry, DebugRecorderOptions, DebugVerbosity } from './recorders/DebugRecorder';
|
|
10
|
+
export { DebugRecorder } from './recorders/DebugRecorder';
|
|
11
|
+
export type { AggregatedMetrics, StageMetrics } from './recorders/MetricRecorder';
|
|
12
|
+
export { MetricRecorder } from './recorders/MetricRecorder';
|
|
13
|
+
export type { NarrativeDetail, NarrativeOperation, NarrativeRecorderOptions, StageNarrativeData, } from './recorders/NarrativeRecorder';
|
|
14
|
+
export { NarrativeRecorder } from './recorders/NarrativeRecorder';
|
|
15
|
+
export type { ScopeProtectionMode, ScopeProtectionOptions } from './protection';
|
|
16
|
+
export { createErrorMessage, createProtectedScope } from './protection';
|
|
17
|
+
export type { ProviderResolver, ResolveOptions, ScopeFactory, ScopeProvider, StageContextLike, StrictMode, } from './providers';
|
|
18
|
+
export { __clearScopeResolversForTests, attachBaseStateCompat, attachScopeMethods, isSubclassOfScopeFacade, looksLikeClassCtor, looksLikeFactory, makeClassProvider, makeFactoryProvider, registerScopeResolver, resolveScopeProvider, toScopeFactory, } from './providers';
|
|
19
|
+
export type { DefineScopeOptions } from './state/zod/defineScopeFromZod';
|
|
20
|
+
export { defineScopeFromZod } from './state/zod/defineScopeFromZod';
|
|
21
|
+
export { ZodScopeResolver } from './state/zod/resolver';
|
|
22
|
+
export { defineScopeSchema, isScopeSchema } from './state/zod/schema/builder';
|
|
23
|
+
export { createScopeProxyFromZod } from './state/zod/scopeFactory';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope Protection — Proxy-based protection layer
|
|
3
|
+
*
|
|
4
|
+
* Intercepts direct property assignments on scope objects and provides
|
|
5
|
+
* clear error messages guiding developers to use setValue() instead.
|
|
6
|
+
*/
|
|
7
|
+
import type { ScopeProtectionOptions } from './types';
|
|
8
|
+
export declare function createErrorMessage(propertyName: string, stageName: string): string;
|
|
9
|
+
export declare function createProtectedScope<T extends object>(scope: T, options?: ScopeProtectionOptions): T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope Protection Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the Proxy-based protection system that prevents
|
|
5
|
+
* direct property assignment on scope objects.
|
|
6
|
+
*/
|
|
7
|
+
export type ScopeProtectionMode = 'error' | 'warn' | 'off';
|
|
8
|
+
export interface ScopeProtectionOptions {
|
|
9
|
+
mode?: ScopeProtectionMode;
|
|
10
|
+
stageName?: string;
|
|
11
|
+
logger?: (message: string) => void;
|
|
12
|
+
allowedInternalProperties?: (string | symbol)[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* attachScopeMethods — Attach ScopeFacade-compatible methods onto any target object.
|
|
3
|
+
*
|
|
4
|
+
* Gives non-class scopes (like Zod-generated proxies) the same convenience
|
|
5
|
+
* methods as ScopeFacade subclasses: getValue, setValue, addDebugInfo, etc.
|
|
6
|
+
*
|
|
7
|
+
* API matches ScopeFacade's simplified signatures (no path arrays).
|
|
8
|
+
*/
|
|
9
|
+
import type { StageContextLike } from './types';
|
|
10
|
+
/** @deprecated Use attachScopeMethods instead. */
|
|
11
|
+
export declare const attachBaseStateCompat: typeof attachScopeMethods;
|
|
12
|
+
/** Attach ScopeFacade-compatible methods onto any target (e.g., a proxy scope). */
|
|
13
|
+
export declare function attachScopeMethods<T extends object>(target: T, ctx: StageContextLike, stageName: string, readOnly?: unknown): T & {
|
|
14
|
+
addDebugInfo(k: string, v: unknown): void;
|
|
15
|
+
addDebugMessage(v: unknown): void;
|
|
16
|
+
addErrorInfo(k: string, v: unknown): void;
|
|
17
|
+
addMetric(name: string, v: unknown): void;
|
|
18
|
+
addEval(name: string, v: unknown): void;
|
|
19
|
+
getInitialValueFor(k: string): unknown;
|
|
20
|
+
getValue(key?: string): unknown;
|
|
21
|
+
setValue(key: string, value: unknown, shouldRedact?: boolean, description?: string): void;
|
|
22
|
+
updateValue(key: string, value: unknown, description?: string): void;
|
|
23
|
+
setObjectInRoot(key: string, value: unknown): void;
|
|
24
|
+
getReadOnlyValues(): unknown;
|
|
25
|
+
getPipelineId(): string | undefined;
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards — Heuristic functions for detecting input types
|
|
3
|
+
*
|
|
4
|
+
* Used by the registry to determine whether an input is a class constructor,
|
|
5
|
+
* factory function, or ScopeFacade subclass.
|
|
6
|
+
*/
|
|
7
|
+
type CallableFunction = (...args: unknown[]) => unknown;
|
|
8
|
+
/** Heuristic: class constructor vs. plain function */
|
|
9
|
+
export declare function looksLikeClassCtor(fn: unknown): fn is CallableFunction;
|
|
10
|
+
/** Heuristic: factory function (a function that is NOT a class ctor) */
|
|
11
|
+
export declare function looksLikeFactory(fn: unknown): fn is CallableFunction;
|
|
12
|
+
/** True iff `ctor` is a class that extends ScopeFacade (checks prototype chain) */
|
|
13
|
+
export declare function isSubclassOfScopeFacade(ctor: unknown): boolean;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { attachBaseStateCompat, attachScopeMethods } from './baseStateCompatible';
|
|
2
|
+
export { isSubclassOfScopeFacade, looksLikeClassCtor, looksLikeFactory } from './guards';
|
|
3
|
+
export { makeClassProvider, makeFactoryProvider } from './providers';
|
|
4
|
+
export { __clearScopeResolversForTests, resolveScopeProvider } from './registry';
|
|
5
|
+
export { registerScopeResolver, toScopeFactory } from './resolve';
|
|
6
|
+
export type { ProviderResolver, ResolveOptions, ScopeFactory, ScopeProvider, StageContextLike, StrictMode, } from './types';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Factories — Wrap factory functions and class constructors as ScopeProviders
|
|
3
|
+
*/
|
|
4
|
+
import type { ScopeFactory, ScopeProvider, StageContextLike } from './types';
|
|
5
|
+
/** Wrap an existing factory function as a ScopeProvider */
|
|
6
|
+
export declare function makeFactoryProvider<TScope>(factory: ScopeFactory<TScope>): ScopeProvider<TScope>;
|
|
7
|
+
/** Wrap a class constructor as a ScopeProvider */
|
|
8
|
+
export declare function makeClassProvider<TScope>(Ctor: new (ctx: StageContextLike, stageName: string, readOnly?: unknown) => TScope): ScopeProvider<TScope>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry — Central registry for scope provider resolvers
|
|
3
|
+
*
|
|
4
|
+
* Maintains a list of registered resolvers. Resolvers are checked in
|
|
5
|
+
* registration order (first match wins). Built-in resolvers (class, factory)
|
|
6
|
+
* are checked last as fallback.
|
|
7
|
+
*/
|
|
8
|
+
import type { ProviderResolver, ResolveOptions, ScopeProvider } from './types';
|
|
9
|
+
export declare function registerScopeResolver(resolver: ProviderResolver): void;
|
|
10
|
+
export declare function __clearScopeResolversForTests(): void;
|
|
11
|
+
export declare function resolveScopeProvider<TScope>(input: unknown, options?: ResolveOptions): ScopeProvider<TScope>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolve.ts — Public API for converting scope inputs to ScopeFactory
|
|
3
|
+
*/
|
|
4
|
+
import type { ResolveOptions, ScopeFactory } from './types';
|
|
5
|
+
/** Normalize a factory/class/schema-like input into a ScopeFactory the pipeline expects */
|
|
6
|
+
export declare function toScopeFactory<TScope>(input: unknown, options?: ResolveOptions): ScopeFactory<TScope>;
|
|
7
|
+
export { registerScopeResolver } from './registry';
|
|
8
|
+
export type { ResolveOptions, ScopeProvider } from './types';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider System Types
|
|
3
|
+
*
|
|
4
|
+
* Defines contracts between the registry, resolvers, and providers.
|
|
5
|
+
* StageContextLike is the minimal surface from StageContext to avoid tight coupling.
|
|
6
|
+
*/
|
|
7
|
+
/** Minimal surface from StageContext (patch-based) */
|
|
8
|
+
export interface StageContextLike {
|
|
9
|
+
getValue(path: string[], key?: string): unknown;
|
|
10
|
+
setObject(path: string[], key: string, value: unknown, shouldRedact?: boolean, description?: string): void;
|
|
11
|
+
updateObject(path: string[], key: string, value: unknown, description?: string): void;
|
|
12
|
+
addLog?(key: string, val: unknown): void;
|
|
13
|
+
addError?(key: string, val: unknown): void;
|
|
14
|
+
getFromGlobalContext?(key: string): unknown;
|
|
15
|
+
setRoot?(key: string, value: unknown): void;
|
|
16
|
+
setGlobal?(key: string, value: unknown, description?: string): void;
|
|
17
|
+
pipelineId?: string;
|
|
18
|
+
runId?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Factory type the pipeline expects */
|
|
21
|
+
export type ScopeFactory<TScope> = (ctx: StageContextLike, stageName: string, readOnly?: unknown) => TScope;
|
|
22
|
+
/** Strategy object that creates a scope */
|
|
23
|
+
export interface ScopeProvider<TScope> {
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
create(ctx: StageContextLike, stageName: string, readOnly?: unknown): TScope;
|
|
26
|
+
}
|
|
27
|
+
/** Resolver that can turn an arbitrary input into a ScopeProvider */
|
|
28
|
+
export interface ProviderResolver<TScope = any> {
|
|
29
|
+
name: string;
|
|
30
|
+
canHandle(input: unknown): boolean;
|
|
31
|
+
makeProvider(input: unknown, options?: unknown): ScopeProvider<TScope>;
|
|
32
|
+
}
|
|
33
|
+
/** Optional strictness for schema-backed providers */
|
|
34
|
+
export type StrictMode = 'off' | 'warn' | 'deny';
|
|
35
|
+
/** Options bag passed to resolve() */
|
|
36
|
+
export type ResolveOptions = {
|
|
37
|
+
zod?: {
|
|
38
|
+
strict?: StrictMode;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DebugRecorder — Development-focused recorder for detailed debugging
|
|
3
|
+
*
|
|
4
|
+
* Captures errors (always), mutations and reads (in verbose mode),
|
|
5
|
+
* and stage lifecycle events for troubleshooting.
|
|
6
|
+
*/
|
|
7
|
+
import type { ErrorEvent, ReadEvent, Recorder, StageEvent, WriteEvent } from '../types';
|
|
8
|
+
export type DebugVerbosity = 'minimal' | 'verbose';
|
|
9
|
+
export interface DebugEntry {
|
|
10
|
+
type: 'read' | 'write' | 'error' | 'stageStart' | 'stageEnd';
|
|
11
|
+
stageName: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
data: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface DebugRecorderOptions {
|
|
16
|
+
id?: string;
|
|
17
|
+
verbosity?: DebugVerbosity;
|
|
18
|
+
}
|
|
19
|
+
export declare class DebugRecorder implements Recorder {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
private entries;
|
|
22
|
+
private verbosity;
|
|
23
|
+
constructor(options?: DebugRecorderOptions);
|
|
24
|
+
onRead(event: ReadEvent): void;
|
|
25
|
+
onWrite(event: WriteEvent): void;
|
|
26
|
+
onError(event: ErrorEvent): void;
|
|
27
|
+
onStageStart(event: StageEvent): void;
|
|
28
|
+
onStageEnd(event: StageEvent): void;
|
|
29
|
+
getEntries(): DebugEntry[];
|
|
30
|
+
getErrors(): DebugEntry[];
|
|
31
|
+
getEntriesForStage(stageName: string): DebugEntry[];
|
|
32
|
+
setVerbosity(level: DebugVerbosity): void;
|
|
33
|
+
getVerbosity(): DebugVerbosity;
|
|
34
|
+
clear(): void;
|
|
35
|
+
}
|