import { setupAsyncLocalStorage } from './helpers/asyncContext'; import type { AdminRoleMode, AsyncActionEnvelope, AuthData, GenericModels, MutatorContext, QueryBuilder, Transaction } from './types'; import type { AnyQueryRegistry, HumanReadable, Query, Schema as ZeroSchema, ServerTransaction as RocicorpServerTransaction } from '@rocicorp/zero'; import type { handleQueryRequest as zeroHandleQueryRequest } from '@rocicorp/zero/server'; export { setupAsyncLocalStorage }; export type JsonPrimitive = string | number | boolean | null; export type JsonValue = JsonPrimitive | readonly JsonValue[] | { readonly [key: string]: JsonValue; }; export type NormalizedClaims = { readonly userID: string; readonly [claim: string]: JsonValue; }; export type TransactionQueryFormat = { readonly relationships: Readonly>; readonly singular: boolean; }; export type SqlStatementMetadata = { readonly table: string; readonly publicTable: string; readonly kind: 'delete' | 'insert' | 'update' | 'upsert'; }; export interface ZeroServerApplicationTransaction { exec(sql: string, params?: readonly unknown[], metadata?: SqlStatementMetadata): Promise<{ readonly changes: number; }>; query = Record>(sql: string, params?: readonly unknown[]): Promise; queryAst(ast: JsonValue, format: TransactionQueryFormat, queryName?: string): Promise; } export type ZeroServerTransaction = RocicorpServerTransaction; export type ZeroServerMutationContext = { readonly claims: NormalizedClaims; defer(effect: () => void | Promise, options?: { readonly barrier?: boolean; }): void; }; export type ZeroServerRegisteredMutator = (input: { readonly tx: ZeroServerTransaction; readonly args: JsonValue; readonly ctx: ZeroServerMutationContext; }) => void | Promise; export type ZeroServerMutatorRegistry = Readonly>>; export interface ZeroServerExecutor { execute(name: string, args: JsonValue, claims: NormalizedClaims): Promise; transaction(claims: NormalizedClaims, work: (tx: ZeroServerTransaction) => Value | Promise): Promise; query(claims: NormalizedClaims, work: (tx: ZeroServerTransaction) => Result | Promise): Promise; } export type ValidateQueryArgs = { authData: AuthData | null; queryName: string; params: unknown; }; export type ValidateMutationArgs = { authData: AuthData | null; mutatorName: string; tableName: string; args: unknown; }; export type ValidateQueryFn = (args: ValidateQueryArgs) => void; export type ValidateMutationFn = (args: ValidateMutationArgs) => void | Promise; type MutateAuthData = Pick & Partial; export type MutateOptions = { authData?: MutateAuthData; }; export type ServerMutate = { [Key in keyof Models]: { [K in keyof Models[Key]['mutate']]: Models[Key]['mutate'][K] extends (ctx: MutatorContext, arg: infer Arg) => any ? (arg: Arg, options?: MutateOptions) => Promise : (options?: MutateOptions) => Promise; }; }; export type ZeroServerActionsConfig = { execute(action: Action): void | Promise; dispatchRemote?(action: Action): void | Promise; }; export type CreateZeroServerBindingsOptions, Action extends AsyncActionEnvelope = never> = { schema: Schema; models: Models; createServerActions: () => ServerActions; actions?: ZeroServerActionsConfig; queries?: AnyQueryRegistry; mutations?: Record>; validateQuery?: ValidateQueryFn; validateMutation?: ValidateMutationFn; defaultAllowAdminRole?: AdminRoleMode; mapClaims?: (claims: NormalizedClaims) => AuthData | null; }; export type ZeroServerBindings = { mutators: ZeroServerMutatorRegistry; /** * The app's queries in the standard Zero registry shape a sync host * resolves in-process: entries map the host's claims to authData, run the * on-zero query context, serve `permission.` queries, and apply * `validateQuery`. Pass this straight to the host config's `queries`. */ queries: AnyQueryRegistry; resolveQuery(name: string, args: readonly JsonValue[], authData: AuthData | null): Promise; transformQueryRequest(options: { authData: AuthData | null; request: Request; }): ReturnType; server(executor: ZeroServerExecutor): { mutate: ServerMutate; transaction(authData: AuthData | null, work: (tx: Transaction) => Value | Promise): Promise; query(authData: AuthData | null, work: (q: QueryBuilder) => Query): Promise>; }; }; export type CreateSyncQueriesOptions = { schema: Schema; queries: AnyQueryRegistry; validateQuery?: ValidateQueryFn; defaultAllowAdminRole?: AdminRoleMode; mapClaims?: (claims: NormalizedClaims) => AuthData | null; }; /** * The app's queries in the standard Zero registry shape a sync host resolves * in-process, without the rest of the server bindings. This is what a * split-worker deployment bundles into its sync worker: schema + query * definitions only, no models, server actions, or database. Entries map the * host's claims to authData, run the on-zero query context, serve * `permission.
` queries, and apply `validateQuery`. */ export declare function createSyncQueries(options: CreateSyncQueriesOptions): AnyQueryRegistry; export declare function createZeroServerBindings, Action extends AsyncActionEnvelope = never>(options: CreateZeroServerBindingsOptions): ZeroServerBindings; //# sourceMappingURL=server.d.ts.map