2023-04-23 02:09:25 -07:00
|
|
|
import { AxiosHeaders } from 'axios';
|
|
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
|
|
|
|
// Since ts-rest client returns a strict response type, we need to add the headers to the body object
|
|
|
|
|
export const resultWithHeaders = <ItemType extends z.ZodTypeAny>(itemSchema: ItemType) => {
|
|
|
|
|
return z.object({
|
|
|
|
|
data: itemSchema,
|
|
|
|
|
headers: z.instanceof(AxiosHeaders),
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-04-24 01:21:29 -07:00
|
|
|
|
|
|
|
|
export const resultSubsonicBaseResponse = <ItemType extends z.ZodRawShape>(
|
|
|
|
|
itemSchema: ItemType,
|
|
|
|
|
) => {
|
|
|
|
|
return z.object({
|
|
|
|
|
'subsonic-response': z
|
|
|
|
|
.object({
|
|
|
|
|
status: z.string(),
|
|
|
|
|
version: z.string(),
|
|
|
|
|
})
|
|
|
|
|
.extend(itemSchema),
|
|
|
|
|
});
|
|
|
|
|
};
|