@orpc/client 0.0.0-next.fb0d07c → 0.0.0-next.fb5a52a
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 +11 -8
- package/dist/adapters/fetch/index.d.mts +23 -10
- package/dist/adapters/fetch/index.d.ts +23 -10
- package/dist/adapters/fetch/index.mjs +24 -8
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +86 -0
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +3 -2
- package/dist/adapters/websocket/index.d.mts +12 -12
- package/dist/adapters/websocket/index.d.ts +12 -12
- package/dist/adapters/websocket/index.mjs +26 -11
- package/dist/index.d.mts +86 -25
- package/dist/index.d.ts +86 -25
- package/dist/index.mjs +54 -8
- package/dist/plugins/index.d.mts +47 -6
- package/dist/plugins/index.d.ts +47 -6
- package/dist/plugins/index.mjs +143 -27
- package/dist/shared/client.BH1AYT_p.d.mts +83 -0
- package/dist/shared/client.BH1AYT_p.d.ts +83 -0
- package/dist/shared/{client.DpICn1BD.mjs → client.Bqv3Fq2U.mjs} +62 -20
- 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.CRWEpqLB.mjs → client.DJGGl6U1.mjs} +66 -33
- package/dist/shared/{client.BMoG_EdN.d.mts → client.De8SW4Kw.d.ts} +1 -2
- package/package.json +11 -6
- package/dist/shared/client.4TS_0JaO.d.mts +0 -29
- package/dist/shared/client.4TS_0JaO.d.ts +0 -29
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { isObject, isTypescriptObject } from '@orpc/shared';
|
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
2
|
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
|
5
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.fb5a52a";
|
|
6
|
+
|
|
4
7
|
const COMMON_ORPC_ERROR_DEFS = {
|
|
5
8
|
BAD_REQUEST: {
|
|
6
9
|
status: 400,
|
|
@@ -85,21 +88,25 @@ function fallbackORPCErrorStatus(code, status) {
|
|
|
85
88
|
function fallbackORPCErrorMessage(code, message) {
|
|
86
89
|
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
87
90
|
}
|
|
91
|
+
const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
|
|
92
|
+
void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
|
93
|
+
const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
|
88
94
|
class ORPCError extends Error {
|
|
89
95
|
defined;
|
|
90
96
|
code;
|
|
91
97
|
status;
|
|
92
98
|
data;
|
|
93
|
-
constructor(code, ...
|
|
94
|
-
|
|
99
|
+
constructor(code, ...rest) {
|
|
100
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
101
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
95
102
|
throw new Error("[ORPCError] Invalid error status code.");
|
|
96
103
|
}
|
|
97
|
-
const message = fallbackORPCErrorMessage(code, options
|
|
104
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
98
105
|
super(message, options);
|
|
99
106
|
this.code = code;
|
|
100
|
-
this.status = fallbackORPCErrorStatus(code, options
|
|
101
|
-
this.defined = options
|
|
102
|
-
this.data = options
|
|
107
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
108
|
+
this.defined = options.defined ?? false;
|
|
109
|
+
this.data = options.data;
|
|
103
110
|
}
|
|
104
111
|
toJSON() {
|
|
105
112
|
return {
|
|
@@ -110,7 +117,29 @@ class ORPCError extends Error {
|
|
|
110
117
|
data: this.data
|
|
111
118
|
};
|
|
112
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Workaround for Next.js where different contexts use separate
|
|
122
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
123
|
+
* `instanceof` checks across contexts.
|
|
124
|
+
*
|
|
125
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
126
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
127
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
128
|
+
* invocation context due to separate class constructors.
|
|
129
|
+
*
|
|
130
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
131
|
+
*/
|
|
132
|
+
static [Symbol.hasInstance](instance) {
|
|
133
|
+
if (globalORPCErrorConstructors.has(this)) {
|
|
134
|
+
const constructor = getConstructor(instance);
|
|
135
|
+
if (constructor && globalORPCErrorConstructors.has(constructor)) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return super[Symbol.hasInstance](instance);
|
|
140
|
+
}
|
|
113
141
|
}
|
|
142
|
+
globalORPCErrorConstructors.add(ORPCError);
|
|
114
143
|
function isDefinedError(error) {
|
|
115
144
|
return error instanceof ORPCError && error.defined;
|
|
116
145
|
}
|
|
@@ -141,35 +170,39 @@ function createORPCErrorFromJson(json, options = {}) {
|
|
|
141
170
|
}
|
|
142
171
|
|
|
143
172
|
function mapEventIterator(iterator, maps) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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;
|
|
173
|
+
const mapError = async (error) => {
|
|
174
|
+
let mappedError = await maps.error(error);
|
|
175
|
+
if (mappedError !== error) {
|
|
176
|
+
const meta = getEventMeta(error);
|
|
177
|
+
if (meta && isTypescriptObject(mappedError)) {
|
|
178
|
+
mappedError = withEventMeta(mappedError, meta);
|
|
159
179
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
180
|
+
}
|
|
181
|
+
return mappedError;
|
|
182
|
+
};
|
|
183
|
+
return new AsyncIteratorClass(async () => {
|
|
184
|
+
const { done, value } = await (async () => {
|
|
185
|
+
try {
|
|
186
|
+
return await iterator.next();
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw await mapError(error);
|
|
189
|
+
}
|
|
190
|
+
})();
|
|
191
|
+
let mappedValue = await maps.value(value, done);
|
|
192
|
+
if (mappedValue !== value) {
|
|
193
|
+
const meta = getEventMeta(value);
|
|
194
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
|
195
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
|
167
196
|
}
|
|
168
|
-
|
|
169
|
-
|
|
197
|
+
}
|
|
198
|
+
return { done, value: mappedValue };
|
|
199
|
+
}, async () => {
|
|
200
|
+
try {
|
|
170
201
|
await iterator.return?.();
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw await mapError(error);
|
|
171
204
|
}
|
|
172
|
-
}
|
|
205
|
+
});
|
|
173
206
|
}
|
|
174
207
|
|
|
175
|
-
export { COMMON_ORPC_ERROR_DEFS as C,
|
|
208
|
+
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, mapEventIterator as m, 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.fb5a52a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -38,19 +38,24 @@
|
|
|
38
38
|
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
39
|
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
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"
|
|
41
46
|
}
|
|
42
47
|
},
|
|
43
48
|
"files": [
|
|
44
49
|
"dist"
|
|
45
50
|
],
|
|
46
51
|
"dependencies": {
|
|
47
|
-
"@orpc/shared": "0.0.0-next.
|
|
48
|
-
"@orpc/standard-server
|
|
49
|
-
"@orpc/standard-server-peer": "0.0.0-next.
|
|
50
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
52
|
+
"@orpc/shared": "0.0.0-next.fb5a52a",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.fb5a52a",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.fb5a52a",
|
|
55
|
+
"@orpc/standard-server-fetch": "0.0.0-next.fb5a52a"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|
|
53
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.1.12"
|
|
54
59
|
},
|
|
55
60
|
"scripts": {
|
|
56
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 };
|