import ApiCall from "./ApiCall"; import Collections from "./Collections"; import Documents, { DeleteQuery, DocumentSchema, DocumentWriteParameters, } from "./Documents"; import { normalizeArrayableParams } from "./Utils"; export interface DocumentsRetrieveParameters { include_fields?: string | string[]; exclude_fields?: string | string[]; } export class Document { constructor( private collectionName: string, private documentId: string, private apiCall: ApiCall ) {} async retrieve(options?: DocumentsRetrieveParameters): Promise { const queryParams = normalizeArrayableParams(options ?? {}) return this.apiCall.get(this.endpointPath(), queryParams); } async delete(options?: DeleteQuery): Promise { return this.apiCall.delete(this.endpointPath(), options); } async update( partialDocument: Partial, options: DocumentWriteParameters = {} ): Promise { return this.apiCall.patch(this.endpointPath(), partialDocument, options); } private endpointPath(): string { return `${Collections.RESOURCEPATH}/${encodeURIComponent(this.collectionName)}${Documents.RESOURCEPATH}/${encodeURIComponent(this.documentId)}`; } }