@orpc/client 0.0.0-next.aac73c2 → 0.0.0-next.ab2f831

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 (32) hide show
  1. package/README.md +22 -22
  2. package/dist/adapters/fetch/index.d.mts +31 -11
  3. package/dist/adapters/fetch/index.d.ts +31 -11
  4. package/dist/adapters/fetch/index.mjs +27 -13
  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 +7 -5
  9. package/dist/adapters/standard/index.d.ts +7 -5
  10. package/dist/adapters/standard/index.mjs +4 -2
  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 +105 -27
  15. package/dist/index.d.ts +105 -27
  16. package/dist/index.mjs +61 -14
  17. package/dist/plugins/index.d.mts +209 -21
  18. package/dist/plugins/index.d.ts +209 -21
  19. package/dist/plugins/index.mjs +412 -53
  20. package/dist/shared/client.BH1AYT_p.d.mts +83 -0
  21. package/dist/shared/client.BH1AYT_p.d.ts +83 -0
  22. package/dist/shared/{client.D77bw0hs.mjs → client.BJ7mFf_E.mjs} +95 -30
  23. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  24. package/dist/shared/{client.DczFzIj1.d.ts → client.BxV-mzeR.d.ts} +13 -25
  25. package/dist/shared/{client.D_TnaeH1.d.mts → client.CPgZaUox.d.mts} +20 -14
  26. package/dist/shared/client.Czkbx_PI.mjs +171 -0
  27. package/dist/shared/{client.DnHi1dp8.d.mts → client.D8lMmWVC.d.mts} +13 -25
  28. package/dist/shared/{client.BZZMKcrk.d.ts → client.De8SW4Kw.d.ts} +20 -14
  29. package/package.json +16 -5
  30. package/dist/shared/client.Bnaxb-CE.d.mts +0 -30
  31. package/dist/shared/client.Bnaxb-CE.d.ts +0 -30
  32. package/dist/shared/client.jKEwIsRd.mjs +0 -175
@@ -1,6 +1,6 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.Bnaxb-CE.mjs';
2
- import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.D_TnaeH1.mjs';
3
- import { Segment, Value } from '@orpc/shared';
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CPgZaUox.mjs';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
6
6
  declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
@@ -44,46 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
44
  /**
45
45
  * Base url for all requests.
46
46
  */
47
- url: Value<string | URL, [
48
- options: ClientOptions<T>,
49
- path: readonly string[],
50
- input: unknown
51
- ]>;
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
52
48
  /**
53
49
  * The maximum length of the URL.
54
50
  *
55
51
  * @default 2083
56
52
  */
57
- maxUrlLength?: Value<number, [
58
- options: ClientOptions<T>,
59
- path: readonly string[],
60
- input: unknown
61
- ]>;
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
62
54
  /**
63
55
  * The method used to make the request.
64
56
  *
65
57
  * @default 'POST'
66
58
  */
67
- method?: Value<HTTPMethod, [
68
- options: ClientOptions<T>,
69
- path: readonly string[],
70
- input: unknown
71
- ]>;
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
72
60
  /**
73
61
  * The method to use when the payload cannot safely pass to the server with method return from method function.
74
62
  * GET is not allowed, it's very dangerous.
75
63
  *
76
64
  * @default 'POST'
77
65
  */
78
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
79
67
  /**
80
68
  * Inject headers to the request.
81
69
  */
82
- headers?: Value<StandardHeaders, [
83
- options: ClientOptions<T>,
84
- path: readonly string[],
85
- input: unknown
86
- ]>;
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
87
71
  }
88
72
  declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
89
73
  private readonly serializer;
@@ -99,5 +83,9 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
99
83
 
100
84
  interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
101
85
  }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
102
89
 
103
- export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
91
+ export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
@@ -1,6 +1,16 @@
1
1
  import { Interceptor } from '@orpc/shared';
2
2
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
- import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.Bnaxb-CE.js';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.js';
4
+
5
+ interface StandardLinkPlugin<T extends ClientContext> {
6
+ order?: number;
7
+ init?(options: StandardLinkOptions<T>): void;
8
+ }
9
+ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
10
+ protected readonly plugins: TPlugin[];
11
+ constructor(plugins?: readonly TPlugin[]);
12
+ init(options: StandardLinkOptions<T>): void;
13
+ }
4
14
 
5
15
  interface StandardLinkCodec<T extends ClientContext> {
6
16
  encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
@@ -10,24 +20,19 @@ interface StandardLinkClient<T extends ClientContext> {
10
20
  call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
21
  }
12
22
 
13
- declare class InvalidEventIteratorRetryResponse extends Error {
23
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
+ path: readonly string[];
25
+ input: unknown;
14
26
  }
15
- interface StandardLinkPlugin<T extends ClientContext> {
16
- init?(options: StandardLinkOptions<T>): void;
27
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
28
+ request: StandardRequest;
17
29
  }
18
30
  interface StandardLinkOptions<T extends ClientContext> {
19
- interceptors?: Interceptor<{
20
- path: readonly string[];
21
- input: unknown;
22
- options: ClientOptions<T>;
23
- }, unknown, unknown>[];
24
- clientInterceptors?: Interceptor<{
25
- request: StandardRequest;
26
- }, StandardLazyResponse, unknown>[];
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
27
33
  plugins?: StandardLinkPlugin<T>[];
28
34
  }
29
35
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
30
- #private;
31
36
  readonly codec: StandardLinkCodec<T>;
32
37
  readonly sender: StandardLinkClient<T>;
33
38
  private readonly interceptors;
@@ -36,4 +41,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
41
  call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
37
42
  }
38
43
 
39
- export { InvalidEventIteratorRetryResponse as I, type StandardLinkPlugin as S, type StandardLinkOptions as a, StandardLink as b, type StandardLinkCodec as c, type StandardLinkClient as d };
44
+ export { CompositeStandardLinkPlugin as C, StandardLink as d };
45
+ export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.0.0-next.aac73c2",
4
+ "version": "0.0.0-next.ab2f831",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -33,18 +33,29 @@
33
33
  "types": "./dist/adapters/fetch/index.d.mts",
34
34
  "import": "./dist/adapters/fetch/index.mjs",
35
35
  "default": "./dist/adapters/fetch/index.mjs"
36
+ },
37
+ "./websocket": {
38
+ "types": "./dist/adapters/websocket/index.d.mts",
39
+ "import": "./dist/adapters/websocket/index.mjs",
40
+ "default": "./dist/adapters/websocket/index.mjs"
41
+ },
42
+ "./message-port": {
43
+ "types": "./dist/adapters/message-port/index.d.mts",
44
+ "import": "./dist/adapters/message-port/index.mjs",
45
+ "default": "./dist/adapters/message-port/index.mjs"
36
46
  }
37
47
  },
38
48
  "files": [
39
49
  "dist"
40
50
  ],
41
51
  "dependencies": {
42
- "@orpc/shared": "0.0.0-next.aac73c2",
43
- "@orpc/standard-server": "0.0.0-next.aac73c2",
44
- "@orpc/standard-server-fetch": "0.0.0-next.aac73c2"
52
+ "@orpc/shared": "0.0.0-next.ab2f831",
53
+ "@orpc/standard-server": "0.0.0-next.ab2f831",
54
+ "@orpc/standard-server-fetch": "0.0.0-next.ab2f831",
55
+ "@orpc/standard-server-peer": "0.0.0-next.ab2f831"
45
56
  },
46
57
  "devDependencies": {
47
- "zod": "^3.24.2"
58
+ "zod": "^4.1.12"
48
59
  },
49
60
  "scripts": {
50
61
  "build": "unbuild",
@@ -1,30 +0,0 @@
1
- import { PromiseWithError } from '@orpc/shared';
2
-
3
- type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
- type ClientContext = Record<string, any>;
6
- type FriendlyClientOptions<TClientContext extends ClientContext> = {
7
- signal?: AbortSignal;
8
- lastEventId?: string | undefined;
9
- } & (Record<never, never> extends TClientContext ? {
10
- context?: TClientContext;
11
- } : {
12
- context: TClientContext;
13
- });
14
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
15
- type ClientPromiseResult<TOutput, TError extends Error> = PromiseWithError<TOutput, TError>;
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 ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
24
- context: TClientContext;
25
- };
26
- interface ClientLink<TClientContext extends ClientContext> {
27
- call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
28
- }
29
-
30
- export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
@@ -1,30 +0,0 @@
1
- import { PromiseWithError } from '@orpc/shared';
2
-
3
- type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
- type ClientContext = Record<string, any>;
6
- type FriendlyClientOptions<TClientContext extends ClientContext> = {
7
- signal?: AbortSignal;
8
- lastEventId?: string | undefined;
9
- } & (Record<never, never> extends TClientContext ? {
10
- context?: TClientContext;
11
- } : {
12
- context: TClientContext;
13
- });
14
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
15
- type ClientPromiseResult<TOutput, TError extends Error> = PromiseWithError<TOutput, TError>;
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 ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
24
- context: TClientContext;
25
- };
26
- interface ClientLink<TClientContext extends ClientContext> {
27
- call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
28
- }
29
-
30
- export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
@@ -1,175 +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 && !isORPCErrorStatus(options.status)) {
95
- throw new Error("[ORPCError] Invalid error status code.");
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
- function isORPCErrorStatus(status) {
140
- return status < 200 || status >= 400;
141
- }
142
-
143
- function mapEventIterator(iterator, maps) {
144
- return async function* () {
145
- try {
146
- while (true) {
147
- const { done, value } = await iterator.next();
148
- let mappedValue = await maps.value(value, done);
149
- if (mappedValue !== value) {
150
- const meta = getEventMeta(value);
151
- if (meta && isTypescriptObject(mappedValue)) {
152
- mappedValue = withEventMeta(mappedValue, meta);
153
- }
154
- }
155
- if (done) {
156
- return mappedValue;
157
- }
158
- yield mappedValue;
159
- }
160
- } catch (error) {
161
- let mappedError = await maps.error(error);
162
- if (mappedError !== error) {
163
- const meta = getEventMeta(error);
164
- if (meta && isTypescriptObject(mappedError)) {
165
- mappedError = withEventMeta(mappedError, meta);
166
- }
167
- }
168
- throw mappedError;
169
- } finally {
170
- await iterator.return?.();
171
- }
172
- }();
173
- }
174
-
175
- export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };