@orpc/client 0.0.0-next.ce2f84d → 0.0.0-next.ce777b8

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 (29) hide show
  1. package/README.md +19 -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 +26 -13
  5. package/dist/adapters/message-port/index.d.mts +59 -0
  6. package/dist/adapters/message-port/index.d.ts +59 -0
  7. package/dist/adapters/message-port/index.mjs +72 -0
  8. package/dist/adapters/standard/index.d.mts +6 -5
  9. package/dist/adapters/standard/index.d.ts +6 -5
  10. package/dist/adapters/standard/index.mjs +3 -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 +46 -0
  14. package/dist/index.d.mts +69 -23
  15. package/dist/index.d.ts +69 -23
  16. package/dist/index.mjs +25 -8
  17. package/dist/plugins/index.d.mts +162 -25
  18. package/dist/plugins/index.d.ts +162 -25
  19. package/dist/plugins/index.mjs +331 -56
  20. package/dist/shared/{client.5813Ufvs.d.mts → client.BG98rYdO.d.ts} +21 -15
  21. package/dist/shared/{client.C0lT7w02.d.mts → client.BOYsZIRq.d.mts} +8 -9
  22. package/dist/shared/{client.C0lT7w02.d.ts → client.BOYsZIRq.d.ts} +8 -9
  23. package/dist/shared/{client.grRbC25r.d.ts → client.Bwgm6dgk.d.mts} +21 -15
  24. package/dist/shared/{client.D-jrSuDb.d.ts → client.CVVVqf1Y.d.ts} +13 -25
  25. package/dist/shared/client.Dpln0Rf1.mjs +208 -0
  26. package/dist/shared/{client.DSPm2IGZ.mjs → client.W-O_y5wk.mjs} +89 -29
  27. package/dist/shared/{client.Bt94sjrK.d.mts → client._Y_enhib.d.mts} +13 -25
  28. package/package.json +16 -5
  29. 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.C0lT7w02.mjs';
2
- import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.5813Ufvs.mjs';
3
- import { Segment, Value } from '@orpc/shared';
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.Bwgm6dgk.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 };
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.ce2f84d",
4
+ "version": "0.0.0-next.ce777b8",
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.ce2f84d",
43
- "@orpc/standard-server-fetch": "0.0.0-next.ce2f84d",
44
- "@orpc/standard-server": "0.0.0-next.ce2f84d"
52
+ "@orpc/shared": "0.0.0-next.ce777b8",
53
+ "@orpc/standard-server-peer": "0.0.0-next.ce777b8",
54
+ "@orpc/standard-server-fetch": "0.0.0-next.ce777b8",
55
+ "@orpc/standard-server": "0.0.0-next.ce777b8"
45
56
  },
46
57
  "devDependencies": {
47
- "zod": "^3.24.2"
58
+ "zod": "^4.1.5"
48
59
  },
49
60
  "scripts": {
50
61
  "build": "unbuild",
@@ -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 };