@orpc/client 0.0.0-next.b4e6d3a → 0.0.0-next.b4fc1d9

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.
@@ -0,0 +1,334 @@
1
+ import { intercept, isObject, value, trim, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
+ import { C as CompositeClientPlugin } from './client.CvnV7_uV.mjs';
3
+ import { ErrorEvent } from '@orpc/standard-server';
4
+ import { O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BacCdg3F.mjs';
5
+
6
+ class InvalidEventIteratorRetryResponse extends Error {
7
+ }
8
+ class StandardLink {
9
+ constructor(codec, sender, options = {}) {
10
+ this.codec = codec;
11
+ this.sender = sender;
12
+ const plugin = new CompositeClientPlugin(options.plugins);
13
+ plugin.init(options);
14
+ this.interceptors = options.interceptors ?? [];
15
+ this.clientInterceptors = options.clientInterceptors ?? [];
16
+ }
17
+ interceptors;
18
+ clientInterceptors;
19
+ call(path, input, options) {
20
+ return intercept(this.interceptors, { path, input, options }, async ({ path: path2, input: input2, options: options2 }) => {
21
+ const output = await this.#call(path2, input2, options2);
22
+ return output;
23
+ });
24
+ }
25
+ async #call(path, input, options) {
26
+ const request = await this.codec.encode(path, input, options);
27
+ const response = await intercept(
28
+ this.clientInterceptors,
29
+ { request },
30
+ ({ request: request2 }) => this.sender.call(request2, options, path, input)
31
+ );
32
+ const output = await this.codec.decode(response, options, path, input);
33
+ return output;
34
+ }
35
+ }
36
+
37
+ const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = {
38
+ BIGINT: 0,
39
+ DATE: 1,
40
+ NAN: 2,
41
+ UNDEFINED: 3,
42
+ URL: 4,
43
+ REGEXP: 5,
44
+ SET: 6,
45
+ MAP: 7
46
+ };
47
+ class StandardRPCJsonSerializer {
48
+ customSerializers;
49
+ constructor(options = {}) {
50
+ this.customSerializers = options.customJsonSerializers ?? [];
51
+ if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) {
52
+ throw new Error("Custom serializer type must be unique.");
53
+ }
54
+ }
55
+ serialize(data, segments = [], meta = [], maps = [], blobs = []) {
56
+ for (const custom of this.customSerializers) {
57
+ if (custom.condition(data)) {
58
+ const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs);
59
+ meta.push([custom.type, ...segments]);
60
+ return result;
61
+ }
62
+ }
63
+ if (data instanceof Blob) {
64
+ maps.push(segments);
65
+ blobs.push(data);
66
+ return [data, meta, maps, blobs];
67
+ }
68
+ if (typeof data === "bigint") {
69
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]);
70
+ return [data.toString(), meta, maps, blobs];
71
+ }
72
+ if (data instanceof Date) {
73
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]);
74
+ if (Number.isNaN(data.getTime())) {
75
+ return [null, meta, maps, blobs];
76
+ }
77
+ return [data.toISOString(), meta, maps, blobs];
78
+ }
79
+ if (Number.isNaN(data)) {
80
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]);
81
+ return [null, meta, maps, blobs];
82
+ }
83
+ if (data instanceof URL) {
84
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]);
85
+ return [data.toString(), meta, maps, blobs];
86
+ }
87
+ if (data instanceof RegExp) {
88
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]);
89
+ return [data.toString(), meta, maps, blobs];
90
+ }
91
+ if (data instanceof Set) {
92
+ const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
93
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]);
94
+ return result;
95
+ }
96
+ if (data instanceof Map) {
97
+ const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
98
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]);
99
+ return result;
100
+ }
101
+ if (Array.isArray(data)) {
102
+ const json = data.map((v, i) => {
103
+ if (v === void 0) {
104
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]);
105
+ return v;
106
+ }
107
+ return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
108
+ });
109
+ return [json, meta, maps, blobs];
110
+ }
111
+ if (isObject(data)) {
112
+ const json = {};
113
+ for (const k in data) {
114
+ if (k === "toJSON" && typeof data[k] === "function") {
115
+ continue;
116
+ }
117
+ json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
118
+ }
119
+ return [json, meta, maps, blobs];
120
+ }
121
+ return [data, meta, maps, blobs];
122
+ }
123
+ deserialize(json, meta, maps, getBlob) {
124
+ const ref = { data: json };
125
+ if (maps && getBlob) {
126
+ maps.forEach((segments, i) => {
127
+ let currentRef = ref;
128
+ let preSegment = "data";
129
+ segments.forEach((segment) => {
130
+ currentRef = currentRef[preSegment];
131
+ preSegment = segment;
132
+ });
133
+ currentRef[preSegment] = getBlob(i);
134
+ });
135
+ }
136
+ for (const item of meta) {
137
+ const type = item[0];
138
+ let currentRef = ref;
139
+ let preSegment = "data";
140
+ for (let i = 1; i < item.length; i++) {
141
+ currentRef = currentRef[preSegment];
142
+ preSegment = item[i];
143
+ }
144
+ for (const custom of this.customSerializers) {
145
+ if (custom.type === type) {
146
+ currentRef[preSegment] = custom.deserialize(currentRef[preSegment]);
147
+ break;
148
+ }
149
+ }
150
+ switch (type) {
151
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT:
152
+ currentRef[preSegment] = BigInt(currentRef[preSegment]);
153
+ break;
154
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE:
155
+ currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
156
+ break;
157
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN:
158
+ currentRef[preSegment] = Number.NaN;
159
+ break;
160
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED:
161
+ currentRef[preSegment] = void 0;
162
+ break;
163
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL:
164
+ currentRef[preSegment] = new URL(currentRef[preSegment]);
165
+ break;
166
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: {
167
+ const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
168
+ currentRef[preSegment] = new RegExp(pattern, flags);
169
+ break;
170
+ }
171
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET:
172
+ currentRef[preSegment] = new Set(currentRef[preSegment]);
173
+ break;
174
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP:
175
+ currentRef[preSegment] = new Map(currentRef[preSegment]);
176
+ break;
177
+ }
178
+ }
179
+ return ref.data;
180
+ }
181
+ }
182
+
183
+ class StandardRPCLinkCodec {
184
+ constructor(serializer, options) {
185
+ this.serializer = serializer;
186
+ this.baseUrl = options.url;
187
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
188
+ this.fallbackMethod = options.fallbackMethod ?? "POST";
189
+ this.expectedMethod = options.method ?? this.fallbackMethod;
190
+ this.headers = options.headers ?? {};
191
+ }
192
+ baseUrl;
193
+ maxUrlLength;
194
+ fallbackMethod;
195
+ expectedMethod;
196
+ headers;
197
+ async encode(path, input, options) {
198
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
199
+ const headers = { ...await value(this.headers, options, path, input) };
200
+ const baseUrl = await value(this.baseUrl, options, path, input);
201
+ const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
202
+ if (options.lastEventId !== void 0) {
203
+ if (Array.isArray(headers["last-event-id"])) {
204
+ headers["last-event-id"] = [...headers["last-event-id"], options.lastEventId];
205
+ } else if (headers["last-event-id"] !== void 0) {
206
+ headers["last-event-id"] = [headers["last-event-id"], options.lastEventId];
207
+ } else {
208
+ headers["last-event-id"] = options.lastEventId;
209
+ }
210
+ }
211
+ const serialized = this.serializer.serialize(input);
212
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
213
+ const maxUrlLength = await value(this.maxUrlLength, options, path, input);
214
+ const getUrl = new URL(url);
215
+ getUrl.searchParams.append("data", stringifyJSON(serialized));
216
+ if (getUrl.toString().length <= maxUrlLength) {
217
+ return {
218
+ body: void 0,
219
+ method: expectedMethod,
220
+ headers,
221
+ url: getUrl,
222
+ signal: options.signal
223
+ };
224
+ }
225
+ }
226
+ return {
227
+ url,
228
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
229
+ headers,
230
+ body: serialized,
231
+ signal: options.signal
232
+ };
233
+ }
234
+ async decode(response) {
235
+ const isOk = response.status >= 200 && response.status < 300;
236
+ const deserialized = await (async () => {
237
+ let isBodyOk = false;
238
+ try {
239
+ const body = await response.body();
240
+ isBodyOk = true;
241
+ return this.serializer.deserialize(body);
242
+ } catch (error) {
243
+ if (!isBodyOk) {
244
+ throw new Error("Cannot parse response body, please check the response body and content-type.", {
245
+ cause: error
246
+ });
247
+ }
248
+ throw new Error("Invalid RPC response format.", {
249
+ cause: error
250
+ });
251
+ }
252
+ })();
253
+ if (!isOk) {
254
+ if (ORPCError.isValidJSON(deserialized)) {
255
+ throw ORPCError.fromJSON(deserialized);
256
+ }
257
+ throw new Error("Invalid RPC error response format.", {
258
+ cause: deserialized
259
+ });
260
+ }
261
+ return deserialized;
262
+ }
263
+ }
264
+
265
+ class StandardRPCSerializer {
266
+ constructor(jsonSerializer) {
267
+ this.jsonSerializer = jsonSerializer;
268
+ }
269
+ serialize(data) {
270
+ if (isAsyncIteratorObject(data)) {
271
+ return mapEventIterator(data, {
272
+ value: async (value) => this.#serialize(value, false),
273
+ error: async (e) => {
274
+ return new ErrorEvent({
275
+ data: this.#serialize(toORPCError(e).toJSON(), false),
276
+ cause: e
277
+ });
278
+ }
279
+ });
280
+ }
281
+ return this.#serialize(data, true);
282
+ }
283
+ #serialize(data, enableFormData) {
284
+ const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
285
+ const meta = meta_.length === 0 ? void 0 : meta_;
286
+ if (!enableFormData || blobs.length === 0) {
287
+ return {
288
+ json,
289
+ meta
290
+ };
291
+ }
292
+ const form = new FormData();
293
+ form.set("data", stringifyJSON({ json, meta, maps }));
294
+ blobs.forEach((blob, i) => {
295
+ form.set(i.toString(), blob);
296
+ });
297
+ return form;
298
+ }
299
+ deserialize(data) {
300
+ if (isAsyncIteratorObject(data)) {
301
+ return mapEventIterator(data, {
302
+ value: async (value) => this.#deserialize(value),
303
+ error: async (e) => {
304
+ if (!(e instanceof ErrorEvent)) {
305
+ return e;
306
+ }
307
+ const deserialized = this.#deserialize(e.data);
308
+ if (ORPCError.isValidJSON(deserialized)) {
309
+ return ORPCError.fromJSON(deserialized, { cause: e });
310
+ }
311
+ return new ErrorEvent({
312
+ data: deserialized,
313
+ cause: e
314
+ });
315
+ }
316
+ });
317
+ }
318
+ return this.#deserialize(data);
319
+ }
320
+ #deserialize(data) {
321
+ if (!(data instanceof FormData)) {
322
+ return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
323
+ }
324
+ const serialized = JSON.parse(data.get("data"));
325
+ return this.jsonSerializer.deserialize(
326
+ serialized.json,
327
+ serialized.meta ?? [],
328
+ serialized.maps,
329
+ (i) => data.get(i.toString())
330
+ );
331
+ }
332
+ }
333
+
334
+ export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d };
@@ -0,0 +1,172 @@
1
+ import { isObject, isTypescriptObject } from '@orpc/shared';
2
+ import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
+
4
+ const COMMON_ORPC_ERROR_DEFS = {
5
+ BAD_REQUEST: {
6
+ status: 400,
7
+ message: "Bad Request"
8
+ },
9
+ UNAUTHORIZED: {
10
+ status: 401,
11
+ message: "Unauthorized"
12
+ },
13
+ FORBIDDEN: {
14
+ status: 403,
15
+ message: "Forbidden"
16
+ },
17
+ NOT_FOUND: {
18
+ status: 404,
19
+ message: "Not Found"
20
+ },
21
+ METHOD_NOT_SUPPORTED: {
22
+ status: 405,
23
+ message: "Method Not Supported"
24
+ },
25
+ NOT_ACCEPTABLE: {
26
+ status: 406,
27
+ message: "Not Acceptable"
28
+ },
29
+ TIMEOUT: {
30
+ status: 408,
31
+ message: "Request Timeout"
32
+ },
33
+ CONFLICT: {
34
+ status: 409,
35
+ message: "Conflict"
36
+ },
37
+ PRECONDITION_FAILED: {
38
+ status: 412,
39
+ message: "Precondition Failed"
40
+ },
41
+ PAYLOAD_TOO_LARGE: {
42
+ status: 413,
43
+ message: "Payload Too Large"
44
+ },
45
+ UNSUPPORTED_MEDIA_TYPE: {
46
+ status: 415,
47
+ message: "Unsupported Media Type"
48
+ },
49
+ UNPROCESSABLE_CONTENT: {
50
+ status: 422,
51
+ message: "Unprocessable Content"
52
+ },
53
+ TOO_MANY_REQUESTS: {
54
+ status: 429,
55
+ message: "Too Many Requests"
56
+ },
57
+ CLIENT_CLOSED_REQUEST: {
58
+ status: 499,
59
+ message: "Client Closed Request"
60
+ },
61
+ INTERNAL_SERVER_ERROR: {
62
+ status: 500,
63
+ message: "Internal Server Error"
64
+ },
65
+ NOT_IMPLEMENTED: {
66
+ status: 501,
67
+ message: "Not Implemented"
68
+ },
69
+ BAD_GATEWAY: {
70
+ status: 502,
71
+ message: "Bad Gateway"
72
+ },
73
+ SERVICE_UNAVAILABLE: {
74
+ status: 503,
75
+ message: "Service Unavailable"
76
+ },
77
+ GATEWAY_TIMEOUT: {
78
+ status: 504,
79
+ message: "Gateway Timeout"
80
+ }
81
+ };
82
+ function fallbackORPCErrorStatus(code, status) {
83
+ return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
84
+ }
85
+ function fallbackORPCErrorMessage(code, message) {
86
+ return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
87
+ }
88
+ class ORPCError extends Error {
89
+ defined;
90
+ code;
91
+ status;
92
+ data;
93
+ constructor(code, ...[options]) {
94
+ if (options?.status && (options.status < 400 || options.status >= 600)) {
95
+ throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
96
+ }
97
+ const message = fallbackORPCErrorMessage(code, options?.message);
98
+ super(message, options);
99
+ this.code = code;
100
+ this.status = fallbackORPCErrorStatus(code, options?.status);
101
+ this.defined = options?.defined ?? false;
102
+ this.data = options?.data;
103
+ }
104
+ toJSON() {
105
+ return {
106
+ defined: this.defined,
107
+ code: this.code,
108
+ status: this.status,
109
+ message: this.message,
110
+ data: this.data
111
+ };
112
+ }
113
+ static fromJSON(json, options) {
114
+ return new ORPCError(json.code, {
115
+ ...options,
116
+ ...json
117
+ });
118
+ }
119
+ static isValidJSON(json) {
120
+ if (!isObject(json)) {
121
+ return false;
122
+ }
123
+ const validKeys = ["defined", "code", "status", "message", "data"];
124
+ if (Object.keys(json).some((k) => !validKeys.includes(k))) {
125
+ return false;
126
+ }
127
+ return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
128
+ }
129
+ }
130
+ function isDefinedError(error) {
131
+ return error instanceof ORPCError && error.defined;
132
+ }
133
+ function toORPCError(error) {
134
+ return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
135
+ message: "Internal server error",
136
+ cause: error
137
+ });
138
+ }
139
+
140
+ function mapEventIterator(iterator, maps) {
141
+ return async function* () {
142
+ try {
143
+ while (true) {
144
+ const { done, value } = await iterator.next();
145
+ let mappedValue = await maps.value(value, done);
146
+ if (mappedValue !== value) {
147
+ const meta = getEventMeta(value);
148
+ if (meta && isTypescriptObject(mappedValue)) {
149
+ mappedValue = withEventMeta(mappedValue, meta);
150
+ }
151
+ }
152
+ if (done) {
153
+ return mappedValue;
154
+ }
155
+ yield mappedValue;
156
+ }
157
+ } catch (error) {
158
+ let mappedError = await maps.error(error);
159
+ if (mappedError !== error) {
160
+ const meta = getEventMeta(error);
161
+ if (meta && isTypescriptObject(mappedError)) {
162
+ mappedError = withEventMeta(mappedError, meta);
163
+ }
164
+ }
165
+ throw mappedError;
166
+ } finally {
167
+ await iterator.return?.();
168
+ }
169
+ }();
170
+ }
171
+
172
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
@@ -0,0 +1,30 @@
1
+ type ClientContext = Record<string, any>;
2
+ type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
+ type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -0,0 +1,30 @@
1
+ type ClientContext = Record<string, any>;
2
+ type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
+ type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -0,0 +1,12 @@
1
+ class CompositeClientPlugin {
2
+ constructor(plugins = []) {
3
+ this.plugins = plugins;
4
+ }
5
+ init(options) {
6
+ for (const plugin of this.plugins) {
7
+ plugin.init?.(options);
8
+ }
9
+ }
10
+ }
11
+
12
+ export { CompositeClientPlugin as C };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.mjs';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ interceptors?: Interceptor<{
17
+ path: readonly string[];
18
+ input: unknown;
19
+ options: ClientOptionsOut<T>;
20
+ }, unknown, unknown>[];
21
+ clientInterceptors?: Interceptor<{
22
+ request: StandardRequest;
23
+ }, StandardLazyResponse, unknown>[];
24
+ plugins?: ClientPlugin<T>[];
25
+ }
26
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
+ #private;
28
+ readonly codec: StandardLinkCodec<T>;
29
+ readonly sender: StandardLinkClient<T>;
30
+ private readonly interceptors;
31
+ private readonly clientInterceptors;
32
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
+ }
35
+
36
+ interface ClientPlugin<T extends ClientContext> {
37
+ init?(options: StandardLinkOptions<T>): void;
38
+ }
39
+ declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
+ private readonly plugins;
41
+ constructor(plugins?: ClientPlugin<T>[]);
42
+ init(options: StandardLinkOptions<T>): void;
43
+ }
44
+
45
+ export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.js';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ interceptors?: Interceptor<{
17
+ path: readonly string[];
18
+ input: unknown;
19
+ options: ClientOptionsOut<T>;
20
+ }, unknown, unknown>[];
21
+ clientInterceptors?: Interceptor<{
22
+ request: StandardRequest;
23
+ }, StandardLazyResponse, unknown>[];
24
+ plugins?: ClientPlugin<T>[];
25
+ }
26
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
+ #private;
28
+ readonly codec: StandardLinkCodec<T>;
29
+ readonly sender: StandardLinkClient<T>;
30
+ private readonly interceptors;
31
+ private readonly clientInterceptors;
32
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
+ }
35
+
36
+ interface ClientPlugin<T extends ClientContext> {
37
+ init?(options: StandardLinkOptions<T>): void;
38
+ }
39
+ declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
+ private readonly plugins;
41
+ constructor(plugins?: ClientPlugin<T>[]);
42
+ init(options: StandardLinkOptions<T>): void;
43
+ }
44
+
45
+ export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };