@orpc/client 0.0.0-next.f22c7ec → 0.0.0-next.f397ca2

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 (38) hide show
  1. package/README.md +101 -0
  2. package/dist/adapters/fetch/index.d.mts +46 -0
  3. package/dist/adapters/fetch/index.d.ts +46 -0
  4. package/dist/adapters/fetch/index.mjs +46 -0
  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 +11 -0
  9. package/dist/adapters/standard/index.d.ts +11 -0
  10. package/dist/adapters/standard/index.mjs +6 -0
  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 +230 -0
  15. package/dist/index.d.ts +230 -0
  16. package/dist/index.mjs +112 -0
  17. package/dist/plugins/index.d.mts +249 -0
  18. package/dist/plugins/index.d.ts +249 -0
  19. package/dist/plugins/index.mjs +485 -0
  20. package/dist/shared/client.B7wn9u6X.mjs +398 -0
  21. package/dist/shared/client.BH1AYT_p.d.mts +83 -0
  22. package/dist/shared/client.BH1AYT_p.d.ts +83 -0
  23. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  24. package/dist/shared/client.BxV-mzeR.d.ts +91 -0
  25. package/dist/shared/client.CPgZaUox.d.mts +45 -0
  26. package/dist/shared/client.D8lMmWVC.d.mts +91 -0
  27. package/dist/shared/client.De8SW4Kw.d.ts +45 -0
  28. package/dist/shared/client.LHg4bnWP.mjs +171 -0
  29. package/package.json +32 -17
  30. package/dist/fetch.js +0 -89
  31. package/dist/index.js +0 -42
  32. package/dist/src/adapters/fetch/index.d.ts +0 -3
  33. package/dist/src/adapters/fetch/orpc-link.d.ts +0 -46
  34. package/dist/src/adapters/fetch/types.d.ts +0 -4
  35. package/dist/src/client.d.ts +0 -11
  36. package/dist/src/dynamic-link.d.ts +0 -13
  37. package/dist/src/index.d.ts +0 -6
  38. package/dist/src/types.d.ts +0 -5
@@ -0,0 +1,91 @@
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.js';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.De8SW4Kw.js';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
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 };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.mjs';
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
+ }
14
+
15
+ interface StandardLinkCodec<T extends ClientContext> {
16
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
17
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
18
+ }
19
+ interface StandardLinkClient<T extends ClientContext> {
20
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
21
+ }
22
+
23
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
+ path: readonly string[];
25
+ input: unknown;
26
+ }
27
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
28
+ request: StandardRequest;
29
+ }
30
+ interface StandardLinkOptions<T extends ClientContext> {
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
33
+ plugins?: StandardLinkPlugin<T>[];
34
+ }
35
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
+ readonly codec: StandardLinkCodec<T>;
37
+ readonly sender: StandardLinkClient<T>;
38
+ private readonly interceptors;
39
+ private readonly clientInterceptors;
40
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
41
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
42
+ }
43
+
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 };
@@ -0,0 +1,91 @@
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
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
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 };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
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
+ }
14
+
15
+ interface StandardLinkCodec<T extends ClientContext> {
16
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
17
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
18
+ }
19
+ interface StandardLinkClient<T extends ClientContext> {
20
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
21
+ }
22
+
23
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
+ path: readonly string[];
25
+ input: unknown;
26
+ }
27
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
28
+ request: StandardRequest;
29
+ }
30
+ interface StandardLinkOptions<T extends ClientContext> {
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
33
+ plugins?: StandardLinkPlugin<T>[];
34
+ }
35
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
+ readonly codec: StandardLinkCodec<T>;
37
+ readonly sender: StandardLinkClient<T>;
38
+ private readonly interceptors;
39
+ private readonly clientInterceptors;
40
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
41
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
42
+ }
43
+
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 };
@@ -0,0 +1,171 @@
1
+ import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared';
2
+
3
+ const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
4
+ const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.f397ca2";
5
+
6
+ const COMMON_ORPC_ERROR_DEFS = {
7
+ BAD_REQUEST: {
8
+ status: 400,
9
+ message: "Bad Request"
10
+ },
11
+ UNAUTHORIZED: {
12
+ status: 401,
13
+ message: "Unauthorized"
14
+ },
15
+ FORBIDDEN: {
16
+ status: 403,
17
+ message: "Forbidden"
18
+ },
19
+ NOT_FOUND: {
20
+ status: 404,
21
+ message: "Not Found"
22
+ },
23
+ METHOD_NOT_SUPPORTED: {
24
+ status: 405,
25
+ message: "Method Not Supported"
26
+ },
27
+ NOT_ACCEPTABLE: {
28
+ status: 406,
29
+ message: "Not Acceptable"
30
+ },
31
+ TIMEOUT: {
32
+ status: 408,
33
+ message: "Request Timeout"
34
+ },
35
+ CONFLICT: {
36
+ status: 409,
37
+ message: "Conflict"
38
+ },
39
+ PRECONDITION_FAILED: {
40
+ status: 412,
41
+ message: "Precondition Failed"
42
+ },
43
+ PAYLOAD_TOO_LARGE: {
44
+ status: 413,
45
+ message: "Payload Too Large"
46
+ },
47
+ UNSUPPORTED_MEDIA_TYPE: {
48
+ status: 415,
49
+ message: "Unsupported Media Type"
50
+ },
51
+ UNPROCESSABLE_CONTENT: {
52
+ status: 422,
53
+ message: "Unprocessable Content"
54
+ },
55
+ TOO_MANY_REQUESTS: {
56
+ status: 429,
57
+ message: "Too Many Requests"
58
+ },
59
+ CLIENT_CLOSED_REQUEST: {
60
+ status: 499,
61
+ message: "Client Closed Request"
62
+ },
63
+ INTERNAL_SERVER_ERROR: {
64
+ status: 500,
65
+ message: "Internal Server Error"
66
+ },
67
+ NOT_IMPLEMENTED: {
68
+ status: 501,
69
+ message: "Not Implemented"
70
+ },
71
+ BAD_GATEWAY: {
72
+ status: 502,
73
+ message: "Bad Gateway"
74
+ },
75
+ SERVICE_UNAVAILABLE: {
76
+ status: 503,
77
+ message: "Service Unavailable"
78
+ },
79
+ GATEWAY_TIMEOUT: {
80
+ status: 504,
81
+ message: "Gateway Timeout"
82
+ }
83
+ };
84
+ function fallbackORPCErrorStatus(code, status) {
85
+ return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
86
+ }
87
+ function fallbackORPCErrorMessage(code, message) {
88
+ return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
89
+ }
90
+ const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
91
+ void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
92
+ const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
93
+ class ORPCError extends Error {
94
+ defined;
95
+ code;
96
+ status;
97
+ data;
98
+ constructor(code, ...rest) {
99
+ const options = resolveMaybeOptionalOptions(rest);
100
+ if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
101
+ throw new Error("[ORPCError] Invalid error status code.");
102
+ }
103
+ const message = fallbackORPCErrorMessage(code, options.message);
104
+ super(message, options);
105
+ this.code = code;
106
+ this.status = fallbackORPCErrorStatus(code, options.status);
107
+ this.defined = options.defined ?? false;
108
+ this.data = options.data;
109
+ }
110
+ toJSON() {
111
+ return {
112
+ defined: this.defined,
113
+ code: this.code,
114
+ status: this.status,
115
+ message: this.message,
116
+ data: this.data
117
+ };
118
+ }
119
+ /**
120
+ * Workaround for Next.js where different contexts use separate
121
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
122
+ * `instanceof` checks across contexts.
123
+ *
124
+ * This is particularly problematic with "Optimized SSR", where orpc-client
125
+ * executes in one context but is invoked from another. When an error is thrown
126
+ * in the execution context, `instanceof ORPCError` checks fail in the
127
+ * invocation context due to separate class constructors.
128
+ *
129
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
130
+ */
131
+ static [Symbol.hasInstance](instance) {
132
+ if (globalORPCErrorConstructors.has(this)) {
133
+ const constructor = getConstructor(instance);
134
+ if (constructor && globalORPCErrorConstructors.has(constructor)) {
135
+ return true;
136
+ }
137
+ }
138
+ return super[Symbol.hasInstance](instance);
139
+ }
140
+ }
141
+ globalORPCErrorConstructors.add(ORPCError);
142
+ function isDefinedError(error) {
143
+ return error instanceof ORPCError && error.defined;
144
+ }
145
+ function toORPCError(error) {
146
+ return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
147
+ message: "Internal server error",
148
+ cause: error
149
+ });
150
+ }
151
+ function isORPCErrorStatus(status) {
152
+ return status < 200 || status >= 400;
153
+ }
154
+ function isORPCErrorJson(json) {
155
+ if (!isObject(json)) {
156
+ return false;
157
+ }
158
+ const validKeys = ["defined", "code", "status", "message", "data"];
159
+ if (Object.keys(json).some((k) => !validKeys.includes(k))) {
160
+ return false;
161
+ }
162
+ return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string";
163
+ }
164
+ function createORPCErrorFromJson(json, options = {}) {
165
+ return new ORPCError(json.code, {
166
+ ...options,
167
+ ...json
168
+ });
169
+ }
170
+
171
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t };
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.f22c7ec",
4
+ "version": "0.0.0-next.f397ca2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,35 +15,50 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
+ },
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
26
+ },
27
+ "./standard": {
28
+ "types": "./dist/adapters/standard/index.d.mts",
29
+ "import": "./dist/adapters/standard/index.mjs",
30
+ "default": "./dist/adapters/standard/index.mjs"
21
31
  },
22
32
  "./fetch": {
23
- "types": "./dist/src/adapters/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
33
+ "types": "./dist/adapters/fetch/index.d.mts",
34
+ "import": "./dist/adapters/fetch/index.mjs",
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"
26
41
  },
27
- "./🔒/*": {
28
- "types": "./dist/src/*.d.ts"
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"
29
46
  }
30
47
  },
31
48
  "files": [
32
- "!**/*.map",
33
- "!**/*.tsbuildinfo",
34
49
  "dist"
35
50
  ],
36
51
  "dependencies": {
37
- "@orpc/contract": "0.0.0-next.f22c7ec",
38
- "@orpc/server": "0.0.0-next.f22c7ec",
39
- "@orpc/shared": "0.0.0-next.f22c7ec"
52
+ "@orpc/shared": "0.0.0-next.f397ca2",
53
+ "@orpc/standard-server": "0.0.0-next.f397ca2",
54
+ "@orpc/standard-server-fetch": "0.0.0-next.f397ca2",
55
+ "@orpc/standard-server-peer": "0.0.0-next.f397ca2"
40
56
  },
41
57
  "devDependencies": {
42
- "zod": "^3.24.1",
43
- "@orpc/openapi": "0.0.0-next.f22c7ec"
58
+ "zod": "^4.1.12"
44
59
  },
45
60
  "scripts": {
46
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
61
+ "build": "unbuild",
47
62
  "build:watch": "pnpm run build --watch",
48
63
  "type:check": "tsc -b"
49
64
  }
package/dist/fetch.js DELETED
@@ -1,89 +0,0 @@
1
- // src/adapters/fetch/orpc-link.ts
2
- import { ORPCError } from "@orpc/contract";
3
- import { ORPCPayloadCodec } from "@orpc/server/fetch";
4
- import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
5
- var RPCLink = class {
6
- fetch;
7
- payloadCodec;
8
- maxURLLength;
9
- fallbackMethod;
10
- getMethod;
11
- getHeaders;
12
- url;
13
- constructor(options) {
14
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
15
- this.payloadCodec = options.payloadCodec ?? new ORPCPayloadCodec();
16
- this.maxURLLength = options.maxURLLength ?? 2083;
17
- this.fallbackMethod = options.fallbackMethod ?? "POST";
18
- this.url = options.url;
19
- this.getMethod = async (path, input, context) => {
20
- return await options.method?.(path, input, context) ?? this.fallbackMethod;
21
- };
22
- this.getHeaders = async (path, input, context) => {
23
- return new Headers(await options.headers?.(path, input, context));
24
- };
25
- }
26
- async call(path, input, options) {
27
- const clientContext = options.context;
28
- const encoded = await this.encode(path, input, options);
29
- const response = await this.fetch(encoded.url, {
30
- method: encoded.method,
31
- headers: encoded.headers,
32
- body: encoded.body,
33
- signal: options.signal
34
- }, clientContext);
35
- const decoded = await this.payloadCodec.decode(response);
36
- if (!response.ok) {
37
- if (ORPCError.isValidJSON(decoded)) {
38
- throw new ORPCError(decoded);
39
- }
40
- throw new ORPCError({
41
- status: response.status,
42
- code: "INTERNAL_SERVER_ERROR",
43
- message: "Internal server error",
44
- cause: decoded
45
- });
46
- }
47
- return decoded;
48
- }
49
- async encode(path, input, options) {
50
- const clientContext = options.context;
51
- const expectMethod = await this.getMethod(path, input, clientContext);
52
- const methods = /* @__PURE__ */ new Set([expectMethod, this.fallbackMethod]);
53
- const baseHeaders = await this.getHeaders(path, input, clientContext);
54
- const baseUrl = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
55
- baseHeaders.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
56
- for (const method of methods) {
57
- const url = new URL(baseUrl);
58
- const headers = new Headers(baseHeaders);
59
- const encoded = this.payloadCodec.encode(input, method, this.fallbackMethod);
60
- if (encoded.query) {
61
- for (const [key, value] of encoded.query.entries()) {
62
- url.searchParams.append(key, value);
63
- }
64
- }
65
- if (url.toString().length > this.maxURLLength) {
66
- continue;
67
- }
68
- if (encoded.headers) {
69
- for (const [key, value] of encoded.headers.entries()) {
70
- headers.append(key, value);
71
- }
72
- }
73
- return {
74
- url,
75
- headers,
76
- method: encoded.method,
77
- body: encoded.body
78
- };
79
- }
80
- throw new ORPCError({
81
- code: "BAD_REQUEST",
82
- message: "Cannot encode the request, please check the url length or payload."
83
- });
84
- }
85
- };
86
- export {
87
- RPCLink
88
- };
89
- //# sourceMappingURL=fetch.js.map
package/dist/index.js DELETED
@@ -1,42 +0,0 @@
1
- // src/client.ts
2
- function createORPCClient(link, options) {
3
- const path = options?.path ?? [];
4
- const procedureClient = async (...[input, options2]) => {
5
- return await link.call(path, input, options2 ?? {});
6
- };
7
- const recursive = new Proxy(procedureClient, {
8
- get(target, key) {
9
- if (typeof key !== "string") {
10
- return Reflect.get(target, key);
11
- }
12
- return createORPCClient(link, {
13
- ...options,
14
- path: [...path, key]
15
- });
16
- }
17
- });
18
- return recursive;
19
- }
20
-
21
- // src/dynamic-link.ts
22
- var DynamicLink = class {
23
- constructor(linkResolver) {
24
- this.linkResolver = linkResolver;
25
- }
26
- async call(path, input, options) {
27
- const resolvedLink = await this.linkResolver(path, input, options.context);
28
- const output = await resolvedLink.call(path, input, options);
29
- return output;
30
- }
31
- };
32
-
33
- // src/index.ts
34
- import { isDefinedError, ORPCError, safe } from "@orpc/contract";
35
- export {
36
- DynamicLink,
37
- ORPCError,
38
- createORPCClient,
39
- isDefinedError,
40
- safe
41
- };
42
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- export * from './orpc-link';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map