@orpc/client 0.0.0-next.62795ca → 0.0.0-next.62c9665

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.
Files changed (35) hide show
  1. package/README.md +33 -32
  2. package/dist/adapters/fetch/index.d.mts +31 -15
  3. package/dist/adapters/fetch/index.d.ts +31 -15
  4. package/dist/adapters/fetch/index.mjs +27 -18
  5. package/dist/adapters/message-port/index.d.mts +80 -0
  6. package/dist/adapters/message-port/index.d.ts +80 -0
  7. package/dist/adapters/message-port/index.mjs +87 -0
  8. package/dist/adapters/standard/index.d.mts +9 -103
  9. package/dist/adapters/standard/index.d.ts +9 -103
  10. package/dist/adapters/standard/index.mjs +4 -3
  11. package/dist/adapters/websocket/index.d.mts +29 -0
  12. package/dist/adapters/websocket/index.d.ts +29 -0
  13. package/dist/adapters/websocket/index.mjs +47 -0
  14. package/dist/index.d.mts +107 -27
  15. package/dist/index.d.ts +107 -27
  16. package/dist/index.mjs +85 -36
  17. package/dist/plugins/index.d.mts +210 -23
  18. package/dist/plugins/index.d.ts +210 -23
  19. package/dist/plugins/index.mjs +412 -54
  20. package/dist/shared/client.2jUAqzYU.d.ts +45 -0
  21. package/dist/shared/client.B3pNRBih.d.ts +91 -0
  22. package/dist/shared/client.BFAVy68H.d.mts +91 -0
  23. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  24. package/dist/shared/client.CpCa3si8.d.mts +45 -0
  25. package/dist/shared/client.i2uoJbEp.d.mts +83 -0
  26. package/dist/shared/client.i2uoJbEp.d.ts +83 -0
  27. package/dist/shared/client.v--pww3D.mjs +171 -0
  28. package/dist/shared/{client.3Q53fveR.mjs → client.wb_KbNQw.mjs} +110 -40
  29. package/package.json +18 -8
  30. package/dist/shared/client.BacCdg3F.mjs +0 -172
  31. package/dist/shared/client.CupM8eRP.d.mts +0 -30
  32. package/dist/shared/client.CupM8eRP.d.ts +0 -30
  33. package/dist/shared/client.CvnV7_uV.mjs +0 -12
  34. package/dist/shared/client.DrOAzyMB.d.mts +0 -45
  35. package/dist/shared/client.aGal-uGY.d.ts +0 -45
@@ -1,36 +1,79 @@
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';
1
+ import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
2
+ import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, t as toORPCError } from './client.v--pww3D.mjs';
4
+ import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
5
+ import { m as mapEventIterator } from './client.BLtwTQUg.mjs';
5
6
 
6
- class InvalidEventIteratorRetryResponse extends Error {
7
+ class CompositeStandardLinkPlugin {
8
+ plugins;
9
+ constructor(plugins = []) {
10
+ this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
11
+ }
12
+ init(options) {
13
+ for (const plugin of this.plugins) {
14
+ plugin.init?.(options);
15
+ }
16
+ }
7
17
  }
18
+
8
19
  class StandardLink {
9
20
  constructor(codec, sender, options = {}) {
10
21
  this.codec = codec;
11
22
  this.sender = sender;
12
- const plugin = new CompositeClientPlugin(options.plugins);
23
+ const plugin = new CompositeStandardLinkPlugin(options.plugins);
13
24
  plugin.init(options);
14
- this.interceptors = options.interceptors ?? [];
15
- this.clientInterceptors = options.clientInterceptors ?? [];
25
+ this.interceptors = toArray(options.interceptors);
26
+ this.clientInterceptors = toArray(options.clientInterceptors);
16
27
  }
17
28
  interceptors;
18
29
  clientInterceptors;
19
30
  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
+ return runWithSpan(
32
+ { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
33
+ (span) => {
34
+ span?.setAttribute("rpc.system", ORPC_NAME);
35
+ span?.setAttribute("rpc.method", path.join("."));
36
+ if (isAsyncIteratorObject(input)) {
37
+ input = asyncIteratorWithSpan(
38
+ { name: "consume_event_iterator_input", signal: options.signal },
39
+ input
40
+ );
41
+ }
42
+ return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
43
+ const otelConfig = getGlobalOtelConfig();
44
+ let otelContext;
45
+ const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
46
+ if (currentSpan && otelConfig) {
47
+ otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
48
+ }
49
+ const request = await runWithSpan(
50
+ { name: "encode_request", context: otelContext },
51
+ () => this.codec.encode(path2, input2, options2)
52
+ );
53
+ const response = await intercept(
54
+ this.clientInterceptors,
55
+ { ...options2, input: input2, path: path2, request },
56
+ ({ input: input3, path: path3, request: request2, ...options3 }) => {
57
+ return runWithSpan(
58
+ { name: "send_request", signal: options3.signal, context: otelContext },
59
+ () => this.sender.call(request2, options3, path3, input3)
60
+ );
61
+ }
62
+ );
63
+ const output = await runWithSpan(
64
+ { name: "decode_response", context: otelContext },
65
+ () => this.codec.decode(response, options2, path2, input2)
66
+ );
67
+ if (isAsyncIteratorObject(output)) {
68
+ return asyncIteratorWithSpan(
69
+ { name: "consume_event_iterator_output", signal: options2.signal },
70
+ output
71
+ );
72
+ }
73
+ return output;
74
+ });
75
+ }
31
76
  );
32
- const output = await this.codec.decode(response, options, path, input);
33
- return output;
34
77
  }
35
78
  }
36
79
 
@@ -129,6 +172,9 @@ class StandardRPCJsonSerializer {
129
172
  segments.forEach((segment) => {
130
173
  currentRef = currentRef[preSegment];
131
174
  preSegment = segment;
175
+ if (!Object.hasOwn(currentRef, preSegment)) {
176
+ throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`);
177
+ }
132
178
  });
133
179
  currentRef[preSegment] = getBlob(i);
134
180
  });
@@ -140,6 +186,9 @@ class StandardRPCJsonSerializer {
140
186
  for (let i = 1; i < item.length; i++) {
141
187
  currentRef = currentRef[preSegment];
142
188
  preSegment = item[i];
189
+ if (!Object.hasOwn(currentRef, preSegment)) {
190
+ throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`);
191
+ }
143
192
  }
144
193
  for (const custom of this.customSerializers) {
145
194
  if (custom.type === type) {
@@ -180,6 +229,19 @@ class StandardRPCJsonSerializer {
180
229
  }
181
230
  }
182
231
 
232
+ function toHttpPath(path) {
233
+ return `/${path.map(encodeURIComponent).join("/")}`;
234
+ }
235
+ function toStandardHeaders(headers) {
236
+ if (typeof headers.forEach === "function") {
237
+ return toStandardHeaders$1(headers);
238
+ }
239
+ return headers;
240
+ }
241
+ function getMalformedResponseErrorCode(status) {
242
+ return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
243
+ }
244
+
183
245
  class StandardRPCLinkCodec {
184
246
  constructor(serializer, options) {
185
247
  this.serializer = serializer;
@@ -195,19 +257,14 @@ class StandardRPCLinkCodec {
195
257
  expectedMethod;
196
258
  headers;
197
259
  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("/")}`);
260
+ let headers = toStandardHeaders(await value(this.headers, options, path, input));
202
261
  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
- }
262
+ headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
210
263
  }
264
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
265
+ const baseUrl = await value(this.baseUrl, options, path, input);
266
+ const url = new URL(baseUrl);
267
+ url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
211
268
  const serialized = this.serializer.serialize(input);
212
269
  if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
213
270
  const maxUrlLength = await value(this.maxUrlLength, options, path, input);
@@ -232,7 +289,7 @@ class StandardRPCLinkCodec {
232
289
  };
233
290
  }
234
291
  async decode(response) {
235
- const isOk = response.status >= 200 && response.status < 300;
292
+ const isOk = !isORPCErrorStatus(response.status);
236
293
  const deserialized = await (async () => {
237
294
  let isBodyOk = false;
238
295
  try {
@@ -251,11 +308,12 @@ class StandardRPCLinkCodec {
251
308
  }
252
309
  })();
253
310
  if (!isOk) {
254
- if (ORPCError.isValidJSON(deserialized)) {
255
- throw ORPCError.fromJSON(deserialized);
311
+ if (isORPCErrorJson(deserialized)) {
312
+ throw createORPCErrorFromJson(deserialized);
256
313
  }
257
- throw new Error("Invalid RPC error response format.", {
258
- cause: deserialized
314
+ throw new ORPCError(getMalformedResponseErrorCode(response.status), {
315
+ status: response.status,
316
+ data: { ...response, body: deserialized }
259
317
  });
260
318
  }
261
319
  return deserialized;
@@ -305,8 +363,8 @@ class StandardRPCSerializer {
305
363
  return e;
306
364
  }
307
365
  const deserialized = this.#deserialize(e.data);
308
- if (ORPCError.isValidJSON(deserialized)) {
309
- return ORPCError.fromJSON(deserialized, { cause: e });
366
+ if (isORPCErrorJson(deserialized)) {
367
+ return createORPCErrorFromJson(deserialized, { cause: e });
310
368
  }
311
369
  return new ErrorEvent({
312
370
  data: deserialized,
@@ -318,6 +376,9 @@ class StandardRPCSerializer {
318
376
  return this.#deserialize(data);
319
377
  }
320
378
  #deserialize(data) {
379
+ if (data === void 0) {
380
+ return void 0;
381
+ }
321
382
  if (!(data instanceof FormData)) {
322
383
  return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
323
384
  }
@@ -331,4 +392,13 @@ class StandardRPCSerializer {
331
392
  }
332
393
  }
333
394
 
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 };
395
+ class StandardRPCLink extends StandardLink {
396
+ constructor(linkClient, options) {
397
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
398
+ const serializer = new StandardRPCSerializer(jsonSerializer);
399
+ const linkCodec = new StandardRPCLinkCodec(serializer, options);
400
+ super(linkCodec, linkClient, options);
401
+ }
402
+ }
403
+
404
+ export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t };
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.0.0-next.62795ca",
4
+ "version": "0.0.0-next.62c9665",
5
5
  "license": "MIT",
6
- "homepage": "https://orpc.unnoq.com",
6
+ "homepage": "https://orpc.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/middleapi/orpc.git",
10
10
  "directory": "packages/client"
11
11
  },
12
12
  "keywords": [
13
- "unnoq",
14
13
  "orpc"
15
14
  ],
16
15
  "exports": {
@@ -33,18 +32,29 @@
33
32
  "types": "./dist/adapters/fetch/index.d.mts",
34
33
  "import": "./dist/adapters/fetch/index.mjs",
35
34
  "default": "./dist/adapters/fetch/index.mjs"
35
+ },
36
+ "./websocket": {
37
+ "types": "./dist/adapters/websocket/index.d.mts",
38
+ "import": "./dist/adapters/websocket/index.mjs",
39
+ "default": "./dist/adapters/websocket/index.mjs"
40
+ },
41
+ "./message-port": {
42
+ "types": "./dist/adapters/message-port/index.d.mts",
43
+ "import": "./dist/adapters/message-port/index.mjs",
44
+ "default": "./dist/adapters/message-port/index.mjs"
36
45
  }
37
46
  },
38
47
  "files": [
39
48
  "dist"
40
49
  ],
41
50
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.62795ca",
43
- "@orpc/standard-server": "0.0.0-next.62795ca",
44
- "@orpc/standard-server-fetch": "0.0.0-next.62795ca"
51
+ "@orpc/shared": "0.0.0-next.62c9665",
52
+ "@orpc/standard-server": "0.0.0-next.62c9665",
53
+ "@orpc/standard-server-peer": "0.0.0-next.62c9665",
54
+ "@orpc/standard-server-fetch": "0.0.0-next.62c9665"
45
55
  },
46
56
  "devDependencies": {
47
- "zod": "^3.24.2"
57
+ "zod": "^4.3.6"
48
58
  },
49
59
  "scripts": {
50
60
  "build": "unbuild",
@@ -1,172 +0,0 @@
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 };
@@ -1,30 +0,0 @@
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 };
@@ -1,30 +0,0 @@
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 };
@@ -1,12 +0,0 @@
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 };
@@ -1,45 +0,0 @@
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 };
@@ -1,45 +0,0 @@
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 };