@orpc/client 0.0.0-next.f17a1a0 → 0.0.0-next.f21e305
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 +31 -21
- package/dist/adapters/fetch/index.d.mts +46 -0
- package/dist/adapters/fetch/index.d.ts +46 -0
- package/dist/adapters/fetch/index.mjs +45 -0
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +72 -0
- package/dist/adapters/standard/index.d.mts +11 -0
- package/dist/adapters/standard/index.d.ts +11 -0
- package/dist/adapters/standard/index.mjs +5 -0
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +46 -0
- package/dist/index.d.mts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.mjs +111 -0
- package/dist/plugins/index.d.mts +202 -0
- package/dist/plugins/index.d.ts +202 -0
- package/dist/plugins/index.mjs +406 -0
- package/dist/shared/client.BG98rYdO.d.ts +45 -0
- package/dist/shared/client.BIYmXux0.mjs +397 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.Bwgm6dgk.d.mts +45 -0
- package/dist/shared/client.C9Q9FzmH.mjs +208 -0
- package/dist/shared/client.CVVVqf1Y.d.ts +91 -0
- package/dist/shared/client._Y_enhib.d.mts +91 -0
- package/package.json +30 -24
- package/dist/chunk-4FUUNP74.js +0 -212
- package/dist/chunk-OGAGXWCU.js +0 -281
- package/dist/fetch.js +0 -128
- package/dist/index.js +0 -81
- package/dist/openapi.js +0 -231
- package/dist/rpc.js +0 -10
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
- package/dist/src/adapters/fetch/types.d.ts +0 -5
- package/dist/src/client.d.ts +0 -9
- package/dist/src/dynamic-link.d.ts +0 -12
- package/dist/src/error.d.ts +0 -106
- package/dist/src/event-iterator-state.d.ts +0 -9
- package/dist/src/event-iterator.d.ts +0 -12
- package/dist/src/index.d.ts +0 -9
- package/dist/src/openapi/bracket-notation.d.ts +0 -9
- package/dist/src/openapi/index.d.ts +0 -4
- package/dist/src/openapi/json-serializer.d.ts +0 -7
- package/dist/src/openapi/serializer.d.ts +0 -11
- package/dist/src/rpc/index.d.ts +0 -3
- package/dist/src/rpc/json-serializer.d.ts +0 -12
- package/dist/src/rpc/serializer.d.ts +0 -9
- package/dist/src/types.d.ts +0 -29
- package/dist/src/utils.d.ts +0 -5
@@ -0,0 +1,208 @@
|
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
2
|
+
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
3
|
+
|
4
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
5
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.f21e305";
|
6
|
+
|
7
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
8
|
+
BAD_REQUEST: {
|
9
|
+
status: 400,
|
10
|
+
message: "Bad Request"
|
11
|
+
},
|
12
|
+
UNAUTHORIZED: {
|
13
|
+
status: 401,
|
14
|
+
message: "Unauthorized"
|
15
|
+
},
|
16
|
+
FORBIDDEN: {
|
17
|
+
status: 403,
|
18
|
+
message: "Forbidden"
|
19
|
+
},
|
20
|
+
NOT_FOUND: {
|
21
|
+
status: 404,
|
22
|
+
message: "Not Found"
|
23
|
+
},
|
24
|
+
METHOD_NOT_SUPPORTED: {
|
25
|
+
status: 405,
|
26
|
+
message: "Method Not Supported"
|
27
|
+
},
|
28
|
+
NOT_ACCEPTABLE: {
|
29
|
+
status: 406,
|
30
|
+
message: "Not Acceptable"
|
31
|
+
},
|
32
|
+
TIMEOUT: {
|
33
|
+
status: 408,
|
34
|
+
message: "Request Timeout"
|
35
|
+
},
|
36
|
+
CONFLICT: {
|
37
|
+
status: 409,
|
38
|
+
message: "Conflict"
|
39
|
+
},
|
40
|
+
PRECONDITION_FAILED: {
|
41
|
+
status: 412,
|
42
|
+
message: "Precondition Failed"
|
43
|
+
},
|
44
|
+
PAYLOAD_TOO_LARGE: {
|
45
|
+
status: 413,
|
46
|
+
message: "Payload Too Large"
|
47
|
+
},
|
48
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
49
|
+
status: 415,
|
50
|
+
message: "Unsupported Media Type"
|
51
|
+
},
|
52
|
+
UNPROCESSABLE_CONTENT: {
|
53
|
+
status: 422,
|
54
|
+
message: "Unprocessable Content"
|
55
|
+
},
|
56
|
+
TOO_MANY_REQUESTS: {
|
57
|
+
status: 429,
|
58
|
+
message: "Too Many Requests"
|
59
|
+
},
|
60
|
+
CLIENT_CLOSED_REQUEST: {
|
61
|
+
status: 499,
|
62
|
+
message: "Client Closed Request"
|
63
|
+
},
|
64
|
+
INTERNAL_SERVER_ERROR: {
|
65
|
+
status: 500,
|
66
|
+
message: "Internal Server Error"
|
67
|
+
},
|
68
|
+
NOT_IMPLEMENTED: {
|
69
|
+
status: 501,
|
70
|
+
message: "Not Implemented"
|
71
|
+
},
|
72
|
+
BAD_GATEWAY: {
|
73
|
+
status: 502,
|
74
|
+
message: "Bad Gateway"
|
75
|
+
},
|
76
|
+
SERVICE_UNAVAILABLE: {
|
77
|
+
status: 503,
|
78
|
+
message: "Service Unavailable"
|
79
|
+
},
|
80
|
+
GATEWAY_TIMEOUT: {
|
81
|
+
status: 504,
|
82
|
+
message: "Gateway Timeout"
|
83
|
+
}
|
84
|
+
};
|
85
|
+
function fallbackORPCErrorStatus(code, status) {
|
86
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
87
|
+
}
|
88
|
+
function fallbackORPCErrorMessage(code, message) {
|
89
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
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];
|
94
|
+
class ORPCError extends Error {
|
95
|
+
defined;
|
96
|
+
code;
|
97
|
+
status;
|
98
|
+
data;
|
99
|
+
constructor(code, ...rest) {
|
100
|
+
const options = resolveMaybeOptionalOptions(rest);
|
101
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
102
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
103
|
+
}
|
104
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
105
|
+
super(message, options);
|
106
|
+
this.code = code;
|
107
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
108
|
+
this.defined = options.defined ?? false;
|
109
|
+
this.data = options.data;
|
110
|
+
}
|
111
|
+
toJSON() {
|
112
|
+
return {
|
113
|
+
defined: this.defined,
|
114
|
+
code: this.code,
|
115
|
+
status: this.status,
|
116
|
+
message: this.message,
|
117
|
+
data: this.data
|
118
|
+
};
|
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
|
+
}
|
141
|
+
}
|
142
|
+
globalORPCErrorConstructors.add(ORPCError);
|
143
|
+
function isDefinedError(error) {
|
144
|
+
return error instanceof ORPCError && error.defined;
|
145
|
+
}
|
146
|
+
function toORPCError(error) {
|
147
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
148
|
+
message: "Internal server error",
|
149
|
+
cause: error
|
150
|
+
});
|
151
|
+
}
|
152
|
+
function isORPCErrorStatus(status) {
|
153
|
+
return status < 200 || status >= 400;
|
154
|
+
}
|
155
|
+
function isORPCErrorJson(json) {
|
156
|
+
if (!isObject(json)) {
|
157
|
+
return false;
|
158
|
+
}
|
159
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
160
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
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";
|
164
|
+
}
|
165
|
+
function createORPCErrorFromJson(json, options = {}) {
|
166
|
+
return new ORPCError(json.code, {
|
167
|
+
...options,
|
168
|
+
...json
|
169
|
+
});
|
170
|
+
}
|
171
|
+
|
172
|
+
function mapEventIterator(iterator, maps) {
|
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);
|
179
|
+
}
|
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);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
return { done, value: mappedValue };
|
199
|
+
}, async () => {
|
200
|
+
try {
|
201
|
+
await iterator.return?.();
|
202
|
+
} catch (error) {
|
203
|
+
throw await mapError(error);
|
204
|
+
}
|
205
|
+
});
|
206
|
+
}
|
207
|
+
|
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 };
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.js';
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BG98rYdO.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,91 @@
|
|
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
|
+
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 };
|
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.f21e305",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,44 +15,50 @@
|
|
15
15
|
],
|
16
16
|
"exports": {
|
17
17
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
18
|
+
"types": "./dist/index.d.mts",
|
19
|
+
"import": "./dist/index.mjs",
|
20
|
+
"default": "./dist/index.mjs"
|
21
21
|
},
|
22
|
-
"./
|
23
|
-
"types": "./dist/
|
24
|
-
"import": "./dist/
|
25
|
-
"default": "./dist/
|
22
|
+
"./plugins": {
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
26
26
|
},
|
27
|
-
"./
|
28
|
-
"types": "./dist/
|
29
|
-
"import": "./dist/
|
30
|
-
"default": "./dist/
|
27
|
+
"./standard": {
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
31
31
|
},
|
32
32
|
"./fetch": {
|
33
|
-
"types": "./dist/
|
34
|
-
"import": "./dist/fetch.
|
35
|
-
"default": "./dist/fetch.
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
36
36
|
},
|
37
|
-
"
|
38
|
-
"types": "./dist/
|
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"
|
39
46
|
}
|
40
47
|
},
|
41
48
|
"files": [
|
42
|
-
"!**/*.map",
|
43
|
-
"!**/*.tsbuildinfo",
|
44
49
|
"dist"
|
45
50
|
],
|
46
51
|
"dependencies": {
|
47
|
-
"@orpc/server
|
48
|
-
"@orpc/
|
49
|
-
"@orpc/
|
52
|
+
"@orpc/standard-server": "0.0.0-next.f21e305",
|
53
|
+
"@orpc/shared": "0.0.0-next.f21e305",
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.f21e305",
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.f21e305"
|
50
56
|
},
|
51
57
|
"devDependencies": {
|
52
|
-
"zod": "^
|
58
|
+
"zod": "^4.1.5"
|
53
59
|
},
|
54
60
|
"scripts": {
|
55
|
-
"build": "
|
61
|
+
"build": "unbuild",
|
56
62
|
"build:watch": "pnpm run build --watch",
|
57
63
|
"type:check": "tsc -b"
|
58
64
|
}
|
package/dist/chunk-4FUUNP74.js
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
ORPCError,
|
3
|
-
mapEventIterator,
|
4
|
-
toORPCError
|
5
|
-
} from "./chunk-OGAGXWCU.js";
|
6
|
-
|
7
|
-
// src/rpc/json-serializer.ts
|
8
|
-
import { isObject } from "@orpc/shared";
|
9
|
-
var RPCJsonSerializer = class {
|
10
|
-
serialize(data, segments = [], meta = [], maps = [], blobs = []) {
|
11
|
-
if (data instanceof Blob) {
|
12
|
-
maps.push(segments);
|
13
|
-
blobs.push(data);
|
14
|
-
return [data, meta, maps, blobs];
|
15
|
-
}
|
16
|
-
if (typeof data === "bigint") {
|
17
|
-
meta.push([0, segments]);
|
18
|
-
return [data.toString(), meta, maps, blobs];
|
19
|
-
}
|
20
|
-
if (data instanceof Date) {
|
21
|
-
meta.push([1, segments]);
|
22
|
-
if (Number.isNaN(data.getTime())) {
|
23
|
-
return [null, meta, maps, blobs];
|
24
|
-
}
|
25
|
-
return [data.toISOString(), meta, maps, blobs];
|
26
|
-
}
|
27
|
-
if (Number.isNaN(data)) {
|
28
|
-
meta.push([2, segments]);
|
29
|
-
return [null, meta, maps, blobs];
|
30
|
-
}
|
31
|
-
if (data instanceof URL) {
|
32
|
-
meta.push([4, segments]);
|
33
|
-
return [data.toString(), meta, maps, blobs];
|
34
|
-
}
|
35
|
-
if (data instanceof RegExp) {
|
36
|
-
meta.push([5, segments]);
|
37
|
-
return [data.toString(), meta, maps, blobs];
|
38
|
-
}
|
39
|
-
if (data instanceof Set) {
|
40
|
-
const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
|
41
|
-
meta.push([6, segments]);
|
42
|
-
return result;
|
43
|
-
}
|
44
|
-
if (data instanceof Map) {
|
45
|
-
const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
|
46
|
-
meta.push([7, segments]);
|
47
|
-
return result;
|
48
|
-
}
|
49
|
-
if (Array.isArray(data)) {
|
50
|
-
const json = data.map((v, i) => {
|
51
|
-
if (v === void 0) {
|
52
|
-
meta.push([3, [...segments, i]]);
|
53
|
-
return v;
|
54
|
-
}
|
55
|
-
return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
|
56
|
-
});
|
57
|
-
return [json, meta, maps, blobs];
|
58
|
-
}
|
59
|
-
if (isObject(data)) {
|
60
|
-
const json = {};
|
61
|
-
for (const k in data) {
|
62
|
-
json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
|
63
|
-
}
|
64
|
-
return [json, meta, maps, blobs];
|
65
|
-
}
|
66
|
-
return [data, meta, maps, blobs];
|
67
|
-
}
|
68
|
-
deserialize(json, meta, maps, getBlob) {
|
69
|
-
const ref = { data: json };
|
70
|
-
if (maps && getBlob) {
|
71
|
-
maps.forEach((segments, i) => {
|
72
|
-
let currentRef = ref;
|
73
|
-
let preSegment = "data";
|
74
|
-
segments.forEach((segment) => {
|
75
|
-
currentRef = currentRef[preSegment];
|
76
|
-
preSegment = segment;
|
77
|
-
});
|
78
|
-
currentRef[preSegment] = getBlob(i);
|
79
|
-
});
|
80
|
-
}
|
81
|
-
for (const [type, segments] of meta) {
|
82
|
-
let currentRef = ref;
|
83
|
-
let preSegment = "data";
|
84
|
-
segments.forEach((segment) => {
|
85
|
-
currentRef = currentRef[preSegment];
|
86
|
-
preSegment = segment;
|
87
|
-
});
|
88
|
-
switch (type) {
|
89
|
-
case 0:
|
90
|
-
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
91
|
-
break;
|
92
|
-
case 1:
|
93
|
-
currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
|
94
|
-
break;
|
95
|
-
case 2:
|
96
|
-
currentRef[preSegment] = Number.NaN;
|
97
|
-
break;
|
98
|
-
case 3:
|
99
|
-
currentRef[preSegment] = void 0;
|
100
|
-
break;
|
101
|
-
case 4:
|
102
|
-
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
103
|
-
break;
|
104
|
-
case 5: {
|
105
|
-
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
106
|
-
currentRef[preSegment] = new RegExp(pattern, flags);
|
107
|
-
break;
|
108
|
-
}
|
109
|
-
case 6:
|
110
|
-
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
111
|
-
break;
|
112
|
-
case 7:
|
113
|
-
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
114
|
-
break;
|
115
|
-
/* v8 ignore next 3 */
|
116
|
-
default: {
|
117
|
-
const _expected = type;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
return ref.data;
|
122
|
-
}
|
123
|
-
};
|
124
|
-
|
125
|
-
// src/rpc/serializer.ts
|
126
|
-
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
|
127
|
-
var RPCSerializer = class {
|
128
|
-
constructor(jsonSerializer = new RPCJsonSerializer()) {
|
129
|
-
this.jsonSerializer = jsonSerializer;
|
130
|
-
}
|
131
|
-
serialize(data) {
|
132
|
-
if (isAsyncIteratorObject(data)) {
|
133
|
-
return mapEventIterator(data, {
|
134
|
-
value: async (value) => this.#serialize(value, false),
|
135
|
-
error: async (e) => {
|
136
|
-
if (e instanceof ErrorEvent) {
|
137
|
-
return new ErrorEvent({
|
138
|
-
data: this.#serialize(e.data, false),
|
139
|
-
cause: e
|
140
|
-
});
|
141
|
-
}
|
142
|
-
return new ErrorEvent({
|
143
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
144
|
-
cause: e
|
145
|
-
});
|
146
|
-
}
|
147
|
-
});
|
148
|
-
}
|
149
|
-
return this.#serialize(data, true);
|
150
|
-
}
|
151
|
-
#serialize(data, enableFormData) {
|
152
|
-
if (data === void 0 || data instanceof Blob) {
|
153
|
-
return data;
|
154
|
-
}
|
155
|
-
const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
|
156
|
-
const meta = meta_.length === 0 ? void 0 : meta_;
|
157
|
-
if (!enableFormData || blobs.length === 0) {
|
158
|
-
return {
|
159
|
-
json,
|
160
|
-
meta
|
161
|
-
};
|
162
|
-
}
|
163
|
-
const form = new FormData();
|
164
|
-
form.set("data", JSON.stringify({ json, meta, maps }));
|
165
|
-
blobs.forEach((blob, i) => {
|
166
|
-
form.set(i.toString(), blob);
|
167
|
-
});
|
168
|
-
return form;
|
169
|
-
}
|
170
|
-
deserialize(data) {
|
171
|
-
if (isAsyncIteratorObject(data)) {
|
172
|
-
return mapEventIterator(data, {
|
173
|
-
value: async (value) => this.#deserialize(value),
|
174
|
-
error: async (e) => {
|
175
|
-
if (!(e instanceof ErrorEvent)) {
|
176
|
-
return e;
|
177
|
-
}
|
178
|
-
const deserialized = this.#deserialize(e.data);
|
179
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
180
|
-
return ORPCError.fromJSON(deserialized, { cause: e });
|
181
|
-
}
|
182
|
-
return new ErrorEvent({
|
183
|
-
data: deserialized,
|
184
|
-
cause: e
|
185
|
-
});
|
186
|
-
}
|
187
|
-
});
|
188
|
-
}
|
189
|
-
return this.#deserialize(data);
|
190
|
-
}
|
191
|
-
#deserialize(data) {
|
192
|
-
if (data === void 0 || data instanceof Blob) {
|
193
|
-
return data;
|
194
|
-
}
|
195
|
-
if (!(data instanceof FormData)) {
|
196
|
-
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
197
|
-
}
|
198
|
-
const serialized = JSON.parse(data.get("data"));
|
199
|
-
return this.jsonSerializer.deserialize(
|
200
|
-
serialized.json,
|
201
|
-
serialized.meta ?? [],
|
202
|
-
serialized.maps,
|
203
|
-
(i) => data.get(i.toString())
|
204
|
-
);
|
205
|
-
}
|
206
|
-
};
|
207
|
-
|
208
|
-
export {
|
209
|
-
RPCJsonSerializer,
|
210
|
-
RPCSerializer
|
211
|
-
};
|
212
|
-
//# sourceMappingURL=chunk-4FUUNP74.js.map
|