mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Fix pagination lint errors
This commit is contained in:
parent
f2e2072184
commit
70f0eb3b03
2 changed files with 12 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { paginated, paginatedList } from '@ditto/mastoapi/pagination';
|
import { paginated } from '@ditto/mastoapi/pagination';
|
||||||
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export interface Pagination {
|
||||||
|
max_id?: string;
|
||||||
|
min_id?: string;
|
||||||
|
since?: number;
|
||||||
|
until?: number;
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
|
}
|
||||||
|
|
||||||
/** Schema to parse pagination query params. */
|
/** Schema to parse pagination query params. */
|
||||||
export const paginationSchema = z.object({
|
export const paginationSchema: z.ZodType<Pagination> = z.object({
|
||||||
max_id: z.string().transform((val) => {
|
max_id: z.string().transform((val) => {
|
||||||
if (!val.includes('-')) return val;
|
if (!val.includes('-')) return val;
|
||||||
return val.split('-')[1];
|
return val.split('-')[1];
|
||||||
|
|
@ -11,4 +20,4 @@ export const paginationSchema = z.object({
|
||||||
until: z.coerce.number().nonnegative().optional().catch(undefined),
|
until: z.coerce.number().nonnegative().optional().catch(undefined),
|
||||||
limit: z.coerce.number().catch(20).transform((value) => Math.min(Math.max(value, 0), 40)),
|
limit: z.coerce.number().catch(20).transform((value) => Math.min(Math.max(value, 0), 40)),
|
||||||
offset: z.coerce.number().nonnegative().catch(0),
|
offset: z.coerce.number().nonnegative().catch(0),
|
||||||
});
|
}) as z.ZodType<Pagination>;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue