@orpc/server 0.0.0-next.4555a17 → 0.0.0-next.4e27480

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 (58) hide show
  1. package/dist/chunk-GK2Z6B6W.js +230 -0
  2. package/dist/chunk-SXUFCJBY.js +301 -0
  3. package/dist/chunk-WUOGVGWG.js +1 -0
  4. package/dist/fetch.js +11 -107
  5. package/dist/hono.js +30 -0
  6. package/dist/index.js +890 -294
  7. package/dist/next.js +36 -0
  8. package/dist/node.js +87 -0
  9. package/dist/src/adapters/fetch/index.d.ts +6 -0
  10. package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
  11. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
  12. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
  13. package/dist/src/adapters/fetch/super-json.d.ts +12 -0
  14. package/dist/src/adapters/fetch/types.d.ts +21 -0
  15. package/dist/src/adapters/hono/index.d.ts +3 -0
  16. package/dist/src/adapters/hono/middleware.d.ts +12 -0
  17. package/dist/src/adapters/next/index.d.ts +3 -0
  18. package/dist/src/adapters/next/serve.d.ts +19 -0
  19. package/dist/src/adapters/node/index.d.ts +5 -0
  20. package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
  21. package/dist/src/adapters/node/request-listener.d.ts +28 -0
  22. package/dist/src/adapters/node/types.d.ts +22 -0
  23. package/dist/src/builder-with-errors-middlewares.d.ts +51 -0
  24. package/dist/src/builder-with-errors.d.ts +52 -0
  25. package/dist/src/builder-with-middlewares.d.ts +48 -0
  26. package/dist/src/builder.d.ts +42 -47
  27. package/dist/src/config.d.ts +6 -0
  28. package/dist/src/context.d.ts +11 -0
  29. package/dist/src/error.d.ts +10 -0
  30. package/dist/src/hidden.d.ts +6 -0
  31. package/dist/src/implementer-chainable.d.ts +14 -0
  32. package/dist/src/index.d.ts +13 -4
  33. package/dist/src/lazy-decorated.d.ts +7 -0
  34. package/dist/src/lazy-utils.d.ts +4 -0
  35. package/dist/src/lazy.d.ts +6 -11
  36. package/dist/src/middleware-decorated.d.ts +10 -0
  37. package/dist/src/middleware.d.ts +22 -12
  38. package/dist/src/procedure-builder-with-input.d.ts +34 -0
  39. package/dist/src/procedure-builder-with-output.d.ts +33 -0
  40. package/dist/src/procedure-builder.d.ts +24 -28
  41. package/dist/src/procedure-client.d.ts +22 -0
  42. package/dist/src/procedure-decorated.d.ts +26 -0
  43. package/dist/src/procedure-implementer.d.ts +19 -19
  44. package/dist/src/procedure-utils.d.ts +17 -0
  45. package/dist/src/procedure.d.ts +39 -26
  46. package/dist/src/router-builder.d.ts +29 -23
  47. package/dist/src/router-client.d.ts +26 -0
  48. package/dist/src/router-implementer.d.ts +18 -20
  49. package/dist/src/router.d.ts +11 -15
  50. package/dist/src/types.d.ts +8 -8
  51. package/package.json +22 -10
  52. package/dist/chunk-VARUID7X.js +0 -273
  53. package/dist/src/fetch/handle.d.ts +0 -7
  54. package/dist/src/fetch/handler.d.ts +0 -3
  55. package/dist/src/fetch/index.d.ts +0 -4
  56. package/dist/src/fetch/types.d.ts +0 -28
  57. package/dist/src/procedure-caller.d.ts +0 -26
  58. package/dist/src/router-caller.d.ts +0 -25
package/dist/next.js ADDED
@@ -0,0 +1,36 @@
1
+ import "./chunk-WUOGVGWG.js";
2
+ import {
3
+ ORPCPayloadCodec,
4
+ ORPCProcedureMatcher,
5
+ RPCHandler,
6
+ super_json_exports
7
+ } from "./chunk-SXUFCJBY.js";
8
+ import "./chunk-GK2Z6B6W.js";
9
+
10
+ // src/adapters/next/serve.ts
11
+ import { value } from "@orpc/shared";
12
+ function serve(handler, ...[options]) {
13
+ const main = async (req) => {
14
+ const context = await value(options?.context, req);
15
+ const { matched, response } = await handler.handle(req, { ...options, context });
16
+ if (matched) {
17
+ return response;
18
+ }
19
+ return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
20
+ };
21
+ return {
22
+ GET: main,
23
+ POST: main,
24
+ PUT: main,
25
+ PATCH: main,
26
+ DELETE: main
27
+ };
28
+ }
29
+ export {
30
+ ORPCPayloadCodec,
31
+ ORPCProcedureMatcher,
32
+ RPCHandler,
33
+ super_json_exports as SuperJSON,
34
+ serve
35
+ };
36
+ //# sourceMappingURL=next.js.map
package/dist/node.js ADDED
@@ -0,0 +1,87 @@
1
+ import {
2
+ RPCHandler
3
+ } from "./chunk-SXUFCJBY.js";
4
+ import "./chunk-GK2Z6B6W.js";
5
+
6
+ // src/adapters/node/request-listener.ts
7
+ function createRequest(req, res) {
8
+ const controller = new AbortController();
9
+ res.on("close", () => {
10
+ controller.abort();
11
+ });
12
+ const method = req.method ?? "GET";
13
+ const headers = createHeaders(req);
14
+ const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
15
+ const host = headers.get("Host") ?? "localhost";
16
+ const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
17
+ const init = { method, headers, signal: controller.signal };
18
+ if (method !== "GET" && method !== "HEAD") {
19
+ init.body = new ReadableStream({
20
+ start(controller2) {
21
+ req.on("data", (chunk) => {
22
+ controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
23
+ });
24
+ req.on("end", () => {
25
+ controller2.close();
26
+ });
27
+ }
28
+ });
29
+ init.duplex = "half";
30
+ }
31
+ return new Request(url, init);
32
+ }
33
+ function createHeaders(req) {
34
+ const headers = new Headers();
35
+ const rawHeaders = req.rawHeaders;
36
+ for (let i = 0; i < rawHeaders.length; i += 2) {
37
+ headers.append(rawHeaders[i], rawHeaders[i + 1]);
38
+ }
39
+ return headers;
40
+ }
41
+ async function sendResponse(res, response) {
42
+ const headers = {};
43
+ for (const [key, value] of response.headers) {
44
+ if (key in headers) {
45
+ if (Array.isArray(headers[key])) {
46
+ headers[key].push(value);
47
+ } else {
48
+ headers[key] = [headers[key], value];
49
+ }
50
+ } else {
51
+ headers[key] = value;
52
+ }
53
+ }
54
+ res.writeHead(response.status, headers);
55
+ if (response.body != null && res.req.method !== "HEAD") {
56
+ for await (const chunk of response.body) {
57
+ res.write(chunk);
58
+ }
59
+ }
60
+ res.end();
61
+ }
62
+
63
+ // src/adapters/node/orpc-handler.ts
64
+ var RPCHandler2 = class {
65
+ orpcFetchHandler;
66
+ constructor(router, options) {
67
+ this.orpcFetchHandler = new RPCHandler(router, options);
68
+ }
69
+ async handle(req, res, ...[options]) {
70
+ const request = createRequest(req, res);
71
+ const castedOptions = options ?? {};
72
+ const result = await this.orpcFetchHandler.handle(request, castedOptions);
73
+ if (result.matched === false) {
74
+ return { matched: false };
75
+ }
76
+ await options?.beforeSend?.(result.response, castedOptions.context);
77
+ await sendResponse(res, result.response);
78
+ return { matched: true };
79
+ }
80
+ };
81
+ export {
82
+ RPCHandler2 as RPCHandler,
83
+ createHeaders,
84
+ createRequest,
85
+ sendResponse
86
+ };
87
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1,6 @@
1
+ export * from './orpc-handler';
2
+ export * from './orpc-payload-codec';
3
+ export * from './orpc-procedure-matcher';
4
+ export * as SuperJSON from './super-json';
5
+ export * from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,21 @@
1
+ import type { HTTPPath } from '@orpc/contract';
2
+ import type { Context } from '../../types';
3
+ export type FetchHandleOptions<T extends Context> = {
4
+ prefix?: HTTPPath;
5
+ } & (undefined extends T ? {
6
+ context?: T;
7
+ } : {
8
+ context: T;
9
+ });
10
+ export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (undefined extends T ? [] : never);
11
+ export type FetchHandleResult = {
12
+ matched: true;
13
+ response: Response;
14
+ } | {
15
+ matched: false;
16
+ response: undefined;
17
+ };
18
+ export interface FetchHandler<T extends Context> {
19
+ handle: (request: Request, ...rest: FetchHandleRest<T>) => Promise<FetchHandleResult>;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from '../fetch';
2
+ export * from './middleware';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { Context as HonoContext, MiddlewareHandler } from 'hono';
2
+ import type { Context } from '../../types';
3
+ import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
+ import { type Value } from '@orpc/shared';
5
+ export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (undefined extends T ? {
6
+ context?: Value<T, [HonoContext]>;
7
+ } : {
8
+ context: Value<T, [HonoContext]>;
9
+ });
10
+ export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (undefined extends T ? [] : never);
11
+ export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
12
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from '../fetch';
2
+ export * from './serve';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { NextRequest } from 'next/server';
2
+ import type { Context } from '../../types';
3
+ import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
+ import { type Value } from '@orpc/shared';
5
+ export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (undefined extends T ? {
6
+ context?: Value<T, [NextRequest]>;
7
+ } : {
8
+ context: Value<T, [NextRequest]>;
9
+ });
10
+ export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (undefined extends T ? [] : never);
11
+ export interface ServeResult {
12
+ GET: (req: NextRequest) => Promise<Response>;
13
+ POST: (req: NextRequest) => Promise<Response>;
14
+ PUT: (req: NextRequest) => Promise<Response>;
15
+ PATCH: (req: NextRequest) => Promise<Response>;
16
+ DELETE: (req: NextRequest) => Promise<Response>;
17
+ }
18
+ export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
19
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from './orpc-handler';
2
+ export * from './orpc-handler';
3
+ export * from './request-listener';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,22 @@
1
+ import type { HTTPPath } from '@orpc/contract';
2
+ import type { Promisable } from '@orpc/shared';
3
+ import type { IncomingMessage, ServerResponse } from 'node:http';
4
+ import type { Context } from '../../types';
5
+ export type RequestHandleOptions<T extends Context> = {
6
+ prefix?: HTTPPath;
7
+ beforeSend?: (response: Response, context: T) => Promisable<void>;
8
+ } & (undefined extends T ? {
9
+ context?: T;
10
+ } : {
11
+ context: T;
12
+ });
13
+ export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (undefined extends T ? [] : never);
14
+ export type RequestHandleResult = {
15
+ matched: true;
16
+ } | {
17
+ matched: false;
18
+ };
19
+ export interface RequestHandler<T extends Context> {
20
+ handle: (req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>) => Promise<RequestHandleResult>;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,51 @@
1
+ import type { ContractBuilderConfig, 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
+ config: ContractBuilderConfig;
24
+ }
25
+ /**
26
+ * `BuilderWithErrorsMiddlewares` is a combination of `BuilderWithErrorsMiddlewares` and `BuilderWithErrors`.
27
+ *
28
+ * Why?
29
+ * - prevents .middleware after .use (can mislead the behavior)
30
+ * - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
31
+ * - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
32
+ *
33
+ */
34
+ export declare class BuilderWithErrorsMiddlewares<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
35
+ '~type': "BuilderWithErrorsMiddlewares";
36
+ '~orpc': BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>;
37
+ constructor(def: BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>);
38
+ errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, TErrorMap & U>;
39
+ use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
40
+ route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TErrorMap>;
41
+ input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, TErrorMap>;
42
+ output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, TErrorMap>;
43
+ handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>;
44
+ prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, TErrorMap>;
45
+ tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, TErrorMap>;
46
+ router<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
47
+ lazy<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
48
+ default: U;
49
+ }>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
50
+ }
51
+ //# sourceMappingURL=builder-with-errors-middlewares.d.ts.map
@@ -0,0 +1,52 @@
1
+ import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
+ import type { BuilderConfig } from './builder';
3
+ import type { ContextGuard } from './context';
4
+ import type { ORPCErrorConstructorMap } from './error';
5
+ import type { FlattenLazy } from './lazy';
6
+ import type { Middleware } from './middleware';
7
+ import type { DecoratedMiddleware } from './middleware-decorated';
8
+ import type { ProcedureHandler } from './procedure';
9
+ import type { Router } from './router';
10
+ import type { AdaptedRouter } from './router-builder';
11
+ import type { Context, MergeContext } from './types';
12
+ import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
13
+ import { ProcedureBuilder } from './procedure-builder';
14
+ import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
15
+ import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
16
+ import { DecoratedProcedure } from './procedure-decorated';
17
+ import { RouterBuilder } from './router-builder';
18
+ export interface BuilderWithErrorsDef<TContext extends Context, TErrorMap extends ErrorMap> {
19
+ types?: {
20
+ context: TContext;
21
+ };
22
+ errorMap: TErrorMap;
23
+ config: BuilderConfig;
24
+ }
25
+ /**
26
+ * `BuilderWithErrors` is a branch of `Builder` which it has error map.
27
+ *
28
+ * Why?
29
+ * - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
30
+ *
31
+ */
32
+ export declare class BuilderWithErrors<TContext extends Context, TErrorMap extends ErrorMap> {
33
+ '~type': "BuilderWithErrors";
34
+ '~orpc': BuilderWithErrorsDef<TContext, TErrorMap>;
35
+ constructor(def: BuilderWithErrorsDef<TContext, TErrorMap>);
36
+ config(config: ContractBuilderConfig): BuilderWithErrors<TContext, TErrorMap>;
37
+ context<UContext extends Context = TContext>(): BuilderWithErrors<UContext, TErrorMap>;
38
+ errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, TErrorMap & U>;
39
+ middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>;
40
+ use<U extends Context & ContextGuard<TContext>>(middleware: Middleware<TContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, U, TErrorMap>;
41
+ route(route: RouteOptions): ProcedureBuilder<TContext, undefined, TErrorMap>;
42
+ input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, undefined, USchema, TErrorMap>;
43
+ output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, undefined, USchema, TErrorMap>;
44
+ handler<UFuncOutput>(handler: ProcedureHandler<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>;
45
+ prefix(prefix: HTTPPath): RouterBuilder<TContext, undefined, TErrorMap>;
46
+ tag(...tags: string[]): RouterBuilder<TContext, undefined, TErrorMap>;
47
+ router<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
48
+ lazy<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
49
+ default: U;
50
+ }>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
51
+ }
52
+ //# sourceMappingURL=builder-with-errors.d.ts.map
@@ -0,0 +1,48 @@
1
+ import type { ContractBuilderConfig, 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
+ config: ContractBuilderConfig;
26
+ middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
27
+ inputValidationIndex: number;
28
+ outputValidationIndex: number;
29
+ }
30
+ export declare class BuilderWithMiddlewares<TContext extends Context, TExtraContext extends Context> {
31
+ '~type': "BuilderHasMiddlewares";
32
+ '~orpc': BuilderWithMiddlewaresDef<TContext, TExtraContext>;
33
+ constructor(def: BuilderWithMiddlewaresDef<TContext, TExtraContext>);
34
+ use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<TContext, MergeContext<TExtraContext, U>>;
35
+ errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, U>;
36
+ route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, Record<never, never>>;
37
+ input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, Record<never, never>>;
38
+ output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, Record<never, never>>;
39
+ handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>;
40
+ prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
41
+ tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
42
+ router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
43
+ lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
44
+ default: U;
45
+ }>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
46
+ contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TContext, TExtraContext, U>;
47
+ }
48
+ //# sourceMappingURL=builder-with-middlewares.d.ts.map
@@ -1,54 +1,49 @@
1
- import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { IsEqual } from '@orpc/shared';
3
- import type { DecoratedLazy } from './lazy';
4
- import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
5
- import type { HandledRouter, Router } from './router';
1
+ import type { ContractBuilderConfig, 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 { DecoratedMiddleware } from './middleware-decorated';
6
+ import type { ProcedureHandler } from './procedure';
7
+ import type { Router } from './router';
8
+ import type { AdaptedRouter } from './router-builder';
6
9
  import type { Context, MergeContext } from './types';
7
- import { ContractProcedure } from '@orpc/contract';
8
- import { type DecoratedMiddleware, type MapInputMiddleware, type Middleware } from './middleware';
10
+ import { BuilderWithErrors } from './builder-with-errors';
11
+ import { BuilderWithMiddlewares } from './builder-with-middlewares';
12
+ import { type ChainableImplementer } from './implementer-chainable';
9
13
  import { ProcedureBuilder } from './procedure-builder';
10
- import { ProcedureImplementer } from './procedure-implementer';
14
+ import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
15
+ import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
16
+ import { DecoratedProcedure } from './procedure-decorated';
11
17
  import { RouterBuilder } from './router-builder';
12
- import { type ChainedRouterImplementer } from './router-implementer';
13
- export declare class Builder<TContext extends Context, TExtraContext extends Context> {
14
- zz$b: {
15
- middlewares?: Middleware<any, any, any, any>[];
18
+ export interface BuilderConfig extends ContractBuilderConfig {
19
+ initialInputValidationIndex?: number;
20
+ initialOutputValidationIndex?: number;
21
+ }
22
+ export interface BuilderDef<TContext extends Context> {
23
+ types?: {
24
+ context: TContext;
16
25
  };
17
- constructor(zz$b?: {
18
- middlewares?: Middleware<any, any, any, any>[];
19
- });
20
- /**
21
- * Self chainable
22
- */
23
- context<UContext extends Context>(): IsEqual<UContext, Context> extends true ? Builder<TContext, TExtraContext> : Builder<UContext, TExtraContext>;
24
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, unknown, unknown>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
25
- use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, unknown>, mapInput: MapInputMiddleware<unknown, UMappedInput>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
26
- /**
27
- * Convert to ContractProcedureBuilder
28
- */
29
- route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
30
- input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
31
- output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
32
- /**
33
- * Convert to Procedure
34
- */
35
- func<UFuncOutput = undefined>(func: ProcedureFunc<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
36
- /**
37
- * Convert to ProcedureImplementer | RouterBuilder
38
- */
39
- contract<UContract extends ANY_CONTRACT_PROCEDURE | ContractRouter>(contract: UContract): UContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : UContract extends ContractRouter ? ChainedRouterImplementer<TContext, UContract, TExtraContext> : never;
40
- /**
41
- * Create ExtendedMiddleware
42
- */
43
- middleware<UExtraContext extends Context = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>;
44
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
45
- tags(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
46
- /**
47
- * Create DecoratedRouter
48
- */
49
- router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>;
50
- lazy<U extends Router<TContext> | Procedure<TContext, any, any, any, any>>(loader: () => Promise<{
26
+ config: BuilderConfig;
27
+ }
28
+ export declare class Builder<TContext extends Context> {
29
+ '~type': "Builder";
30
+ '~orpc': BuilderDef<TContext>;
31
+ constructor(def: BuilderDef<TContext>);
32
+ config(config: ContractBuilderConfig): Builder<TContext>;
33
+ context<UContext extends Context = TContext>(): Builder<UContext>;
34
+ middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, Record<never, never>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, Record<never, never>>;
35
+ errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, U>;
36
+ use<U extends Context & ContextGuard<TContext>>(middleware: Middleware<TContext, U, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<TContext, U>;
37
+ route(route: RouteOptions): ProcedureBuilder<TContext, undefined, Record<never, never>>;
38
+ input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, undefined, USchema, Record<never, never>>;
39
+ output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, undefined, USchema, Record<never, never>>;
40
+ handler<UFuncOutput>(handler: ProcedureHandler<TContext, undefined, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TContext, undefined, undefined, undefined, UFuncOutput, Record<never, never>>;
41
+ prefix(prefix: HTTPPath): RouterBuilder<TContext, undefined, Record<never, never>>;
42
+ tag(...tags: string[]): RouterBuilder<TContext, undefined, Record<never, never>>;
43
+ router<U extends Router<MergeContext<TContext, undefined>, any>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
44
+ lazy<U extends Router<MergeContext<TContext, undefined>, any>>(loader: () => Promise<{
51
45
  default: U;
52
- }>): DecoratedLazy<U>;
46
+ }>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
47
+ contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TContext, undefined, U>;
53
48
  }
54
49
  //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1,6 @@
1
+ export interface Config {
2
+ initialInputValidationIndex: number;
3
+ initialOutputValidationIndex: number;
4
+ }
5
+ export declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Context } from './types';
2
+ /**
3
+ * U extends Context & ContextGuard<TContext>
4
+ *
5
+ * Purpose:
6
+ * - Ensures that any extension `U` of `Context` must conform to the current `TContext`.
7
+ * - This is useful when redefining `TContext` to maintain type compatibility with the existing context.
8
+ *
9
+ */
10
+ export type ContextGuard<T extends Context> = Partial<T> | undefined;
11
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { ErrorMap, ErrorMapItem, ORPCErrorOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import { ORPCError } from '@orpc/contract';
3
+ export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
4
+ export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
5
+ export type ORPCErrorConstructorMapItem<TCode extends string, TDataSchema extends Schema> = (...rest: ORPCErrorConstructorMapItemRest<SchemaInput<TDataSchema>>) => ORPCError<TCode, SchemaOutput<TDataSchema>>;
6
+ export type ORPCErrorConstructorMap<T extends ErrorMap> = {
7
+ [K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
8
+ };
9
+ export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
10
+ //# sourceMappingURL=error.d.ts.map