/** * Policy gate module for the Kubun engine. * * Policies gate engine operations with sync-before-async ordering. * Each gate has optional sync and async check arrays. Sync checks run first * (fast, in-memory). If any sync check fails, async checks are skipped entirely. * * Result types follow the Standard Schema output specification: * - Success: `{ value }` — the context passes through * - Failure: `{ issues }` — an array of issues with at minimum a `message` field */ /** * A path segment in a policy issue, matching StandardSchemaV1.PathSegment. */ export type PolicyPathSegment = { readonly key: PropertyKey; }; /** * A policy issue, matching StandardSchemaV1.Issue. */ export type PolicyIssue = { readonly message: string; readonly path?: ReadonlyArray | undefined; }; /** * Successful policy check result. */ export type PolicySuccessResult = { readonly value: TContext; readonly issues?: undefined; }; /** * Failed policy check result. */ export type PolicyFailureResult = { readonly issues: ReadonlyArray; }; /** * The result of a policy check — either success or failure. */ export type PolicyResult = PolicySuccessResult | PolicyFailureResult; /** * A synchronous policy check function. * Returns a Standard Schema result immediately (in-memory, fast). */ export type SyncPolicyCheck = (context: TContext) => PolicyResult; /** * An asynchronous policy check function. * Returns a Promise of a Standard Schema result (may involve DB lookups, etc.). */ export type AsyncPolicyCheck = (context: TContext) => Promise>; /** * A single policy gate with optional sync and async check arrays. */ export type PolicyGate = { sync?: Array>; async?: Array>; }; /** * Map of gate type names to their policy gates. */ export type PolicyGateMap = Record>; /** * Run all policy checks for a given gate type. * * Execution order: * 1. Run ALL sync checks — fail fast if any return issues * 2. Run ALL async checks — fail fast if any return issues * 3. Return success with the original context * * If the gate type is not present in the map, the operation is allowed by default. */ export declare function runPolicies(gates: PolicyGateMap, gateType: string, context: TContext): Promise>;