Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 route payload options missing types #4507

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 8 additions & 6 deletions lib/types/route.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ export interface RouteOptionsPayload {
*/
maxBytes?: number | undefined;

/**
* @default 1000
* Limits the size of incoming payloads to the specified byte count. Allowing very large payloads may cause the server to run out of memory.
damusix marked this conversation as resolved.
Show resolved Hide resolved
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmaxparts)
*/
maxParts?: number;

/**
* @default none.
* Overrides payload processing for multipart requests. Value can be one of:
Expand All @@ -267,12 +274,7 @@ export interface RouteOptionsPayload {
* * * * payload - the processed part payload.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmultipart)
*/
multipart?:
| false
| {
output: PayloadOutput | 'annotated';
}
| undefined;
multipart?: boolean | { output: PayloadOutput | 'annotated' };

/**
* @default 'data'.
Expand Down
2 changes: 2 additions & 0 deletions lib/types/server/methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type ServerMethod = (...args: any[]) => any;
*/
export interface ServerMethodCache extends PolicyOptions<any> {
generateTimeout: number | false;
cache?: string;
segment?: string;
}

/**
Expand Down
30 changes: 29 additions & 1 deletion test/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { types as lab } from '@hapi/lab';
import { expect } from '@hapi/code';
import * as CatboxMemory from '@hapi/catbox-memory';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependent on hapijs/catbox-memory#90 for tests to pass


import {
Plugin,
Expand Down Expand Up @@ -39,11 +40,17 @@ interface RequestDecorations {
type AppRequest = Request<RequestDecorations>;

const route: ServerRoute<RequestDecorations> = {
method: 'GET',
method: 'POST',
path: '/',
options: {
app: {
prefix: ['xx-']
},
payload: {
maxParts: 100,
maxBytes: 1024 * 1024,
output: 'stream',
multipart: true
}
},
handler: (request: AppRequest, h: ResponseToolkit) => {
Expand Down Expand Up @@ -96,3 +103,24 @@ check.type<RequestRoute | null>(server.match('get', '/'));
const sum = loadedServer.plugins.test.add(1, 2);
expect(sum).to.equal(130);
check.type<number>(sum);

server.cache.provision({
name: 'some-cache',
provider: {
constructor: CatboxMemory.Engine,
options: {
partition: 'test'
}
}
})

server.method('test.add', (a: number, b: number) => a + b, {
bind: server,
cache: {
expiresIn: 1000,
generateTimeout: 100,
cache: 'some-cache',
segment: 'test-segment',
},
generateKey: (a: number, b: number) => `${a}${b}`
});
Loading