import { apiWrapper, boolApiWrapper } from './index'; /** A raw collection row as returned by the API (positional from SQL columns) */ export type CollectionRow = [ uuid: string, name: string, lastChange: string, ]; /** A raw shared collection row as returned by the API */ export type SharedCollectionRow = [ uuid: string, name: string, user: string, ]; /** * Fetch all collections owned by the current user. * * @param token - The auth token * @returns An array of {@link CollectionRow} on success, or `undefined` on failure */ export async function getFullOwn(token: string): Promise { return apiWrapper('/api/collection/getFullOwn', { token }); } /** * Fetch the detail of a single owned collection by UUID. * * @param token - The auth token * @param uuid - The collection UUID * @returns A single {@link CollectionRow} on success, or `undefined` on failure */ export async function getDetailOwn(token: string, uuid: string): Promise { return apiWrapper('/api/collection/getDetailOwn', { token, uuid }); } /** * Create a new collection. * * @param token - The auth token * @param name - The collection name * @returns The new collection UUID on success, or `undefined` on failure */ export async function addOwn(token: string, name: string): Promise { return apiWrapper('/api/collection/addOwn', { token, name }); } /** * Update an existing collection's name. * * @param token - The auth token * @param uuid - The collection UUID * @param name - The new collection name * @param lastChange - The last known `lastChange` value (optimistic concurrency) * @returns The new `lastChange` value on success, or `undefined` on failure */ export async function updateOwn(token: string, uuid: string, name: string, lastChange: string): Promise { return apiWrapper('/api/collection/updateOwn', { token, uuid, name, lastChange }); } /** * Delete an owned collection. * * @param token - The auth token * @param uuid - The collection UUID * @param lastChange - The last known `lastChange` value (optimistic concurrency) * @returns `true` on success, `false` on failure */ export async function deleteOwn(token: string, uuid: string, lastChange: string): Promise { return boolApiWrapper('/api/collection/deleteOwn', { token, uuid, lastChange }); } /** * Fetch all users this collection is shared with. * * @param token - The auth token * @param uuid - The collection UUID * @returns An array of target usernames on success, or `undefined` on failure */ export async function getSharing(token: string, uuid: string): Promise { return apiWrapper('/api/collection/getSharing', { token, uuid }); } /** * Remove a sharing target from a collection. * * @param token - The auth token * @param uuid - The collection UUID * @param target - The username to unshare with * @param lastChange - The last known `lastChange` value (optimistic concurrency) * @returns The new `lastChange` value on success, or `undefined` on failure */ export async function deleteSharing(token: string, uuid: string, target: string, lastChange: string): Promise { return apiWrapper('/api/collection/deleteSharing', { token, uuid, target, lastChange }); } /** * Add a sharing target to a collection. * * @param token - The auth token * @param uuid - The collection UUID * @param target - The username to share with * @param lastChange - The last known `lastChange` value (optimistic concurrency) * @returns The new `lastChange` value on success, or `undefined` on failure */ export async function addSharing(token: string, uuid: string, target: string, lastChange: string): Promise { return apiWrapper('/api/collection/addSharing', { token, uuid, target, lastChange }); } /** * Fetch all collections shared with the current user. * * @param token - The auth token * @returns An array of {@link SharedCollectionRow} on success, or `undefined` on failure */ export async function getShared(token: string): Promise { return apiWrapper('/api/collection/getShared', { token }); }