Skip to main content

Browser TypeScript Package API

This page covers the public primadb browser package entrypoint and its hook helper surface. The re-exported runtime classes and transport bindings are documented on the browser runtime API page.

This page is generated from the current package source declarations.

packages/primadb/index.ts

Primary primadb entrypoint.

Direct exports

PrimadbInitInput

Kind: type alias

export type PrimadbInitInput = Parameters<typeof initWasm>[0];

PrimadbInitOutput

Kind: type alias

export type PrimadbInitOutput = Awaited<ReturnType<typeof initWasm>>;

initPrimadb

Kind: function

export declare function initPrimadb(input?: PrimadbInitInput): Promise<PrimadbInitOutput>;

createPrimadb

Kind: function

export declare function createPrimadb(replicaId?: string | null, input?: PrimadbInitInput): Promise<Primadb>;

Re-exports

export * from "./vendor/default/primadb.js";
export * from "./hooks.js";
export { initWasm };
export default initPrimadb;

packages/primadb/hooks.ts

Package-level hook helper types and registration utilities.

Direct exports

ConnectHookContext

Kind: interface

export interface ConnectHookContext {
peer: {
peerId: string;
replicaId: string;
transport: string;
capabilities?: string[];
topics?: string[];
metadata?: Record<string, string>;
};
transport: "relay" | "mesh";
relayUrl?: string | null;
}

RoomHookContext

Kind: interface

export interface RoomHookContext {
peerId: string;
room: string;
transport: "relay" | "mesh";
peer?: ConnectHookContext["peer"] | null;
}

PullRequestKind

Kind: type alias

export type PullRequestKind = {
kind: "get";
path: {
anchor: string;
segments?: string[];
};
} | {
kind: "map";
path: {
anchor: string;
segments?: string[];
};
} | {
kind: "query";
path: {
anchor: string;
segments?: string[];
};
spec: Record<string, unknown>;
} | {
kind: "lex";
path: {
anchor: string;
segments?: string[];
};
spec: Record<string, unknown>;
} | {
kind: "snapshot";
root?: string | null;
};

RemoteResult

Kind: type alias

export type RemoteResult = {
kind: "get";
value: unknown | null;
} | {
kind: "map";
entries: unknown[];
} | {
kind: "query";
entries: unknown[];
} | {
kind: "lex";
entries: unknown[];
} | {
kind: "snapshot";
snapshot: unknown;
};

ServeRequestContext

Kind: interface

export interface ServeRequestContext {
peerId: string;
transport: "relay" | "mesh";
requestId?: string | null;
watchId?: string | null;
request: PullRequestKind;
}

ServeResultContext

Kind: interface

export interface ServeResultContext {
peerId: string;
transport: "relay" | "mesh";
requestId?: string | null;
watchId?: string | null;
request: PullRequestKind;
initial: boolean;
}

VoidHookDecision

Kind: type alias

export type VoidHookDecision = boolean | string | {
allow?: boolean;
message?: string;
} | null | undefined;

RequestHookDecision

Kind: type alias

export type RequestHookDecision = VoidHookDecision | PullRequestKind | {
allow?: boolean;
message?: string;
request?: PullRequestKind;
};

ResultHookDecision

Kind: type alias

export type ResultHookDecision = VoidHookDecision | RemoteResult | {
allow?: boolean;
message?: string;
result?: RemoteResult;
};

NetworkHooks

Kind: interface

export interface NetworkHooks {
onConnect?(context: ConnectHookContext): VoidHookDecision;
onJoinRoom?(context: RoomHookContext): VoidHookDecision;
onPull?(context: ServeRequestContext): RequestHookDecision;
onWatch?(context: ServeRequestContext): RequestHookDecision;
onServeResult?(context: ServeResultContext, result: RemoteResult): ResultHookDecision;
}

setNetworkHooks

Kind: function

export declare function setNetworkHooks(db: Primadb, hooks: NetworkHooks | null | undefined): void;

clearNetworkHooks

Kind: function

export declare function clearNetworkHooks(db: Primadb): void;