@robosystems/client 0.2.25 → 0.2.27
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 +7 -6
- package/bin/{create-feature → create-feature.sh} +11 -1
- package/client/client.gen.js +118 -34
- package/client/client.gen.ts +125 -38
- package/client/index.d.ts +2 -1
- package/client/index.js +3 -1
- package/client/index.ts +1 -1
- package/client/types.gen.d.ts +11 -16
- package/client/types.gen.js +0 -1
- package/client/types.gen.ts +44 -64
- package/client/utils.gen.d.ts +8 -20
- package/client/utils.gen.js +44 -112
- package/client/utils.gen.ts +57 -181
- package/client.gen.d.ts +3 -3
- package/client.gen.js +1 -3
- package/client.gen.ts +4 -6
- package/core/auth.gen.ts +1 -2
- package/core/bodySerializer.gen.d.ts +12 -4
- package/core/bodySerializer.gen.js +1 -1
- package/core/bodySerializer.gen.ts +17 -25
- package/core/params.gen.d.ts +10 -0
- package/core/params.gen.js +17 -5
- package/core/params.gen.ts +37 -21
- package/core/pathSerializer.gen.js +3 -11
- package/core/pathSerializer.gen.ts +4 -14
- package/core/queryKeySerializer.gen.d.ts +18 -0
- package/core/queryKeySerializer.gen.js +98 -0
- package/core/queryKeySerializer.gen.ts +117 -0
- package/core/serverSentEvents.gen.d.ts +71 -0
- package/core/serverSentEvents.gen.js +137 -0
- package/core/serverSentEvents.gen.ts +243 -0
- package/core/types.gen.d.ts +12 -12
- package/core/types.gen.js +0 -1
- package/core/types.gen.ts +21 -38
- package/core/utils.gen.d.ts +19 -0
- package/core/utils.gen.js +93 -0
- package/core/utils.gen.ts +140 -0
- package/extensions/QueryClient.js +23 -2
- package/extensions/QueryClient.test.ts +2 -1
- package/extensions/QueryClient.ts +27 -2
- package/index.ts +3 -2
- package/package.json +9 -7
- package/sdk/client/client.gen.js +118 -34
- package/sdk/client/client.gen.ts +125 -38
- package/sdk/client/index.d.ts +2 -1
- package/sdk/client/index.js +3 -1
- package/sdk/client/index.ts +1 -1
- package/sdk/client/types.gen.d.ts +11 -16
- package/sdk/client/types.gen.js +0 -1
- package/sdk/client/types.gen.ts +44 -64
- package/sdk/client/utils.gen.d.ts +8 -20
- package/sdk/client/utils.gen.js +44 -112
- package/sdk/client/utils.gen.ts +57 -181
- package/sdk/client.gen.d.ts +3 -3
- package/sdk/client.gen.js +1 -3
- package/sdk/client.gen.ts +4 -6
- package/sdk/core/auth.gen.ts +1 -2
- package/sdk/core/bodySerializer.gen.d.ts +12 -4
- package/sdk/core/bodySerializer.gen.js +1 -1
- package/sdk/core/bodySerializer.gen.ts +17 -25
- package/sdk/core/params.gen.d.ts +10 -0
- package/sdk/core/params.gen.js +17 -5
- package/sdk/core/params.gen.ts +37 -21
- package/sdk/core/pathSerializer.gen.js +3 -11
- package/sdk/core/pathSerializer.gen.ts +4 -14
- package/sdk/core/queryKeySerializer.gen.d.ts +18 -0
- package/sdk/core/queryKeySerializer.gen.js +98 -0
- package/sdk/core/queryKeySerializer.gen.ts +117 -0
- package/sdk/core/serverSentEvents.gen.d.ts +71 -0
- package/sdk/core/serverSentEvents.gen.js +137 -0
- package/sdk/core/serverSentEvents.gen.ts +243 -0
- package/sdk/core/types.gen.d.ts +12 -12
- package/sdk/core/types.gen.js +0 -1
- package/sdk/core/types.gen.ts +21 -38
- package/sdk/core/utils.gen.d.ts +19 -0
- package/sdk/core/utils.gen.js +93 -0
- package/sdk/core/utils.gen.ts +140 -0
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +114 -17
- package/sdk/index.ts +3 -2
- package/sdk/sdk.gen.d.ts +112 -3
- package/sdk/sdk.gen.js +778 -1736
- package/sdk/sdk.gen.ts +782 -1740
- package/sdk/types.gen.d.ts +851 -5
- package/sdk/types.gen.ts +852 -6
- package/sdk-extensions/QueryClient.js +23 -2
- package/sdk-extensions/QueryClient.test.ts +2 -1
- package/sdk-extensions/QueryClient.ts +27 -2
- package/sdk.gen.d.ts +112 -3
- package/sdk.gen.js +778 -1736
- package/sdk.gen.ts +782 -1740
- package/types.gen.d.ts +851 -5
- package/types.gen.ts +852 -6
package/sdk/client/utils.gen.js
CHANGED
|
@@ -1,63 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createConfig = exports.createInterceptors = exports.mergeHeaders = exports.mergeConfigs = exports.
|
|
4
|
+
exports.createConfig = exports.createInterceptors = exports.mergeHeaders = exports.mergeConfigs = exports.buildUrl = exports.setAuthParams = exports.getParseAs = exports.createQuerySerializer = void 0;
|
|
5
5
|
const auth_gen_1 = require("../core/auth.gen");
|
|
6
6
|
const bodySerializer_gen_1 = require("../core/bodySerializer.gen");
|
|
7
7
|
const pathSerializer_gen_1 = require("../core/pathSerializer.gen");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
let url = _url;
|
|
11
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
12
|
-
if (matches) {
|
|
13
|
-
for (const match of matches) {
|
|
14
|
-
let explode = false;
|
|
15
|
-
let name = match.substring(1, match.length - 1);
|
|
16
|
-
let style = 'simple';
|
|
17
|
-
if (name.endsWith('*')) {
|
|
18
|
-
explode = true;
|
|
19
|
-
name = name.substring(0, name.length - 1);
|
|
20
|
-
}
|
|
21
|
-
if (name.startsWith('.')) {
|
|
22
|
-
name = name.substring(1);
|
|
23
|
-
style = 'label';
|
|
24
|
-
}
|
|
25
|
-
else if (name.startsWith(';')) {
|
|
26
|
-
name = name.substring(1);
|
|
27
|
-
style = 'matrix';
|
|
28
|
-
}
|
|
29
|
-
const value = path[name];
|
|
30
|
-
if (value === undefined || value === null) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(value)) {
|
|
34
|
-
url = url.replace(match, (0, pathSerializer_gen_1.serializeArrayParam)({ explode, name, style, value }));
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (typeof value === 'object') {
|
|
38
|
-
url = url.replace(match, (0, pathSerializer_gen_1.serializeObjectParam)({
|
|
39
|
-
explode,
|
|
40
|
-
name,
|
|
41
|
-
style,
|
|
42
|
-
value: value,
|
|
43
|
-
valueOnly: true,
|
|
44
|
-
}));
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (style === 'matrix') {
|
|
48
|
-
url = url.replace(match, `;${(0, pathSerializer_gen_1.serializePrimitiveParam)({
|
|
49
|
-
name,
|
|
50
|
-
value: value,
|
|
51
|
-
})}`);
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
|
|
55
|
-
url = url.replace(match, replaceValue);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return url;
|
|
59
|
-
};
|
|
60
|
-
const createQuerySerializer = ({ allowReserved, array, object, } = {}) => {
|
|
8
|
+
const utils_gen_1 = require("../core/utils.gen");
|
|
9
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
61
10
|
const querySerializer = (queryParams) => {
|
|
62
11
|
const search = [];
|
|
63
12
|
if (queryParams && typeof queryParams === 'object') {
|
|
@@ -66,33 +15,34 @@ const createQuerySerializer = ({ allowReserved, array, object, } = {}) => {
|
|
|
66
15
|
if (value === undefined || value === null) {
|
|
67
16
|
continue;
|
|
68
17
|
}
|
|
18
|
+
const options = parameters[name] || args;
|
|
69
19
|
if (Array.isArray(value)) {
|
|
70
20
|
const serializedArray = (0, pathSerializer_gen_1.serializeArrayParam)({
|
|
71
|
-
allowReserved,
|
|
21
|
+
allowReserved: options.allowReserved,
|
|
72
22
|
explode: true,
|
|
73
23
|
name,
|
|
74
24
|
style: 'form',
|
|
75
25
|
value,
|
|
76
|
-
...array,
|
|
26
|
+
...options.array,
|
|
77
27
|
});
|
|
78
28
|
if (serializedArray)
|
|
79
29
|
search.push(serializedArray);
|
|
80
30
|
}
|
|
81
31
|
else if (typeof value === 'object') {
|
|
82
32
|
const serializedObject = (0, pathSerializer_gen_1.serializeObjectParam)({
|
|
83
|
-
allowReserved,
|
|
33
|
+
allowReserved: options.allowReserved,
|
|
84
34
|
explode: true,
|
|
85
35
|
name,
|
|
86
36
|
style: 'deepObject',
|
|
87
37
|
value: value,
|
|
88
|
-
...object,
|
|
38
|
+
...options.object,
|
|
89
39
|
});
|
|
90
40
|
if (serializedObject)
|
|
91
41
|
search.push(serializedObject);
|
|
92
42
|
}
|
|
93
43
|
else {
|
|
94
44
|
const serializedPrimitive = (0, pathSerializer_gen_1.serializePrimitiveParam)({
|
|
95
|
-
allowReserved,
|
|
45
|
+
allowReserved: options.allowReserved,
|
|
96
46
|
name,
|
|
97
47
|
value: value,
|
|
98
48
|
});
|
|
@@ -119,8 +69,7 @@ const getParseAs = (contentType) => {
|
|
|
119
69
|
if (!cleanContent) {
|
|
120
70
|
return;
|
|
121
71
|
}
|
|
122
|
-
if (cleanContent.startsWith('application/json') ||
|
|
123
|
-
cleanContent.endsWith('+json')) {
|
|
72
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
124
73
|
return 'json';
|
|
125
74
|
}
|
|
126
75
|
if (cleanContent === 'multipart/form-data') {
|
|
@@ -174,35 +123,16 @@ const setAuthParams = async ({ security, ...options }) => {
|
|
|
174
123
|
}
|
|
175
124
|
};
|
|
176
125
|
exports.setAuthParams = setAuthParams;
|
|
177
|
-
const buildUrl = (options) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
return url;
|
|
188
|
-
};
|
|
126
|
+
const buildUrl = (options) => (0, utils_gen_1.getUrl)({
|
|
127
|
+
baseUrl: options.baseUrl,
|
|
128
|
+
path: options.path,
|
|
129
|
+
query: options.query,
|
|
130
|
+
querySerializer: typeof options.querySerializer === 'function'
|
|
131
|
+
? options.querySerializer
|
|
132
|
+
: (0, exports.createQuerySerializer)(options.querySerializer),
|
|
133
|
+
url: options.url,
|
|
134
|
+
});
|
|
189
135
|
exports.buildUrl = buildUrl;
|
|
190
|
-
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
|
|
191
|
-
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
192
|
-
let url = (baseUrl ?? '') + pathUrl;
|
|
193
|
-
if (path) {
|
|
194
|
-
url = defaultPathSerializer({ path, url });
|
|
195
|
-
}
|
|
196
|
-
let search = query ? querySerializer(query) : '';
|
|
197
|
-
if (search.startsWith('?')) {
|
|
198
|
-
search = search.substring(1);
|
|
199
|
-
}
|
|
200
|
-
if (search) {
|
|
201
|
-
url += `?${search}`;
|
|
202
|
-
}
|
|
203
|
-
return url;
|
|
204
|
-
};
|
|
205
|
-
exports.getUrl = getUrl;
|
|
206
136
|
const mergeConfigs = (a, b) => {
|
|
207
137
|
const config = { ...a, ...b };
|
|
208
138
|
if (config.baseUrl?.endsWith('/')) {
|
|
@@ -212,13 +142,20 @@ const mergeConfigs = (a, b) => {
|
|
|
212
142
|
return config;
|
|
213
143
|
};
|
|
214
144
|
exports.mergeConfigs = mergeConfigs;
|
|
145
|
+
const headersEntries = (headers) => {
|
|
146
|
+
const entries = [];
|
|
147
|
+
headers.forEach((value, key) => {
|
|
148
|
+
entries.push([key, value]);
|
|
149
|
+
});
|
|
150
|
+
return entries;
|
|
151
|
+
};
|
|
215
152
|
const mergeHeaders = (...headers) => {
|
|
216
153
|
const mergedHeaders = new Headers();
|
|
217
154
|
for (const header of headers) {
|
|
218
|
-
if (!header
|
|
155
|
+
if (!header) {
|
|
219
156
|
continue;
|
|
220
157
|
}
|
|
221
|
-
const iterator = header instanceof Headers ? header
|
|
158
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
222
159
|
for (const [key, value] of iterator) {
|
|
223
160
|
if (value === null) {
|
|
224
161
|
mergedHeaders.delete(key);
|
|
@@ -240,45 +177,40 @@ const mergeHeaders = (...headers) => {
|
|
|
240
177
|
exports.mergeHeaders = mergeHeaders;
|
|
241
178
|
class Interceptors {
|
|
242
179
|
constructor() {
|
|
243
|
-
this.
|
|
180
|
+
this.fns = [];
|
|
244
181
|
}
|
|
245
182
|
clear() {
|
|
246
|
-
this.
|
|
183
|
+
this.fns = [];
|
|
247
184
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
else {
|
|
253
|
-
return this._fns.indexOf(id);
|
|
185
|
+
eject(id) {
|
|
186
|
+
const index = this.getInterceptorIndex(id);
|
|
187
|
+
if (this.fns[index]) {
|
|
188
|
+
this.fns[index] = null;
|
|
254
189
|
}
|
|
255
190
|
}
|
|
256
191
|
exists(id) {
|
|
257
192
|
const index = this.getInterceptorIndex(id);
|
|
258
|
-
return
|
|
193
|
+
return Boolean(this.fns[index]);
|
|
259
194
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this._fns[index] = null;
|
|
195
|
+
getInterceptorIndex(id) {
|
|
196
|
+
if (typeof id === 'number') {
|
|
197
|
+
return this.fns[id] ? id : -1;
|
|
264
198
|
}
|
|
199
|
+
return this.fns.indexOf(id);
|
|
265
200
|
}
|
|
266
201
|
update(id, fn) {
|
|
267
202
|
const index = this.getInterceptorIndex(id);
|
|
268
|
-
if (this.
|
|
269
|
-
this.
|
|
203
|
+
if (this.fns[index]) {
|
|
204
|
+
this.fns[index] = fn;
|
|
270
205
|
return id;
|
|
271
206
|
}
|
|
272
|
-
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
207
|
+
return false;
|
|
275
208
|
}
|
|
276
209
|
use(fn) {
|
|
277
|
-
this.
|
|
278
|
-
return this.
|
|
210
|
+
this.fns.push(fn);
|
|
211
|
+
return this.fns.length - 1;
|
|
279
212
|
}
|
|
280
213
|
}
|
|
281
|
-
// do not add `Middleware` as return type so we can use _fns internally
|
|
282
214
|
const createInterceptors = () => ({
|
|
283
215
|
error: new Interceptors(),
|
|
284
216
|
request: new Interceptors(),
|
package/sdk/client/utils.gen.ts
CHANGED
|
@@ -1,103 +1,19 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
|
|
3
3
|
import { getAuthToken } from '../core/auth.gen';
|
|
4
|
-
import type {
|
|
5
|
-
QuerySerializer,
|
|
6
|
-
QuerySerializerOptions,
|
|
7
|
-
} from '../core/bodySerializer.gen';
|
|
4
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
8
5
|
import { jsonBodySerializer } from '../core/bodySerializer.gen';
|
|
9
6
|
import {
|
|
10
7
|
serializeArrayParam,
|
|
11
8
|
serializeObjectParam,
|
|
12
9
|
serializePrimitiveParam,
|
|
13
10
|
} from '../core/pathSerializer.gen';
|
|
11
|
+
import { getUrl } from '../core/utils.gen';
|
|
14
12
|
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
15
13
|
|
|
16
|
-
interface PathSerializer {
|
|
17
|
-
path: Record<string, unknown>;
|
|
18
|
-
url: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
22
|
-
|
|
23
|
-
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
24
|
-
type MatrixStyle = 'label' | 'matrix' | 'simple';
|
|
25
|
-
type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
|
|
26
|
-
|
|
27
|
-
const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
28
|
-
let url = _url;
|
|
29
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
30
|
-
if (matches) {
|
|
31
|
-
for (const match of matches) {
|
|
32
|
-
let explode = false;
|
|
33
|
-
let name = match.substring(1, match.length - 1);
|
|
34
|
-
let style: ArraySeparatorStyle = 'simple';
|
|
35
|
-
|
|
36
|
-
if (name.endsWith('*')) {
|
|
37
|
-
explode = true;
|
|
38
|
-
name = name.substring(0, name.length - 1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (name.startsWith('.')) {
|
|
42
|
-
name = name.substring(1);
|
|
43
|
-
style = 'label';
|
|
44
|
-
} else if (name.startsWith(';')) {
|
|
45
|
-
name = name.substring(1);
|
|
46
|
-
style = 'matrix';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const value = path[name];
|
|
50
|
-
|
|
51
|
-
if (value === undefined || value === null) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (Array.isArray(value)) {
|
|
56
|
-
url = url.replace(
|
|
57
|
-
match,
|
|
58
|
-
serializeArrayParam({ explode, name, style, value }),
|
|
59
|
-
);
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (typeof value === 'object') {
|
|
64
|
-
url = url.replace(
|
|
65
|
-
match,
|
|
66
|
-
serializeObjectParam({
|
|
67
|
-
explode,
|
|
68
|
-
name,
|
|
69
|
-
style,
|
|
70
|
-
value: value as Record<string, unknown>,
|
|
71
|
-
valueOnly: true,
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (style === 'matrix') {
|
|
78
|
-
url = url.replace(
|
|
79
|
-
match,
|
|
80
|
-
`;${serializePrimitiveParam({
|
|
81
|
-
name,
|
|
82
|
-
value: value as string,
|
|
83
|
-
})}`,
|
|
84
|
-
);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const replaceValue = encodeURIComponent(
|
|
89
|
-
style === 'label' ? `.${value as string}` : (value as string),
|
|
90
|
-
);
|
|
91
|
-
url = url.replace(match, replaceValue);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return url;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
14
|
export const createQuerySerializer = <T = unknown>({
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
object,
|
|
15
|
+
parameters = {},
|
|
16
|
+
...args
|
|
101
17
|
}: QuerySerializerOptions = {}) => {
|
|
102
18
|
const querySerializer = (queryParams: T) => {
|
|
103
19
|
const search: string[] = [];
|
|
@@ -109,29 +25,31 @@ export const createQuerySerializer = <T = unknown>({
|
|
|
109
25
|
continue;
|
|
110
26
|
}
|
|
111
27
|
|
|
28
|
+
const options = parameters[name] || args;
|
|
29
|
+
|
|
112
30
|
if (Array.isArray(value)) {
|
|
113
31
|
const serializedArray = serializeArrayParam({
|
|
114
|
-
allowReserved,
|
|
32
|
+
allowReserved: options.allowReserved,
|
|
115
33
|
explode: true,
|
|
116
34
|
name,
|
|
117
35
|
style: 'form',
|
|
118
36
|
value,
|
|
119
|
-
...array,
|
|
37
|
+
...options.array,
|
|
120
38
|
});
|
|
121
39
|
if (serializedArray) search.push(serializedArray);
|
|
122
40
|
} else if (typeof value === 'object') {
|
|
123
41
|
const serializedObject = serializeObjectParam({
|
|
124
|
-
allowReserved,
|
|
42
|
+
allowReserved: options.allowReserved,
|
|
125
43
|
explode: true,
|
|
126
44
|
name,
|
|
127
45
|
style: 'deepObject',
|
|
128
46
|
value: value as Record<string, unknown>,
|
|
129
|
-
...object,
|
|
47
|
+
...options.object,
|
|
130
48
|
});
|
|
131
49
|
if (serializedObject) search.push(serializedObject);
|
|
132
50
|
} else {
|
|
133
51
|
const serializedPrimitive = serializePrimitiveParam({
|
|
134
|
-
allowReserved,
|
|
52
|
+
allowReserved: options.allowReserved,
|
|
135
53
|
name,
|
|
136
54
|
value: value as string,
|
|
137
55
|
});
|
|
@@ -147,9 +65,7 @@ export const createQuerySerializer = <T = unknown>({
|
|
|
147
65
|
/**
|
|
148
66
|
* Infers parseAs value from provided Content-Type header.
|
|
149
67
|
*/
|
|
150
|
-
export const getParseAs = (
|
|
151
|
-
contentType: string | null,
|
|
152
|
-
): Exclude<Config['parseAs'], 'auto'> => {
|
|
68
|
+
export const getParseAs = (contentType: string | null): Exclude<Config['parseAs'], 'auto'> => {
|
|
153
69
|
if (!contentType) {
|
|
154
70
|
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
155
71
|
// which is effectively the same as the 'stream' option.
|
|
@@ -162,10 +78,7 @@ export const getParseAs = (
|
|
|
162
78
|
return;
|
|
163
79
|
}
|
|
164
80
|
|
|
165
|
-
if (
|
|
166
|
-
cleanContent.startsWith('application/json') ||
|
|
167
|
-
cleanContent.endsWith('+json')
|
|
168
|
-
) {
|
|
81
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
169
82
|
return 'json';
|
|
170
83
|
}
|
|
171
84
|
|
|
@@ -174,9 +87,7 @@ export const getParseAs = (
|
|
|
174
87
|
}
|
|
175
88
|
|
|
176
89
|
if (
|
|
177
|
-
['application/', 'audio/', 'image/', 'video/'].some((type) =>
|
|
178
|
-
cleanContent.startsWith(type),
|
|
179
|
-
)
|
|
90
|
+
['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
|
|
180
91
|
) {
|
|
181
92
|
return 'blob';
|
|
182
93
|
}
|
|
@@ -245,8 +156,8 @@ export const setAuthParams = async ({
|
|
|
245
156
|
}
|
|
246
157
|
};
|
|
247
158
|
|
|
248
|
-
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
249
|
-
|
|
159
|
+
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
160
|
+
getUrl({
|
|
250
161
|
baseUrl: options.baseUrl as string,
|
|
251
162
|
path: options.path,
|
|
252
163
|
query: options.query,
|
|
@@ -256,36 +167,6 @@ export const buildUrl: Client['buildUrl'] = (options) => {
|
|
|
256
167
|
: createQuerySerializer(options.querySerializer),
|
|
257
168
|
url: options.url,
|
|
258
169
|
});
|
|
259
|
-
return url;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
export const getUrl = ({
|
|
263
|
-
baseUrl,
|
|
264
|
-
path,
|
|
265
|
-
query,
|
|
266
|
-
querySerializer,
|
|
267
|
-
url: _url,
|
|
268
|
-
}: {
|
|
269
|
-
baseUrl?: string;
|
|
270
|
-
path?: Record<string, unknown>;
|
|
271
|
-
query?: Record<string, unknown>;
|
|
272
|
-
querySerializer: QuerySerializer;
|
|
273
|
-
url: string;
|
|
274
|
-
}) => {
|
|
275
|
-
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
276
|
-
let url = (baseUrl ?? '') + pathUrl;
|
|
277
|
-
if (path) {
|
|
278
|
-
url = defaultPathSerializer({ path, url });
|
|
279
|
-
}
|
|
280
|
-
let search = query ? querySerializer(query) : '';
|
|
281
|
-
if (search.startsWith('?')) {
|
|
282
|
-
search = search.substring(1);
|
|
283
|
-
}
|
|
284
|
-
if (search) {
|
|
285
|
-
url += `?${search}`;
|
|
286
|
-
}
|
|
287
|
-
return url;
|
|
288
|
-
};
|
|
289
170
|
|
|
290
171
|
export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
291
172
|
const config = { ...a, ...b };
|
|
@@ -296,17 +177,24 @@ export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
|
296
177
|
return config;
|
|
297
178
|
};
|
|
298
179
|
|
|
180
|
+
const headersEntries = (headers: Headers): Array<[string, string]> => {
|
|
181
|
+
const entries: Array<[string, string]> = [];
|
|
182
|
+
headers.forEach((value, key) => {
|
|
183
|
+
entries.push([key, value]);
|
|
184
|
+
});
|
|
185
|
+
return entries;
|
|
186
|
+
};
|
|
187
|
+
|
|
299
188
|
export const mergeHeaders = (
|
|
300
189
|
...headers: Array<Required<Config>['headers'] | undefined>
|
|
301
190
|
): Headers => {
|
|
302
191
|
const mergedHeaders = new Headers();
|
|
303
192
|
for (const header of headers) {
|
|
304
|
-
if (!header
|
|
193
|
+
if (!header) {
|
|
305
194
|
continue;
|
|
306
195
|
}
|
|
307
196
|
|
|
308
|
-
const iterator =
|
|
309
|
-
header instanceof Headers ? header.entries() : Object.entries(header);
|
|
197
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
310
198
|
|
|
311
199
|
for (const [key, value] of iterator) {
|
|
312
200
|
if (value === null) {
|
|
@@ -335,10 +223,7 @@ type ErrInterceptor<Err, Res, Req, Options> = (
|
|
|
335
223
|
options: Options,
|
|
336
224
|
) => Err | Promise<Err>;
|
|
337
225
|
|
|
338
|
-
type ReqInterceptor<Req, Options> = (
|
|
339
|
-
request: Req,
|
|
340
|
-
options: Options,
|
|
341
|
-
) => Req | Promise<Req>;
|
|
226
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
342
227
|
|
|
343
228
|
type ResInterceptor<Res, Req, Options> = (
|
|
344
229
|
response: Res,
|
|
@@ -347,67 +232,58 @@ type ResInterceptor<Res, Req, Options> = (
|
|
|
347
232
|
) => Res | Promise<Res>;
|
|
348
233
|
|
|
349
234
|
class Interceptors<Interceptor> {
|
|
350
|
-
|
|
235
|
+
fns: Array<Interceptor | null> = [];
|
|
351
236
|
|
|
352
|
-
|
|
353
|
-
this.
|
|
237
|
+
clear(): void {
|
|
238
|
+
this.fns = [];
|
|
354
239
|
}
|
|
355
240
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
getInterceptorIndex(id: number | Interceptor): number {
|
|
361
|
-
if (typeof id === 'number') {
|
|
362
|
-
return this._fns[id] ? id : -1;
|
|
363
|
-
} else {
|
|
364
|
-
return this._fns.indexOf(id);
|
|
241
|
+
eject(id: number | Interceptor): void {
|
|
242
|
+
const index = this.getInterceptorIndex(id);
|
|
243
|
+
if (this.fns[index]) {
|
|
244
|
+
this.fns[index] = null;
|
|
365
245
|
}
|
|
366
246
|
}
|
|
367
|
-
|
|
247
|
+
|
|
248
|
+
exists(id: number | Interceptor): boolean {
|
|
368
249
|
const index = this.getInterceptorIndex(id);
|
|
369
|
-
return
|
|
250
|
+
return Boolean(this.fns[index]);
|
|
370
251
|
}
|
|
371
252
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this._fns[index] = null;
|
|
253
|
+
getInterceptorIndex(id: number | Interceptor): number {
|
|
254
|
+
if (typeof id === 'number') {
|
|
255
|
+
return this.fns[id] ? id : -1;
|
|
376
256
|
}
|
|
257
|
+
return this.fns.indexOf(id);
|
|
377
258
|
}
|
|
378
259
|
|
|
379
|
-
update(id: number | Interceptor, fn: Interceptor) {
|
|
260
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
|
|
380
261
|
const index = this.getInterceptorIndex(id);
|
|
381
|
-
if (this.
|
|
382
|
-
this.
|
|
262
|
+
if (this.fns[index]) {
|
|
263
|
+
this.fns[index] = fn;
|
|
383
264
|
return id;
|
|
384
|
-
} else {
|
|
385
|
-
return false;
|
|
386
265
|
}
|
|
266
|
+
return false;
|
|
387
267
|
}
|
|
388
268
|
|
|
389
|
-
use(fn: Interceptor) {
|
|
390
|
-
this.
|
|
391
|
-
return this.
|
|
269
|
+
use(fn: Interceptor): number {
|
|
270
|
+
this.fns.push(fn);
|
|
271
|
+
return this.fns.length - 1;
|
|
392
272
|
}
|
|
393
273
|
}
|
|
394
274
|
|
|
395
|
-
// `createInterceptors()` response, meant for external use as it does not
|
|
396
|
-
// expose internals
|
|
397
275
|
export interface Middleware<Req, Res, Err, Options> {
|
|
398
|
-
error:
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
>;
|
|
402
|
-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
|
|
403
|
-
response: Pick<
|
|
404
|
-
Interceptors<ResInterceptor<Res, Req, Options>>,
|
|
405
|
-
'eject' | 'use'
|
|
406
|
-
>;
|
|
276
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
277
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
278
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
407
279
|
}
|
|
408
280
|
|
|
409
|
-
|
|
410
|
-
|
|
281
|
+
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
|
282
|
+
Req,
|
|
283
|
+
Res,
|
|
284
|
+
Err,
|
|
285
|
+
Options
|
|
286
|
+
> => ({
|
|
411
287
|
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
|
412
288
|
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
|
413
289
|
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
package/sdk/client.gen.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import { type ClientOptions, type Config } from './client';
|
|
2
|
+
import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
3
3
|
/**
|
|
4
4
|
* The `createClientConfig()` function will be called on client initialization
|
|
5
5
|
* and the returned object will become the client's initial configuration.
|
|
@@ -8,5 +8,5 @@ import { type Config, type ClientOptions as DefaultClientOptions } from './clien
|
|
|
8
8
|
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
9
|
* to ensure your client always has the correct values.
|
|
10
10
|
*/
|
|
11
|
-
export type CreateClientConfig<T extends
|
|
11
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
12
|
export declare const client: import("./client").Client;
|
package/sdk/client.gen.js
CHANGED
|
@@ -3,6 +3,4 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.client = void 0;
|
|
5
5
|
const client_1 = require("./client");
|
|
6
|
-
exports.client = (0, client_1.createClient)((0, client_1.createConfig)({
|
|
7
|
-
baseUrl: 'http://localhost:8000'
|
|
8
|
-
}));
|
|
6
|
+
exports.client = (0, client_1.createClient)((0, client_1.createConfig)({ baseUrl: 'http://localhost:8000' }));
|
package/sdk/client.gen.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
3
|
+
import { type ClientOptions, type Config, createClient, createConfig } from './client';
|
|
4
|
+
import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The `createClientConfig()` function will be called on client initialization
|
|
@@ -11,8 +11,6 @@ import { type Config, type ClientOptions as DefaultClientOptions, createClient,
|
|
|
11
11
|
* `setConfig()`. This is useful for example if you're using Next.js
|
|
12
12
|
* to ensure your client always has the correct values.
|
|
13
13
|
*/
|
|
14
|
-
export type CreateClientConfig<T extends
|
|
14
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
15
15
|
|
|
16
|
-
export const client = createClient(createConfig<
|
|
17
|
-
baseUrl: 'http://localhost:8000'
|
|
18
|
-
}));
|
|
16
|
+
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: 'http://localhost:8000' }));
|
package/sdk/core/auth.gen.ts
CHANGED
|
@@ -23,8 +23,7 @@ export const getAuthToken = async (
|
|
|
23
23
|
auth: Auth,
|
|
24
24
|
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
|
25
25
|
): Promise<string | undefined> => {
|
|
26
|
-
const token =
|
|
27
|
-
typeof callback === 'function' ? await callback(auth) : callback;
|
|
26
|
+
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
28
27
|
|
|
29
28
|
if (!token) {
|
|
30
29
|
return;
|