@orpc/client 0.0.0-next.ca29a36 → 0.0.0-next.caeb672

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.
Files changed (52) hide show
  1. package/README.md +29 -21
  2. package/dist/adapters/fetch/index.d.mts +33 -0
  3. package/dist/adapters/fetch/index.d.ts +33 -0
  4. package/dist/adapters/fetch/index.mjs +29 -0
  5. package/dist/adapters/message-port/index.d.mts +59 -0
  6. package/dist/adapters/message-port/index.d.ts +59 -0
  7. package/dist/adapters/message-port/index.mjs +71 -0
  8. package/dist/adapters/standard/index.d.mts +10 -0
  9. package/dist/adapters/standard/index.d.ts +10 -0
  10. package/dist/adapters/standard/index.mjs +4 -0
  11. package/dist/adapters/websocket/index.d.mts +29 -0
  12. package/dist/adapters/websocket/index.d.ts +29 -0
  13. package/dist/adapters/websocket/index.mjs +44 -0
  14. package/dist/index.d.mts +185 -0
  15. package/dist/index.d.ts +185 -0
  16. package/dist/index.mjs +82 -0
  17. package/dist/plugins/index.d.mts +202 -0
  18. package/dist/plugins/index.d.ts +202 -0
  19. package/dist/plugins/index.mjs +389 -0
  20. package/dist/shared/client.BOYsZIRq.d.mts +29 -0
  21. package/dist/shared/client.BOYsZIRq.d.ts +29 -0
  22. package/dist/shared/client.BngOL3Ai.mjs +173 -0
  23. package/dist/shared/client.BvXDSBF5.mjs +355 -0
  24. package/dist/shared/client.C4VxIexA.d.mts +46 -0
  25. package/dist/shared/client.CXXEPIbK.d.ts +46 -0
  26. package/dist/shared/client.WCinBImJ.d.ts +91 -0
  27. package/dist/shared/client.aTp4sII-.d.mts +91 -0
  28. package/package.json +30 -24
  29. package/dist/chunk-7F3XVLRJ.js +0 -281
  30. package/dist/chunk-FF5VXXNP.js +0 -213
  31. package/dist/fetch.js +0 -127
  32. package/dist/index.js +0 -90
  33. package/dist/openapi.js +0 -232
  34. package/dist/rpc.js +0 -10
  35. package/dist/src/adapters/fetch/index.d.ts +0 -3
  36. package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
  37. package/dist/src/adapters/fetch/types.d.ts +0 -5
  38. package/dist/src/client.d.ts +0 -9
  39. package/dist/src/dynamic-link.d.ts +0 -12
  40. package/dist/src/error.d.ts +0 -106
  41. package/dist/src/event-iterator-state.d.ts +0 -9
  42. package/dist/src/event-iterator.d.ts +0 -12
  43. package/dist/src/index.d.ts +0 -9
  44. package/dist/src/openapi/bracket-notation.d.ts +0 -9
  45. package/dist/src/openapi/index.d.ts +0 -4
  46. package/dist/src/openapi/json-serializer.d.ts +0 -7
  47. package/dist/src/openapi/serializer.d.ts +0 -11
  48. package/dist/src/rpc/index.d.ts +0 -3
  49. package/dist/src/rpc/json-serializer.d.ts +0 -12
  50. package/dist/src/rpc/serializer.d.ts +0 -9
  51. package/dist/src/types.d.ts +0 -29
  52. package/dist/src/utils.d.ts +0 -17
@@ -1,213 +0,0 @@
1
- import {
2
- ORPCError,
3
- mapEventIterator,
4
- toORPCError
5
- } from "./chunk-7F3XVLRJ.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 { isAsyncIteratorObject, stringifyJSON } from "@orpc/shared";
127
- import { ErrorEvent } from "@orpc/standard-server";
128
- var RPCSerializer = class {
129
- constructor(jsonSerializer = new RPCJsonSerializer()) {
130
- this.jsonSerializer = jsonSerializer;
131
- }
132
- serialize(data) {
133
- if (isAsyncIteratorObject(data)) {
134
- return mapEventIterator(data, {
135
- value: async (value) => this.#serialize(value, false),
136
- error: async (e) => {
137
- if (e instanceof ErrorEvent) {
138
- return new ErrorEvent({
139
- data: this.#serialize(e.data, false),
140
- cause: e
141
- });
142
- }
143
- return new ErrorEvent({
144
- data: this.#serialize(toORPCError(e).toJSON(), false),
145
- cause: e
146
- });
147
- }
148
- });
149
- }
150
- return this.#serialize(data, true);
151
- }
152
- #serialize(data, enableFormData) {
153
- if (data === void 0 || data instanceof Blob) {
154
- return data;
155
- }
156
- const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
157
- const meta = meta_.length === 0 ? void 0 : meta_;
158
- if (!enableFormData || blobs.length === 0) {
159
- return {
160
- json,
161
- meta
162
- };
163
- }
164
- const form = new FormData();
165
- form.set("data", stringifyJSON({ json, meta, maps }));
166
- blobs.forEach((blob, i) => {
167
- form.set(i.toString(), blob);
168
- });
169
- return form;
170
- }
171
- deserialize(data) {
172
- if (isAsyncIteratorObject(data)) {
173
- return mapEventIterator(data, {
174
- value: async (value) => this.#deserialize(value),
175
- error: async (e) => {
176
- if (!(e instanceof ErrorEvent)) {
177
- return e;
178
- }
179
- const deserialized = this.#deserialize(e.data);
180
- if (ORPCError.isValidJSON(deserialized)) {
181
- return ORPCError.fromJSON(deserialized, { cause: e });
182
- }
183
- return new ErrorEvent({
184
- data: deserialized,
185
- cause: e
186
- });
187
- }
188
- });
189
- }
190
- return this.#deserialize(data);
191
- }
192
- #deserialize(data) {
193
- if (data === void 0 || data instanceof Blob) {
194
- return data;
195
- }
196
- if (!(data instanceof FormData)) {
197
- return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
198
- }
199
- const serialized = JSON.parse(data.get("data"));
200
- return this.jsonSerializer.deserialize(
201
- serialized.json,
202
- serialized.meta ?? [],
203
- serialized.maps,
204
- (i) => data.get(i.toString())
205
- );
206
- }
207
- };
208
-
209
- export {
210
- RPCJsonSerializer,
211
- RPCSerializer
212
- };
213
- //# sourceMappingURL=chunk-FF5VXXNP.js.map
package/dist/fetch.js DELETED
@@ -1,127 +0,0 @@
1
- import {
2
- RPCSerializer
3
- } from "./chunk-FF5VXXNP.js";
4
- import {
5
- ORPCError,
6
- createAutoRetryEventIterator
7
- } from "./chunk-7F3XVLRJ.js";
8
-
9
- // src/adapters/fetch/rpc-link.ts
10
- import { isAsyncIteratorObject, stringifyJSON, trim, value } from "@orpc/shared";
11
- import { toFetchBody, toStandardBody } from "@orpc/standard-server-fetch";
12
- var InvalidEventSourceRetryResponse = class extends Error {
13
- };
14
- var RPCLink = class {
15
- fetch;
16
- rpcSerializer;
17
- maxUrlLength;
18
- fallbackMethod;
19
- method;
20
- headers;
21
- url;
22
- eventSourceMaxNumberOfRetries;
23
- eventSourceRetryDelay;
24
- eventSourceRetry;
25
- constructor(options) {
26
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
27
- this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
28
- this.maxUrlLength = options.maxUrlLength ?? 2083;
29
- this.fallbackMethod = options.fallbackMethod ?? "POST";
30
- this.url = options.url;
31
- this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
32
- this.method = options.method ?? this.fallbackMethod;
33
- this.headers = options.headers ?? {};
34
- this.eventSourceRetry = options.eventSourceRetry ?? true;
35
- this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
36
- }
37
- async call(path, input, options) {
38
- const output = await this.performCall(path, input, options);
39
- if (!isAsyncIteratorObject(output)) {
40
- return output;
41
- }
42
- return createAutoRetryEventIterator(output, async (reconnectOptions) => {
43
- if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
44
- return null;
45
- }
46
- if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
47
- return null;
48
- }
49
- const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
50
- await new Promise((resolve) => setTimeout(resolve, delay));
51
- const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
52
- const maybeIterator = await this.performCall(path, input, updatedOptions);
53
- if (!isAsyncIteratorObject(maybeIterator)) {
54
- throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
55
- }
56
- return maybeIterator;
57
- }, void 0);
58
- }
59
- async performCall(path, input, options) {
60
- const encoded = await this.encodeRequest(path, input, options);
61
- const fetchBody = toFetchBody(encoded.body, encoded.headers);
62
- if (options.lastEventId !== void 0) {
63
- encoded.headers.set("last-event-id", options.lastEventId);
64
- }
65
- const response = await this.fetch(encoded.url, {
66
- method: encoded.method,
67
- headers: encoded.headers,
68
- body: fetchBody,
69
- signal: options.signal
70
- }, options, path, input);
71
- const body = await toStandardBody(response);
72
- const deserialized = (() => {
73
- try {
74
- return this.rpcSerializer.deserialize(body);
75
- } catch (error) {
76
- if (response.ok) {
77
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
78
- message: "Invalid RPC response",
79
- cause: error
80
- });
81
- }
82
- throw new ORPCError(response.status.toString(), {
83
- message: response.statusText
84
- });
85
- }
86
- })();
87
- if (!response.ok) {
88
- if (ORPCError.isValidJSON(deserialized)) {
89
- throw ORPCError.fromJSON(deserialized);
90
- }
91
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
92
- message: "Invalid RPC error response",
93
- cause: deserialized
94
- });
95
- }
96
- return deserialized;
97
- }
98
- async encodeRequest(path, input, options) {
99
- const expectedMethod = await value(this.method, options, path, input);
100
- const headers = new Headers(await value(this.headers, options, path, input));
101
- const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
102
- const serialized = this.rpcSerializer.serialize(input);
103
- if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
104
- const getUrl = new URL(url);
105
- getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
106
- if (getUrl.toString().length <= this.maxUrlLength) {
107
- return {
108
- body: void 0,
109
- method: expectedMethod,
110
- headers,
111
- url: getUrl
112
- };
113
- }
114
- }
115
- return {
116
- url,
117
- method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
118
- headers,
119
- body: serialized
120
- };
121
- }
122
- };
123
- export {
124
- InvalidEventSourceRetryResponse,
125
- RPCLink
126
- };
127
- //# sourceMappingURL=fetch.js.map
package/dist/index.js DELETED
@@ -1,90 +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-7F3XVLRJ.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 Object.assign(
57
- [null, output, false],
58
- { error: null, data: output, isDefined: false }
59
- );
60
- } catch (e) {
61
- const error = e;
62
- if (isDefinedError(error)) {
63
- return Object.assign(
64
- [error, void 0, true],
65
- { error, data: void 0, isDefined: true }
66
- );
67
- }
68
- return Object.assign(
69
- [error, void 0, false],
70
- { error, data: void 0, isDefined: false }
71
- );
72
- }
73
- }
74
- export {
75
- COMMON_ORPC_ERROR_DEFS,
76
- DynamicLink,
77
- ORPCError,
78
- createAutoRetryEventIterator,
79
- createORPCClient,
80
- fallbackORPCErrorMessage,
81
- fallbackORPCErrorStatus,
82
- isDefinedError,
83
- mapEventIterator,
84
- onEventIteratorStatusChange,
85
- registerEventIteratorState,
86
- safe,
87
- toORPCError,
88
- updateEventIteratorStatus
89
- };
90
- //# sourceMappingURL=index.js.map
package/dist/openapi.js DELETED
@@ -1,232 +0,0 @@
1
- import {
2
- ORPCError,
3
- mapEventIterator,
4
- toORPCError
5
- } from "./chunk-7F3XVLRJ.js";
6
-
7
- // src/openapi/bracket-notation.ts
8
- import { isObject } from "@orpc/shared";
9
- var BracketNotationSerializer = class {
10
- serialize(data, segments = [], result = []) {
11
- if (Array.isArray(data)) {
12
- data.forEach((item, i) => {
13
- this.serialize(item, [...segments, i], result);
14
- });
15
- } else if (isObject(data)) {
16
- for (const key in data) {
17
- this.serialize(data[key], [...segments, key], result);
18
- }
19
- } else {
20
- result.push([this.stringifyPath(segments), data]);
21
- }
22
- return result;
23
- }
24
- deserialize(serialized) {
25
- const arrayPushStyles = /* @__PURE__ */ new WeakSet();
26
- const ref = { value: [] };
27
- for (const [path, value] of serialized) {
28
- const segments = this.parsePath(path);
29
- let currentRef = ref;
30
- let nextSegment = "value";
31
- segments.forEach((segment, i) => {
32
- if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
33
- currentRef[nextSegment] = [];
34
- }
35
- if (i !== segments.length - 1) {
36
- if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
37
- currentRef[nextSegment] = { ...currentRef[nextSegment] };
38
- }
39
- } else {
40
- if (Array.isArray(currentRef[nextSegment])) {
41
- if (segment === "") {
42
- if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
43
- currentRef[nextSegment] = { ...currentRef[nextSegment] };
44
- }
45
- } else {
46
- if (arrayPushStyles.has(currentRef[nextSegment])) {
47
- currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
48
- } else if (!isValidArrayIndex(segment)) {
49
- currentRef[nextSegment] = { ...currentRef[nextSegment] };
50
- }
51
- }
52
- }
53
- }
54
- currentRef = currentRef[nextSegment];
55
- nextSegment = segment;
56
- });
57
- if (Array.isArray(currentRef)) {
58
- if (nextSegment === "") {
59
- arrayPushStyles.add(currentRef);
60
- currentRef.push(value);
61
- } else {
62
- currentRef[Number(nextSegment)] = value;
63
- }
64
- } else {
65
- currentRef[nextSegment] = value;
66
- }
67
- }
68
- return ref.value;
69
- }
70
- stringifyPath(segments) {
71
- return segments.map((segment) => {
72
- return segment.toString().replace(/[\\[\]]/g, (match) => {
73
- switch (match) {
74
- case "\\":
75
- return "\\\\";
76
- case "[":
77
- return "\\[";
78
- case "]":
79
- return "\\]";
80
- /* v8 ignore next 2 */
81
- default:
82
- return match;
83
- }
84
- });
85
- }).reduce((result, segment, i) => {
86
- if (i === 0) {
87
- return segment;
88
- }
89
- return `${result}[${segment}]`;
90
- }, "");
91
- }
92
- parsePath(path) {
93
- const segments = [];
94
- let inBrackets = false;
95
- let currentSegment = "";
96
- let backslashCount = 0;
97
- for (let i = 0; i < path.length; i++) {
98
- const char = path[i];
99
- const nextChar = path[i + 1];
100
- if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
101
- if (nextChar === void 0) {
102
- inBrackets = false;
103
- }
104
- segments.push(currentSegment);
105
- currentSegment = "";
106
- i++;
107
- } else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
108
- inBrackets = true;
109
- segments.push(currentSegment);
110
- currentSegment = "";
111
- } else if (char === "\\") {
112
- backslashCount++;
113
- } else {
114
- currentSegment += "\\".repeat(backslashCount / 2) + char;
115
- backslashCount = 0;
116
- }
117
- }
118
- return inBrackets || segments.length === 0 ? [path] : segments;
119
- }
120
- };
121
- function isValidArrayIndex(value) {
122
- return /^0$|^[1-9]\d*$/.test(value);
123
- }
124
-
125
- // src/openapi/json-serializer.ts
126
- import { isObject as isObject2 } from "@orpc/shared";
127
- var OpenAPIJsonSerializer = class {
128
- serialize(data, hasBlobRef = { value: false }) {
129
- if (data instanceof Blob) {
130
- hasBlobRef.value = true;
131
- return [data, hasBlobRef.value];
132
- }
133
- if (data instanceof Set) {
134
- return this.serialize(Array.from(data), hasBlobRef);
135
- }
136
- if (data instanceof Map) {
137
- return this.serialize(Array.from(data.entries()), hasBlobRef);
138
- }
139
- if (Array.isArray(data)) {
140
- const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
141
- return [json, hasBlobRef.value];
142
- }
143
- if (isObject2(data)) {
144
- const json = {};
145
- for (const k in data) {
146
- json[k] = this.serialize(data[k], hasBlobRef)[0];
147
- }
148
- return [json, hasBlobRef.value];
149
- }
150
- if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
151
- return [data.toString(), hasBlobRef.value];
152
- }
153
- if (data instanceof Date) {
154
- return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
155
- }
156
- if (Number.isNaN(data)) {
157
- return [null, hasBlobRef.value];
158
- }
159
- return [data, hasBlobRef.value];
160
- }
161
- };
162
-
163
- // src/openapi/serializer.ts
164
- import { isAsyncIteratorObject } from "@orpc/shared";
165
- import { ErrorEvent } from "@orpc/standard-server";
166
- var OpenAPISerializer = class {
167
- constructor(jsonSerializer = new OpenAPIJsonSerializer(), bracketNotation = new BracketNotationSerializer()) {
168
- this.jsonSerializer = jsonSerializer;
169
- this.bracketNotation = bracketNotation;
170
- }
171
- serialize(data) {
172
- if (isAsyncIteratorObject(data)) {
173
- return mapEventIterator(data, {
174
- value: async (value) => this.#serialize(value, false),
175
- error: async (e) => {
176
- if (e instanceof ErrorEvent) {
177
- return new ErrorEvent({
178
- data: this.#serialize(e.data, false),
179
- cause: e
180
- });
181
- }
182
- return new ErrorEvent({
183
- data: this.#serialize(toORPCError(e).toJSON(), false),
184
- cause: e
185
- });
186
- }
187
- });
188
- }
189
- return this.#serialize(data, true);
190
- }
191
- #serialize(data, enableFormData) {
192
- if (data instanceof Blob || data === void 0) {
193
- return data;
194
- }
195
- const [json, hasBlob] = this.jsonSerializer.serialize(data);
196
- if (!enableFormData || !hasBlob) {
197
- return json;
198
- }
199
- const form = new FormData();
200
- for (const [path, value] of this.bracketNotation.serialize(json)) {
201
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
202
- form.append(path, value.toString());
203
- } else if (value instanceof Blob) {
204
- form.append(path, value);
205
- }
206
- }
207
- return form;
208
- }
209
- deserialize(data) {
210
- if (data instanceof URLSearchParams || data instanceof FormData) {
211
- return this.bracketNotation.deserialize(Array.from(data.entries()));
212
- }
213
- if (isAsyncIteratorObject(data)) {
214
- return mapEventIterator(data, {
215
- value: async (value) => value,
216
- error: async (e) => {
217
- if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
218
- return ORPCError.fromJSON(e.data, { cause: e });
219
- }
220
- return e;
221
- }
222
- });
223
- }
224
- return data;
225
- }
226
- };
227
- export {
228
- BracketNotationSerializer,
229
- OpenAPIJsonSerializer,
230
- OpenAPISerializer
231
- };
232
- //# sourceMappingURL=openapi.js.map
package/dist/rpc.js DELETED
@@ -1,10 +0,0 @@
1
- import {
2
- RPCJsonSerializer,
3
- RPCSerializer
4
- } from "./chunk-FF5VXXNP.js";
5
- import "./chunk-7F3XVLRJ.js";
6
- export {
7
- RPCJsonSerializer,
8
- RPCSerializer
9
- };
10
- //# sourceMappingURL=rpc.js.map
@@ -1,3 +0,0 @@
1
- export * from './rpc-link';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map