@townco/fly 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/client/client.gen.d.ts +2 -0
  2. package/dist/client/client.gen.js +228 -0
  3. package/dist/client/index.d.ts +8 -0
  4. package/dist/client/index.js +6 -0
  5. package/dist/client/types.gen.d.ts +117 -0
  6. package/dist/client/types.gen.js +2 -0
  7. package/dist/client/utils.gen.d.ts +33 -0
  8. package/dist/client/utils.gen.js +231 -0
  9. package/{src/client.gen.ts → dist/client.gen.d.ts} +3 -16
  10. package/dist/client.gen.js +3 -0
  11. package/dist/core/auth.gen.d.ts +18 -0
  12. package/dist/core/auth.gen.js +14 -0
  13. package/dist/core/bodySerializer.gen.d.ts +25 -0
  14. package/dist/core/bodySerializer.gen.js +57 -0
  15. package/dist/core/params.gen.d.ts +43 -0
  16. package/dist/core/params.gen.js +100 -0
  17. package/dist/core/pathSerializer.gen.d.ts +33 -0
  18. package/dist/core/pathSerializer.gen.js +114 -0
  19. package/dist/core/queryKeySerializer.gen.d.ts +18 -0
  20. package/dist/core/queryKeySerializer.gen.js +99 -0
  21. package/dist/core/serverSentEvents.gen.d.ts +71 -0
  22. package/dist/core/serverSentEvents.gen.js +135 -0
  23. package/dist/core/types.gen.d.ts +78 -0
  24. package/dist/core/types.gen.js +2 -0
  25. package/dist/core/utils.gen.d.ts +19 -0
  26. package/dist/core/utils.gen.js +87 -0
  27. package/dist/hey-api.d.ts +2 -0
  28. package/dist/hey-api.js +6 -0
  29. package/dist/index.d.ts +2 -0
  30. package/{src/index.ts → dist/index.js} +0 -2
  31. package/dist/sdk.gen.d.ts +379 -0
  32. package/dist/sdk.gen.js +557 -0
  33. package/dist/types.gen.d.ts +2592 -0
  34. package/dist/types.gen.js +2 -0
  35. package/package.json +6 -3
  36. package/.envrc +0 -11
  37. package/openapi-ts.config.ts +0 -7
  38. package/spec.json +0 -5072
  39. package/src/client/client.gen.ts +0 -301
  40. package/src/client/index.ts +0 -25
  41. package/src/client/types.gen.ts +0 -241
  42. package/src/client/utils.gen.ts +0 -337
  43. package/src/core/auth.gen.ts +0 -42
  44. package/src/core/bodySerializer.gen.ts +0 -100
  45. package/src/core/params.gen.ts +0 -176
  46. package/src/core/pathSerializer.gen.ts +0 -181
  47. package/src/core/queryKeySerializer.gen.ts +0 -136
  48. package/src/core/serverSentEvents.gen.ts +0 -264
  49. package/src/core/types.gen.ts +0 -118
  50. package/src/core/utils.gen.ts +0 -143
  51. package/src/hey-api.ts +0 -8
  52. package/src/sdk.gen.ts +0 -1163
  53. package/src/types.gen.ts +0 -2974
  54. package/tsconfig.json +0 -11
@@ -1,337 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import { getAuthToken } from "../core/auth.gen";
4
- import type { QuerySerializerOptions } from "../core/bodySerializer.gen";
5
- import { jsonBodySerializer } from "../core/bodySerializer.gen";
6
- import {
7
- serializeArrayParam,
8
- serializeObjectParam,
9
- serializePrimitiveParam,
10
- } from "../core/pathSerializer.gen";
11
- import { getUrl } from "../core/utils.gen";
12
- import type {
13
- Client,
14
- ClientOptions,
15
- Config,
16
- RequestOptions,
17
- } from "./types.gen";
18
-
19
- export const createQuerySerializer = <T = unknown>({
20
- parameters = {},
21
- ...args
22
- }: QuerySerializerOptions = {}) => {
23
- const querySerializer = (queryParams: T) => {
24
- const search: string[] = [];
25
- if (queryParams && typeof queryParams === "object") {
26
- for (const name in queryParams) {
27
- const value = queryParams[name];
28
-
29
- if (value === undefined || value === null) {
30
- continue;
31
- }
32
-
33
- const options = parameters[name] || args;
34
-
35
- if (Array.isArray(value)) {
36
- const serializedArray = serializeArrayParam({
37
- allowReserved: options.allowReserved,
38
- explode: true,
39
- name,
40
- style: "form",
41
- value,
42
- ...options.array,
43
- });
44
- if (serializedArray) search.push(serializedArray);
45
- } else if (typeof value === "object") {
46
- const serializedObject = serializeObjectParam({
47
- allowReserved: options.allowReserved,
48
- explode: true,
49
- name,
50
- style: "deepObject",
51
- value: value as Record<string, unknown>,
52
- ...options.object,
53
- });
54
- if (serializedObject) search.push(serializedObject);
55
- } else {
56
- const serializedPrimitive = serializePrimitiveParam({
57
- allowReserved: options.allowReserved,
58
- name,
59
- value: value as string,
60
- });
61
- if (serializedPrimitive) search.push(serializedPrimitive);
62
- }
63
- }
64
- }
65
- return search.join("&");
66
- };
67
- return querySerializer;
68
- };
69
-
70
- /**
71
- * Infers parseAs value from provided Content-Type header.
72
- */
73
- export const getParseAs = (
74
- contentType: string | null,
75
- ): Exclude<Config["parseAs"], "auto"> => {
76
- if (!contentType) {
77
- // If no Content-Type header is provided, the best we can do is return the raw response body,
78
- // which is effectively the same as the 'stream' option.
79
- return "stream";
80
- }
81
-
82
- const cleanContent = contentType.split(";")[0]?.trim();
83
-
84
- if (!cleanContent) {
85
- return;
86
- }
87
-
88
- if (
89
- cleanContent.startsWith("application/json") ||
90
- cleanContent.endsWith("+json")
91
- ) {
92
- return "json";
93
- }
94
-
95
- if (cleanContent === "multipart/form-data") {
96
- return "formData";
97
- }
98
-
99
- if (
100
- ["application/", "audio/", "image/", "video/"].some((type) =>
101
- cleanContent.startsWith(type),
102
- )
103
- ) {
104
- return "blob";
105
- }
106
-
107
- if (cleanContent.startsWith("text/")) {
108
- return "text";
109
- }
110
-
111
- return;
112
- };
113
-
114
- const checkForExistence = (
115
- options: Pick<RequestOptions, "auth" | "query"> & {
116
- headers: Headers;
117
- },
118
- name?: string,
119
- ): boolean => {
120
- if (!name) {
121
- return false;
122
- }
123
- if (
124
- options.headers.has(name) ||
125
- options.query?.[name] ||
126
- options.headers.get("Cookie")?.includes(`${name}=`)
127
- ) {
128
- return true;
129
- }
130
- return false;
131
- };
132
-
133
- export const setAuthParams = async ({
134
- security,
135
- ...options
136
- }: Pick<Required<RequestOptions>, "security"> &
137
- Pick<RequestOptions, "auth" | "query"> & {
138
- headers: Headers;
139
- }) => {
140
- for (const auth of security) {
141
- if (checkForExistence(options, auth.name)) {
142
- continue;
143
- }
144
-
145
- const token = await getAuthToken(auth, options.auth);
146
-
147
- if (!token) {
148
- continue;
149
- }
150
-
151
- const name = auth.name ?? "Authorization";
152
-
153
- switch (auth.in) {
154
- case "query":
155
- if (!options.query) {
156
- options.query = {};
157
- }
158
- options.query[name] = token;
159
- break;
160
- case "cookie":
161
- options.headers.append("Cookie", `${name}=${token}`);
162
- break;
163
- case "header":
164
- default:
165
- options.headers.set(name, token);
166
- break;
167
- }
168
- }
169
- };
170
-
171
- export const buildUrl: Client["buildUrl"] = (options) =>
172
- getUrl({
173
- baseUrl: options.baseUrl as string,
174
- path: options.path,
175
- query: options.query,
176
- querySerializer:
177
- typeof options.querySerializer === "function"
178
- ? options.querySerializer
179
- : createQuerySerializer(options.querySerializer),
180
- url: options.url,
181
- });
182
-
183
- export const mergeConfigs = (a: Config, b: Config): Config => {
184
- const config = { ...a, ...b };
185
- if (config.baseUrl?.endsWith("/")) {
186
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
187
- }
188
- config.headers = mergeHeaders(a.headers, b.headers);
189
- return config;
190
- };
191
-
192
- const headersEntries = (headers: Headers): Array<[string, string]> => {
193
- const entries: Array<[string, string]> = [];
194
- headers.forEach((value, key) => {
195
- entries.push([key, value]);
196
- });
197
- return entries;
198
- };
199
-
200
- export const mergeHeaders = (
201
- ...headers: Array<Required<Config>["headers"] | undefined>
202
- ): Headers => {
203
- const mergedHeaders = new Headers();
204
- for (const header of headers) {
205
- if (!header) {
206
- continue;
207
- }
208
-
209
- const iterator =
210
- header instanceof Headers
211
- ? headersEntries(header)
212
- : Object.entries(header);
213
-
214
- for (const [key, value] of iterator) {
215
- if (value === null) {
216
- mergedHeaders.delete(key);
217
- } else if (Array.isArray(value)) {
218
- for (const v of value) {
219
- mergedHeaders.append(key, v as string);
220
- }
221
- } else if (value !== undefined) {
222
- // assume object headers are meant to be JSON stringified, i.e. their
223
- // content value in OpenAPI specification is 'application/json'
224
- mergedHeaders.set(
225
- key,
226
- typeof value === "object" ? JSON.stringify(value) : (value as string),
227
- );
228
- }
229
- }
230
- }
231
- return mergedHeaders;
232
- };
233
-
234
- type ErrInterceptor<Err, Res, Req, Options> = (
235
- error: Err,
236
- response: Res,
237
- request: Req,
238
- options: Options,
239
- ) => Err | Promise<Err>;
240
-
241
- type ReqInterceptor<Req, Options> = (
242
- request: Req,
243
- options: Options,
244
- ) => Req | Promise<Req>;
245
-
246
- type ResInterceptor<Res, Req, Options> = (
247
- response: Res,
248
- request: Req,
249
- options: Options,
250
- ) => Res | Promise<Res>;
251
-
252
- class Interceptors<Interceptor> {
253
- fns: Array<Interceptor | null> = [];
254
-
255
- clear(): void {
256
- this.fns = [];
257
- }
258
-
259
- eject(id: number | Interceptor): void {
260
- const index = this.getInterceptorIndex(id);
261
- if (this.fns[index]) {
262
- this.fns[index] = null;
263
- }
264
- }
265
-
266
- exists(id: number | Interceptor): boolean {
267
- const index = this.getInterceptorIndex(id);
268
- return Boolean(this.fns[index]);
269
- }
270
-
271
- getInterceptorIndex(id: number | Interceptor): number {
272
- if (typeof id === "number") {
273
- return this.fns[id] ? id : -1;
274
- }
275
- return this.fns.indexOf(id);
276
- }
277
-
278
- update(
279
- id: number | Interceptor,
280
- fn: Interceptor,
281
- ): number | Interceptor | false {
282
- const index = this.getInterceptorIndex(id);
283
- if (this.fns[index]) {
284
- this.fns[index] = fn;
285
- return id;
286
- }
287
- return false;
288
- }
289
-
290
- use(fn: Interceptor): number {
291
- this.fns.push(fn);
292
- return this.fns.length - 1;
293
- }
294
- }
295
-
296
- export interface Middleware<Req, Res, Err, Options> {
297
- error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
298
- request: Interceptors<ReqInterceptor<Req, Options>>;
299
- response: Interceptors<ResInterceptor<Res, Req, Options>>;
300
- }
301
-
302
- export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
303
- Req,
304
- Res,
305
- Err,
306
- Options
307
- > => ({
308
- error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
309
- request: new Interceptors<ReqInterceptor<Req, Options>>(),
310
- response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
311
- });
312
-
313
- const defaultQuerySerializer = createQuerySerializer({
314
- allowReserved: false,
315
- array: {
316
- explode: true,
317
- style: "form",
318
- },
319
- object: {
320
- explode: true,
321
- style: "deepObject",
322
- },
323
- });
324
-
325
- const defaultHeaders = {
326
- "Content-Type": "application/json",
327
- };
328
-
329
- export const createConfig = <T extends ClientOptions = ClientOptions>(
330
- override: Config<Omit<ClientOptions, keyof T> & T> = {},
331
- ): Config<Omit<ClientOptions, keyof T> & T> => ({
332
- ...jsonBodySerializer,
333
- headers: defaultHeaders,
334
- parseAs: "auto",
335
- querySerializer: defaultQuerySerializer,
336
- ...override,
337
- });
@@ -1,42 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- export type AuthToken = string | undefined;
4
-
5
- export interface Auth {
6
- /**
7
- * Which part of the request do we use to send the auth?
8
- *
9
- * @default 'header'
10
- */
11
- in?: "header" | "query" | "cookie";
12
- /**
13
- * Header or query parameter name.
14
- *
15
- * @default 'Authorization'
16
- */
17
- name?: string;
18
- scheme?: "basic" | "bearer";
19
- type: "apiKey" | "http";
20
- }
21
-
22
- export const getAuthToken = async (
23
- auth: Auth,
24
- callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
25
- ): Promise<string | undefined> => {
26
- const token =
27
- typeof callback === "function" ? await callback(auth) : callback;
28
-
29
- if (!token) {
30
- return;
31
- }
32
-
33
- if (auth.scheme === "bearer") {
34
- return `Bearer ${token}`;
35
- }
36
-
37
- if (auth.scheme === "basic") {
38
- return `Basic ${btoa(token)}`;
39
- }
40
-
41
- return token;
42
- };
@@ -1,100 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import type {
4
- ArrayStyle,
5
- ObjectStyle,
6
- SerializerOptions,
7
- } from "./pathSerializer.gen";
8
-
9
- export type QuerySerializer = (query: Record<string, unknown>) => string;
10
-
11
- export type BodySerializer = (body: any) => any;
12
-
13
- type QuerySerializerOptionsObject = {
14
- allowReserved?: boolean;
15
- array?: Partial<SerializerOptions<ArrayStyle>>;
16
- object?: Partial<SerializerOptions<ObjectStyle>>;
17
- };
18
-
19
- export type QuerySerializerOptions = QuerySerializerOptionsObject & {
20
- /**
21
- * Per-parameter serialization overrides. When provided, these settings
22
- * override the global array/object settings for specific parameter names.
23
- */
24
- parameters?: Record<string, QuerySerializerOptionsObject>;
25
- };
26
-
27
- const serializeFormDataPair = (
28
- data: FormData,
29
- key: string,
30
- value: unknown,
31
- ): void => {
32
- if (typeof value === "string" || value instanceof Blob) {
33
- data.append(key, value);
34
- } else if (value instanceof Date) {
35
- data.append(key, value.toISOString());
36
- } else {
37
- data.append(key, JSON.stringify(value));
38
- }
39
- };
40
-
41
- const serializeUrlSearchParamsPair = (
42
- data: URLSearchParams,
43
- key: string,
44
- value: unknown,
45
- ): void => {
46
- if (typeof value === "string") {
47
- data.append(key, value);
48
- } else {
49
- data.append(key, JSON.stringify(value));
50
- }
51
- };
52
-
53
- export const formDataBodySerializer = {
54
- bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
55
- body: T,
56
- ): FormData => {
57
- const data = new FormData();
58
-
59
- Object.entries(body).forEach(([key, value]) => {
60
- if (value === undefined || value === null) {
61
- return;
62
- }
63
- if (Array.isArray(value)) {
64
- value.forEach((v) => serializeFormDataPair(data, key, v));
65
- } else {
66
- serializeFormDataPair(data, key, value);
67
- }
68
- });
69
-
70
- return data;
71
- },
72
- };
73
-
74
- export const jsonBodySerializer = {
75
- bodySerializer: <T>(body: T): string =>
76
- JSON.stringify(body, (_key, value) =>
77
- typeof value === "bigint" ? value.toString() : value,
78
- ),
79
- };
80
-
81
- export const urlSearchParamsBodySerializer = {
82
- bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
83
- body: T,
84
- ): string => {
85
- const data = new URLSearchParams();
86
-
87
- Object.entries(body).forEach(([key, value]) => {
88
- if (value === undefined || value === null) {
89
- return;
90
- }
91
- if (Array.isArray(value)) {
92
- value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
93
- } else {
94
- serializeUrlSearchParamsPair(data, key, value);
95
- }
96
- });
97
-
98
- return data.toString();
99
- },
100
- };
@@ -1,176 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- type Slot = "body" | "headers" | "path" | "query";
4
-
5
- export type Field =
6
- | {
7
- in: Exclude<Slot, "body">;
8
- /**
9
- * Field name. This is the name we want the user to see and use.
10
- */
11
- key: string;
12
- /**
13
- * Field mapped name. This is the name we want to use in the request.
14
- * If omitted, we use the same value as `key`.
15
- */
16
- map?: string;
17
- }
18
- | {
19
- in: Extract<Slot, "body">;
20
- /**
21
- * Key isn't required for bodies.
22
- */
23
- key?: string;
24
- map?: string;
25
- }
26
- | {
27
- /**
28
- * Field name. This is the name we want the user to see and use.
29
- */
30
- key: string;
31
- /**
32
- * Field mapped name. This is the name we want to use in the request.
33
- * If `in` is omitted, `map` aliases `key` to the transport layer.
34
- */
35
- map: Slot;
36
- };
37
-
38
- export interface Fields {
39
- allowExtra?: Partial<Record<Slot, boolean>>;
40
- args?: ReadonlyArray<Field>;
41
- }
42
-
43
- export type FieldsConfig = ReadonlyArray<Field | Fields>;
44
-
45
- const extraPrefixesMap: Record<string, Slot> = {
46
- $body_: "body",
47
- $headers_: "headers",
48
- $path_: "path",
49
- $query_: "query",
50
- };
51
- const extraPrefixes = Object.entries(extraPrefixesMap);
52
-
53
- type KeyMap = Map<
54
- string,
55
- | {
56
- in: Slot;
57
- map?: string;
58
- }
59
- | {
60
- in?: never;
61
- map: Slot;
62
- }
63
- >;
64
-
65
- const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
66
- if (!map) {
67
- map = new Map();
68
- }
69
-
70
- for (const config of fields) {
71
- if ("in" in config) {
72
- if (config.key) {
73
- map.set(config.key, {
74
- in: config.in,
75
- map: config.map,
76
- });
77
- }
78
- } else if ("key" in config) {
79
- map.set(config.key, {
80
- map: config.map,
81
- });
82
- } else if (config.args) {
83
- buildKeyMap(config.args, map);
84
- }
85
- }
86
-
87
- return map;
88
- };
89
-
90
- interface Params {
91
- body: unknown;
92
- headers: Record<string, unknown>;
93
- path: Record<string, unknown>;
94
- query: Record<string, unknown>;
95
- }
96
-
97
- const stripEmptySlots = (params: Params) => {
98
- for (const [slot, value] of Object.entries(params)) {
99
- if (value && typeof value === "object" && !Object.keys(value).length) {
100
- delete params[slot as Slot];
101
- }
102
- }
103
- };
104
-
105
- export const buildClientParams = (
106
- args: ReadonlyArray<unknown>,
107
- fields: FieldsConfig,
108
- ) => {
109
- const params: Params = {
110
- body: {},
111
- headers: {},
112
- path: {},
113
- query: {},
114
- };
115
-
116
- const map = buildKeyMap(fields);
117
-
118
- let config: FieldsConfig[number] | undefined;
119
-
120
- for (const [index, arg] of args.entries()) {
121
- if (fields[index]) {
122
- config = fields[index];
123
- }
124
-
125
- if (!config) {
126
- continue;
127
- }
128
-
129
- if ("in" in config) {
130
- if (config.key) {
131
- const field = map.get(config.key)!;
132
- const name = field.map || config.key;
133
- if (field.in) {
134
- (params[field.in] as Record<string, unknown>)[name] = arg;
135
- }
136
- } else {
137
- params.body = arg;
138
- }
139
- } else {
140
- for (const [key, value] of Object.entries(arg ?? {})) {
141
- const field = map.get(key);
142
-
143
- if (field) {
144
- if (field.in) {
145
- const name = field.map || key;
146
- (params[field.in] as Record<string, unknown>)[name] = value;
147
- } else {
148
- params[field.map] = value;
149
- }
150
- } else {
151
- const extra = extraPrefixes.find(([prefix]) =>
152
- key.startsWith(prefix),
153
- );
154
-
155
- if (extra) {
156
- const [prefix, slot] = extra;
157
- (params[slot] as Record<string, unknown>)[
158
- key.slice(prefix.length)
159
- ] = value;
160
- } else if ("allowExtra" in config && config.allowExtra) {
161
- for (const [slot, allowed] of Object.entries(config.allowExtra)) {
162
- if (allowed) {
163
- (params[slot as Slot] as Record<string, unknown>)[key] = value;
164
- break;
165
- }
166
- }
167
- }
168
- }
169
- }
170
- }
171
- }
172
-
173
- stripEmptySlots(params);
174
-
175
- return params;
176
- };