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

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 (49) hide show
  1. package/README.md +28 -18
  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/standard/index.d.mts +10 -0
  6. package/dist/adapters/standard/index.d.ts +10 -0
  7. package/dist/adapters/standard/index.mjs +4 -0
  8. package/dist/adapters/websocket/index.d.mts +29 -0
  9. package/dist/adapters/websocket/index.d.ts +29 -0
  10. package/dist/adapters/websocket/index.mjs +31 -0
  11. package/dist/index.d.mts +169 -0
  12. package/dist/index.d.ts +169 -0
  13. package/dist/index.mjs +65 -0
  14. package/dist/plugins/index.d.mts +162 -0
  15. package/dist/plugins/index.d.ts +162 -0
  16. package/dist/plugins/index.mjs +291 -0
  17. package/dist/shared/client.4TS_0JaO.d.mts +29 -0
  18. package/dist/shared/client.4TS_0JaO.d.ts +29 -0
  19. package/dist/shared/client.7ZYxJok_.d.ts +46 -0
  20. package/dist/shared/client.B2432-Lu.d.ts +91 -0
  21. package/dist/shared/client.CRWEpqLB.mjs +175 -0
  22. package/dist/shared/client.ClwIM_ku.d.mts +91 -0
  23. package/dist/shared/client.DpICn1BD.mjs +355 -0
  24. package/dist/shared/client.ds1abV85.d.mts +46 -0
  25. package/package.json +25 -24
  26. package/dist/chunk-7F3XVLRJ.js +0 -281
  27. package/dist/chunk-FF5VXXNP.js +0 -213
  28. package/dist/fetch.js +0 -127
  29. package/dist/index.js +0 -90
  30. package/dist/openapi.js +0 -232
  31. package/dist/rpc.js +0 -10
  32. package/dist/src/adapters/fetch/index.d.ts +0 -3
  33. package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
  34. package/dist/src/adapters/fetch/types.d.ts +0 -5
  35. package/dist/src/client.d.ts +0 -9
  36. package/dist/src/dynamic-link.d.ts +0 -12
  37. package/dist/src/error.d.ts +0 -106
  38. package/dist/src/event-iterator-state.d.ts +0 -9
  39. package/dist/src/event-iterator.d.ts +0 -12
  40. package/dist/src/index.d.ts +0 -9
  41. package/dist/src/openapi/bracket-notation.d.ts +0 -9
  42. package/dist/src/openapi/index.d.ts +0 -4
  43. package/dist/src/openapi/json-serializer.d.ts +0 -7
  44. package/dist/src/openapi/serializer.d.ts +0 -11
  45. package/dist/src/rpc/index.d.ts +0 -3
  46. package/dist/src/rpc/json-serializer.d.ts +0 -12
  47. package/dist/src/rpc/serializer.d.ts +0 -9
  48. package/dist/src/types.d.ts +0 -29
  49. package/dist/src/utils.d.ts +0 -17
@@ -1,281 +0,0 @@
1
- // src/error.ts
2
- import { isObject } from "@orpc/shared";
3
- var COMMON_ORPC_ERROR_DEFS = {
4
- BAD_REQUEST: {
5
- status: 400,
6
- message: "Bad Request"
7
- },
8
- UNAUTHORIZED: {
9
- status: 401,
10
- message: "Unauthorized"
11
- },
12
- FORBIDDEN: {
13
- status: 403,
14
- message: "Forbidden"
15
- },
16
- NOT_FOUND: {
17
- status: 404,
18
- message: "Not Found"
19
- },
20
- METHOD_NOT_SUPPORTED: {
21
- status: 405,
22
- message: "Method Not Supported"
23
- },
24
- NOT_ACCEPTABLE: {
25
- status: 406,
26
- message: "Not Acceptable"
27
- },
28
- TIMEOUT: {
29
- status: 408,
30
- message: "Request Timeout"
31
- },
32
- CONFLICT: {
33
- status: 409,
34
- message: "Conflict"
35
- },
36
- PRECONDITION_FAILED: {
37
- status: 412,
38
- message: "Precondition Failed"
39
- },
40
- PAYLOAD_TOO_LARGE: {
41
- status: 413,
42
- message: "Payload Too Large"
43
- },
44
- UNSUPPORTED_MEDIA_TYPE: {
45
- status: 415,
46
- message: "Unsupported Media Type"
47
- },
48
- UNPROCESSABLE_CONTENT: {
49
- status: 422,
50
- message: "Unprocessable Content"
51
- },
52
- TOO_MANY_REQUESTS: {
53
- status: 429,
54
- message: "Too Many Requests"
55
- },
56
- CLIENT_CLOSED_REQUEST: {
57
- status: 499,
58
- message: "Client Closed Request"
59
- },
60
- INTERNAL_SERVER_ERROR: {
61
- status: 500,
62
- message: "Internal Server Error"
63
- },
64
- NOT_IMPLEMENTED: {
65
- status: 501,
66
- message: "Not Implemented"
67
- },
68
- BAD_GATEWAY: {
69
- status: 502,
70
- message: "Bad Gateway"
71
- },
72
- SERVICE_UNAVAILABLE: {
73
- status: 503,
74
- message: "Service Unavailable"
75
- },
76
- GATEWAY_TIMEOUT: {
77
- status: 504,
78
- message: "Gateway Timeout"
79
- }
80
- };
81
- function fallbackORPCErrorStatus(code, status) {
82
- return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
83
- }
84
- function fallbackORPCErrorMessage(code, message) {
85
- return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
86
- }
87
- var ORPCError = class _ORPCError extends Error {
88
- defined;
89
- code;
90
- status;
91
- data;
92
- constructor(code, ...[options]) {
93
- if (options?.status && (options.status < 400 || options.status >= 600)) {
94
- throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
95
- }
96
- const message = fallbackORPCErrorMessage(code, options?.message);
97
- super(message, options);
98
- this.code = code;
99
- this.status = fallbackORPCErrorStatus(code, options?.status);
100
- this.defined = options?.defined ?? false;
101
- this.data = options?.data;
102
- }
103
- toJSON() {
104
- return {
105
- defined: this.defined,
106
- code: this.code,
107
- status: this.status,
108
- message: this.message,
109
- data: this.data
110
- };
111
- }
112
- static fromJSON(json, options) {
113
- return new _ORPCError(json.code, {
114
- ...options,
115
- ...json
116
- });
117
- }
118
- static isValidJSON(json) {
119
- if (!isObject(json)) {
120
- return false;
121
- }
122
- const validKeys = ["defined", "code", "status", "message", "data"];
123
- if (Object.keys(json).some((k) => !validKeys.includes(k))) {
124
- return false;
125
- }
126
- return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
127
- }
128
- };
129
- function isDefinedError(error) {
130
- return error instanceof ORPCError && error.defined;
131
- }
132
- function toORPCError(error) {
133
- return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
134
- message: "Internal server error",
135
- cause: error
136
- });
137
- }
138
-
139
- // src/event-iterator-state.ts
140
- var iteratorStates = /* @__PURE__ */ new WeakMap();
141
- function registerEventIteratorState(iterator, state) {
142
- iteratorStates.set(iterator, state);
143
- }
144
- function updateEventIteratorStatus(state, status) {
145
- if (state.status !== status) {
146
- state.status = status;
147
- state.listeners.forEach((cb) => cb(status));
148
- }
149
- }
150
- function onEventIteratorStatusChange(iterator, callback, notifyImmediately = true) {
151
- const state = iteratorStates.get(iterator);
152
- if (!state) {
153
- throw new Error("Iterator is not registered.");
154
- }
155
- if (notifyImmediately) {
156
- callback(state.status);
157
- }
158
- state.listeners.push(callback);
159
- return () => {
160
- const index = state.listeners.indexOf(callback);
161
- if (index !== -1) {
162
- state.listeners.splice(index, 1);
163
- }
164
- };
165
- }
166
-
167
- // src/event-iterator.ts
168
- import { isTypescriptObject, retry } from "@orpc/shared";
169
- import { getEventMeta, withEventMeta } from "@orpc/standard-server";
170
- function mapEventIterator(iterator, maps) {
171
- return async function* () {
172
- try {
173
- while (true) {
174
- const { done, value } = await iterator.next();
175
- let mappedValue = await maps.value(value, done);
176
- if (mappedValue !== value) {
177
- const meta = getEventMeta(value);
178
- if (meta && isTypescriptObject(mappedValue)) {
179
- mappedValue = withEventMeta(mappedValue, meta);
180
- }
181
- }
182
- if (done) {
183
- return mappedValue;
184
- }
185
- yield mappedValue;
186
- }
187
- } catch (error) {
188
- let mappedError = await maps.error(error);
189
- if (mappedError !== error) {
190
- const meta = getEventMeta(error);
191
- if (meta && isTypescriptObject(mappedError)) {
192
- mappedError = withEventMeta(mappedError, meta);
193
- }
194
- }
195
- throw mappedError;
196
- } finally {
197
- await iterator.return?.();
198
- }
199
- }();
200
- }
201
- var MAX_ALLOWED_RETRY_TIMES = 99;
202
- function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
203
- const state = {
204
- status: "connected",
205
- listeners: []
206
- };
207
- const iterator = async function* () {
208
- let current = initial;
209
- let lastEventId = initialLastEventId;
210
- let lastRetry;
211
- let retryTimes = 0;
212
- try {
213
- while (true) {
214
- try {
215
- updateEventIteratorStatus(state, "connected");
216
- const { done, value } = await current.next();
217
- const meta = getEventMeta(value);
218
- lastEventId = meta?.id ?? lastEventId;
219
- lastRetry = meta?.retry ?? lastRetry;
220
- retryTimes = 0;
221
- if (done) {
222
- return value;
223
- }
224
- yield value;
225
- } catch (e) {
226
- updateEventIteratorStatus(state, "reconnecting");
227
- const meta = getEventMeta(e);
228
- lastEventId = meta?.id ?? lastEventId;
229
- lastRetry = meta?.retry ?? lastRetry;
230
- let currentError = e;
231
- current = await retry({ times: MAX_ALLOWED_RETRY_TIMES }, async (exit) => {
232
- retryTimes += 1;
233
- if (retryTimes > MAX_ALLOWED_RETRY_TIMES) {
234
- throw exit(new Error(
235
- `Exceeded maximum retry attempts (${MAX_ALLOWED_RETRY_TIMES}) for event source. Possible infinite retry loop detected. Please review the retry logic.`,
236
- { cause: currentError }
237
- ));
238
- }
239
- const reconnected = await (async () => {
240
- try {
241
- return await reconnect({
242
- lastRetry,
243
- lastEventId,
244
- retryTimes,
245
- error: currentError
246
- });
247
- } catch (e2) {
248
- currentError = e2;
249
- throw e2;
250
- }
251
- })();
252
- if (!reconnected) {
253
- throw exit(currentError);
254
- }
255
- return reconnected;
256
- });
257
- }
258
- }
259
- } finally {
260
- updateEventIteratorStatus(state, "closed");
261
- await current.return?.();
262
- }
263
- }();
264
- registerEventIteratorState(iterator, state);
265
- return iterator;
266
- }
267
-
268
- export {
269
- COMMON_ORPC_ERROR_DEFS,
270
- fallbackORPCErrorStatus,
271
- fallbackORPCErrorMessage,
272
- ORPCError,
273
- isDefinedError,
274
- toORPCError,
275
- registerEventIteratorState,
276
- updateEventIteratorStatus,
277
- onEventIteratorStatusChange,
278
- mapEventIterator,
279
- createAutoRetryEventIterator
280
- };
281
- //# sourceMappingURL=chunk-7F3XVLRJ.js.map
@@ -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