@orpc/client 0.0.0-next.c40b544 → 0.0.0-next.c462bb4
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.
- package/README.md +7 -2
- package/dist/adapters/fetch/index.d.mts +23 -10
- package/dist/adapters/fetch/index.d.ts +23 -10
- package/dist/adapters/fetch/index.mjs +25 -8
- package/dist/adapters/message-port/index.d.mts +36 -15
- package/dist/adapters/message-port/index.d.ts +36 -15
- package/dist/adapters/message-port/index.mjs +30 -14
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +4 -2
- package/dist/adapters/websocket/index.d.mts +11 -11
- package/dist/adapters/websocket/index.d.ts +11 -11
- package/dist/adapters/websocket/index.mjs +13 -10
- package/dist/index.d.mts +86 -25
- package/dist/index.d.ts +86 -25
- package/dist/index.mjs +54 -7
- package/dist/plugins/index.d.mts +52 -5
- package/dist/plugins/index.d.ts +52 -5
- package/dist/plugins/index.mjs +121 -25
- package/dist/shared/{client.CQCGVpTM.mjs → client.A0J6mgVq.mjs} +63 -20
- package/dist/shared/client.BH1AYT_p.d.mts +83 -0
- package/dist/shared/client.BH1AYT_p.d.ts +83 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/{client.7UM0t5o-.d.ts → client.BxV-mzeR.d.ts} +3 -3
- package/dist/shared/{client.C0KbSWlC.d.ts → client.CPgZaUox.d.mts} +1 -2
- package/dist/shared/{client.BdD8cpjs.d.mts → client.D8lMmWVC.d.mts} +3 -3
- package/dist/shared/{client.BX0_8bnM.mjs → client.DL-GilqA.mjs} +37 -38
- package/dist/shared/{client.BMoG_EdN.d.mts → client.De8SW4Kw.d.ts} +1 -2
- package/package.json +6 -6
- package/dist/shared/client.4TS_0JaO.d.mts +0 -29
- package/dist/shared/client.4TS_0JaO.d.ts +0 -29
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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.c462bb4";
|
|
3
5
|
|
|
4
6
|
const COMMON_ORPC_ERROR_DEFS = {
|
|
5
7
|
BAD_REQUEST: {
|
|
@@ -85,21 +87,25 @@ function fallbackORPCErrorStatus(code, status) {
|
|
|
85
87
|
function fallbackORPCErrorMessage(code, message) {
|
|
86
88
|
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
87
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];
|
|
88
93
|
class ORPCError extends Error {
|
|
89
94
|
defined;
|
|
90
95
|
code;
|
|
91
96
|
status;
|
|
92
97
|
data;
|
|
93
|
-
constructor(code, ...
|
|
94
|
-
|
|
98
|
+
constructor(code, ...rest) {
|
|
99
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
100
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
95
101
|
throw new Error("[ORPCError] Invalid error status code.");
|
|
96
102
|
}
|
|
97
|
-
const message = fallbackORPCErrorMessage(code, options
|
|
103
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
98
104
|
super(message, options);
|
|
99
105
|
this.code = code;
|
|
100
|
-
this.status = fallbackORPCErrorStatus(code, options
|
|
101
|
-
this.defined = options
|
|
102
|
-
this.data = options
|
|
106
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
107
|
+
this.defined = options.defined ?? false;
|
|
108
|
+
this.data = options.data;
|
|
103
109
|
}
|
|
104
110
|
toJSON() {
|
|
105
111
|
return {
|
|
@@ -110,7 +116,29 @@ class ORPCError extends Error {
|
|
|
110
116
|
data: this.data
|
|
111
117
|
};
|
|
112
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
|
+
}
|
|
113
140
|
}
|
|
141
|
+
globalORPCErrorConstructors.add(ORPCError);
|
|
114
142
|
function isDefinedError(error) {
|
|
115
143
|
return error instanceof ORPCError && error.defined;
|
|
116
144
|
}
|
|
@@ -140,33 +168,4 @@ function createORPCErrorFromJson(json, options = {}) {
|
|
|
140
168
|
});
|
|
141
169
|
}
|
|
142
170
|
|
|
143
|
-
|
|
144
|
-
return new AsyncIteratorClass(async () => {
|
|
145
|
-
try {
|
|
146
|
-
const { done, value } = await iterator.next();
|
|
147
|
-
let mappedValue = await maps.value(value, done);
|
|
148
|
-
if (mappedValue !== value) {
|
|
149
|
-
const meta = getEventMeta(value);
|
|
150
|
-
if (meta && isTypescriptObject(mappedValue)) {
|
|
151
|
-
mappedValue = withEventMeta(mappedValue, meta);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return { done, value: mappedValue };
|
|
155
|
-
} catch (error) {
|
|
156
|
-
let mappedError = await maps.error(error);
|
|
157
|
-
if (mappedError !== error) {
|
|
158
|
-
const meta = getEventMeta(error);
|
|
159
|
-
if (meta && isTypescriptObject(mappedError)) {
|
|
160
|
-
mappedError = withEventMeta(mappedError, meta);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
throw mappedError;
|
|
164
|
-
}
|
|
165
|
-
}, async (reason) => {
|
|
166
|
-
if (reason !== "next") {
|
|
167
|
-
await iterator.return?.();
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, isORPCErrorJson as c, createORPCErrorFromJson as d, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
|
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Interceptor } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.js';
|
|
4
4
|
|
|
5
5
|
interface StandardLinkPlugin<T extends ClientContext> {
|
|
6
6
|
order?: number;
|
|
@@ -33,7 +33,6 @@ interface StandardLinkOptions<T extends ClientContext> {
|
|
|
33
33
|
plugins?: StandardLinkPlugin<T>[];
|
|
34
34
|
}
|
|
35
35
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
|
-
#private;
|
|
37
36
|
readonly codec: StandardLinkCodec<T>;
|
|
38
37
|
readonly sender: StandardLinkClient<T>;
|
|
39
38
|
private readonly interceptors;
|
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.
|
|
4
|
+
"version": "0.0.0-next.c462bb4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"dist"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
53
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
|
54
|
-
"@orpc/shared": "0.0.0-next.
|
|
55
|
-
"@orpc/standard-server-peer": "0.0.0-next.
|
|
52
|
+
"@orpc/standard-server": "0.0.0-next.c462bb4",
|
|
53
|
+
"@orpc/standard-server-fetch": "0.0.0-next.c462bb4",
|
|
54
|
+
"@orpc/shared": "0.0.0-next.c462bb4",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.c462bb4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.1.12"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "unbuild",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
type HTTPPath = `/${string}`;
|
|
4
|
-
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
-
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
-
interface ClientOptions<T extends ClientContext> {
|
|
7
|
-
signal?: AbortSignal;
|
|
8
|
-
lastEventId?: string | undefined;
|
|
9
|
-
context: T;
|
|
10
|
-
}
|
|
11
|
-
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
-
context?: T;
|
|
13
|
-
} : {
|
|
14
|
-
context: T;
|
|
15
|
-
});
|
|
16
|
-
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>];
|
|
17
|
-
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
-
}
|
|
21
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
-
[k: string]: NestedClient<TClientContext>;
|
|
23
|
-
};
|
|
24
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
-
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
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,29 +0,0 @@
|
|
|
1
|
-
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
type HTTPPath = `/${string}`;
|
|
4
|
-
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
-
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
-
interface ClientOptions<T extends ClientContext> {
|
|
7
|
-
signal?: AbortSignal;
|
|
8
|
-
lastEventId?: string | undefined;
|
|
9
|
-
context: T;
|
|
10
|
-
}
|
|
11
|
-
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
-
context?: T;
|
|
13
|
-
} : {
|
|
14
|
-
context: T;
|
|
15
|
-
});
|
|
16
|
-
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>];
|
|
17
|
-
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
-
}
|
|
21
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
-
[k: string]: NestedClient<TClientContext>;
|
|
23
|
-
};
|
|
24
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
-
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
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 };
|