UNPKG

@leordev-web5/api

Version:

SDK for accessing the features and capabilities of Web5

206 lines 5.55 kB
import type { Web5Agent } from '@web5/agent'; import type { RecordsReadOptions, RecordsQueryOptions, RecordsWriteOptions, RecordsDeleteOptions, ProtocolsQueryOptions, ProtocolsConfigureOptions, ProtocolsConfigureDescriptor } from '@tbd54566975/dwn-sdk-js'; import { Record } from './record.js'; import { Protocol } from './protocol.js'; /** * Status code and detailed message for a response. * * @beta */ export type ResponseStatus = { status: { code: number; detail: string; }; }; /** * Request to setup a protocol with its definitions * * @beta */ export type ProtocolsConfigureRequest = { message: Omit<ProtocolsConfigureOptions, 'signer'>; }; /** * Response for the protocol configure request * * @beta */ export type ProtocolsConfigureResponse = ResponseStatus & { protocol?: Protocol; }; /** * Represents each entry on the protocols query reply * * @beta */ export type ProtocolsQueryReplyEntry = { descriptor: ProtocolsConfigureDescriptor; }; /** * Request to query protocols * * @beta */ export type ProtocolsQueryRequest = { from?: string; message: Omit<ProtocolsQueryOptions, 'signer'>; }; /** * Response with the retrieved protocols * * @beta */ export type ProtocolsQueryResponse = ResponseStatus & { protocols: Protocol[]; }; /** * Type alias for {@link RecordsWriteRequest} * * @beta */ export type RecordsCreateRequest = RecordsWriteRequest; /** * Type alias for {@link RecordsWriteResponse} * * @beta */ export type RecordsCreateResponse = RecordsWriteResponse; /** * Request to create a record from an existing one (useful for updating an existing record) * * @beta */ export type RecordsCreateFromRequest = { author: string; data: unknown; message?: Omit<RecordsWriteOptions, 'signer'>; record: Record; }; /** * Request to delete a record from the DWN * * @beta */ export type RecordsDeleteRequest = { from?: string; message: Omit<RecordsDeleteOptions, 'signer'>; }; /** * Request to query records from the DWN * * @beta */ export type RecordsQueryRequest = { /** The from property indicates the DID to query from and return results. */ from?: string; message: Omit<RecordsQueryOptions, 'signer'>; }; /** * Response for the query request * * @beta */ export type RecordsQueryResponse = ResponseStatus & { records?: Record[]; /** If there are additional results, the messageCid of the last record will be returned as a pagination cursor. */ cursor?: string; }; /** * Request to read a record from the DWN * * @beta */ export type RecordsReadRequest = { /** The from property indicates the DID to read from and return results fro. */ from?: string; message: Omit<RecordsReadOptions, 'signer'>; }; /** * Response for the read request * * @beta */ export type RecordsReadResponse = ResponseStatus & { record: Record; }; /** * Request to write a record to the DWN * * @beta */ export type RecordsWriteRequest = { data: unknown; message?: Omit<Partial<RecordsWriteOptions>, 'signer'>; store?: boolean; }; /** * Response for the write request * * @beta */ export type RecordsWriteResponse = ResponseStatus & { record?: Record; }; /** * Interface to interact with DWN Records and Protocols * * @beta */ export declare class DwnApi { private agent; private connectedDid; constructor(options: { agent: Web5Agent; connectedDid: string; }); /** * API to interact with DWN protocols (e.g., `dwn.protocols.configure()`). */ get protocols(): { /** * Configure method, used to setup a new protocol (or update) with the passed definitions */ configure: (request: ProtocolsConfigureRequest) => Promise<ProtocolsConfigureResponse>; /** * Query the available protocols */ query: (request: ProtocolsQueryRequest) => Promise<ProtocolsQueryResponse>; }; /** * API to interact with DWN records (e.g., `dwn.records.create()`). */ get records(): { /** * Alias for the `write` method */ create: (request: RecordsCreateRequest) => Promise<RecordsCreateResponse>; /** * Write a record based on an existing one (useful for updating an existing record) */ createFrom: (request: RecordsCreateFromRequest) => Promise<RecordsWriteResponse>; /** * Delete a record */ delete: (request: RecordsDeleteRequest) => Promise<ResponseStatus>; /** * Query a single or multiple records based on the given filter */ query: (request: RecordsQueryRequest) => Promise<RecordsQueryResponse>; /** * Read a single record based on the given filter */ read: (request: RecordsReadRequest) => Promise<RecordsReadResponse>; /** * Writes a record to the DWN * * As a convenience, the Record instance returned will cache a copy of the data. This is done * to maintain consistency with other DWN methods, like RecordsQuery, that include relatively * small data payloads when returning RecordsWrite message properties. Regardless of data * size, methods such as `record.data.stream()` will return the data when called even if it * requires fetching from the DWN datastore. */ write: (request: RecordsWriteRequest) => Promise<RecordsWriteResponse>; }; } //# sourceMappingURL=dwn-api.d.ts.map