import { type ServerAuthOption, type WireAuthContext } from "@concavejs/core/auth"; import type { UserIdentityAttributes } from "convex/server"; import { type ConcaveStorage, type ConcaveStorageOptions, type PlacementManifest, type PlacementValidationOption } from "@concavejs/core"; import { type SyncProtocolHandler, type SyncWebSocket } from "@concavejs/core/sync"; import { type ClientMessage, type ServerMessage } from "@concavejs/core/types"; import type { WriteInvalidation } from "./abstractions.js"; import { type ModuleLoader, type UdfResult } from "@concavejs/core/udf"; import type { ClientTransport, RuntimeHost, RuntimeUdfRequest } from "./abstractions.js"; import { type EmbeddedWriteFanoutAdapter, type EmbeddedWriteFanoutConfig, type EmbeddedWriteFanoutOptions } from "./write-fanout.js"; type ModuleRegistryEntry = (() => Promise) | Promise | any; export type EmbeddedModuleMap = Record; export type EmbeddedModuleSource = ModuleLoader | EmbeddedModuleMap; export type EmbeddedModuleSources = EmbeddedModuleSource | EmbeddedModuleSource[]; export type EmbeddedSchemaBootstrapMode = "auto" | "skip"; export type EmbeddedExecutionMode = "auto" | "parallel" | "serial"; export declare const DEFAULT_EMBEDDED_CLIENT_URL = "http://localhost"; export interface EmbeddedRuntimeOptions { /** * Storage: a backend (e.g. `memory()`), a capability map, or a * fully-specified `ConcaveStorage` object. */ storage: ConcaveStorageOptions | ConcaveStorage; modules?: EmbeddedModuleSources; schema?: EmbeddedSchemaBootstrapMode; /** Required: no implicit dev default (fail closed). */ isDev: boolean; /** * Auth mode: "env" verifies credentials from environment config, * "insecure" accepts admin/system access without verification (dev only), * or a DefaultAuthResolver instance for full control. Defaults to * "insecure" in dev and "env" otherwise. */ auth?: ServerAuthOption; /** * Placement capability validation at startup: "auto" (default) warns in * dev and refuses to start in production when the app requires * capabilities this placement lacks (e.g. crons — the embedded placement * has no scheduler); "warn"/"error" force one behavior; "off" disables it. */ placementValidation?: PlacementValidationOption; /** * Scheduler for crons and ctx.scheduler functions. Enabled by default * (polling task executor, like the Bun/Node servers). Note the placement * caveat: scheduled work only runs while this runtime is alive — when the * hosting tab/app is closed, due jobs wait until the next start. Pass * false to disable (placement validation then flags defined crons), or * { pollIntervalMs } to tune the poll cadence. Pass "manual" to keep the * scheduler configured but never auto-poll — the caller pumps due work * deterministically via {@link EmbeddedRuntime.finishScheduledFunctions} * (used by the test harness with a stepped virtual clock). */ scheduler?: boolean | "manual" | { pollIntervalMs?: number; }; /** Log sink for runtime notices (auth mode, placement gaps). Defaults to console. */ logger?: Pick; instanceName?: string; executionMode?: EmbeddedExecutionMode; clientUrl?: string; /** Application variables for this embedded deployment. System URLs default to clientUrl. */ env?: Record; writeFanout?: EmbeddedWriteFanoutConfig; } export type { EmbeddedWriteFanoutAdapter, EmbeddedWriteFanoutOptions }; export type EmbeddedTransport = ClientTransport; export declare class EmbeddedRuntime implements RuntimeHost { readonly clientUrl: string; private readonly runtime; private readonly protocolHandler; private readonly httpHandler; private readonly udfExecutor; private readonly udfAdapter; private readonly serverUdfAdapter; private readonly authResolver; private readonly authMode; private readonly isDev; private readonly placementValidation?; private readonly logger; private readonly schedulerEnabled; private readonly schedulerManual; private readonly schedulerPollIntervalMs?; private schedulerClockMs; private taskExecutor?; private readonly testRunSlots; private testRunSlotCounter; private readonly schemaMode; private readonly instanceName; private readonly runtimeId; private readonly closeStorage?; private readonly socketSessions; private readonly writeFanout; private webSocketConstructor?; private startPromise?; private closed; private readonly detachCommitLog; private readonly detachWriteFanout; constructor(options: EmbeddedRuntimeOptions); get url(): string; start(): Promise; executeUdf(request: RuntimeUdfRequest): Promise; executeHttp(request: Request, auth?: WireAuthContext | UserIdentityAttributes, requestId?: string): Promise; /** * Run an ad-hoc handler with a real `MutationCtx` inside a real OCC * transaction, without defining a UDF (the `t.run` test seam). Writes commit * atomically; a throw rolls the transaction back. The handler's return value * is passed through in-process, so it may be any value (e.g. a `Blob`). */ runInTransaction(handler: (ctx: any) => T | Promise, options?: { auth?: WireAuthContext | UserIdentityAttributes; }): Promise; /** * Drain all currently-scheduled functions and everything they schedule, * executing due jobs against a stepped virtual clock until the scheduled * queue is empty. Requires `scheduler: "manual"`. Recurring crons are not * driven here (they never drain); `maxIterations` bounds accidental infinite * runAfter recursion, mirroring convex-test's `finishAllScheduledFunctions`. */ finishScheduledFunctions(maxIterations?: number): Promise; /** * Run scheduled functions already due at the current virtual clock exactly * once (does not advance time). Requires `scheduler: "manual"`. */ finishInProgressScheduledFunctions(): Promise; private requireManualScheduler; createSyncSession(sessionId: string, websocket: SyncWebSocket): Promise; updateSyncSessionId(oldSessionId: string, newSessionId: string): void; handleSyncMessage(sessionId: string, message: ClientMessage): Promise; destroySyncSession(sessionId: string): void; /** * Re-reads the schema module and reapplies index metadata. * * Useful for embedded/editor workflows where module sources can be updated * while keeping active transports and sync sessions alive. */ refreshSchema(): Promise; handleRequest(request: Request): Promise; notifyWrites(invalidation: WriteInvalidation): Promise; createWebSocketConstructor(): typeof WebSocket; createFetch(clientUrl?: string): (input: RequestInfo | URL, init?: RequestInit) => Promise; createTransport(clientUrl?: string): EmbeddedTransport; close(): Promise; getSyncProtocolHandler(): SyncProtocolHandler; /** The declared capability surface of this embedded placement. */ getPlacementManifest(): PlacementManifest; private initialize; private discoverCronSpecs; private loadAuthConfig; private resolveSchemaIndexes; private applyWrites; private handleClientMessage; private closeSocket; }