/** Public, token-only data access contracts. Durable adapters and RLS policy enforcement stay outside * this package; this subpath defines the typed seam they implement. */ export declare const DATA_CAPABILITIES: Readonly<{ readonly read: "db.read"; readonly write: "db.write"; }>; export type DataAccess = keyof typeof DATA_CAPABILITIES; export type DataCapability = (typeof DATA_CAPABILITIES)[DataAccess]; export interface DataOperationSpec { readonly access: DataAccess; readonly input?: unknown; readonly output?: unknown; } export type DataOperationMap = Readonly>; export interface DataContract { readonly version: string; readonly operations: Operations; } /** Opaque request-local RLS (or equivalent data-policy) scope passed to an adapter. */ export interface RlsScope { /** Caller-owned scope token. The public seam never interprets, logs, or derives identity from it. */ readonly token: string; /** Optional opaque digest for correlating a scope without exposing tenant or subject data. */ readonly digest?: string; } /** Backward-compatible name for the request scope carried by every data operation. */ export type DataScope = RlsScope; export interface DataRequest { readonly operation: Operation; readonly scope: DataScope; readonly capability: DataCapability; readonly input: Input; } export interface DataDrift { readonly kind: "version" | "added" | "removed" | "access-changed"; readonly operation?: string; readonly declaredAccess?: DataAccess; readonly observedAccess?: DataAccess; readonly declaredVersion?: string; readonly observedVersion?: string; } type InputOf = Operation extends { readonly input: infer Input; } ? Input : never; type OutputOf = Operation extends { readonly output: infer Output; } ? Output : unknown; type CapabilityOf = Operation extends { readonly access: "read"; } ? typeof DATA_CAPABILITIES.read : Operation extends { readonly access: "write"; } ? typeof DATA_CAPABILITIES.write : DataCapability; type InputField = [Input] extends [never] ? { readonly input?: never; } : { readonly input: Input; }; export type DataInput = Contract["operations"][Operation] extends infer Definition ? InputOf : never; export type DataOutput = Contract["operations"][Operation] extends infer Definition ? OutputOf : unknown; export type DataRequestFor = { readonly operation: Operation; readonly scope: DataScope; readonly capability: CapabilityOf; } & InputField>; export interface TypedDataPort { execute(request: DataRequestFor): Promise>; } /** Runtime capability beacon used by a request-bound data port. */ export type DataCapabilityBeacon = (context: object, capability: DataCapability) => void; /** Options for the public request-bound data port wrapper. */ export interface DataPortOptions { /** Usually `useCapability` from `@nifrajs/core/capabilities`. */ readonly beacon?: DataCapabilityBeacon; } /** A data port bound to one request context; every operation emits capability evidence first. */ export interface BoundDataPort extends TypedDataPort { } /** Public factory for wiring a private data adapter into Nifra's capability evidence chain. */ export interface DataPort { for(context: object): BoundDataPort; } /** * Bind a private data adapter to request-local capability evidence. * * The adapter remains responsible for RLS enforcement and durable storage. This wrapper owns the * framework-side proof boundary: it emits exactly the operation's typed `db.read`/`db.write` token * before invoking the adapter, and refuses to run when no beacon is configured or the beacon denies * the operation. The context is never copied into the request or retained by the port. * * The emitted token is derived from the **contract**, never from `request.capability`. The typed * request narrows that field, but types are erased before this line runs, and a request assembled * from decoded input would otherwise let a write operation announce itself as `db.read` - evidence * that names the wrong capability is worse than no evidence, because the ledger looks satisfied. An * unknown operation, or a declared capability that disagrees with the contract, fails closed. */ export declare function createDataPort(contract: Contract, adapter: TypedDataPort, options?: DataPortOptions): DataPort; /** Create a bounded, opaque RLS/equivalent policy scope for a data adapter. */ export declare function rlsScope(token: string, digest?: string): RlsScope; /** Backward-compatible constructor for {@link RlsScope}. */ export declare function dataScope(token: string, digest?: string): DataScope; /** Define and freeze a token-only data contract. Input/output types are erased at runtime. */ export declare function defineDataContract(input: { readonly version: string; readonly operations: Operations; }): DataContract; export interface DataContractSnapshot { readonly version: string; readonly operations: Readonly>; } /** Strip a contract to its token-only version/access snapshot for CI or adapter drift checks. */ export declare function snapshotDataContract(contract: DataContract): DataContractSnapshot; /** Compare a declared contract with an adapter-observed token-only snapshot. */ export declare function diffDataContract(declared: DataContract, observed: DataContractSnapshot | DataContract): readonly DataDrift[]; export {}; //# sourceMappingURL=data.d.ts.map