@orpc/server 0.0.0-next.73eb96a → 0.0.0-next.748dfd9

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 (33) hide show
  1. package/dist/chunk-3BAPJGK6.js +302 -0
  2. package/dist/{chunk-6A7XHEBH.js → chunk-E7GUWVR4.js} +12 -15
  3. package/dist/chunk-WUOGVGWG.js +1 -0
  4. package/dist/fetch.js +7 -316
  5. package/dist/hono.js +30 -0
  6. package/dist/index.js +9 -6
  7. package/dist/next.js +36 -0
  8. package/dist/node.js +87 -0
  9. package/dist/src/{fetch → adapters/fetch}/index.d.ts +0 -1
  10. package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
  11. package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +2 -2
  12. package/dist/src/adapters/fetch/types.d.ts +21 -0
  13. package/dist/src/adapters/hono/index.d.ts +3 -0
  14. package/dist/src/adapters/hono/middleware.d.ts +12 -0
  15. package/dist/src/adapters/next/index.d.ts +3 -0
  16. package/dist/src/adapters/next/serve.d.ts +19 -0
  17. package/dist/src/adapters/node/index.d.ts +5 -0
  18. package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
  19. package/dist/src/adapters/node/request-listener.d.ts +28 -0
  20. package/dist/src/adapters/node/types.d.ts +22 -0
  21. package/dist/src/builder.d.ts +2 -2
  22. package/dist/src/index.d.ts +1 -0
  23. package/dist/src/middleware.d.ts +16 -6
  24. package/dist/src/procedure-builder.d.ts +2 -2
  25. package/dist/src/procedure-implementer.d.ts +2 -2
  26. package/dist/src/procedure.d.ts +11 -4
  27. package/dist/src/types.d.ts +2 -0
  28. package/package.json +24 -8
  29. package/dist/src/fetch/composite-handler.d.ts +0 -8
  30. package/dist/src/fetch/orpc-handler.d.ts +0 -20
  31. package/dist/src/fetch/types.d.ts +0 -16
  32. /package/dist/src/{fetch → adapters/fetch}/orpc-payload-codec.d.ts +0 -0
  33. /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
package/dist/hono.js ADDED
@@ -0,0 +1,30 @@
1
+ import "./chunk-WUOGVGWG.js";
2
+ import {
3
+ ORPCHandler,
4
+ ORPCPayloadCodec,
5
+ ORPCProcedureMatcher,
6
+ super_json_exports
7
+ } from "./chunk-3BAPJGK6.js";
8
+ import "./chunk-E7GUWVR4.js";
9
+
10
+ // src/adapters/hono/middleware.ts
11
+ import { value } from "@orpc/shared";
12
+ function createMiddleware(handler, ...[options]) {
13
+ return async (c, next) => {
14
+ const context = await value(options?.context, c);
15
+ const { matched, response } = await handler.handle(c.req.raw, { ...options, context });
16
+ if (matched) {
17
+ c.res = response;
18
+ return;
19
+ }
20
+ await next();
21
+ };
22
+ }
23
+ export {
24
+ ORPCHandler,
25
+ ORPCPayloadCodec,
26
+ ORPCProcedureMatcher,
27
+ super_json_exports as SuperJSON,
28
+ createMiddleware
29
+ };
30
+ //# sourceMappingURL=hono.js.map
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  lazy,
10
10
  mergeContext,
11
11
  unlazy
12
- } from "./chunk-6A7XHEBH.js";
12
+ } from "./chunk-E7GUWVR4.js";
13
13
 
14
14
  // src/builder.ts
15
15
  import { ContractProcedure } from "@orpc/contract";
@@ -23,17 +23,17 @@ function decorateMiddleware(middleware) {
23
23
  const decorated = middleware;
24
24
  decorated.mapInput = (mapInput) => {
25
25
  const mapped = decorateMiddleware(
26
- (input, ...rest) => middleware(mapInput(input), ...rest)
26
+ (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
27
27
  );
28
28
  return mapped;
29
29
  };
30
30
  decorated.concat = (concatMiddleware, mapInput) => {
31
31
  const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
32
- const concatted = decorateMiddleware((input, context, meta, ...rest) => {
33
- const next = async (options) => {
34
- return mapped(input, mergeContext(context, options.context), meta, ...rest);
32
+ const concatted = decorateMiddleware((options, input, output, ...rest) => {
33
+ const next = async (nextOptions) => {
34
+ return mapped({ ...options, context: mergeContext(nextOptions.context, options.context) }, input, output, ...rest);
35
35
  };
36
- const merged = middleware(input, context, { ...meta, next }, ...rest);
36
+ const merged = middleware({ ...options, next }, input, output, ...rest);
37
37
  return merged;
38
38
  });
39
39
  return concatted;
@@ -486,6 +486,7 @@ function createRouterClient(options) {
486
486
  }
487
487
 
488
488
  // src/index.ts
489
+ import { configGlobal, fallbackToGlobalConfig } from "@orpc/contract";
489
490
  export * from "@orpc/shared/error";
490
491
  var os = new Builder({});
491
492
  export {
@@ -496,6 +497,7 @@ export {
496
497
  ProcedureImplementer,
497
498
  RouterBuilder,
498
499
  RouterImplementer,
500
+ configGlobal,
499
501
  createChainableImplementer,
500
502
  createProcedureClient,
501
503
  createRouterClient,
@@ -503,6 +505,7 @@ export {
503
505
  decorateMiddleware,
504
506
  decorateProcedure,
505
507
  deepSetLazyRouterPrefix,
508
+ fallbackToGlobalConfig,
506
509
  flatLazy,
507
510
  getLazyRouterPrefix,
508
511
  getRouterChild,
package/dist/next.js ADDED
@@ -0,0 +1,36 @@
1
+ import "./chunk-WUOGVGWG.js";
2
+ import {
3
+ ORPCHandler,
4
+ ORPCPayloadCodec,
5
+ ORPCProcedureMatcher,
6
+ super_json_exports
7
+ } from "./chunk-3BAPJGK6.js";
8
+ import "./chunk-E7GUWVR4.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
+ ORPCHandler,
31
+ ORPCPayloadCodec,
32
+ ORPCProcedureMatcher,
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
+ ORPCHandler
3
+ } from "./chunk-3BAPJGK6.js";
4
+ import "./chunk-E7GUWVR4.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 ORPCHandler2 = class {
65
+ orpcFetchHandler;
66
+ constructor(router, options) {
67
+ this.orpcFetchHandler = new ORPCHandler(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
+ ORPCHandler2 as ORPCHandler,
83
+ createHeaders,
84
+ createRequest,
85
+ sendResponse
86
+ };
87
+ //# sourceMappingURL=node.js.map
@@ -1,4 +1,3 @@
1
- export * from './composite-handler';
2
1
  export * from './orpc-handler';
3
2
  export * from './orpc-payload-codec';
4
3
  export * from './orpc-procedure-matcher';
@@ -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 ORPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
8
+ signal?: AbortSignal;
9
+ }> & {
10
+ procedureMatcher?: PublicORPCProcedureMatcher;
11
+ payloadCodec?: PublicORPCPayloadCodec;
12
+ };
13
+ export declare class ORPCHandler<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<ORPCHandlerOptions<T>> | undefined);
18
+ handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
19
+ }
20
+ //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,5 +1,5 @@
1
- import type { ANY_PROCEDURE } from '../procedure';
2
- import { type ANY_ROUTER } from '../router';
1
+ import type { ANY_PROCEDURE } from '../../procedure';
2
+ import { type ANY_ROUTER } from '../../router';
3
3
  export declare class ORPCProcedureMatcher {
4
4
  private readonly router;
5
5
  constructor(router: ANY_ROUTER);
@@ -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 { ORPCHandlerOptions } from '../fetch/orpc-handler';
5
+ import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
6
+ import { type ExpressableIncomingMessage } from './request-listener';
7
+ export declare class ORPCHandler<T extends Context> implements RequestHandler<T> {
8
+ private readonly orpcFetchHandler;
9
+ constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<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
@@ -6,7 +6,7 @@ import type { Router } from './router';
6
6
  import type { AdaptedRouter } from './router-builder';
7
7
  import type { Context, MergeContext, WELL_CONTEXT } from './types';
8
8
  import { type ChainableImplementer } from './implementer-chainable';
9
- import { type ProcedureFunc } from './procedure';
9
+ import { type ProcedureHandler } from './procedure';
10
10
  import { ProcedureBuilder } from './procedure-builder';
11
11
  import { type DecoratedProcedure } from './procedure-decorated';
12
12
  import { RouterBuilder } from './router-builder';
@@ -23,7 +23,7 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
23
23
  route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
24
24
  input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
25
25
  output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
26
- handler<UFuncOutput = undefined>(handler: ProcedureFunc<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
26
+ handler<UFuncOutput = undefined>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
27
27
  prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
28
28
  tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
29
29
  router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
@@ -18,6 +18,7 @@ export * from './router-client';
18
18
  export * from './router-implementer';
19
19
  export * from './types';
20
20
  export * from './utils';
21
+ export { configGlobal, fallbackToGlobalConfig } from '@orpc/contract';
21
22
  export * from '@orpc/shared/error';
22
23
  export declare const os: Builder<WELL_CONTEXT, undefined>;
23
24
  //# sourceMappingURL=index.d.ts.map
@@ -1,19 +1,29 @@
1
1
  import type { Promisable } from '@orpc/shared';
2
- import type { Context, Meta } from './types';
2
+ import type { ANY_PROCEDURE } from './procedure';
3
+ import type { Context } from './types';
3
4
  export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
4
5
  output: TOutput;
5
6
  context: TExtraContext;
6
7
  }>;
7
- export interface MiddlewareMeta<TOutput> extends Meta {
8
- next: <UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
8
+ export interface MiddlewareNextFn<TOutput> {
9
+ <UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
9
10
  context?: UExtraContext;
10
11
  } : {
11
12
  context: UExtraContext;
12
- }) => MiddlewareResult<UExtraContext, TOutput>;
13
- output: <UOutput>(output: UOutput) => MiddlewareResult<undefined, UOutput>;
13
+ }): MiddlewareResult<UExtraContext, TOutput>;
14
+ }
15
+ export interface MiddlewareOutputFn<TOutput> {
16
+ (output: TOutput): MiddlewareResult<undefined, TOutput>;
17
+ }
18
+ export interface MiddlewareOptions<TContext extends Context, TOutput> {
19
+ context: TContext;
20
+ path: string[];
21
+ procedure: ANY_PROCEDURE;
22
+ signal?: AbortSignal;
23
+ next: MiddlewareNextFn<TOutput>;
14
24
  }
15
25
  export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput> {
16
- (input: TInput, context: TContext, meta: MiddlewareMeta<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
26
+ (options: MiddlewareOptions<TContext, TOutput>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
17
27
  }
18
28
  export type ANY_MIDDLEWARE = Middleware<any, any, any, any>;
19
29
  export interface MapInputMiddleware<TInput, TMappedInput> {
@@ -2,7 +2,7 @@ import type { MapInputMiddleware, Middleware } from './middleware';
2
2
  import type { DecoratedProcedure } from './procedure-decorated';
3
3
  import type { Context, MergeContext } from './types';
4
4
  import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
5
- import { type ProcedureFunc } from './procedure';
5
+ import { type ProcedureHandler } from './procedure';
6
6
  import { ProcedureImplementer } from './procedure-implementer';
7
7
  export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
8
8
  contract: ContractProcedure<TInputSchema, TOutputSchema>;
@@ -17,6 +17,6 @@ export declare class ProcedureBuilder<TContext extends Context, TExtraContext ex
17
17
  output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U>;
18
18
  use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
19
19
  use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
20
- handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
20
+ handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
21
21
  }
22
22
  //# sourceMappingURL=procedure-builder.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { MapInputMiddleware, Middleware } from './middleware';
3
- import type { ProcedureFunc } from './procedure';
3
+ import type { ProcedureHandler } from './procedure';
4
4
  import type { DecoratedProcedure } from './procedure-decorated';
5
5
  import type { Context, MergeContext } from './types';
6
6
  export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> = {
@@ -13,6 +13,6 @@ export declare class ProcedureImplementer<TContext extends Context, TExtraContex
13
13
  constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
14
14
  use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
15
15
  use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
16
- handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
16
+ handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
17
17
  }
18
18
  //# sourceMappingURL=procedure-implementer.d.ts.map
@@ -1,15 +1,22 @@
1
1
  import type { Promisable } from '@orpc/shared';
2
2
  import type { Lazy } from './lazy';
3
3
  import type { Middleware } from './middleware';
4
- import type { Context, MergeContext, Meta } from './types';
4
+ import type { AbortSignal, Context, MergeContext } from './types';
5
5
  import { type ContractProcedure, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
6
- export interface ProcedureFunc<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
7
- (input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
6
+ export interface ProcedureHandlerOptions<TContext extends Context, TInput> {
7
+ context: TContext;
8
+ input: TInput;
9
+ path: string[];
10
+ procedure: ANY_PROCEDURE;
11
+ signal?: AbortSignal;
12
+ }
13
+ export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
14
+ (opt: ProcedureHandlerOptions<MergeContext<TContext, TExtraContext>, SchemaOutput<TInputSchema>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
8
15
  }
9
16
  export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
10
17
  middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, any>[];
11
18
  contract: ContractProcedure<TInputSchema, TOutputSchema>;
12
- handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
19
+ handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
13
20
  }
14
21
  export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
15
22
  '~type': "Procedure";
@@ -1,7 +1,9 @@
1
+ import type { FindGlobalInstanceType } from '@orpc/shared';
1
2
  import type { ANY_PROCEDURE } from './procedure';
2
3
  export type Context = Record<string, any> | undefined;
3
4
  export type WELL_CONTEXT = Record<string, unknown> | undefined;
4
5
  export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
6
+ export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
5
7
  export interface WithSignal {
6
8
  signal?: AbortSignal;
7
9
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.73eb96a",
4
+ "version": "0.0.0-next.748dfd9",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -20,10 +20,25 @@
20
20
  "default": "./dist/index.js"
21
21
  },
22
22
  "./fetch": {
23
- "types": "./dist/src/fetch/index.d.ts",
23
+ "types": "./dist/src/adapters/fetch/index.d.ts",
24
24
  "import": "./dist/fetch.js",
25
25
  "default": "./dist/fetch.js"
26
26
  },
27
+ "./hono": {
28
+ "types": "./dist/src/adapters/hono/index.d.ts",
29
+ "import": "./dist/hono.js",
30
+ "default": "./dist/hono.js"
31
+ },
32
+ "./next": {
33
+ "types": "./dist/src/adapters/next/index.d.ts",
34
+ "import": "./dist/next.js",
35
+ "default": "./dist/next.js"
36
+ },
37
+ "./node": {
38
+ "types": "./dist/src/adapters/node/index.d.ts",
39
+ "import": "./dist/node.js",
40
+ "default": "./dist/node.js"
41
+ },
27
42
  "./🔒/*": {
28
43
  "types": "./dist/src/*.d.ts"
29
44
  }
@@ -33,15 +48,16 @@
33
48
  "!**/*.tsbuildinfo",
34
49
  "dist"
35
50
  ],
36
- "dependencies": {
37
- "@orpc/contract": "0.0.0-next.73eb96a",
38
- "@orpc/shared": "0.0.0-next.73eb96a"
51
+ "peerDependencies": {
52
+ "hono": ">=4.6.0",
53
+ "next": ">=14.0.0"
39
54
  },
40
- "devDependencies": {
41
- "zod": "^3.24.1"
55
+ "dependencies": {
56
+ "@orpc/shared": "0.0.0-next.748dfd9",
57
+ "@orpc/contract": "0.0.0-next.748dfd9"
42
58
  },
43
59
  "scripts": {
44
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
60
+ "build": "tsup --onSuccess='tsc -b --noCheck'",
45
61
  "build:watch": "pnpm run build --watch",
46
62
  "type:check": "tsc -b"
47
63
  }
@@ -1,8 +0,0 @@
1
- import type { Context } from '../types';
2
- import type { ConditionalFetchHandler, FetchHandler, FetchOptions } from './types';
3
- export declare class CompositeHandler<T extends Context> implements FetchHandler<T> {
4
- private readonly handlers;
5
- constructor(handlers: ConditionalFetchHandler<T>[]);
6
- fetch(request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
7
- }
8
- //# sourceMappingURL=composite-handler.d.ts.map
@@ -1,20 +0,0 @@
1
- import type { Hooks } from '@orpc/shared';
2
- import type { Router } from '../router';
3
- import type { Context, WithSignal } from '../types';
4
- import type { ConditionalFetchHandler, FetchOptions } from './types';
5
- import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
6
- import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
7
- export type ORPCHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
8
- procedureMatcher?: PublicORPCProcedureMatcher;
9
- payloadCodec?: PublicORPCPayloadCodec;
10
- };
11
- export declare class ORPCHandler<T extends Context> implements ConditionalFetchHandler<T> {
12
- readonly router: Router<T, any>;
13
- readonly options?: NoInfer<ORPCHandlerOptions<T>> | undefined;
14
- private readonly procedureMatcher;
15
- private readonly payloadCodec;
16
- constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>> | undefined);
17
- condition(request: Request): boolean;
18
- fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
19
- }
20
- //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,16 +0,0 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Context, WithSignal } from '../types';
3
- export type FetchOptions<T extends Context> = WithSignal & {
4
- prefix?: HTTPPath;
5
- } & (undefined extends T ? {
6
- context?: T;
7
- } : {
8
- context: T;
9
- });
10
- export interface FetchHandler<T extends Context> {
11
- fetch: (request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)) => Promise<Response>;
12
- }
13
- export interface ConditionalFetchHandler<T extends Context> extends FetchHandler<T> {
14
- condition: (request: Request) => boolean;
15
- }
16
- //# sourceMappingURL=types.d.ts.map