Something went wrong. Try again.
A local-first note taking app
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061/** * Shape of a `network.habitat.docs` (owner) and `network.habitat.docs.edit` * (collaborator mirror) record's `value`. * * `blob` is the base64-encoded CRDT state. For Yjs docs this is * `Y.encodeStateAsUpdateV2(ydoc)`; for Automerge docs it is * `Automerge.save(doc)`. `editorClique` is the AT URI of the clique * record listing DIDs with edit access. * * `crdtType` defaults to `'yjs'` for backwards compatibility with * existing records that omit the field. */export type HabitatDoc = { name: string; blob: string | null; editorClique?: string; crdtType?: 'yjs' | 'automerge';};
/** A subset of `network.habitat.repo.getRecord` / `listRecords` outputs that we use. */export type TypedRecord<T = Record<string, unknown>> = { uri: string; cid: string; value: T; /** Only populated when `includePermissions: true` was requested. */ permissions?: Array<Record<string, unknown>>;};
export type ListRecordsResponse<T = Record<string, unknown>> = { cursor?: string; records: TypedRecord<T>[];};
/** Mirrors upstream's XRPCError for `instanceof` checks in UI code. */export class XRPCError extends Error { status: number; error: string; /** Endpoint NSID (or full path) that failed; helps locate the caller. */ endpoint?: string; /** Request path passed to `habitatAuth.fetch`. */ requestPath?: string; /** Raw response body if it wasn't a parseable JSON error envelope. */ rawBody?: string;
constructor( status: number, payload: { error?: string; message?: string }, context?: { endpoint?: string; requestPath?: string; rawBody?: string }, ) { const detail = payload.message || payload.error || `XRPC error ${status}`; const prefix = context?.endpoint ? `[${context.endpoint}] ` : ''; super(`${prefix}${status} ${detail}`); this.name = 'XRPCError'; this.status = status; this.error = payload.error ?? 'XRPCError'; this.endpoint = context?.endpoint; this.requestPath = context?.requestPath; this.rawBody = context?.rawBody; }}