@orpc/server 0.0.0-next.44bdf93 → 0.0.0-next.47e44e3

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 (75) hide show
  1. package/README.md +118 -0
  2. package/dist/chunk-7A2ZRAPK.js +182 -0
  3. package/dist/chunk-MEBJNUSY.js +32 -0
  4. package/dist/chunk-MHVECKBC.js +421 -0
  5. package/dist/chunk-WQNNSBXW.js +120 -0
  6. package/dist/fetch.js +6 -11
  7. package/dist/hono.js +18 -14
  8. package/dist/index.js +216 -790
  9. package/dist/next.js +6 -11
  10. package/dist/node.js +19 -75
  11. package/dist/plugins.js +11 -0
  12. package/dist/src/adapters/fetch/index.d.ts +1 -4
  13. package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
  14. package/dist/src/adapters/fetch/types.d.ts +4 -11
  15. package/dist/src/adapters/hono/middleware.d.ts +6 -6
  16. package/dist/src/adapters/next/serve.d.ts +11 -11
  17. package/dist/src/adapters/node/index.d.ts +1 -3
  18. package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
  19. package/dist/src/adapters/node/types.d.ts +15 -15
  20. package/dist/src/adapters/standard/handler.d.ts +53 -0
  21. package/dist/src/adapters/standard/index.d.ts +6 -0
  22. package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
  23. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  24. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  25. package/dist/src/adapters/standard/types.d.ts +21 -0
  26. package/dist/src/builder-variants.d.ts +75 -0
  27. package/dist/src/builder.d.ts +51 -36
  28. package/dist/src/config.d.ts +6 -0
  29. package/dist/src/context.d.ts +7 -10
  30. package/dist/src/error.d.ts +8 -6
  31. package/dist/src/hidden.d.ts +5 -3
  32. package/dist/src/implementer-procedure.d.ts +33 -0
  33. package/dist/src/implementer-variants.d.ts +18 -0
  34. package/dist/src/implementer.d.ts +29 -0
  35. package/dist/src/index.d.ts +12 -12
  36. package/dist/src/lazy-utils.d.ts +4 -2
  37. package/dist/src/lazy.d.ts +9 -5
  38. package/dist/src/middleware-decorated.d.ts +7 -6
  39. package/dist/src/middleware-utils.d.ts +5 -0
  40. package/dist/src/middleware.d.ts +23 -21
  41. package/dist/src/plugins/base.d.ts +11 -0
  42. package/dist/src/plugins/cors.d.ts +19 -0
  43. package/dist/src/plugins/index.d.ts +4 -0
  44. package/dist/src/plugins/response-headers.d.ts +10 -0
  45. package/dist/src/procedure-client.d.ts +23 -12
  46. package/dist/src/procedure-decorated.d.ts +13 -15
  47. package/dist/src/procedure-utils.d.ts +6 -4
  48. package/dist/src/procedure.d.ts +18 -32
  49. package/dist/src/router-accessible-lazy.d.ts +8 -0
  50. package/dist/src/router-client.d.ts +8 -22
  51. package/dist/src/router.d.ts +26 -12
  52. package/dist/src/utils.d.ts +23 -2
  53. package/dist/standard.js +13 -0
  54. package/package.json +20 -3
  55. package/dist/chunk-GK2Z6B6W.js +0 -230
  56. package/dist/chunk-SXUFCJBY.js +0 -301
  57. package/dist/chunk-WUOGVGWG.js +0 -1
  58. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  59. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  60. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  61. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  62. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  63. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  64. package/dist/src/builder-with-errors-middlewares.d.ts +0 -50
  65. package/dist/src/builder-with-errors.d.ts +0 -49
  66. package/dist/src/builder-with-middlewares.d.ts +0 -47
  67. package/dist/src/implementer-chainable.d.ts +0 -14
  68. package/dist/src/lazy-decorated.d.ts +0 -7
  69. package/dist/src/procedure-builder-with-input.d.ts +0 -34
  70. package/dist/src/procedure-builder-with-output.d.ts +0 -33
  71. package/dist/src/procedure-builder.d.ts +0 -27
  72. package/dist/src/procedure-implementer.d.ts +0 -22
  73. package/dist/src/router-builder.d.ts +0 -33
  74. package/dist/src/router-implementer.d.ts +0 -22
  75. package/dist/src/types.d.ts +0 -14
@@ -1,301 +0,0 @@
1
- import {
2
- __export,
3
- createProcedureClient,
4
- getRouterChild,
5
- isProcedure,
6
- unlazy
7
- } from "./chunk-GK2Z6B6W.js";
8
-
9
- // src/adapters/fetch/super-json.ts
10
- var super_json_exports = {};
11
- __export(super_json_exports, {
12
- deserialize: () => deserialize,
13
- serialize: () => serialize
14
- });
15
-
16
- // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
17
- function getType(payload) {
18
- return Object.prototype.toString.call(payload).slice(8, -1);
19
- }
20
-
21
- // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
22
- function isPlainObject(payload) {
23
- if (getType(payload) !== "Object")
24
- return false;
25
- const prototype = Object.getPrototypeOf(payload);
26
- return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
27
- }
28
-
29
- // src/adapters/fetch/super-json.ts
30
- function serialize(value, segments = [], meta = []) {
31
- if (typeof value === "bigint") {
32
- meta.push(["bigint", segments]);
33
- return { data: value.toString(), meta };
34
- }
35
- if (value instanceof Date) {
36
- meta.push(["date", segments]);
37
- const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
38
- return { data, meta };
39
- }
40
- if (Number.isNaN(value)) {
41
- meta.push(["nan", segments]);
42
- return { data: "NaN", meta };
43
- }
44
- if (value instanceof RegExp) {
45
- meta.push(["regexp", segments]);
46
- return { data: value.toString(), meta };
47
- }
48
- if (value instanceof URL) {
49
- meta.push(["url", segments]);
50
- return { data: value.toString(), meta };
51
- }
52
- if (isPlainObject(value)) {
53
- const data = {};
54
- for (const k in value) {
55
- data[k] = serialize(value[k], [...segments, k], meta).data;
56
- }
57
- return { data, meta };
58
- }
59
- if (Array.isArray(value)) {
60
- const data = value.map((v, i) => {
61
- if (v === void 0) {
62
- meta.push(["undefined", [...segments, i]]);
63
- return null;
64
- }
65
- return serialize(v, [...segments, i], meta).data;
66
- });
67
- return { data, meta };
68
- }
69
- if (value instanceof Set) {
70
- const result = serialize(Array.from(value), segments, meta);
71
- meta.push(["set", segments]);
72
- return result;
73
- }
74
- if (value instanceof Map) {
75
- const result = serialize(Array.from(value.entries()), segments, meta);
76
- meta.push(["map", segments]);
77
- return result;
78
- }
79
- return { data: value, meta };
80
- }
81
- function deserialize({
82
- data,
83
- meta
84
- }) {
85
- if (meta.length === 0) {
86
- return data;
87
- }
88
- const ref = { data };
89
- for (const [type, segments] of meta) {
90
- let currentRef = ref;
91
- let preSegment = "data";
92
- for (let i = 0; i < segments.length; i++) {
93
- currentRef = currentRef[preSegment];
94
- preSegment = segments[i];
95
- }
96
- switch (type) {
97
- case "nan":
98
- currentRef[preSegment] = Number.NaN;
99
- break;
100
- case "bigint":
101
- currentRef[preSegment] = BigInt(currentRef[preSegment]);
102
- break;
103
- case "date":
104
- currentRef[preSegment] = new Date(currentRef[preSegment]);
105
- break;
106
- case "regexp": {
107
- const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
108
- currentRef[preSegment] = new RegExp(pattern, flags);
109
- break;
110
- }
111
- case "url":
112
- currentRef[preSegment] = new URL(currentRef[preSegment]);
113
- break;
114
- case "undefined":
115
- currentRef[preSegment] = void 0;
116
- break;
117
- case "map":
118
- currentRef[preSegment] = new Map(currentRef[preSegment]);
119
- break;
120
- case "set":
121
- currentRef[preSegment] = new Set(currentRef[preSegment]);
122
- break;
123
- /* v8 ignore next 3 */
124
- default: {
125
- const _expected = type;
126
- }
127
- }
128
- }
129
- return ref.data;
130
- }
131
-
132
- // src/adapters/fetch/orpc-payload-codec.ts
133
- import { ORPCError } from "@orpc/contract";
134
- import { findDeepMatches, set } from "@orpc/shared";
135
- var ORPCPayloadCodec = class {
136
- /**
137
- * If method is GET, the payload will be encoded as query string.
138
- * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
139
- */
140
- encode(payload, method = "POST", fallbackMethod = "POST") {
141
- const { data, meta } = serialize(payload);
142
- const { maps, values } = findDeepMatches((v) => v instanceof Blob, data);
143
- if (method === "GET" && (values.length === 0 || fallbackMethod === "GET")) {
144
- const query = new URLSearchParams({
145
- data: JSON.stringify(data),
146
- meta: JSON.stringify(meta)
147
- });
148
- return {
149
- query,
150
- method: "GET"
151
- };
152
- }
153
- const nonGETMethod = method === "GET" ? fallbackMethod : method;
154
- if (values.length > 0) {
155
- const form = new FormData();
156
- if (data !== void 0) {
157
- form.append("data", JSON.stringify(data));
158
- }
159
- form.append("meta", JSON.stringify(meta));
160
- form.append("maps", JSON.stringify(maps));
161
- for (const i in values) {
162
- const value = values[i];
163
- form.append(i, value);
164
- }
165
- return {
166
- body: form,
167
- method: nonGETMethod
168
- };
169
- }
170
- return {
171
- body: JSON.stringify({ data, meta }),
172
- headers: new Headers({
173
- "content-type": "application/json"
174
- }),
175
- method: nonGETMethod
176
- };
177
- }
178
- async decode(re) {
179
- try {
180
- if ("method" in re && re.method === "GET") {
181
- const url = new URL(re.url);
182
- const query = url.searchParams;
183
- const data = JSON.parse(query.getAll("data").at(-1));
184
- const meta = JSON.parse(query.getAll("meta").at(-1));
185
- return deserialize({
186
- data,
187
- meta
188
- });
189
- }
190
- if (re.headers.get("content-type")?.startsWith("multipart/form-data")) {
191
- const form = await re.formData();
192
- const rawData = form.get("data");
193
- const rawMeta = form.get("meta");
194
- const rawMaps = form.get("maps");
195
- let data = JSON.parse(rawData);
196
- const meta = JSON.parse(rawMeta);
197
- const maps = JSON.parse(rawMaps);
198
- for (const i in maps) {
199
- data = set(data, maps[i], form.get(i));
200
- }
201
- return deserialize({
202
- data,
203
- meta
204
- });
205
- }
206
- const json = await re.json();
207
- return deserialize(json);
208
- } catch (e) {
209
- throw new ORPCError({
210
- code: "BAD_REQUEST",
211
- message: "Cannot parse request/response. Please check the request/response body and Content-Type header.",
212
- cause: e
213
- });
214
- }
215
- }
216
- };
217
-
218
- // src/adapters/fetch/orpc-procedure-matcher.ts
219
- import { trim } from "@orpc/shared";
220
- var ORPCProcedureMatcher = class {
221
- constructor(router) {
222
- this.router = router;
223
- }
224
- async match(pathname) {
225
- const path = trim(pathname, "/").split("/").map(decodeURIComponent);
226
- const match = getRouterChild(this.router, ...path);
227
- const { default: maybeProcedure } = await unlazy(match);
228
- if (!isProcedure(maybeProcedure)) {
229
- return void 0;
230
- }
231
- return {
232
- procedure: maybeProcedure,
233
- path
234
- };
235
- }
236
- };
237
-
238
- // src/adapters/fetch/orpc-handler.ts
239
- import { ORPCError as ORPCError2 } from "@orpc/contract";
240
- import { executeWithHooks, trim as trim2 } from "@orpc/shared";
241
- var RPCHandler = class {
242
- constructor(router, options) {
243
- this.options = options;
244
- this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
245
- this.payloadCodec = options?.payloadCodec ?? new ORPCPayloadCodec();
246
- }
247
- procedureMatcher;
248
- payloadCodec;
249
- async handle(request, ...[options]) {
250
- const context = options?.context;
251
- const execute = async () => {
252
- const url = new URL(request.url);
253
- const pathname = `/${trim2(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
254
- const match = await this.procedureMatcher.match(pathname);
255
- if (!match) {
256
- return { matched: false, response: void 0 };
257
- }
258
- const input = await this.payloadCodec.decode(request);
259
- const client = createProcedureClient(match.procedure, {
260
- context,
261
- path: match.path
262
- });
263
- const output = await client(input, { signal: request.signal });
264
- const { body, headers } = this.payloadCodec.encode(output);
265
- const response = new Response(body, { headers });
266
- return { matched: true, response };
267
- };
268
- try {
269
- const result = await executeWithHooks({
270
- context,
271
- execute,
272
- input: request,
273
- hooks: this.options,
274
- meta: {
275
- signal: request.signal
276
- }
277
- });
278
- return result;
279
- } catch (e) {
280
- const error = e instanceof ORPCError2 ? e : new ORPCError2({
281
- code: "INTERNAL_SERVER_ERROR",
282
- message: "Internal server error",
283
- cause: e
284
- });
285
- const { body, headers } = this.payloadCodec.encode(error.toJSON());
286
- const response = new Response(body, {
287
- headers,
288
- status: error.status
289
- });
290
- return { matched: true, response };
291
- }
292
- }
293
- };
294
-
295
- export {
296
- super_json_exports,
297
- ORPCPayloadCodec,
298
- ORPCProcedureMatcher,
299
- RPCHandler
300
- };
301
- //# sourceMappingURL=chunk-SXUFCJBY.js.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-WUOGVGWG.js.map
@@ -1,20 +0,0 @@
1
- import type { Hooks } from '@orpc/shared';
2
- import type { Router } from '../../router';
3
- import type { Context } from '../../types';
4
- import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
5
- import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
6
- import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
7
- export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
8
- signal?: AbortSignal;
9
- }> & {
10
- procedureMatcher?: PublicORPCProcedureMatcher;
11
- payloadCodec?: PublicORPCPayloadCodec;
12
- };
13
- export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
14
- private readonly options?;
15
- private readonly procedureMatcher;
16
- private readonly payloadCodec;
17
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
18
- handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
19
- }
20
- //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,16 +0,0 @@
1
- import { type HTTPMethod } from '@orpc/contract';
2
- export declare class ORPCPayloadCodec {
3
- /**
4
- * If method is GET, the payload will be encoded as query string.
5
- * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
6
- */
7
- encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
8
- query?: URLSearchParams;
9
- body?: FormData | string;
10
- headers?: Headers;
11
- method: HTTPMethod;
12
- };
13
- decode(re: Request | Response): Promise<unknown>;
14
- }
15
- export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
16
- //# sourceMappingURL=orpc-payload-codec.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ANY_PROCEDURE } from '../../procedure';
2
- import { type ANY_ROUTER } from '../../router';
3
- export declare class ORPCProcedureMatcher {
4
- private readonly router;
5
- constructor(router: ANY_ROUTER);
6
- match(pathname: string): Promise<{
7
- path: string[];
8
- procedure: ANY_PROCEDURE;
9
- } | undefined>;
10
- }
11
- export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
12
- //# sourceMappingURL=orpc-procedure-matcher.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { Segment } from '@orpc/shared';
2
- export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
3
- export type JSONMeta = [JSONExtraType, Segment[]][];
4
- export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
5
- data: unknown;
6
- meta: JSONMeta;
7
- };
8
- export declare function deserialize({ data, meta, }: {
9
- data: unknown;
10
- meta: JSONMeta;
11
- }): unknown;
12
- //# sourceMappingURL=super-json.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ServerResponse } from 'node:http';
2
- import type { Router } from '../../router';
3
- import type { Context } from '../../types';
4
- import type { RPCHandlerOptions } from '../fetch/orpc-handler';
5
- import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
6
- import { type ExpressableIncomingMessage } from './request-listener';
7
- export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
8
- private readonly orpcFetchHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
10
- handle(req: ExpressableIncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
11
- }
12
- //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,28 +0,0 @@
1
- import type { IncomingMessage, ServerResponse } from 'node:http';
2
- export interface ExpressableIncomingMessage extends IncomingMessage {
3
- originalUrl?: string;
4
- }
5
- /**
6
- * Creates a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object from a Node.js
7
- * [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) and
8
- * [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) pair.
9
- *
10
- */
11
- export declare function createRequest(req: ExpressableIncomingMessage, res: ServerResponse): Request;
12
- /**
13
- * Creates a [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object from the headers
14
- * in a Node.js [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
15
- *
16
- * @param req The incoming request object.
17
- * @returns A headers object.
18
- */
19
- export declare function createHeaders(req: IncomingMessage): Headers;
20
- /**
21
- * Sends a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) to the client using the
22
- * Node.js [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) object.
23
- *
24
- * @param res The server response object.
25
- * @param response The response to send.
26
- */
27
- export declare function sendResponse(res: ServerResponse, response: Response): Promise<void>;
28
- //# sourceMappingURL=request-listener.d.ts.map
@@ -1,50 +0,0 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { FlattenLazy } from './lazy';
5
- import type { Middleware } from './middleware';
6
- import type { ProcedureHandler } from './procedure';
7
- import type { Router } from './router';
8
- import type { AdaptedRouter } from './router-builder';
9
- import type { Context, MergeContext } from './types';
10
- import { ProcedureBuilder } from './procedure-builder';
11
- import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
12
- import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
13
- import { DecoratedProcedure } from './procedure-decorated';
14
- import { RouterBuilder } from './router-builder';
15
- export interface BuilderWithErrorsMiddlewaresDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
16
- types?: {
17
- context: TContext;
18
- };
19
- errorMap: TErrorMap;
20
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
21
- inputValidationIndex: number;
22
- outputValidationIndex: number;
23
- }
24
- /**
25
- * `BuilderWithErrorsMiddlewares` is a combination of `BuilderWithErrorsMiddlewares` and `BuilderWithErrors`.
26
- *
27
- * Why?
28
- * - prevents .middleware after .use (can mislead the behavior)
29
- * - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
30
- * - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
31
- *
32
- */
33
- export declare class BuilderWithErrorsMiddlewares<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
34
- '~type': "BuilderWithErrorsMiddlewares";
35
- '~orpc': BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>;
36
- constructor(def: BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>);
37
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, TErrorMap & U>;
38
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
39
- route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TErrorMap>;
40
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, TErrorMap>;
41
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, TErrorMap>;
42
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>;
43
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, TErrorMap>;
44
- tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, TErrorMap>;
45
- router<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
46
- lazy<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
47
- default: U;
48
- }>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
49
- }
50
- //# sourceMappingURL=builder-with-errors-middlewares.d.ts.map
@@ -1,49 +0,0 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { FlattenLazy } from './lazy';
5
- import type { Middleware } from './middleware';
6
- import type { DecoratedMiddleware } from './middleware-decorated';
7
- import type { ProcedureHandler } from './procedure';
8
- import type { Router } from './router';
9
- import type { AdaptedRouter } from './router-builder';
10
- import type { Context, MergeContext } from './types';
11
- import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
12
- import { ProcedureBuilder } from './procedure-builder';
13
- import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
14
- import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
15
- import { DecoratedProcedure } from './procedure-decorated';
16
- import { RouterBuilder } from './router-builder';
17
- export interface BuilderWithErrorsDef<TContext extends Context, TErrorMap extends ErrorMap> {
18
- types?: {
19
- context: TContext;
20
- };
21
- errorMap: TErrorMap;
22
- }
23
- /**
24
- * `BuilderWithErrors` is a branch of `Builder` which it has error map.
25
- *
26
- * Why?
27
- * - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
28
- *
29
- */
30
- export declare class BuilderWithErrors<TContext extends Context, TErrorMap extends ErrorMap> {
31
- '~type': "BuilderWithErrors";
32
- '~orpc': BuilderWithErrorsDef<TContext, TErrorMap>;
33
- constructor(def: BuilderWithErrorsDef<TContext, TErrorMap>);
34
- context<UContext extends Context = TContext>(): BuilderWithErrors<UContext, TErrorMap>;
35
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, TErrorMap & U>;
36
- middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>;
37
- use<U extends Context & ContextGuard<TContext>>(middleware: Middleware<TContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, U, TErrorMap>;
38
- route(route: RouteOptions): ProcedureBuilder<TContext, undefined, TErrorMap>;
39
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, undefined, USchema, TErrorMap>;
40
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, undefined, USchema, TErrorMap>;
41
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>;
42
- prefix(prefix: HTTPPath): RouterBuilder<TContext, undefined, TErrorMap>;
43
- tag(...tags: string[]): RouterBuilder<TContext, undefined, TErrorMap>;
44
- router<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
45
- lazy<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
46
- default: U;
47
- }>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
48
- }
49
- //# sourceMappingURL=builder-with-errors.d.ts.map
@@ -1,47 +0,0 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { FlattenLazy } from './lazy';
4
- import type { Middleware } from './middleware';
5
- import type { ProcedureHandler } from './procedure';
6
- import type { Router } from './router';
7
- import type { AdaptedRouter } from './router-builder';
8
- import type { Context, MergeContext } from './types';
9
- import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
10
- import { type ChainableImplementer } from './implementer-chainable';
11
- import { ProcedureBuilder } from './procedure-builder';
12
- import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
13
- import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
14
- import { DecoratedProcedure } from './procedure-decorated';
15
- import { RouterBuilder } from './router-builder';
16
- /**
17
- * `BuilderWithMiddlewares` is a branch of `Builder` which it has middlewares.
18
- *
19
- * Why?
20
- * - prevents .middleware after .use (can mislead the behavior)
21
- * - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
22
- *
23
- */
24
- export interface BuilderWithMiddlewaresDef<TContext extends Context, TExtraContext extends Context> {
25
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
26
- inputValidationIndex: number;
27
- outputValidationIndex: number;
28
- }
29
- export declare class BuilderWithMiddlewares<TContext extends Context, TExtraContext extends Context> {
30
- '~type': "BuilderHasMiddlewares";
31
- '~orpc': BuilderWithMiddlewaresDef<TContext, TExtraContext>;
32
- constructor(def: BuilderWithMiddlewaresDef<TContext, TExtraContext>);
33
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<TContext, MergeContext<TExtraContext, U>>;
34
- errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, U>;
35
- route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, Record<never, never>>;
36
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, Record<never, never>>;
37
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, Record<never, never>>;
38
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>;
39
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
40
- tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
41
- router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
42
- lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
43
- default: U;
44
- }>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
45
- contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TContext, TExtraContext, U>;
46
- }
47
- //# sourceMappingURL=builder-with-middlewares.d.ts.map
@@ -1,14 +0,0 @@
1
- import type { Middleware } from './middleware';
2
- import type { Context, MergeContext, WELL_CONTEXT } from './types';
3
- import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
4
- import { ProcedureImplementer } from './procedure-implementer';
5
- import { RouterImplementer } from './router-implementer';
6
- export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter<any>> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
7
- [K in keyof TContract]: TContract[K] extends ContractRouter<any> ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
8
- } & Omit<RouterImplementer<TContext, TExtraContext, TContract>, '~type' | '~orpc'>;
9
- export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter<any> = any>(contract: TContract, options: {
10
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, any>[];
11
- inputValidationIndex: number;
12
- outputValidationIndex: number;
13
- }): ChainableImplementer<TContext, TExtraContext, TContract>;
14
- //# sourceMappingURL=implementer-chainable.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { Lazy } from './lazy';
2
- import { type ANY_ROUTER } from './router';
3
- export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
4
- [K in keyof T]: DecoratedLazy<T[K]>;
5
- } : unknown);
6
- export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
7
- //# sourceMappingURL=lazy-decorated.d.ts.map
@@ -1,34 +0,0 @@
1
- import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaOutput } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { MapInputMiddleware, Middleware } from './middleware';
5
- import type { ProcedureHandler } from './procedure';
6
- import type { Context, MergeContext } from './types';
7
- import { DecoratedProcedure } from './procedure-decorated';
8
- import { ProcedureImplementer } from './procedure-implementer';
9
- export interface ProcedureBuilderWithInputDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
10
- contract: ContractProcedure<TInputSchema, undefined, TErrorMap>;
11
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>[];
12
- inputValidationIndex: number;
13
- outputValidationIndex: number;
14
- }
15
- /**
16
- * `ProcedureBuilderWithInput` is a branch of `ProcedureBuilder` which it has input schema.
17
- *
18
- * Why?
19
- * - prevents override input schema after .input
20
- * - allows .use between .input and .output
21
- *
22
- */
23
- export declare class ProcedureBuilderWithInput<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
24
- '~type': "ProcedureBuilderWithInput";
25
- '~orpc': ProcedureBuilderWithInputDef<TContext, TExtraContext, TInputSchema, TErrorMap>;
26
- constructor(def: ProcedureBuilderWithInputDef<TContext, TExtraContext, TInputSchema, TErrorMap>);
27
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithInput<TContext, TExtraContext, TInputSchema, TErrorMap & U>;
28
- route(route: RouteOptions): ProcedureBuilderWithInput<TContext, TExtraContext, TInputSchema, TErrorMap>;
29
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>>): ProcedureBuilderWithInput<TContext, MergeContext<TExtraContext, U>, TInputSchema, TErrorMap>;
30
- use<UExtra extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TErrorMap>;
31
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureImplementer<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
32
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, undefined, UFuncOutput, TErrorMap>;
33
- }
34
- //# sourceMappingURL=procedure-builder-with-input.d.ts.map
@@ -1,33 +0,0 @@
1
- import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaInput } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { Middleware } from './middleware';
5
- import type { ProcedureHandler } from './procedure';
6
- import type { Context, MergeContext } from './types';
7
- import { DecoratedProcedure } from './procedure-decorated';
8
- import { ProcedureImplementer } from './procedure-implementer';
9
- export interface ProcedureBuilderWithOutputDef<TContext extends Context, TExtraContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
10
- contract: ContractProcedure<undefined, TOutputSchema, TErrorMap>;
11
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
12
- inputValidationIndex: number;
13
- outputValidationIndex: number;
14
- }
15
- /**
16
- * `ProcedureBuilderWithOutput` is a branch of `ProcedureBuilder` which it has output schema.
17
- *
18
- * Why?
19
- * - prevents override output schema after .output
20
- * - allows .use between .input and .output
21
- *
22
- */
23
- export declare class ProcedureBuilderWithOutput<TContext extends Context, TExtraContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
24
- '~type': "ProcedureBuilderWithOutput";
25
- '~orpc': ProcedureBuilderWithOutputDef<TContext, TExtraContext, TOutputSchema, TErrorMap>;
26
- constructor(def: ProcedureBuilderWithOutputDef<TContext, TExtraContext, TOutputSchema, TErrorMap>);
27
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithOutput<TContext, TExtraContext, TOutputSchema, TErrorMap & U>;
28
- route(route: RouteOptions): ProcedureBuilderWithOutput<TContext, TExtraContext, TOutputSchema, TErrorMap>;
29
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureBuilderWithOutput<TContext, MergeContext<TExtraContext, U>, TOutputSchema, TErrorMap>;
30
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureImplementer<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
31
- handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>;
32
- }
33
- //# sourceMappingURL=procedure-builder-with-output.d.ts.map