Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class RestApiHandler<Schema extends SchemaDef = SchemaDef> 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(),
Expand Down
34 changes: 31 additions & 3 deletions packages/server/test/api/options-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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();
});
Expand Down
Loading