import { type RemoteOperationResponse, type RowValue } from '@syncular/core'; import type { SyncRequestContext } from './context.js'; import type { AuthoritativeQueryValue } from './storage.js'; import { type ValidateRow } from './validate.js'; export interface RemoteQueryDependency { readonly table: string; readonly scopeKeys?: readonly string[]; } export interface RemoteQueryCoverage { readonly base: { readonly table: string; readonly variable: string; readonly fixedScopes?: Readonly>; }; readonly units: readonly string[]; } /** Structural subset implemented by generated NamedQuery descriptors. */ export interface AuthoritativeQueryDescriptor { readonly id: string; readonly hasParams: boolean; readonly sql: string; readonly tables: readonly string[]; readonly resultColumns: readonly { readonly name: string; readonly type: 'string' | 'integer' | 'float' | 'boolean' | 'json' | 'bytes' | 'blob_ref' | 'crdt'; readonly nullable: boolean; }[]; readonly bind: (params: Params) => readonly AuthoritativeQueryValue[]; readonly sqlFor?: (params: Params) => string; readonly dependencies: (params: Params) => readonly RemoteQueryDependency[]; readonly coverage: (params: Params) => readonly RemoteQueryCoverage[]; } export interface RemoteOperationAuthContext { readonly actorId: string; readonly partition: string; readonly clientId: string; } export type RegisteredRemoteQuery = { readonly kind: 'query'; readonly id: string; readonly tables: readonly string[]; readonly run: (ctx: SyncRequestContext, clientId: string, params: unknown) => Promise; }; export interface RemoteCommandDescriptor { readonly id: string; readonly __input?: Input; } export type CommandMutation = { readonly table: string; readonly op: 'upsert'; readonly values: Readonly>; } | { readonly table: string; readonly op: 'delete'; readonly rowId: string; }; export interface RemoteCommandContext { readonly actorId: string; readonly partition: string; readonly clientId: string; readonly operationId: string; readonly requestId: string; getRow(table: string, rowId: string): Promise; } export interface RemoteCommandOptions { readonly authorize: (context: RemoteOperationAuthContext, input: Input) => boolean | Promise; readonly run: (context: RemoteCommandContext, input: Input) => readonly CommandMutation[] | Promise; } export type RegisteredRemoteCommand = { readonly kind: 'command'; readonly id: string; readonly run: (ctx: SyncRequestContext, clientId: string, requestId: string, params: unknown) => Promise; }; export type RegisteredRemoteOperation = RegisteredRemoteQuery | RegisteredRemoteCommand; type RemoteQueryAccess = { readonly access: 'scoped'; } | { readonly access: 'privileged'; readonly authorize: (context: RemoteOperationAuthContext, params: Params) => boolean | Promise; }; export interface RemoteQueryOptions { readonly maxRows: number; readonly auth: RemoteQueryAccess; } /** Register one generated named query as an authoritative remote operation. */ export declare function registerRemoteQuery(descriptor: AuthoritativeQueryDescriptor, options: RemoteQueryOptions): RegisteredRemoteQuery; /** A typed client/server identity for a server-authoritative command. */ export declare function remoteCommand(id: string): RemoteCommandDescriptor; /** Register custom command code that plans one ordinary Syncular commit. */ export declare function registerRemoteCommand(descriptor: RemoteCommandDescriptor, options: RemoteCommandOptions): RegisteredRemoteCommand; export declare class RemoteOperationRegistry { #private; constructor(operations: readonly RegisteredRemoteOperation[]); get(id: string): RegisteredRemoteOperation | undefined; } export declare function handleRemoteOperation(bytes: Uint8Array, ctx: SyncRequestContext, registry: RemoteOperationRegistry): Promise; export {};