@orpc/client 0.0.0-next.85df466 → 0.0.0-next.8900489
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 +5 -1
- package/dist/adapters/fetch/index.d.mts +22 -96
- package/dist/adapters/fetch/index.d.ts +22 -96
- package/dist/adapters/fetch/index.mjs +26 -111
- package/dist/adapters/standard/index.d.mts +160 -13
- package/dist/adapters/standard/index.d.ts +160 -13
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +3 -3
- package/dist/shared/client.CPmBUYbj.mjs +351 -0
- package/dist/shared/{client.Ly4zGQrc.mjs → client.XAn8cDTM.mjs} +3 -2
- package/package.json +5 -5
- package/dist/shared/client.DHJ8vRIG.mjs +0 -192
|
@@ -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 };
|