From 6f2f1b8d09b1ea94d194f4954bc3d982a97e4cdf Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 9 Jan 2026 15:36:06 +0800 Subject: [PATCH 1/2] fix(server): allow Infinity as pageSize option for REST api --- packages/server/src/api/rest/index.ts | 2 +- .../test/api/options-validation.test.ts | 34 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/rest/index.ts b/packages/server/src/api/rest/index.ts index b4e5dce25..d8247ffb1 100644 --- a/packages/server/src/api/rest/index.ts +++ b/packages/server/src/api/rest/index.ts @@ -292,7 +292,7 @@ export class RestApiHandler implements Api schema: z.object(), log: loggerSchema.optional(), endpoint: z.string().min(1), - pageSize: z.number().positive().optional(), + pageSize: z.union([z.number().positive(), z.literal(Infinity)]).optional(), idDivider: z.string().min(1).optional(), urlSegmentCharset: z.string().min(1).optional(), modelNameMapping: z.record(z.string(), z.string()).optional(), diff --git a/packages/server/test/api/options-validation.test.ts b/packages/server/test/api/options-validation.test.ts index 5861a13c1..53f7f3680 100644 --- a/packages/server/test/api/options-validation.test.ts +++ b/packages/server/test/api/options-validation.test.ts @@ -260,6 +260,36 @@ describe('API Handler Options Validation', () => { }).not.toThrow(); }); + it('should accept Infinity as pageSize to disable pagination', () => { + expect(() => { + new RestApiHandler({ + schema: client.$schema, + endpoint: 'http://localhost/api', + pageSize: Infinity, + }); + }).not.toThrow(); + }); + + it('should throw error when pageSize is a decimal', () => { + expect(() => { + new RestApiHandler({ + schema: client.$schema, + endpoint: 'http://localhost/api', + pageSize: 10.5, + }); + }).toThrow('Invalid options'); + }); + + it('should throw error when pageSize is NaN', () => { + expect(() => { + new RestApiHandler({ + schema: client.$schema, + endpoint: 'http://localhost/api', + pageSize: NaN, + }); + }).toThrow('Invalid options'); + }); + it('should accept single character idDivider', () => { expect(() => { new RestApiHandler({ @@ -555,13 +585,11 @@ describe('API Handler Options Validation', () => { }); it('RestApiHandler with disabled pagination (Infinity pageSize)', () => { - // Note: According to the code, this would need to be set to Infinity - // after construction, not in options, as Zod validation requires positive number expect(() => { new RestApiHandler({ schema: client.$schema, endpoint: 'http://localhost/api', - pageSize: 999999, // Large number as workaround + pageSize: Infinity, }); }).not.toThrow(); }); From bd2562794f92b651d3aac148d1a57ba02c6c6810 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 9 Jan 2026 15:38:08 +0800 Subject: [PATCH 2/2] fix schema --- packages/server/src/api/rest/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/rest/index.ts b/packages/server/src/api/rest/index.ts index d8247ffb1..db342ba6e 100644 --- a/packages/server/src/api/rest/index.ts +++ b/packages/server/src/api/rest/index.ts @@ -292,7 +292,7 @@ export class RestApiHandler implements Api schema: z.object(), log: loggerSchema.optional(), endpoint: z.string().min(1), - pageSize: z.union([z.number().positive(), z.literal(Infinity)]).optional(), + pageSize: z.union([z.number().int().positive(), z.literal(Infinity)]).optional(), idDivider: z.string().min(1).optional(), urlSegmentCharset: z.string().min(1).optional(), modelNameMapping: z.record(z.string(), z.string()).optional(),