@orpc/client 0.0.0-next.3f40711 → 0.0.0-next.3f73bd3
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 +96 -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 +44 -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 +389 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.C4VxIexA.d.mts +46 -0
- package/dist/shared/client.CXXEPIbK.d.ts +46 -0
- package/dist/shared/client.DHOfWE0c.mjs +172 -0
- package/dist/shared/client.DwfV9Oyl.mjs +355 -0
- package/dist/shared/client.WCinBImJ.d.ts +91 -0
- package/dist/shared/client.aTp4sII-.d.mts +91 -0
- package/package.json +32 -19
- package/dist/chunk-HYT35LXG.js +0 -105
- package/dist/fetch.js +0 -126
- package/dist/index.js +0 -58
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/orpc-link.d.ts +0 -97
- package/dist/src/adapters/fetch/types.d.ts +0 -6
- package/dist/src/client.d.ts +0 -11
- package/dist/src/dynamic-link.d.ts +0 -13
- package/dist/src/event-iterator-state.d.ts +0 -9
- package/dist/src/event-iterator.d.ts +0 -8
- package/dist/src/index.d.ts +0 -8
- package/dist/src/types.d.ts +0 -8
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CXXEPIbK.js';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
|
|
6
|
+
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
7
|
+
readonly BIGINT: 0;
|
|
8
|
+
readonly DATE: 1;
|
|
9
|
+
readonly NAN: 2;
|
|
10
|
+
readonly UNDEFINED: 3;
|
|
11
|
+
readonly URL: 4;
|
|
12
|
+
readonly REGEXP: 5;
|
|
13
|
+
readonly SET: 6;
|
|
14
|
+
readonly MAP: 7;
|
|
15
|
+
};
|
|
16
|
+
type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
|
|
17
|
+
type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
|
|
18
|
+
interface StandardRPCCustomJsonSerializer {
|
|
19
|
+
type: number;
|
|
20
|
+
condition(data: unknown): boolean;
|
|
21
|
+
serialize(data: any): unknown;
|
|
22
|
+
deserialize(serialized: any): unknown;
|
|
23
|
+
}
|
|
24
|
+
interface StandardRPCJsonSerializerOptions {
|
|
25
|
+
customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
|
|
26
|
+
}
|
|
27
|
+
declare class StandardRPCJsonSerializer {
|
|
28
|
+
private readonly customSerializers;
|
|
29
|
+
constructor(options?: StandardRPCJsonSerializerOptions);
|
|
30
|
+
serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
|
|
31
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
|
|
32
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class StandardRPCSerializer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly jsonSerializer;
|
|
38
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
|
39
|
+
serialize(data: unknown): object;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum length of the URL.
|
|
50
|
+
*
|
|
51
|
+
* @default 2083
|
|
52
|
+
*/
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
|
+
/**
|
|
55
|
+
* The method used to make the request.
|
|
56
|
+
*
|
|
57
|
+
* @default 'POST'
|
|
58
|
+
*/
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
|
+
/**
|
|
61
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
|
+
* GET is not allowed, it's very dangerous.
|
|
63
|
+
*
|
|
64
|
+
* @default 'POST'
|
|
65
|
+
*/
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
67
|
+
/**
|
|
68
|
+
* Inject headers to the request.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
|
+
}
|
|
72
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
|
+
private readonly serializer;
|
|
74
|
+
private readonly baseUrl;
|
|
75
|
+
private readonly maxUrlLength;
|
|
76
|
+
private readonly fallbackMethod;
|
|
77
|
+
private readonly expectedMethod;
|
|
78
|
+
private readonly headers;
|
|
79
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
|
80
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
81
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
85
|
+
}
|
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
+
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.C4VxIexA.mjs';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
|
|
6
|
+
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
7
|
+
readonly BIGINT: 0;
|
|
8
|
+
readonly DATE: 1;
|
|
9
|
+
readonly NAN: 2;
|
|
10
|
+
readonly UNDEFINED: 3;
|
|
11
|
+
readonly URL: 4;
|
|
12
|
+
readonly REGEXP: 5;
|
|
13
|
+
readonly SET: 6;
|
|
14
|
+
readonly MAP: 7;
|
|
15
|
+
};
|
|
16
|
+
type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
|
|
17
|
+
type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
|
|
18
|
+
interface StandardRPCCustomJsonSerializer {
|
|
19
|
+
type: number;
|
|
20
|
+
condition(data: unknown): boolean;
|
|
21
|
+
serialize(data: any): unknown;
|
|
22
|
+
deserialize(serialized: any): unknown;
|
|
23
|
+
}
|
|
24
|
+
interface StandardRPCJsonSerializerOptions {
|
|
25
|
+
customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
|
|
26
|
+
}
|
|
27
|
+
declare class StandardRPCJsonSerializer {
|
|
28
|
+
private readonly customSerializers;
|
|
29
|
+
constructor(options?: StandardRPCJsonSerializerOptions);
|
|
30
|
+
serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
|
|
31
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
|
|
32
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class StandardRPCSerializer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly jsonSerializer;
|
|
38
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
|
39
|
+
serialize(data: unknown): object;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum length of the URL.
|
|
50
|
+
*
|
|
51
|
+
* @default 2083
|
|
52
|
+
*/
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
|
+
/**
|
|
55
|
+
* The method used to make the request.
|
|
56
|
+
*
|
|
57
|
+
* @default 'POST'
|
|
58
|
+
*/
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
|
+
/**
|
|
61
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
|
+
* GET is not allowed, it's very dangerous.
|
|
63
|
+
*
|
|
64
|
+
* @default 'POST'
|
|
65
|
+
*/
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
67
|
+
/**
|
|
68
|
+
* Inject headers to the request.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
|
+
}
|
|
72
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
|
+
private readonly serializer;
|
|
74
|
+
private readonly baseUrl;
|
|
75
|
+
private readonly maxUrlLength;
|
|
76
|
+
private readonly fallbackMethod;
|
|
77
|
+
private readonly expectedMethod;
|
|
78
|
+
private readonly headers;
|
|
79
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
|
80
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
81
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
85
|
+
}
|
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
+
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.3f73bd3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,37 +15,50 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./plugins": {
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./standard": {
|
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
21
31
|
},
|
|
22
32
|
"./fetch": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/fetch.
|
|
25
|
-
"default": "./dist/fetch.
|
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
26
41
|
},
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
29
46
|
}
|
|
30
47
|
},
|
|
31
48
|
"files": [
|
|
32
|
-
"!**/*.map",
|
|
33
|
-
"!**/*.tsbuildinfo",
|
|
34
49
|
"dist"
|
|
35
50
|
],
|
|
36
51
|
"dependencies": {
|
|
37
|
-
"@orpc/
|
|
38
|
-
"@orpc/server-
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
41
|
-
"@orpc/server": "0.0.0-next.3f40711"
|
|
52
|
+
"@orpc/shared": "0.0.0-next.3f73bd3",
|
|
53
|
+
"@orpc/standard-server-fetch": "0.0.0-next.3f73bd3",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.3f73bd3",
|
|
55
|
+
"@orpc/standard-server": "0.0.0-next.3f73bd3"
|
|
42
56
|
},
|
|
43
57
|
"devDependencies": {
|
|
44
|
-
"zod": "^
|
|
45
|
-
"@orpc/openapi": "0.0.0-next.3f40711"
|
|
58
|
+
"zod": "^4.0.5"
|
|
46
59
|
},
|
|
47
60
|
"scripts": {
|
|
48
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
49
62
|
"build:watch": "pnpm run build --watch",
|
|
50
63
|
"type:check": "tsc -b"
|
|
51
64
|
}
|
package/dist/chunk-HYT35LXG.js
DELETED
|
@@ -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
|
package/dist/fetch.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createAutoRetryEventIterator
|
|
3
|
-
} from "./chunk-HYT35LXG.js";
|
|
4
|
-
|
|
5
|
-
// src/adapters/fetch/orpc-link.ts
|
|
6
|
-
import { ORPCError } from "@orpc/contract";
|
|
7
|
-
import { isAsyncIteratorObject } from "@orpc/server-standard";
|
|
8
|
-
import { toFetchBody, toStandardBody } from "@orpc/server-standard-fetch";
|
|
9
|
-
import { RPCSerializer } from "@orpc/server/standard";
|
|
10
|
-
import { trim, value } from "@orpc/shared";
|
|
11
|
-
var InvalidEventSourceRetryResponse = class extends Error {
|
|
12
|
-
};
|
|
13
|
-
var RPCLink = class {
|
|
14
|
-
fetch;
|
|
15
|
-
rpcSerializer;
|
|
16
|
-
maxUrlLength;
|
|
17
|
-
fallbackMethod;
|
|
18
|
-
method;
|
|
19
|
-
headers;
|
|
20
|
-
url;
|
|
21
|
-
eventSourceMaxNumberOfRetries;
|
|
22
|
-
eventSourceRetryDelay;
|
|
23
|
-
eventSourceRetry;
|
|
24
|
-
constructor(options) {
|
|
25
|
-
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
26
|
-
this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
|
|
27
|
-
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
28
|
-
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
29
|
-
this.url = options.url;
|
|
30
|
-
this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
|
|
31
|
-
this.method = options.method ?? this.fallbackMethod;
|
|
32
|
-
this.headers = options.headers ?? {};
|
|
33
|
-
this.eventSourceRetry = options.eventSourceRetry ?? true;
|
|
34
|
-
this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
|
|
35
|
-
}
|
|
36
|
-
async call(path, input, options) {
|
|
37
|
-
const output = await this.performCall(path, input, options);
|
|
38
|
-
if (!isAsyncIteratorObject(output)) {
|
|
39
|
-
return output;
|
|
40
|
-
}
|
|
41
|
-
return createAutoRetryEventIterator(output, async (reconnectOptions) => {
|
|
42
|
-
if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
|
|
49
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
50
|
-
const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
|
|
51
|
-
const maybeIterator = await this.performCall(path, input, updatedOptions);
|
|
52
|
-
if (!isAsyncIteratorObject(maybeIterator)) {
|
|
53
|
-
throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
|
|
54
|
-
}
|
|
55
|
-
return maybeIterator;
|
|
56
|
-
}, void 0);
|
|
57
|
-
}
|
|
58
|
-
async performCall(path, input, options) {
|
|
59
|
-
const encoded = await this.encodeRequest(path, input, options);
|
|
60
|
-
const fetchBody = toFetchBody(encoded.body, encoded.headers);
|
|
61
|
-
if (options.lastEventId !== void 0) {
|
|
62
|
-
encoded.headers.set("last-event-id", options.lastEventId);
|
|
63
|
-
}
|
|
64
|
-
const response = await this.fetch(encoded.url, {
|
|
65
|
-
method: encoded.method,
|
|
66
|
-
headers: encoded.headers,
|
|
67
|
-
body: fetchBody,
|
|
68
|
-
signal: options.signal
|
|
69
|
-
}, options, path, input);
|
|
70
|
-
const body = await toStandardBody(response);
|
|
71
|
-
const deserialized = (() => {
|
|
72
|
-
try {
|
|
73
|
-
return this.rpcSerializer.deserialize(body);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (response.ok) {
|
|
76
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
77
|
-
message: "Invalid RPC response",
|
|
78
|
-
cause: error
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
throw new ORPCError(response.status.toString(), {
|
|
82
|
-
message: response.statusText
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
})();
|
|
86
|
-
if (!response.ok) {
|
|
87
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
|
88
|
-
throw ORPCError.fromJSON(deserialized);
|
|
89
|
-
}
|
|
90
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
91
|
-
message: "Invalid RPC error response",
|
|
92
|
-
cause: deserialized
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return deserialized;
|
|
96
|
-
}
|
|
97
|
-
async encodeRequest(path, input, options) {
|
|
98
|
-
const expectedMethod = await value(this.method, options, path, input);
|
|
99
|
-
const headers = new Headers(await value(this.headers, options, path, input));
|
|
100
|
-
const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
|
|
101
|
-
const serialized = this.rpcSerializer.serialize(input);
|
|
102
|
-
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
103
|
-
const getUrl = new URL(url);
|
|
104
|
-
getUrl.searchParams.append("data", JSON.stringify(serialized));
|
|
105
|
-
if (getUrl.toString().length <= this.maxUrlLength) {
|
|
106
|
-
return {
|
|
107
|
-
body: void 0,
|
|
108
|
-
method: expectedMethod,
|
|
109
|
-
headers,
|
|
110
|
-
url: getUrl
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
url,
|
|
116
|
-
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
|
117
|
-
headers,
|
|
118
|
-
body: serialized
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
export {
|
|
123
|
-
InvalidEventSourceRetryResponse,
|
|
124
|
-
RPCLink
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createAutoRetryEventIterator,
|
|
3
|
-
onEventIteratorStatusChange,
|
|
4
|
-
registerEventIteratorState,
|
|
5
|
-
updateEventIteratorStatus
|
|
6
|
-
} from "./chunk-HYT35LXG.js";
|
|
7
|
-
|
|
8
|
-
// src/client.ts
|
|
9
|
-
function createORPCClient(link, options) {
|
|
10
|
-
const path = options?.path ?? [];
|
|
11
|
-
const procedureClient = async (...[input, options2]) => {
|
|
12
|
-
const optionsOut = {
|
|
13
|
-
...options2,
|
|
14
|
-
context: options2?.context ?? {}
|
|
15
|
-
// options.context can be undefined when all field is optional
|
|
16
|
-
};
|
|
17
|
-
return await link.call(path, input, optionsOut);
|
|
18
|
-
};
|
|
19
|
-
const recursive = new Proxy(procedureClient, {
|
|
20
|
-
get(target, key) {
|
|
21
|
-
if (typeof key !== "string") {
|
|
22
|
-
return Reflect.get(target, key);
|
|
23
|
-
}
|
|
24
|
-
return createORPCClient(link, {
|
|
25
|
-
...options,
|
|
26
|
-
path: [...path, key]
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return recursive;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/dynamic-link.ts
|
|
34
|
-
var DynamicLink = class {
|
|
35
|
-
constructor(linkResolver) {
|
|
36
|
-
this.linkResolver = linkResolver;
|
|
37
|
-
}
|
|
38
|
-
async call(path, input, options) {
|
|
39
|
-
const resolvedLink = await this.linkResolver(options, path, input);
|
|
40
|
-
const output = await resolvedLink.call(path, input, options);
|
|
41
|
-
return output;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/index.ts
|
|
46
|
-
import { isDefinedError, ORPCError, safe } from "@orpc/contract";
|
|
47
|
-
export {
|
|
48
|
-
DynamicLink,
|
|
49
|
-
ORPCError,
|
|
50
|
-
createAutoRetryEventIterator,
|
|
51
|
-
createORPCClient,
|
|
52
|
-
isDefinedError,
|
|
53
|
-
onEventIteratorStatusChange,
|
|
54
|
-
registerEventIteratorState,
|
|
55
|
-
safe,
|
|
56
|
-
updateEventIteratorStatus
|
|
57
|
-
};
|
|
58
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { ClientContext, HTTPMethod } from '@orpc/contract';
|
|
2
|
-
import type { Value } from '@orpc/shared';
|
|
3
|
-
import type { ClientLink, ClientOptionsOut } from '../../types';
|
|
4
|
-
import type { FetchWithContext } from './types';
|
|
5
|
-
import { RPCSerializer } from '@orpc/server/standard';
|
|
6
|
-
import { type EventIteratorReconnectOptions } from '../../event-iterator';
|
|
7
|
-
export declare class InvalidEventSourceRetryResponse extends Error {
|
|
8
|
-
}
|
|
9
|
-
export interface RPCLinkOptions<TClientContext extends ClientContext> {
|
|
10
|
-
/**
|
|
11
|
-
* Base url for all requests.
|
|
12
|
-
*/
|
|
13
|
-
url: string;
|
|
14
|
-
/**
|
|
15
|
-
* The maximum length of the URL.
|
|
16
|
-
*
|
|
17
|
-
* @default 2083
|
|
18
|
-
*/
|
|
19
|
-
maxUrlLength?: number;
|
|
20
|
-
/**
|
|
21
|
-
* The method used to make the request.
|
|
22
|
-
*
|
|
23
|
-
* @default 'POST'
|
|
24
|
-
*/
|
|
25
|
-
method?: Value<HTTPMethod, [
|
|
26
|
-
options: ClientOptionsOut<TClientContext>,
|
|
27
|
-
path: readonly string[],
|
|
28
|
-
input: unknown
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
32
|
-
* GET is not allowed, it's very dangerous.
|
|
33
|
-
*
|
|
34
|
-
* @default 'POST'
|
|
35
|
-
*/
|
|
36
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
37
|
-
/**
|
|
38
|
-
* Inject headers to the request.
|
|
39
|
-
*/
|
|
40
|
-
headers?: Value<[string, string][] | Record<string, string> | Headers, [
|
|
41
|
-
options: ClientOptionsOut<TClientContext>,
|
|
42
|
-
path: readonly string[],
|
|
43
|
-
input: unknown
|
|
44
|
-
]>;
|
|
45
|
-
/**
|
|
46
|
-
* Custom fetch implementation.
|
|
47
|
-
*
|
|
48
|
-
* @default globalThis.fetch.bind(globalThis)
|
|
49
|
-
*/
|
|
50
|
-
fetch?: FetchWithContext<TClientContext>;
|
|
51
|
-
rpcSerializer?: RPCSerializer;
|
|
52
|
-
/**
|
|
53
|
-
* Maximum number of retry attempts for EventSource errors before throwing.
|
|
54
|
-
*
|
|
55
|
-
* @default 5
|
|
56
|
-
*/
|
|
57
|
-
eventSourceMaxNumberOfRetries?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Delay (in ms) before retrying an EventSource call.
|
|
60
|
-
*
|
|
61
|
-
* @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
|
|
62
|
-
*/
|
|
63
|
-
eventSourceRetryDelay?: Value<number, [
|
|
64
|
-
reconnectOptions: EventIteratorReconnectOptions,
|
|
65
|
-
options: ClientOptionsOut<TClientContext>,
|
|
66
|
-
path: readonly string[],
|
|
67
|
-
input: unknown
|
|
68
|
-
]>;
|
|
69
|
-
/**
|
|
70
|
-
* Function to determine if an error is retryable.
|
|
71
|
-
*
|
|
72
|
-
* @default true
|
|
73
|
-
*/
|
|
74
|
-
eventSourceRetry?: Value<boolean, [
|
|
75
|
-
reconnectOptions: EventIteratorReconnectOptions,
|
|
76
|
-
options: ClientOptionsOut<TClientContext>,
|
|
77
|
-
path: readonly string[],
|
|
78
|
-
input: unknown
|
|
79
|
-
]>;
|
|
80
|
-
}
|
|
81
|
-
export declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
|
82
|
-
private readonly fetch;
|
|
83
|
-
private readonly rpcSerializer;
|
|
84
|
-
private readonly maxUrlLength;
|
|
85
|
-
private readonly fallbackMethod;
|
|
86
|
-
private readonly method;
|
|
87
|
-
private readonly headers;
|
|
88
|
-
private readonly url;
|
|
89
|
-
private readonly eventSourceMaxNumberOfRetries;
|
|
90
|
-
private readonly eventSourceRetryDelay;
|
|
91
|
-
private readonly eventSourceRetry;
|
|
92
|
-
constructor(options: RPCLinkOptions<TClientContext>);
|
|
93
|
-
call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
|
|
94
|
-
private performCall;
|
|
95
|
-
private encodeRequest;
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=orpc-link.d.ts.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ClientContext } from '@orpc/contract';
|
|
2
|
-
import type { ClientOptionsOut } from '../../types';
|
|
3
|
-
export interface FetchWithContext<TClientContext extends ClientContext> {
|
|
4
|
-
(url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AnyContractRouter, ClientContext, ContractRouterClient } from '@orpc/contract';
|
|
2
|
-
import type { AnyRouter, RouterClient } from '@orpc/server';
|
|
3
|
-
import type { ClientLink } from './types';
|
|
4
|
-
export interface createORPCClientOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
|
7
|
-
*/
|
|
8
|
-
path?: string[];
|
|
9
|
-
}
|
|
10
|
-
export declare function createORPCClient<TRouter extends AnyRouter | AnyContractRouter, TClientContext extends ClientContext = Record<never, never>>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): TRouter extends AnyRouter ? RouterClient<TRouter, TClientContext> : TRouter extends AnyContractRouter ? ContractRouterClient<TRouter, TClientContext> : never;
|
|
11
|
-
//# sourceMappingURL=client.d.ts.map
|