UNPKG

knack-nest

Version:
112 lines (110 loc) 5.08 kB
import { AuthenticateArgs, AuthenticateTokenArgs, CreateRecordArgs, CreateViewRecordArgs, DeletePayload, DeleteRecordArgs, DeleteViewRecordArgs, GetRecordArgs, GetRecordsArgs, GetRecordsPayload, ObjectPayload, UpdateRecordArgs, UpdateViewRecordArgs, UploadFileArgs, ViewRecordPayload } from "knack-sdk/dist/types"; export abstract class IGenericRepository { /** * Authenticate a user via their email and password * @param args - AuthenticateArgs * @param args.email - User's email * @param args.password - User's password * @returns Promise<void> */ abstract authenticate(args: AuthenticateArgs): Promise<string> /** * Authenticate tokens by getting a clean view * @param args - AuthenticateTokenArgs * @param args.sceneKey - The scene key * @param args.viewKey - The view key * @param args.token - The token to be validated * @returns Promise<ViewRecordPayload> */ abstract authenticateToken(args: AuthenticateTokenArgs): Promise<ViewRecordPayload> /** * Creates a record in the Object of your choice * @param args - CreateRecordArgs * @param args.objectKey - The desired Object where this record will live * @param args.data - JSON pojo of field keys with corresponding data * @returns Promise<ObjectPayload> */ abstract createRecord(args: CreateRecordArgs): Promise<ObjectPayload> /** * Creates a record in the Object of your choice, limited to a User's view * @param args - CreateViewRecordArgs * @param args.sceneKey - The scene key * @param args.viewKey - The view key * @param args.data - JSON pojo of field keys with corresponding data * @returns Promise<ViewRecordPayload> */ abstract createViewRecord(args: CreateViewRecordArgs): Promise<ViewRecordPayload> /** * Deletes a record by object key and record id * @param args - DeleteRecordArgs * @param args.objectKey - The Object where this record lives * @param args.recordId - The Record's ID that it to be deleted * @returns Promise<DeletePayload> */ abstract deleteRecord(args: DeleteRecordArgs): Promise<DeletePayload> /** * Deletes a record based on a users' allowed actions * @param args - DeleteViewRecordArgs * @param args.sceneKey - The scene key * @param args.viewKey - The view key * @param args.recordId - The Record's ID that it to be deleted * @returns Promise<DeletePayload> */ abstract deleteViewRecord(args: DeleteViewRecordArgs): Promise<DeletePayload> /** * Gets a record by object key and record id * @param args - GetRecordArgs * @param args.objectKey - The Object where this record lives * @param args.recordId - The Record's ID that it to be deleted * @returns Promise<ObjectPayload> */ abstract getRecord(args: GetRecordArgs): Promise<ObjectPayload> /** * Gets record by object key and filters. Supports pagination and sorting * @param args - GetRecordsArgs * @param args.objectKey - The Object where this record lives * @param [args.format] - Format of the response `raw`, `html`, or `both` * @param [args.filters] - Filter rules for narrowing your results * @param [args.page] - Page you're requesting * @param [args.rowsPerPage] - Number of rows per page * @param [args.sortField] - Field to sort results on * @param [args.sortOrder] - Ascending (`asc`) or Descending (`desc`) * @returns Promise<GetRecordsPayload> */ abstract getRecords(args: GetRecordsArgs): Promise<GetRecordsPayload> /** * Updates a record for a type of Object * @param args - UpdateRecordArgs * @param args.objectKey - The desired Object where this record is * @param args.recordId - The Record's ID that it to be updated * @param args.data - JSON pojo of field keys with corresponding data * @returns Promise<ObjectPayload> */ abstract updateRecord(args: UpdateRecordArgs): Promise<ObjectPayload> /** * Updates a record of a type of Object, limited to a User's view * @param args - UpdateViewRecordArgs * @param args.sceneKey - The scene key * @param args.viewKey - The view key * @param args.data - JSON pojo of field keys with corresponding data * @returns Promise<ViewRecordPayload> */ abstract updateViewRecord(args: UpdateViewRecordArgs): Promise<ViewRecordPayload> /** * Uploads a file or image to knack and return the public url. * @param args - UploadFileArgs * @param args.file - Readable Stream of the file you wish to upload * @returns Promise<ObjectPayload> */ abstract uploadFileToRecord(args: UploadFileArgs): Promise<ObjectPayload> /** * Uploads a file or image to a record in a designated field * @param args - UploadFileArgs * @param args.objectKey - The desired Object where this record will live * @param args.fieldKey - The desired Field where this file will be added * @param args.file - Readable Stream of the file you wish to upload * @param args.timeout - timeout to prevent hanging requests * @returns Promise<ObjectPayload> */ abstract uploadFile(args: UploadFileArgs): Promise<ObjectPayload> }