@orpc/client 0.0.0-next.ff5907c → 0.0.0-next.ff7ad2e
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 +98 -0
- 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 +45 -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 +400 -0
- package/dist/shared/client.BG98rYdO.d.ts +45 -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.C176log5.d.ts +91 -0
- package/dist/shared/client.DKmRtVO2.mjs +390 -0
- package/dist/shared/client.Ycwr4Tuo.d.mts +91 -0
- package/dist/shared/client.txdq_i5V.mjs +180 -0
- package/package.json +30 -24
- package/dist/chunk-2UPNYYFF.js +0 -288
- package/dist/chunk-TPEMQB7D.js +0 -178
- package/dist/fetch.js +0 -128
- package/dist/index.js +0 -81
- package/dist/openapi.js +0 -329
- 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 -84
- package/dist/src/openapi/index.d.ts +0 -4
- package/dist/src/openapi/json-serializer.d.ts +0 -5
- package/dist/src/openapi/serializer.d.ts +0 -11
- package/dist/src/rpc/index.d.ts +0 -2
- package/dist/src/rpc/serializer.d.ts +0 -22
- package/dist/src/types.d.ts +0 -29
- package/dist/src/utils.d.ts +0 -5
package/dist/chunk-TPEMQB7D.js
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
ORPCError,
|
3
|
-
mapEventIterator,
|
4
|
-
toORPCError
|
5
|
-
} from "./chunk-2UPNYYFF.js";
|
6
|
-
|
7
|
-
// src/rpc/serializer.ts
|
8
|
-
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
|
9
|
-
import { findDeepMatches, isObject, set } from "@orpc/shared";
|
10
|
-
var RPCSerializer = class {
|
11
|
-
serialize(data) {
|
12
|
-
if (isAsyncIteratorObject(data)) {
|
13
|
-
return mapEventIterator(data, {
|
14
|
-
value: async (value) => serializeRPCJson(value),
|
15
|
-
error: async (e) => {
|
16
|
-
if (e instanceof ErrorEvent) {
|
17
|
-
return new ErrorEvent({
|
18
|
-
data: serializeRPCJson(e.data),
|
19
|
-
cause: e
|
20
|
-
});
|
21
|
-
}
|
22
|
-
return new ErrorEvent({
|
23
|
-
data: serializeRPCJson(toORPCError(e).toJSON()),
|
24
|
-
cause: e
|
25
|
-
});
|
26
|
-
}
|
27
|
-
});
|
28
|
-
}
|
29
|
-
const serializedJSON = serializeRPCJson(data);
|
30
|
-
const { maps, values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON.json);
|
31
|
-
if (blobs.length === 0) {
|
32
|
-
return serializedJSON;
|
33
|
-
}
|
34
|
-
const form = new FormData();
|
35
|
-
form.set("data", JSON.stringify(serializedJSON));
|
36
|
-
form.set("maps", JSON.stringify(maps));
|
37
|
-
for (const i in blobs) {
|
38
|
-
form.set(i, blobs[i]);
|
39
|
-
}
|
40
|
-
return form;
|
41
|
-
}
|
42
|
-
deserialize(serialized) {
|
43
|
-
if (isAsyncIteratorObject(serialized)) {
|
44
|
-
return mapEventIterator(serialized, {
|
45
|
-
value: async (value) => deserializeRPCJson(value),
|
46
|
-
error: async (e) => {
|
47
|
-
if (!(e instanceof ErrorEvent)) {
|
48
|
-
return e;
|
49
|
-
}
|
50
|
-
const deserialized = deserializeRPCJson(e.data);
|
51
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
52
|
-
return ORPCError.fromJSON(deserialized, { cause: e });
|
53
|
-
}
|
54
|
-
return new ErrorEvent({
|
55
|
-
data: deserialized,
|
56
|
-
cause: e
|
57
|
-
});
|
58
|
-
}
|
59
|
-
});
|
60
|
-
}
|
61
|
-
if (!(serialized instanceof FormData)) {
|
62
|
-
return deserializeRPCJson(serialized);
|
63
|
-
}
|
64
|
-
const data = JSON.parse(serialized.get("data"));
|
65
|
-
const maps = JSON.parse(serialized.get("maps"));
|
66
|
-
for (const i in maps) {
|
67
|
-
data.json = set(data.json, maps[i], serialized.get(i));
|
68
|
-
}
|
69
|
-
return deserializeRPCJson(data);
|
70
|
-
}
|
71
|
-
};
|
72
|
-
function serializeRPCJson(value, segments = [], meta = []) {
|
73
|
-
if (typeof value === "bigint") {
|
74
|
-
meta.push(["bigint", segments]);
|
75
|
-
return { json: value.toString(), meta };
|
76
|
-
}
|
77
|
-
if (value instanceof Date) {
|
78
|
-
meta.push(["date", segments]);
|
79
|
-
const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
|
80
|
-
return { json: data, meta };
|
81
|
-
}
|
82
|
-
if (Number.isNaN(value)) {
|
83
|
-
meta.push(["nan", segments]);
|
84
|
-
return { json: "NaN", meta };
|
85
|
-
}
|
86
|
-
if (value instanceof RegExp) {
|
87
|
-
meta.push(["regexp", segments]);
|
88
|
-
return { json: value.toString(), meta };
|
89
|
-
}
|
90
|
-
if (value instanceof URL) {
|
91
|
-
meta.push(["url", segments]);
|
92
|
-
return { json: value.toString(), meta };
|
93
|
-
}
|
94
|
-
if (isObject(value)) {
|
95
|
-
const json = {};
|
96
|
-
for (const k in value) {
|
97
|
-
json[k] = serializeRPCJson(value[k], [...segments, k], meta).json;
|
98
|
-
}
|
99
|
-
return { json, meta };
|
100
|
-
}
|
101
|
-
if (Array.isArray(value)) {
|
102
|
-
const json = value.map((v, i) => {
|
103
|
-
if (v === void 0) {
|
104
|
-
meta.push(["undefined", [...segments, i]]);
|
105
|
-
return null;
|
106
|
-
}
|
107
|
-
return serializeRPCJson(v, [...segments, i], meta).json;
|
108
|
-
});
|
109
|
-
return { json, meta };
|
110
|
-
}
|
111
|
-
if (value instanceof Set) {
|
112
|
-
const result = serializeRPCJson(Array.from(value), segments, meta);
|
113
|
-
meta.push(["set", segments]);
|
114
|
-
return result;
|
115
|
-
}
|
116
|
-
if (value instanceof Map) {
|
117
|
-
const result = serializeRPCJson(Array.from(value.entries()), segments, meta);
|
118
|
-
meta.push(["map", segments]);
|
119
|
-
return result;
|
120
|
-
}
|
121
|
-
return { json: value, meta };
|
122
|
-
}
|
123
|
-
function deserializeRPCJson({
|
124
|
-
json,
|
125
|
-
meta
|
126
|
-
}) {
|
127
|
-
if (meta.length === 0) {
|
128
|
-
return json;
|
129
|
-
}
|
130
|
-
const ref = { data: json };
|
131
|
-
for (const [type, segments] of meta) {
|
132
|
-
let currentRef = ref;
|
133
|
-
let preSegment = "data";
|
134
|
-
for (let i = 0; i < segments.length; i++) {
|
135
|
-
currentRef = currentRef[preSegment];
|
136
|
-
preSegment = segments[i];
|
137
|
-
}
|
138
|
-
switch (type) {
|
139
|
-
case "nan":
|
140
|
-
currentRef[preSegment] = Number.NaN;
|
141
|
-
break;
|
142
|
-
case "bigint":
|
143
|
-
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
144
|
-
break;
|
145
|
-
case "date":
|
146
|
-
currentRef[preSegment] = new Date(currentRef[preSegment]);
|
147
|
-
break;
|
148
|
-
case "regexp": {
|
149
|
-
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
150
|
-
currentRef[preSegment] = new RegExp(pattern, flags);
|
151
|
-
break;
|
152
|
-
}
|
153
|
-
case "url":
|
154
|
-
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
155
|
-
break;
|
156
|
-
case "undefined":
|
157
|
-
currentRef[preSegment] = void 0;
|
158
|
-
break;
|
159
|
-
case "map":
|
160
|
-
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
161
|
-
break;
|
162
|
-
case "set":
|
163
|
-
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
164
|
-
break;
|
165
|
-
/* v8 ignore next 3 */
|
166
|
-
default: {
|
167
|
-
const _expected = type;
|
168
|
-
}
|
169
|
-
}
|
170
|
-
}
|
171
|
-
return ref.data;
|
172
|
-
}
|
173
|
-
|
174
|
-
export {
|
175
|
-
RPCSerializer,
|
176
|
-
serializeRPCJson
|
177
|
-
};
|
178
|
-
//# sourceMappingURL=chunk-TPEMQB7D.js.map
|
package/dist/fetch.js
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCSerializer
|
3
|
-
} from "./chunk-TPEMQB7D.js";
|
4
|
-
import {
|
5
|
-
ORPCError,
|
6
|
-
createAutoRetryEventIterator
|
7
|
-
} from "./chunk-2UPNYYFF.js";
|
8
|
-
|
9
|
-
// src/adapters/fetch/rpc-link.ts
|
10
|
-
import { isAsyncIteratorObject } from "@orpc/server-standard";
|
11
|
-
import { toFetchBody, toStandardBody } from "@orpc/server-standard-fetch";
|
12
|
-
import { trim, value } from "@orpc/shared";
|
13
|
-
var InvalidEventSourceRetryResponse = class extends Error {
|
14
|
-
};
|
15
|
-
var RPCLink = class {
|
16
|
-
fetch;
|
17
|
-
rpcSerializer;
|
18
|
-
maxUrlLength;
|
19
|
-
fallbackMethod;
|
20
|
-
method;
|
21
|
-
headers;
|
22
|
-
url;
|
23
|
-
eventSourceMaxNumberOfRetries;
|
24
|
-
eventSourceRetryDelay;
|
25
|
-
eventSourceRetry;
|
26
|
-
constructor(options) {
|
27
|
-
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
28
|
-
this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
|
29
|
-
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
30
|
-
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
31
|
-
this.url = options.url;
|
32
|
-
this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
|
33
|
-
this.method = options.method ?? this.fallbackMethod;
|
34
|
-
this.headers = options.headers ?? {};
|
35
|
-
this.eventSourceRetry = options.eventSourceRetry ?? true;
|
36
|
-
this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
|
37
|
-
}
|
38
|
-
async call(path, input, options) {
|
39
|
-
const output = await this.performCall(path, input, options);
|
40
|
-
if (!isAsyncIteratorObject(output)) {
|
41
|
-
return output;
|
42
|
-
}
|
43
|
-
return createAutoRetryEventIterator(output, async (reconnectOptions) => {
|
44
|
-
if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
|
45
|
-
return null;
|
46
|
-
}
|
47
|
-
if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
|
48
|
-
return null;
|
49
|
-
}
|
50
|
-
const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
|
51
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
52
|
-
const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
|
53
|
-
const maybeIterator = await this.performCall(path, input, updatedOptions);
|
54
|
-
if (!isAsyncIteratorObject(maybeIterator)) {
|
55
|
-
throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
|
56
|
-
}
|
57
|
-
return maybeIterator;
|
58
|
-
}, void 0);
|
59
|
-
}
|
60
|
-
async performCall(path, input, options) {
|
61
|
-
const encoded = await this.encodeRequest(path, input, options);
|
62
|
-
const fetchBody = toFetchBody(encoded.body, encoded.headers);
|
63
|
-
if (options.lastEventId !== void 0) {
|
64
|
-
encoded.headers.set("last-event-id", options.lastEventId);
|
65
|
-
}
|
66
|
-
const response = await this.fetch(encoded.url, {
|
67
|
-
method: encoded.method,
|
68
|
-
headers: encoded.headers,
|
69
|
-
body: fetchBody,
|
70
|
-
signal: options.signal
|
71
|
-
}, options, path, input);
|
72
|
-
const body = await toStandardBody(response);
|
73
|
-
const deserialized = (() => {
|
74
|
-
try {
|
75
|
-
return this.rpcSerializer.deserialize(body);
|
76
|
-
} catch (error) {
|
77
|
-
if (response.ok) {
|
78
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
79
|
-
message: "Invalid RPC response",
|
80
|
-
cause: error
|
81
|
-
});
|
82
|
-
}
|
83
|
-
throw new ORPCError(response.status.toString(), {
|
84
|
-
message: response.statusText
|
85
|
-
});
|
86
|
-
}
|
87
|
-
})();
|
88
|
-
if (!response.ok) {
|
89
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
90
|
-
throw ORPCError.fromJSON(deserialized);
|
91
|
-
}
|
92
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
93
|
-
message: "Invalid RPC error response",
|
94
|
-
cause: deserialized
|
95
|
-
});
|
96
|
-
}
|
97
|
-
return deserialized;
|
98
|
-
}
|
99
|
-
async encodeRequest(path, input, options) {
|
100
|
-
const expectedMethod = await value(this.method, options, path, input);
|
101
|
-
const headers = new Headers(await value(this.headers, options, path, input));
|
102
|
-
const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
|
103
|
-
const serialized = this.rpcSerializer.serialize(input);
|
104
|
-
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
105
|
-
const getUrl = new URL(url);
|
106
|
-
getUrl.searchParams.append("data", JSON.stringify(serialized));
|
107
|
-
if (getUrl.toString().length <= this.maxUrlLength) {
|
108
|
-
return {
|
109
|
-
body: void 0,
|
110
|
-
method: expectedMethod,
|
111
|
-
headers,
|
112
|
-
url: getUrl
|
113
|
-
};
|
114
|
-
}
|
115
|
-
}
|
116
|
-
return {
|
117
|
-
url,
|
118
|
-
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
119
|
-
headers,
|
120
|
-
body: serialized
|
121
|
-
};
|
122
|
-
}
|
123
|
-
};
|
124
|
-
export {
|
125
|
-
InvalidEventSourceRetryResponse,
|
126
|
-
RPCLink
|
127
|
-
};
|
128
|
-
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
COMMON_ORPC_ERROR_DEFS,
|
3
|
-
ORPCError,
|
4
|
-
createAutoRetryEventIterator,
|
5
|
-
fallbackORPCErrorMessage,
|
6
|
-
fallbackORPCErrorStatus,
|
7
|
-
isDefinedError,
|
8
|
-
mapEventIterator,
|
9
|
-
onEventIteratorStatusChange,
|
10
|
-
registerEventIteratorState,
|
11
|
-
toORPCError,
|
12
|
-
updateEventIteratorStatus
|
13
|
-
} from "./chunk-2UPNYYFF.js";
|
14
|
-
|
15
|
-
// src/client.ts
|
16
|
-
function createORPCClient(link, options) {
|
17
|
-
const path = options?.path ?? [];
|
18
|
-
const procedureClient = async (...[input, options2]) => {
|
19
|
-
const optionsOut = {
|
20
|
-
...options2,
|
21
|
-
context: options2?.context ?? {}
|
22
|
-
// options.context can be undefined when all field is optional
|
23
|
-
};
|
24
|
-
return await link.call(path, input, optionsOut);
|
25
|
-
};
|
26
|
-
const recursive = new Proxy(procedureClient, {
|
27
|
-
get(target, key) {
|
28
|
-
if (typeof key !== "string") {
|
29
|
-
return Reflect.get(target, key);
|
30
|
-
}
|
31
|
-
return createORPCClient(link, {
|
32
|
-
...options,
|
33
|
-
path: [...path, key]
|
34
|
-
});
|
35
|
-
}
|
36
|
-
});
|
37
|
-
return recursive;
|
38
|
-
}
|
39
|
-
|
40
|
-
// src/dynamic-link.ts
|
41
|
-
var DynamicLink = class {
|
42
|
-
constructor(linkResolver) {
|
43
|
-
this.linkResolver = linkResolver;
|
44
|
-
}
|
45
|
-
async call(path, input, options) {
|
46
|
-
const resolvedLink = await this.linkResolver(options, path, input);
|
47
|
-
const output = await resolvedLink.call(path, input, options);
|
48
|
-
return output;
|
49
|
-
}
|
50
|
-
};
|
51
|
-
|
52
|
-
// src/utils.ts
|
53
|
-
async function safe(promise) {
|
54
|
-
try {
|
55
|
-
const output = await promise;
|
56
|
-
return [output, void 0, false];
|
57
|
-
} catch (e) {
|
58
|
-
const error = e;
|
59
|
-
if (isDefinedError(error)) {
|
60
|
-
return [void 0, error, true];
|
61
|
-
}
|
62
|
-
return [void 0, error, false];
|
63
|
-
}
|
64
|
-
}
|
65
|
-
export {
|
66
|
-
COMMON_ORPC_ERROR_DEFS,
|
67
|
-
DynamicLink,
|
68
|
-
ORPCError,
|
69
|
-
createAutoRetryEventIterator,
|
70
|
-
createORPCClient,
|
71
|
-
fallbackORPCErrorMessage,
|
72
|
-
fallbackORPCErrorStatus,
|
73
|
-
isDefinedError,
|
74
|
-
mapEventIterator,
|
75
|
-
onEventIteratorStatusChange,
|
76
|
-
registerEventIteratorState,
|
77
|
-
safe,
|
78
|
-
toORPCError,
|
79
|
-
updateEventIteratorStatus
|
80
|
-
};
|
81
|
-
//# sourceMappingURL=index.js.map
|
package/dist/openapi.js
DELETED
@@ -1,329 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
ORPCError,
|
3
|
-
__export,
|
4
|
-
mapEventIterator,
|
5
|
-
toORPCError
|
6
|
-
} from "./chunk-2UPNYYFF.js";
|
7
|
-
|
8
|
-
// src/openapi/bracket-notation.ts
|
9
|
-
var bracket_notation_exports = {};
|
10
|
-
__export(bracket_notation_exports, {
|
11
|
-
deserialize: () => deserialize,
|
12
|
-
escapeSegment: () => escapeSegment,
|
13
|
-
parsePath: () => parsePath,
|
14
|
-
serialize: () => serialize,
|
15
|
-
stringifyPath: () => stringifyPath
|
16
|
-
});
|
17
|
-
import { isObject } from "@orpc/shared";
|
18
|
-
function serialize(payload, parentKey = "") {
|
19
|
-
if (!Array.isArray(payload) && !isObject(payload))
|
20
|
-
return [["", payload]];
|
21
|
-
const result = [];
|
22
|
-
function helper(value, path) {
|
23
|
-
if (Array.isArray(value)) {
|
24
|
-
value.forEach((item, index) => {
|
25
|
-
helper(item, [...path, String(index)]);
|
26
|
-
});
|
27
|
-
} else if (isObject(value)) {
|
28
|
-
for (const [key, val] of Object.entries(value)) {
|
29
|
-
helper(val, [...path, key]);
|
30
|
-
}
|
31
|
-
} else {
|
32
|
-
result.push([stringifyPath(path), value]);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
helper(payload, parentKey ? [parentKey] : []);
|
36
|
-
return result;
|
37
|
-
}
|
38
|
-
function deserialize(entities) {
|
39
|
-
if (entities.length === 0) {
|
40
|
-
return void 0;
|
41
|
-
}
|
42
|
-
const isRootArray = entities.every(([path]) => path === "");
|
43
|
-
const result = isRootArray ? [] : {};
|
44
|
-
const arrayPushPaths = /* @__PURE__ */ new Set();
|
45
|
-
for (const [path, _] of entities) {
|
46
|
-
const segments = parsePath(path);
|
47
|
-
const base = segments.slice(0, -1).join(".");
|
48
|
-
const last = segments[segments.length - 1];
|
49
|
-
if (last === "") {
|
50
|
-
arrayPushPaths.add(base);
|
51
|
-
} else {
|
52
|
-
arrayPushPaths.delete(base);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
function setValue(obj, segments, value, fullPath) {
|
56
|
-
const [first, ...rest_] = segments;
|
57
|
-
if (Array.isArray(obj) && first === "") {
|
58
|
-
;
|
59
|
-
obj.push(value);
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
const objAsRecord = obj;
|
63
|
-
if (rest_.length === 0) {
|
64
|
-
objAsRecord[first] = value;
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
const rest = rest_;
|
68
|
-
if (rest[0] === "") {
|
69
|
-
const pathToCheck = segments.slice(0, -1).join(".");
|
70
|
-
if (rest.length === 1 && arrayPushPaths.has(pathToCheck)) {
|
71
|
-
if (!(first in objAsRecord)) {
|
72
|
-
objAsRecord[first] = [];
|
73
|
-
}
|
74
|
-
if (Array.isArray(objAsRecord[first])) {
|
75
|
-
;
|
76
|
-
objAsRecord[first].push(value);
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
}
|
80
|
-
if (!(first in objAsRecord)) {
|
81
|
-
objAsRecord[first] = {};
|
82
|
-
}
|
83
|
-
const target = objAsRecord[first];
|
84
|
-
target[""] = value;
|
85
|
-
return;
|
86
|
-
}
|
87
|
-
if (!(first in objAsRecord)) {
|
88
|
-
objAsRecord[first] = {};
|
89
|
-
}
|
90
|
-
setValue(
|
91
|
-
objAsRecord[first],
|
92
|
-
rest,
|
93
|
-
value,
|
94
|
-
fullPath
|
95
|
-
);
|
96
|
-
}
|
97
|
-
for (const [path, value] of entities) {
|
98
|
-
const segments = parsePath(path);
|
99
|
-
setValue(result, segments, value, path);
|
100
|
-
}
|
101
|
-
return result;
|
102
|
-
}
|
103
|
-
function escapeSegment(segment) {
|
104
|
-
return segment.replace(/[\\[\]]/g, (match) => {
|
105
|
-
switch (match) {
|
106
|
-
case "\\":
|
107
|
-
return "\\\\";
|
108
|
-
case "[":
|
109
|
-
return "\\[";
|
110
|
-
case "]":
|
111
|
-
return "\\]";
|
112
|
-
default:
|
113
|
-
return match;
|
114
|
-
}
|
115
|
-
});
|
116
|
-
}
|
117
|
-
function stringifyPath(path) {
|
118
|
-
const [first, ...rest] = path;
|
119
|
-
const firstSegment = escapeSegment(first);
|
120
|
-
const base = first === "" ? "" : firstSegment;
|
121
|
-
return rest.reduce(
|
122
|
-
(result, segment) => `${result}[${escapeSegment(segment)}]`,
|
123
|
-
base
|
124
|
-
);
|
125
|
-
}
|
126
|
-
function parsePath(path) {
|
127
|
-
if (path === "")
|
128
|
-
return [""];
|
129
|
-
const result = [];
|
130
|
-
let currentSegment = "";
|
131
|
-
let inBracket = false;
|
132
|
-
let bracketContent = "";
|
133
|
-
let backslashCount = 0;
|
134
|
-
for (let i = 0; i < path.length; i++) {
|
135
|
-
const char = path[i];
|
136
|
-
if (char === "\\") {
|
137
|
-
backslashCount++;
|
138
|
-
continue;
|
139
|
-
}
|
140
|
-
if (backslashCount > 0) {
|
141
|
-
const literalBackslashes = "\\".repeat(Math.floor(backslashCount / 2));
|
142
|
-
if (char === "[" || char === "]") {
|
143
|
-
if (backslashCount % 2 === 1) {
|
144
|
-
if (inBracket) {
|
145
|
-
bracketContent += literalBackslashes + char;
|
146
|
-
} else {
|
147
|
-
currentSegment += literalBackslashes + char;
|
148
|
-
}
|
149
|
-
} else {
|
150
|
-
if (inBracket) {
|
151
|
-
bracketContent += literalBackslashes;
|
152
|
-
} else {
|
153
|
-
currentSegment += literalBackslashes;
|
154
|
-
}
|
155
|
-
if (char === "[" && !inBracket) {
|
156
|
-
if (currentSegment !== "" || result.length === 0) {
|
157
|
-
result.push(currentSegment);
|
158
|
-
}
|
159
|
-
inBracket = true;
|
160
|
-
bracketContent = "";
|
161
|
-
currentSegment = "";
|
162
|
-
} else if (char === "]" && inBracket) {
|
163
|
-
result.push(bracketContent);
|
164
|
-
inBracket = false;
|
165
|
-
bracketContent = "";
|
166
|
-
} else {
|
167
|
-
if (inBracket) {
|
168
|
-
bracketContent += char;
|
169
|
-
} else {
|
170
|
-
currentSegment += char;
|
171
|
-
}
|
172
|
-
}
|
173
|
-
}
|
174
|
-
} else {
|
175
|
-
const allBackslashes = "\\".repeat(backslashCount);
|
176
|
-
if (inBracket) {
|
177
|
-
bracketContent += allBackslashes + char;
|
178
|
-
} else {
|
179
|
-
currentSegment += allBackslashes + char;
|
180
|
-
}
|
181
|
-
}
|
182
|
-
backslashCount = 0;
|
183
|
-
continue;
|
184
|
-
}
|
185
|
-
if (char === "[" && !inBracket) {
|
186
|
-
if (currentSegment !== "" || result.length === 0) {
|
187
|
-
result.push(currentSegment);
|
188
|
-
}
|
189
|
-
inBracket = true;
|
190
|
-
bracketContent = "";
|
191
|
-
currentSegment = "";
|
192
|
-
continue;
|
193
|
-
}
|
194
|
-
if (char === "]" && inBracket) {
|
195
|
-
result.push(bracketContent);
|
196
|
-
inBracket = false;
|
197
|
-
bracketContent = "";
|
198
|
-
continue;
|
199
|
-
}
|
200
|
-
if (inBracket) {
|
201
|
-
bracketContent += char;
|
202
|
-
} else {
|
203
|
-
currentSegment += char;
|
204
|
-
}
|
205
|
-
}
|
206
|
-
if (backslashCount > 0) {
|
207
|
-
const remainingBackslashes = "\\".repeat(backslashCount);
|
208
|
-
if (inBracket) {
|
209
|
-
bracketContent += remainingBackslashes;
|
210
|
-
} else {
|
211
|
-
currentSegment += remainingBackslashes;
|
212
|
-
}
|
213
|
-
}
|
214
|
-
if (inBracket) {
|
215
|
-
if (currentSegment !== "" || result.length === 0) {
|
216
|
-
result.push(currentSegment);
|
217
|
-
}
|
218
|
-
result.push(`[${bracketContent}`);
|
219
|
-
} else if (currentSegment !== "" || result.length === 0) {
|
220
|
-
result.push(currentSegment);
|
221
|
-
}
|
222
|
-
return result;
|
223
|
-
}
|
224
|
-
|
225
|
-
// src/openapi/json-serializer.ts
|
226
|
-
import { isObject as isObject2 } from "@orpc/shared";
|
227
|
-
var OpenAPIJsonSerializer = class {
|
228
|
-
serialize(payload) {
|
229
|
-
if (payload instanceof Set)
|
230
|
-
return this.serialize([...payload]);
|
231
|
-
if (payload instanceof Map)
|
232
|
-
return this.serialize([...payload.entries()]);
|
233
|
-
if (Array.isArray(payload)) {
|
234
|
-
return payload.map((v) => v === void 0 ? "undefined" : this.serialize(v));
|
235
|
-
}
|
236
|
-
if (Number.isNaN(payload))
|
237
|
-
return "NaN";
|
238
|
-
if (typeof payload === "bigint")
|
239
|
-
return payload.toString();
|
240
|
-
if (payload instanceof Date && Number.isNaN(payload.getTime())) {
|
241
|
-
return "Invalid Date";
|
242
|
-
}
|
243
|
-
if (payload instanceof RegExp)
|
244
|
-
return payload.toString();
|
245
|
-
if (payload instanceof URL)
|
246
|
-
return payload.toString();
|
247
|
-
if (!isObject2(payload))
|
248
|
-
return payload;
|
249
|
-
return Object.keys(payload).reduce(
|
250
|
-
(carry, key) => {
|
251
|
-
const val = payload[key];
|
252
|
-
carry[key] = this.serialize(val);
|
253
|
-
return carry;
|
254
|
-
},
|
255
|
-
{}
|
256
|
-
);
|
257
|
-
}
|
258
|
-
};
|
259
|
-
|
260
|
-
// src/openapi/serializer.ts
|
261
|
-
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
|
262
|
-
import { findDeepMatches } from "@orpc/shared";
|
263
|
-
var OpenAPISerializer = class {
|
264
|
-
jsonSerializer;
|
265
|
-
constructor(options) {
|
266
|
-
this.jsonSerializer = options?.jsonSerializer ?? new OpenAPIJsonSerializer();
|
267
|
-
}
|
268
|
-
serialize(data) {
|
269
|
-
if (data instanceof Blob || data === void 0) {
|
270
|
-
return data;
|
271
|
-
}
|
272
|
-
if (isAsyncIteratorObject(data)) {
|
273
|
-
return mapEventIterator(data, {
|
274
|
-
value: async (value) => this.jsonSerializer.serialize(value),
|
275
|
-
error: async (e) => {
|
276
|
-
if (e instanceof ErrorEvent) {
|
277
|
-
return new ErrorEvent({
|
278
|
-
data: this.jsonSerializer.serialize(e.data),
|
279
|
-
cause: e
|
280
|
-
});
|
281
|
-
}
|
282
|
-
return new ErrorEvent({
|
283
|
-
data: this.jsonSerializer.serialize(toORPCError(e).toJSON()),
|
284
|
-
cause: e
|
285
|
-
});
|
286
|
-
}
|
287
|
-
});
|
288
|
-
}
|
289
|
-
const serializedJSON = this.jsonSerializer.serialize(data);
|
290
|
-
const { values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON);
|
291
|
-
if (blobs.length === 0) {
|
292
|
-
return serializedJSON;
|
293
|
-
}
|
294
|
-
const form = new FormData();
|
295
|
-
for (const [path, value] of serialize(serializedJSON)) {
|
296
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
297
|
-
form.append(path, value.toString());
|
298
|
-
} else if (value instanceof Date) {
|
299
|
-
form.append(path, value.toISOString());
|
300
|
-
} else if (value instanceof Blob) {
|
301
|
-
form.append(path, value);
|
302
|
-
}
|
303
|
-
}
|
304
|
-
return form;
|
305
|
-
}
|
306
|
-
deserialize(serialized) {
|
307
|
-
if (serialized instanceof URLSearchParams || serialized instanceof FormData) {
|
308
|
-
return deserialize([...serialized.entries()]);
|
309
|
-
}
|
310
|
-
if (isAsyncIteratorObject(serialized)) {
|
311
|
-
return mapEventIterator(serialized, {
|
312
|
-
value: async (value) => value,
|
313
|
-
error: async (e) => {
|
314
|
-
if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
|
315
|
-
return ORPCError.fromJSON(e.data, { cause: e });
|
316
|
-
}
|
317
|
-
return e;
|
318
|
-
}
|
319
|
-
});
|
320
|
-
}
|
321
|
-
return serialized;
|
322
|
-
}
|
323
|
-
};
|
324
|
-
export {
|
325
|
-
bracket_notation_exports as BracketNotation,
|
326
|
-
OpenAPIJsonSerializer,
|
327
|
-
OpenAPISerializer
|
328
|
-
};
|
329
|
-
//# sourceMappingURL=openapi.js.map
|