@nxgt/httpyz 0.1.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/README.md +1295 -0
- package/dist/cancel/abort.d.ts +20 -0
- package/dist/cancel/abort.d.ts.map +1 -0
- package/dist/cancel/latest.d.ts +3 -0
- package/dist/cancel/latest.d.ts.map +1 -0
- package/dist/client/create-http-client.d.ts +14 -0
- package/dist/client/create-http-client.d.ts.map +1 -0
- package/dist/client/types.d.ts +123 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/errors/errors.d.ts +80 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1110 -0
- package/dist/index.js.map +27 -0
- package/dist/integration/index.d.ts +9 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/index.js +1051 -0
- package/dist/integration/index.js.map +25 -0
- package/dist/middleware/auth.d.ts +18 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/cache.d.ts +42 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/compose.d.ts +22 -0
- package/dist/middleware/compose.d.ts.map +1 -0
- package/dist/middleware/retry.d.ts +36 -0
- package/dist/middleware/retry.d.ts.map +1 -0
- package/dist/reply/media-type.d.ts +18 -0
- package/dist/reply/media-type.d.ts.map +1 -0
- package/dist/reply/read-reply.d.ts +25 -0
- package/dist/reply/read-reply.d.ts.map +1 -0
- package/dist/reply/types.d.ts +55 -0
- package/dist/reply/types.d.ts.map +1 -0
- package/dist/reply/unwrap.d.ts +31 -0
- package/dist/reply/unwrap.d.ts.map +1 -0
- package/dist/request/encode.d.ts +24 -0
- package/dist/request/encode.d.ts.map +1 -0
- package/dist/request/types.d.ts +57 -0
- package/dist/request/types.d.ts.map +1 -0
- package/dist/schema/standard-schema.d.ts +46 -0
- package/dist/schema/standard-schema.d.ts.map +1 -0
- package/dist/stream/connection.d.ts +45 -0
- package/dist/stream/connection.d.ts.map +1 -0
- package/dist/stream/event-stream.d.ts +15 -0
- package/dist/stream/event-stream.d.ts.map +1 -0
- package/dist/stream/line-parser.d.ts +13 -0
- package/dist/stream/line-parser.d.ts.map +1 -0
- package/dist/stream/line-stream.d.ts +10 -0
- package/dist/stream/line-stream.d.ts.map +1 -0
- package/dist/stream/sse-parser.d.ts +25 -0
- package/dist/stream/sse-parser.d.ts.map +1 -0
- package/dist/stream/types.d.ts +66 -0
- package/dist/stream/types.d.ts.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aborts, as the client makes and recognizes them. A call aborted through its
|
|
3
|
+
* `signal`, by a later call with the same `latest`, or by its group's
|
|
4
|
+
* `cancel()` rejects with the abort's reason, unwrapped: an `AbortError`
|
|
5
|
+
* unless the caller gave a reason of its own.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Whether `error` ended a call because it was aborted, rather than failed:
|
|
9
|
+
* a signal aborted without a reason of its own, or by `AbortSignal.timeout()`,
|
|
10
|
+
* a later call with the same `latest`, or a group's `cancel()`. The client's
|
|
11
|
+
* own `TimeoutError`, past `timeout`, is a failure, not an abort.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isAbortError(error: unknown): boolean;
|
|
14
|
+
/** What the client aborts a call with: an `AbortError`, which `isAbortError` knows. */
|
|
15
|
+
export declare const cancelled: (message: string) => DOMException;
|
|
16
|
+
/** `promise`, or the signal's reason as soon as it aborts; the promise itself runs on. */
|
|
17
|
+
export declare function abortable<T>(promise: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
18
|
+
/** One signal that aborts with the first of them; `undefined` when there are none. */
|
|
19
|
+
export declare function joinSignals(...signals: (AbortSignal | null | undefined)[]): AbortSignal | undefined;
|
|
20
|
+
//# sourceMappingURL=abort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/cancel/abort.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKpD;AAED,uFAAuF;AACvF,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,KAAG,YACJ,CAAC;AAEzC,0FAA0F;AAC1F,wBAAgB,SAAS,CAAC,CAAC,EAC1B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC7B,OAAO,CAAC,CAAC,CAAC,CAUZ;AAED,sFAAsF;AACtF,wBAAgB,WAAW,CAC1B,GAAG,OAAO,EAAE,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC5C,WAAW,GAAG,SAAS,CAKzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"latest.d.ts","sourceRoot":"","sources":["../../src/cancel/latest.ts"],"names":[],"mappings":"AAOA,uGAAuG;AACvG,wBAAgB,YAAY,IAAI,CAAC,GAAG,EAAE,MAAM,KAAK,WAAW,CAa3D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HttpClient, HttpClientOptions, Method } from './types';
|
|
2
|
+
export declare const METHODS: readonly Method[];
|
|
3
|
+
/**
|
|
4
|
+
* ```ts
|
|
5
|
+
* const http = createHttpClient({ baseUrl: 'https://api.example.com', retry: 2 });
|
|
6
|
+
* const reply = await http.get('/employees/{id}', {
|
|
7
|
+
* param: { id },
|
|
8
|
+
* responses: { 200: Employee, 404: Problem },
|
|
9
|
+
* });
|
|
10
|
+
* if (reply.status === 200) reply.data.name;
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function createHttpClient(options?: HttpClientOptions): HttpClient;
|
|
14
|
+
//# sourceMappingURL=create-http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-http-client.d.ts","sourceRoot":"","sources":["../../src/client/create-http-client.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAEX,UAAU,EACV,iBAAiB,EAEjB,MAAM,EAEN,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,OAAO,EAAE,SAAS,MAAM,EAUpC,CAAC;AAwCF;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAiV5E"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/** The client, its options, and what each call takes. */
|
|
2
|
+
import type { AuthOptions } from '../middleware/auth';
|
|
3
|
+
import type { Middleware } from '../middleware/compose';
|
|
4
|
+
import type { RetryOptions } from '../middleware/retry';
|
|
5
|
+
import type { HttpReply, Responses } from '../reply/types';
|
|
6
|
+
import type { PathParamNames, RequestInput } from '../request/types';
|
|
7
|
+
import type { StandardSchemaV1 } from '../schema/standard-schema';
|
|
8
|
+
import type { EventSchemas, EventStream, EventsOptions, LinesOptions, Stream, StreamEvent, StreamItem } from '../stream/types';
|
|
9
|
+
/** HTTP's methods, as OpenAPI lists them, and `query`. */
|
|
10
|
+
export type Method = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace' | 'query';
|
|
11
|
+
export interface HttpClientOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Where the API is served: `https://api.example.com`, or with a prefix,
|
|
14
|
+
* `https://example.com/api`. Without one, URLs are relative, which only a
|
|
15
|
+
* browser resolves.
|
|
16
|
+
*/
|
|
17
|
+
baseUrl?: string | URL;
|
|
18
|
+
/** Sends each request. Default: `globalThis.fetch`, looked up at each call. */
|
|
19
|
+
fetch?: (request: Request) => Promise<Response>;
|
|
20
|
+
/** Sent with every request. A function runs before each one. */
|
|
21
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
22
|
+
/** fetch options for every request: `credentials`, `mode`, `cache`… */
|
|
23
|
+
init?: Omit<RequestInit, 'method' | 'body' | 'headers' | 'signal'>;
|
|
24
|
+
/** Milliseconds before a call fails with a `TimeoutError`. Default: none. */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
/** A token on every request, refreshed once on a 401. */
|
|
27
|
+
auth?: AuthOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Sends a request again after a failure that may pass: a number of
|
|
30
|
+
* retries, or `RetryOptions`. Default: never.
|
|
31
|
+
*/
|
|
32
|
+
retry?: number | RetryOptions | false;
|
|
33
|
+
/** Around every request, the first outermost, inside `retry` and `auth`. */
|
|
34
|
+
use?: readonly Middleware[];
|
|
35
|
+
}
|
|
36
|
+
/** What any call may add: fetch's own options, and its own timeout and retry. */
|
|
37
|
+
export interface CallOptions extends Omit<RequestInit, 'method' | 'body' | 'headers'> {
|
|
38
|
+
/** Over the client's `headers`. A `Content-Type` here wins over the body's own. */
|
|
39
|
+
headers?: HeadersInit;
|
|
40
|
+
/** This call's `timeout`, instead of the client's. */
|
|
41
|
+
timeout?: number;
|
|
42
|
+
/** This call's `retry`, instead of the client's: `false` never retries. */
|
|
43
|
+
retry?: number | RetryOptions | false;
|
|
44
|
+
/** Names the call, in its errors and to middleware: an OpenAPI `operationId`. */
|
|
45
|
+
operationId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* One call running per key: this call aborts the one before it with the
|
|
48
|
+
* same `latest`, if that one still runs, which rejects with an
|
|
49
|
+
* `AbortError`. A search typed ahead keeps only its last query in flight.
|
|
50
|
+
*/
|
|
51
|
+
latest?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ReplyOptions<R extends Responses | undefined, Decoded extends boolean> {
|
|
54
|
+
/**
|
|
55
|
+
* The replies the call expects, by status: a schema for JSON, `null` for
|
|
56
|
+
* no content, or a schema per media type. A status not in it throws an
|
|
57
|
+
* `UndeclaredStatusError`. Without it, every reply is returned, read by
|
|
58
|
+
* its media type, as `unknown`.
|
|
59
|
+
*/
|
|
60
|
+
responses?: R;
|
|
61
|
+
/** Checks each reply with its schema, throwing a `ValidationError`. Default: `true`. */
|
|
62
|
+
validate?: boolean;
|
|
63
|
+
/** Returns what each schema outputs, rather than what it was given. Default: `true`. */
|
|
64
|
+
decode?: Decoded;
|
|
65
|
+
}
|
|
66
|
+
export type RequestOptions<Path extends string, R extends Responses | undefined = undefined, Decoded extends boolean = true> = RequestInput<Path> & CallOptions & ReplyOptions<R, Decoded>;
|
|
67
|
+
/** Options for a call to `Path`: required when the path has `{name}`s to fill. */
|
|
68
|
+
export type ArgsFor<Path extends string, Options> = [
|
|
69
|
+
PathParamNames<Path>
|
|
70
|
+
] extends [never] ? [options?: Options] : [options: Options];
|
|
71
|
+
export type RequestArgs<Path extends string, R extends Responses | undefined, Decoded extends boolean> = ArgsFor<Path, RequestOptions<Path, R, Decoded>>;
|
|
72
|
+
export type EventsArgs<Path extends string, E extends EventSchemas | undefined, Decoded extends boolean> = ArgsFor<Path, RequestInput<Path> & EventsOptions<E, Decoded>>;
|
|
73
|
+
export type LinesArgs<Path extends string, I extends StandardSchemaV1 | undefined, Decoded extends boolean> = ArgsFor<Path, RequestInput<Path> & LinesOptions<I, Decoded>>;
|
|
74
|
+
/** `http.get(path, options)`, and the other methods. */
|
|
75
|
+
export type Call = <Path extends string, R extends Responses | undefined = undefined, Decoded extends boolean = true>(path: Path, ...args: RequestArgs<Path, R, Decoded>) => Promise<HttpReply<R, Decoded>>;
|
|
76
|
+
export interface SendOptions {
|
|
77
|
+
timeout?: number;
|
|
78
|
+
retry?: number | RetryOptions | false;
|
|
79
|
+
operationId?: string;
|
|
80
|
+
/** As a call's `latest`: aborts the request before it with the same key. */
|
|
81
|
+
latest?: string;
|
|
82
|
+
}
|
|
83
|
+
/** Calls that end together: a page's, a component's, a job's. */
|
|
84
|
+
export type HttpGroup = HttpClient & {
|
|
85
|
+
/**
|
|
86
|
+
* Aborts every call and stream of the group still running, with `reason`,
|
|
87
|
+
* or an `AbortError`. The group goes on: the calls made after it run.
|
|
88
|
+
*/
|
|
89
|
+
cancel(reason?: unknown): void;
|
|
90
|
+
/** Aborts on the next `cancel()`: for work of your own that ends with the group's calls. */
|
|
91
|
+
readonly signal: AbortSignal;
|
|
92
|
+
};
|
|
93
|
+
export type HttpClient = {
|
|
94
|
+
/** A call with the method as a value: `http.request('get', '/items/{id}', { param })`. */
|
|
95
|
+
request<Path extends string, R extends Responses | undefined = undefined, Decoded extends boolean = true>(method: Method, path: Path, ...args: RequestArgs<Path, R, Decoded>): Promise<HttpReply<R, Decoded>>;
|
|
96
|
+
/**
|
|
97
|
+
* A `Request` of your own, through the client's `retry`, `auth`, `use`
|
|
98
|
+
* and timeout, with its `headers` added where the request has none. Its
|
|
99
|
+
* `Response` is returned as it is.
|
|
100
|
+
*/
|
|
101
|
+
send(request: Request, options?: SendOptions): Promise<Response>;
|
|
102
|
+
/**
|
|
103
|
+
* Server-sent events, read with `for await`, each narrowed on its
|
|
104
|
+
* `event`: `http.events('/feed', { events: { update: Item } })`. It
|
|
105
|
+
* connects when read, and reconnects as `EventSource` does. `timeout`
|
|
106
|
+
* bounds each connection until its headers arrive, not the stream.
|
|
107
|
+
*/
|
|
108
|
+
events<Path extends string, E extends EventSchemas | undefined = undefined, Decoded extends boolean = true>(path: Path, ...args: EventsArgs<Path, E, Decoded>): EventStream<StreamEvent<E, Decoded>>;
|
|
109
|
+
/**
|
|
110
|
+
* JSON Lines, NDJSON or JSON text sequences, a record at a time, each
|
|
111
|
+
* checked by `item`: `http.lines('/export', { item: Row })`.
|
|
112
|
+
*/
|
|
113
|
+
lines<Path extends string, I extends StandardSchemaV1 | undefined = undefined, Decoded extends boolean = true>(path: Path, ...args: LinesArgs<Path, I, Decoded>): Stream<StreamItem<I, Decoded>>;
|
|
114
|
+
/**
|
|
115
|
+
* The same client, for calls that end together: `group.cancel()` aborts
|
|
116
|
+
* every call and stream made through it that still runs. A group's group
|
|
117
|
+
* is cancelled with it.
|
|
118
|
+
*/
|
|
119
|
+
group(): HttpGroup;
|
|
120
|
+
} & {
|
|
121
|
+
readonly [M in Method]: Call;
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,iBAAiB,CAAC;AAEzB,0DAA0D;AAC1D,MAAM,MAAM,MAAM,GACf,KAAK,GACL,KAAK,GACL,MAAM,GACN,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,CAAC;AAEX,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACvB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChD,gEAAgE;IAChE,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,uEAAuE;IACvE,IAAI,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;IACnE,6EAA6E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,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAClC;;;;OAIG;IACH,KAAK,IAAI,SAAS,CAAC;CACnB,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,GAAG,IAAI;CAAE,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Which call failed: every error a call throws carries it. */
|
|
2
|
+
export interface CallContext {
|
|
3
|
+
readonly method: string;
|
|
4
|
+
/** As the caller wrote it: `/employees/{id}`. */
|
|
5
|
+
readonly path: string;
|
|
6
|
+
/** The call's name, when it was given one: an OpenAPI `operationId`. */
|
|
7
|
+
readonly operationId?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Where a value was found wrong, as `@nxgt/openapi-hono` reports it. */
|
|
10
|
+
export interface ValidationIssue {
|
|
11
|
+
target: 'param' | 'query' | 'header' | 'json' | 'form' | 'body' | 'response';
|
|
12
|
+
/** Inside the target: `['items', 0, 'name']`, or `[]` for the whole of it. */
|
|
13
|
+
path: (string | number)[];
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
/** The same shape as the server's: one failure, every issue in it. */
|
|
18
|
+
export interface ValidationFailure {
|
|
19
|
+
kind: 'request' | 'response';
|
|
20
|
+
operationId?: string;
|
|
21
|
+
method: string;
|
|
22
|
+
path: string;
|
|
23
|
+
status?: number;
|
|
24
|
+
issues: ValidationIssue[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Every error a call throws, but an abort the caller asked for, which comes
|
|
28
|
+
* through as the `AbortError` its signal gave.
|
|
29
|
+
*/
|
|
30
|
+
export declare class ClientError extends Error {
|
|
31
|
+
name: string;
|
|
32
|
+
readonly operationId: string | undefined;
|
|
33
|
+
readonly method: string;
|
|
34
|
+
readonly path: string;
|
|
35
|
+
constructor(context: CallContext, message: string, options?: ErrorOptions);
|
|
36
|
+
}
|
|
37
|
+
/** fetch failed: no connection, a refused one, a CORS refusal. The cause is fetch's error. */
|
|
38
|
+
export declare class NetworkError extends ClientError {
|
|
39
|
+
name: string;
|
|
40
|
+
constructor(context: CallContext, options?: ErrorOptions);
|
|
41
|
+
}
|
|
42
|
+
export declare class TimeoutError extends ClientError {
|
|
43
|
+
name: string;
|
|
44
|
+
readonly timeout: number;
|
|
45
|
+
constructor(context: CallContext, timeout: number, options?: ErrorOptions);
|
|
46
|
+
}
|
|
47
|
+
/** A status the call's `responses` do not declare. */
|
|
48
|
+
export declare class UndeclaredStatusError extends ClientError {
|
|
49
|
+
name: string;
|
|
50
|
+
readonly status: number;
|
|
51
|
+
/** Unread: its body is still there to read. */
|
|
52
|
+
readonly response: Response;
|
|
53
|
+
constructor(context: CallContext, response: Response);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A reply its declaration does not describe: an undeclared media type, JSON
|
|
57
|
+
* that does not parse, a value its schema refuses; or a request refused
|
|
58
|
+
* before it was sent.
|
|
59
|
+
*/
|
|
60
|
+
export declare class ValidationError extends ClientError {
|
|
61
|
+
name: string;
|
|
62
|
+
readonly failure: ValidationFailure;
|
|
63
|
+
constructor(context: CallContext, failure: ValidationFailure);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* From `unwrap()` or `ok()`: a declared reply, but not one of the statuses
|
|
67
|
+
* asked for. No status asked for means any 2xx.
|
|
68
|
+
*/
|
|
69
|
+
export declare class ReplyStatusError extends Error {
|
|
70
|
+
name: string;
|
|
71
|
+
readonly status: number;
|
|
72
|
+
readonly data: unknown;
|
|
73
|
+
readonly response: Response | undefined;
|
|
74
|
+
constructor(reply: {
|
|
75
|
+
status: number;
|
|
76
|
+
data: unknown;
|
|
77
|
+
response?: Response;
|
|
78
|
+
}, expected: readonly number[]);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"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AAI,SAAkB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIzE;AAED,sDAAsD;AACtD,qBAAa,qBAAsB,SAAQ,WAAW;IAC5C,IAAI,SAA2B;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;gBAEhB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ;CAKpD;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,WAAW;IACtC,IAAI,SAAqB;IAClC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;gBAExB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB;CAI5D;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACjC,IAAI,SAAsB;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;gBAGvC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,EAC7D,QAAQ,EAAE,SAAS,MAAM,EAAE;CAQ5B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { isAbortError } from './cancel/abort';
|
|
2
|
+
export { createHttpClient } from './client/create-http-client';
|
|
3
|
+
export type { ArgsFor, Call, CallOptions, EventsArgs, HttpClient, HttpClientOptions, HttpGroup, LinesArgs, Method, ReplyOptions, RequestArgs, RequestOptions, SendOptions, } from './client/types';
|
|
4
|
+
export { type CallContext, ClientError, NetworkError, ReplyStatusError, TimeoutError, UndeclaredStatusError, ValidationError, type ValidationFailure, type ValidationIssue, } from './errors/errors';
|
|
5
|
+
export type { AuthOptions } from './middleware/auth';
|
|
6
|
+
export { type Cache, type CacheOptions, cache } from './middleware/cache';
|
|
7
|
+
export type { Middleware, Next } from './middleware/compose';
|
|
8
|
+
export type { RetryOptions } from './middleware/retry';
|
|
9
|
+
export type { AnyReply, Declared, HttpReply, ReplyOf, Responses, SchemaData, WithResponse, } from './reply/types';
|
|
10
|
+
export { ok, type Success, unwrap } from './reply/unwrap';
|
|
11
|
+
export type { BodyInput, FormFields, ParamValue, PathInput, PathParamNames, QueryInput, QueryValue, RequestInput, } from './request/types';
|
|
12
|
+
export type { InferInput, InferOutput, StandardIssue, StandardResult, StandardSchemaV1, } from './schema/standard-schema';
|
|
13
|
+
export type { ServerEvent } from './stream/sse-parser';
|
|
14
|
+
export type { EventSchemas, EventStream, EventsOptions, LinesOptions, ReconnectOptions, Stream, StreamEvent, StreamItem, } from './stream/types';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EACX,OAAO,EACP,IAAI,EACJ,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,MAAM,EACN,YAAY,EACZ,WAAW,EACX,cAAc,EACd,WAAW,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,KAAK,WAAW,EAChB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,WAAW,EAAE,MAAM,mB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