mcard-js
Version:
MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers
103 lines • 2.71 kB
TypeScript
/**
* IO Effects - Observable side-effects for Lambda Calculus computations
*
* Implements the IO Monad pattern for CLM:
* IO a = World → (a, World')
*
* In our context:
* Reduction = TermHash → (TermHash', IOEffects)
*
* IO effects are purely observational - they do not affect computation results.
* The same input will always produce the same output regardless of IO configuration.
*
* @module mcard-js/ptr/lambda/IOEffects
*/
export type IOFormat = 'minimal' | 'verbose' | 'json';
export interface NetworkConfig {
enabled: boolean;
endpoint?: string;
method?: 'POST' | 'PUT';
headers?: Record<string, string>;
}
export interface IOEffectsConfig {
enabled: boolean;
console?: boolean;
network?: NetworkConfig;
onStep?: boolean;
onComplete?: boolean;
onError?: boolean;
format?: IOFormat;
}
export interface StepEvent {
type: 'step';
stepNumber: number;
termHash: string;
prettyPrint: string;
timestamp: Date;
}
export interface CompleteEvent {
type: 'complete';
normalForm: string;
prettyPrint: string;
totalSteps: number;
reductionPath: string[];
timestamp: Date;
}
export interface ErrorEvent {
type: 'error';
message: string;
partialSteps: number;
lastTermHash?: string;
timestamp: Date;
}
export type IOEvent = StepEvent | CompleteEvent | ErrorEvent;
export declare class IOEffectsHandler {
private config;
private events;
constructor(config?: Partial<IOEffectsConfig>);
/**
* Check if IO effects are enabled
*/
isEnabled(): boolean;
/**
* Emit a step event
*/
emitStep(stepNumber: number, termHash: string, prettyPrint: string): Promise<void>;
/**
* Emit a completion event
*/
emitComplete(normalForm: string, prettyPrint: string, totalSteps: number, reductionPath: string[]): Promise<void>;
/**
* Emit an error event
*/
emitError(message: string, partialSteps: number, lastTermHash?: string): Promise<void>;
/**
* Get all collected events
*/
getEvents(): IOEvent[];
/**
* Clear collected events
*/
clearEvents(): void;
/**
* Dispatch event to configured outputs
*/
private dispatch;
/**
* Format event for output
*/
private format;
private formatMinimal;
private formatVerbose;
private logToConsole;
private sendToNetwork;
}
/**
* Create an IO effects handler from CLM config
*/
export declare function createIOHandler(config: any): IOEffectsHandler;
/**
* No-op handler for when IO effects are disabled
*/
export declare const noopIOHandler: IOEffectsHandler;
//# sourceMappingURL=IOEffects.d.ts.map