createNaru
함수createNaru(options?: { site?: string }): NaruClientCreates a client bound to one site.
Admin
인터페이스interface Adminmedia: { upload( file: Blob | File, options?: { onProgress?: ( progress: | { phase: "preparing" } | { loaded: number; phase: "uploading"; total: number } | { phase: "finishing" }, ) => void; signal?: AbortSignal; }, ): Promise<{ contentType: string; name: string; size: number; url: string; }>; }batch( writes: readonly ( | { collection: string; set: { condition?: WriteCondition; data: unknown; id: string }; } | { collection: string; delete: { condition?: { revision: Revision }; id: string }; } )[], options?: { signal?: AbortSignal }, ): Promise< ({ createdAt: string; id: string; revision: Revision; updatedAt: string; } | null)[] >Commits every write or none. Conditions guard individual documents. Does not retry. Resolves, in the order written, with what each
setstored andnullfor eachdelete.collection<T = Json>(name: string): AdminCollection<T>signOut(): Promise<void>This handle stops working at once, even if the revoke request fails.
AdminCollection
인터페이스interface AdminCollection<T = Json> extends PublicCollection<T>delete( id: string, options?: { condition?: { revision: Revision }; signal?: AbortSignal }, ): Promise<void>Deleting a missing document succeeds unless a condition was supplied.
set( id: string, data: T, options?: { condition?: WriteCondition; signal?: AbortSignal }, ): Promise<Document<T>>Replaces the whole document or creates it.
Document
인터페이스interface Document<T = Json>A read or successful write: user data stays separate from server metadata.
createdAt: stringdata: Tid: stringrevision: RevisionupdatedAt: string
ListOptions
인터페이스interface ListOptionsafter?: string | nullOpaque cursor returned by the preceding page.
filter?: FilterincludeTotal?: booleansignal?: AbortSignalsize?: numberDefault 50; maximum 100.
sort?: Sort
NaruClient
인터페이스interface NaruClientauth: { session(): Promise<Admin | null>; signIn(options: { collections: readonly string[] }): Promise<void>; }collection<T = Json>(name: string): PublicCollection<T>Visitor access, even when signed in.
Page
인터페이스interface Page<T = Json>documents: Document<T>[]nextCursor: string | nulltotalCount?: number
PublicCollection
인터페이스interface PublicCollection<T = Json>add(data: T, options?: { signal?: AbortSignal }): Promise<Document<T>>count(options?: { filter?: Filter; signal?: AbortSignal; }): Promise<number>How many documents match
filter, or the whole collection.get(id: string, options?: { signal?: AbortSignal }): Promise<Document<T>>list(options?: ListOptions): Promise<Page<T>>pages(options?: ListOptions): AsyncIterable<Page<T>>Every page of a query in turn, following
nextCursorfromafter(or the start). Not a snapshot: writes in between can shift later pages.
NaruError
클래스class NaruError extends ErrorA Naru operation that could not be completed. Check it with instanceof.
code: NaruErrorCode
Filter
타입type Filter = Record<
string,
| string
| number
| boolean
| null
| {
gt?: string | number;
gte?: string | number;
lt?: string | number;
lte?: string | number;
}
>Top-level user fields, combined with AND.
Json
타입type Json =
| null
| boolean
| number
| string
| Json[]
| { [key: string]: Json }NaruErrorCode
타입type NaruErrorCode =
| "CONFLICT"
| "QUOTA_EXCEEDED"
| "AUTH_REQUIRED"
| "ACCESS_DENIED"
| "NOT_FOUND"
| "RATE_LIMITED"
| "INVALID_REQUEST"
| "UNAVAILABLE"Why an operation failed. The list is closed for v1: a code a later server adds reaches this version as the nearest code here.
Revision
타입type Revision = string & { [revisionBrand]: true }An opaque concurrency token. Store and return it unchanged.
Sort
타입type Sort =
| readonly [
readonly [
string | { metadata: "id" | "createdAt" | "updatedAt" },
"asc" | "desc",
],
]
| readonly [
readonly [
string | { metadata: "id" | "createdAt" | "updatedAt" },
"asc" | "desc",
],
readonly [
string | { metadata: "id" | "createdAt" | "updatedAt" },
"asc" | "desc",
],
]One or two keys: a user field by name, or document metadata.
WriteCondition
타입type WriteCondition = { revision: Revision } | { absent: true }Write only at this revision, or only if the document does not exist yet.