Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 9033211

Browse files
authored
fix(server): allow Infinity as pageSize option for REST api (#581)
* fix(server): allow Infinity as pageSize option for REST api * fix schema
1 parent cedef22 commit 9033211

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

packages/server/src/api/rest/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements Api
292292
schema: z.object(),
293293
log: loggerSchema.optional(),
294294
endpoint: z.string().min(1),
295-
pageSize: z.number().positive().optional(),
295+
pageSize: z.union([z.number().int().positive(), z.literal(Infinity)]).optional(),
296296
idDivider: z.string().min(1).optional(),
297297
urlSegmentCharset: z.string().min(1).optional(),
298298
modelNameMapping: z.record(z.string(), z.string()).optional(),

packages/server/test/api/options-validation.test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,36 @@ describe('API Handler Options Validation', () => {
260260
}).not.toThrow();
261261
});
262262

263+
it('should accept Infinity as pageSize to disable pagination', () => {
264+
expect(() => {
265+
new RestApiHandler({
266+
schema: client.$schema,
267+
endpoint: 'http://localhost/api',
268+
pageSize: Infinity,
269+
});
270+
}).not.toThrow();
271+
});
272+
273+
it('should throw error when pageSize is a decimal', () => {
274+
expect(() => {
275+
new RestApiHandler({
276+
schema: client.$schema,
277+
endpoint: 'http://localhost/api',
278+
pageSize: 10.5,
279+
});
280+
}).toThrow('Invalid options');
281+
});
282+
283+
it('should throw error when pageSize is NaN', () => {
284+
expect(() => {
285+
new RestApiHandler({
286+
schema: client.$schema,
287+
endpoint: 'http://localhost/api',
288+
pageSize: NaN,
289+
});
290+
}).toThrow('Invalid options');
291+
});
292+
263293
it('should accept single character idDivider', () => {
264294
expect(() => {
265295
new RestApiHandler({
@@ -555,13 +585,11 @@ describe('API Handler Options Validation', () => {
555585
});
556586

557587
it('RestApiHandler with disabled pagination (Infinity pageSize)', () => {
558-
// Note: According to the code, this would need to be set to Infinity
559-
// after construction, not in options, as Zod validation requires positive number
560588
expect(() => {
561589
new RestApiHandler({
562590
schema: client.$schema,
563591
endpoint: 'http://localhost/api',
564-
pageSize: 999999, // Large number as workaround
592+
pageSize: Infinity,
565593
});
566594
}).not.toThrow();
567595
});

0 commit comments

Comments
 (0)