@orpc/server 0.0.0-next.bc564a6 → 0.0.0-next.bc9d3dd

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 (50) hide show
  1. package/dist/chunk-4IQKTPXM.js +145 -0
  2. package/dist/chunk-SD2T3J2Z.js +319 -0
  3. package/dist/{chunk-KK4SDLC7.js → chunk-SV6DBVXJ.js} +83 -26
  4. package/dist/chunk-XFBAK67J.js +128 -0
  5. package/dist/fetch.js +10 -9
  6. package/dist/hono.js +23 -13
  7. package/dist/index.js +14 -1
  8. package/dist/next.js +11 -10
  9. package/dist/node.js +146 -63
  10. package/dist/plugins.js +11 -0
  11. package/dist/src/adapters/fetch/index.d.ts +2 -4
  12. package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
  13. package/dist/src/adapters/fetch/types.d.ts +2 -10
  14. package/dist/src/adapters/fetch/utils.d.ts +5 -0
  15. package/dist/src/adapters/hono/middleware.d.ts +3 -2
  16. package/dist/src/adapters/next/serve.d.ts +3 -2
  17. package/dist/src/adapters/node/index.d.ts +2 -3
  18. package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
  19. package/dist/src/adapters/node/types.d.ts +13 -14
  20. package/dist/src/adapters/node/utils.d.ts +5 -0
  21. package/dist/src/adapters/standard/handler.d.ts +51 -0
  22. package/dist/src/adapters/standard/index.d.ts +7 -0
  23. package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
  24. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  25. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  26. package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
  27. package/dist/src/adapters/standard/types.d.ts +44 -0
  28. package/dist/src/implementer-procedure.d.ts +2 -2
  29. package/dist/src/implementer-variants.d.ts +6 -5
  30. package/dist/src/implementer.d.ts +7 -6
  31. package/dist/src/index.d.ts +2 -0
  32. package/dist/src/plugins/base.d.ts +13 -0
  33. package/dist/src/plugins/cors.d.ts +19 -0
  34. package/dist/src/plugins/index.d.ts +4 -0
  35. package/dist/src/plugins/response-headers.d.ts +10 -0
  36. package/dist/src/procedure-client.d.ts +18 -7
  37. package/dist/src/procedure-decorated.d.ts +2 -2
  38. package/dist/src/procedure-utils.d.ts +2 -2
  39. package/dist/src/router-client.d.ts +3 -14
  40. package/dist/src/utils.d.ts +24 -0
  41. package/dist/standard.js +17 -0
  42. package/package.json +17 -3
  43. package/dist/chunk-ESTRJAOX.js +0 -299
  44. package/dist/chunk-WUOGVGWG.js +0 -1
  45. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  46. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  47. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  48. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  49. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  50. package/dist/src/adapters/node/request-listener.d.ts +0 -28
@@ -1,22 +1,21 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Promisable } from '@orpc/shared';
3
1
  import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
4
3
  import type { Context } from '../../context';
5
- export type RequestHandleOptions<T extends Context> = {
6
- prefix?: HTTPPath;
7
- beforeSend?(response: Response, context: T): Promisable<void>;
8
- } & (Record<never, never> extends T ? {
9
- context?: T;
10
- } : {
11
- context: T;
12
- });
13
- export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
14
- export type RequestHandleResult = {
4
+ import type { StandardHandleRest } from '../standard';
5
+ export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
6
+ /**
7
+ * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
8
+ * This is useful for `express.js` middleware.
9
+ */
10
+ originalUrl?: string;
11
+ };
12
+ export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
13
+ export type NodeHttpHandleResult = {
15
14
  matched: true;
16
15
  } | {
17
16
  matched: false;
18
17
  };
19
- export interface RequestHandler<T extends Context> {
20
- handle(req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
18
+ export interface NodeHttpHandler<T extends Context> {
19
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
21
20
  }
22
21
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { StandardRequest, StandardResponse } from '../standard';
2
+ import type { NodeHttpRequest, NodeHttpResponse } from './types';
3
+ export declare function nodeHttpToStandardRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardRequest;
4
+ export declare function nodeHttpResponseSendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse): Promise<void>;
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,51 @@
1
+ import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
2
+ import type { Interceptor } from '@orpc/shared';
3
+ import type { Context } from '../../context';
4
+ import type { Plugin } from '../../plugins';
5
+ import type { CreateProcedureClientOptions } from '../../procedure-client';
6
+ import type { Router } from '../../router';
7
+ import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
8
+ export type StandardHandleOptions<T extends Context> = {
9
+ prefix?: HTTPPath;
10
+ } & (Record<never, never> extends T ? {
11
+ context?: T;
12
+ } : {
13
+ context: T;
14
+ });
15
+ export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
16
+ context: T;
17
+ };
18
+ export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
19
+ export type StandardHandleResult = {
20
+ matched: true;
21
+ response: StandardResponse;
22
+ } | {
23
+ matched: false;
24
+ response: undefined;
25
+ };
26
+ export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
27
+ request: StandardRequest;
28
+ };
29
+ export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, unknown> & {
30
+ context: TContext;
31
+ };
32
+ export interface StandardHandlerOptions<TContext extends Context> {
33
+ plugins?: Plugin<TContext>[];
34
+ /**
35
+ * Interceptors at the request level, helpful when you want catch errors
36
+ */
37
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
38
+ /**
39
+ * Interceptors at the root level, helpful when you want override the response
40
+ */
41
+ interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
42
+ }
43
+ export declare class StandardHandler<TContext extends Context> {
44
+ private readonly matcher;
45
+ private readonly codec;
46
+ private readonly options;
47
+ private readonly plugin;
48
+ constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
49
+ handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): Promise<StandardHandleResult>;
50
+ }
51
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1,7 @@
1
+ export * from './handler';
2
+ export * from './rpc-codec';
3
+ export * from './rpc-handler';
4
+ export * from './rpc-matcher';
5
+ export * from './rpc-serializer';
6
+ export * from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,15 @@
1
+ import type { ORPCError } from '@orpc/contract';
2
+ import type { AnyProcedure } from '../../procedure';
3
+ import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from './types';
4
+ import { RPCSerializer } from './rpc-serializer';
5
+ export interface StandardCodecOptions {
6
+ serializer?: RPCSerializer;
7
+ }
8
+ export declare class RPCCodec implements StandardCodec {
9
+ private readonly serializer;
10
+ constructor(options?: StandardCodecOptions);
11
+ decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
12
+ encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
13
+ encodeError(error: ORPCError<any, any>): StandardResponse;
14
+ }
15
+ //# sourceMappingURL=rpc-codec.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { Context } from '../../context';
2
+ import type { StandardHandlerOptions } from './handler';
3
+ import type { StandardCodec, StandardMatcher } from './types';
4
+ export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
5
+ matcher?: StandardMatcher;
6
+ codec?: StandardCodec;
7
+ }
8
+ //# sourceMappingURL=rpc-handler.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { HTTPPath } from '@orpc/contract';
2
+ import type { StandardMatcher, StandardMatchResult } from './types';
3
+ import { type AnyRouter } from '../../router';
4
+ export declare class RPCMatcher implements StandardMatcher {
5
+ private readonly tree;
6
+ private pendingRouters;
7
+ init(router: AnyRouter, path?: string[]): void;
8
+ match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
9
+ }
10
+ //# sourceMappingURL=rpc-matcher.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { Segment } from '@orpc/shared';
2
+ export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url', Segment[]][];
3
+ export type RPCSerialized = {
4
+ json: unknown;
5
+ meta: RPCSerializedJsonMeta;
6
+ } | FormData | Blob | undefined;
7
+ export type RPCSerializedFormDataMaps = Segment[][];
8
+ export declare class RPCSerializer {
9
+ serialize(data: unknown): RPCSerialized;
10
+ deserialize(serialized: RPCSerialized): unknown;
11
+ }
12
+ export declare function serializeRPCJson(value: unknown, segments?: Segment[], meta?: RPCSerializedJsonMeta): {
13
+ json: unknown;
14
+ meta: RPCSerializedJsonMeta;
15
+ };
16
+ //# sourceMappingURL=rpc-serializer.d.ts.map
@@ -0,0 +1,44 @@
1
+ import type { AbortSignal, HTTPPath, ORPCError } from '@orpc/contract';
2
+ import type { JsonValue } from '@orpc/shared';
3
+ import type { AnyProcedure } from '../../procedure';
4
+ import type { AnyRouter } from '../../router';
5
+ export interface StandardHeaders {
6
+ [key: string]: string | string[] | undefined;
7
+ }
8
+ export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData;
9
+ export interface StandardRequest {
10
+ /**
11
+ * Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
12
+ */
13
+ raw: Record<string, unknown>;
14
+ method: string;
15
+ url: URL;
16
+ headers: StandardHeaders;
17
+ /**
18
+ * The body has been parsed base on the content-type header.
19
+ * This method can safely call multiple times (cached).
20
+ */
21
+ body(): Promise<StandardBody>;
22
+ signal?: AbortSignal;
23
+ }
24
+ export interface StandardResponse {
25
+ status: number;
26
+ headers: StandardHeaders;
27
+ body: StandardBody;
28
+ }
29
+ export type StandardParams = Record<string, string>;
30
+ export type StandardMatchResult = {
31
+ path: string[];
32
+ procedure: AnyProcedure;
33
+ params?: StandardParams;
34
+ } | undefined;
35
+ export interface StandardMatcher {
36
+ init(router: AnyRouter): void;
37
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
38
+ }
39
+ export interface StandardCodec {
40
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
41
+ encodeError(error: ORPCError<any, any>): StandardResponse;
42
+ decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
43
+ }
44
+ //# sourceMappingURL=types.d.ts.map
@@ -13,11 +13,11 @@ export interface ImplementedProcedure<TInitialContext extends Context, TCurrentC
13
13
  /**
14
14
  * Make this procedure callable (works like a function while still being a procedure).
15
15
  */
16
- callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
16
+ callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
17
17
  /**
18
18
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
19
19
  */
20
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
20
+ actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
21
21
  }
22
22
  /**
23
23
  * Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
@@ -1,16 +1,17 @@
1
- import type { AnyContractRouter, ContractProcedure, ContractRouter, ContractRouterToErrorMap, ORPCErrorConstructorMap } from '@orpc/contract';
1
+ import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
2
2
  import type { ConflictContextGuard, Context, MergedContext } from './context';
3
3
  import type { ProcedureImplementer } from './implementer-procedure';
4
4
  import type { FlattenLazy } from './lazy-utils';
5
5
  import type { Middleware } from './middleware';
6
6
  import type { AdaptedRouter, Router } from './router';
7
- export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : TContract extends ContractRouter<infer UMeta> ? {
8
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, UMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
7
+ export interface RouterImplementerWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
8
+ use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
9
9
  router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
10
10
  lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
11
11
  default: U;
12
12
  }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
13
- } & {
13
+ }
14
+ export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
14
15
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
15
- } : never);
16
+ });
16
17
  //# sourceMappingURL=implementer-variants.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { AnyContractRouter, ContractProcedure, ContractRouter, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
1
+ import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
2
2
  import type { ConflictContextGuard, Context, MergedContext } from './context';
3
3
  import type { ProcedureImplementer } from './implementer-procedure';
4
4
  import type { ImplementerInternalWithMiddlewares } from './implementer-variants';
@@ -7,17 +7,18 @@ import { type BuilderConfig } from './builder';
7
7
  import { type FlattenLazy } from './lazy-utils';
8
8
  import { type DecoratedMiddleware } from './middleware-decorated';
9
9
  import { type AdaptedRouter, type Router } from './router';
10
- export type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : TContract extends ContractRouter<infer UMeta> ? {
10
+ export interface RouterImplementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
11
11
  middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
12
- middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, UMeta>;
13
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, UMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
12
+ middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, ContractRouterToMeta<TContract>>;
13
+ use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
14
14
  router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
15
15
  lazy<U extends Router<TCurrentContext, TContract>>(loader: () => Promise<{
16
16
  default: U;
17
17
  }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
18
- } & {
18
+ }
19
+ export type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
19
20
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
20
- } : never);
21
+ });
21
22
  export declare function implementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
22
23
  export type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
23
24
  $context<U extends Context>(): Implementer<TContract, U, U>;
@@ -17,5 +17,7 @@ export * from './procedure-utils';
17
17
  export * from './router';
18
18
  export * from './router-accessible-lazy';
19
19
  export * from './router-client';
20
+ export * from './utils';
20
21
  export { isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
22
+ export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
21
23
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { StandardHandlerInterceptorOptions, StandardHandlerOptions, WellCreateProcedureClientOptions } from '../adapters/standard';
2
+ import type { Context } from '../context';
3
+ export interface Plugin<TContext extends Context> {
4
+ init?(options: StandardHandlerOptions<TContext>): void;
5
+ beforeCreateProcedureClient?(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
6
+ }
7
+ export declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
8
+ private readonly plugins;
9
+ constructor(plugins?: Plugin<TContext>[]);
10
+ init(options: StandardHandlerOptions<TContext>): void;
11
+ beforeCreateProcedureClient(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
12
+ }
13
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { StandardHandlerInterceptorOptions, StandardHandlerOptions } from '../adapters/standard';
2
+ import type { Context } from '../context';
3
+ import type { Plugin } from './base';
4
+ import { type Value } from '@orpc/shared';
5
+ export interface CORSOptions<TContext extends Context> {
6
+ origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
7
+ timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
8
+ allowMethods?: string[];
9
+ allowHeaders?: string[];
10
+ maxAge?: number;
11
+ credentials?: boolean;
12
+ exposeHeaders?: string[];
13
+ }
14
+ export declare class CORSPlugin<TContext extends Context> implements Plugin<TContext> {
15
+ private readonly options;
16
+ constructor(options?: Partial<CORSOptions<TContext>>);
17
+ init(options: StandardHandlerOptions<TContext>): void;
18
+ }
19
+ //# sourceMappingURL=cors.d.ts.map
@@ -0,0 +1,4 @@
1
+ export * from './base';
2
+ export * from './cors';
3
+ export * from './response-headers';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { StandardHandlerOptions } from '../adapters/standard';
2
+ import type { Context } from '../context';
3
+ import type { Plugin } from './base';
4
+ export interface ResponseHeadersPluginContext {
5
+ resHeaders?: Headers;
6
+ }
7
+ export declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements Plugin<TContext> {
8
+ init(options: StandardHandlerOptions<TContext>): void;
9
+ }
10
+ //# sourceMappingURL=response-headers.d.ts.map
@@ -1,20 +1,31 @@
1
- import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { Hooks, Value } from '@orpc/shared';
1
+ import type { Client, ErrorFromErrorMap, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Interceptor, Value } from '@orpc/shared';
3
3
  import type { Context } from './context';
4
4
  import type { Lazyable } from './lazy';
5
5
  import type { Procedure } from './procedure';
6
6
  export type ProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
7
+ export interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
8
+ context: TInitialContext;
9
+ input: SchemaInput<TInputSchema>;
10
+ errors: ORPCErrorConstructorMap<TErrorMap>;
11
+ path: string[];
12
+ procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
13
+ signal?: AbortSignal;
14
+ }
7
15
  /**
8
16
  * Options for creating a procedure caller with comprehensive type safety
9
17
  */
10
- export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
18
+ export type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = {
11
19
  /**
12
20
  * This is helpful for logging and analytics.
13
21
  */
14
22
  path?: string[];
15
- } & ({
23
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>[];
24
+ } & (Record<never, never> extends TInitialContext ? {
25
+ context?: Value<TInitialContext, [clientContext: TClientContext]>;
26
+ } : {
16
27
  context: Value<TInitialContext, [clientContext: TClientContext]>;
17
- } | (Record<never, never> extends TInitialContext ? Record<never, never> : never)) & Hooks<unknown, SchemaOutput<TCurrentContext, THandlerOutput>, TInitialContext, any>;
18
- export type CreateProcedureClientRest<TInitialContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
19
- export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, any>>, ...[options]: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
28
+ });
29
+ export type CreateProcedureClientRest<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
30
+ export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
20
31
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -12,10 +12,10 @@ export declare class DecoratedProcedure<TInitialContext extends Context, TCurren
12
12
  /**
13
13
  * Make this procedure callable (works like a function while still being a procedure).
14
14
  */
15
- callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
15
+ callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
16
16
  /**
17
17
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
18
18
  */
19
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
19
+ actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
20
20
  }
21
21
  //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Meta, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { Context } from './context';
3
3
  import type { Lazyable } from './lazy';
4
4
  import type { Procedure } from './procedure';
@@ -13,5 +13,5 @@ import { type CreateProcedureClientRest } from './procedure-client';
13
13
  * ```
14
14
  *
15
15
  */
16
- export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, any>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
16
+ export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
17
17
  //# sourceMappingURL=procedure-utils.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { Hooks, Value } from '@orpc/shared';
1
+ import type { ErrorMap, Meta } from '@orpc/contract';
2
2
  import type { Lazy } from './lazy';
3
3
  import type { Procedure } from './procedure';
4
4
  import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
@@ -6,17 +6,6 @@ import type { AnyRouter, Router } from './router';
6
6
  export type RouterClient<TRouter extends AnyRouter, TClientContext> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
7
7
  [K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
8
8
  };
9
- export type CreateRouterClientOptions<TRouter extends AnyRouter> = {
10
- /**
11
- * This is helpful for logging and analytics.
12
- *
13
- * @internal
14
- */
15
- path?: string[];
16
- } & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
17
- context?: Value<UContext>;
18
- } : {
19
- context: Value<UContext>;
20
- } : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, any>;
21
- export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
9
+ export type CreateRouterClientRest<TRouter extends AnyRouter, TClientContext> = CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>;
10
+ export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateRouterClientRest<TRouter, TClientContext>): RouterClient<TRouter, TClientContext>;
22
11
  //# sourceMappingURL=router-client.d.ts.map
@@ -0,0 +1,24 @@
1
+ import type { AnyContractProcedure, AnyContractRouter, HTTPPath } from '@orpc/contract';
2
+ import type { Lazy } from './lazy';
3
+ import type { AnyProcedure } from './procedure';
4
+ import type { AnyRouter } from './router';
5
+ export interface EachContractProcedureOptions {
6
+ router: AnyRouter | AnyContractRouter;
7
+ path: string[];
8
+ }
9
+ export interface EachContractProcedureCallbackOptions {
10
+ contract: AnyContractProcedure;
11
+ path: string[];
12
+ }
13
+ export interface EachContractProcedureLaziedOptions {
14
+ lazied: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
15
+ path: string[];
16
+ }
17
+ export declare function eachContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void, laziedOptions?: EachContractProcedureLaziedOptions[]): EachContractProcedureLaziedOptions[];
18
+ export declare function eachAllContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void): Promise<void>;
19
+ export declare function convertPathToHttpPath(path: string[]): HTTPPath;
20
+ /**
21
+ * Create a new procedure that ensure the contract is applied to the procedure.
22
+ */
23
+ export declare function createContractedProcedure(contract: AnyContractProcedure, procedure: AnyProcedure): AnyProcedure;
24
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,17 @@
1
+ import {
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ RPCSerializer,
5
+ StandardHandler,
6
+ serializeRPCJson
7
+ } from "./chunk-SD2T3J2Z.js";
8
+ import "./chunk-SV6DBVXJ.js";
9
+ import "./chunk-XFBAK67J.js";
10
+ export {
11
+ RPCCodec,
12
+ RPCMatcher,
13
+ RPCSerializer,
14
+ StandardHandler,
15
+ serializeRPCJson
16
+ };
17
+ //# sourceMappingURL=standard.js.map
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.bc564a6",
4
+ "version": "0.0.0-next.bc9d3dd",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,6 +19,16 @@
19
19
  "import": "./dist/index.js",
20
20
  "default": "./dist/index.js"
21
21
  },
22
+ "./plugins": {
23
+ "types": "./dist/src/plugins/index.d.ts",
24
+ "import": "./dist/plugins.js",
25
+ "default": "./dist/plugins.js"
26
+ },
27
+ "./standard": {
28
+ "types": "./dist/src/adapters/standard/index.d.ts",
29
+ "import": "./dist/standard.js",
30
+ "default": "./dist/standard.js"
31
+ },
22
32
  "./fetch": {
23
33
  "types": "./dist/src/adapters/fetch/index.d.ts",
24
34
  "import": "./dist/fetch.js",
@@ -53,8 +63,12 @@
53
63
  "next": ">=14.0.0"
54
64
  },
55
65
  "dependencies": {
56
- "@orpc/contract": "0.0.0-next.bc564a6",
57
- "@orpc/shared": "0.0.0-next.bc564a6"
66
+ "@tinyhttp/content-disposition": "^2.2.2",
67
+ "@orpc/contract": "0.0.0-next.bc9d3dd",
68
+ "@orpc/shared": "0.0.0-next.bc9d3dd"
69
+ },
70
+ "devDependencies": {
71
+ "light-my-request": "^6.5.1"
58
72
  },
59
73
  "scripts": {
60
74
  "build": "tsup --onSuccess='tsc -b --noCheck'",