@orpc/client 1.14.6 → 2.0.0-beta.2

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 (38) hide show
  1. package/README.md +74 -106
  2. package/dist/adapters/fetch/index.d.mts +55 -36
  3. package/dist/adapters/fetch/index.d.ts +55 -36
  4. package/dist/adapters/fetch/index.mjs +50 -28
  5. package/dist/adapters/message-port/index.d.mts +25 -30
  6. package/dist/adapters/message-port/index.d.ts +25 -30
  7. package/dist/adapters/message-port/index.mjs +33 -29
  8. package/dist/adapters/standard/index.d.mts +58 -9
  9. package/dist/adapters/standard/index.d.ts +58 -9
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +113 -21
  12. package/dist/adapters/websocket/index.d.ts +113 -21
  13. package/dist/adapters/websocket/index.mjs +95 -37
  14. package/dist/index.d.mts +84 -159
  15. package/dist/index.d.ts +84 -159
  16. package/dist/index.mjs +76 -34
  17. package/dist/plugins/index.d.mts +125 -132
  18. package/dist/plugins/index.d.ts +125 -132
  19. package/dist/plugins/index.mjs +373 -284
  20. package/dist/shared/client.8ug8I-zu.d.mts +167 -0
  21. package/dist/shared/client.8ug8I-zu.d.ts +167 -0
  22. package/dist/shared/client.BdItY5DT.d.mts +111 -0
  23. package/dist/shared/client.BdItY5DT.d.ts +111 -0
  24. package/dist/shared/client.CPF3hX6O.d.ts +96 -0
  25. package/dist/shared/client.Cby_-GGh.d.mts +96 -0
  26. package/dist/shared/client.DMXKFDyV.mjs +343 -0
  27. package/dist/shared/client.DXhchJ84.mjs +174 -0
  28. package/dist/shared/client.Dnfj8jnT.mjs +92 -0
  29. package/package.json +7 -7
  30. package/dist/shared/client.2jUAqzYU.d.ts +0 -45
  31. package/dist/shared/client.B3pNRBih.d.ts +0 -91
  32. package/dist/shared/client.BFAVy68H.d.mts +0 -91
  33. package/dist/shared/client.BLtwTQUg.mjs +0 -40
  34. package/dist/shared/client.CpCa3si8.d.mts +0 -45
  35. package/dist/shared/client.D9eWXdBV.mjs +0 -174
  36. package/dist/shared/client.DLhbktiD.mjs +0 -404
  37. package/dist/shared/client.i2uoJbEp.d.mts +0 -83
  38. package/dist/shared/client.i2uoJbEp.d.ts +0 -83
@@ -0,0 +1,167 @@
1
+ import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
2
+
3
+ interface ClientContext {
4
+ [key: PropertyKey]: any;
5
+ }
6
+ interface ClientOptions<T extends ClientContext> {
7
+ signal?: AbortSignal | undefined;
8
+ lastEventId?: string | undefined;
9
+ context: T;
10
+ }
11
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
12
+ context?: T;
13
+ } : {
14
+ context: T;
15
+ });
16
+ type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
17
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
18
+ (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
19
+ }
20
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
21
+ [k: string]: NestedClient<TClientContext>;
22
+ };
23
+ type AnyNestedClient = NestedClient<any>;
24
+ type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
25
+ interface ClientLink<TClientContext extends ClientContext> {
26
+ call: (path: 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 AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
34
+ [K in keyof T]: T[K] extends AnyNestedClient ? 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 AnyNestedClient> = 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 AnyNestedClient ? 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 AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
53
+ [K in keyof T]: T[K] extends AnyNestedClient ? 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 AnyNestedClient> = 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 AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
65
+ };
66
+ /**
67
+ * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/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 AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
72
+ [K in keyof T]: T[K] extends AnyNestedClient ? 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.dev/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 InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
80
+ [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
81
+ }[keyof T];
82
+
83
+ declare const COMMON_ERROR_STATUS_MAP: {
84
+ BAD_REQUEST: number;
85
+ UNAUTHORIZED: number;
86
+ PAYMENT_REQUIRED: number;
87
+ FORBIDDEN: number;
88
+ NOT_FOUND: number;
89
+ METHOD_NOT_SUPPORTED: number;
90
+ NOT_ACCEPTABLE: number;
91
+ TIMEOUT: number;
92
+ CONFLICT: number;
93
+ GONE: number;
94
+ PRECONDITION_FAILED: number;
95
+ PAYLOAD_TOO_LARGE: number;
96
+ UNSUPPORTED_MEDIA_TYPE: number;
97
+ UNPROCESSABLE_CONTENT: number;
98
+ PRECONDITION_REQUIRED: number;
99
+ TOO_MANY_REQUESTS: number;
100
+ CLIENT_CLOSED_REQUEST: number;
101
+ INTERNAL_SERVER_ERROR: number;
102
+ NOT_IMPLEMENTED: number;
103
+ BAD_GATEWAY: number;
104
+ SERVICE_UNAVAILABLE: number;
105
+ GATEWAY_TIMEOUT: number;
106
+ };
107
+ type ORPCErrorCode = Registry extends {
108
+ ORPCErrorCode: infer T extends string;
109
+ } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
110
+ type ORPCErrorOptions<TData> = ErrorOptions & {
111
+ message?: string;
112
+ } & (undefined extends TData ? {
113
+ data?: TData;
114
+ } : {
115
+ data: TData;
116
+ });
117
+ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
118
+ /**
119
+ * @info
120
+ * The `__branch` property is used for type branding, helping TypeScript distinguish
121
+ * an `ORPCError` instance from plain objects with a similar structure.
122
+ */
123
+ readonly name: "ORPCError" & {
124
+ __branch: "ORPCError";
125
+ };
126
+ /**
127
+ * Indicates whether the error matches a definition in the procedure's `.errors` map.
128
+ */
129
+ readonly defined: boolean;
130
+ /**
131
+ * Indicates whether the error's type is inferable at the TypeScript level.
132
+ * This is typically true when the error is explicitly defined or returned within a handler.
133
+ */
134
+ readonly inferable: boolean;
135
+ code: TCode;
136
+ data: TData;
137
+ constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
138
+ toJSON(): ORPCErrorJSON<TCode, TData>;
139
+ /**
140
+ * Workaround for Next.js where different contexts use separate
141
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
142
+ * `instanceof` checks across contexts.
143
+ *
144
+ * This is particularly problematic with "Optimized SSR", where orpc-client
145
+ * executes in one context but is invoked from another. When an error is thrown
146
+ * in the execution context, `instanceof ORPCError` checks fail in the
147
+ * invocation context due to separate class constructors.
148
+ *
149
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
150
+ */
151
+ static [Symbol.hasInstance](instance: unknown): boolean;
152
+ }
153
+ interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
154
+ /**
155
+ * remove readonly
156
+ */
157
+ defined: boolean;
158
+ /**
159
+ * remove readonly
160
+ */
161
+ inferable: boolean;
162
+ }
163
+ type AnyORPCError = ORPCError<any, any>;
164
+ type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
165
+
166
+ export { ORPCError as c, COMMON_ERROR_STATUS_MAP as j };
167
+ export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, ORPCErrorJSON as d, AnyNestedClient as e, InferClientError as f, Client as g, ClientRest as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p };
@@ -0,0 +1,167 @@
1
+ import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
2
+
3
+ interface ClientContext {
4
+ [key: PropertyKey]: any;
5
+ }
6
+ interface ClientOptions<T extends ClientContext> {
7
+ signal?: AbortSignal | undefined;
8
+ lastEventId?: string | undefined;
9
+ context: T;
10
+ }
11
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
12
+ context?: T;
13
+ } : {
14
+ context: T;
15
+ });
16
+ type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
17
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
18
+ (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
19
+ }
20
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
21
+ [k: string]: NestedClient<TClientContext>;
22
+ };
23
+ type AnyNestedClient = NestedClient<any>;
24
+ type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
25
+ interface ClientLink<TClientContext extends ClientContext> {
26
+ call: (path: 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 AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
34
+ [K in keyof T]: T[K] extends AnyNestedClient ? 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 AnyNestedClient> = 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 AnyNestedClient ? 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 AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
53
+ [K in keyof T]: T[K] extends AnyNestedClient ? 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 AnyNestedClient> = 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 AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
65
+ };
66
+ /**
67
+ * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/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 AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
72
+ [K in keyof T]: T[K] extends AnyNestedClient ? 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.dev/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 InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
80
+ [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
81
+ }[keyof T];
82
+
83
+ declare const COMMON_ERROR_STATUS_MAP: {
84
+ BAD_REQUEST: number;
85
+ UNAUTHORIZED: number;
86
+ PAYMENT_REQUIRED: number;
87
+ FORBIDDEN: number;
88
+ NOT_FOUND: number;
89
+ METHOD_NOT_SUPPORTED: number;
90
+ NOT_ACCEPTABLE: number;
91
+ TIMEOUT: number;
92
+ CONFLICT: number;
93
+ GONE: number;
94
+ PRECONDITION_FAILED: number;
95
+ PAYLOAD_TOO_LARGE: number;
96
+ UNSUPPORTED_MEDIA_TYPE: number;
97
+ UNPROCESSABLE_CONTENT: number;
98
+ PRECONDITION_REQUIRED: number;
99
+ TOO_MANY_REQUESTS: number;
100
+ CLIENT_CLOSED_REQUEST: number;
101
+ INTERNAL_SERVER_ERROR: number;
102
+ NOT_IMPLEMENTED: number;
103
+ BAD_GATEWAY: number;
104
+ SERVICE_UNAVAILABLE: number;
105
+ GATEWAY_TIMEOUT: number;
106
+ };
107
+ type ORPCErrorCode = Registry extends {
108
+ ORPCErrorCode: infer T extends string;
109
+ } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
110
+ type ORPCErrorOptions<TData> = ErrorOptions & {
111
+ message?: string;
112
+ } & (undefined extends TData ? {
113
+ data?: TData;
114
+ } : {
115
+ data: TData;
116
+ });
117
+ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
118
+ /**
119
+ * @info
120
+ * The `__branch` property is used for type branding, helping TypeScript distinguish
121
+ * an `ORPCError` instance from plain objects with a similar structure.
122
+ */
123
+ readonly name: "ORPCError" & {
124
+ __branch: "ORPCError";
125
+ };
126
+ /**
127
+ * Indicates whether the error matches a definition in the procedure's `.errors` map.
128
+ */
129
+ readonly defined: boolean;
130
+ /**
131
+ * Indicates whether the error's type is inferable at the TypeScript level.
132
+ * This is typically true when the error is explicitly defined or returned within a handler.
133
+ */
134
+ readonly inferable: boolean;
135
+ code: TCode;
136
+ data: TData;
137
+ constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
138
+ toJSON(): ORPCErrorJSON<TCode, TData>;
139
+ /**
140
+ * Workaround for Next.js where different contexts use separate
141
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
142
+ * `instanceof` checks across contexts.
143
+ *
144
+ * This is particularly problematic with "Optimized SSR", where orpc-client
145
+ * executes in one context but is invoked from another. When an error is thrown
146
+ * in the execution context, `instanceof ORPCError` checks fail in the
147
+ * invocation context due to separate class constructors.
148
+ *
149
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
150
+ */
151
+ static [Symbol.hasInstance](instance: unknown): boolean;
152
+ }
153
+ interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
154
+ /**
155
+ * remove readonly
156
+ */
157
+ defined: boolean;
158
+ /**
159
+ * remove readonly
160
+ */
161
+ inferable: boolean;
162
+ }
163
+ type AnyORPCError = ORPCError<any, any>;
164
+ type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
165
+
166
+ export { ORPCError as c, COMMON_ERROR_STATUS_MAP as j };
167
+ export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, ORPCErrorJSON as d, AnyNestedClient as e, InferClientError as f, Client as g, ClientRest as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p };
@@ -0,0 +1,111 @@
1
+ import { StandardBody } from '@standardserver/core';
2
+ import { Segment } from '@orpc/shared';
3
+
4
+ type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
5
+ type RPCJsonSerialization = {
6
+ json: unknown;
7
+ meta?: RPCJsonSerializationMeta[] | undefined;
8
+ maps?: undefined;
9
+ blobs?: undefined;
10
+ } | {
11
+ json: unknown;
12
+ meta?: RPCJsonSerializationMeta[] | undefined;
13
+ maps: Segment[][];
14
+ blobs: Blob[];
15
+ };
16
+ interface RPCJsonSerializerHandler {
17
+ condition(value: unknown): boolean;
18
+ serialize(value: any): unknown;
19
+ deserialize(serialized: any): unknown;
20
+ /**
21
+ * If false, the result of this serializer will not be further processed by other serializers,
22
+ * even if it matches their conditions and treat it as final serialized value.
23
+ * This can be useful for serializers that return primitive values, which should not be further processed.
24
+ * to improve performance and avoid potential issues with other serializers.
25
+ *
26
+ * @default false
27
+ */
28
+ isTerminal?: boolean;
29
+ }
30
+ interface RPCJsonSerializerOptions {
31
+ /**
32
+ * Extend or override the built-in type handlers used during serialization and deserialization.
33
+ *
34
+ * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
35
+ * that defines how to detect, serialize, and deserialize values of that type.
36
+ *
37
+ * **Extending:** Add new keys to support custom types:
38
+ * ```ts
39
+ * handlers: {
40
+ * buffer: {
41
+ * condition: (v) => v instanceof Buffer,
42
+ * serialize: (v: Buffer) => v.toString('base64'),
43
+ * deserialize: (s: string) => Buffer.from(s, 'base64'),
44
+ * isTerminal: true,
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * **Overriding:** Use an existing key to replace a built-in handler:
50
+ * ```ts
51
+ * handlers: {
52
+ * date: {
53
+ * condition: (v) => v instanceof Date,
54
+ * serialize: (v: Date) => v.getTime(),
55
+ * deserialize: (n: number) => new Date(n),
56
+ * isTerminal: true,
57
+ * }
58
+ * }
59
+ * ```
60
+ *
61
+ * **Disabling:** Set a key to `undefined` to remove a built-in handler:
62
+ * ```ts
63
+ * handlers: { regexp: undefined }
64
+ * ```
65
+ *
66
+ * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`.
67
+ */
68
+ handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
69
+ /**
70
+ * If true, properties with undefined values will be omitted during serialization.
71
+ *
72
+ * @default true
73
+ */
74
+ omitUndefinedProperties?: boolean | undefined;
75
+ }
76
+ declare class RPCJsonSerializer {
77
+ private readonly handlers;
78
+ private readonly omitUndefinedProperties;
79
+ constructor(options?: RPCJsonSerializerOptions);
80
+ serialize(data: unknown): RPCJsonSerialization;
81
+ private serializeValue;
82
+ deserialize(serialized: RPCJsonSerialization): unknown;
83
+ }
84
+
85
+ interface RPCSerializerSerializeOptions {
86
+ /**
87
+ * Use FormData for serialization when nested blobs are present.
88
+ * Does not apply to root-level Blob values.
89
+ *
90
+ * @default true
91
+ */
92
+ useFormDataForBlobFields?: boolean;
93
+ }
94
+ interface RPCSerializerOptions extends RPCJsonSerializerOptions {
95
+ /**
96
+ * Default options for serialize method
97
+ */
98
+ serialize?: RPCSerializerSerializeOptions | undefined;
99
+ }
100
+ declare class RPCSerializer {
101
+ private readonly jsonSerializer;
102
+ private readonly defaultSerializeOptions;
103
+ constructor(options?: RPCSerializerOptions);
104
+ serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody;
105
+ private serializeValue;
106
+ deserialize(data: StandardBody): unknown;
107
+ private deserializeValue;
108
+ }
109
+
110
+ export { RPCJsonSerializer as b, RPCSerializer as e };
111
+ export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g };
@@ -0,0 +1,111 @@
1
+ import { StandardBody } from '@standardserver/core';
2
+ import { Segment } from '@orpc/shared';
3
+
4
+ type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
5
+ type RPCJsonSerialization = {
6
+ json: unknown;
7
+ meta?: RPCJsonSerializationMeta[] | undefined;
8
+ maps?: undefined;
9
+ blobs?: undefined;
10
+ } | {
11
+ json: unknown;
12
+ meta?: RPCJsonSerializationMeta[] | undefined;
13
+ maps: Segment[][];
14
+ blobs: Blob[];
15
+ };
16
+ interface RPCJsonSerializerHandler {
17
+ condition(value: unknown): boolean;
18
+ serialize(value: any): unknown;
19
+ deserialize(serialized: any): unknown;
20
+ /**
21
+ * If false, the result of this serializer will not be further processed by other serializers,
22
+ * even if it matches their conditions and treat it as final serialized value.
23
+ * This can be useful for serializers that return primitive values, which should not be further processed.
24
+ * to improve performance and avoid potential issues with other serializers.
25
+ *
26
+ * @default false
27
+ */
28
+ isTerminal?: boolean;
29
+ }
30
+ interface RPCJsonSerializerOptions {
31
+ /**
32
+ * Extend or override the built-in type handlers used during serialization and deserialization.
33
+ *
34
+ * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
35
+ * that defines how to detect, serialize, and deserialize values of that type.
36
+ *
37
+ * **Extending:** Add new keys to support custom types:
38
+ * ```ts
39
+ * handlers: {
40
+ * buffer: {
41
+ * condition: (v) => v instanceof Buffer,
42
+ * serialize: (v: Buffer) => v.toString('base64'),
43
+ * deserialize: (s: string) => Buffer.from(s, 'base64'),
44
+ * isTerminal: true,
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * **Overriding:** Use an existing key to replace a built-in handler:
50
+ * ```ts
51
+ * handlers: {
52
+ * date: {
53
+ * condition: (v) => v instanceof Date,
54
+ * serialize: (v: Date) => v.getTime(),
55
+ * deserialize: (n: number) => new Date(n),
56
+ * isTerminal: true,
57
+ * }
58
+ * }
59
+ * ```
60
+ *
61
+ * **Disabling:** Set a key to `undefined` to remove a built-in handler:
62
+ * ```ts
63
+ * handlers: { regexp: undefined }
64
+ * ```
65
+ *
66
+ * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`.
67
+ */
68
+ handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
69
+ /**
70
+ * If true, properties with undefined values will be omitted during serialization.
71
+ *
72
+ * @default true
73
+ */
74
+ omitUndefinedProperties?: boolean | undefined;
75
+ }
76
+ declare class RPCJsonSerializer {
77
+ private readonly handlers;
78
+ private readonly omitUndefinedProperties;
79
+ constructor(options?: RPCJsonSerializerOptions);
80
+ serialize(data: unknown): RPCJsonSerialization;
81
+ private serializeValue;
82
+ deserialize(serialized: RPCJsonSerialization): unknown;
83
+ }
84
+
85
+ interface RPCSerializerSerializeOptions {
86
+ /**
87
+ * Use FormData for serialization when nested blobs are present.
88
+ * Does not apply to root-level Blob values.
89
+ *
90
+ * @default true
91
+ */
92
+ useFormDataForBlobFields?: boolean;
93
+ }
94
+ interface RPCSerializerOptions extends RPCJsonSerializerOptions {
95
+ /**
96
+ * Default options for serialize method
97
+ */
98
+ serialize?: RPCSerializerSerializeOptions | undefined;
99
+ }
100
+ declare class RPCSerializer {
101
+ private readonly jsonSerializer;
102
+ private readonly defaultSerializeOptions;
103
+ constructor(options?: RPCSerializerOptions);
104
+ serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody;
105
+ private serializeValue;
106
+ deserialize(data: StandardBody): unknown;
107
+ private deserializeValue;
108
+ }
109
+
110
+ export { RPCJsonSerializer as b, RPCSerializer as e };
111
+ export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g };
@@ -0,0 +1,96 @@
1
+ import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
3
+ import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.8ug8I-zu.js';
4
+
5
+ type StandardLinkCodecDecodedResponse = {
6
+ kind: 'output';
7
+ output: unknown;
8
+ } | {
9
+ kind: 'error';
10
+ error: AnyORPCError;
11
+ };
12
+ interface StandardLinkCodec<T extends ClientContext> {
13
+ encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>;
14
+ decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>;
15
+ }
16
+
17
+ interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
18
+ /**
19
+ * Initializes the plugin and returns new link options.
20
+ * Called once per plugin instance during composition.
21
+ *
22
+ * This method allows plugins to wrap, extend, or transform link options
23
+ * such as interceptors, or configuration.
24
+ *
25
+ * @param options - The current link options from previous plugins or base configuration
26
+ * @returns Transformed link options with plugin's modifications applied
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * init(options) {
31
+ * return {
32
+ * ...options,
33
+ * interceptors: [...(options.interceptors || []), myInterceptor]
34
+ * }
35
+ * }
36
+ * ```
37
+ */
38
+ init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
39
+ }
40
+ declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
41
+ name: string;
42
+ protected readonly plugins: StandardLinkPlugin<T>[];
43
+ constructor(plugins?: StandardLinkPlugin<T>[]);
44
+ init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
45
+ }
46
+
47
+ /**
48
+ * Handles the transport layer for sending requests and receiving responses.
49
+ *
50
+ * Implementations are responsible for the actual network communication,
51
+ * such as HTTP fetch, WebSocket, or other transport mechanisms.
52
+ */
53
+ interface StandardLinkTransport<T extends ClientContext> {
54
+ /**
55
+ * @throws Transport-level errors (network failures, timeouts, etc.)
56
+ */
57
+ send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
58
+ }
59
+
60
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
61
+ path: string[];
62
+ input: unknown;
63
+ }
64
+ type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>;
65
+ interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
66
+ path: string[];
67
+ request: StandardRequest;
68
+ }
69
+ type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>;
70
+ interface StandardLinkOptions<T extends ClientContext> {
71
+ /**
72
+ * Interceptors that execute around the entire call, including transport and codec.
73
+ * Useful for error handling, logging, metrics, ...
74
+ */
75
+ interceptors?: StandardLinkInterceptor<T>[];
76
+ /**
77
+ * Interceptors that execute around the transport layer, after encoding and before decoding.
78
+ * Useful for modifying the request or response, adding transport-level logging, ...
79
+ */
80
+ transportInterceptors?: StandardLinkTransportInterceptor<T>[];
81
+ plugins?: StandardLinkPlugin<T>[];
82
+ }
83
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
84
+ private readonly codec;
85
+ private readonly transport;
86
+ private readonly interceptors;
87
+ private readonly transportInterceptors;
88
+ constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>);
89
+ /**
90
+ * @throws ORPCError, transport-level errors (network failures, timeouts, etc.)
91
+ */
92
+ call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
93
+ }
94
+
95
+ export { CompositeStandardLinkPlugin as C, StandardLink as a };
96
+ export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i };