shoal-web-sdk 0.0.1
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.
- package/package.json +37 -0
- package/sdk/client/client.gen.ts +268 -0
- package/sdk/client/index.ts +26 -0
- package/sdk/client/types.gen.ts +268 -0
- package/sdk/client/utils.gen.ts +332 -0
- package/sdk/client.gen.ts +18 -0
- package/sdk/core/auth.gen.ts +42 -0
- package/sdk/core/bodySerializer.gen.ts +100 -0
- package/sdk/core/params.gen.ts +153 -0
- package/sdk/core/pathSerializer.gen.ts +181 -0
- package/sdk/core/queryKeySerializer.gen.ts +136 -0
- package/sdk/core/serverSentEvents.gen.ts +264 -0
- package/sdk/core/types.gen.ts +118 -0
- package/sdk/core/utils.gen.ts +143 -0
- package/sdk/index.ts +4 -0
- package/sdk/sdk.gen.ts +37 -0
- package/sdk/types.gen.ts +23 -0
- package/tanstack-codegen/generated/generated.ts +33 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
|
|
4
|
+
import {
|
|
5
|
+
type ArraySeparatorStyle,
|
|
6
|
+
serializeArrayParam,
|
|
7
|
+
serializeObjectParam,
|
|
8
|
+
serializePrimitiveParam,
|
|
9
|
+
} from './pathSerializer.gen';
|
|
10
|
+
|
|
11
|
+
export interface PathSerializer {
|
|
12
|
+
path: Record<string, unknown>;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
17
|
+
|
|
18
|
+
export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
19
|
+
let url = _url;
|
|
20
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
21
|
+
if (matches) {
|
|
22
|
+
for (const match of matches) {
|
|
23
|
+
let explode = false;
|
|
24
|
+
let name = match.substring(1, match.length - 1);
|
|
25
|
+
let style: ArraySeparatorStyle = 'simple';
|
|
26
|
+
|
|
27
|
+
if (name.endsWith('*')) {
|
|
28
|
+
explode = true;
|
|
29
|
+
name = name.substring(0, name.length - 1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (name.startsWith('.')) {
|
|
33
|
+
name = name.substring(1);
|
|
34
|
+
style = 'label';
|
|
35
|
+
} else if (name.startsWith(';')) {
|
|
36
|
+
name = name.substring(1);
|
|
37
|
+
style = 'matrix';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const value = path[name];
|
|
41
|
+
|
|
42
|
+
if (value === undefined || value === null) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
url = url.replace(
|
|
48
|
+
match,
|
|
49
|
+
serializeArrayParam({ explode, name, style, value }),
|
|
50
|
+
);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof value === 'object') {
|
|
55
|
+
url = url.replace(
|
|
56
|
+
match,
|
|
57
|
+
serializeObjectParam({
|
|
58
|
+
explode,
|
|
59
|
+
name,
|
|
60
|
+
style,
|
|
61
|
+
value: value as Record<string, unknown>,
|
|
62
|
+
valueOnly: true,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (style === 'matrix') {
|
|
69
|
+
url = url.replace(
|
|
70
|
+
match,
|
|
71
|
+
`;${serializePrimitiveParam({
|
|
72
|
+
name,
|
|
73
|
+
value: value as string,
|
|
74
|
+
})}`,
|
|
75
|
+
);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const replaceValue = encodeURIComponent(
|
|
80
|
+
style === 'label' ? `.${value as string}` : (value as string),
|
|
81
|
+
);
|
|
82
|
+
url = url.replace(match, replaceValue);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return url;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const getUrl = ({
|
|
89
|
+
baseUrl,
|
|
90
|
+
path,
|
|
91
|
+
query,
|
|
92
|
+
querySerializer,
|
|
93
|
+
url: _url,
|
|
94
|
+
}: {
|
|
95
|
+
baseUrl?: string;
|
|
96
|
+
path?: Record<string, unknown>;
|
|
97
|
+
query?: Record<string, unknown>;
|
|
98
|
+
querySerializer: QuerySerializer;
|
|
99
|
+
url: string;
|
|
100
|
+
}) => {
|
|
101
|
+
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
102
|
+
let url = (baseUrl ?? '') + pathUrl;
|
|
103
|
+
if (path) {
|
|
104
|
+
url = defaultPathSerializer({ path, url });
|
|
105
|
+
}
|
|
106
|
+
let search = query ? querySerializer(query) : '';
|
|
107
|
+
if (search.startsWith('?')) {
|
|
108
|
+
search = search.substring(1);
|
|
109
|
+
}
|
|
110
|
+
if (search) {
|
|
111
|
+
url += `?${search}`;
|
|
112
|
+
}
|
|
113
|
+
return url;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export function getValidRequestBody(options: {
|
|
117
|
+
body?: unknown;
|
|
118
|
+
bodySerializer?: BodySerializer | null;
|
|
119
|
+
serializedBody?: unknown;
|
|
120
|
+
}) {
|
|
121
|
+
const hasBody = options.body !== undefined;
|
|
122
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
123
|
+
|
|
124
|
+
if (isSerializedBody) {
|
|
125
|
+
if ('serializedBody' in options) {
|
|
126
|
+
const hasSerializedBody =
|
|
127
|
+
options.serializedBody !== undefined && options.serializedBody !== '';
|
|
128
|
+
|
|
129
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// not all clients implement a serializedBody property (i.e. client-axios)
|
|
133
|
+
return options.body !== '' ? options.body : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// plain/text body
|
|
137
|
+
if (hasBody) {
|
|
138
|
+
return options.body;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// no body was provided
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
package/sdk/index.ts
ADDED
package/sdk/sdk.gen.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { Client, Options as Options2, TDataShape } from './client';
|
|
4
|
+
import { client } from './client.gen';
|
|
5
|
+
import type { GetHelloData, GetHelloResponses } from './types.gen';
|
|
6
|
+
|
|
7
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
|
|
8
|
+
/**
|
|
9
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
10
|
+
* individual options. This might be also useful if you want to implement a
|
|
11
|
+
* custom client.
|
|
12
|
+
*/
|
|
13
|
+
client?: Client;
|
|
14
|
+
/**
|
|
15
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
16
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
17
|
+
*/
|
|
18
|
+
meta?: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Hello world
|
|
23
|
+
*
|
|
24
|
+
* Simple health / sanity endpoint
|
|
25
|
+
*/
|
|
26
|
+
export const getHello = <ThrowOnError extends boolean = false>(options?: Options<GetHelloData, ThrowOnError>) => {
|
|
27
|
+
return (options?.client ?? client).get<GetHelloResponses, unknown, ThrowOnError>({
|
|
28
|
+
security: [
|
|
29
|
+
{
|
|
30
|
+
scheme: 'bearer',
|
|
31
|
+
type: 'http'
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
url: '/hello',
|
|
35
|
+
...options
|
|
36
|
+
});
|
|
37
|
+
};
|
package/sdk/types.gen.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type ClientOptions = {
|
|
4
|
+
baseUrl: 'http://localhost:8080/core-service/v1' | (string & {});
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type GetHelloData = {
|
|
8
|
+
body?: never;
|
|
9
|
+
path?: never;
|
|
10
|
+
query?: never;
|
|
11
|
+
url: '/hello';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type GetHelloResponses = {
|
|
15
|
+
/**
|
|
16
|
+
* Hello world response
|
|
17
|
+
*/
|
|
18
|
+
200: {
|
|
19
|
+
message?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type GetHelloResponse = GetHelloResponses[keyof GetHelloResponses];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* THIS FILE IS GENERATED - DO NOT EDIT */
|
|
2
|
+
|
|
3
|
+
//@ts-expect-error
|
|
4
|
+
import { useAccessToken } from "@/lib/hooks/auth"
|
|
5
|
+
|
|
6
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
|
7
|
+
import { isPromise } from "../util"
|
|
8
|
+
import { GetHelloData } from "../../sdk/types.gen"
|
|
9
|
+
import { getHello } from "../../sdk/sdk.gen"
|
|
10
|
+
|
|
11
|
+
export const useGetHello = (options?:Omit<GetHelloData, "url"> & {enabled?:boolean}) =>
|
|
12
|
+
{
|
|
13
|
+
const token = useAccessToken();
|
|
14
|
+
let {enabled, ...rest} = options || { enabled: true };
|
|
15
|
+
const opts = { throwOnError: true, url: "/hello" }
|
|
16
|
+
const funcer = async () =>
|
|
17
|
+
{
|
|
18
|
+
const auth = isPromise(token) ? (await token) || "" : token || "";
|
|
19
|
+
if(isPromise(token) && !token) return;
|
|
20
|
+
const res = await getHello({ ...opts, ...rest, auth })
|
|
21
|
+
return res.data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if(!token) enabled = false;
|
|
25
|
+
|
|
26
|
+
return useQuery(
|
|
27
|
+
{
|
|
28
|
+
queryKey: ["hello", options?.query ?? {}],
|
|
29
|
+
queryFn: funcer,
|
|
30
|
+
enabled,
|
|
31
|
+
retry: false
|
|
32
|
+
})
|
|
33
|
+
}
|