Skip to content
Sarj Workspace Sync

operations/kernel

@sarj-ai/workspace-sync/operations/kernel ยท Source

import { type OperationRegistry, type OperationContext, type RegisteredApplyOperation } from "./registry.ts";
import { type ApplyActionResult, type ApplyOperationResult, type ManagedChange, type OperationActor, type OperationPlanEnvelope, type SignedOperationPlan } from "./schemas.ts";
export type OperationPlanErrorCode = "actor_mismatch" | "environment_mismatch" | "invalid_confirmation" | "invalid_plan" | "invalid_signature" | "unknown_operation";
export declare class OperationPlanError extends Error {
readonly code: OperationPlanErrorCode;
constructor(options: ErrorOptions & {
code: OperationPlanErrorCode;
message: string;
});
}
export interface OperationKernelOptions {
now?: () => number;
registry: OperationRegistry;
signingKey: string;
}
export interface PlanOperationRequest {
actor: OperationActor;
environment: string;
input: unknown;
operation: string;
}
export interface ApplyOperationContext {
actor: OperationActor;
environment: string;
}
export interface OperationApplyPort {
apply(rawRequest: unknown, rawContext: ApplyOperationContext): Promise<ApplyOperationResult>;
}
export interface OperationPlanPort {
plan(request: PlanOperationRequest): Promise<SignedOperationPlan>;
}
export type PreparedOperationApply = {
actions: ApplyActionResult[];
context: OperationContext;
ok: true;
operation: RegisteredApplyOperation;
pending: ManagedChange[];
plan: OperationPlanEnvelope;
} | {
ok: false;
result: ApplyOperationResult;
};
export interface OperationPrepareApplyPort {
prepareApply(rawRequest: unknown, rawContext: ApplyOperationContext): Promise<PreparedOperationApply>;
}
export declare class OperationKernel implements OperationApplyPort, OperationPlanPort, OperationPrepareApplyPort {
#private;
constructor(options: OperationKernelOptions);
plan(request: PlanOperationRequest): Promise<SignedOperationPlan>;
apply(rawRequest: unknown, rawContext: ApplyOperationContext): Promise<ApplyOperationResult>;
prepareApply(rawRequest: unknown, rawContext: ApplyOperationContext): Promise<PreparedOperationApply>;
}