@trpc/client 11.23.0 → 11.23.1-canary.14.507382d73
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/dist/{TRPCClientError-CxFRO7Js.mjs → TRPCClientError-Byo7P4QG.mjs} +14 -1
- package/dist/TRPCClientError-Byo7P4QG.mjs.map +1 -0
- package/dist/{TRPCClientError-CmHlBkPF.cjs → TRPCClientError-CPEwAI4E.cjs} +13 -0
- package/dist/{httpBatchLink-DPypDRI1.mjs → httpBatchLink-B-gQhW2d.mjs} +6 -3
- package/dist/httpBatchLink-B-gQhW2d.mjs.map +1 -0
- package/dist/httpBatchLink-CRRfyw0c.d.cts +46 -0
- package/dist/httpBatchLink-CRRfyw0c.d.cts.map +1 -0
- package/dist/httpBatchLink-DFDg8cHu.d.mts +46 -0
- package/dist/httpBatchLink-DFDg8cHu.d.mts.map +1 -0
- package/dist/{httpBatchLink-Cmao5uUF.cjs → httpBatchLink-DfpTwHVx.cjs} +5 -2
- package/dist/{httpLink-eSAq8J9S.d.mts → httpLink-Bc4oLWCJ.d.cts} +12 -5
- package/dist/httpLink-Bc4oLWCJ.d.cts.map +1 -0
- package/dist/{httpLink-B6E1HSLY.cjs → httpLink-CTrye8t0.cjs} +11 -2
- package/dist/{httpLink--yqaZ9lA.mjs → httpLink-D1jF9wdN.mjs} +12 -3
- package/dist/httpLink-D1jF9wdN.mjs.map +1 -0
- package/dist/{httpLink-D5FQijY2.d.cts → httpLink-yX9QPwni.d.mts} +12 -5
- package/dist/httpLink-yX9QPwni.d.mts.map +1 -0
- package/dist/httpUtils-j-oJ4G4z.d.cts +25 -0
- package/dist/httpUtils-j-oJ4G4z.d.cts.map +1 -0
- package/dist/{httpUtils-CrSF2CZF.cjs → httpUtils-os0q2Zvy.cjs} +4 -0
- package/dist/{httpUtils-CAZsqwOQ.mjs → httpUtils-ttfajAo5.mjs} +5 -1
- package/dist/httpUtils-ttfajAo5.mjs.map +1 -0
- package/dist/httpUtils-v7O5xeam.d.mts +25 -0
- package/dist/httpUtils-v7O5xeam.d.mts.map +1 -0
- package/dist/index.cjs +55 -16
- package/dist/index.d.cts +150 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +150 -26
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +55 -16
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.cjs +1 -1
- package/dist/links/httpBatchLink.d.cts +1 -1
- package/dist/links/httpBatchLink.d.mts +1 -1
- package/dist/links/httpBatchLink.mjs +1 -1
- package/dist/links/httpLink.cjs +1 -1
- package/dist/links/httpLink.d.cts +1 -1
- package/dist/links/httpLink.d.mts +1 -1
- package/dist/links/httpLink.mjs +1 -1
- package/dist/links/loggerLink.cjs +4 -1
- package/dist/links/loggerLink.d.cts +1 -1
- package/dist/links/loggerLink.d.mts +1 -1
- package/dist/links/loggerLink.mjs +4 -1
- package/dist/links/loggerLink.mjs.map +1 -1
- package/dist/links/splitLink.cjs +1 -1
- package/dist/links/splitLink.d.cts +1 -1
- package/dist/links/splitLink.d.mts +1 -1
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/wsLink/wsLink.cjs +1 -1
- package/dist/links/wsLink/wsLink.d.cts +1 -1
- package/dist/links/wsLink/wsLink.d.mts +1 -1
- package/dist/links/wsLink/wsLink.mjs +1 -1
- package/dist/{loggerLink-CFercTVc.d.mts → loggerLink-BEMtA7V5.d.cts} +20 -4
- package/dist/loggerLink-BEMtA7V5.d.cts.map +1 -0
- package/dist/{loggerLink-2o-uZ3r1.d.cts → loggerLink-Daki_B65.d.mts} +20 -4
- package/dist/loggerLink-Daki_B65.d.mts.map +1 -0
- package/dist/{splitLink-MXnaFlEb.cjs → splitLink-CL8W2Mit.cjs} +5 -0
- package/dist/{splitLink-BZPioDdG.mjs → splitLink-DcpFI5s5.mjs} +6 -1
- package/dist/splitLink-DcpFI5s5.mjs.map +1 -0
- package/dist/{splitLink-CJdcmEmS.d.cts → splitLink-i7EskO_m.d.cts} +10 -2
- package/dist/splitLink-i7EskO_m.d.cts.map +1 -0
- package/dist/{splitLink-CixmF14P.d.mts → splitLink-zyV5y7N1.d.mts} +10 -2
- package/dist/splitLink-zyV5y7N1.d.mts.map +1 -0
- package/dist/{types-BxbMkv6C.d.cts → types-BrCJd1zp.d.cts} +54 -6
- package/dist/types-BrCJd1zp.d.cts.map +1 -0
- package/dist/{types-CAPs7vhA.d.mts → types-DO-GCB2q.d.mts} +54 -6
- package/dist/types-DO-GCB2q.d.mts.map +1 -0
- package/dist/{unstable-internals-CE8gFBQ9.d.cts → unstable-internals-CNoyg7Yf.d.cts} +4 -4
- package/dist/{unstable-internals-CE8gFBQ9.d.cts.map → unstable-internals-CNoyg7Yf.d.cts.map} +1 -1
- package/dist/{unstable-internals-CE8gFBQ9.d.mts → unstable-internals-CNoyg7Yf.d.mts} +4 -4
- package/dist/{unstable-internals-CE8gFBQ9.d.mts.map → unstable-internals-CNoyg7Yf.d.mts.map} +1 -1
- package/dist/unstable-internals.d.cts +1 -1
- package/dist/unstable-internals.d.mts +1 -1
- package/dist/unstable-internals.mjs.map +1 -1
- package/dist/{wsLink-CQGBu_VZ.cjs → wsLink-Bl27m-y2.cjs} +18 -1
- package/dist/{wsLink--7trqYPG.mjs → wsLink-CDaUjHvu.mjs} +19 -2
- package/dist/wsLink-CDaUjHvu.mjs.map +1 -0
- package/dist/{wsLink-DnvK9sTv.d.mts → wsLink-CEgNu9Gj.d.mts} +39 -5
- package/dist/wsLink-CEgNu9Gj.d.mts.map +1 -0
- package/dist/{wsLink-C3hsDLsL.d.cts → wsLink-DZr_cFFg.d.cts} +39 -5
- package/dist/wsLink-DZr_cFFg.d.cts.map +1 -0
- package/package.json +4 -4
- package/skills/client-setup/SKILL.md +1 -1
- package/skills/links/SKILL.md +1 -1
- package/skills/superjson/SKILL.md +1 -1
- package/src/TRPCClientError.ts +27 -2
- package/src/createTRPCClient.ts +38 -7
- package/src/createTRPCUntypedClient.ts +4 -0
- package/src/getFetch.ts +4 -0
- package/src/internals/TRPCUntypedClient.ts +33 -2
- package/src/internals/transformer.ts +3 -3
- package/src/internals/types.ts +9 -1
- package/src/links/HTTPBatchLinkOptions.ts +17 -3
- package/src/links/httpBatchLink.ts +3 -0
- package/src/links/httpBatchStreamLink.ts +10 -1
- package/src/links/httpLink.ts +9 -2
- package/src/links/httpSubscriptionLink.ts +10 -3
- package/src/links/internals/contentTypes.ts +7 -0
- package/src/links/internals/httpUtils.ts +6 -4
- package/src/links/internals/urlWithConnectionParams.ts +1 -0
- package/src/links/localLink.ts +22 -3
- package/src/links/loggerLink.ts +18 -2
- package/src/links/retryLink.ts +4 -1
- package/src/links/splitLink.ts +8 -0
- package/src/links/types.ts +17 -2
- package/src/links/wsLink/createWsClient.ts +9 -0
- package/src/links/wsLink/wsClient/encoder.ts +3 -0
- package/src/links/wsLink/wsClient/options.ts +7 -2
- package/src/links/wsLink/wsClient/wsClient.ts +3 -0
- package/src/links/wsLink/wsLink.ts +13 -0
- package/src/safe.ts +11 -2
- package/dist/TRPCClientError-CxFRO7Js.mjs.map +0 -1
- package/dist/httpBatchLink-Br-pzPXf.d.cts +0 -29
- package/dist/httpBatchLink-Br-pzPXf.d.cts.map +0 -1
- package/dist/httpBatchLink-DPypDRI1.mjs.map +0 -1
- package/dist/httpBatchLink-nvc48L_N.d.mts +0 -29
- package/dist/httpBatchLink-nvc48L_N.d.mts.map +0 -1
- package/dist/httpLink--yqaZ9lA.mjs.map +0 -1
- package/dist/httpLink-D5FQijY2.d.cts.map +0 -1
- package/dist/httpLink-eSAq8J9S.d.mts.map +0 -1
- package/dist/httpUtils-C37jRVnj.d.mts +0 -23
- package/dist/httpUtils-C37jRVnj.d.mts.map +0 -1
- package/dist/httpUtils-CAZsqwOQ.mjs.map +0 -1
- package/dist/httpUtils-CUqAubVD.d.cts +0 -23
- package/dist/httpUtils-CUqAubVD.d.cts.map +0 -1
- package/dist/loggerLink-2o-uZ3r1.d.cts.map +0 -1
- package/dist/loggerLink-CFercTVc.d.mts.map +0 -1
- package/dist/splitLink-BZPioDdG.mjs.map +0 -1
- package/dist/splitLink-CJdcmEmS.d.cts.map +0 -1
- package/dist/splitLink-CixmF14P.d.mts.map +0 -1
- package/dist/types-BxbMkv6C.d.cts.map +0 -1
- package/dist/types-CAPs7vhA.d.mts.map +0 -1
- package/dist/wsLink--7trqYPG.mjs.map +0 -1
- package/dist/wsLink-C3hsDLsL.d.cts.map +0 -1
- package/dist/wsLink-DnvK9sTv.d.mts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,42 +1,77 @@
|
|
|
1
1
|
import { t as TRPCConnectionState } from "./subscriptions-DcqRZc4h.mjs";
|
|
2
|
-
import { a as OperationResultEnvelope, c as TRPCClientRuntime, d as TRPCClientError, f as TRPCClientErrorBase, g as NativeFetchEsque, h as FetchEsque, i as OperationLink, l as TRPCFetch, m as isTRPCClientError, n as Operation, o as OperationResultObservable, p as TRPCClientErrorLike, r as OperationContext, s as OperationResultObserver, t as HTTPHeaders, u as TRPCLink, v as TRPCProcedureOptions } from "./types-
|
|
3
|
-
import { n as TransformerOptions } from "./unstable-internals-
|
|
4
|
-
import { n as HTTPBatchLinkOptions, t as httpBatchLink } from "./httpBatchLink-
|
|
5
|
-
import { n as httpLink, t as HTTPLinkOptions } from "./httpLink-
|
|
6
|
-
import { n as loggerLink, t as LoggerLinkOptions } from "./loggerLink-
|
|
7
|
-
import { t as splitLink } from "./splitLink-
|
|
8
|
-
import { a as WebSocketClientOptions, c as jsonEncoder, i as createWSClient, n as wsLink, o as UrlOptionsWithConnectionParams, r as TRPCWebSocketClient, s as Encoder, t as WebSocketLinkOptions } from "./wsLink-
|
|
2
|
+
import { a as OperationResultEnvelope, c as TRPCClientRuntime, d as TRPCClientError, f as TRPCClientErrorBase, g as NativeFetchEsque, h as FetchEsque, i as OperationLink, l as TRPCFetch, m as isTRPCClientError, n as Operation, o as OperationResultObservable, p as TRPCClientErrorLike, r as OperationContext, s as OperationResultObserver, t as HTTPHeaders, u as TRPCLink, v as TRPCProcedureOptions } from "./types-DO-GCB2q.mjs";
|
|
3
|
+
import { n as TransformerOptions } from "./unstable-internals-CNoyg7Yf.mjs";
|
|
4
|
+
import { n as HTTPBatchLinkOptions, t as httpBatchLink } from "./httpBatchLink-DFDg8cHu.mjs";
|
|
5
|
+
import { n as httpLink, t as HTTPLinkOptions } from "./httpLink-yX9QPwni.mjs";
|
|
6
|
+
import { n as loggerLink, t as LoggerLinkOptions } from "./loggerLink-Daki_B65.mjs";
|
|
7
|
+
import { t as splitLink } from "./splitLink-zyV5y7N1.mjs";
|
|
8
|
+
import { a as WebSocketClientOptions, c as jsonEncoder, i as createWSClient, n as wsLink, o as UrlOptionsWithConnectionParams, r as TRPCWebSocketClient, s as Encoder, t as WebSocketLinkOptions } from "./wsLink-CEgNu9Gj.mjs";
|
|
9
9
|
import { Unsubscribable } from "@trpc/server/observable";
|
|
10
10
|
import { AnyClientTypes, AnyProcedure, AnyRouter, ErrorHandlerOptions, EventSourceLike, InferrableClientTypes, ProcedureType, RouterRecord, TypeError, inferAsyncIterableYield, inferClientTypes, inferProcedureErrorShape, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
|
|
11
11
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
12
12
|
//#region src/links/internals/contentTypes.d.ts
|
|
13
|
+
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
13
14
|
export declare function isOctetType(input: unknown): input is Uint8Array<ArrayBuffer> | Blob;
|
|
15
|
+
/** Whether an input is `FormData`. */
|
|
14
16
|
export declare function isFormData(input: unknown): input is FormData;
|
|
17
|
+
/**
|
|
18
|
+
* Whether an input can't be sent as JSON: binary data or `FormData`. Use
|
|
19
|
+
* it in a `splitLink` to send such inputs with `httpLink`.
|
|
20
|
+
* @see https://trpc.io/docs/server/non-json-content-types#client-setup
|
|
21
|
+
*/
|
|
15
22
|
export declare function isNonJsonSerializable(input: unknown): input is Blob | FormData | Uint8Array<ArrayBuffer>;
|
|
16
23
|
//#endregion
|
|
17
24
|
//#region src/internals/TRPCUntypedClient.d.ts
|
|
25
|
+
/** The options of a call made with the untyped client. */
|
|
18
26
|
interface TRPCRequestOptions {
|
|
19
27
|
/**
|
|
20
|
-
*
|
|
28
|
+
* Context for the links, such as a flag a `splitLink` reads.
|
|
29
|
+
* @see https://trpc.io/docs/client/links#managing-context
|
|
21
30
|
*/
|
|
22
31
|
context?: OperationContext;
|
|
32
|
+
/**
|
|
33
|
+
* Aborts the call. With `httpBatchLink`, the request is only aborted once
|
|
34
|
+
* every call in its batch is, so an aborted call can still get a result.
|
|
35
|
+
*/
|
|
23
36
|
signal?: AbortSignal;
|
|
24
37
|
}
|
|
38
|
+
/** The callbacks a subscription takes on the client. */
|
|
25
39
|
interface TRPCSubscriptionObserver<TValue, TError> {
|
|
40
|
+
/** Called when the link sends a `started` result. */
|
|
26
41
|
onStarted: (opts: {
|
|
27
42
|
context: OperationContext | undefined;
|
|
28
43
|
}) => void;
|
|
44
|
+
/** Called with each event. */
|
|
29
45
|
onData: (value: inferAsyncIterableYield<TValue>) => void;
|
|
46
|
+
/** Called when the subscription ends with an error. */
|
|
30
47
|
onError: (err: TError) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Called when the link sends a `stopped` result. Not every link sends
|
|
50
|
+
* one; `localLink` doesn't.
|
|
51
|
+
*/
|
|
31
52
|
onStopped: () => void;
|
|
53
|
+
/** Called when the subscription's observable completes, for any reason. */
|
|
32
54
|
onComplete: () => void;
|
|
55
|
+
/** Called when the connection connects, drops or reconnects. */
|
|
33
56
|
onConnectionStateChange: (state: TRPCConnectionState<TError>) => void;
|
|
34
57
|
}
|
|
35
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* The options of `createTRPCClient`.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
36
62
|
type CreateTRPCClientOptions<TRouter extends InferrableClientTypes> = {
|
|
63
|
+
/**
|
|
64
|
+
* The links each call goes through, in order. The last one must send
|
|
65
|
+
* the call, such as `httpBatchLink`.
|
|
66
|
+
* @see https://trpc.io/docs/client/links
|
|
67
|
+
*/
|
|
37
68
|
links: TRPCLink<TRouter>[];
|
|
38
69
|
transformer?: TypeError<'The transformer property has moved to httpLink/httpBatchLink/wsLink'>;
|
|
39
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* A client that calls procedures by path string, without types.
|
|
73
|
+
* `createTRPCClient` wraps one.
|
|
74
|
+
*/
|
|
40
75
|
export declare class TRPCUntypedClient<TInferrable extends InferrableClientTypes> {
|
|
41
76
|
private readonly links;
|
|
42
77
|
readonly runtime: TRPCClientRuntime;
|
|
@@ -44,12 +79,19 @@ export declare class TRPCUntypedClient<TInferrable extends InferrableClientTypes
|
|
|
44
79
|
constructor(opts: CreateTRPCClientOptions<TInferrable>);
|
|
45
80
|
private $request;
|
|
46
81
|
private requestAsPromise;
|
|
82
|
+
/** Calls a query. */
|
|
47
83
|
query(path: string, input?: unknown, opts?: TRPCRequestOptions): Promise<unknown>;
|
|
84
|
+
/** Calls a mutation. */
|
|
48
85
|
mutation(path: string, input?: unknown, opts?: TRPCRequestOptions): Promise<unknown>;
|
|
86
|
+
/** Starts a subscription. Returns what stops it. */
|
|
49
87
|
subscription(path: string, input: unknown, opts: Partial<TRPCSubscriptionObserver<unknown, TRPCClientError<AnyRouter>>> & TRPCRequestOptions): Unsubscribable;
|
|
50
88
|
}
|
|
51
89
|
//#endregion
|
|
52
90
|
//#region src/createTRPCUntypedClient.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* Creates a client that calls procedures by path string, without types.
|
|
93
|
+
* Meant for libraries built on tRPC; apps should use `createTRPCClient`.
|
|
94
|
+
*/
|
|
53
95
|
export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCUntypedClient<TRouter>;
|
|
54
96
|
//#endregion
|
|
55
97
|
//#region src/safe.d.ts
|
|
@@ -57,6 +99,10 @@ export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts:
|
|
|
57
99
|
* @internal
|
|
58
100
|
*/
|
|
59
101
|
declare const errorShapeTag: unique symbol;
|
|
102
|
+
/**
|
|
103
|
+
* The promise a client's `.query()` or `.mutate()` returns, tagged with
|
|
104
|
+
* the procedure's error shape for `safe()`.
|
|
105
|
+
*/
|
|
60
106
|
type TRPCTaggedPromise<TData, TErrorShape> = Promise<TData> & {
|
|
61
107
|
readonly [errorShapeTag]: TErrorShape;
|
|
62
108
|
};
|
|
@@ -67,10 +113,14 @@ type inferSafeError<TErrorShape> = TRPCClientError<{
|
|
|
67
113
|
errorShape: TErrorShape;
|
|
68
114
|
transformer: boolean;
|
|
69
115
|
}>;
|
|
116
|
+
/**
|
|
117
|
+
* What `safe()` resolves to: `[data, undefined]` or `[undefined, error]`.
|
|
118
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling#errors-as-values-with-safe
|
|
119
|
+
*/
|
|
70
120
|
type SafeResult<TData, TErrorShape> = readonly [data: TData, error: undefined] | readonly [data: undefined, error: inferSafeError<TErrorShape>];
|
|
71
121
|
/**
|
|
72
|
-
*
|
|
73
|
-
* `[data, error]` pair typed with
|
|
122
|
+
* Awaits a client `.query()` or `.mutate()` call without throwing, and
|
|
123
|
+
* returns a `[data, error]` pair typed with the procedure's error shape.
|
|
74
124
|
*
|
|
75
125
|
* @example
|
|
76
126
|
* ```ts
|
|
@@ -81,22 +131,28 @@ type SafeResult<TData, TErrorShape> = readonly [data: TData, error: undefined] |
|
|
|
81
131
|
*
|
|
82
132
|
* const id = post.id;
|
|
83
133
|
* ```
|
|
134
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling#errors-as-values-with-safe
|
|
84
135
|
*/
|
|
85
136
|
export declare function safe<TData, TErrorShape>(promise: TRPCTaggedPromise<TData, TErrorShape>): Promise<SafeResult<TData, TErrorShape>>;
|
|
86
137
|
//#endregion
|
|
87
138
|
//#region src/createTRPCClient.d.ts
|
|
88
139
|
/**
|
|
140
|
+
* The type of a client for a router.
|
|
141
|
+
* @deprecated Use {@link TRPCClient} instead. This will be removed in v12.
|
|
89
142
|
* @public
|
|
90
|
-
* @deprecated use {@link TRPCClient} instead, will be removed in v12
|
|
91
143
|
**/
|
|
92
144
|
export type inferRouterClient<TRouter extends AnyRouter> = TRPCClient<TRouter>;
|
|
93
145
|
/**
|
|
146
|
+
* The type of a client for a router.
|
|
147
|
+
* @deprecated Use {@link TRPCClient} instead. This will be removed in v12.
|
|
94
148
|
* @public
|
|
95
|
-
* @deprecated use {@link TRPCClient} instead, will be removed in v12
|
|
96
149
|
**/
|
|
97
150
|
export type CreateTRPCClient<TRouter extends AnyRouter> = TRPCClient<TRouter>;
|
|
98
151
|
declare const untypedClientSymbol: unique symbol;
|
|
99
152
|
/**
|
|
153
|
+
* A typed client for a router, as `createTRPCClient` returns it. Each
|
|
154
|
+
* procedure has `.query()`, `.mutate()` or `.subscribe()`.
|
|
155
|
+
* @see https://trpc.io/docs/client/vanilla/infer-types
|
|
100
156
|
* @public
|
|
101
157
|
**/
|
|
102
158
|
export type TRPCClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<{
|
|
@@ -105,7 +161,10 @@ export type TRPCClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<{
|
|
|
105
161
|
}, TRouter['_def']['record']> & {
|
|
106
162
|
[untypedClientSymbol]: TRPCUntypedClient<TRouter>;
|
|
107
163
|
};
|
|
108
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* A procedure's types, as the client sees them.
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
109
168
|
export type TRPCResolverDef = {
|
|
110
169
|
input: any;
|
|
111
170
|
output: any;
|
|
@@ -113,9 +172,15 @@ export type TRPCResolverDef = {
|
|
|
113
172
|
errorShape: any;
|
|
114
173
|
};
|
|
115
174
|
type coerceAsyncGeneratorToIterable<T> = T extends AsyncGenerator<infer $T, infer $Return, infer $Next> ? AsyncIterable<$T, $Return, $Next> : T;
|
|
116
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* The `.query()` or `.mutate()` of a procedure on the client.
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
117
179
|
export type Resolver<TDef extends TRPCResolverDef> = (input: TDef['input'], opts?: TRPCProcedureOptions) => TRPCTaggedPromise<coerceAsyncGeneratorToIterable<TDef['output']>, TDef['errorShape']>;
|
|
118
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* The `.subscribe()` of a subscription procedure on the client.
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
119
184
|
export type SubscriptionResolver<TDef extends TRPCResolverDef> = (input: TDef['input'], opts: Partial<TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>> & TRPCProcedureOptions) => Unsubscribable;
|
|
120
185
|
type DecorateProcedure<TType extends ProcedureType, TDef extends TRPCResolverDef> = TType extends 'query' ? {
|
|
121
186
|
query: Resolver<TDef>;
|
|
@@ -133,23 +198,50 @@ type DecoratedProcedureRecord<TRoot extends InferrableClientTypes, TRecord exten
|
|
|
133
198
|
errorShape: inferProcedureErrorShape<TRoot, $Value>;
|
|
134
199
|
transformer: inferClientTypes<TRoot>['transformer'];
|
|
135
200
|
}> : $Value extends RouterRecord ? DecoratedProcedureRecord<TRoot, $Value> : never : never; };
|
|
136
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* The procedure type of a client method: `query`, `mutate` or `subscribe`.
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
137
205
|
export declare const clientCallTypeToProcedureType: (clientCallType: string) => ProcedureType;
|
|
138
206
|
/**
|
|
207
|
+
* Wraps an untyped client in the typed proxy `createTRPCClient` returns.
|
|
139
208
|
* @internal
|
|
140
209
|
*/
|
|
141
210
|
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): TRPCClient<TRouter>;
|
|
211
|
+
/**
|
|
212
|
+
* Creates a typed client for a router. Pass the router's type, and the
|
|
213
|
+
* links that send its calls.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const client = createTRPCClient<AppRouter>({
|
|
217
|
+
* links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
|
|
218
|
+
* });
|
|
219
|
+
* const post = await client.post.byId.query({ id: '1' });
|
|
220
|
+
* ```
|
|
221
|
+
* @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
|
|
222
|
+
*/
|
|
142
223
|
export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCClient<TRouter>;
|
|
143
224
|
/**
|
|
144
|
-
*
|
|
225
|
+
* The untyped client behind a typed client, which calls procedures by
|
|
226
|
+
* path string.
|
|
145
227
|
* @internal
|
|
146
228
|
*/
|
|
147
229
|
export declare function getUntypedClient<TRouter extends AnyRouter>(client: TRPCClient<TRouter>): TRPCUntypedClient<TRouter>;
|
|
148
230
|
//#endregion
|
|
149
231
|
//#region src/getFetch.d.ts
|
|
232
|
+
/**
|
|
233
|
+
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
234
|
+
* Throws if there's none.
|
|
235
|
+
*/
|
|
150
236
|
export declare function getFetch(customFetchImpl?: FetchEsque | NativeFetchEsque): FetchEsque;
|
|
151
237
|
//#endregion
|
|
152
238
|
//#region src/links/httpBatchStreamLink.d.ts
|
|
239
|
+
/**
|
|
240
|
+
* Options for {@link httpBatchStreamLink}. Takes the same options as
|
|
241
|
+
* `httpBatchLink`, plus `streamHeader`.
|
|
242
|
+
*
|
|
243
|
+
* @see https://trpc.io/docs/client/links/httpBatchStreamLink#options
|
|
244
|
+
*/
|
|
153
245
|
export type HTTPBatchStreamLinkOptions<TRoot extends AnyClientTypes> = HTTPBatchLinkOptions<TRoot> & {
|
|
154
246
|
/**
|
|
155
247
|
* Which header to use to signal the server that the client wants a streaming response.
|
|
@@ -160,33 +252,43 @@ export type HTTPBatchStreamLinkOptions<TRoot extends AnyClientTypes> = HTTPBatch
|
|
|
160
252
|
streamHeader?: 'trpc-accept' | 'accept';
|
|
161
253
|
};
|
|
162
254
|
/**
|
|
255
|
+
* A terminating link that batches calls like `httpBatchLink`, but streams each
|
|
256
|
+
* response back as soon as it is ready.
|
|
257
|
+
*
|
|
163
258
|
* @see https://trpc.io/docs/client/links/httpBatchStreamLink
|
|
164
259
|
*/
|
|
165
260
|
export declare function httpBatchStreamLink<TRouter extends AnyRouter$1>(opts: HTTPBatchStreamLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
166
261
|
/**
|
|
167
|
-
* @deprecated
|
|
262
|
+
* @deprecated Use {@link httpBatchStreamLink} instead.
|
|
168
263
|
*/
|
|
169
264
|
export declare const unstable_httpBatchStreamLink: typeof httpBatchStreamLink;
|
|
170
265
|
//#endregion
|
|
171
266
|
//#region src/links/httpSubscriptionLink.d.ts
|
|
267
|
+
/**
|
|
268
|
+
* @see https://trpc.io/docs/client/links/httpSubscriptionLink#httpsubscriptionlink-options
|
|
269
|
+
*/
|
|
172
270
|
type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes, TEventSource extends EventSourceLike.AnyConstructor = typeof EventSource> = {
|
|
173
271
|
/**
|
|
174
|
-
* EventSource
|
|
272
|
+
* The `EventSource` class to use, for runtimes that don't have one.
|
|
273
|
+
* @see https://trpc.io/docs/client/links/httpSubscriptionLink#custom-headers-through-ponyfill
|
|
175
274
|
*/
|
|
176
275
|
EventSource?: TEventSource;
|
|
177
276
|
/**
|
|
178
|
-
* EventSource
|
|
277
|
+
* Options passed to the `EventSource`, or a function that returns them for
|
|
278
|
+
* each subscription.
|
|
179
279
|
*/
|
|
180
280
|
eventSourceOptions?: EventSourceLike.InitDictOf<TEventSource> | ((opts: {
|
|
181
281
|
op: Operation;
|
|
182
282
|
}) => EventSourceLike.InitDictOf<TEventSource> | Promise<EventSourceLike.InitDictOf<TEventSource>>);
|
|
183
283
|
} & TransformerOptions<TRoot> & UrlOptionsWithConnectionParams;
|
|
184
284
|
/**
|
|
285
|
+
* A terminating link that runs subscriptions over Server-Sent Events.
|
|
286
|
+
*
|
|
185
287
|
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
186
288
|
*/
|
|
187
289
|
export declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable>;
|
|
188
290
|
/**
|
|
189
|
-
* @deprecated
|
|
291
|
+
* @deprecated Use {@link httpSubscriptionLink} instead.
|
|
190
292
|
*/
|
|
191
293
|
export declare const unstable_httpSubscriptionLink: typeof httpSubscriptionLink;
|
|
192
294
|
//#endregion
|
|
@@ -216,29 +318,51 @@ interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
|
|
|
216
318
|
attempts: number;
|
|
217
319
|
}
|
|
218
320
|
/**
|
|
219
|
-
*
|
|
321
|
+
* Retries failed operations. Subscriptions resume from the last tracked event
|
|
322
|
+
* id.
|
|
323
|
+
*
|
|
324
|
+
* @see https://trpc.io/docs/client/links/retryLink
|
|
220
325
|
*/
|
|
221
326
|
export declare function retryLink<TInferrable extends InferrableClientTypes>(opts: RetryLinkOptions<TInferrable>): TRPCLink<TInferrable>;
|
|
222
327
|
//#endregion
|
|
223
328
|
//#region src/links/localLink.d.ts
|
|
329
|
+
/**
|
|
330
|
+
* Options for {@link localLink}.
|
|
331
|
+
*
|
|
332
|
+
* @see https://trpc.io/docs/client/links/localLink#options
|
|
333
|
+
*/
|
|
224
334
|
export type LocalLinkOptions<TRouter extends AnyRouter> = {
|
|
335
|
+
/**
|
|
336
|
+
* The router to call.
|
|
337
|
+
* @see https://trpc.io/docs/client/links/localLink#router
|
|
338
|
+
*/
|
|
225
339
|
router: TRouter;
|
|
340
|
+
/**
|
|
341
|
+
* Creates the context for each call.
|
|
342
|
+
* @see https://trpc.io/docs/client/links/localLink#createcontext
|
|
343
|
+
*/
|
|
226
344
|
createContext: () => Promise<inferRouterContext<TRouter>>;
|
|
345
|
+
/**
|
|
346
|
+
* Called when a procedure throws.
|
|
347
|
+
* @see https://trpc.io/docs/client/links/localLink#onerror
|
|
348
|
+
*/
|
|
227
349
|
onError?: (opts: ErrorHandlerOptions<inferRouterContext<TRouter>>) => void;
|
|
228
350
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
229
351
|
/**
|
|
230
|
-
*
|
|
352
|
+
* A terminating link that calls procedures on a router in the same process,
|
|
353
|
+
* without HTTP.
|
|
231
354
|
*
|
|
232
355
|
* @see https://trpc.io/docs/client/links/localLink
|
|
233
356
|
*/
|
|
234
357
|
export declare function localLink<TRouter extends AnyRouter>(opts: LocalLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
235
358
|
/**
|
|
236
|
-
* @deprecated
|
|
359
|
+
* @deprecated Use {@link localLink} instead.
|
|
237
360
|
* @function
|
|
238
361
|
*/
|
|
239
362
|
export declare const unstable_localLink: typeof localLink;
|
|
240
363
|
/**
|
|
241
|
-
* @deprecated
|
|
364
|
+
* @deprecated Use {@link localLink} instead. This alias will be removed in a
|
|
365
|
+
* future major release.
|
|
242
366
|
*/
|
|
243
367
|
export declare const experimental_localLink: typeof localLink;
|
|
244
368
|
//#endregion
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/links/internals/contentTypes.ts","../src/internals/TRPCUntypedClient.ts","../src/createTRPCUntypedClient.ts","../src/safe.ts","../src/createTRPCClient.ts","../src/getFetch.ts","../src/links/httpBatchStreamLink.ts","../src/links/httpSubscriptionLink.ts","../src/links/retryLink.ts","../src/links/localLink.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/links/internals/contentTypes.ts","../src/internals/TRPCUntypedClient.ts","../src/createTRPCUntypedClient.ts","../src/safe.ts","../src/createTRPCClient.ts","../src/getFetch.ts","../src/links/httpBatchStreamLink.ts","../src/links/httpSubscriptionLink.ts","../src/links/retryLink.ts","../src/links/localLink.ts"],"mappings":"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"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { n as createChain, t as splitLink } from "./splitLink-
|
|
1
|
+
import { n as createChain, t as splitLink } from "./splitLink-DcpFI5s5.mjs";
|
|
2
2
|
import { n as _defineProperty, t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
3
|
-
import { n as isTRPCClientError, t as TRPCClientError } from "./TRPCClientError-
|
|
4
|
-
import { c as allAbortSignals, l as raceAbortSignals, n as getBody, o as resolveHTTPLinkOptions, r as getUrl, s as abortSignalToPromise, t as fetchHTTPResponse, u as getFetch } from "./httpUtils-
|
|
5
|
-
import { i as isOctetType, n as isFormData, r as isNonJsonSerializable, t as httpLink } from "./httpLink
|
|
6
|
-
import { n as dataLoader, t as httpBatchLink } from "./httpBatchLink-
|
|
3
|
+
import { n as isTRPCClientError, t as TRPCClientError } from "./TRPCClientError-Byo7P4QG.mjs";
|
|
4
|
+
import { c as allAbortSignals, l as raceAbortSignals, n as getBody, o as resolveHTTPLinkOptions, r as getUrl, s as abortSignalToPromise, t as fetchHTTPResponse, u as getFetch } from "./httpUtils-ttfajAo5.mjs";
|
|
5
|
+
import { i as isOctetType, n as isFormData, r as isNonJsonSerializable, t as httpLink } from "./httpLink-D1jF9wdN.mjs";
|
|
6
|
+
import { n as dataLoader, t as httpBatchLink } from "./httpBatchLink-B-gQhW2d.mjs";
|
|
7
7
|
import { getTransformer } from "./unstable-internals.mjs";
|
|
8
8
|
import { loggerLink } from "./links/loggerLink.mjs";
|
|
9
|
-
import { i as jsonEncoder, n as createWSClient, r as resultOf, t as wsLink } from "./wsLink
|
|
9
|
+
import { i as jsonEncoder, n as createWSClient, r as resultOf, t as wsLink } from "./wsLink-CDaUjHvu.mjs";
|
|
10
10
|
import { behaviorSubject, observable, observableToPromise, share } from "@trpc/server/observable";
|
|
11
11
|
import { callProcedure, createFlatProxy, createRecursiveProxy, isAbortError, isAsyncIterable, iteratorResource, jsonlStreamConsumer, makeResource, retryableRpcCodes, run, sseStreamConsumer } from "@trpc/server/unstable-core-do-not-import";
|
|
12
12
|
import { getTRPCErrorFromUnknown, getTRPCErrorShape, isTrackedEnvelope } from "@trpc/server";
|
|
13
13
|
import { TRPC_ERROR_CODES_BY_KEY } from "@trpc/server/rpc";
|
|
14
14
|
//#region src/internals/TRPCUntypedClient.ts
|
|
15
|
+
/**
|
|
16
|
+
* A client that calls procedures by path string, without types.
|
|
17
|
+
* `createTRPCClient` wraps one.
|
|
18
|
+
*/
|
|
15
19
|
var TRPCUntypedClient = class {
|
|
16
20
|
constructor(opts) {
|
|
17
21
|
_defineProperty(this, "links", void 0);
|
|
@@ -39,6 +43,7 @@ var TRPCUntypedClient = class {
|
|
|
39
43
|
throw TRPCClientError.from(err);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
46
|
+
/** Calls a query. */
|
|
42
47
|
query(path, input, opts) {
|
|
43
48
|
return this.requestAsPromise({
|
|
44
49
|
type: "query",
|
|
@@ -48,6 +53,7 @@ var TRPCUntypedClient = class {
|
|
|
48
53
|
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
49
54
|
});
|
|
50
55
|
}
|
|
56
|
+
/** Calls a mutation. */
|
|
51
57
|
mutation(path, input, opts) {
|
|
52
58
|
return this.requestAsPromise({
|
|
53
59
|
type: "mutation",
|
|
@@ -57,6 +63,7 @@ var TRPCUntypedClient = class {
|
|
|
57
63
|
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
58
64
|
});
|
|
59
65
|
}
|
|
66
|
+
/** Starts a subscription. Returns what stops it. */
|
|
60
67
|
subscription(path, input, opts) {
|
|
61
68
|
return this.$request({
|
|
62
69
|
type: "subscription",
|
|
@@ -98,6 +105,10 @@ var TRPCUntypedClient = class {
|
|
|
98
105
|
};
|
|
99
106
|
//#endregion
|
|
100
107
|
//#region src/createTRPCUntypedClient.ts
|
|
108
|
+
/**
|
|
109
|
+
* Creates a client that calls procedures by path string, without types.
|
|
110
|
+
* Meant for libraries built on tRPC; apps should use `createTRPCClient`.
|
|
111
|
+
*/
|
|
101
112
|
function createTRPCUntypedClient(opts) {
|
|
102
113
|
return new TRPCUntypedClient(opts);
|
|
103
114
|
}
|
|
@@ -109,11 +120,15 @@ const clientCallTypeMap = {
|
|
|
109
120
|
mutate: "mutation",
|
|
110
121
|
subscribe: "subscription"
|
|
111
122
|
};
|
|
112
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* The procedure type of a client method: `query`, `mutate` or `subscribe`.
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
113
127
|
const clientCallTypeToProcedureType = (clientCallType) => {
|
|
114
128
|
return clientCallTypeMap[clientCallType];
|
|
115
129
|
};
|
|
116
130
|
/**
|
|
131
|
+
* Wraps an untyped client in the typed proxy `createTRPCClient` returns.
|
|
117
132
|
* @internal
|
|
118
133
|
*/
|
|
119
134
|
function createTRPCClientProxy(client) {
|
|
@@ -128,11 +143,24 @@ function createTRPCClientProxy(client) {
|
|
|
128
143
|
return proxy[key];
|
|
129
144
|
});
|
|
130
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a typed client for a router. Pass the router's type, and the
|
|
148
|
+
* links that send its calls.
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const client = createTRPCClient<AppRouter>({
|
|
152
|
+
* links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
|
|
153
|
+
* });
|
|
154
|
+
* const post = await client.post.byId.query({ id: '1' });
|
|
155
|
+
* ```
|
|
156
|
+
* @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
|
|
157
|
+
*/
|
|
131
158
|
function createTRPCClient(opts) {
|
|
132
159
|
return createTRPCClientProxy(new TRPCUntypedClient(opts));
|
|
133
160
|
}
|
|
134
161
|
/**
|
|
135
|
-
*
|
|
162
|
+
* The untyped client behind a typed client, which calls procedures by
|
|
163
|
+
* path string.
|
|
136
164
|
* @internal
|
|
137
165
|
*/
|
|
138
166
|
function getUntypedClient(client) {
|
|
@@ -141,6 +169,9 @@ function getUntypedClient(client) {
|
|
|
141
169
|
//#endregion
|
|
142
170
|
//#region src/links/httpBatchStreamLink.ts
|
|
143
171
|
/**
|
|
172
|
+
* A terminating link that batches calls like `httpBatchLink`, but streams each
|
|
173
|
+
* response back as soon as it is ready.
|
|
174
|
+
*
|
|
144
175
|
* @see https://trpc.io/docs/client/links/httpBatchStreamLink
|
|
145
176
|
*/
|
|
146
177
|
function httpBatchStreamLink(opts) {
|
|
@@ -259,7 +290,7 @@ function httpBatchStreamLink(opts) {
|
|
|
259
290
|
};
|
|
260
291
|
}
|
|
261
292
|
/**
|
|
262
|
-
* @deprecated
|
|
293
|
+
* @deprecated Use {@link httpBatchStreamLink} instead.
|
|
263
294
|
*/
|
|
264
295
|
const unstable_httpBatchStreamLink = httpBatchStreamLink;
|
|
265
296
|
//#endregion
|
|
@@ -324,6 +355,8 @@ async function urlWithConnectionParams(opts) {
|
|
|
324
355
|
return url;
|
|
325
356
|
}
|
|
326
357
|
/**
|
|
358
|
+
* A terminating link that runs subscriptions over Server-Sent Events.
|
|
359
|
+
*
|
|
327
360
|
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
328
361
|
*/
|
|
329
362
|
function httpSubscriptionLink(opts) {
|
|
@@ -455,14 +488,17 @@ function httpSubscriptionLink(opts) {
|
|
|
455
488
|
};
|
|
456
489
|
}
|
|
457
490
|
/**
|
|
458
|
-
* @deprecated
|
|
491
|
+
* @deprecated Use {@link httpSubscriptionLink} instead.
|
|
459
492
|
*/
|
|
460
493
|
const unstable_httpSubscriptionLink = httpSubscriptionLink;
|
|
461
494
|
//#endregion
|
|
462
495
|
//#region src/links/retryLink.ts
|
|
463
496
|
/* istanbul ignore file -- @preserve */
|
|
464
497
|
/**
|
|
465
|
-
*
|
|
498
|
+
* Retries failed operations. Subscriptions resume from the last tracked event
|
|
499
|
+
* id.
|
|
500
|
+
*
|
|
501
|
+
* @see https://trpc.io/docs/client/links/retryLink
|
|
466
502
|
*/
|
|
467
503
|
function retryLink(opts) {
|
|
468
504
|
return () => {
|
|
@@ -659,7 +695,8 @@ AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator ||
|
|
|
659
695
|
//#endregion
|
|
660
696
|
//#region src/links/localLink.ts
|
|
661
697
|
/**
|
|
662
|
-
*
|
|
698
|
+
* A terminating link that calls procedures on a router in the same process,
|
|
699
|
+
* without HTTP.
|
|
663
700
|
*
|
|
664
701
|
* @see https://trpc.io/docs/client/links/localLink
|
|
665
702
|
*/
|
|
@@ -835,19 +872,20 @@ function localLink(opts) {
|
|
|
835
872
|
});
|
|
836
873
|
}
|
|
837
874
|
/**
|
|
838
|
-
* @deprecated
|
|
875
|
+
* @deprecated Use {@link localLink} instead.
|
|
839
876
|
* @function
|
|
840
877
|
*/
|
|
841
878
|
const unstable_localLink = localLink;
|
|
842
879
|
/**
|
|
843
|
-
* @deprecated
|
|
880
|
+
* @deprecated Use {@link localLink} instead. This alias will be removed in a
|
|
881
|
+
* future major release.
|
|
844
882
|
*/
|
|
845
883
|
const experimental_localLink = localLink;
|
|
846
884
|
//#endregion
|
|
847
885
|
//#region src/safe.ts
|
|
848
886
|
/**
|
|
849
|
-
*
|
|
850
|
-
* `[data, error]` pair typed with
|
|
887
|
+
* Awaits a client `.query()` or `.mutate()` call without throwing, and
|
|
888
|
+
* returns a `[data, error]` pair typed with the procedure's error shape.
|
|
851
889
|
*
|
|
852
890
|
* @example
|
|
853
891
|
* ```ts
|
|
@@ -858,6 +896,7 @@ const experimental_localLink = localLink;
|
|
|
858
896
|
*
|
|
859
897
|
* const id = post.id;
|
|
860
898
|
* ```
|
|
899
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling#errors-as-values-with-safe
|
|
861
900
|
*/
|
|
862
901
|
async function safe(promise) {
|
|
863
902
|
try {
|