@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/README.md
CHANGED
|
@@ -21,18 +21,19 @@ Official TypeScript Client for the RoboSystems Financial Knowledge Graph API. Ac
|
|
|
21
21
|
npm install @robosystems/client
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Resources
|
|
25
25
|
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
26
|
+
- [RoboSystems Platform](https://robosystems.ai)
|
|
27
|
+
- [GitHub Repository](https://github.com/RoboFinSystems/robosystems)
|
|
28
|
+
- [API Documentation](https://api.robosystems.ai/docs)
|
|
29
|
+
- [OpenAPI Specification](https://api.robosystems.ai/openapi.json)
|
|
29
30
|
|
|
30
31
|
## Support
|
|
31
32
|
|
|
32
33
|
- [Issues](https://github.com/RoboFinSystems/robosystems-typescript-client/issues)
|
|
33
|
-
- [Discussions](https://github.com/RoboFinSystems/robosystems/discussions)
|
|
34
|
-
- [Projects](https://github.com/RoboFinSystems/robosystems/projects)
|
|
35
34
|
- [Wiki](https://github.com/RoboFinSystems/robosystems/wiki)
|
|
35
|
+
- [Projects](https://github.com/orgs/RoboFinSystems/projects)
|
|
36
|
+
- [Discussions](https://github.com/orgs/RoboFinSystems/discussions)
|
|
36
37
|
|
|
37
38
|
## License
|
|
38
39
|
|
|
@@ -3,12 +3,13 @@ set -e
|
|
|
3
3
|
|
|
4
4
|
# Create feature branch script - local Git operations
|
|
5
5
|
# Creates a new feature/bugfix/hotfix branch locally and pushes to remote
|
|
6
|
-
# Usage: ./bin/create-feature [feature|bugfix|hotfix|chore|refactor] [branch-name] [base-branch]
|
|
6
|
+
# Usage: ./bin/create-feature.sh [feature|bugfix|hotfix|chore|refactor] [branch-name] [base-branch] [update-deps]
|
|
7
7
|
|
|
8
8
|
# Default values
|
|
9
9
|
BRANCH_TYPE=${1:-feature}
|
|
10
10
|
BRANCH_NAME=${2:-}
|
|
11
11
|
BASE_BRANCH=${3:-main}
|
|
12
|
+
UPDATE_DEPS=${4:-yes}
|
|
12
13
|
|
|
13
14
|
# Validate branch type
|
|
14
15
|
if [[ "$BRANCH_TYPE" != "feature" && "$BRANCH_TYPE" != "bugfix" && "$BRANCH_TYPE" != "hotfix" && "$BRANCH_TYPE" != "chore" && "$BRANCH_TYPE" != "refactor" ]]; then
|
|
@@ -78,6 +79,15 @@ git push -u origin $FULL_BRANCH
|
|
|
78
79
|
|
|
79
80
|
echo ""
|
|
80
81
|
echo "🎉 Successfully created and checked out $FULL_BRANCH"
|
|
82
|
+
|
|
83
|
+
# Update dependencies if requested (default: yes)
|
|
84
|
+
if [[ "$UPDATE_DEPS" == "yes" ]]; then
|
|
85
|
+
echo ""
|
|
86
|
+
echo "📦 Updating dependencies..."
|
|
87
|
+
npm update
|
|
88
|
+
echo "✅ Dependencies updated"
|
|
89
|
+
fi
|
|
90
|
+
|
|
81
91
|
echo ""
|
|
82
92
|
echo "📝 Next steps:"
|
|
83
93
|
echo " 1. Make your changes and commit them"
|
package/client/client.gen.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
-
/* eslint-disable no-undef */
|
|
4
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
4
|
exports.createClient = void 0;
|
|
6
|
-
const
|
|
5
|
+
const serverSentEvents_gen_1 = require("../core/serverSentEvents.gen");
|
|
6
|
+
const utils_gen_1 = require("../core/utils.gen");
|
|
7
|
+
const utils_gen_2 = require("./utils.gen");
|
|
7
8
|
const createClient = (config = {}) => {
|
|
8
|
-
let _config = (0,
|
|
9
|
+
let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
|
|
9
10
|
const getConfig = () => ({ ..._config });
|
|
10
11
|
const setConfig = (config) => {
|
|
11
|
-
_config = (0,
|
|
12
|
+
_config = (0, utils_gen_2.mergeConfigs)(_config, config);
|
|
12
13
|
return getConfig();
|
|
13
14
|
};
|
|
14
|
-
const interceptors = (0,
|
|
15
|
-
const
|
|
15
|
+
const interceptors = (0, utils_gen_2.createInterceptors)();
|
|
16
|
+
const beforeRequest = async (options) => {
|
|
16
17
|
const opts = {
|
|
17
18
|
..._config,
|
|
18
19
|
...options,
|
|
19
20
|
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
20
|
-
headers: (0,
|
|
21
|
+
headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
|
|
21
22
|
serializedBody: undefined,
|
|
22
23
|
};
|
|
23
24
|
if (opts.security) {
|
|
24
|
-
await (0,
|
|
25
|
+
await (0, utils_gen_2.setAuthParams)({
|
|
25
26
|
...opts,
|
|
26
27
|
security: opts.security,
|
|
27
28
|
});
|
|
@@ -29,21 +30,25 @@ const createClient = (config = {}) => {
|
|
|
29
30
|
if (opts.requestValidator) {
|
|
30
31
|
await opts.requestValidator(opts);
|
|
31
32
|
}
|
|
32
|
-
if (opts.body && opts.bodySerializer) {
|
|
33
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
33
34
|
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
34
35
|
}
|
|
35
36
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
36
|
-
if (opts.
|
|
37
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
37
38
|
opts.headers.delete('Content-Type');
|
|
38
39
|
}
|
|
39
|
-
const url = (0,
|
|
40
|
+
const url = (0, utils_gen_2.buildUrl)(opts);
|
|
41
|
+
return { opts, url };
|
|
42
|
+
};
|
|
43
|
+
const request = async (options) => {
|
|
44
|
+
const { opts, url } = await beforeRequest(options);
|
|
40
45
|
const requestInit = {
|
|
41
46
|
redirect: 'follow',
|
|
42
47
|
...opts,
|
|
43
|
-
body: opts
|
|
48
|
+
body: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
44
49
|
};
|
|
45
50
|
let request = new Request(url, requestInit);
|
|
46
|
-
for (const fn of interceptors.request.
|
|
51
|
+
for (const fn of interceptors.request.fns) {
|
|
47
52
|
if (fn) {
|
|
48
53
|
request = await fn(request, opts);
|
|
49
54
|
}
|
|
@@ -51,8 +56,32 @@ const createClient = (config = {}) => {
|
|
|
51
56
|
// fetch must be assigned here, otherwise it would throw the error:
|
|
52
57
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
53
58
|
const _fetch = opts.fetch;
|
|
54
|
-
let response
|
|
55
|
-
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await _fetch(request);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
65
|
+
let finalError = error;
|
|
66
|
+
for (const fn of interceptors.error.fns) {
|
|
67
|
+
if (fn) {
|
|
68
|
+
finalError = (await fn(error, undefined, request, opts));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
finalError = finalError || {};
|
|
72
|
+
if (opts.throwOnError) {
|
|
73
|
+
throw finalError;
|
|
74
|
+
}
|
|
75
|
+
// Return error response
|
|
76
|
+
return opts.responseStyle === 'data'
|
|
77
|
+
? undefined
|
|
78
|
+
: {
|
|
79
|
+
error: finalError,
|
|
80
|
+
request,
|
|
81
|
+
response: undefined,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
for (const fn of interceptors.response.fns) {
|
|
56
85
|
if (fn) {
|
|
57
86
|
response = await fn(response, request, opts);
|
|
58
87
|
}
|
|
@@ -62,27 +91,50 @@ const createClient = (config = {}) => {
|
|
|
62
91
|
response,
|
|
63
92
|
};
|
|
64
93
|
if (response.ok) {
|
|
65
|
-
|
|
66
|
-
response.headers.get('Content-
|
|
94
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
95
|
+
? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
|
|
96
|
+
: opts.parseAs) ?? 'json';
|
|
97
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
98
|
+
let emptyData;
|
|
99
|
+
switch (parseAs) {
|
|
100
|
+
case 'arrayBuffer':
|
|
101
|
+
case 'blob':
|
|
102
|
+
case 'text':
|
|
103
|
+
emptyData = await response[parseAs]();
|
|
104
|
+
break;
|
|
105
|
+
case 'formData':
|
|
106
|
+
emptyData = new FormData();
|
|
107
|
+
break;
|
|
108
|
+
case 'stream':
|
|
109
|
+
emptyData = response.body;
|
|
110
|
+
break;
|
|
111
|
+
case 'json':
|
|
112
|
+
default:
|
|
113
|
+
emptyData = {};
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
67
116
|
return opts.responseStyle === 'data'
|
|
68
|
-
?
|
|
117
|
+
? emptyData
|
|
69
118
|
: {
|
|
70
|
-
data:
|
|
119
|
+
data: emptyData,
|
|
71
120
|
...result,
|
|
72
121
|
};
|
|
73
122
|
}
|
|
74
|
-
const parseAs = (opts.parseAs === 'auto'
|
|
75
|
-
? (0, utils_gen_1.getParseAs)(response.headers.get('Content-Type'))
|
|
76
|
-
: opts.parseAs) ?? 'json';
|
|
77
123
|
let data;
|
|
78
124
|
switch (parseAs) {
|
|
79
125
|
case 'arrayBuffer':
|
|
80
126
|
case 'blob':
|
|
81
127
|
case 'formData':
|
|
82
|
-
case 'json':
|
|
83
128
|
case 'text':
|
|
84
129
|
data = await response[parseAs]();
|
|
85
130
|
break;
|
|
131
|
+
case 'json': {
|
|
132
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
133
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
134
|
+
const text = await response.text();
|
|
135
|
+
data = text ? JSON.parse(text) : {};
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
86
138
|
case 'stream':
|
|
87
139
|
return opts.responseStyle === 'data'
|
|
88
140
|
? response.body
|
|
@@ -116,7 +168,7 @@ const createClient = (config = {}) => {
|
|
|
116
168
|
}
|
|
117
169
|
const error = jsonError ?? textError;
|
|
118
170
|
let finalError = error;
|
|
119
|
-
for (const fn of interceptors.error.
|
|
171
|
+
for (const fn of interceptors.error.fns) {
|
|
120
172
|
if (fn) {
|
|
121
173
|
finalError = (await fn(error, response, request, opts));
|
|
122
174
|
}
|
|
@@ -133,21 +185,53 @@ const createClient = (config = {}) => {
|
|
|
133
185
|
...result,
|
|
134
186
|
};
|
|
135
187
|
};
|
|
188
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
189
|
+
const makeSseFn = (method) => async (options) => {
|
|
190
|
+
const { opts, url } = await beforeRequest(options);
|
|
191
|
+
return (0, serverSentEvents_gen_1.createSseClient)({
|
|
192
|
+
...opts,
|
|
193
|
+
body: opts.body,
|
|
194
|
+
headers: opts.headers,
|
|
195
|
+
method,
|
|
196
|
+
onRequest: async (url, init) => {
|
|
197
|
+
let request = new Request(url, init);
|
|
198
|
+
for (const fn of interceptors.request.fns) {
|
|
199
|
+
if (fn) {
|
|
200
|
+
request = await fn(request, opts);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return request;
|
|
204
|
+
},
|
|
205
|
+
serializedBody: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
206
|
+
url,
|
|
207
|
+
});
|
|
208
|
+
};
|
|
136
209
|
return {
|
|
137
|
-
buildUrl:
|
|
138
|
-
connect: (
|
|
139
|
-
delete: (
|
|
140
|
-
get: (
|
|
210
|
+
buildUrl: utils_gen_2.buildUrl,
|
|
211
|
+
connect: makeMethodFn('CONNECT'),
|
|
212
|
+
delete: makeMethodFn('DELETE'),
|
|
213
|
+
get: makeMethodFn('GET'),
|
|
141
214
|
getConfig,
|
|
142
|
-
head: (
|
|
215
|
+
head: makeMethodFn('HEAD'),
|
|
143
216
|
interceptors,
|
|
144
|
-
options: (
|
|
145
|
-
patch: (
|
|
146
|
-
post: (
|
|
147
|
-
put: (
|
|
217
|
+
options: makeMethodFn('OPTIONS'),
|
|
218
|
+
patch: makeMethodFn('PATCH'),
|
|
219
|
+
post: makeMethodFn('POST'),
|
|
220
|
+
put: makeMethodFn('PUT'),
|
|
148
221
|
request,
|
|
149
222
|
setConfig,
|
|
150
|
-
|
|
223
|
+
sse: {
|
|
224
|
+
connect: makeSseFn('CONNECT'),
|
|
225
|
+
delete: makeSseFn('DELETE'),
|
|
226
|
+
get: makeSseFn('GET'),
|
|
227
|
+
head: makeSseFn('HEAD'),
|
|
228
|
+
options: makeSseFn('OPTIONS'),
|
|
229
|
+
patch: makeSseFn('PATCH'),
|
|
230
|
+
post: makeSseFn('POST'),
|
|
231
|
+
put: makeSseFn('PUT'),
|
|
232
|
+
trace: makeSseFn('TRACE'),
|
|
233
|
+
},
|
|
234
|
+
trace: makeMethodFn('TRACE'),
|
|
151
235
|
};
|
|
152
236
|
};
|
|
153
237
|
exports.createClient = createClient;
|
package/client/client.gen.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
2
|
|
|
4
|
-
import
|
|
3
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
4
|
+
import type { HttpMethod } from '../core/types.gen';
|
|
5
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
6
|
+
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
|
|
5
7
|
import {
|
|
6
8
|
buildUrl,
|
|
7
9
|
createConfig,
|
|
@@ -27,14 +29,9 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
27
29
|
return getConfig();
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
const interceptors = createInterceptors<
|
|
31
|
-
Request,
|
|
32
|
-
Response,
|
|
33
|
-
unknown,
|
|
34
|
-
ResolvedRequestOptions
|
|
35
|
-
>();
|
|
32
|
+
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
|
|
36
33
|
|
|
37
|
-
const
|
|
34
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
38
35
|
const opts = {
|
|
39
36
|
..._config,
|
|
40
37
|
...options,
|
|
@@ -54,25 +51,31 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
54
51
|
await opts.requestValidator(opts);
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
if (opts.body && opts.bodySerializer) {
|
|
54
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
58
55
|
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
62
|
-
if (opts.
|
|
59
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
63
60
|
opts.headers.delete('Content-Type');
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
const url = buildUrl(opts);
|
|
64
|
+
|
|
65
|
+
return { opts, url };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const request: Client['request'] = async (options) => {
|
|
69
|
+
const { opts, url } = await beforeRequest(options);
|
|
67
70
|
const requestInit: ReqInit = {
|
|
68
71
|
redirect: 'follow',
|
|
69
72
|
...opts,
|
|
70
|
-
body: opts
|
|
73
|
+
body: getValidRequestBody(opts),
|
|
71
74
|
};
|
|
72
75
|
|
|
73
76
|
let request = new Request(url, requestInit);
|
|
74
77
|
|
|
75
|
-
for (const fn of interceptors.request.
|
|
78
|
+
for (const fn of interceptors.request.fns) {
|
|
76
79
|
if (fn) {
|
|
77
80
|
request = await fn(request, opts);
|
|
78
81
|
}
|
|
@@ -81,9 +84,37 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
81
84
|
// fetch must be assigned here, otherwise it would throw the error:
|
|
82
85
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
83
86
|
const _fetch = opts.fetch!;
|
|
84
|
-
let response
|
|
87
|
+
let response: Response;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
response = await _fetch(request);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
93
|
+
let finalError = error;
|
|
94
|
+
|
|
95
|
+
for (const fn of interceptors.error.fns) {
|
|
96
|
+
if (fn) {
|
|
97
|
+
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
85
100
|
|
|
86
|
-
|
|
101
|
+
finalError = finalError || ({} as unknown);
|
|
102
|
+
|
|
103
|
+
if (opts.throwOnError) {
|
|
104
|
+
throw finalError;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Return error response
|
|
108
|
+
return opts.responseStyle === 'data'
|
|
109
|
+
? undefined
|
|
110
|
+
: {
|
|
111
|
+
error: finalError,
|
|
112
|
+
request,
|
|
113
|
+
response: undefined as any,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const fn of interceptors.response.fns) {
|
|
87
118
|
if (fn) {
|
|
88
119
|
response = await fn(response, request, opts);
|
|
89
120
|
}
|
|
@@ -95,32 +126,53 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
95
126
|
};
|
|
96
127
|
|
|
97
128
|
if (response.ok) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
129
|
+
const parseAs =
|
|
130
|
+
(opts.parseAs === 'auto'
|
|
131
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
132
|
+
: opts.parseAs) ?? 'json';
|
|
133
|
+
|
|
134
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
135
|
+
let emptyData: any;
|
|
136
|
+
switch (parseAs) {
|
|
137
|
+
case 'arrayBuffer':
|
|
138
|
+
case 'blob':
|
|
139
|
+
case 'text':
|
|
140
|
+
emptyData = await response[parseAs]();
|
|
141
|
+
break;
|
|
142
|
+
case 'formData':
|
|
143
|
+
emptyData = new FormData();
|
|
144
|
+
break;
|
|
145
|
+
case 'stream':
|
|
146
|
+
emptyData = response.body;
|
|
147
|
+
break;
|
|
148
|
+
case 'json':
|
|
149
|
+
default:
|
|
150
|
+
emptyData = {};
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
102
153
|
return opts.responseStyle === 'data'
|
|
103
|
-
?
|
|
154
|
+
? emptyData
|
|
104
155
|
: {
|
|
105
|
-
data:
|
|
156
|
+
data: emptyData,
|
|
106
157
|
...result,
|
|
107
158
|
};
|
|
108
159
|
}
|
|
109
160
|
|
|
110
|
-
const parseAs =
|
|
111
|
-
(opts.parseAs === 'auto'
|
|
112
|
-
? getParseAs(response.headers.get('Content-Type'))
|
|
113
|
-
: opts.parseAs) ?? 'json';
|
|
114
|
-
|
|
115
161
|
let data: any;
|
|
116
162
|
switch (parseAs) {
|
|
117
163
|
case 'arrayBuffer':
|
|
118
164
|
case 'blob':
|
|
119
165
|
case 'formData':
|
|
120
|
-
case 'json':
|
|
121
166
|
case 'text':
|
|
122
167
|
data = await response[parseAs]();
|
|
123
168
|
break;
|
|
169
|
+
case 'json': {
|
|
170
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
171
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
172
|
+
const text = await response.text();
|
|
173
|
+
data = text ? JSON.parse(text) : {};
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
124
176
|
case 'stream':
|
|
125
177
|
return opts.responseStyle === 'data'
|
|
126
178
|
? response.body
|
|
@@ -160,7 +212,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
160
212
|
const error = jsonError ?? textError;
|
|
161
213
|
let finalError = error;
|
|
162
214
|
|
|
163
|
-
for (const fn of interceptors.error.
|
|
215
|
+
for (const fn of interceptors.error.fns) {
|
|
164
216
|
if (fn) {
|
|
165
217
|
finalError = (await fn(error, response, request, opts)) as string;
|
|
166
218
|
}
|
|
@@ -181,20 +233,55 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
181
233
|
};
|
|
182
234
|
};
|
|
183
235
|
|
|
236
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
237
|
+
request({ ...options, method });
|
|
238
|
+
|
|
239
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
240
|
+
const { opts, url } = await beforeRequest(options);
|
|
241
|
+
return createSseClient({
|
|
242
|
+
...opts,
|
|
243
|
+
body: opts.body as BodyInit | null | undefined,
|
|
244
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
245
|
+
method,
|
|
246
|
+
onRequest: async (url, init) => {
|
|
247
|
+
let request = new Request(url, init);
|
|
248
|
+
for (const fn of interceptors.request.fns) {
|
|
249
|
+
if (fn) {
|
|
250
|
+
request = await fn(request, opts);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return request;
|
|
254
|
+
},
|
|
255
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
256
|
+
url,
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
184
260
|
return {
|
|
185
261
|
buildUrl,
|
|
186
|
-
connect: (
|
|
187
|
-
delete: (
|
|
188
|
-
get: (
|
|
262
|
+
connect: makeMethodFn('CONNECT'),
|
|
263
|
+
delete: makeMethodFn('DELETE'),
|
|
264
|
+
get: makeMethodFn('GET'),
|
|
189
265
|
getConfig,
|
|
190
|
-
head: (
|
|
266
|
+
head: makeMethodFn('HEAD'),
|
|
191
267
|
interceptors,
|
|
192
|
-
options: (
|
|
193
|
-
patch: (
|
|
194
|
-
post: (
|
|
195
|
-
put: (
|
|
268
|
+
options: makeMethodFn('OPTIONS'),
|
|
269
|
+
patch: makeMethodFn('PATCH'),
|
|
270
|
+
post: makeMethodFn('POST'),
|
|
271
|
+
put: makeMethodFn('PUT'),
|
|
196
272
|
request,
|
|
197
273
|
setConfig,
|
|
198
|
-
|
|
199
|
-
|
|
274
|
+
sse: {
|
|
275
|
+
connect: makeSseFn('CONNECT'),
|
|
276
|
+
delete: makeSseFn('DELETE'),
|
|
277
|
+
get: makeSseFn('GET'),
|
|
278
|
+
head: makeSseFn('HEAD'),
|
|
279
|
+
options: makeSseFn('OPTIONS'),
|
|
280
|
+
patch: makeSseFn('PATCH'),
|
|
281
|
+
post: makeSseFn('POST'),
|
|
282
|
+
put: makeSseFn('PUT'),
|
|
283
|
+
trace: makeSseFn('TRACE'),
|
|
284
|
+
},
|
|
285
|
+
trace: makeMethodFn('TRACE'),
|
|
286
|
+
} as Client;
|
|
200
287
|
};
|
package/client/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type { Auth } from '../core/auth.gen';
|
|
|
2
2
|
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
3
|
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
4
|
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
5
6
|
export { createClient } from './client.gen';
|
|
6
|
-
export type { Client, ClientOptions, Config, CreateClientConfig, Options,
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
7
8
|
export { createConfig, mergeHeaders } from './utils.gen';
|
package/client/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
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.mergeHeaders = exports.createConfig = exports.createClient = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
|
|
4
|
+
exports.mergeHeaders = exports.createConfig = exports.createClient = exports.serializeQueryKeyValue = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
|
|
5
5
|
var bodySerializer_gen_1 = require("../core/bodySerializer.gen");
|
|
6
6
|
Object.defineProperty(exports, "formDataBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.formDataBodySerializer; } });
|
|
7
7
|
Object.defineProperty(exports, "jsonBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.jsonBodySerializer; } });
|
|
8
8
|
Object.defineProperty(exports, "urlSearchParamsBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.urlSearchParamsBodySerializer; } });
|
|
9
9
|
var params_gen_1 = require("../core/params.gen");
|
|
10
10
|
Object.defineProperty(exports, "buildClientParams", { enumerable: true, get: function () { return params_gen_1.buildClientParams; } });
|
|
11
|
+
var queryKeySerializer_gen_1 = require("../core/queryKeySerializer.gen");
|
|
12
|
+
Object.defineProperty(exports, "serializeQueryKeyValue", { enumerable: true, get: function () { return queryKeySerializer_gen_1.serializeQueryKeyValue; } });
|
|
11
13
|
var client_gen_1 = require("./client.gen");
|
|
12
14
|
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_gen_1.createClient; } });
|
|
13
15
|
var utils_gen_1 = require("./utils.gen");
|
package/client/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export {
|
|
|
8
8
|
urlSearchParamsBodySerializer,
|
|
9
9
|
} from '../core/bodySerializer.gen';
|
|
10
10
|
export { buildClientParams } from '../core/params.gen';
|
|
11
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
11
12
|
export { createClient } from './client.gen';
|
|
12
13
|
export type {
|
|
13
14
|
Client,
|
|
@@ -15,7 +16,6 @@ export type {
|
|
|
15
16
|
Config,
|
|
16
17
|
CreateClientConfig,
|
|
17
18
|
Options,
|
|
18
|
-
OptionsLegacyParser,
|
|
19
19
|
RequestOptions,
|
|
20
20
|
RequestResult,
|
|
21
21
|
ResolvedRequestOptions,
|
package/client/types.gen.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
2
3
|
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
3
4
|
import type { Middleware } from './utils.gen';
|
|
4
5
|
export type ResponseStyle = 'data' | 'fields';
|
|
@@ -13,7 +14,7 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
13
14
|
*
|
|
14
15
|
* @default globalThis.fetch
|
|
15
16
|
*/
|
|
16
|
-
fetch?:
|
|
17
|
+
fetch?: typeof fetch;
|
|
17
18
|
/**
|
|
18
19
|
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
19
20
|
* options won't have any effect.
|
|
@@ -43,10 +44,10 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
43
44
|
*/
|
|
44
45
|
throwOnError?: T['throwOnError'];
|
|
45
46
|
}
|
|
46
|
-
export interface RequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
47
48
|
responseStyle: TResponseStyle;
|
|
48
49
|
throwOnError: ThrowOnError;
|
|
49
|
-
}> {
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
50
51
|
/**
|
|
51
52
|
* Any body that you want to add to your request.
|
|
52
53
|
*
|
|
@@ -61,7 +62,7 @@ export interface RequestOptions<TResponseStyle extends ResponseStyle = 'fields',
|
|
|
61
62
|
security?: ReadonlyArray<Auth>;
|
|
62
63
|
url: Url;
|
|
63
64
|
}
|
|
64
|
-
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<TResponseStyle, ThrowOnError, Url> {
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
65
66
|
serializedBody?: string;
|
|
66
67
|
}
|
|
67
68
|
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
@@ -83,15 +84,16 @@ export interface ClientOptions {
|
|
|
83
84
|
responseStyle?: ResponseStyle;
|
|
84
85
|
throwOnError?: boolean;
|
|
85
86
|
}
|
|
86
|
-
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
87
|
-
type
|
|
87
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
89
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
90
|
type BuildUrlFn = <TData extends {
|
|
89
91
|
body?: unknown;
|
|
90
92
|
path?: Record<string, unknown>;
|
|
91
93
|
query?: Record<string, unknown>;
|
|
92
94
|
url: string;
|
|
93
|
-
}>(options:
|
|
94
|
-
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
|
|
95
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
95
97
|
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
96
98
|
};
|
|
97
99
|
/**
|
|
@@ -111,12 +113,5 @@ export interface TDataShape {
|
|
|
111
113
|
url: string;
|
|
112
114
|
}
|
|
113
115
|
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
114
|
-
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & Omit<TData, 'url'
|
|
115
|
-
export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = TData extends {
|
|
116
|
-
body?: any;
|
|
117
|
-
} ? TData extends {
|
|
118
|
-
headers?: any;
|
|
119
|
-
} ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'headers' | 'url'> & TData : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'url'> & TData & Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'headers'> : TData extends {
|
|
120
|
-
headers?: any;
|
|
121
|
-
} ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'headers' | 'url'> & TData & Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'body'> : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'url'> & TData;
|
|
116
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
122
117
|
export {};
|
package/client/types.gen.js
CHANGED