@fndchagas/coolify-mcp 0.1.2 → 0.1.3
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/README.md +33 -62
- package/dist/config.js +2 -1
- package/dist/coolify/client.js +12 -49
- package/dist/coolify/constants.js +3 -0
- package/dist/generated/client/client.gen.js +229 -0
- package/dist/generated/client/index.js +6 -0
- package/dist/generated/client/types.gen.js +2 -0
- package/dist/generated/client/utils.gen.js +231 -0
- package/dist/generated/client.gen.js +3 -0
- package/dist/generated/core/auth.gen.js +14 -0
- package/dist/generated/core/bodySerializer.gen.js +57 -0
- package/dist/generated/core/params.gen.js +100 -0
- package/dist/generated/core/pathSerializer.gen.js +114 -0
- package/dist/generated/core/queryKeySerializer.gen.js +99 -0
- package/dist/generated/core/serverSentEvents.gen.js +137 -0
- package/dist/generated/core/types.gen.js +2 -0
- package/dist/generated/core/utils.gen.js +87 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/sdk.gen.js +176 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/generated/zod.gen.js +340 -0
- package/dist/server.js +21 -3
- package/dist/tools/coolify.js +120 -117
- package/package.json +16 -5
- package/dist/generated/coolify-api.js +0 -5
- package/openapi/coolify/v4.0.0-beta.460.json +0 -11151
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { getAuthToken } from '../core/auth.gen.js';
|
|
3
|
+
import { jsonBodySerializer } from '../core/bodySerializer.gen.js';
|
|
4
|
+
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from '../core/pathSerializer.gen.js';
|
|
5
|
+
import { getUrl } from '../core/utils.gen.js';
|
|
6
|
+
export const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
7
|
+
const querySerializer = (queryParams) => {
|
|
8
|
+
const search = [];
|
|
9
|
+
if (queryParams && typeof queryParams === 'object') {
|
|
10
|
+
for (const name in queryParams) {
|
|
11
|
+
const value = queryParams[name];
|
|
12
|
+
if (value === undefined || value === null) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const options = parameters[name] || args;
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
const serializedArray = serializeArrayParam({
|
|
18
|
+
allowReserved: options.allowReserved,
|
|
19
|
+
explode: true,
|
|
20
|
+
name,
|
|
21
|
+
style: 'form',
|
|
22
|
+
value,
|
|
23
|
+
...options.array,
|
|
24
|
+
});
|
|
25
|
+
if (serializedArray)
|
|
26
|
+
search.push(serializedArray);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof value === 'object') {
|
|
29
|
+
const serializedObject = serializeObjectParam({
|
|
30
|
+
allowReserved: options.allowReserved,
|
|
31
|
+
explode: true,
|
|
32
|
+
name,
|
|
33
|
+
style: 'deepObject',
|
|
34
|
+
value: value,
|
|
35
|
+
...options.object,
|
|
36
|
+
});
|
|
37
|
+
if (serializedObject)
|
|
38
|
+
search.push(serializedObject);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
42
|
+
allowReserved: options.allowReserved,
|
|
43
|
+
name,
|
|
44
|
+
value: value,
|
|
45
|
+
});
|
|
46
|
+
if (serializedPrimitive)
|
|
47
|
+
search.push(serializedPrimitive);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return search.join('&');
|
|
52
|
+
};
|
|
53
|
+
return querySerializer;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Infers parseAs value from provided Content-Type header.
|
|
57
|
+
*/
|
|
58
|
+
export const getParseAs = (contentType) => {
|
|
59
|
+
if (!contentType) {
|
|
60
|
+
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
61
|
+
// which is effectively the same as the 'stream' option.
|
|
62
|
+
return 'stream';
|
|
63
|
+
}
|
|
64
|
+
const cleanContent = contentType.split(';')[0]?.trim();
|
|
65
|
+
if (!cleanContent) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (cleanContent.startsWith('application/json') ||
|
|
69
|
+
cleanContent.endsWith('+json')) {
|
|
70
|
+
return 'json';
|
|
71
|
+
}
|
|
72
|
+
if (cleanContent === 'multipart/form-data') {
|
|
73
|
+
return 'formData';
|
|
74
|
+
}
|
|
75
|
+
if (['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))) {
|
|
76
|
+
return 'blob';
|
|
77
|
+
}
|
|
78
|
+
if (cleanContent.startsWith('text/')) {
|
|
79
|
+
return 'text';
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
};
|
|
83
|
+
const checkForExistence = (options, name) => {
|
|
84
|
+
if (!name) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (options.headers.has(name) ||
|
|
88
|
+
options.query?.[name] ||
|
|
89
|
+
options.headers.get('Cookie')?.includes(`${name}=`)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
};
|
|
94
|
+
export const setAuthParams = async ({ security, ...options }) => {
|
|
95
|
+
for (const auth of security) {
|
|
96
|
+
if (checkForExistence(options, auth.name)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const token = await getAuthToken(auth, options.auth);
|
|
100
|
+
if (!token) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const name = auth.name ?? 'Authorization';
|
|
104
|
+
switch (auth.in) {
|
|
105
|
+
case 'query':
|
|
106
|
+
if (!options.query) {
|
|
107
|
+
options.query = {};
|
|
108
|
+
}
|
|
109
|
+
options.query[name] = token;
|
|
110
|
+
break;
|
|
111
|
+
case 'cookie':
|
|
112
|
+
options.headers.append('Cookie', `${name}=${token}`);
|
|
113
|
+
break;
|
|
114
|
+
case 'header':
|
|
115
|
+
default:
|
|
116
|
+
options.headers.set(name, token);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export const buildUrl = (options) => getUrl({
|
|
122
|
+
baseUrl: options.baseUrl,
|
|
123
|
+
path: options.path,
|
|
124
|
+
query: options.query,
|
|
125
|
+
querySerializer: typeof options.querySerializer === 'function'
|
|
126
|
+
? options.querySerializer
|
|
127
|
+
: createQuerySerializer(options.querySerializer),
|
|
128
|
+
url: options.url,
|
|
129
|
+
});
|
|
130
|
+
export const mergeConfigs = (a, b) => {
|
|
131
|
+
const config = { ...a, ...b };
|
|
132
|
+
if (config.baseUrl?.endsWith('/')) {
|
|
133
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
134
|
+
}
|
|
135
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
136
|
+
return config;
|
|
137
|
+
};
|
|
138
|
+
const headersEntries = (headers) => {
|
|
139
|
+
const entries = [];
|
|
140
|
+
headers.forEach((value, key) => {
|
|
141
|
+
entries.push([key, value]);
|
|
142
|
+
});
|
|
143
|
+
return entries;
|
|
144
|
+
};
|
|
145
|
+
export const mergeHeaders = (...headers) => {
|
|
146
|
+
const mergedHeaders = new Headers();
|
|
147
|
+
for (const header of headers) {
|
|
148
|
+
if (!header) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const iterator = header instanceof Headers
|
|
152
|
+
? headersEntries(header)
|
|
153
|
+
: Object.entries(header);
|
|
154
|
+
for (const [key, value] of iterator) {
|
|
155
|
+
if (value === null) {
|
|
156
|
+
mergedHeaders.delete(key);
|
|
157
|
+
}
|
|
158
|
+
else if (Array.isArray(value)) {
|
|
159
|
+
for (const v of value) {
|
|
160
|
+
mergedHeaders.append(key, v);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (value !== undefined) {
|
|
164
|
+
// assume object headers are meant to be JSON stringified, i.e. their
|
|
165
|
+
// content value in OpenAPI specification is 'application/json'
|
|
166
|
+
mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return mergedHeaders;
|
|
171
|
+
};
|
|
172
|
+
class Interceptors {
|
|
173
|
+
fns = [];
|
|
174
|
+
clear() {
|
|
175
|
+
this.fns = [];
|
|
176
|
+
}
|
|
177
|
+
eject(id) {
|
|
178
|
+
const index = this.getInterceptorIndex(id);
|
|
179
|
+
if (this.fns[index]) {
|
|
180
|
+
this.fns[index] = null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exists(id) {
|
|
184
|
+
const index = this.getInterceptorIndex(id);
|
|
185
|
+
return Boolean(this.fns[index]);
|
|
186
|
+
}
|
|
187
|
+
getInterceptorIndex(id) {
|
|
188
|
+
if (typeof id === 'number') {
|
|
189
|
+
return this.fns[id] ? id : -1;
|
|
190
|
+
}
|
|
191
|
+
return this.fns.indexOf(id);
|
|
192
|
+
}
|
|
193
|
+
update(id, fn) {
|
|
194
|
+
const index = this.getInterceptorIndex(id);
|
|
195
|
+
if (this.fns[index]) {
|
|
196
|
+
this.fns[index] = fn;
|
|
197
|
+
return id;
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
use(fn) {
|
|
202
|
+
this.fns.push(fn);
|
|
203
|
+
return this.fns.length - 1;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export const createInterceptors = () => ({
|
|
207
|
+
error: new Interceptors(),
|
|
208
|
+
request: new Interceptors(),
|
|
209
|
+
response: new Interceptors(),
|
|
210
|
+
});
|
|
211
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
212
|
+
allowReserved: false,
|
|
213
|
+
array: {
|
|
214
|
+
explode: true,
|
|
215
|
+
style: 'form',
|
|
216
|
+
},
|
|
217
|
+
object: {
|
|
218
|
+
explode: true,
|
|
219
|
+
style: 'deepObject',
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
const defaultHeaders = {
|
|
223
|
+
'Content-Type': 'application/json',
|
|
224
|
+
};
|
|
225
|
+
export const createConfig = (override = {}) => ({
|
|
226
|
+
...jsonBodySerializer,
|
|
227
|
+
headers: defaultHeaders,
|
|
228
|
+
parseAs: 'auto',
|
|
229
|
+
querySerializer: defaultQuerySerializer,
|
|
230
|
+
...override,
|
|
231
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export const getAuthToken = async (auth, callback) => {
|
|
3
|
+
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
4
|
+
if (!token) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (auth.scheme === 'bearer') {
|
|
8
|
+
return `Bearer ${token}`;
|
|
9
|
+
}
|
|
10
|
+
if (auth.scheme === 'basic') {
|
|
11
|
+
return `Basic ${btoa(token)}`;
|
|
12
|
+
}
|
|
13
|
+
return token;
|
|
14
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
const serializeFormDataPair = (data, key, value) => {
|
|
3
|
+
if (typeof value === 'string' || value instanceof Blob) {
|
|
4
|
+
data.append(key, value);
|
|
5
|
+
}
|
|
6
|
+
else if (value instanceof Date) {
|
|
7
|
+
data.append(key, value.toISOString());
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
data.append(key, JSON.stringify(value));
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const serializeUrlSearchParamsPair = (data, key, value) => {
|
|
14
|
+
if (typeof value === 'string') {
|
|
15
|
+
data.append(key, value);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
data.append(key, JSON.stringify(value));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const formDataBodySerializer = {
|
|
22
|
+
bodySerializer: (body) => {
|
|
23
|
+
const data = new FormData();
|
|
24
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
value.forEach((v) => serializeFormDataPair(data, key, v));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
serializeFormDataPair(data, key, value);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return data;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export const jsonBodySerializer = {
|
|
39
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === 'bigint' ? value.toString() : value),
|
|
40
|
+
};
|
|
41
|
+
export const urlSearchParamsBodySerializer = {
|
|
42
|
+
bodySerializer: (body) => {
|
|
43
|
+
const data = new URLSearchParams();
|
|
44
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
45
|
+
if (value === undefined || value === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
serializeUrlSearchParamsPair(data, key, value);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return data.toString();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
const extraPrefixesMap = {
|
|
3
|
+
$body_: 'body',
|
|
4
|
+
$headers_: 'headers',
|
|
5
|
+
$path_: 'path',
|
|
6
|
+
$query_: 'query',
|
|
7
|
+
};
|
|
8
|
+
const extraPrefixes = Object.entries(extraPrefixesMap);
|
|
9
|
+
const buildKeyMap = (fields, map) => {
|
|
10
|
+
if (!map) {
|
|
11
|
+
map = new Map();
|
|
12
|
+
}
|
|
13
|
+
for (const config of fields) {
|
|
14
|
+
if ('in' in config) {
|
|
15
|
+
if (config.key) {
|
|
16
|
+
map.set(config.key, {
|
|
17
|
+
in: config.in,
|
|
18
|
+
map: config.map,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if ('key' in config) {
|
|
23
|
+
map.set(config.key, {
|
|
24
|
+
map: config.map,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else if (config.args) {
|
|
28
|
+
buildKeyMap(config.args, map);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return map;
|
|
32
|
+
};
|
|
33
|
+
const stripEmptySlots = (params) => {
|
|
34
|
+
for (const [slot, value] of Object.entries(params)) {
|
|
35
|
+
if (value && typeof value === 'object' && !Object.keys(value).length) {
|
|
36
|
+
delete params[slot];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const buildClientParams = (args, fields) => {
|
|
41
|
+
const params = {
|
|
42
|
+
body: {},
|
|
43
|
+
headers: {},
|
|
44
|
+
path: {},
|
|
45
|
+
query: {},
|
|
46
|
+
};
|
|
47
|
+
const map = buildKeyMap(fields);
|
|
48
|
+
let config;
|
|
49
|
+
for (const [index, arg] of args.entries()) {
|
|
50
|
+
if (fields[index]) {
|
|
51
|
+
config = fields[index];
|
|
52
|
+
}
|
|
53
|
+
if (!config) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if ('in' in config) {
|
|
57
|
+
if (config.key) {
|
|
58
|
+
const field = map.get(config.key);
|
|
59
|
+
const name = field.map || config.key;
|
|
60
|
+
if (field.in) {
|
|
61
|
+
params[field.in][name] = arg;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
params.body = arg;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
70
|
+
const field = map.get(key);
|
|
71
|
+
if (field) {
|
|
72
|
+
if (field.in) {
|
|
73
|
+
const name = field.map || key;
|
|
74
|
+
params[field.in][name] = value;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
params[field.map] = value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
82
|
+
if (extra) {
|
|
83
|
+
const [prefix, slot] = extra;
|
|
84
|
+
params[slot][key.slice(prefix.length)] = value;
|
|
85
|
+
}
|
|
86
|
+
else if ('allowExtra' in config && config.allowExtra) {
|
|
87
|
+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
88
|
+
if (allowed) {
|
|
89
|
+
params[slot][key] = value;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
stripEmptySlots(params);
|
|
99
|
+
return params;
|
|
100
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export const separatorArrayExplode = (style) => {
|
|
3
|
+
switch (style) {
|
|
4
|
+
case 'label':
|
|
5
|
+
return '.';
|
|
6
|
+
case 'matrix':
|
|
7
|
+
return ';';
|
|
8
|
+
case 'simple':
|
|
9
|
+
return ',';
|
|
10
|
+
default:
|
|
11
|
+
return '&';
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const separatorArrayNoExplode = (style) => {
|
|
15
|
+
switch (style) {
|
|
16
|
+
case 'form':
|
|
17
|
+
return ',';
|
|
18
|
+
case 'pipeDelimited':
|
|
19
|
+
return '|';
|
|
20
|
+
case 'spaceDelimited':
|
|
21
|
+
return '%20';
|
|
22
|
+
default:
|
|
23
|
+
return ',';
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const separatorObjectExplode = (style) => {
|
|
27
|
+
switch (style) {
|
|
28
|
+
case 'label':
|
|
29
|
+
return '.';
|
|
30
|
+
case 'matrix':
|
|
31
|
+
return ';';
|
|
32
|
+
case 'simple':
|
|
33
|
+
return ',';
|
|
34
|
+
default:
|
|
35
|
+
return '&';
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const serializeArrayParam = ({ allowReserved, explode, name, style, value, }) => {
|
|
39
|
+
if (!explode) {
|
|
40
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
41
|
+
switch (style) {
|
|
42
|
+
case 'label':
|
|
43
|
+
return `.${joinedValues}`;
|
|
44
|
+
case 'matrix':
|
|
45
|
+
return `;${name}=${joinedValues}`;
|
|
46
|
+
case 'simple':
|
|
47
|
+
return joinedValues;
|
|
48
|
+
default:
|
|
49
|
+
return `${name}=${joinedValues}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const separator = separatorArrayExplode(style);
|
|
53
|
+
const joinedValues = value
|
|
54
|
+
.map((v) => {
|
|
55
|
+
if (style === 'label' || style === 'simple') {
|
|
56
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
57
|
+
}
|
|
58
|
+
return serializePrimitiveParam({
|
|
59
|
+
allowReserved,
|
|
60
|
+
name,
|
|
61
|
+
value: v,
|
|
62
|
+
});
|
|
63
|
+
})
|
|
64
|
+
.join(separator);
|
|
65
|
+
return style === 'label' || style === 'matrix'
|
|
66
|
+
? separator + joinedValues
|
|
67
|
+
: joinedValues;
|
|
68
|
+
};
|
|
69
|
+
export const serializePrimitiveParam = ({ allowReserved, name, value, }) => {
|
|
70
|
+
if (value === undefined || value === null) {
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === 'object') {
|
|
74
|
+
throw new Error('Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.');
|
|
75
|
+
}
|
|
76
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
77
|
+
};
|
|
78
|
+
export const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly, }) => {
|
|
79
|
+
if (value instanceof Date) {
|
|
80
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
81
|
+
}
|
|
82
|
+
if (style !== 'deepObject' && !explode) {
|
|
83
|
+
let values = [];
|
|
84
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
85
|
+
values = [
|
|
86
|
+
...values,
|
|
87
|
+
key,
|
|
88
|
+
allowReserved ? v : encodeURIComponent(v),
|
|
89
|
+
];
|
|
90
|
+
});
|
|
91
|
+
const joinedValues = values.join(',');
|
|
92
|
+
switch (style) {
|
|
93
|
+
case 'form':
|
|
94
|
+
return `${name}=${joinedValues}`;
|
|
95
|
+
case 'label':
|
|
96
|
+
return `.${joinedValues}`;
|
|
97
|
+
case 'matrix':
|
|
98
|
+
return `;${name}=${joinedValues}`;
|
|
99
|
+
default:
|
|
100
|
+
return joinedValues;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const separator = separatorObjectExplode(style);
|
|
104
|
+
const joinedValues = Object.entries(value)
|
|
105
|
+
.map(([key, v]) => serializePrimitiveParam({
|
|
106
|
+
allowReserved,
|
|
107
|
+
name: style === 'deepObject' ? `${name}[${key}]` : key,
|
|
108
|
+
value: v,
|
|
109
|
+
}))
|
|
110
|
+
.join(separator);
|
|
111
|
+
return style === 'label' || style === 'matrix'
|
|
112
|
+
? separator + joinedValues
|
|
113
|
+
: joinedValues;
|
|
114
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
/**
|
|
3
|
+
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
|
|
4
|
+
*/
|
|
5
|
+
export const queryKeyJsonReplacer = (_key, value) => {
|
|
6
|
+
if (value === undefined ||
|
|
7
|
+
typeof value === 'function' ||
|
|
8
|
+
typeof value === 'symbol') {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'bigint') {
|
|
12
|
+
return value.toString();
|
|
13
|
+
}
|
|
14
|
+
if (value instanceof Date) {
|
|
15
|
+
return value.toISOString();
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Safely stringifies a value and parses it back into a JsonValue.
|
|
21
|
+
*/
|
|
22
|
+
export const stringifyToJsonValue = (input) => {
|
|
23
|
+
try {
|
|
24
|
+
const json = JSON.stringify(input, queryKeyJsonReplacer);
|
|
25
|
+
if (json === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return JSON.parse(json);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Detects plain objects (including objects with a null prototype).
|
|
36
|
+
*/
|
|
37
|
+
const isPlainObject = (value) => {
|
|
38
|
+
if (value === null || typeof value !== 'object') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const prototype = Object.getPrototypeOf(value);
|
|
42
|
+
return prototype === Object.prototype || prototype === null;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Turns URLSearchParams into a sorted JSON object for deterministic keys.
|
|
46
|
+
*/
|
|
47
|
+
const serializeSearchParams = (params) => {
|
|
48
|
+
const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b));
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const [key, value] of entries) {
|
|
51
|
+
const existing = result[key];
|
|
52
|
+
if (existing === undefined) {
|
|
53
|
+
result[key] = value;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(existing)) {
|
|
57
|
+
existing.push(value);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
result[key] = [existing, value];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Normalizes any accepted value into a JSON-friendly shape for query keys.
|
|
67
|
+
*/
|
|
68
|
+
export const serializeQueryKeyValue = (value) => {
|
|
69
|
+
if (value === null) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (typeof value === 'string' ||
|
|
73
|
+
typeof value === 'number' ||
|
|
74
|
+
typeof value === 'boolean') {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
if (value === undefined ||
|
|
78
|
+
typeof value === 'function' ||
|
|
79
|
+
typeof value === 'symbol') {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === 'bigint') {
|
|
83
|
+
return value.toString();
|
|
84
|
+
}
|
|
85
|
+
if (value instanceof Date) {
|
|
86
|
+
return value.toISOString();
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
return stringifyToJsonValue(value);
|
|
90
|
+
}
|
|
91
|
+
if (typeof URLSearchParams !== 'undefined' &&
|
|
92
|
+
value instanceof URLSearchParams) {
|
|
93
|
+
return serializeSearchParams(value);
|
|
94
|
+
}
|
|
95
|
+
if (isPlainObject(value)) {
|
|
96
|
+
return stringifyToJsonValue(value);
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
};
|