@orpc/client 0.0.0-next.3cb80cf → 0.0.0-next.3e1c2e9

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 (42) hide show
  1. package/README.md +92 -0
  2. package/dist/adapters/fetch/index.d.mts +30 -0
  3. package/dist/adapters/fetch/index.d.ts +30 -0
  4. package/dist/adapters/fetch/index.mjs +37 -0
  5. package/dist/adapters/standard/index.d.mts +105 -0
  6. package/dist/adapters/standard/index.d.ts +105 -0
  7. package/dist/adapters/standard/index.mjs +5 -0
  8. package/dist/index.d.mts +150 -0
  9. package/dist/index.d.ts +150 -0
  10. package/dist/{index.js → index.mjs} +20 -38
  11. package/dist/plugins/index.d.mts +62 -0
  12. package/dist/plugins/index.d.ts +62 -0
  13. package/dist/plugins/index.mjs +127 -0
  14. package/dist/shared/client.3Q53fveR.mjs +334 -0
  15. package/dist/{chunk-2UPNYYFF.js → shared/client.BacCdg3F.mjs} +9 -125
  16. package/dist/shared/client.CupM8eRP.d.mts +30 -0
  17. package/dist/shared/client.CupM8eRP.d.ts +30 -0
  18. package/dist/shared/client.CvnV7_uV.mjs +12 -0
  19. package/dist/shared/client.DrOAzyMB.d.mts +45 -0
  20. package/dist/shared/client.aGal-uGY.d.ts +45 -0
  21. package/package.json +20 -25
  22. package/dist/chunk-TPEMQB7D.js +0 -178
  23. package/dist/fetch.js +0 -128
  24. package/dist/openapi.js +0 -329
  25. package/dist/rpc.js +0 -10
  26. package/dist/src/adapters/fetch/index.d.ts +0 -3
  27. package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
  28. package/dist/src/adapters/fetch/types.d.ts +0 -5
  29. package/dist/src/client.d.ts +0 -9
  30. package/dist/src/dynamic-link.d.ts +0 -12
  31. package/dist/src/error.d.ts +0 -106
  32. package/dist/src/event-iterator-state.d.ts +0 -9
  33. package/dist/src/event-iterator.d.ts +0 -12
  34. package/dist/src/index.d.ts +0 -9
  35. package/dist/src/openapi/bracket-notation.d.ts +0 -84
  36. package/dist/src/openapi/index.d.ts +0 -4
  37. package/dist/src/openapi/json-serializer.d.ts +0 -5
  38. package/dist/src/openapi/serializer.d.ts +0 -11
  39. package/dist/src/rpc/index.d.ts +0 -2
  40. package/dist/src/rpc/serializer.d.ts +0 -22
  41. package/dist/src/types.d.ts +0 -29
  42. package/dist/src/utils.d.ts +0 -5
@@ -0,0 +1,334 @@
1
+ import { intercept, isObject, value, trim, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
+ import { C as CompositeClientPlugin } from './client.CvnV7_uV.mjs';
3
+ import { ErrorEvent } from '@orpc/standard-server';
4
+ import { O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BacCdg3F.mjs';
5
+
6
+ class InvalidEventIteratorRetryResponse extends Error {
7
+ }
8
+ class StandardLink {
9
+ constructor(codec, sender, options = {}) {
10
+ this.codec = codec;
11
+ this.sender = sender;
12
+ const plugin = new CompositeClientPlugin(options.plugins);
13
+ plugin.init(options);
14
+ this.interceptors = options.interceptors ?? [];
15
+ this.clientInterceptors = options.clientInterceptors ?? [];
16
+ }
17
+ interceptors;
18
+ clientInterceptors;
19
+ call(path, input, options) {
20
+ return intercept(this.interceptors, { path, input, options }, async ({ path: path2, input: input2, options: options2 }) => {
21
+ const output = await this.#call(path2, input2, options2);
22
+ return output;
23
+ });
24
+ }
25
+ async #call(path, input, options) {
26
+ const request = await this.codec.encode(path, input, options);
27
+ const response = await intercept(
28
+ this.clientInterceptors,
29
+ { request },
30
+ ({ request: request2 }) => this.sender.call(request2, options, path, input)
31
+ );
32
+ const output = await this.codec.decode(response, options, path, input);
33
+ return output;
34
+ }
35
+ }
36
+
37
+ const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = {
38
+ BIGINT: 0,
39
+ DATE: 1,
40
+ NAN: 2,
41
+ UNDEFINED: 3,
42
+ URL: 4,
43
+ REGEXP: 5,
44
+ SET: 6,
45
+ MAP: 7
46
+ };
47
+ class StandardRPCJsonSerializer {
48
+ customSerializers;
49
+ constructor(options = {}) {
50
+ this.customSerializers = options.customJsonSerializers ?? [];
51
+ if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) {
52
+ throw new Error("Custom serializer type must be unique.");
53
+ }
54
+ }
55
+ serialize(data, segments = [], meta = [], maps = [], blobs = []) {
56
+ for (const custom of this.customSerializers) {
57
+ if (custom.condition(data)) {
58
+ const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs);
59
+ meta.push([custom.type, ...segments]);
60
+ return result;
61
+ }
62
+ }
63
+ if (data instanceof Blob) {
64
+ maps.push(segments);
65
+ blobs.push(data);
66
+ return [data, meta, maps, blobs];
67
+ }
68
+ if (typeof data === "bigint") {
69
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]);
70
+ return [data.toString(), meta, maps, blobs];
71
+ }
72
+ if (data instanceof Date) {
73
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]);
74
+ if (Number.isNaN(data.getTime())) {
75
+ return [null, meta, maps, blobs];
76
+ }
77
+ return [data.toISOString(), meta, maps, blobs];
78
+ }
79
+ if (Number.isNaN(data)) {
80
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]);
81
+ return [null, meta, maps, blobs];
82
+ }
83
+ if (data instanceof URL) {
84
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]);
85
+ return [data.toString(), meta, maps, blobs];
86
+ }
87
+ if (data instanceof RegExp) {
88
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]);
89
+ return [data.toString(), meta, maps, blobs];
90
+ }
91
+ if (data instanceof Set) {
92
+ const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
93
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]);
94
+ return result;
95
+ }
96
+ if (data instanceof Map) {
97
+ const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
98
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]);
99
+ return result;
100
+ }
101
+ if (Array.isArray(data)) {
102
+ const json = data.map((v, i) => {
103
+ if (v === void 0) {
104
+ meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]);
105
+ return v;
106
+ }
107
+ return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
108
+ });
109
+ return [json, meta, maps, blobs];
110
+ }
111
+ if (isObject(data)) {
112
+ const json = {};
113
+ for (const k in data) {
114
+ if (k === "toJSON" && typeof data[k] === "function") {
115
+ continue;
116
+ }
117
+ json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
118
+ }
119
+ return [json, meta, maps, blobs];
120
+ }
121
+ return [data, meta, maps, blobs];
122
+ }
123
+ deserialize(json, meta, maps, getBlob) {
124
+ const ref = { data: json };
125
+ if (maps && getBlob) {
126
+ maps.forEach((segments, i) => {
127
+ let currentRef = ref;
128
+ let preSegment = "data";
129
+ segments.forEach((segment) => {
130
+ currentRef = currentRef[preSegment];
131
+ preSegment = segment;
132
+ });
133
+ currentRef[preSegment] = getBlob(i);
134
+ });
135
+ }
136
+ for (const item of meta) {
137
+ const type = item[0];
138
+ let currentRef = ref;
139
+ let preSegment = "data";
140
+ for (let i = 1; i < item.length; i++) {
141
+ currentRef = currentRef[preSegment];
142
+ preSegment = item[i];
143
+ }
144
+ for (const custom of this.customSerializers) {
145
+ if (custom.type === type) {
146
+ currentRef[preSegment] = custom.deserialize(currentRef[preSegment]);
147
+ break;
148
+ }
149
+ }
150
+ switch (type) {
151
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT:
152
+ currentRef[preSegment] = BigInt(currentRef[preSegment]);
153
+ break;
154
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE:
155
+ currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
156
+ break;
157
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN:
158
+ currentRef[preSegment] = Number.NaN;
159
+ break;
160
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED:
161
+ currentRef[preSegment] = void 0;
162
+ break;
163
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL:
164
+ currentRef[preSegment] = new URL(currentRef[preSegment]);
165
+ break;
166
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: {
167
+ const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
168
+ currentRef[preSegment] = new RegExp(pattern, flags);
169
+ break;
170
+ }
171
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET:
172
+ currentRef[preSegment] = new Set(currentRef[preSegment]);
173
+ break;
174
+ case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP:
175
+ currentRef[preSegment] = new Map(currentRef[preSegment]);
176
+ break;
177
+ }
178
+ }
179
+ return ref.data;
180
+ }
181
+ }
182
+
183
+ class StandardRPCLinkCodec {
184
+ constructor(serializer, options) {
185
+ this.serializer = serializer;
186
+ this.baseUrl = options.url;
187
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
188
+ this.fallbackMethod = options.fallbackMethod ?? "POST";
189
+ this.expectedMethod = options.method ?? this.fallbackMethod;
190
+ this.headers = options.headers ?? {};
191
+ }
192
+ baseUrl;
193
+ maxUrlLength;
194
+ fallbackMethod;
195
+ expectedMethod;
196
+ headers;
197
+ async encode(path, input, options) {
198
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
199
+ const headers = { ...await value(this.headers, options, path, input) };
200
+ const baseUrl = await value(this.baseUrl, options, path, input);
201
+ const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
202
+ if (options.lastEventId !== void 0) {
203
+ if (Array.isArray(headers["last-event-id"])) {
204
+ headers["last-event-id"] = [...headers["last-event-id"], options.lastEventId];
205
+ } else if (headers["last-event-id"] !== void 0) {
206
+ headers["last-event-id"] = [headers["last-event-id"], options.lastEventId];
207
+ } else {
208
+ headers["last-event-id"] = options.lastEventId;
209
+ }
210
+ }
211
+ const serialized = this.serializer.serialize(input);
212
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
213
+ const maxUrlLength = await value(this.maxUrlLength, options, path, input);
214
+ const getUrl = new URL(url);
215
+ getUrl.searchParams.append("data", stringifyJSON(serialized));
216
+ if (getUrl.toString().length <= maxUrlLength) {
217
+ return {
218
+ body: void 0,
219
+ method: expectedMethod,
220
+ headers,
221
+ url: getUrl,
222
+ signal: options.signal
223
+ };
224
+ }
225
+ }
226
+ return {
227
+ url,
228
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
229
+ headers,
230
+ body: serialized,
231
+ signal: options.signal
232
+ };
233
+ }
234
+ async decode(response) {
235
+ const isOk = response.status >= 200 && response.status < 300;
236
+ const deserialized = await (async () => {
237
+ let isBodyOk = false;
238
+ try {
239
+ const body = await response.body();
240
+ isBodyOk = true;
241
+ return this.serializer.deserialize(body);
242
+ } catch (error) {
243
+ if (!isBodyOk) {
244
+ throw new Error("Cannot parse response body, please check the response body and content-type.", {
245
+ cause: error
246
+ });
247
+ }
248
+ throw new Error("Invalid RPC response format.", {
249
+ cause: error
250
+ });
251
+ }
252
+ })();
253
+ if (!isOk) {
254
+ if (ORPCError.isValidJSON(deserialized)) {
255
+ throw ORPCError.fromJSON(deserialized);
256
+ }
257
+ throw new Error("Invalid RPC error response format.", {
258
+ cause: deserialized
259
+ });
260
+ }
261
+ return deserialized;
262
+ }
263
+ }
264
+
265
+ class StandardRPCSerializer {
266
+ constructor(jsonSerializer) {
267
+ this.jsonSerializer = jsonSerializer;
268
+ }
269
+ serialize(data) {
270
+ if (isAsyncIteratorObject(data)) {
271
+ return mapEventIterator(data, {
272
+ value: async (value) => this.#serialize(value, false),
273
+ error: async (e) => {
274
+ return new ErrorEvent({
275
+ data: this.#serialize(toORPCError(e).toJSON(), false),
276
+ cause: e
277
+ });
278
+ }
279
+ });
280
+ }
281
+ return this.#serialize(data, true);
282
+ }
283
+ #serialize(data, enableFormData) {
284
+ const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
285
+ const meta = meta_.length === 0 ? void 0 : meta_;
286
+ if (!enableFormData || blobs.length === 0) {
287
+ return {
288
+ json,
289
+ meta
290
+ };
291
+ }
292
+ const form = new FormData();
293
+ form.set("data", stringifyJSON({ json, meta, maps }));
294
+ blobs.forEach((blob, i) => {
295
+ form.set(i.toString(), blob);
296
+ });
297
+ return form;
298
+ }
299
+ deserialize(data) {
300
+ if (isAsyncIteratorObject(data)) {
301
+ return mapEventIterator(data, {
302
+ value: async (value) => this.#deserialize(value),
303
+ error: async (e) => {
304
+ if (!(e instanceof ErrorEvent)) {
305
+ return e;
306
+ }
307
+ const deserialized = this.#deserialize(e.data);
308
+ if (ORPCError.isValidJSON(deserialized)) {
309
+ return ORPCError.fromJSON(deserialized, { cause: e });
310
+ }
311
+ return new ErrorEvent({
312
+ data: deserialized,
313
+ cause: e
314
+ });
315
+ }
316
+ });
317
+ }
318
+ return this.#deserialize(data);
319
+ }
320
+ #deserialize(data) {
321
+ if (!(data instanceof FormData)) {
322
+ return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
323
+ }
324
+ const serialized = JSON.parse(data.get("data"));
325
+ return this.jsonSerializer.deserialize(
326
+ serialized.json,
327
+ serialized.meta ?? [],
328
+ serialized.maps,
329
+ (i) => data.get(i.toString())
330
+ );
331
+ }
332
+ }
333
+
334
+ export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d };
@@ -1,12 +1,7 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
1
+ import { isObject, isTypescriptObject } from '@orpc/shared';
2
+ import { getEventMeta, withEventMeta } from '@orpc/standard-server';
6
3
 
7
- // src/error.ts
8
- import { isObject } from "@orpc/shared";
9
- var COMMON_ORPC_ERROR_DEFS = {
4
+ const COMMON_ORPC_ERROR_DEFS = {
10
5
  BAD_REQUEST: {
11
6
  status: 400,
12
7
  message: "Bad Request"
@@ -90,7 +85,7 @@ function fallbackORPCErrorStatus(code, status) {
90
85
  function fallbackORPCErrorMessage(code, message) {
91
86
  return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
92
87
  }
93
- var ORPCError = class _ORPCError extends Error {
88
+ class ORPCError extends Error {
94
89
  defined;
95
90
  code;
96
91
  status;
@@ -116,7 +111,7 @@ var ORPCError = class _ORPCError extends Error {
116
111
  };
117
112
  }
118
113
  static fromJSON(json, options) {
119
- return new _ORPCError(json.code, {
114
+ return new ORPCError(json.code, {
120
115
  ...options,
121
116
  ...json
122
117
  });
@@ -131,7 +126,7 @@ var ORPCError = class _ORPCError extends Error {
131
126
  }
132
127
  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";
133
128
  }
134
- };
129
+ }
135
130
  function isDefinedError(error) {
136
131
  return error instanceof ORPCError && error.defined;
137
132
  }
@@ -142,37 +137,6 @@ function toORPCError(error) {
142
137
  });
143
138
  }
144
139
 
145
- // src/event-iterator-state.ts
146
- var iteratorStates = /* @__PURE__ */ new WeakMap();
147
- function registerEventIteratorState(iterator, state) {
148
- iteratorStates.set(iterator, state);
149
- }
150
- function updateEventIteratorStatus(state, status) {
151
- if (state.status !== status) {
152
- state.status = status;
153
- state.listeners.forEach((cb) => cb(status));
154
- }
155
- }
156
- function onEventIteratorStatusChange(iterator, callback, notifyImmediately = true) {
157
- const state = iteratorStates.get(iterator);
158
- if (!state) {
159
- throw new Error("Iterator is not registered.");
160
- }
161
- if (notifyImmediately) {
162
- callback(state.status);
163
- }
164
- state.listeners.push(callback);
165
- return () => {
166
- const index = state.listeners.indexOf(callback);
167
- if (index !== -1) {
168
- state.listeners.splice(index, 1);
169
- }
170
- };
171
- }
172
-
173
- // src/event-iterator.ts
174
- import { getEventMeta, isEventMetaContainer, withEventMeta } from "@orpc/server-standard";
175
- import { retry } from "@orpc/shared";
176
140
  function mapEventIterator(iterator, maps) {
177
141
  return async function* () {
178
142
  try {
@@ -181,7 +145,7 @@ function mapEventIterator(iterator, maps) {
181
145
  let mappedValue = await maps.value(value, done);
182
146
  if (mappedValue !== value) {
183
147
  const meta = getEventMeta(value);
184
- if (meta && isEventMetaContainer(mappedValue)) {
148
+ if (meta && isTypescriptObject(mappedValue)) {
185
149
  mappedValue = withEventMeta(mappedValue, meta);
186
150
  }
187
151
  }
@@ -194,7 +158,7 @@ function mapEventIterator(iterator, maps) {
194
158
  let mappedError = await maps.error(error);
195
159
  if (mappedError !== error) {
196
160
  const meta = getEventMeta(error);
197
- if (meta && isEventMetaContainer(mappedError)) {
161
+ if (meta && isTypescriptObject(mappedError)) {
198
162
  mappedError = withEventMeta(mappedError, meta);
199
163
  }
200
164
  }
@@ -204,85 +168,5 @@ function mapEventIterator(iterator, maps) {
204
168
  }
205
169
  }();
206
170
  }
207
- var MAX_ALLOWED_RETRY_TIMES = 99;
208
- function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
209
- const state = {
210
- status: "connected",
211
- listeners: []
212
- };
213
- const iterator = async function* () {
214
- let current = initial;
215
- let lastEventId = initialLastEventId;
216
- let lastRetry;
217
- let retryTimes = 0;
218
- try {
219
- while (true) {
220
- try {
221
- updateEventIteratorStatus(state, "connected");
222
- const { done, value } = await current.next();
223
- const meta = getEventMeta(value);
224
- lastEventId = meta?.id ?? lastEventId;
225
- lastRetry = meta?.retry ?? lastRetry;
226
- retryTimes = 0;
227
- if (done) {
228
- return value;
229
- }
230
- yield value;
231
- } catch (e) {
232
- updateEventIteratorStatus(state, "reconnecting");
233
- const meta = getEventMeta(e);
234
- lastEventId = meta?.id ?? lastEventId;
235
- lastRetry = meta?.retry ?? lastRetry;
236
- let currentError = e;
237
- current = await retry({ times: MAX_ALLOWED_RETRY_TIMES }, async (exit) => {
238
- retryTimes += 1;
239
- if (retryTimes > MAX_ALLOWED_RETRY_TIMES) {
240
- throw exit(new Error(
241
- `Exceeded maximum retry attempts (${MAX_ALLOWED_RETRY_TIMES}) for event source. Possible infinite retry loop detected. Please review the retry logic.`,
242
- { cause: currentError }
243
- ));
244
- }
245
- const reconnected = await (async () => {
246
- try {
247
- return await reconnect({
248
- lastRetry,
249
- lastEventId,
250
- retryTimes,
251
- error: currentError
252
- });
253
- } catch (e2) {
254
- currentError = e2;
255
- throw e2;
256
- }
257
- })();
258
- if (!reconnected) {
259
- throw exit(currentError);
260
- }
261
- return reconnected;
262
- });
263
- }
264
- }
265
- } finally {
266
- updateEventIteratorStatus(state, "closed");
267
- await current.return?.();
268
- }
269
- }();
270
- registerEventIteratorState(iterator, state);
271
- return iterator;
272
- }
273
171
 
274
- export {
275
- __export,
276
- COMMON_ORPC_ERROR_DEFS,
277
- fallbackORPCErrorStatus,
278
- fallbackORPCErrorMessage,
279
- ORPCError,
280
- isDefinedError,
281
- toORPCError,
282
- registerEventIteratorState,
283
- updateEventIteratorStatus,
284
- onEventIteratorStatusChange,
285
- mapEventIterator,
286
- createAutoRetryEventIterator
287
- };
288
- //# sourceMappingURL=chunk-2UPNYYFF.js.map
172
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
@@ -0,0 +1,30 @@
1
+ type ClientContext = Record<string, any>;
2
+ type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
+ type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -0,0 +1,30 @@
1
+ type ClientContext = Record<string, any>;
2
+ type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<TClientContext>];
11
+ type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
26
+ interface ClientLink<TClientContext extends ClientContext> {
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
28
+ }
29
+
30
+ export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
@@ -0,0 +1,12 @@
1
+ class CompositeClientPlugin {
2
+ constructor(plugins = []) {
3
+ this.plugins = plugins;
4
+ }
5
+ init(options) {
6
+ for (const plugin of this.plugins) {
7
+ plugin.init?.(options);
8
+ }
9
+ }
10
+ }
11
+
12
+ export { CompositeClientPlugin as C };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.mjs';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ interceptors?: Interceptor<{
17
+ path: readonly string[];
18
+ input: unknown;
19
+ options: ClientOptionsOut<T>;
20
+ }, unknown, unknown>[];
21
+ clientInterceptors?: Interceptor<{
22
+ request: StandardRequest;
23
+ }, StandardLazyResponse, unknown>[];
24
+ plugins?: ClientPlugin<T>[];
25
+ }
26
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
+ #private;
28
+ readonly codec: StandardLinkCodec<T>;
29
+ readonly sender: StandardLinkClient<T>;
30
+ private readonly interceptors;
31
+ private readonly clientInterceptors;
32
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
+ }
35
+
36
+ interface ClientPlugin<T extends ClientContext> {
37
+ init?(options: StandardLinkOptions<T>): void;
38
+ }
39
+ declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
+ private readonly plugins;
41
+ constructor(plugins?: ClientPlugin<T>[]);
42
+ init(options: StandardLinkOptions<T>): void;
43
+ }
44
+
45
+ export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.js';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ interceptors?: Interceptor<{
17
+ path: readonly string[];
18
+ input: unknown;
19
+ options: ClientOptionsOut<T>;
20
+ }, unknown, unknown>[];
21
+ clientInterceptors?: Interceptor<{
22
+ request: StandardRequest;
23
+ }, StandardLazyResponse, unknown>[];
24
+ plugins?: ClientPlugin<T>[];
25
+ }
26
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
27
+ #private;
28
+ readonly codec: StandardLinkCodec<T>;
29
+ readonly sender: StandardLinkClient<T>;
30
+ private readonly interceptors;
31
+ private readonly clientInterceptors;
32
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
33
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
34
+ }
35
+
36
+ interface ClientPlugin<T extends ClientContext> {
37
+ init?(options: StandardLinkOptions<T>): void;
38
+ }
39
+ declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
40
+ private readonly plugins;
41
+ constructor(plugins?: ClientPlugin<T>[]);
42
+ init(options: StandardLinkOptions<T>): void;
43
+ }
44
+
45
+ export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };