@pg-atlas/data-sdk 0.4.0
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/generated/client/client.gen.d.ts +2 -0
- package/dist/generated/client/client.gen.js +235 -0
- package/dist/generated/client/index.d.ts +8 -0
- package/dist/generated/client/index.js +6 -0
- package/dist/generated/client/types.gen.d.ts +117 -0
- package/dist/generated/client/types.gen.js +2 -0
- package/dist/generated/client/utils.gen.d.ts +33 -0
- package/dist/generated/client/utils.gen.js +228 -0
- package/dist/generated/client.gen.d.ts +12 -0
- package/dist/generated/client.gen.js +3 -0
- package/dist/generated/core/auth.gen.d.ts +18 -0
- package/dist/generated/core/auth.gen.js +14 -0
- package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
- package/dist/generated/core/bodySerializer.gen.js +57 -0
- package/dist/generated/core/params.gen.d.ts +43 -0
- package/dist/generated/core/params.gen.js +100 -0
- package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
- package/dist/generated/core/pathSerializer.gen.js +106 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/generated/core/queryKeySerializer.gen.js +92 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/generated/core/serverSentEvents.gen.js +133 -0
- package/dist/generated/core/types.gen.d.ts +78 -0
- package/dist/generated/core/types.gen.js +2 -0
- package/dist/generated/core/utils.gen.d.ts +19 -0
- package/dist/generated/core/utils.gen.js +87 -0
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/schemas.gen.d.ts +1015 -0
- package/dist/generated/schemas.gen.js +1338 -0
- package/dist/generated/sdk.gen.d.ts +146 -0
- package/dist/generated/sdk.gen.js +133 -0
- package/dist/generated/types.gen.d.ts +1172 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PG Atlas Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# PG Atlas TS SDK
|
|
2
|
+
|
|
3
|
+
The PG Atlas TypeScript SDK is generated from the PG Atlas OpenAPI specification.
|
|
4
|
+
|
|
5
|
+
All operation functions are generated by `@hey-api/openapi-ts` and re-exported from the package entrypoint.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Generated operation functions from the current OpenAPI contract
|
|
10
|
+
- Generated request/response types and JSON schemas
|
|
11
|
+
- Generated client helpers for runtime configuration (`client`, `createClient`, `createConfig`)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm add @pg-atlas/data-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Example Usage
|
|
20
|
+
|
|
21
|
+
Operation names are generated from `operationId` values in the API specification.
|
|
22
|
+
Use your editor autocomplete on `@pg-atlas/data-sdk` exports to discover the current operation names.
|
|
23
|
+
|
|
24
|
+
### Basic call
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { client, getHealth } from "@pg-atlas/data-sdk";
|
|
28
|
+
|
|
29
|
+
const { data } = await getHealth({ client });
|
|
30
|
+
console.log(data?.status);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Configure authentication (for ingest endpoints)
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { client, ingestSbom } from "@pg-atlas/data-sdk";
|
|
37
|
+
|
|
38
|
+
client.setConfig({
|
|
39
|
+
headers: {
|
|
40
|
+
Authorization: "Bearer your-github-oidc-token",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const { data } = await ingestSbom({
|
|
45
|
+
client,
|
|
46
|
+
body: mySbom,
|
|
47
|
+
});
|
|
48
|
+
console.log(data?.repository);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
Configure the shared generated client using `client.setConfig(...)`, or create per-call clients using `createClient(...)`.
|
|
54
|
+
|
|
55
|
+
| Attribute | Default | Description |
|
|
56
|
+
| ---------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
57
|
+
| `baseUrl` | `https://pg-atlas-backend-h8gen.ondigitalocean.app` | The root URL of the PG Atlas API. |
|
|
58
|
+
| `Authorization` header | `unset` | Bearer token used for authenticated requests (for example GitHub OIDC JWT on ingest endpoints). |
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
Copyright 2026 PG Atlas Contributors
|
|
63
|
+
|
|
64
|
+
[MIT License](https://opensource.org/license/mit)
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
3
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
4
|
+
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils.gen';
|
|
5
|
+
export const createClient = (config = {}) => {
|
|
6
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
7
|
+
const getConfig = () => ({ ..._config });
|
|
8
|
+
const setConfig = (config) => {
|
|
9
|
+
_config = mergeConfigs(_config, config);
|
|
10
|
+
return getConfig();
|
|
11
|
+
};
|
|
12
|
+
const interceptors = createInterceptors();
|
|
13
|
+
const beforeRequest = async (options) => {
|
|
14
|
+
const opts = {
|
|
15
|
+
..._config,
|
|
16
|
+
...options,
|
|
17
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
19
|
+
serializedBody: undefined,
|
|
20
|
+
};
|
|
21
|
+
if (opts.security) {
|
|
22
|
+
await setAuthParams({
|
|
23
|
+
...opts,
|
|
24
|
+
security: opts.security,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (opts.requestValidator) {
|
|
28
|
+
await opts.requestValidator(opts);
|
|
29
|
+
}
|
|
30
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
31
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
32
|
+
}
|
|
33
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
34
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
35
|
+
opts.headers.delete('Content-Type');
|
|
36
|
+
}
|
|
37
|
+
const resolvedOpts = opts;
|
|
38
|
+
const url = buildUrl(resolvedOpts);
|
|
39
|
+
return { opts: resolvedOpts, url };
|
|
40
|
+
};
|
|
41
|
+
const request = async (options) => {
|
|
42
|
+
const { opts, url } = await beforeRequest(options);
|
|
43
|
+
const requestInit = {
|
|
44
|
+
redirect: 'follow',
|
|
45
|
+
...opts,
|
|
46
|
+
body: getValidRequestBody(opts),
|
|
47
|
+
};
|
|
48
|
+
let request = new Request(url, requestInit);
|
|
49
|
+
for (const fn of interceptors.request.fns) {
|
|
50
|
+
if (fn) {
|
|
51
|
+
request = await fn(request, opts);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
55
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
56
|
+
const _fetch = opts.fetch;
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await _fetch(request);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
63
|
+
let finalError = error;
|
|
64
|
+
for (const fn of interceptors.error.fns) {
|
|
65
|
+
if (fn) {
|
|
66
|
+
finalError = (await fn(error, undefined, request, opts));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finalError = finalError || {};
|
|
70
|
+
if (opts.throwOnError) {
|
|
71
|
+
throw finalError;
|
|
72
|
+
}
|
|
73
|
+
// Return error response
|
|
74
|
+
return opts.responseStyle === 'data'
|
|
75
|
+
? undefined
|
|
76
|
+
: {
|
|
77
|
+
error: finalError,
|
|
78
|
+
request,
|
|
79
|
+
response: undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
for (const fn of interceptors.response.fns) {
|
|
83
|
+
if (fn) {
|
|
84
|
+
response = await fn(response, request, opts);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const result = {
|
|
88
|
+
request,
|
|
89
|
+
response,
|
|
90
|
+
};
|
|
91
|
+
if (response.ok) {
|
|
92
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
93
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
94
|
+
: opts.parseAs) ?? 'json';
|
|
95
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
96
|
+
let emptyData;
|
|
97
|
+
switch (parseAs) {
|
|
98
|
+
case 'arrayBuffer':
|
|
99
|
+
case 'blob':
|
|
100
|
+
case 'text':
|
|
101
|
+
emptyData = await response[parseAs]();
|
|
102
|
+
break;
|
|
103
|
+
case 'formData':
|
|
104
|
+
emptyData = new FormData();
|
|
105
|
+
break;
|
|
106
|
+
case 'stream':
|
|
107
|
+
emptyData = response.body;
|
|
108
|
+
break;
|
|
109
|
+
case 'json':
|
|
110
|
+
default:
|
|
111
|
+
emptyData = {};
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return opts.responseStyle === 'data'
|
|
115
|
+
? emptyData
|
|
116
|
+
: {
|
|
117
|
+
data: emptyData,
|
|
118
|
+
...result,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
let data;
|
|
122
|
+
switch (parseAs) {
|
|
123
|
+
case 'arrayBuffer':
|
|
124
|
+
case 'blob':
|
|
125
|
+
case 'formData':
|
|
126
|
+
case 'text':
|
|
127
|
+
data = await response[parseAs]();
|
|
128
|
+
break;
|
|
129
|
+
case 'json': {
|
|
130
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
131
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
132
|
+
const text = await response.text();
|
|
133
|
+
data = text ? JSON.parse(text) : {};
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'stream':
|
|
137
|
+
return opts.responseStyle === 'data'
|
|
138
|
+
? response.body
|
|
139
|
+
: {
|
|
140
|
+
data: response.body,
|
|
141
|
+
...result,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (parseAs === 'json') {
|
|
145
|
+
if (opts.responseValidator) {
|
|
146
|
+
await opts.responseValidator(data);
|
|
147
|
+
}
|
|
148
|
+
if (opts.responseTransformer) {
|
|
149
|
+
data = await opts.responseTransformer(data);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return opts.responseStyle === 'data'
|
|
153
|
+
? data
|
|
154
|
+
: {
|
|
155
|
+
data,
|
|
156
|
+
...result,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const textError = await response.text();
|
|
160
|
+
let jsonError;
|
|
161
|
+
try {
|
|
162
|
+
jsonError = JSON.parse(textError);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// noop
|
|
166
|
+
}
|
|
167
|
+
const error = jsonError ?? textError;
|
|
168
|
+
let finalError = error;
|
|
169
|
+
for (const fn of interceptors.error.fns) {
|
|
170
|
+
if (fn) {
|
|
171
|
+
finalError = (await fn(error, response, request, opts));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
finalError = finalError || {};
|
|
175
|
+
if (opts.throwOnError) {
|
|
176
|
+
throw finalError;
|
|
177
|
+
}
|
|
178
|
+
// TODO: we probably want to return error and improve types
|
|
179
|
+
return opts.responseStyle === 'data'
|
|
180
|
+
? undefined
|
|
181
|
+
: {
|
|
182
|
+
error: finalError,
|
|
183
|
+
...result,
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
187
|
+
const makeSseFn = (method) => async (options) => {
|
|
188
|
+
const { opts, url } = await beforeRequest(options);
|
|
189
|
+
return createSseClient({
|
|
190
|
+
...opts,
|
|
191
|
+
body: opts.body,
|
|
192
|
+
headers: opts.headers,
|
|
193
|
+
method,
|
|
194
|
+
onRequest: async (url, init) => {
|
|
195
|
+
let request = new Request(url, init);
|
|
196
|
+
for (const fn of interceptors.request.fns) {
|
|
197
|
+
if (fn) {
|
|
198
|
+
request = await fn(request, opts);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return request;
|
|
202
|
+
},
|
|
203
|
+
serializedBody: getValidRequestBody(opts),
|
|
204
|
+
url,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
208
|
+
return {
|
|
209
|
+
buildUrl: _buildUrl,
|
|
210
|
+
connect: makeMethodFn('CONNECT'),
|
|
211
|
+
delete: makeMethodFn('DELETE'),
|
|
212
|
+
get: makeMethodFn('GET'),
|
|
213
|
+
getConfig,
|
|
214
|
+
head: makeMethodFn('HEAD'),
|
|
215
|
+
interceptors,
|
|
216
|
+
options: makeMethodFn('OPTIONS'),
|
|
217
|
+
patch: makeMethodFn('PATCH'),
|
|
218
|
+
post: makeMethodFn('POST'),
|
|
219
|
+
put: makeMethodFn('PUT'),
|
|
220
|
+
request,
|
|
221
|
+
setConfig,
|
|
222
|
+
sse: {
|
|
223
|
+
connect: makeSseFn('CONNECT'),
|
|
224
|
+
delete: makeSseFn('DELETE'),
|
|
225
|
+
get: makeSseFn('GET'),
|
|
226
|
+
head: makeSseFn('HEAD'),
|
|
227
|
+
options: makeSseFn('OPTIONS'),
|
|
228
|
+
patch: makeSseFn('PATCH'),
|
|
229
|
+
post: makeSseFn('POST'),
|
|
230
|
+
put: makeSseFn('PUT'),
|
|
231
|
+
trace: makeSseFn('TRACE'),
|
|
232
|
+
},
|
|
233
|
+
trace: makeMethodFn('TRACE'),
|
|
234
|
+
};
|
|
235
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth.gen';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
|
+
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export { createClient } from './client.gen';
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
8
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
3
|
+
export { buildClientParams } from '../core/params.gen';
|
|
4
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
5
|
+
export { createClient } from './client.gen';
|
|
6
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
4
|
+
import type { Middleware } from './utils.gen';
|
|
5
|
+
export type ResponseStyle = 'data' | 'fields';
|
|
6
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for all requests made by this client.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: T['baseUrl'];
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
13
|
+
* fetch instance.
|
|
14
|
+
*
|
|
15
|
+
* @default globalThis.fetch
|
|
16
|
+
*/
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/**
|
|
19
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
|
+
* options won't have any effect.
|
|
21
|
+
*
|
|
22
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
23
|
+
*/
|
|
24
|
+
next?: never;
|
|
25
|
+
/**
|
|
26
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
27
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
28
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
29
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
30
|
+
*
|
|
31
|
+
* @default 'auto'
|
|
32
|
+
*/
|
|
33
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
34
|
+
/**
|
|
35
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
36
|
+
*
|
|
37
|
+
* @default 'fields'
|
|
38
|
+
*/
|
|
39
|
+
responseStyle?: ResponseStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Throw an error instead of returning it in the response?
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
throwOnError?: T['throwOnError'];
|
|
46
|
+
}
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
|
+
responseStyle: TResponseStyle;
|
|
49
|
+
throwOnError: ThrowOnError;
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
51
|
+
/**
|
|
52
|
+
* Any body that you want to add to your request.
|
|
53
|
+
*
|
|
54
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
55
|
+
*/
|
|
56
|
+
body?: unknown;
|
|
57
|
+
path?: Record<string, unknown>;
|
|
58
|
+
query?: Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Security mechanism(s) to use for the request.
|
|
61
|
+
*/
|
|
62
|
+
security?: ReadonlyArray<Auth>;
|
|
63
|
+
url: Url;
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
serializedBody?: string;
|
|
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 : {
|
|
69
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
70
|
+
request: Request;
|
|
71
|
+
response: Response;
|
|
72
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
73
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
74
|
+
error: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
data: undefined;
|
|
77
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
|
+
}) & {
|
|
79
|
+
request: Request;
|
|
80
|
+
response: Response;
|
|
81
|
+
}>;
|
|
82
|
+
export interface ClientOptions {
|
|
83
|
+
baseUrl?: string;
|
|
84
|
+
responseStyle?: ResponseStyle;
|
|
85
|
+
throwOnError?: boolean;
|
|
86
|
+
}
|
|
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<never, 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>;
|
|
90
|
+
type BuildUrlFn = <TData extends {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
path?: Record<string, unknown>;
|
|
93
|
+
query?: Record<string, unknown>;
|
|
94
|
+
url: string;
|
|
95
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
97
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
101
|
+
* and the returned object will become the client's initial configuration.
|
|
102
|
+
*
|
|
103
|
+
* You may want to initialize your client this way instead of calling
|
|
104
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
105
|
+
* to ensure your client always has the correct values.
|
|
106
|
+
*/
|
|
107
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
108
|
+
export interface TDataShape {
|
|
109
|
+
body?: unknown;
|
|
110
|
+
headers?: unknown;
|
|
111
|
+
path?: unknown;
|
|
112
|
+
query?: unknown;
|
|
113
|
+
url: string;
|
|
114
|
+
}
|
|
115
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
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'>);
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Infers parseAs value from provided Content-Type header.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
+
export declare const setAuthParams: ({ security, ...options }: Pick<Required<RequestOptions>, "security"> & Pick<RequestOptions, "auth" | "query"> & {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
export declare const buildUrl: Client['buildUrl'];
|
|
12
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
|
|
15
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
|
+
declare class Interceptors<Interceptor> {
|
|
18
|
+
fns: Array<Interceptor | null>;
|
|
19
|
+
clear(): void;
|
|
20
|
+
eject(id: number | Interceptor): void;
|
|
21
|
+
exists(id: number | Interceptor): boolean;
|
|
22
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
23
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
24
|
+
use(fn: Interceptor): number;
|
|
25
|
+
}
|
|
26
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
27
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
28
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
29
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
30
|
+
}
|
|
31
|
+
export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
|
|
32
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
33
|
+
export {};
|