fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at feat/use-query-options 82 lines 2.5 kB view raw
1// This file is auto-generated by @hey-api/openapi-ts 2 3import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen'; 4 5export type QuerySerializer = (query: Record<string, unknown>) => string; 6 7export type BodySerializer = (body: unknown) => unknown; 8 9type QuerySerializerOptionsObject = { 10 allowReserved?: boolean; 11 array?: Partial<SerializerOptions<ArrayStyle>>; 12 object?: Partial<SerializerOptions<ObjectStyle>>; 13}; 14 15export type QuerySerializerOptions = QuerySerializerOptionsObject & { 16 /** 17 * Per-parameter serialization overrides. When provided, these settings 18 * override the global array/object settings for specific parameter names. 19 */ 20 parameters?: Record<string, QuerySerializerOptionsObject>; 21}; 22 23const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => { 24 if (typeof value === 'string' || value instanceof Blob) { 25 data.append(key, value); 26 } else if (value instanceof Date) { 27 data.append(key, value.toISOString()); 28 } else { 29 data.append(key, JSON.stringify(value)); 30 } 31}; 32 33const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => { 34 if (typeof value === 'string') { 35 data.append(key, value); 36 } else { 37 data.append(key, JSON.stringify(value)); 38 } 39}; 40 41export const formDataBodySerializer = { 42 bodySerializer: (body: unknown): FormData => { 43 const data = new FormData(); 44 45 Object.entries(body as Record<string, unknown>).forEach(([key, value]) => { 46 if (value === undefined || value === null) { 47 return; 48 } 49 if (Array.isArray(value)) { 50 value.forEach((v) => serializeFormDataPair(data, key, v)); 51 } else { 52 serializeFormDataPair(data, key, value); 53 } 54 }); 55 56 return data; 57 }, 58}; 59 60export const jsonBodySerializer = { 61 bodySerializer: (body: unknown): string => 62 JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)), 63}; 64 65export const urlSearchParamsBodySerializer = { 66 bodySerializer: (body: unknown): string => { 67 const data = new URLSearchParams(); 68 69 Object.entries(body as Record<string, unknown>).forEach(([key, value]) => { 70 if (value === undefined || value === null) { 71 return; 72 } 73 if (Array.isArray(value)) { 74 value.forEach((v) => serializeUrlSearchParamsPair(data, key, v)); 75 } else { 76 serializeUrlSearchParamsPair(data, key, value); 77 } 78 }); 79 80 return data.toString(); 81 }, 82};