import { Observable } from 'rxjs'; export { gappPreloadPlugin } from './vitePlugin.cjs'; import 'vite'; declare function createCallbackSet(): { add: (callback: (args: T) => void) => () => void; call: (args: T) => void; clear: () => void; }; interface Result { isOk(): this is Ok; isErr(): this is Err; map(fn: (value: T) => U): Result; unwrap(): T | never; unwrapOrDefault(defaultValue: T): T; } declare function ok(): Result; declare function ok(value: T): Result; declare function err(): Result; declare function err(error: E): Result; declare class Ok implements Result { value: T; constructor(value: T); isOk(): this is Ok; isErr(): this is Err; map(fn: (value: T) => U): Result; unwrap(): T; unwrapOrDefault(_defaultValue: T): T; } declare class Err implements Result { error: E; constructor(error: E); isOk(): this is Ok; isErr(): this is Err; map(_fn: (value: T) => U): Result; unwrap(): T; unwrapOrDefault(defaultValue: T): T; } type DecodedRpc = { method: string; request: unknown; response: unknown; }; declare abstract class Store { protected state: State; private listeners; constructor(initialState: State); getState(): State; setState(newState: State): void; subscribe(callback: (newState: State) => void): () => void; dispatch(action: Action): void; reduceRpc(state: State, _event: RpcResult): State; reduceSendRpc(state: State, _event: RpcRequest): State; reduceAction(state: State, _action: Action): State; } declare class StoreRegistry { private stores; register>(store: S): S; dispatchRpc(event: unknown): void; dispatchSendRpc(event: unknown): void; hydrate(decoded: DecodedRpc[]): void; } type ExtractSegmentParams = S extends `:${infer Param}?` ? { [k in Param]?: string; } : S extends `:${infer Param}` ? { [k in Param]: string; } : {}; type ExtractParams = S extends `${infer Head}/${infer Rest}` ? ExtractSegmentParams & ExtractParams : ExtractSegmentParams; type Route = { factory: (props: ExtractParams) => Metadata; path: Path; }; type RouteTree = { node: Route | null; static: { [key: string]: RouteTree; }; dynamic: { key: string; optional: boolean; value: RouteTree; } | null; }; type WindowAPI = { getPathname: () => string; navigate: (to: string) => void; addEventListener: (type: string, listener: (this: Window, ev: Event) => any) => void; removeEventListener: (type: string, listener: (this: Window, ev: Event) => any) => void; }; declare class Router { private windowAPI; tree: RouteTree; private subscribers; private cache; private metadataCache; constructor(routes: Route[], windowAPI?: WindowAPI); cleanup(): void; private onPopstate; url(route: Route, params: ExtractParams, queryParams?: { [key: string]: string | number | boolean; }): string; onNavigate(callback: (metadata: Metadata) => void): () => void; current(): Metadata; path(): string; navigate(path: string): void; find(path: string): Metadata | null; private findParams; private addRouteToTree; } /** * Utility types to extract RPC request/response types from service interfaces. * This avoids manually maintaining discriminated unions for each RPC method. */ type MethodNames = { [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never; }[keyof T] & string; type RequestType = T extends (req: infer R) => any ? R : never; type ResponseType = T extends (req: any) => Promise ? R : T extends (req: any) => Observable ? R : never; type RpcRequestFromService = { [K in MethodNames]: { method: K; request: RequestType; }; }[MethodNames]; type RpcResultFromService = { [K in MethodNames]: { method: K; request: RequestType; result: Result, Error>; }; }[MethodNames]; /** * Creates a proxy around an RPC client that auto-dispatches to stores. * @param client The base RPC client to wrap * @param options.registry The store registry to dispatch events to * @param options.streamingMethods Methods that should not be wrapped (streaming methods) */ declare function createRpcProxy(client: T, options: { registry: StoreRegistry; streamingMethods?: Set; }): T; type RpcTransportConfig = { url: string | (() => string); credentials?: RequestCredentials; }; /** * The Rpc interface expected by ts-proto generated clients. */ interface RpcTransport { request(service: string, method: string, data: Uint8Array): Promise; clientStreamingRequest(service: string, method: string, data: Observable): Promise; serverStreamingRequest(service: string, method: string, data: Uint8Array): Observable; bidirectionalStreamingRequest(service: string, method: string, data: Observable): Observable; } declare function createRpcTransport(config: RpcTransportConfig): RpcTransport; declare const RpcErrorCode: { readonly VALIDATION_ERROR: "VALIDATION_ERROR"; readonly NOT_FOUND: "NOT_FOUND"; readonly ALREADY_EXISTS: "ALREADY_EXISTS"; readonly UNAUTHENTICATED: "UNAUTHENTICATED"; readonly PERMISSION_DENIED: "PERMISSION_DENIED"; readonly RATE_LIMITED: "RATE_LIMITED"; readonly INTERNAL: "INTERNAL"; }; type RpcErrorCodeType = (typeof RpcErrorCode)[keyof typeof RpcErrorCode]; declare class RpcError extends Error { code: string; details: Record; httpStatus: number; constructor(code: string, message: string, httpStatus: number, details?: Record); is(code: string): boolean; } type PreloadedData = { [method: string]: { requestBytes: string; responseBytes: string; }; }; declare global { interface Window { __PRELOADED__?: PreloadedData; __PRELOAD_TIMESTAMP__?: number; } } type RpcDeclaration = { method: string; params?: Record; }; type DecoderMap = Record unknown>; /** * Decode and dispatch all preloaded RPCs. * Returns array of { method, request, response } for dispatching to stores. * Data is gzip compressed, so decompression is async. */ declare function decodeAllPreloaded(requestDecoders: DecoderMap, responseDecoders: DecoderMap): Promise>; export { type DecodedRpc, type DecoderMap, Err, type MethodNames, Ok, type PreloadedData, type RequestType, type ResponseType, type Result, type Route, type RouteTree, Router, type RpcDeclaration, RpcError, RpcErrorCode, type RpcErrorCodeType, type RpcRequestFromService, type RpcResultFromService, type RpcTransport, type RpcTransportConfig, Store, StoreRegistry, createCallbackSet, createRpcProxy, createRpcTransport, decodeAllPreloaded, err, ok };