@temporary-name/server 1.9.3-alpha.03f5d40e5b399f85012c2fb4e98167e26d551d36 → 1.9.3-alpha.0489b23089852dc674460c2b1311b592746e58e1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -6
  3. package/dist/adapters/aws-lambda/index.mjs +4 -4
  4. package/dist/adapters/fetch/index.d.mts +8 -86
  5. package/dist/adapters/fetch/index.d.ts +8 -86
  6. package/dist/adapters/fetch/index.mjs +16 -155
  7. package/dist/adapters/node/index.d.mts +8 -63
  8. package/dist/adapters/node/index.d.ts +8 -63
  9. package/dist/adapters/node/index.mjs +14 -120
  10. package/dist/adapters/standard/index.d.mts +10 -7
  11. package/dist/adapters/standard/index.d.ts +10 -7
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +121 -258
  15. package/dist/index.d.ts +121 -258
  16. package/dist/index.mjs +168 -359
  17. package/dist/openapi/index.d.mts +12 -28
  18. package/dist/openapi/index.d.ts +12 -28
  19. package/dist/openapi/index.mjs +134 -152
  20. package/dist/shared/server.B0LJ_wu-.d.ts +41 -0
  21. package/dist/shared/server.BQZMQrPe.d.mts +41 -0
  22. package/dist/shared/server.C1RJffw4.mjs +30 -0
  23. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  24. package/dist/shared/server.CYa9puL2.mjs +403 -0
  25. package/dist/shared/server.ChOv1yG3.mjs +319 -0
  26. package/dist/shared/server.Cza0RB3u.mjs +160 -0
  27. package/dist/shared/server.DXPMDozZ.d.mts +388 -0
  28. package/dist/shared/server.DXPMDozZ.d.ts +388 -0
  29. package/dist/shared/server.YUvuxHty.mjs +48 -0
  30. package/package.json +10 -28
  31. package/dist/plugins/index.d.mts +0 -160
  32. package/dist/plugins/index.d.ts +0 -160
  33. package/dist/plugins/index.mjs +0 -288
  34. package/dist/shared/server.BEHw7Eyx.mjs +0 -247
  35. package/dist/shared/server.BVxcyR6X.mjs +0 -287
  36. package/dist/shared/server.Bk5r0-2R.d.ts +0 -56
  37. package/dist/shared/server.Bs6ka_UE.d.mts +0 -23
  38. package/dist/shared/server.CZNLCQBm.d.mts +0 -192
  39. package/dist/shared/server.CZNLCQBm.d.ts +0 -192
  40. package/dist/shared/server.CbLTWfgn.d.mts +0 -56
  41. package/dist/shared/server.D2UFMrxf.d.ts +0 -23
  42. package/dist/shared/server.DcfsPloY.mjs +0 -202
@@ -1,287 +0,0 @@
1
- import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, value, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
2
- import { flattenHeader } from '@temporary-name/standard-server';
3
- import { c as createProcedureClient } from './server.DcfsPloY.mjs';
4
- import { fallbackContractConfig } from '@temporary-name/contract';
5
- import { d as deserialize, s as serialize, a as standardizeHTTPPath } from './server.BEHw7Eyx.mjs';
6
- import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
7
- import { createRouter, addRoute, findRoute } from 'rou3';
8
-
9
- async function decode(request, params, procedure) {
10
- const inputStructure = fallbackContractConfig(
11
- "defaultInputStructure",
12
- procedure["~orpc"].route.inputStructure
13
- );
14
- if (inputStructure === "compact") {
15
- const data = request.method === "GET" ? deserialize(request.url.searchParams) : deserialize(await request.body());
16
- if (data === void 0) {
17
- return params;
18
- }
19
- if (isObject(data)) {
20
- return {
21
- ...params,
22
- ...data
23
- };
24
- }
25
- return data;
26
- }
27
- const deserializeSearchParams = () => {
28
- return deserialize(request.url.searchParams);
29
- };
30
- return {
31
- params,
32
- get query() {
33
- const value = deserializeSearchParams();
34
- Object.defineProperty(this, "query", { value, writable: true });
35
- return value;
36
- },
37
- set query(value) {
38
- Object.defineProperty(this, "query", { value, writable: true });
39
- },
40
- headers: request.headers,
41
- body: deserialize(await request.body())
42
- };
43
- }
44
- function encode(output, procedure) {
45
- const successStatus = fallbackContractConfig(
46
- "defaultSuccessStatus",
47
- procedure["~orpc"].route.successStatus
48
- );
49
- const outputStructure = fallbackContractConfig(
50
- "defaultOutputStructure",
51
- procedure["~orpc"].route.outputStructure
52
- );
53
- if (outputStructure === "compact") {
54
- return {
55
- status: successStatus,
56
- headers: {},
57
- body: serialize(output)
58
- };
59
- }
60
- if (!isDetailedOutput(output)) {
61
- throw new Error(`
62
- Invalid "detailed" output structure:
63
- \u2022 Expected an object with optional properties:
64
- - status (number 200-399)
65
- - headers (Record<string, string | string[]>)
66
- - body (any)
67
- \u2022 No extra keys allowed.
68
-
69
- Actual value:
70
- ${stringifyJSON(output)}
71
- `);
72
- }
73
- return {
74
- status: output.status ?? successStatus,
75
- headers: output.headers ?? {},
76
- body: serialize(output.body)
77
- };
78
- }
79
- function encodeError(error) {
80
- return {
81
- status: error.status,
82
- headers: {},
83
- body: serialize(error.toJSON(), { outputFormat: "plain" })
84
- };
85
- }
86
- function isDetailedOutput(output) {
87
- if (!isObject(output)) {
88
- return false;
89
- }
90
- if (output.headers && !isObject(output.headers)) {
91
- return false;
92
- }
93
- if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
94
- return false;
95
- }
96
- return true;
97
- }
98
-
99
- function resolveFriendlyStandardHandleOptions(options) {
100
- return {
101
- ...options,
102
- context: options.context ?? {}
103
- // Context only optional if all fields are optional
104
- };
105
- }
106
- function toRou3Pattern(path) {
107
- return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
108
- }
109
- function decodeParams(params) {
110
- return Object.fromEntries(
111
- Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)])
112
- );
113
- }
114
-
115
- class StandardOpenAPIMatcher {
116
- tree = createRouter();
117
- pendingRouters = [];
118
- init(router, path = []) {
119
- const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
120
- if (!value(true, traverseOptions)) {
121
- return;
122
- }
123
- const { path: path2, contract } = traverseOptions;
124
- const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
125
- const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
126
- if (isProcedure(contract)) {
127
- addRoute(this.tree, method, httpPath, {
128
- path: path2,
129
- contract,
130
- procedure: contract,
131
- // this mean dev not used contract-first so we can used contract as procedure directly
132
- router
133
- });
134
- } else {
135
- addRoute(this.tree, method, httpPath, {
136
- path: path2,
137
- contract,
138
- procedure: void 0,
139
- router
140
- });
141
- }
142
- });
143
- this.pendingRouters.push(
144
- ...laziedOptions.map((option) => ({
145
- ...option,
146
- httpPathPrefix: toHttpPath(option.path),
147
- laziedPrefix: getLazyMeta(option.router).prefix
148
- }))
149
- );
150
- }
151
- async match(method, pathname) {
152
- if (this.pendingRouters.length) {
153
- const newPendingRouters = [];
154
- for (const pendingRouter of this.pendingRouters) {
155
- if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
156
- const { default: router } = await unlazy(pendingRouter.router);
157
- this.init(router, pendingRouter.path);
158
- } else {
159
- newPendingRouters.push(pendingRouter);
160
- }
161
- }
162
- this.pendingRouters = newPendingRouters;
163
- }
164
- const match = findRoute(this.tree, method, pathname);
165
- if (!match) {
166
- return void 0;
167
- }
168
- if (!match.data.procedure) {
169
- const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
170
- if (!isProcedure(maybeProcedure)) {
171
- throw new Error(`
172
- [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
173
- Ensure that the procedure is correctly defined and matches the expected contract.
174
- `);
175
- }
176
- match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
177
- }
178
- return {
179
- path: match.data.path,
180
- procedure: match.data.procedure,
181
- params: match.params ? decodeParams(match.params) : void 0
182
- };
183
- }
184
- }
185
-
186
- class CompositeStandardHandlerPlugin {
187
- plugins;
188
- constructor(plugins = []) {
189
- this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
190
- }
191
- init(options, router) {
192
- for (const plugin of this.plugins) {
193
- plugin.init?.(options, router);
194
- }
195
- }
196
- }
197
-
198
- class StandardHandler {
199
- interceptors;
200
- clientInterceptors;
201
- rootInterceptors;
202
- matcher;
203
- constructor(router, options) {
204
- this.matcher = new StandardOpenAPIMatcher();
205
- const plugins = new CompositeStandardHandlerPlugin(options.plugins);
206
- plugins.init(options, router);
207
- this.interceptors = toArray(options.interceptors);
208
- this.clientInterceptors = toArray(options.clientInterceptors);
209
- this.rootInterceptors = toArray(options.rootInterceptors);
210
- this.matcher.init(router);
211
- }
212
- async handle(request, options) {
213
- const prefix = options.prefix?.replace(/\/$/, "") || void 0;
214
- if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
215
- return { matched: false, response: void 0 };
216
- }
217
- return intercept(this.rootInterceptors, { ...options, request, prefix }, async (interceptorOptions) => {
218
- return runWithSpan({ name: `${request.method} ${request.url.pathname}` }, async (span) => {
219
- let step;
220
- try {
221
- return await intercept(
222
- this.interceptors,
223
- interceptorOptions,
224
- async ({ request: request2, context, prefix: prefix2 }) => {
225
- const method = request2.method;
226
- const url = request2.url;
227
- const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
228
- const match = await runWithSpan(
229
- { name: "find_procedure" },
230
- () => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
231
- );
232
- if (!match) {
233
- return { matched: false, response: void 0 };
234
- }
235
- span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
236
- span?.setAttribute("rpc.system", ORPC_NAME);
237
- span?.setAttribute("rpc.method", match.path.join("."));
238
- step = "decode_input";
239
- let input = await runWithSpan(
240
- { name: "decode_input" },
241
- () => decode(request2, match.params, match.procedure)
242
- );
243
- step = void 0;
244
- if (isAsyncIteratorObject(input)) {
245
- input = asyncIteratorWithSpan(
246
- { name: "consume_event_iterator_input", signal: request2.signal },
247
- input
248
- );
249
- }
250
- const client = createProcedureClient(match.procedure, {
251
- context,
252
- path: match.path,
253
- interceptors: this.clientInterceptors
254
- });
255
- step = "call_procedure";
256
- const output = await client(input, {
257
- signal: request2.signal,
258
- lastEventId: flattenHeader(request2.headers["last-event-id"])
259
- });
260
- step = void 0;
261
- const response = encode(output, match.procedure);
262
- return {
263
- matched: true,
264
- response
265
- };
266
- }
267
- );
268
- } catch (e) {
269
- if (step !== "call_procedure") {
270
- setSpanError(span, e);
271
- }
272
- const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
273
- message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
274
- cause: e
275
- }) : toORPCError(e);
276
- const response = encodeError(error);
277
- return {
278
- matched: true,
279
- response
280
- };
281
- }
282
- });
283
- });
284
- }
285
- }
286
-
287
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
@@ -1,56 +0,0 @@
1
- import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
- import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.CZNLCQBm.js';
5
-
6
- interface StandardHandlerPlugin<T extends Context> {
7
- order?: number;
8
- init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
9
- }
10
- declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
11
- protected readonly plugins: TPlugin[];
12
- constructor(plugins?: readonly TPlugin[]);
13
- init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
14
- }
15
-
16
- interface StandardHandleOptions<T extends Context> {
17
- prefix?: HTTPPath;
18
- context: T;
19
- }
20
- type StandardHandleResult = {
21
- matched: true;
22
- response: StandardResponse;
23
- } | {
24
- matched: false;
25
- response: undefined;
26
- };
27
- interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
28
- request: StandardLazyRequest;
29
- }
30
- interface StandardHandlerOptions<TContext extends Context> {
31
- plugins?: StandardHandlerPlugin<TContext>[];
32
- /**
33
- * Interceptors at the request level, helpful when you want catch errors
34
- */
35
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
36
- /**
37
- * Interceptors at the root level, helpful when you want override the request/response
38
- */
39
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
40
- /**
41
- *
42
- * Interceptors for procedure client.
43
- */
44
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
45
- }
46
- declare class StandardHandler<T extends Context> {
47
- private readonly interceptors;
48
- private readonly clientInterceptors;
49
- private readonly rootInterceptors;
50
- private readonly matcher;
51
- constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
52
- handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
53
- }
54
-
55
- export { CompositeStandardHandlerPlugin as C, StandardHandler as e };
56
- export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardHandleOptions as c, StandardHandleResult as d };
@@ -1,23 +0,0 @@
1
- import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.CZNLCQBm.mjs';
3
- import { c as StandardHandleOptions } from './server.CbLTWfgn.mjs';
4
-
5
- type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
- context?: T;
7
- } : {
8
- context: T;
9
- });
10
- declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
11
- /**
12
- * {@link https://github.com/unjs/rou3}
13
- *
14
- * @internal
15
- */
16
- declare function toRou3Pattern(path: HTTPPath): string;
17
- /**
18
- * @internal
19
- */
20
- declare function decodeParams(params: Record<string, string>): Record<string, string>;
21
-
22
- export { decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
23
- export type { FriendlyStandardHandleOptions as F };
@@ -1,192 +0,0 @@
1
- import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@temporary-name/contract';
2
- import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, HTTPPath, Promisable, ClientContext, Interceptor, PromiseWithError, Value, Client } from '@temporary-name/shared';
3
-
4
- type Context = Record<PropertyKey, any>;
5
- type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
6
- type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
7
- declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
8
-
9
- type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
10
- type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
11
- type ORPCErrorConstructorMap<T extends ErrorMap> = {
12
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
13
- };
14
- declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
15
-
16
- declare const LAZY_SYMBOL: unique symbol;
17
- interface LazyMeta {
18
- prefix?: HTTPPath;
19
- }
20
- interface Lazy<T> {
21
- [LAZY_SYMBOL]: {
22
- loader: () => Promise<{
23
- default: T;
24
- }>;
25
- meta: LazyMeta;
26
- };
27
- }
28
- type Lazyable<T> = T | Lazy<T>;
29
- /**
30
- * Creates a lazy-loaded item.
31
- *
32
- * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
33
- */
34
- declare function lazy<T>(loader: () => Promise<{
35
- default: T;
36
- }>, meta?: LazyMeta): Lazy<T>;
37
- declare function isLazy(item: unknown): item is Lazy<any>;
38
- declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
39
- declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
40
- default: T extends Lazy<infer U> ? U : T;
41
- }>;
42
-
43
- interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
44
- context: TCurrentContext;
45
- input: TInput;
46
- path: readonly string[];
47
- procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
48
- signal?: AbortSignal;
49
- lastEventId: string | undefined;
50
- errors: TErrorConstructorMap;
51
- }
52
- interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
53
- (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
54
- }
55
- interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
56
- __initialContext?: (type: TInitialContext) => unknown;
57
- middlewares: readonly AnyMiddleware[];
58
- inputValidationIndex: number;
59
- outputValidationIndex: number;
60
- handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
61
- }
62
- /**
63
- * This class represents a procedure.
64
- *
65
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
- */
67
- declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
- /**
69
- * This property holds the defined options.
70
- */
71
- '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
72
- constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
73
- }
74
- type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
75
- declare function isProcedure(item: unknown): item is AnyProcedure;
76
-
77
- type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
78
- output: TOutput;
79
- context: TOutContext;
80
- }>;
81
- type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
82
- context?: TOutContext;
83
- } : {
84
- context: TOutContext;
85
- };
86
- interface MiddlewareNextFn<TOutput> {
87
- <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
88
- }
89
- interface MiddlewareOutputFn<TOutput> {
90
- (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
91
- }
92
- interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
93
- context: TInContext;
94
- path: readonly string[];
95
- procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
96
- signal?: AbortSignal;
97
- lastEventId: string | undefined;
98
- next: MiddlewareNextFn<TOutput>;
99
- errors: TErrorConstructorMap;
100
- }
101
- /**
102
- * A function that represents a middleware.
103
- *
104
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
- */
106
- interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
107
- (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
108
- }
109
- type AnyMiddleware = Middleware<any, any, any, any, any, any>;
110
- interface MapInputMiddleware<TInput, TMappedInput> {
111
- (input: TInput): TMappedInput;
112
- }
113
- declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
114
-
115
- type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
116
- interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
117
- context: TInitialContext;
118
- input: unknown;
119
- errors: ORPCErrorConstructorMap<TErrorMap>;
120
- path: readonly string[];
121
- procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
122
- signal?: AbortSignal;
123
- lastEventId: string | undefined;
124
- }
125
- type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
126
- /**
127
- * This is helpful for logging and analytics.
128
- */
129
- path?: readonly string[];
130
- interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
131
- } & (Record<never, never> extends TInitialContext ? {
132
- context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
133
- } : {
134
- context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
135
- });
136
- /**
137
- * Create Server-side client from a procedure.
138
- *
139
- * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
- */
141
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
142
-
143
- /**
144
- * Represents a router, which defines a hierarchical structure of procedures.
145
- *
146
- * @info A procedure is a router too.
147
- * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
- */
149
- type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
150
- [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
151
- };
152
- type AnyRouter = Router<any, any>;
153
- type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
154
- /**
155
- * Infer all initial context of the router.
156
- *
157
- * @info A procedure is a router too.
158
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
- */
160
- type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
161
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
162
- };
163
- /**
164
- * Infer all current context of the router.
165
- *
166
- * @info A procedure is a router too.
167
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
- */
169
- type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
170
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
171
- };
172
- /**
173
- * Infer all router inputs
174
- *
175
- * @info A procedure is a router too.
176
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
- */
178
- type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
179
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
180
- };
181
- /**
182
- * Infer all router outputs
183
- *
184
- * @info A procedure is a router too.
185
- * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
- */
187
- type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
188
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
189
- };
190
-
191
- export { isProcedure as D, createProcedureClient as F, Procedure as P, createORPCErrorConstructorMap as l, mergeCurrentContext as m, LAZY_SYMBOL as n, lazy as p, isLazy as q, getLazyMeta as r, unlazy as u, middlewareOutputFn as y };
192
- export type { AnyMiddleware as A, ProcedureDef as B, Context as C, ProcedureClientInterceptorOptions as E, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, CreateProcedureClientOptions as a, ProcedureClient as b, AnyRouter as c, Lazy as d, AnyProcedure as e, Middleware as f, MergedCurrentContext as g, ProcedureHandler as h, MapInputMiddleware as i, ORPCErrorConstructorMapItemOptions as j, ORPCErrorConstructorMapItem as k, LazyMeta as o, MiddlewareResult as s, MiddlewareNextFnOptions as t, MiddlewareNextFn as v, MiddlewareOutputFn as w, MiddlewareOptions as x, ProcedureHandlerOptions as z };