@orpc/client 0.0.0-next.e9dc36e → 0.0.0-next.ea1d4fd
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 +101 -0
- package/dist/adapters/fetch/index.d.mts +46 -0
- package/dist/adapters/fetch/index.d.ts +46 -0
- package/dist/adapters/fetch/index.mjs +46 -0
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +87 -0
- package/dist/adapters/standard/index.d.mts +11 -0
- package/dist/adapters/standard/index.d.ts +11 -0
- package/dist/adapters/standard/index.mjs +6 -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 +47 -0
- package/dist/index.d.mts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.mjs +112 -0
- package/dist/plugins/index.d.mts +249 -0
- package/dist/plugins/index.d.ts +249 -0
- package/dist/plugins/index.mjs +485 -0
- package/dist/shared/client.BDbd8GMX.mjs +171 -0
- package/dist/shared/client.BH1AYT_p.d.mts +83 -0
- package/dist/shared/client.BH1AYT_p.d.ts +83 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/client.BxV-mzeR.d.ts +91 -0
- package/dist/shared/client.CPgZaUox.d.mts +45 -0
- package/dist/shared/client.D8lMmWVC.d.mts +91 -0
- package/dist/shared/client.De8SW4Kw.d.ts +45 -0
- package/dist/shared/client._xOn23bS.mjs +398 -0
- package/package.json +39 -24
- package/dist/index.js +0 -83
- package/dist/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/procedure.d.ts +0 -27
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router.d.ts +0 -34
- package/dist/src/router.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/index.ts +0 -9
- package/src/procedure.test.ts +0 -245
- package/src/procedure.ts +0 -108
- package/src/router.test.ts +0 -148
- package/src/router.ts +0 -96
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Recursively infers the **input types** from a client.
|
|
30
|
+
*
|
|
31
|
+
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
+
*/
|
|
33
|
+
type InferClientInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientInputs<T[K]> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recursively infers the **body input types** from a client.
|
|
38
|
+
*
|
|
39
|
+
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
+
* Produces a nested map of body input types.
|
|
41
|
+
*/
|
|
42
|
+
type InferClientBodyInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
+
body: infer UBody;
|
|
44
|
+
} ? UBody : U : {
|
|
45
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Recursively infers the **output types** from a client.
|
|
49
|
+
*
|
|
50
|
+
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
+
*/
|
|
52
|
+
type InferClientOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientOutputs<T[K]> : never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Recursively infers the **body output types** from a client.
|
|
57
|
+
*
|
|
58
|
+
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
+
* Produces a nested map of body output types.
|
|
60
|
+
*/
|
|
61
|
+
type InferClientBodyOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
+
body: infer UBody;
|
|
63
|
+
} ? UBody : U : {
|
|
64
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling).
|
|
68
|
+
*
|
|
69
|
+
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
+
*/
|
|
71
|
+
type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling).
|
|
76
|
+
*
|
|
77
|
+
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
+
*/
|
|
79
|
+
type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never;
|
|
81
|
+
}[keyof T];
|
|
82
|
+
|
|
83
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Recursively infers the **input types** from a client.
|
|
30
|
+
*
|
|
31
|
+
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
+
*/
|
|
33
|
+
type InferClientInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientInputs<T[K]> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recursively infers the **body input types** from a client.
|
|
38
|
+
*
|
|
39
|
+
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
+
* Produces a nested map of body input types.
|
|
41
|
+
*/
|
|
42
|
+
type InferClientBodyInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
+
body: infer UBody;
|
|
44
|
+
} ? UBody : U : {
|
|
45
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Recursively infers the **output types** from a client.
|
|
49
|
+
*
|
|
50
|
+
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
+
*/
|
|
52
|
+
type InferClientOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientOutputs<T[K]> : never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Recursively infers the **body output types** from a client.
|
|
57
|
+
*
|
|
58
|
+
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
+
* Produces a nested map of body output types.
|
|
60
|
+
*/
|
|
61
|
+
type InferClientBodyOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
+
body: infer UBody;
|
|
63
|
+
} ? UBody : U : {
|
|
64
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling).
|
|
68
|
+
*
|
|
69
|
+
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
+
*/
|
|
71
|
+
type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling).
|
|
76
|
+
*
|
|
77
|
+
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
+
*/
|
|
79
|
+
type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never;
|
|
81
|
+
}[keyof T];
|
|
82
|
+
|
|
83
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
|
+
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
|
+
|
|
4
|
+
function mapEventIterator(iterator, maps) {
|
|
5
|
+
const mapError = async (error) => {
|
|
6
|
+
let mappedError = await maps.error(error);
|
|
7
|
+
if (mappedError !== error) {
|
|
8
|
+
const meta = getEventMeta(error);
|
|
9
|
+
if (meta && isTypescriptObject(mappedError)) {
|
|
10
|
+
mappedError = withEventMeta(mappedError, meta);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return mappedError;
|
|
14
|
+
};
|
|
15
|
+
return new AsyncIteratorClass(async () => {
|
|
16
|
+
const { done, value } = await (async () => {
|
|
17
|
+
try {
|
|
18
|
+
return await iterator.next();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw await mapError(error);
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
23
|
+
let mappedValue = await maps.value(value, done);
|
|
24
|
+
if (mappedValue !== value) {
|
|
25
|
+
const meta = getEventMeta(value);
|
|
26
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
|
27
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { done, value: mappedValue };
|
|
31
|
+
}, async () => {
|
|
32
|
+
try {
|
|
33
|
+
await iterator.return?.();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw await mapError(error);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { mapEventIterator as m };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.De8SW4Kw.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 | Headers>, [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,45 @@
|
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.mjs';
|
|
4
|
+
|
|
5
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
6
|
+
order?: number;
|
|
7
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
8
|
+
}
|
|
9
|
+
declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
|
|
10
|
+
protected readonly plugins: TPlugin[];
|
|
11
|
+
constructor(plugins?: readonly TPlugin[]);
|
|
12
|
+
init(options: StandardLinkOptions<T>): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface StandardLinkCodec<T extends ClientContext> {
|
|
16
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
17
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
interface StandardLinkClient<T extends ClientContext> {
|
|
20
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
24
|
+
path: readonly string[];
|
|
25
|
+
input: unknown;
|
|
26
|
+
}
|
|
27
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
28
|
+
request: StandardRequest;
|
|
29
|
+
}
|
|
30
|
+
interface StandardLinkOptions<T extends ClientContext> {
|
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
|
33
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
34
|
+
}
|
|
35
|
+
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
|
+
readonly codec: StandardLinkCodec<T>;
|
|
37
|
+
readonly sender: StandardLinkClient<T>;
|
|
38
|
+
private readonly interceptors;
|
|
39
|
+
private readonly clientInterceptors;
|
|
40
|
+
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
41
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { CompositeStandardLinkPlugin as C, StandardLink as d };
|
|
45
|
+
export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CPgZaUox.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 | Headers>, [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,45 @@
|
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.js';
|
|
4
|
+
|
|
5
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
6
|
+
order?: number;
|
|
7
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
8
|
+
}
|
|
9
|
+
declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
|
|
10
|
+
protected readonly plugins: TPlugin[];
|
|
11
|
+
constructor(plugins?: readonly TPlugin[]);
|
|
12
|
+
init(options: StandardLinkOptions<T>): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface StandardLinkCodec<T extends ClientContext> {
|
|
16
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
17
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
interface StandardLinkClient<T extends ClientContext> {
|
|
20
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
24
|
+
path: readonly string[];
|
|
25
|
+
input: unknown;
|
|
26
|
+
}
|
|
27
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
28
|
+
request: StandardRequest;
|
|
29
|
+
}
|
|
30
|
+
interface StandardLinkOptions<T extends ClientContext> {
|
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
|
33
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
34
|
+
}
|
|
35
|
+
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
|
+
readonly codec: StandardLinkCodec<T>;
|
|
37
|
+
readonly sender: StandardLinkClient<T>;
|
|
38
|
+
private readonly interceptors;
|
|
39
|
+
private readonly clientInterceptors;
|
|
40
|
+
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
41
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { CompositeStandardLinkPlugin as C, StandardLink as d };
|
|
45
|
+
export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
|