@townco/fly 0.1.3 → 0.1.5

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,181 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- interface SerializeOptions<T>
4
- extends SerializePrimitiveOptions,
5
- SerializerOptions<T> {}
6
-
7
- interface SerializePrimitiveOptions {
8
- allowReserved?: boolean;
9
- name: string;
10
- }
11
-
12
- export interface SerializerOptions<T> {
13
- /**
14
- * @default true
15
- */
16
- explode: boolean;
17
- style: T;
18
- }
19
-
20
- export type ArrayStyle = "form" | "spaceDelimited" | "pipeDelimited";
21
- export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
22
- type MatrixStyle = "label" | "matrix" | "simple";
23
- export type ObjectStyle = "form" | "deepObject";
24
- type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
25
-
26
- interface SerializePrimitiveParam extends SerializePrimitiveOptions {
27
- value: string;
28
- }
29
-
30
- export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
31
- switch (style) {
32
- case "label":
33
- return ".";
34
- case "matrix":
35
- return ";";
36
- case "simple":
37
- return ",";
38
- default:
39
- return "&";
40
- }
41
- };
42
-
43
- export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
44
- switch (style) {
45
- case "form":
46
- return ",";
47
- case "pipeDelimited":
48
- return "|";
49
- case "spaceDelimited":
50
- return "%20";
51
- default:
52
- return ",";
53
- }
54
- };
55
-
56
- export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
57
- switch (style) {
58
- case "label":
59
- return ".";
60
- case "matrix":
61
- return ";";
62
- case "simple":
63
- return ",";
64
- default:
65
- return "&";
66
- }
67
- };
68
-
69
- export const serializeArrayParam = ({
70
- allowReserved,
71
- explode,
72
- name,
73
- style,
74
- value,
75
- }: SerializeOptions<ArraySeparatorStyle> & {
76
- value: unknown[];
77
- }) => {
78
- if (!explode) {
79
- const joinedValues = (
80
- allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
81
- ).join(separatorArrayNoExplode(style));
82
- switch (style) {
83
- case "label":
84
- return `.${joinedValues}`;
85
- case "matrix":
86
- return `;${name}=${joinedValues}`;
87
- case "simple":
88
- return joinedValues;
89
- default:
90
- return `${name}=${joinedValues}`;
91
- }
92
- }
93
-
94
- const separator = separatorArrayExplode(style);
95
- const joinedValues = value
96
- .map((v) => {
97
- if (style === "label" || style === "simple") {
98
- return allowReserved ? v : encodeURIComponent(v as string);
99
- }
100
-
101
- return serializePrimitiveParam({
102
- allowReserved,
103
- name,
104
- value: v as string,
105
- });
106
- })
107
- .join(separator);
108
- return style === "label" || style === "matrix"
109
- ? separator + joinedValues
110
- : joinedValues;
111
- };
112
-
113
- export const serializePrimitiveParam = ({
114
- allowReserved,
115
- name,
116
- value,
117
- }: SerializePrimitiveParam) => {
118
- if (value === undefined || value === null) {
119
- return "";
120
- }
121
-
122
- if (typeof value === "object") {
123
- throw new Error(
124
- "Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.",
125
- );
126
- }
127
-
128
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
129
- };
130
-
131
- export const serializeObjectParam = ({
132
- allowReserved,
133
- explode,
134
- name,
135
- style,
136
- value,
137
- valueOnly,
138
- }: SerializeOptions<ObjectSeparatorStyle> & {
139
- value: Record<string, unknown> | Date;
140
- valueOnly?: boolean;
141
- }) => {
142
- if (value instanceof Date) {
143
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
144
- }
145
-
146
- if (style !== "deepObject" && !explode) {
147
- let values: string[] = [];
148
- Object.entries(value).forEach(([key, v]) => {
149
- values = [
150
- ...values,
151
- key,
152
- allowReserved ? (v as string) : encodeURIComponent(v as string),
153
- ];
154
- });
155
- const joinedValues = values.join(",");
156
- switch (style) {
157
- case "form":
158
- return `${name}=${joinedValues}`;
159
- case "label":
160
- return `.${joinedValues}`;
161
- case "matrix":
162
- return `;${name}=${joinedValues}`;
163
- default:
164
- return joinedValues;
165
- }
166
- }
167
-
168
- const separator = separatorObjectExplode(style);
169
- const joinedValues = Object.entries(value)
170
- .map(([key, v]) =>
171
- serializePrimitiveParam({
172
- allowReserved,
173
- name: style === "deepObject" ? `${name}[${key}]` : key,
174
- value: v as string,
175
- }),
176
- )
177
- .join(separator);
178
- return style === "label" || style === "matrix"
179
- ? separator + joinedValues
180
- : joinedValues;
181
- };
@@ -1,136 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- /**
4
- * JSON-friendly union that mirrors what Pinia Colada can hash.
5
- */
6
- export type JsonValue =
7
- | null
8
- | string
9
- | number
10
- | boolean
11
- | JsonValue[]
12
- | { [key: string]: JsonValue };
13
-
14
- /**
15
- * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
16
- */
17
- export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
18
- if (
19
- value === undefined ||
20
- typeof value === "function" ||
21
- typeof value === "symbol"
22
- ) {
23
- return undefined;
24
- }
25
- if (typeof value === "bigint") {
26
- return value.toString();
27
- }
28
- if (value instanceof Date) {
29
- return value.toISOString();
30
- }
31
- return value;
32
- };
33
-
34
- /**
35
- * Safely stringifies a value and parses it back into a JsonValue.
36
- */
37
- export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => {
38
- try {
39
- const json = JSON.stringify(input, queryKeyJsonReplacer);
40
- if (json === undefined) {
41
- return undefined;
42
- }
43
- return JSON.parse(json) as JsonValue;
44
- } catch {
45
- return undefined;
46
- }
47
- };
48
-
49
- /**
50
- * Detects plain objects (including objects with a null prototype).
51
- */
52
- const isPlainObject = (value: unknown): value is Record<string, unknown> => {
53
- if (value === null || typeof value !== "object") {
54
- return false;
55
- }
56
- const prototype = Object.getPrototypeOf(value as object);
57
- return prototype === Object.prototype || prototype === null;
58
- };
59
-
60
- /**
61
- * Turns URLSearchParams into a sorted JSON object for deterministic keys.
62
- */
63
- const serializeSearchParams = (params: URLSearchParams): JsonValue => {
64
- const entries = Array.from(params.entries()).sort(([a], [b]) =>
65
- a.localeCompare(b),
66
- );
67
- const result: Record<string, JsonValue> = {};
68
-
69
- for (const [key, value] of entries) {
70
- const existing = result[key];
71
- if (existing === undefined) {
72
- result[key] = value;
73
- continue;
74
- }
75
-
76
- if (Array.isArray(existing)) {
77
- (existing as string[]).push(value);
78
- } else {
79
- result[key] = [existing, value];
80
- }
81
- }
82
-
83
- return result;
84
- };
85
-
86
- /**
87
- * Normalizes any accepted value into a JSON-friendly shape for query keys.
88
- */
89
- export const serializeQueryKeyValue = (
90
- value: unknown,
91
- ): JsonValue | undefined => {
92
- if (value === null) {
93
- return null;
94
- }
95
-
96
- if (
97
- typeof value === "string" ||
98
- typeof value === "number" ||
99
- typeof value === "boolean"
100
- ) {
101
- return value;
102
- }
103
-
104
- if (
105
- value === undefined ||
106
- typeof value === "function" ||
107
- typeof value === "symbol"
108
- ) {
109
- return undefined;
110
- }
111
-
112
- if (typeof value === "bigint") {
113
- return value.toString();
114
- }
115
-
116
- if (value instanceof Date) {
117
- return value.toISOString();
118
- }
119
-
120
- if (Array.isArray(value)) {
121
- return stringifyToJsonValue(value);
122
- }
123
-
124
- if (
125
- typeof URLSearchParams !== "undefined" &&
126
- value instanceof URLSearchParams
127
- ) {
128
- return serializeSearchParams(value);
129
- }
130
-
131
- if (isPlainObject(value)) {
132
- return stringifyToJsonValue(value);
133
- }
134
-
135
- return undefined;
136
- };
@@ -1,264 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import type { Config } from "./types.gen";
4
-
5
- export type ServerSentEventsOptions<TData = unknown> = Omit<
6
- RequestInit,
7
- "method"
8
- > &
9
- Pick<Config, "method" | "responseTransformer" | "responseValidator"> & {
10
- /**
11
- * Fetch API implementation. You can use this option to provide a custom
12
- * fetch instance.
13
- *
14
- * @default globalThis.fetch
15
- */
16
- fetch?: typeof fetch;
17
- /**
18
- * Implementing clients can call request interceptors inside this hook.
19
- */
20
- onRequest?: (url: string, init: RequestInit) => Promise<Request>;
21
- /**
22
- * Callback invoked when a network or parsing error occurs during streaming.
23
- *
24
- * This option applies only if the endpoint returns a stream of events.
25
- *
26
- * @param error The error that occurred.
27
- */
28
- onSseError?: (error: unknown) => void;
29
- /**
30
- * Callback invoked when an event is streamed from the server.
31
- *
32
- * This option applies only if the endpoint returns a stream of events.
33
- *
34
- * @param event Event streamed from the server.
35
- * @returns Nothing (void).
36
- */
37
- onSseEvent?: (event: StreamEvent<TData>) => void;
38
- serializedBody?: RequestInit["body"];
39
- /**
40
- * Default retry delay in milliseconds.
41
- *
42
- * This option applies only if the endpoint returns a stream of events.
43
- *
44
- * @default 3000
45
- */
46
- sseDefaultRetryDelay?: number;
47
- /**
48
- * Maximum number of retry attempts before giving up.
49
- */
50
- sseMaxRetryAttempts?: number;
51
- /**
52
- * Maximum retry delay in milliseconds.
53
- *
54
- * Applies only when exponential backoff is used.
55
- *
56
- * This option applies only if the endpoint returns a stream of events.
57
- *
58
- * @default 30000
59
- */
60
- sseMaxRetryDelay?: number;
61
- /**
62
- * Optional sleep function for retry backoff.
63
- *
64
- * Defaults to using `setTimeout`.
65
- */
66
- sseSleepFn?: (ms: number) => Promise<void>;
67
- url: string;
68
- };
69
-
70
- export interface StreamEvent<TData = unknown> {
71
- data: TData;
72
- event?: string;
73
- id?: string;
74
- retry?: number;
75
- }
76
-
77
- export type ServerSentEventsResult<
78
- TData = unknown,
79
- TReturn = void,
80
- TNext = unknown,
81
- > = {
82
- stream: AsyncGenerator<
83
- TData extends Record<string, unknown> ? TData[keyof TData] : TData,
84
- TReturn,
85
- TNext
86
- >;
87
- };
88
-
89
- export const createSseClient = <TData = unknown>({
90
- onRequest,
91
- onSseError,
92
- onSseEvent,
93
- responseTransformer,
94
- responseValidator,
95
- sseDefaultRetryDelay,
96
- sseMaxRetryAttempts,
97
- sseMaxRetryDelay,
98
- sseSleepFn,
99
- url,
100
- ...options
101
- }: ServerSentEventsOptions): ServerSentEventsResult<TData> => {
102
- let lastEventId: string | undefined;
103
-
104
- const sleep =
105
- sseSleepFn ??
106
- ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));
107
-
108
- const createStream = async function* () {
109
- let retryDelay: number = sseDefaultRetryDelay ?? 3000;
110
- let attempt = 0;
111
- const signal = options.signal ?? new AbortController().signal;
112
-
113
- while (true) {
114
- if (signal.aborted) break;
115
-
116
- attempt++;
117
-
118
- const headers =
119
- options.headers instanceof Headers
120
- ? options.headers
121
- : new Headers(options.headers as Record<string, string> | undefined);
122
-
123
- if (lastEventId !== undefined) {
124
- headers.set("Last-Event-ID", lastEventId);
125
- }
126
-
127
- try {
128
- const requestInit: RequestInit = {
129
- redirect: "follow",
130
- ...options,
131
- body: options.serializedBody,
132
- headers,
133
- signal,
134
- };
135
- let request = new Request(url, requestInit);
136
- if (onRequest) {
137
- request = await onRequest(url, requestInit);
138
- }
139
- // fetch must be assigned here, otherwise it would throw the error:
140
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
141
- const _fetch = options.fetch ?? globalThis.fetch;
142
- const response = await _fetch(request);
143
-
144
- if (!response.ok)
145
- throw new Error(
146
- `SSE failed: ${response.status} ${response.statusText}`,
147
- );
148
-
149
- if (!response.body) throw new Error("No body in SSE response");
150
-
151
- const reader = response.body
152
- .pipeThrough(new TextDecoderStream())
153
- .getReader();
154
-
155
- let buffer = "";
156
-
157
- const abortHandler = () => {
158
- try {
159
- reader.cancel();
160
- } catch {
161
- // noop
162
- }
163
- };
164
-
165
- signal.addEventListener("abort", abortHandler);
166
-
167
- try {
168
- while (true) {
169
- const { done, value } = await reader.read();
170
- if (done) break;
171
- buffer += value;
172
-
173
- const chunks = buffer.split("\n\n");
174
- buffer = chunks.pop() ?? "";
175
-
176
- for (const chunk of chunks) {
177
- const lines = chunk.split("\n");
178
- const dataLines: Array<string> = [];
179
- let eventName: string | undefined;
180
-
181
- for (const line of lines) {
182
- if (line.startsWith("data:")) {
183
- dataLines.push(line.replace(/^data:\s*/, ""));
184
- } else if (line.startsWith("event:")) {
185
- eventName = line.replace(/^event:\s*/, "");
186
- } else if (line.startsWith("id:")) {
187
- lastEventId = line.replace(/^id:\s*/, "");
188
- } else if (line.startsWith("retry:")) {
189
- const parsed = Number.parseInt(
190
- line.replace(/^retry:\s*/, ""),
191
- 10,
192
- );
193
- if (!Number.isNaN(parsed)) {
194
- retryDelay = parsed;
195
- }
196
- }
197
- }
198
-
199
- let data: unknown;
200
- let parsedJson = false;
201
-
202
- if (dataLines.length) {
203
- const rawData = dataLines.join("\n");
204
- try {
205
- data = JSON.parse(rawData);
206
- parsedJson = true;
207
- } catch {
208
- data = rawData;
209
- }
210
- }
211
-
212
- if (parsedJson) {
213
- if (responseValidator) {
214
- await responseValidator(data);
215
- }
216
-
217
- if (responseTransformer) {
218
- data = await responseTransformer(data);
219
- }
220
- }
221
-
222
- onSseEvent?.({
223
- data,
224
- event: eventName,
225
- id: lastEventId,
226
- retry: retryDelay,
227
- });
228
-
229
- if (dataLines.length) {
230
- yield data as any;
231
- }
232
- }
233
- }
234
- } finally {
235
- signal.removeEventListener("abort", abortHandler);
236
- reader.releaseLock();
237
- }
238
-
239
- break; // exit loop on normal completion
240
- } catch (error) {
241
- // connection failed or aborted; retry after delay
242
- onSseError?.(error);
243
-
244
- if (
245
- sseMaxRetryAttempts !== undefined &&
246
- attempt >= sseMaxRetryAttempts
247
- ) {
248
- break; // stop after firing error
249
- }
250
-
251
- // exponential backoff: double retry each attempt, cap at 30s
252
- const backoff = Math.min(
253
- retryDelay * 2 ** (attempt - 1),
254
- sseMaxRetryDelay ?? 30000,
255
- );
256
- await sleep(backoff);
257
- }
258
- }
259
- };
260
-
261
- const stream = createStream();
262
-
263
- return { stream };
264
- };
@@ -1,118 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import type { Auth, AuthToken } from "./auth.gen";
4
- import type {
5
- BodySerializer,
6
- QuerySerializer,
7
- QuerySerializerOptions,
8
- } from "./bodySerializer.gen";
9
-
10
- export type HttpMethod =
11
- | "connect"
12
- | "delete"
13
- | "get"
14
- | "head"
15
- | "options"
16
- | "patch"
17
- | "post"
18
- | "put"
19
- | "trace";
20
-
21
- export type Client<
22
- RequestFn = never,
23
- Config = unknown,
24
- MethodFn = never,
25
- BuildUrlFn = never,
26
- SseFn = never,
27
- > = {
28
- /**
29
- * Returns the final request URL.
30
- */
31
- buildUrl: BuildUrlFn;
32
- getConfig: () => Config;
33
- request: RequestFn;
34
- setConfig: (config: Config) => Config;
35
- } & {
36
- [K in HttpMethod]: MethodFn;
37
- } & ([SseFn] extends [never]
38
- ? { sse?: never }
39
- : { sse: { [K in HttpMethod]: SseFn } });
40
-
41
- export interface Config {
42
- /**
43
- * Auth token or a function returning auth token. The resolved value will be
44
- * added to the request payload as defined by its `security` array.
45
- */
46
- auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
47
- /**
48
- * A function for serializing request body parameter. By default,
49
- * {@link JSON.stringify()} will be used.
50
- */
51
- bodySerializer?: BodySerializer | null;
52
- /**
53
- * An object containing any HTTP headers that you want to pre-populate your
54
- * `Headers` object with.
55
- *
56
- * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
57
- */
58
- headers?:
59
- | RequestInit["headers"]
60
- | Record<
61
- string,
62
- | string
63
- | number
64
- | boolean
65
- | (string | number | boolean)[]
66
- | null
67
- | undefined
68
- | unknown
69
- >;
70
- /**
71
- * The request method.
72
- *
73
- * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
74
- */
75
- method?: Uppercase<HttpMethod>;
76
- /**
77
- * A function for serializing request query parameters. By default, arrays
78
- * will be exploded in form style, objects will be exploded in deepObject
79
- * style, and reserved characters are percent-encoded.
80
- *
81
- * This method will have no effect if the native `paramsSerializer()` Axios
82
- * API function is used.
83
- *
84
- * {@link https://swagger.io/docs/specification/serialization/#query View examples}
85
- */
86
- querySerializer?: QuerySerializer | QuerySerializerOptions;
87
- /**
88
- * A function validating request data. This is useful if you want to ensure
89
- * the request conforms to the desired shape, so it can be safely sent to
90
- * the server.
91
- */
92
- requestValidator?: (data: unknown) => Promise<unknown>;
93
- /**
94
- * A function transforming response data before it's returned. This is useful
95
- * for post-processing data, e.g. converting ISO strings into Date objects.
96
- */
97
- responseTransformer?: (data: unknown) => Promise<unknown>;
98
- /**
99
- * A function validating response data. This is useful if you want to ensure
100
- * the response conforms to the desired shape, so it can be safely passed to
101
- * the transformers and returned to the user.
102
- */
103
- responseValidator?: (data: unknown) => Promise<unknown>;
104
- }
105
-
106
- type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
107
- ? true
108
- : [T] extends [never | undefined]
109
- ? [undefined] extends [T]
110
- ? false
111
- : true
112
- : false;
113
-
114
- export type OmitNever<T extends Record<string, unknown>> = {
115
- [K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true
116
- ? never
117
- : K]: T[K];
118
- };