feat: improve api
This commit is contained in:
+95
-102
@@ -1,126 +1,119 @@
|
||||
import { apiWrapper, boolApiWrapper } from './index'
|
||||
import { apiWrapper, boolApiWrapper } from './index';
|
||||
|
||||
type Uuid = string;
|
||||
|
||||
// Collection item interface
|
||||
interface CollectionItem {
|
||||
uuid: Uuid
|
||||
name: string
|
||||
lastChange: string
|
||||
}
|
||||
|
||||
// Sharing info interface
|
||||
interface SharingInfo {
|
||||
target: string
|
||||
// Add other sharing-related fields as needed
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all owned collections
|
||||
* @param token - Authentication token
|
||||
* @returns Array of collection items or null if operation failed
|
||||
*/
|
||||
export async function getFullOwn(token: string): Promise<CollectionItem[] | undefined> {
|
||||
return apiWrapper('/api/collection/getFullOwn', { token });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get owned collection detail by UUID
|
||||
* @param token - Authentication token
|
||||
* @param uuid - Collection UUID
|
||||
* @returns Collection item or null if operation failed
|
||||
*/
|
||||
export async function getDetailOwn(token: string, uuid: Uuid): Promise<CollectionItem | undefined> {
|
||||
return apiWrapper('/api/collection/getDetailOwn', { token, uuid });
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new owned collection
|
||||
* @param token - Authentication token
|
||||
* @param name - Collection name
|
||||
* @returns Created collection item or null if operation failed
|
||||
*/
|
||||
export async function addOwn(token: string, name: string): Promise<Uuid | undefined> {
|
||||
return apiWrapper('/api/collection/addOwn', { token, name });
|
||||
}
|
||||
|
||||
/**
|
||||
* Update owned collection
|
||||
* @param token - Authentication token
|
||||
* @param uuid - Collection UUID
|
||||
* @param name - New name
|
||||
* @param lastChange - Last change timestamp
|
||||
* @returns Updated collection item or null if operation failed
|
||||
*/
|
||||
export async function updateOwn(
|
||||
token: string,
|
||||
uuid: Uuid,
|
||||
/** A raw collection row as returned by the API (positional from SQL columns) */
|
||||
export type CollectionRow = [
|
||||
uuid: string,
|
||||
name: string,
|
||||
lastChange: string
|
||||
): Promise<CollectionItem | undefined> {
|
||||
return apiWrapper('/api/collection/updateOwn', { token, uuid, name, lastChange });
|
||||
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<CollectionRow[] | undefined> {
|
||||
return apiWrapper<CollectionRow[]>('/api/collection/getFullOwn', { token });
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete owned collection
|
||||
* @param token - Authentication token
|
||||
* @param uuid - Collection UUID
|
||||
* @param lastChange - Last change timestamp
|
||||
* @returns true if deletion successful, false otherwise
|
||||
* 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 deleteOwn(token: string, uuid: Uuid, lastChange: string): Promise<boolean> {
|
||||
export async function getDetailOwn(token: string, uuid: string): Promise<CollectionRow | undefined> {
|
||||
return apiWrapper<CollectionRow>('/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<string | undefined> {
|
||||
return apiWrapper<string>('/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<string | undefined> {
|
||||
return apiWrapper<string>('/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<boolean> {
|
||||
return boolApiWrapper('/api/collection/deleteOwn', { token, uuid, lastChange });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sharing information for a collection
|
||||
* @param token - Authentication token
|
||||
* @param uuid - Collection UUID
|
||||
* @returns Array of sharing info or null if operation failed
|
||||
* 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: Uuid): Promise<SharingInfo[] | undefined> {
|
||||
return apiWrapper('/api/collection/getSharing', { token, uuid });
|
||||
export async function getSharing(token: string, uuid: string): Promise<string[] | undefined> {
|
||||
return apiWrapper<string[]>('/api/collection/getSharing', { token, uuid });
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete sharing for a collection
|
||||
* @param token - Authentication token
|
||||
* @param uuid - Collection UUID
|
||||
* @param target - Target user
|
||||
* @param lastChange - Last change timestamp
|
||||
* @returns Result data or null if operation failed
|
||||
* 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: Uuid,
|
||||
target: string,
|
||||
lastChange: string
|
||||
): Promise<any | undefined> {
|
||||
return apiWrapper('/api/collection/deleteSharing', { token, uuid, target, lastChange });
|
||||
export async function deleteSharing(token: string, uuid: string, target: string, lastChange: string): Promise<string | undefined> {
|
||||
return apiWrapper<string>('/api/collection/deleteSharing', { token, uuid, target, lastChange });
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sharing for a collection
|
||||
* @param token - Authentication token
|
||||
* @param uuid - Collection UUID
|
||||
* @param target - Target user
|
||||
* @param lastChange - Last change timestamp
|
||||
* @returns Result data or null if operation failed
|
||||
* 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: Uuid,
|
||||
target: string,
|
||||
lastChange: string
|
||||
): Promise<any | undefined> {
|
||||
return apiWrapper('/api/collection/addSharing', { token, uuid, target, lastChange });
|
||||
export async function addSharing(token: string, uuid: string, target: string, lastChange: string): Promise<string | undefined> {
|
||||
return apiWrapper<string>('/api/collection/addSharing', { token, uuid, target, lastChange });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all shared collections
|
||||
* @param token - Authentication token
|
||||
* @returns Array of collection items or null if operation failed
|
||||
* 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<CollectionItem[] | undefined> {
|
||||
return apiWrapper('/api/collection/getShared', { token });
|
||||
export async function getShared(token: string): Promise<SharedCollectionRow[] | undefined> {
|
||||
return apiWrapper<SharedCollectionRow[]>('/api/collection/getShared', { token });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user