@orpc/client 0.0.0-next.7e904b4 → 0.0.0-next.7eaeef7
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 +29 -21
- package/dist/adapters/fetch/index.d.mts +33 -0
- package/dist/adapters/fetch/index.d.ts +33 -0
- package/dist/adapters/fetch/index.mjs +29 -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 +71 -0
- package/dist/adapters/standard/index.d.mts +10 -0
- package/dist/adapters/standard/index.d.ts +10 -0
- package/dist/adapters/standard/index.mjs +4 -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 +44 -0
- package/dist/index.d.mts +185 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.mjs +82 -0
- package/dist/plugins/index.d.mts +202 -0
- package/dist/plugins/index.d.ts +202 -0
- package/dist/plugins/index.mjs +389 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.BngOL3Ai.mjs +173 -0
- package/dist/shared/client.BvXDSBF5.mjs +355 -0
- package/dist/shared/client.C4VxIexA.d.mts +46 -0
- package/dist/shared/client.CXXEPIbK.d.ts +46 -0
- package/dist/shared/client.WCinBImJ.d.ts +91 -0
- package/dist/shared/client.aTp4sII-.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,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.CXXEPIbK.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>, [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.C4VxIexA.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>, [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.7eaeef7",
|
|
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/server-
|
|
49
|
-
"@orpc/shared": "0.0.0-next.
|
|
52
|
+
"@orpc/standard-server": "0.0.0-next.7eaeef7",
|
|
53
|
+
"@orpc/standard-server-fetch": "0.0.0-next.7eaeef7",
|
|
54
|
+
"@orpc/shared": "0.0.0-next.7eaeef7",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.7eaeef7"
|
|
50
56
|
},
|
|
51
57
|
"devDependencies": {
|
|
52
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.0.14"
|
|
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
|