@orpc/client 0.0.0-next.84e58e0 → 0.0.0-next.84ea648
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 +27 -97
- package/dist/adapters/fetch/index.d.ts +27 -97
- package/dist/adapters/fetch/index.mjs +20 -112
- 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 +61 -29
- package/dist/index.d.ts +61 -29
- package/dist/index.mjs +54 -35
- 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.C4VxIexA.d.mts +46 -0
- package/dist/shared/client.CXXEPIbK.d.ts +46 -0
- package/dist/shared/client.DHOfWE0c.mjs +172 -0
- package/dist/shared/client.DwfV9Oyl.mjs +355 -0
- package/dist/shared/client.WCinBImJ.d.ts +91 -0
- package/dist/shared/client.aTp4sII-.d.mts +91 -0
- package/package.json +24 -13
- package/dist/openapi/index.d.mts +0 -27
- package/dist/openapi/index.d.ts +0 -27
- package/dist/openapi/index.mjs +0 -213
- package/dist/rpc/index.d.mts +0 -22
- package/dist/rpc/index.d.ts +0 -22
- package/dist/rpc/index.mjs +0 -4
- package/dist/shared/client.DHJ8vRIG.mjs +0 -192
- package/dist/shared/client.D_CzLDyB.d.mts +0 -42
- package/dist/shared/client.D_CzLDyB.d.ts +0 -42
- package/dist/shared/client.Ly4zGQrc.mjs +0 -265
|
@@ -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.84ea648",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,32 +19,43 @@
|
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
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
33
|
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
34
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
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"
|
|
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"
|
|
36
46
|
}
|
|
37
47
|
},
|
|
38
48
|
"files": [
|
|
39
49
|
"dist"
|
|
40
50
|
],
|
|
41
51
|
"dependencies": {
|
|
42
|
-
"@orpc/shared": "0.0.0-next.
|
|
43
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
44
|
-
"@orpc/standard-server-
|
|
52
|
+
"@orpc/shared": "0.0.0-next.84ea648",
|
|
53
|
+
"@orpc/standard-server-fetch": "0.0.0-next.84ea648",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.84ea648",
|
|
55
|
+
"@orpc/standard-server": "0.0.0-next.84ea648"
|
|
45
56
|
},
|
|
46
57
|
"devDependencies": {
|
|
47
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.0.5"
|
|
48
59
|
},
|
|
49
60
|
"scripts": {
|
|
50
61
|
"build": "unbuild",
|
package/dist/openapi/index.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Segment } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
type BracketNotationSerialized = [string, unknown][];
|
|
4
|
-
declare class BracketNotationSerializer {
|
|
5
|
-
serialize(data: unknown, segments?: Segment[], result?: BracketNotationSerialized): BracketNotationSerialized;
|
|
6
|
-
deserialize(serialized: BracketNotationSerialized): unknown;
|
|
7
|
-
stringifyPath(segments: readonly Segment[]): string;
|
|
8
|
-
parsePath(path: string): string[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type OpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
|
|
12
|
-
declare class OpenAPIJsonSerializer {
|
|
13
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
14
|
-
value: boolean;
|
|
15
|
-
}): OpenAPIJsonSerialized;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare class OpenAPISerializer {
|
|
19
|
-
#private;
|
|
20
|
-
private readonly jsonSerializer;
|
|
21
|
-
private readonly bracketNotation;
|
|
22
|
-
constructor(jsonSerializer?: OpenAPIJsonSerializer, bracketNotation?: BracketNotationSerializer);
|
|
23
|
-
serialize(data: unknown): unknown;
|
|
24
|
-
deserialize(data: unknown): unknown;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { type BracketNotationSerialized, BracketNotationSerializer, type OpenAPIJsonSerialized, OpenAPIJsonSerializer, OpenAPISerializer };
|
package/dist/openapi/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Segment } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
type BracketNotationSerialized = [string, unknown][];
|
|
4
|
-
declare class BracketNotationSerializer {
|
|
5
|
-
serialize(data: unknown, segments?: Segment[], result?: BracketNotationSerialized): BracketNotationSerialized;
|
|
6
|
-
deserialize(serialized: BracketNotationSerialized): unknown;
|
|
7
|
-
stringifyPath(segments: readonly Segment[]): string;
|
|
8
|
-
parsePath(path: string): string[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type OpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
|
|
12
|
-
declare class OpenAPIJsonSerializer {
|
|
13
|
-
serialize(data: unknown, hasBlobRef?: {
|
|
14
|
-
value: boolean;
|
|
15
|
-
}): OpenAPIJsonSerialized;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare class OpenAPISerializer {
|
|
19
|
-
#private;
|
|
20
|
-
private readonly jsonSerializer;
|
|
21
|
-
private readonly bracketNotation;
|
|
22
|
-
constructor(jsonSerializer?: OpenAPIJsonSerializer, bracketNotation?: BracketNotationSerializer);
|
|
23
|
-
serialize(data: unknown): unknown;
|
|
24
|
-
deserialize(data: unknown): unknown;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { type BracketNotationSerialized, BracketNotationSerializer, type OpenAPIJsonSerialized, OpenAPIJsonSerializer, OpenAPISerializer };
|
package/dist/openapi/index.mjs
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { isObject, isAsyncIteratorObject } from '@orpc/shared';
|
|
2
|
-
import { ErrorEvent } from '@orpc/standard-server';
|
|
3
|
-
import { m as mapEventIterator, t as toORPCError, O as ORPCError } from '../shared/client.Ly4zGQrc.mjs';
|
|
4
|
-
|
|
5
|
-
class BracketNotationSerializer {
|
|
6
|
-
serialize(data, segments = [], result = []) {
|
|
7
|
-
if (Array.isArray(data)) {
|
|
8
|
-
data.forEach((item, i) => {
|
|
9
|
-
this.serialize(item, [...segments, i], result);
|
|
10
|
-
});
|
|
11
|
-
} else if (isObject(data)) {
|
|
12
|
-
for (const key in data) {
|
|
13
|
-
this.serialize(data[key], [...segments, key], result);
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
result.push([this.stringifyPath(segments), data]);
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
deserialize(serialized) {
|
|
21
|
-
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
22
|
-
const ref = { value: [] };
|
|
23
|
-
for (const [path, value] of serialized) {
|
|
24
|
-
const segments = this.parsePath(path);
|
|
25
|
-
let currentRef = ref;
|
|
26
|
-
let nextSegment = "value";
|
|
27
|
-
segments.forEach((segment, i) => {
|
|
28
|
-
if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
|
|
29
|
-
currentRef[nextSegment] = [];
|
|
30
|
-
}
|
|
31
|
-
if (i !== segments.length - 1) {
|
|
32
|
-
if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
|
|
33
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
if (Array.isArray(currentRef[nextSegment])) {
|
|
37
|
-
if (segment === "") {
|
|
38
|
-
if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
|
|
39
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
if (arrayPushStyles.has(currentRef[nextSegment])) {
|
|
43
|
-
currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
|
|
44
|
-
} else if (!isValidArrayIndex(segment)) {
|
|
45
|
-
currentRef[nextSegment] = { ...currentRef[nextSegment] };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
currentRef = currentRef[nextSegment];
|
|
51
|
-
nextSegment = segment;
|
|
52
|
-
});
|
|
53
|
-
if (Array.isArray(currentRef)) {
|
|
54
|
-
if (nextSegment === "") {
|
|
55
|
-
arrayPushStyles.add(currentRef);
|
|
56
|
-
currentRef.push(value);
|
|
57
|
-
} else {
|
|
58
|
-
currentRef[Number(nextSegment)] = value;
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
currentRef[nextSegment] = value;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return ref.value;
|
|
65
|
-
}
|
|
66
|
-
stringifyPath(segments) {
|
|
67
|
-
return segments.map((segment) => {
|
|
68
|
-
return segment.toString().replace(/[\\[\]]/g, (match) => {
|
|
69
|
-
switch (match) {
|
|
70
|
-
case "\\":
|
|
71
|
-
return "\\\\";
|
|
72
|
-
case "[":
|
|
73
|
-
return "\\[";
|
|
74
|
-
case "]":
|
|
75
|
-
return "\\]";
|
|
76
|
-
/* v8 ignore next 2 */
|
|
77
|
-
default:
|
|
78
|
-
return match;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}).reduce((result, segment, i) => {
|
|
82
|
-
if (i === 0) {
|
|
83
|
-
return segment;
|
|
84
|
-
}
|
|
85
|
-
return `${result}[${segment}]`;
|
|
86
|
-
}, "");
|
|
87
|
-
}
|
|
88
|
-
parsePath(path) {
|
|
89
|
-
const segments = [];
|
|
90
|
-
let inBrackets = false;
|
|
91
|
-
let currentSegment = "";
|
|
92
|
-
let backslashCount = 0;
|
|
93
|
-
for (let i = 0; i < path.length; i++) {
|
|
94
|
-
const char = path[i];
|
|
95
|
-
const nextChar = path[i + 1];
|
|
96
|
-
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
|
|
97
|
-
if (nextChar === void 0) {
|
|
98
|
-
inBrackets = false;
|
|
99
|
-
}
|
|
100
|
-
segments.push(currentSegment);
|
|
101
|
-
currentSegment = "";
|
|
102
|
-
i++;
|
|
103
|
-
} else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
|
|
104
|
-
inBrackets = true;
|
|
105
|
-
segments.push(currentSegment);
|
|
106
|
-
currentSegment = "";
|
|
107
|
-
} else if (char === "\\") {
|
|
108
|
-
backslashCount++;
|
|
109
|
-
} else {
|
|
110
|
-
currentSegment += "\\".repeat(backslashCount / 2) + char;
|
|
111
|
-
backslashCount = 0;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return inBrackets || segments.length === 0 ? [path] : segments;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function isValidArrayIndex(value) {
|
|
118
|
-
return /^0$|^[1-9]\d*$/.test(value);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
class OpenAPIJsonSerializer {
|
|
122
|
-
serialize(data, hasBlobRef = { value: false }) {
|
|
123
|
-
if (data instanceof Blob) {
|
|
124
|
-
hasBlobRef.value = true;
|
|
125
|
-
return [data, hasBlobRef.value];
|
|
126
|
-
}
|
|
127
|
-
if (data instanceof Set) {
|
|
128
|
-
return this.serialize(Array.from(data), hasBlobRef);
|
|
129
|
-
}
|
|
130
|
-
if (data instanceof Map) {
|
|
131
|
-
return this.serialize(Array.from(data.entries()), hasBlobRef);
|
|
132
|
-
}
|
|
133
|
-
if (Array.isArray(data)) {
|
|
134
|
-
const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
|
|
135
|
-
return [json, hasBlobRef.value];
|
|
136
|
-
}
|
|
137
|
-
if (isObject(data)) {
|
|
138
|
-
const json = {};
|
|
139
|
-
for (const k in data) {
|
|
140
|
-
json[k] = this.serialize(data[k], hasBlobRef)[0];
|
|
141
|
-
}
|
|
142
|
-
return [json, hasBlobRef.value];
|
|
143
|
-
}
|
|
144
|
-
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
145
|
-
return [data.toString(), hasBlobRef.value];
|
|
146
|
-
}
|
|
147
|
-
if (data instanceof Date) {
|
|
148
|
-
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
149
|
-
}
|
|
150
|
-
if (Number.isNaN(data)) {
|
|
151
|
-
return [null, hasBlobRef.value];
|
|
152
|
-
}
|
|
153
|
-
return [data, hasBlobRef.value];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
class OpenAPISerializer {
|
|
158
|
-
constructor(jsonSerializer = new OpenAPIJsonSerializer(), bracketNotation = new BracketNotationSerializer()) {
|
|
159
|
-
this.jsonSerializer = jsonSerializer;
|
|
160
|
-
this.bracketNotation = bracketNotation;
|
|
161
|
-
}
|
|
162
|
-
serialize(data) {
|
|
163
|
-
if (isAsyncIteratorObject(data)) {
|
|
164
|
-
return mapEventIterator(data, {
|
|
165
|
-
value: async (value) => this.#serialize(value, false),
|
|
166
|
-
error: async (e) => {
|
|
167
|
-
return new ErrorEvent({
|
|
168
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
|
169
|
-
cause: e
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return this.#serialize(data, true);
|
|
175
|
-
}
|
|
176
|
-
#serialize(data, enableFormData) {
|
|
177
|
-
if (data instanceof Blob || data === void 0) {
|
|
178
|
-
return data;
|
|
179
|
-
}
|
|
180
|
-
const [json, hasBlob] = this.jsonSerializer.serialize(data);
|
|
181
|
-
if (!enableFormData || !hasBlob) {
|
|
182
|
-
return json;
|
|
183
|
-
}
|
|
184
|
-
const form = new FormData();
|
|
185
|
-
for (const [path, value] of this.bracketNotation.serialize(json)) {
|
|
186
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
187
|
-
form.append(path, value.toString());
|
|
188
|
-
} else if (value instanceof Blob) {
|
|
189
|
-
form.append(path, value);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return form;
|
|
193
|
-
}
|
|
194
|
-
deserialize(data) {
|
|
195
|
-
if (data instanceof URLSearchParams || data instanceof FormData) {
|
|
196
|
-
return this.bracketNotation.deserialize(Array.from(data.entries()));
|
|
197
|
-
}
|
|
198
|
-
if (isAsyncIteratorObject(data)) {
|
|
199
|
-
return mapEventIterator(data, {
|
|
200
|
-
value: async (value) => value,
|
|
201
|
-
error: async (e) => {
|
|
202
|
-
if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
|
|
203
|
-
return ORPCError.fromJSON(e.data, { cause: e });
|
|
204
|
-
}
|
|
205
|
-
return e;
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return data;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export { BracketNotationSerializer, OpenAPIJsonSerializer, OpenAPISerializer };
|
package/dist/rpc/index.d.mts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Segment } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
type RPCJsonSerializedMeta = [
|
|
4
|
-
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
|
|
5
|
-
Segment[]
|
|
6
|
-
][];
|
|
7
|
-
type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
|
|
8
|
-
declare class RPCJsonSerializer {
|
|
9
|
-
serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
|
|
10
|
-
deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
|
|
11
|
-
deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare class RPCSerializer {
|
|
15
|
-
#private;
|
|
16
|
-
private readonly jsonSerializer;
|
|
17
|
-
constructor(jsonSerializer?: RPCJsonSerializer);
|
|
18
|
-
serialize(data: unknown): unknown;
|
|
19
|
-
deserialize(data: unknown): unknown;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer };
|
package/dist/rpc/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Segment } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
type RPCJsonSerializedMeta = [
|
|
4
|
-
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
|
|
5
|
-
Segment[]
|
|
6
|
-
][];
|
|
7
|
-
type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
|
|
8
|
-
declare class RPCJsonSerializer {
|
|
9
|
-
serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
|
|
10
|
-
deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
|
|
11
|
-
deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare class RPCSerializer {
|
|
15
|
-
#private;
|
|
16
|
-
private readonly jsonSerializer;
|
|
17
|
-
constructor(jsonSerializer?: RPCJsonSerializer);
|
|
18
|
-
serialize(data: unknown): unknown;
|
|
19
|
-
deserialize(data: unknown): unknown;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer };
|
package/dist/rpc/index.mjs
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { isObject, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
|
|
2
|
-
import { ErrorEvent } from '@orpc/standard-server';
|
|
3
|
-
import { m as mapEventIterator, t as toORPCError, O as ORPCError } from './client.Ly4zGQrc.mjs';
|
|
4
|
-
|
|
5
|
-
class RPCJsonSerializer {
|
|
6
|
-
serialize(data, segments = [], meta = [], maps = [], blobs = []) {
|
|
7
|
-
if (data instanceof Blob) {
|
|
8
|
-
maps.push(segments);
|
|
9
|
-
blobs.push(data);
|
|
10
|
-
return [data, meta, maps, blobs];
|
|
11
|
-
}
|
|
12
|
-
if (typeof data === "bigint") {
|
|
13
|
-
meta.push([0, segments]);
|
|
14
|
-
return [data.toString(), meta, maps, blobs];
|
|
15
|
-
}
|
|
16
|
-
if (data instanceof Date) {
|
|
17
|
-
meta.push([1, segments]);
|
|
18
|
-
if (Number.isNaN(data.getTime())) {
|
|
19
|
-
return [null, meta, maps, blobs];
|
|
20
|
-
}
|
|
21
|
-
return [data.toISOString(), meta, maps, blobs];
|
|
22
|
-
}
|
|
23
|
-
if (Number.isNaN(data)) {
|
|
24
|
-
meta.push([2, segments]);
|
|
25
|
-
return [null, meta, maps, blobs];
|
|
26
|
-
}
|
|
27
|
-
if (data instanceof URL) {
|
|
28
|
-
meta.push([4, segments]);
|
|
29
|
-
return [data.toString(), meta, maps, blobs];
|
|
30
|
-
}
|
|
31
|
-
if (data instanceof RegExp) {
|
|
32
|
-
meta.push([5, segments]);
|
|
33
|
-
return [data.toString(), meta, maps, blobs];
|
|
34
|
-
}
|
|
35
|
-
if (data instanceof Set) {
|
|
36
|
-
const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
|
|
37
|
-
meta.push([6, segments]);
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
if (data instanceof Map) {
|
|
41
|
-
const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
|
|
42
|
-
meta.push([7, segments]);
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
if (Array.isArray(data)) {
|
|
46
|
-
const json = data.map((v, i) => {
|
|
47
|
-
if (v === void 0) {
|
|
48
|
-
meta.push([3, [...segments, i]]);
|
|
49
|
-
return v;
|
|
50
|
-
}
|
|
51
|
-
return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
|
|
52
|
-
});
|
|
53
|
-
return [json, meta, maps, blobs];
|
|
54
|
-
}
|
|
55
|
-
if (isObject(data)) {
|
|
56
|
-
const json = {};
|
|
57
|
-
for (const k in data) {
|
|
58
|
-
json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
|
|
59
|
-
}
|
|
60
|
-
return [json, meta, maps, blobs];
|
|
61
|
-
}
|
|
62
|
-
return [data, meta, maps, blobs];
|
|
63
|
-
}
|
|
64
|
-
deserialize(json, meta, maps, getBlob) {
|
|
65
|
-
const ref = { data: json };
|
|
66
|
-
if (maps && getBlob) {
|
|
67
|
-
maps.forEach((segments, i) => {
|
|
68
|
-
let currentRef = ref;
|
|
69
|
-
let preSegment = "data";
|
|
70
|
-
segments.forEach((segment) => {
|
|
71
|
-
currentRef = currentRef[preSegment];
|
|
72
|
-
preSegment = segment;
|
|
73
|
-
});
|
|
74
|
-
currentRef[preSegment] = getBlob(i);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
for (const [type, segments] of meta) {
|
|
78
|
-
let currentRef = ref;
|
|
79
|
-
let preSegment = "data";
|
|
80
|
-
segments.forEach((segment) => {
|
|
81
|
-
currentRef = currentRef[preSegment];
|
|
82
|
-
preSegment = segment;
|
|
83
|
-
});
|
|
84
|
-
switch (type) {
|
|
85
|
-
case 0:
|
|
86
|
-
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
|
87
|
-
break;
|
|
88
|
-
case 1:
|
|
89
|
-
currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
|
|
90
|
-
break;
|
|
91
|
-
case 2:
|
|
92
|
-
currentRef[preSegment] = Number.NaN;
|
|
93
|
-
break;
|
|
94
|
-
case 3:
|
|
95
|
-
currentRef[preSegment] = void 0;
|
|
96
|
-
break;
|
|
97
|
-
case 4:
|
|
98
|
-
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
|
99
|
-
break;
|
|
100
|
-
case 5: {
|
|
101
|
-
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
|
102
|
-
currentRef[preSegment] = new RegExp(pattern, flags);
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case 6:
|
|
106
|
-
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
|
107
|
-
break;
|
|
108
|
-
case 7:
|
|
109
|
-
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return ref.data;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
class RPCSerializer {
|
|
118
|
-
constructor(jsonSerializer = new RPCJsonSerializer()) {
|
|
119
|
-
this.jsonSerializer = jsonSerializer;
|
|
120
|
-
}
|
|
121
|
-
serialize(data) {
|
|
122
|
-
if (isAsyncIteratorObject(data)) {
|
|
123
|
-
return mapEventIterator(data, {
|
|
124
|
-
value: async (value) => this.#serialize(value, false),
|
|
125
|
-
error: async (e) => {
|
|
126
|
-
return new ErrorEvent({
|
|
127
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
|
128
|
-
cause: e
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return this.#serialize(data, true);
|
|
134
|
-
}
|
|
135
|
-
#serialize(data, enableFormData) {
|
|
136
|
-
if (data === void 0 || data instanceof Blob) {
|
|
137
|
-
return data;
|
|
138
|
-
}
|
|
139
|
-
const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
|
|
140
|
-
const meta = meta_.length === 0 ? void 0 : meta_;
|
|
141
|
-
if (!enableFormData || blobs.length === 0) {
|
|
142
|
-
return {
|
|
143
|
-
json,
|
|
144
|
-
meta
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
const form = new FormData();
|
|
148
|
-
form.set("data", stringifyJSON({ json, meta, maps }));
|
|
149
|
-
blobs.forEach((blob, i) => {
|
|
150
|
-
form.set(i.toString(), blob);
|
|
151
|
-
});
|
|
152
|
-
return form;
|
|
153
|
-
}
|
|
154
|
-
deserialize(data) {
|
|
155
|
-
if (isAsyncIteratorObject(data)) {
|
|
156
|
-
return mapEventIterator(data, {
|
|
157
|
-
value: async (value) => this.#deserialize(value),
|
|
158
|
-
error: async (e) => {
|
|
159
|
-
if (!(e instanceof ErrorEvent)) {
|
|
160
|
-
return e;
|
|
161
|
-
}
|
|
162
|
-
const deserialized = this.#deserialize(e.data);
|
|
163
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
|
164
|
-
return ORPCError.fromJSON(deserialized, { cause: e });
|
|
165
|
-
}
|
|
166
|
-
return new ErrorEvent({
|
|
167
|
-
data: deserialized,
|
|
168
|
-
cause: e
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
return this.#deserialize(data);
|
|
174
|
-
}
|
|
175
|
-
#deserialize(data) {
|
|
176
|
-
if (data === void 0 || data instanceof Blob) {
|
|
177
|
-
return data;
|
|
178
|
-
}
|
|
179
|
-
if (!(data instanceof FormData)) {
|
|
180
|
-
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
|
181
|
-
}
|
|
182
|
-
const serialized = JSON.parse(data.get("data"));
|
|
183
|
-
return this.jsonSerializer.deserialize(
|
|
184
|
-
serialized.json,
|
|
185
|
-
serialized.meta ?? [],
|
|
186
|
-
serialized.maps,
|
|
187
|
-
(i) => data.get(i.toString())
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export { RPCJsonSerializer as R, RPCSerializer as a };
|