@orpc/client 0.40.0 → 0.41.1

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.
@@ -1,8 +1,29 @@
1
- import type { ClientContext, ClientOptions } from '@orpc/contract';
1
+ export type ClientContext = Record<string, any>;
2
+ export 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
+ export 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
+ export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ export interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ export type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ export type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
2
23
  export type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
3
24
  context: TClientContext;
4
25
  };
5
26
  export interface ClientLink<TClientContext extends ClientContext> {
6
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
7
28
  }
8
29
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { ORPCError } from './error';
2
+ import type { ClientPromiseResult } from './types';
3
+ export type SafeResult<TOutput, TError extends Error> = [output: TOutput, error: undefined, isDefinedError: false] | [output: undefined, error: TError, isDefinedError: false] | [output: undefined, error: Extract<TError, ORPCError<any, any>>, isDefinedError: true];
4
+ export declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
5
+ //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.40.0",
4
+ "version": "0.41.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,6 +19,16 @@
19
19
  "import": "./dist/index.js",
20
20
  "default": "./dist/index.js"
21
21
  },
22
+ "./openapi": {
23
+ "types": "./dist/src/openapi/index.d.ts",
24
+ "import": "./dist/openapi.js",
25
+ "default": "./dist/openapi.js"
26
+ },
27
+ "./rpc": {
28
+ "types": "./dist/src/rpc/index.d.ts",
29
+ "import": "./dist/rpc.js",
30
+ "default": "./dist/rpc.js"
31
+ },
22
32
  "./fetch": {
23
33
  "types": "./dist/src/adapters/fetch/index.d.ts",
24
34
  "import": "./dist/fetch.js",
@@ -36,13 +46,10 @@
36
46
  "dependencies": {
37
47
  "@orpc/server-standard": "^0.4.0",
38
48
  "@orpc/server-standard-fetch": "^0.4.0",
39
- "@orpc/contract": "0.40.0",
40
- "@orpc/server": "0.40.0",
41
- "@orpc/shared": "0.40.0"
49
+ "@orpc/shared": "0.41.1"
42
50
  },
43
51
  "devDependencies": {
44
- "zod": "^3.24.1",
45
- "@orpc/openapi": "0.40.0"
52
+ "zod": "^3.24.1"
46
53
  },
47
54
  "scripts": {
48
55
  "build": "tsup --onSuccess='tsc -b --noCheck'",
@@ -1,105 +0,0 @@
1
- // src/event-iterator-state.ts
2
- var iteratorStates = /* @__PURE__ */ new WeakMap();
3
- function registerEventIteratorState(iterator, state) {
4
- iteratorStates.set(iterator, state);
5
- }
6
- function updateEventIteratorStatus(state, status) {
7
- if (state.status !== status) {
8
- state.status = status;
9
- state.listeners.forEach((cb) => cb(status));
10
- }
11
- }
12
- function onEventIteratorStatusChange(iterator, callback, notifyImmediately = true) {
13
- const state = iteratorStates.get(iterator);
14
- if (!state) {
15
- throw new Error("Iterator is not registered.");
16
- }
17
- if (notifyImmediately) {
18
- callback(state.status);
19
- }
20
- state.listeners.push(callback);
21
- return () => {
22
- const index = state.listeners.indexOf(callback);
23
- if (index !== -1) {
24
- state.listeners.splice(index, 1);
25
- }
26
- };
27
- }
28
-
29
- // src/event-iterator.ts
30
- import { getEventMeta } from "@orpc/server-standard";
31
- import { retry } from "@orpc/shared";
32
- var MAX_ALLOWED_RETRY_TIMES = 99;
33
- function createAutoRetryEventIterator(initial, reconnect, initialLastEventId) {
34
- const state = {
35
- status: "connected",
36
- listeners: []
37
- };
38
- const iterator = async function* () {
39
- let current = initial;
40
- let lastEventId = initialLastEventId;
41
- let lastRetry;
42
- let retryTimes = 0;
43
- try {
44
- while (true) {
45
- try {
46
- updateEventIteratorStatus(state, "connected");
47
- const { done, value } = await current.next();
48
- const meta = getEventMeta(value);
49
- lastEventId = meta?.id ?? lastEventId;
50
- lastRetry = meta?.retry ?? lastRetry;
51
- retryTimes = 0;
52
- if (done) {
53
- return value;
54
- }
55
- yield value;
56
- } catch (e) {
57
- updateEventIteratorStatus(state, "reconnecting");
58
- const meta = getEventMeta(e);
59
- lastEventId = meta?.id ?? lastEventId;
60
- lastRetry = meta?.retry ?? lastRetry;
61
- let currentError = e;
62
- current = await retry({ times: MAX_ALLOWED_RETRY_TIMES }, async (exit) => {
63
- retryTimes += 1;
64
- if (retryTimes > MAX_ALLOWED_RETRY_TIMES) {
65
- throw exit(new Error(
66
- `Exceeded maximum retry attempts (${MAX_ALLOWED_RETRY_TIMES}) for event source. Possible infinite retry loop detected. Please review the retry logic.`,
67
- { cause: currentError }
68
- ));
69
- }
70
- const reconnected = await (async () => {
71
- try {
72
- return await reconnect({
73
- lastRetry,
74
- lastEventId,
75
- retryTimes,
76
- error: currentError
77
- });
78
- } catch (e2) {
79
- currentError = e2;
80
- throw e2;
81
- }
82
- })();
83
- if (!reconnected) {
84
- throw exit(currentError);
85
- }
86
- return reconnected;
87
- });
88
- }
89
- }
90
- } finally {
91
- updateEventIteratorStatus(state, "closed");
92
- await current.return?.();
93
- }
94
- }();
95
- registerEventIteratorState(iterator, state);
96
- return iterator;
97
- }
98
-
99
- export {
100
- registerEventIteratorState,
101
- updateEventIteratorStatus,
102
- onEventIteratorStatusChange,
103
- createAutoRetryEventIterator
104
- };
105
- //# sourceMappingURL=chunk-HYT35LXG.js.map