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
22 changes: 22 additions & 0 deletions src/hooks/params-for-server/params-for-server.hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ describe('paramsForServer', () => {
})
})

it('should accept a readonly array', () => {
const whitelist = ['a', 'b'] as const
expect(
paramsForServer(whitelist)({
params: {
a: 1,
b: 2,
query: {},
},
} as HookContext),
).toEqual({
params: {
query: {
_$client: {
a: 1,
b: 2,
},
},
},
})
})

it('should move params to query._$client and leave remaining', () => {
expect(
paramsForServer('a')({
Expand Down
6 changes: 3 additions & 3 deletions src/internal.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const hasOwnProperty = (
return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x))
}

export type MaybeArray<T> = T | T[]
export const toArray = <T>(value: T | T[]): T[] =>
Array.isArray(value) ? value : [value]
export type MaybeArray<T> = T | readonly T[]
export const toArray = <T>(value: T | readonly T[]): T[] =>
Array.isArray(value) ? [...value] : [value as T]

export type Promisable<T> = T | Promise<T>
export type KeyOf<T> = Extract<keyof T, string>
Expand Down
Loading