@prism-lang/core
Version:
A programming language for uncertainty
97 lines • 3.66 kB
TypeScript
export type ContextProperties = Record<string, unknown>;
export type ContextVariables = Record<string, unknown>;
export interface TransitionOptions {
preserveState?: boolean;
validationRules?: string[];
metadata?: Record<string, unknown>;
}
export interface TransitionResult {
success: boolean;
error?: string;
newContext?: Context;
preservedState?: ContextVariables;
}
export type ValidationRule = (from: Context | undefined, to: Context | undefined) => boolean;
export declare class ContextError extends Error {
code?: string | undefined;
constructor(message: string, code?: string | undefined);
}
export declare class Context {
readonly name: string;
readonly properties: ContextProperties;
readonly parent?: Context | undefined;
private scopes;
constructor(name: string, properties?: ContextProperties, parent?: Context | undefined);
getInheritedProperty(key: string): unknown;
isCompatibleWith(other: Context): boolean;
createScope(variables?: ContextVariables): ContextScope;
getScopes(): ContextScope[];
removeScope(scope: ContextScope): boolean;
toString(): string;
}
export declare class ContextScope {
readonly context: Context;
readonly variables: ContextVariables;
constructor(context: Context, variables?: ContextVariables);
getVariable(name: string): unknown;
setVariable(name: string, value: unknown): void;
hasVariable(name: string): boolean;
getAllVariables(): ContextVariables;
}
export declare class ContextStack {
private stack;
push(context: Context): void;
pop(): Context;
current(): Context | undefined;
depth(): number;
isEmpty(): boolean;
findContext(name: string): Context | undefined;
getContextPath(): string[];
clear(): void;
}
export declare class ContextTransition {
readonly from: Context;
readonly to: Context;
readonly options: TransitionOptions;
constructor(from: Context, to: Context, options?: TransitionOptions);
isValid(): boolean;
execute(): TransitionResult;
}
export declare class ContextValidator {
private rules;
constructor(rules?: ValidationRule[]);
addRule(rule: ValidationRule): void;
validateTransition(from: Context | undefined, to: Context | undefined): void;
removeRule(rule: ValidationRule): boolean;
}
export declare class ContextManager {
private contexts;
private stack;
private validator?;
registerContext(context: Context): void;
getContext(name: string): Context | undefined;
getAllContexts(): Context[];
getCurrentContext(): Context | undefined;
enterContext(name: string): void;
exitContext(): Context | undefined;
switchContext(name: string): void;
executeInContext<T>(contextName: string, operation: () => T): T;
setValidator(validator: ContextValidator): void;
getValidator(): ContextValidator | undefined;
getContextStack(): ContextStack;
}
export interface ContextAware {
getCurrentContext(): Context | undefined;
setContext(context: Context): void;
inContext<T>(context: Context, operation: () => T): T;
}
export declare function createContext(name: string, properties?: ContextProperties): Context;
export declare function withContext<T>(context: Context, operation: (ctx: Context) => T): T;
export declare abstract class ContextAwareBase implements ContextAware {
private currentContext?;
getCurrentContext(): Context | undefined;
setContext(context: Context): void;
inContext<T>(context: Context, operation: () => T): T;
}
export declare const defaultContextManager: ContextManager;
//# sourceMappingURL=context.d.ts.map