import { FilterScalar } from "./shared/ast.mjs"; import "./filters.mjs"; import { SearchIndexMetadata } from "../relations.mjs"; import { Rules } from "../tenancy.mjs"; import { GenericDataModel, GenericDatabaseReader, GenericDocument, PaginationOptions, PaginationResult, QueryInitializer } from "convex/server"; //#region src/querying/security.d.ts export declare const MAX_DOCUMENT_BYTES: number; /** Additive context supplied to existing read/insert/modify rules on BOTH paths. * Reads through db are authorized and bounded. collect, native paginate/filter, * search, and system reads fail closed; use get, take/first/unique, or iteration. * Trusted server callbacks can close * over other readers; arbitrary captured JavaScript cannot be sandboxed here. */ export interface SecurityPolicyContext { readonly db: GenericDatabaseReader; } export interface ManagedScope { readonly mode: 'authenticated' | 'system' | 'trusted'; readonly principal: string | null; readonly organization: string | null; readonly tenant: string | null; readonly role: string | null; } export interface ManagedBudgets { searchCandidates: number; readOperations: number; indexRanges: number; rawCandidates: number; documentBytes: number; fanout: number; depth: number; memoEntries: number; } export declare class ManagedReadError extends Error { readonly code: 'UNMANAGED_QUERY_CONTEXT' | 'MANAGED_READ_BUDGET' | 'POLICY_RECURSION' | 'UNSUPPORTED_MANAGED_READ'; constructor(code: 'UNMANAGED_QUERY_CONTEXT' | 'MANAGED_READ_BUDGET' | 'POLICY_RECURSION' | 'UNSUPPORTED_MANAGED_READ'); } interface Authority { scope: ManagedScope; rules: Rules, DM>; defaultPolicy: 'allow' | 'deny'; } /** Unique closure-only ordinary facade: helper implementation fields never leak. * Ordinary operations preserve their native/helper behavior and receive no new * engine ceilings. Register only from query constructors, never mutations/actions. */ export declare function registerQueryReader(raw: GenericDatabaseReader, ordinary: GenericDatabaseReader, authority: Authority): GenericDatabaseReader; export interface ManagedCounters { readonly readOperations: number; readonly indexRanges: number; readonly rawCandidates: number; readonly documentBytesObserved: number; readonly documentBytesReserved: number; readonly fanout: number; readonly memoEntries: number; } export interface LeafReservation { /** Settle/refund exactly once, including missing/error results (null). */ settle(document: GenericDocument | null): void; } export interface ManagedReadRequest { readonly db: GenericDatabaseReader; readonly scope: ManagedScope & { readonly policyVersion: string; }; readonly budgets: Readonly; readonly counters: ManagedCounters; /** Only the private search operation enables atomic descendant completion. */ readonly atomicCompletion: boolean; search(table: string, index: SearchIndexMetadata, text: string, equalities: readonly { field: string; value: FilterScalar; }[], options: PaginationOptions): Promise>; /** Future native leaf adapter reserves BEFORE every actual next/get, not an outer stream. */ reserveLeaf(): LeafReservation; /** Only raw leaf reservation failures from this request can be resumed by the executor. */ leafBudgetFailure(error: ManagedReadError): 'row-budget' | 'byte-budget' | undefined; openRange(): void; expand(depth: number, count?: number): void; /** Raw candidate visibility for the private executor; every leaf is metered. * Its iterator reserves each next internally; do not add an outer reservation. * Eligibility/authorization must complete before its key is eligible to advance. */ leafQuery(table: string): QueryInitializer; authorize(table: string, document: GenericDocument): Promise; } export interface ManagedSecurityConfig { /** Entire registry: parent/junction/target/policy dependencies share one request. */ tables: readonly string[]; policyVersion: string; budgets?: Partial; /** Central server trust assertion. Never inspect third-party wrapper fields. * The adapter must attest a QUERY transaction reader and the exact effective * composed policy and immutable scope. It assumes responsibility for that claim. */ trustedAdapter?: (ctx: ManagedQueryContext) => (Authority & { reader: GenericDatabaseReader; }) | null; } /** Native writer/action contexts are not accepted by the engine contract. */ export type ManagedQueryContext = { db: GenericDatabaseReader & { insert?: never; patch?: never; replace?: never; delete?: never; }; }; /** Central construction, then one shared request per engine invocation. * Requests may lower, never raise ceilings. Unknown/native contexts fail closed. */ export declare function createManagedSecurity(config: ManagedSecurityConfig): (>(ctx: Ctx, lower?: Partial) => ManagedReadRequest) & { /** Scope-only admission for public cursors. Never returns the registered reader. */ cursorScope(ctx: ManagedQueryContext): ManagedScope & { readonly policyVersion: string; }; }; /** Ordinary rule invocations share a policy-only meter. Ordinary db reads stay * unmetered by engine ceilings; supplied rule dependencies never bypass policy. * Mutation insert/modify receive the same supplied contract as read callbacks. */ export declare function suppliedPolicyRules(raw: GenericDatabaseReader, rules: Rules, DM>, defaultPolicy: 'allow' | 'deny'): Rules, DM>; //#endregion //# sourceMappingURL=security.d.mts.map