diff --git a/packages/server/src/api/rest/index.ts b/packages/server/src/api/rest/index.ts index b4e5dce25..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.number().positive().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(), 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(); });