31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
/**
|
|
* Limits shared by Convex functions and clients. Convex rejects arrays longer
|
|
* than 8,192 values in documents, arguments, and return values.
|
|
*/
|
|
|
|
/** Songs kept in the playback queue, including the current song. */
|
|
export const MAX_QUEUE_LENGTH = 5_000
|
|
|
|
/** Largest uploaded image (profile photo, playlist cover), in bytes after base64 decoding. */
|
|
export const MAX_IMAGE_UPLOAD_BYTES = 2 * 1024 * 1024
|
|
|
|
/** Album covers a generated playlist cover tiles 2x2. */
|
|
export const COVER_GRID_ALBUMS = 4
|
|
|
|
/** Most values Convex accepts in a single array. */
|
|
export const MAX_ARRAY_LENGTH = 8_192
|
|
|
|
/**
|
|
* A list split into arrays of at most `MAX_ARRAY_LENGTH` values, so a query can
|
|
* return more than one array allows. Read it back with `.flat()`.
|
|
*/
|
|
export type Chunked<T> = T[][]
|
|
|
|
export function chunk<T>(items: readonly T[]): Chunked<T> {
|
|
const chunks: Chunked<T> = []
|
|
for (let start = 0; start < items.length; start += MAX_ARRAY_LENGTH) {
|
|
chunks.push(items.slice(start, start + MAX_ARRAY_LENGTH))
|
|
}
|
|
return chunks
|
|
}
|