@tracken/cli 0.0.0-stage → 0.2.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/CHANGELOG.md +376 -0
- package/LICENSE +21 -0
- package/README.md +307 -2
- package/dist/bin/tracken.d.ts +2 -0
- package/dist/bin/tracken.js +5 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +114 -0
- package/dist/cli/commands/api.d.ts +2 -0
- package/dist/cli/commands/api.js +73 -0
- package/dist/cli/commands/auth.d.ts +8 -0
- package/dist/cli/commands/auth.js +141 -0
- package/dist/cli/commands/mcp.d.ts +19 -0
- package/dist/cli/commands/mcp.js +89 -0
- package/dist/cli/commands/org.d.ts +24 -0
- package/dist/cli/commands/org.js +123 -0
- package/dist/cli/context.d.ts +54 -0
- package/dist/cli/context.js +135 -0
- package/dist/cli/execute.d.ts +16 -0
- package/dist/cli/execute.js +112 -0
- package/dist/cli/help.d.ts +8 -0
- package/dist/cli/help.js +153 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +114 -0
- package/dist/cli/operation-args.d.ts +25 -0
- package/dist/cli/operation-args.js +245 -0
- package/dist/core/auth/oauth.d.ts +39 -0
- package/dist/core/auth/oauth.js +102 -0
- package/dist/core/auth/scopes.d.ts +19 -0
- package/dist/core/auth/scopes.js +49 -0
- package/dist/core/auth/secret-store.d.ts +60 -0
- package/dist/core/auth/secret-store.js +141 -0
- package/dist/core/auth/session.d.ts +75 -0
- package/dist/core/auth/session.js +200 -0
- package/dist/core/catalog.d.ts +12 -0
- package/dist/core/catalog.js +33 -0
- package/dist/core/client.d.ts +22 -0
- package/dist/core/client.js +45 -0
- package/dist/core/config.d.ts +27 -0
- package/dist/core/config.js +109 -0
- package/dist/core/environments.d.ts +21 -0
- package/dist/core/environments.js +53 -0
- package/dist/core/errors.d.ts +87 -0
- package/dist/core/errors.js +226 -0
- package/dist/core/index.d.ts +21 -0
- package/dist/core/index.js +22 -0
- package/dist/core/jobs.d.ts +15 -0
- package/dist/core/jobs.js +19 -0
- package/dist/core/operations.d.ts +108 -0
- package/dist/core/operations.js +7 -0
- package/dist/core/output/format.d.ts +19 -0
- package/dist/core/output/format.js +62 -0
- package/dist/core/output/render.d.ts +53 -0
- package/dist/core/output/render.js +229 -0
- package/dist/core/pagination.d.ts +2 -0
- package/dist/core/pagination.js +3 -0
- package/dist/core/request.d.ts +29 -0
- package/dist/core/request.js +109 -0
- package/dist/core/version.d.ts +10 -0
- package/dist/core/version.js +13 -0
- package/dist/generated/mcp-tools.d.ts +2 -0
- package/dist/generated/mcp-tools.js +5937 -0
- package/dist/generated/operations.d.ts +4 -0
- package/dist/generated/operations.js +17701 -0
- package/dist/mcp/errors.d.ts +34 -0
- package/dist/mcp/errors.js +91 -0
- package/dist/mcp/live.d.ts +3 -0
- package/dist/mcp/live.js +5 -0
- package/dist/mcp/prompts.d.ts +23 -0
- package/dist/mcp/prompts.js +101 -0
- package/dist/mcp/resources.d.ts +25 -0
- package/dist/mcp/resources.js +125 -0
- package/dist/mcp/server.d.ts +20 -0
- package/dist/mcp/server.js +59 -0
- package/dist/mcp/session.d.ts +60 -0
- package/dist/mcp/session.js +105 -0
- package/dist/mcp/tools.d.ts +17 -0
- package/dist/mcp/tools.js +181 -0
- package/dist/mcp/types.d.ts +25 -0
- package/dist/mcp/types.js +2 -0
- package/node_modules/@tracken/sdk/LICENSE +21 -0
- package/node_modules/@tracken/sdk/README.md +72 -0
- package/node_modules/@tracken/sdk/SOURCE.json +10 -0
- package/node_modules/@tracken/sdk/dist/client.d.ts +94 -0
- package/node_modules/@tracken/sdk/dist/client.js +258 -0
- package/node_modules/@tracken/sdk/dist/credentials.d.ts +60 -0
- package/node_modules/@tracken/sdk/dist/credentials.js +122 -0
- package/node_modules/@tracken/sdk/dist/decimal.d.ts +20 -0
- package/node_modules/@tracken/sdk/dist/decimal.js +67 -0
- package/node_modules/@tracken/sdk/dist/environments.d.ts +14 -0
- package/node_modules/@tracken/sdk/dist/environments.js +16 -0
- package/node_modules/@tracken/sdk/dist/errors.d.ts +126 -0
- package/node_modules/@tracken/sdk/dist/errors.js +165 -0
- package/node_modules/@tracken/sdk/dist/generated/operations.d.ts +1955 -0
- package/node_modules/@tracken/sdk/dist/generated/operations.js +2745 -0
- package/node_modules/@tracken/sdk/dist/generated/schema.d.ts +17988 -0
- package/node_modules/@tracken/sdk/dist/generated/schema.js +5 -0
- package/node_modules/@tracken/sdk/dist/index.d.ts +27 -0
- package/node_modules/@tracken/sdk/dist/index.js +24 -0
- package/node_modules/@tracken/sdk/dist/jobs.d.ts +23 -0
- package/node_modules/@tracken/sdk/dist/jobs.js +80 -0
- package/node_modules/@tracken/sdk/dist/operations.d.ts +23 -0
- package/node_modules/@tracken/sdk/dist/operations.js +2 -0
- package/node_modules/@tracken/sdk/dist/pagination.d.ts +19 -0
- package/node_modules/@tracken/sdk/dist/pagination.js +49 -0
- package/node_modules/@tracken/sdk/dist/request.d.ts +27 -0
- package/node_modules/@tracken/sdk/dist/request.js +10 -0
- package/node_modules/@tracken/sdk/dist/runtime.d.ts +22 -0
- package/node_modules/@tracken/sdk/dist/runtime.js +33 -0
- package/node_modules/@tracken/sdk/dist/tracken.d.ts +74 -0
- package/node_modules/@tracken/sdk/dist/tracken.js +203 -0
- package/node_modules/@tracken/sdk/dist/types.d.ts +130 -0
- package/node_modules/@tracken/sdk/dist/types.js +1 -0
- package/node_modules/@tracken/sdk/dist/version.d.ts +2 -0
- package/node_modules/@tracken/sdk/dist/version.js +2 -0
- package/node_modules/@tracken/sdk/package.json +42 -0
- package/node_modules/openapi-fetch/CHANGELOG.md +565 -0
- package/node_modules/openapi-fetch/CONTRIBUTING.md +102 -0
- package/node_modules/openapi-fetch/LICENSE +21 -0
- package/node_modules/openapi-fetch/README.md +122 -0
- package/node_modules/openapi-fetch/dist/index.cjs +547 -0
- package/node_modules/openapi-fetch/dist/index.cjs.map +1 -0
- package/node_modules/openapi-fetch/dist/index.d.cts +337 -0
- package/node_modules/openapi-fetch/dist/index.d.mts +335 -0
- package/node_modules/openapi-fetch/dist/index.d.ts +337 -0
- package/node_modules/openapi-fetch/dist/index.mjs +531 -0
- package/node_modules/openapi-fetch/dist/index.mjs.map +1 -0
- package/node_modules/openapi-fetch/package.json +77 -0
- package/node_modules/openapi-fetch/src/index.d.ts +345 -0
- package/node_modules/openapi-fetch/src/index.js +689 -0
- package/node_modules/openapi-typescript-helpers/CHANGELOG.md +98 -0
- package/node_modules/openapi-typescript-helpers/LICENSE +21 -0
- package/node_modules/openapi-typescript-helpers/README.md +5 -0
- package/node_modules/openapi-typescript-helpers/dist/index.cjs +3 -0
- package/node_modules/openapi-typescript-helpers/dist/index.cjs.map +1 -0
- package/node_modules/openapi-typescript-helpers/dist/index.d.cts +167 -0
- package/node_modules/openapi-typescript-helpers/dist/index.d.mts +167 -0
- package/node_modules/openapi-typescript-helpers/dist/index.d.ts +167 -0
- package/node_modules/openapi-typescript-helpers/dist/index.mjs +2 -0
- package/node_modules/openapi-typescript-helpers/dist/index.mjs.map +1 -0
- package/node_modules/openapi-typescript-helpers/package.json +39 -0
- package/openapi/SOURCE.json +10 -0
- package/openapi/openapi.yaml +30513 -0
- package/package.json +63 -4
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openapi-fetch",
|
|
3
|
+
"description": "Fast, type-safe fetch client for your OpenAPI schema. Only 6 kb (min). Works with React, Vue, Svelte, or vanilla JS.",
|
|
4
|
+
"version": "0.17.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Drew Powers",
|
|
7
|
+
"email": "drew@pow.rs"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.mjs",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./*": "./*"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://openapi-ts.dev",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/openapi-ts/openapi-typescript",
|
|
24
|
+
"directory": "packages/openapi-fetch"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/openapi-ts/openapi-typescript/issues"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"openapi",
|
|
31
|
+
"swagger",
|
|
32
|
+
"rest",
|
|
33
|
+
"api",
|
|
34
|
+
"oapi_3",
|
|
35
|
+
"oapi_3_1",
|
|
36
|
+
"typescript",
|
|
37
|
+
"fetch",
|
|
38
|
+
"react",
|
|
39
|
+
"vue",
|
|
40
|
+
"svelte"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"openapi-typescript-helpers": "^0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"axios": "1.13.5",
|
|
47
|
+
"execa": "^9.6.1",
|
|
48
|
+
"express": "5.2.1",
|
|
49
|
+
"feature-fetch": "0.0.51",
|
|
50
|
+
"node-forge": "1.3.1",
|
|
51
|
+
"openapi-typescript-codegen": "0.29.0",
|
|
52
|
+
"openapi-typescript-fetch": "2.2.1",
|
|
53
|
+
"superagent": "10.3.0",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"undici": "7.16.0",
|
|
56
|
+
"vite": "^7.3.1",
|
|
57
|
+
"openapi-typescript": "^7.13.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "unbuild",
|
|
61
|
+
"format": "biome format . --write",
|
|
62
|
+
"lint": "pnpm run lint:js && pnpm run lint:ts && pnpm run lint:ts-no-strict",
|
|
63
|
+
"lint:js": "biome check .",
|
|
64
|
+
"lint:ts": "tsc --noEmit",
|
|
65
|
+
"lint:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json",
|
|
66
|
+
"generate-types": "openapi-typescript -c test/redocly.yaml",
|
|
67
|
+
"pretest": "pnpm run generate-types",
|
|
68
|
+
"test": "pnpm run test:js && pnpm run test:exports",
|
|
69
|
+
"test:js": "vitest run",
|
|
70
|
+
"test:exports": "pnpm run build && attw --pack .",
|
|
71
|
+
"test-e2e": "playwright test",
|
|
72
|
+
"bench:js": "vitest bench",
|
|
73
|
+
"e2e-vite-build": "vite build test/e2e/app",
|
|
74
|
+
"e2e-vite-start": "vite preview test/e2e/app",
|
|
75
|
+
"version": "pnpm run prepare && pnpm run build"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ErrorResponse,
|
|
3
|
+
FilterKeys,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
IsOperationRequestBodyOptional,
|
|
6
|
+
MediaType,
|
|
7
|
+
OperationRequestBodyContent,
|
|
8
|
+
PathsWithMethod,
|
|
9
|
+
Readable,
|
|
10
|
+
RequiredKeysOf,
|
|
11
|
+
ResponseObjectMap,
|
|
12
|
+
SuccessResponse,
|
|
13
|
+
Writable,
|
|
14
|
+
} from "openapi-typescript-helpers";
|
|
15
|
+
|
|
16
|
+
/** Options for each client instance */
|
|
17
|
+
export interface ClientOptions extends Omit<RequestInit, "headers"> {
|
|
18
|
+
/** set the common root URL for all API requests */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/** custom fetch (defaults to globalThis.fetch) */
|
|
21
|
+
fetch?: (input: Request) => Promise<Response>;
|
|
22
|
+
/** custom Request (defaults to globalThis.Request) */
|
|
23
|
+
Request?: typeof Request;
|
|
24
|
+
/** global querySerializer */
|
|
25
|
+
querySerializer?: QuerySerializer<unknown> | QuerySerializerOptions;
|
|
26
|
+
/** global bodySerializer */
|
|
27
|
+
bodySerializer?: BodySerializer<unknown>;
|
|
28
|
+
/** global pathSerializer */
|
|
29
|
+
pathSerializer?: PathSerializer;
|
|
30
|
+
headers?: HeadersOptions;
|
|
31
|
+
/** RequestInit extension object to pass as 2nd argument to fetch when supported (defaults to undefined) */
|
|
32
|
+
requestInitExt?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type HeadersOptions =
|
|
36
|
+
| Required<RequestInit>["headers"]
|
|
37
|
+
| Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined>;
|
|
38
|
+
|
|
39
|
+
export type QuerySerializer<T> = (
|
|
40
|
+
query: T extends { parameters: any } ? NonNullable<T["parameters"]["query"]> : Record<string, unknown>,
|
|
41
|
+
) => string;
|
|
42
|
+
|
|
43
|
+
/** @see https://swagger.io/docs/specification/serialization/#query */
|
|
44
|
+
export type QuerySerializerOptions = {
|
|
45
|
+
/** Set serialization for arrays. @see https://swagger.io/docs/specification/serialization/#query */
|
|
46
|
+
array?: {
|
|
47
|
+
/** default: "form" */
|
|
48
|
+
style: "form" | "spaceDelimited" | "pipeDelimited";
|
|
49
|
+
/** default: true */
|
|
50
|
+
explode: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** Set serialization for objects. @see https://swagger.io/docs/specification/serialization/#query */
|
|
53
|
+
object?: {
|
|
54
|
+
/** default: "deepObject" */
|
|
55
|
+
style: "form" | "deepObject";
|
|
56
|
+
/** default: true */
|
|
57
|
+
explode: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The `allowReserved` keyword specifies whether the reserved characters
|
|
61
|
+
* `:/?#[]@!$&'()*+,;=` in parameter values are allowed to be sent as they
|
|
62
|
+
* are, or should be percent-encoded. By default, allowReserved is `false`,
|
|
63
|
+
* and reserved characters are percent-encoded.
|
|
64
|
+
* @see https://swagger.io/docs/specification/serialization/#query
|
|
65
|
+
*/
|
|
66
|
+
allowReserved?: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type BodySerializer<T> = (body: OperationRequestBodyContent<T>) => any;
|
|
70
|
+
|
|
71
|
+
export type PathSerializer = (pathname: string, pathParams: Record<string, unknown>) => string;
|
|
72
|
+
|
|
73
|
+
type BodyType<T = unknown> = {
|
|
74
|
+
json: T;
|
|
75
|
+
text: Awaited<ReturnType<Response["text"]>>;
|
|
76
|
+
blob: Awaited<ReturnType<Response["blob"]>>;
|
|
77
|
+
arrayBuffer: Awaited<ReturnType<Response["arrayBuffer"]>>;
|
|
78
|
+
stream: Response["body"];
|
|
79
|
+
};
|
|
80
|
+
export type ParseAs = keyof BodyType;
|
|
81
|
+
export type ParseAsResponse<T, Options> = Options extends {
|
|
82
|
+
parseAs: ParseAs;
|
|
83
|
+
}
|
|
84
|
+
? BodyType<T>[Options["parseAs"]]
|
|
85
|
+
: T;
|
|
86
|
+
|
|
87
|
+
export interface DefaultParamsOption {
|
|
88
|
+
params?: {
|
|
89
|
+
query?: Record<string, unknown>;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type ParamsOption<T> = T extends {
|
|
94
|
+
parameters: any;
|
|
95
|
+
}
|
|
96
|
+
? RequiredKeysOf<T["parameters"]> extends never
|
|
97
|
+
? { params?: T["parameters"] }
|
|
98
|
+
: { params: T["parameters"] }
|
|
99
|
+
: DefaultParamsOption;
|
|
100
|
+
|
|
101
|
+
// Writable<T> strips $Read markers (readOnly properties excluded from request body)
|
|
102
|
+
export type RequestBodyOption<T> =
|
|
103
|
+
Writable<OperationRequestBodyContent<T>> extends never
|
|
104
|
+
? { body?: never }
|
|
105
|
+
: IsOperationRequestBodyOptional<T> extends true
|
|
106
|
+
? { body?: Writable<OperationRequestBodyContent<T>> }
|
|
107
|
+
: { body: Writable<OperationRequestBodyContent<T>> };
|
|
108
|
+
|
|
109
|
+
export type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body" | "headers">;
|
|
110
|
+
|
|
111
|
+
// Readable<T> strips $Write markers (writeOnly properties excluded from response)
|
|
112
|
+
export type FetchResponse<T extends Record<string | number, any>, Options, Media extends MediaType> =
|
|
113
|
+
| {
|
|
114
|
+
data: ParseAsResponse<Readable<SuccessResponse<ResponseObjectMap<T>, Media>>, Options>;
|
|
115
|
+
error?: never;
|
|
116
|
+
response: Response;
|
|
117
|
+
}
|
|
118
|
+
| {
|
|
119
|
+
data?: never;
|
|
120
|
+
error: Readable<ErrorResponse<ResponseObjectMap<T>, Media>>;
|
|
121
|
+
response: Response;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type RequestOptions<T> = ParamsOption<T> &
|
|
125
|
+
RequestBodyOption<T> & {
|
|
126
|
+
baseUrl?: string;
|
|
127
|
+
querySerializer?: QuerySerializer<T> | QuerySerializerOptions;
|
|
128
|
+
bodySerializer?: BodySerializer<T>;
|
|
129
|
+
pathSerializer?: PathSerializer;
|
|
130
|
+
parseAs?: ParseAs;
|
|
131
|
+
fetch?: ClientOptions["fetch"];
|
|
132
|
+
headers?: HeadersOptions;
|
|
133
|
+
middleware?: Middleware[];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type MergedOptions<T = unknown> = {
|
|
137
|
+
baseUrl: string;
|
|
138
|
+
parseAs: ParseAs;
|
|
139
|
+
querySerializer: QuerySerializer<T>;
|
|
140
|
+
bodySerializer: BodySerializer<T>;
|
|
141
|
+
pathSerializer: PathSerializer;
|
|
142
|
+
fetch: typeof globalThis.fetch;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export interface MiddlewareRequestParams {
|
|
146
|
+
query?: Record<string, unknown>;
|
|
147
|
+
header?: Record<string, unknown>;
|
|
148
|
+
path?: Record<string, unknown>;
|
|
149
|
+
cookie?: Record<string, unknown>;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface MiddlewareCallbackParams {
|
|
153
|
+
/** Current Request object */
|
|
154
|
+
request: Request;
|
|
155
|
+
/** The original OpenAPI schema path (including curly braces) */
|
|
156
|
+
readonly schemaPath: string;
|
|
157
|
+
/** OpenAPI parameters as provided from openapi-fetch */
|
|
158
|
+
readonly params: MiddlewareRequestParams;
|
|
159
|
+
/** Unique ID for this request */
|
|
160
|
+
readonly id: string;
|
|
161
|
+
/** createClient options (read-only) */
|
|
162
|
+
readonly options: MergedOptions;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type MiddlewareOnRequest = (
|
|
166
|
+
options: MiddlewareCallbackParams,
|
|
167
|
+
) => void | Request | Response | undefined | Promise<Request | Response | undefined | void>;
|
|
168
|
+
type MiddlewareOnResponse = (
|
|
169
|
+
options: MiddlewareCallbackParams & { response: Response },
|
|
170
|
+
) => void | Response | undefined | Promise<Response | undefined | void>;
|
|
171
|
+
type MiddlewareOnError = (
|
|
172
|
+
options: MiddlewareCallbackParams & { error: unknown },
|
|
173
|
+
) => void | Response | Error | Promise<void | Response | Error>;
|
|
174
|
+
|
|
175
|
+
export type Middleware =
|
|
176
|
+
| {
|
|
177
|
+
onRequest: MiddlewareOnRequest;
|
|
178
|
+
onResponse?: MiddlewareOnResponse;
|
|
179
|
+
onError?: MiddlewareOnError;
|
|
180
|
+
}
|
|
181
|
+
| {
|
|
182
|
+
onRequest?: MiddlewareOnRequest;
|
|
183
|
+
onResponse: MiddlewareOnResponse;
|
|
184
|
+
onError?: MiddlewareOnError;
|
|
185
|
+
}
|
|
186
|
+
| {
|
|
187
|
+
onRequest?: MiddlewareOnRequest;
|
|
188
|
+
onResponse?: MiddlewareOnResponse;
|
|
189
|
+
onError: MiddlewareOnError;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
|
|
193
|
+
export type MaybeOptionalInit<Params, Location extends keyof Params> =
|
|
194
|
+
RequiredKeysOf<FetchOptions<FilterKeys<Params, Location>>> extends never
|
|
195
|
+
? FetchOptions<FilterKeys<Params, Location>> | undefined
|
|
196
|
+
: FetchOptions<FilterKeys<Params, Location>>;
|
|
197
|
+
|
|
198
|
+
// The final init param to accept.
|
|
199
|
+
// - Determines if the param is optional or not.
|
|
200
|
+
// - Performs arbitrary [key: string] addition.
|
|
201
|
+
// Note: the addition MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not).
|
|
202
|
+
type InitParam<Init> =
|
|
203
|
+
RequiredKeysOf<Init> extends never ? [(Init & { [key: string]: unknown })?] : [Init & { [key: string]: unknown }];
|
|
204
|
+
|
|
205
|
+
export type ClientMethod<
|
|
206
|
+
Paths extends Record<string, Record<HttpMethod, {}>>,
|
|
207
|
+
Method extends HttpMethod,
|
|
208
|
+
Media extends MediaType,
|
|
209
|
+
> = <Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<Paths[Path], Method>>(
|
|
210
|
+
url: Path,
|
|
211
|
+
...init: InitParam<Init>
|
|
212
|
+
) => Promise<FetchResponse<Paths[Path][Method], Init, Media>>;
|
|
213
|
+
|
|
214
|
+
export type ClientRequestMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
|
|
215
|
+
Method extends HttpMethod,
|
|
216
|
+
Path extends PathsWithMethod<Paths, Method>,
|
|
217
|
+
Init extends MaybeOptionalInit<Paths[Path], Method>,
|
|
218
|
+
>(
|
|
219
|
+
method: Method,
|
|
220
|
+
url: Path,
|
|
221
|
+
...init: InitParam<Init>
|
|
222
|
+
) => Promise<FetchResponse<Paths[Path][Method], Init, Media>>;
|
|
223
|
+
|
|
224
|
+
export type ClientForPath<PathInfo extends Record<string | number, any>, Media extends MediaType> = {
|
|
225
|
+
[Method in keyof PathInfo as Uppercase<string & Method>]: <Init extends MaybeOptionalInit<PathInfo, Method>>(
|
|
226
|
+
...init: InitParam<Init>
|
|
227
|
+
) => Promise<FetchResponse<PathInfo[Method], Init, Media>>;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export interface Client<Paths extends {}, Media extends MediaType = MediaType> {
|
|
231
|
+
request: ClientRequestMethod<Paths, Media>;
|
|
232
|
+
/** Call a GET endpoint */
|
|
233
|
+
GET: ClientMethod<Paths, "get", Media>;
|
|
234
|
+
/** Call a PUT endpoint */
|
|
235
|
+
PUT: ClientMethod<Paths, "put", Media>;
|
|
236
|
+
/** Call a POST endpoint */
|
|
237
|
+
POST: ClientMethod<Paths, "post", Media>;
|
|
238
|
+
/** Call a DELETE endpoint */
|
|
239
|
+
DELETE: ClientMethod<Paths, "delete", Media>;
|
|
240
|
+
/** Call a OPTIONS endpoint */
|
|
241
|
+
OPTIONS: ClientMethod<Paths, "options", Media>;
|
|
242
|
+
/** Call a HEAD endpoint */
|
|
243
|
+
HEAD: ClientMethod<Paths, "head", Media>;
|
|
244
|
+
/** Call a PATCH endpoint */
|
|
245
|
+
PATCH: ClientMethod<Paths, "patch", Media>;
|
|
246
|
+
/** Call a TRACE endpoint */
|
|
247
|
+
TRACE: ClientMethod<Paths, "trace", Media>;
|
|
248
|
+
/** Register middleware */
|
|
249
|
+
use(...middleware: Middleware[]): void;
|
|
250
|
+
/** Unregister middleware */
|
|
251
|
+
eject(...middleware: Middleware[]): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type ClientPathsWithMethod<CreatedClient extends Client<any, any>, Method extends HttpMethod> =
|
|
255
|
+
CreatedClient extends Client<infer Paths, infer _Media> ? PathsWithMethod<Paths, Method> : never;
|
|
256
|
+
|
|
257
|
+
export type MethodResponse<
|
|
258
|
+
CreatedClient extends Client<any, any>,
|
|
259
|
+
Method extends HttpMethod,
|
|
260
|
+
Path extends ClientPathsWithMethod<CreatedClient, Method>,
|
|
261
|
+
Options = {},
|
|
262
|
+
> =
|
|
263
|
+
CreatedClient extends Client<infer Paths extends { [key: string]: any }, infer Media extends MediaType>
|
|
264
|
+
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]>
|
|
265
|
+
: never;
|
|
266
|
+
|
|
267
|
+
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
268
|
+
clientOptions?: ClientOptions,
|
|
269
|
+
): Client<Paths, Media>;
|
|
270
|
+
|
|
271
|
+
export type PathBasedClient<Paths extends Record<string | number, any>, Media extends MediaType = MediaType> = {
|
|
272
|
+
[Path in keyof Paths]: ClientForPath<Paths[Path], Media>;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export declare function wrapAsPathBasedClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
276
|
+
client: Client<Paths, Media>,
|
|
277
|
+
): PathBasedClient<Paths, Media>;
|
|
278
|
+
|
|
279
|
+
export declare function createPathBasedClient<Paths extends {}, Media extends MediaType = MediaType>(
|
|
280
|
+
clientOptions?: ClientOptions,
|
|
281
|
+
): PathBasedClient<Paths, Media>;
|
|
282
|
+
|
|
283
|
+
/** Serialize primitive params to string */
|
|
284
|
+
export declare function serializePrimitiveParam(
|
|
285
|
+
name: string,
|
|
286
|
+
value: string,
|
|
287
|
+
options?: { allowReserved?: boolean },
|
|
288
|
+
): string;
|
|
289
|
+
|
|
290
|
+
/** Serialize object param to string */
|
|
291
|
+
export declare function serializeObjectParam(
|
|
292
|
+
name: string,
|
|
293
|
+
value: Record<string, unknown>,
|
|
294
|
+
options: {
|
|
295
|
+
style: "simple" | "label" | "matrix" | "form" | "deepObject";
|
|
296
|
+
explode: boolean;
|
|
297
|
+
allowReserved?: boolean;
|
|
298
|
+
},
|
|
299
|
+
): string;
|
|
300
|
+
|
|
301
|
+
/** Serialize array param to string */
|
|
302
|
+
export declare function serializeArrayParam(
|
|
303
|
+
name: string,
|
|
304
|
+
value: unknown[],
|
|
305
|
+
options: {
|
|
306
|
+
style: "simple" | "label" | "matrix" | "form" | "spaceDelimited" | "pipeDelimited";
|
|
307
|
+
explode: boolean;
|
|
308
|
+
allowReserved?: boolean;
|
|
309
|
+
},
|
|
310
|
+
): string;
|
|
311
|
+
|
|
312
|
+
/** Serialize query params to string */
|
|
313
|
+
export declare function createQuerySerializer<T = unknown>(
|
|
314
|
+
options?: QuerySerializerOptions,
|
|
315
|
+
): (queryParams: T) => string;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Handle different OpenAPI 3.x serialization styles
|
|
319
|
+
* @type {import("./index.js").defaultPathSerializer}
|
|
320
|
+
* @see https://swagger.io/docs/specification/serialization/#path
|
|
321
|
+
*/
|
|
322
|
+
export declare function defaultPathSerializer(pathname: string, pathParams: Record<string, unknown>): string;
|
|
323
|
+
|
|
324
|
+
/** Serialize body object to string */
|
|
325
|
+
export declare function defaultBodySerializer<T>(body: T): string;
|
|
326
|
+
|
|
327
|
+
/** Construct URL string from baseUrl and handle path and query params */
|
|
328
|
+
export declare function createFinalURL<O>(
|
|
329
|
+
pathname: string,
|
|
330
|
+
options: {
|
|
331
|
+
baseUrl: string;
|
|
332
|
+
params: {
|
|
333
|
+
query?: Record<string, unknown>;
|
|
334
|
+
path?: Record<string, unknown>;
|
|
335
|
+
};
|
|
336
|
+
querySerializer: QuerySerializer<O>;
|
|
337
|
+
pathSerializer: PathSerializer;
|
|
338
|
+
},
|
|
339
|
+
): string;
|
|
340
|
+
|
|
341
|
+
/** Merge headers a and b, with b taking priority */
|
|
342
|
+
export declare function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]): Headers;
|
|
343
|
+
|
|
344
|
+
/** Remove trailing slash from url */
|
|
345
|
+
export declare function removeTrailingSlash(url: string): string;
|