Skip to content

Commit 396c1ba

Browse files
committed
chore: create PaginatedCursorResponse
1 parent 42adea4 commit 396c1ba

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/api/schemas/responses/responses.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Static, Type } from '@sinclair/typebox';
2-
import { Nullable, OptionalNullable, PaginatedResponse } from '../util';
2+
import { Nullable, OptionalNullable, PaginatedCursorResponse, PaginatedResponse } from '../util';
33
import { MempoolStatsSchema } from '../entities/mempool-transactions';
44
import { MempoolTransactionSchema, TransactionSchema } from '../entities/transactions';
55
import { MicroblockSchema } from '../entities/microblock';
@@ -180,13 +180,5 @@ export const RunFaucetResponseSchema = Type.Object(
180180
);
181181
export type RunFaucetResponse = Static<typeof RunFaucetResponseSchema>;
182182

183-
export const BlockListV2ResponseSchema = Type.Object({
184-
limit: Type.Integer({ examples: [20] }),
185-
offset: Type.Integer({ examples: [0] }),
186-
total: Type.Integer({ examples: [1] }),
187-
next_cursor: Nullable(Type.String({ description: 'Next page cursor' })),
188-
prev_cursor: Nullable(Type.String({ description: 'Previous page cursor' })),
189-
cursor: Nullable(Type.String({ description: 'Current page cursor' })),
190-
results: Type.Array(NakamotoBlockSchema),
191-
});
183+
export const BlockListV2ResponseSchema = PaginatedCursorResponse(NakamotoBlockSchema);
192184
export type BlockListV2Response = Static<typeof BlockListV2ResponseSchema>;

src/api/schemas/util.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ export const PaginatedResponse = <T extends TSchema>(type: T, options?: ObjectOp
1212
},
1313
options
1414
);
15+
16+
export const PaginatedCursorResponse = <T extends TSchema>(type: T, options?: ObjectOptions) =>
17+
Type.Object(
18+
{
19+
limit: Type.Integer({ examples: [20] }),
20+
offset: Type.Integer({ examples: [0] }),
21+
total: Type.Integer({ examples: [1] }),
22+
next_cursor: Nullable(Type.String({ description: 'Next page cursor' })),
23+
prev_cursor: Nullable(Type.String({ description: 'Previous page cursor' })),
24+
cursor: Nullable(Type.String({ description: 'Current page cursor' })),
25+
results: Type.Array(type),
26+
},
27+
options
28+
);

0 commit comments

Comments
 (0)