@orpc/server 0.0.0-next.e7ee5a9 → 0.0.0-next.e98b833

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 (35) hide show
  1. package/README.md +2 -1
  2. package/dist/adapters/fetch/index.d.mts +4 -5
  3. package/dist/adapters/fetch/index.d.ts +4 -5
  4. package/dist/adapters/fetch/index.mjs +4 -4
  5. package/dist/adapters/hono/index.d.mts +2 -3
  6. package/dist/adapters/hono/index.d.ts +2 -3
  7. package/dist/adapters/hono/index.mjs +4 -4
  8. package/dist/adapters/next/index.d.mts +2 -3
  9. package/dist/adapters/next/index.d.ts +2 -3
  10. package/dist/adapters/next/index.mjs +4 -4
  11. package/dist/adapters/node/index.d.mts +4 -5
  12. package/dist/adapters/node/index.d.ts +4 -5
  13. package/dist/adapters/node/index.mjs +12 -9
  14. package/dist/adapters/standard/index.d.mts +8 -12
  15. package/dist/adapters/standard/index.d.ts +8 -12
  16. package/dist/adapters/standard/index.mjs +2 -3
  17. package/dist/index.d.mts +120 -106
  18. package/dist/index.d.ts +120 -106
  19. package/dist/index.mjs +39 -29
  20. package/dist/plugins/index.d.mts +12 -12
  21. package/dist/plugins/index.d.ts +12 -12
  22. package/dist/plugins/index.mjs +1 -1
  23. package/dist/shared/{server.dPmfqnQI.d.ts → server.CM3tWr3C.d.mts} +16 -18
  24. package/dist/shared/{server.V6zT5iYQ.mjs → server.CMrS28Go.mjs} +124 -157
  25. package/dist/shared/server.CPteJIPP.d.mts +143 -0
  26. package/dist/shared/server.CPteJIPP.d.ts +143 -0
  27. package/dist/shared/{server.BBGuTxHE.mjs → server.CSZRzcSW.mjs} +11 -16
  28. package/dist/shared/server.Cq3B6PoL.mjs +28 -0
  29. package/dist/shared/{server.D86dtDX_.d.mts → server.DmW25ynm.d.ts} +16 -18
  30. package/package.json +7 -7
  31. package/dist/shared/server.B_cAGti1.d.mts +0 -9
  32. package/dist/shared/server.CUE4Aija.mjs +0 -24
  33. package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
  34. package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
  35. package/dist/shared/server.CynXWJja.d.ts +0 -9
@@ -0,0 +1,143 @@
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
2
+ import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
+
5
+ type Context = Record<string, any>;
6
+ type MergedContext<T extends Context, U extends Context> = T & U;
7
+ declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
8
+ type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
9
+ [K in keyof T]: IsNever<T[K]>;
10
+ }[keyof T] ? never : unknown;
11
+
12
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
13
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
14
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
15
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
16
+ };
17
+
18
+ declare const LAZY_SYMBOL: unique symbol;
19
+ interface LazyMeta {
20
+ prefix?: HTTPPath;
21
+ }
22
+ interface Lazy<T> {
23
+ [LAZY_SYMBOL]: {
24
+ loader: () => Promise<{
25
+ default: T;
26
+ }>;
27
+ meta: LazyMeta;
28
+ };
29
+ }
30
+ type Lazyable<T> = T | Lazy<T>;
31
+ declare function lazy<T>(loader: () => Promise<{
32
+ default: T;
33
+ }>, meta?: LazyMeta): Lazy<T>;
34
+ declare function isLazy(item: unknown): item is Lazy<any>;
35
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
36
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
37
+ default: T extends Lazy<infer U> ? U : T;
38
+ }>;
39
+
40
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
41
+ context: TCurrentContext;
42
+ input: TInput;
43
+ path: readonly string[];
44
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
45
+ signal?: AbortSignal;
46
+ lastEventId: string | undefined;
47
+ errors: TErrorConstructorMap;
48
+ }
49
+ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
50
+ (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
51
+ }
52
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
53
+ __initialContext?: (type: TInitialContext) => unknown;
54
+ middlewares: AnyMiddleware[];
55
+ inputValidationIndex: number;
56
+ outputValidationIndex: number;
57
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
+ }
59
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
60
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
+ }
63
+ type AnyProcedure = Procedure<any, any, any, any, any, any>;
64
+ declare function isProcedure(item: unknown): item is AnyProcedure;
65
+
66
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
67
+ output: TOutput;
68
+ context: TOutContext;
69
+ }>;
70
+ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
71
+ context?: TOutContext;
72
+ } : {
73
+ context: TOutContext;
74
+ };
75
+ interface MiddlewareNextFn<TInContext extends Context, TOutput> {
76
+ <U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
77
+ }
78
+ interface MiddlewareOutputFn<TOutput> {
79
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
80
+ }
81
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
82
+ context: TInContext;
83
+ path: readonly string[];
84
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
85
+ signal?: AbortSignal;
86
+ lastEventId: string | undefined;
87
+ next: MiddlewareNextFn<TInContext, TOutput>;
88
+ errors: TErrorConstructorMap;
89
+ }
90
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
+ }
93
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
94
+ interface MapInputMiddleware<TInput, TMappedInput> {
95
+ (input: TInput): TMappedInput;
96
+ }
97
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
98
+
99
+ type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
100
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
101
+ context: TInitialContext;
102
+ input: InferSchemaInput<TInputSchema>;
103
+ errors: ORPCErrorConstructorMap<TErrorMap>;
104
+ path: readonly string[];
105
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
106
+ signal?: AbortSignal;
107
+ lastEventId: string | undefined;
108
+ }
109
+ /**
110
+ * Options for creating a procedure caller with comprehensive type safety
111
+ */
112
+ type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
+ /**
114
+ * This is helpful for logging and analytics.
115
+ */
116
+ path?: readonly string[];
117
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
118
+ } & (Record<never, never> extends TInitialContext ? {
119
+ context?: Value<TInitialContext, [clientContext: TClientContext]>;
120
+ } : {
121
+ context: Value<TInitialContext, [clientContext: TClientContext]>;
122
+ });
123
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
+
125
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
+ };
128
+ type AnyRouter = Router<any, any>;
129
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
130
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
+ };
133
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
+ };
136
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
+ };
139
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
+ };
142
+
143
+ export { type AnyProcedure as A, createProcedureClient as B, type Context as C, type InferRouterInitialContexts as D, type InferRouterCurrentContexts as E, type InferRouterInputs as F, type InferRouterOutputs as G, type InferRouterInitialContext as I, type Lazyable as L, type Middleware as M, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, LAZY_SYMBOL as k, type LazyMeta as l, mergeContext as m, lazy as n, isLazy as o, getLazyMeta as p, type MiddlewareResult as q, type MiddlewareNextFnOptions as r, type MiddlewareNextFn as s, type MiddlewareOutputFn as t, unlazy as u, type MiddlewareOptions as v, middlewareOutputFn as w, type ProcedureHandlerOptions as x, type ProcedureDef as y, isProcedure as z };
@@ -0,0 +1,143 @@
1
+ import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
2
+ import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
+
5
+ type Context = Record<string, any>;
6
+ type MergedContext<T extends Context, U extends Context> = T & U;
7
+ declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
8
+ type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
9
+ [K in keyof T]: IsNever<T[K]>;
10
+ }[keyof T] ? never : unknown;
11
+
12
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
13
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
14
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
15
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
16
+ };
17
+
18
+ declare const LAZY_SYMBOL: unique symbol;
19
+ interface LazyMeta {
20
+ prefix?: HTTPPath;
21
+ }
22
+ interface Lazy<T> {
23
+ [LAZY_SYMBOL]: {
24
+ loader: () => Promise<{
25
+ default: T;
26
+ }>;
27
+ meta: LazyMeta;
28
+ };
29
+ }
30
+ type Lazyable<T> = T | Lazy<T>;
31
+ declare function lazy<T>(loader: () => Promise<{
32
+ default: T;
33
+ }>, meta?: LazyMeta): Lazy<T>;
34
+ declare function isLazy(item: unknown): item is Lazy<any>;
35
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
36
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
37
+ default: T extends Lazy<infer U> ? U : T;
38
+ }>;
39
+
40
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
41
+ context: TCurrentContext;
42
+ input: TInput;
43
+ path: readonly string[];
44
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
45
+ signal?: AbortSignal;
46
+ lastEventId: string | undefined;
47
+ errors: TErrorConstructorMap;
48
+ }
49
+ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
50
+ (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
51
+ }
52
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
53
+ __initialContext?: (type: TInitialContext) => unknown;
54
+ middlewares: AnyMiddleware[];
55
+ inputValidationIndex: number;
56
+ outputValidationIndex: number;
57
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
+ }
59
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
60
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
+ }
63
+ type AnyProcedure = Procedure<any, any, any, any, any, any>;
64
+ declare function isProcedure(item: unknown): item is AnyProcedure;
65
+
66
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
67
+ output: TOutput;
68
+ context: TOutContext;
69
+ }>;
70
+ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
71
+ context?: TOutContext;
72
+ } : {
73
+ context: TOutContext;
74
+ };
75
+ interface MiddlewareNextFn<TInContext extends Context, TOutput> {
76
+ <U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
77
+ }
78
+ interface MiddlewareOutputFn<TOutput> {
79
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
80
+ }
81
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
82
+ context: TInContext;
83
+ path: readonly string[];
84
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
85
+ signal?: AbortSignal;
86
+ lastEventId: string | undefined;
87
+ next: MiddlewareNextFn<TInContext, TOutput>;
88
+ errors: TErrorConstructorMap;
89
+ }
90
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
+ }
93
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
94
+ interface MapInputMiddleware<TInput, TMappedInput> {
95
+ (input: TInput): TMappedInput;
96
+ }
97
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
98
+
99
+ type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
100
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
101
+ context: TInitialContext;
102
+ input: InferSchemaInput<TInputSchema>;
103
+ errors: ORPCErrorConstructorMap<TErrorMap>;
104
+ path: readonly string[];
105
+ procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
106
+ signal?: AbortSignal;
107
+ lastEventId: string | undefined;
108
+ }
109
+ /**
110
+ * Options for creating a procedure caller with comprehensive type safety
111
+ */
112
+ type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
+ /**
114
+ * This is helpful for logging and analytics.
115
+ */
116
+ path?: readonly string[];
117
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TInputSchema, TErrorMap, TMeta>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>[];
118
+ } & (Record<never, never> extends TInitialContext ? {
119
+ context?: Value<TInitialContext, [clientContext: TClientContext]>;
120
+ } : {
121
+ context: Value<TInitialContext, [clientContext: TClientContext]>;
122
+ });
123
+ declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
+
125
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
+ };
128
+ type AnyRouter = Router<any, any>;
129
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
130
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
+ };
133
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
+ };
136
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
+ };
139
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
+ };
142
+
143
+ export { type AnyProcedure as A, createProcedureClient as B, type Context as C, type InferRouterInitialContexts as D, type InferRouterCurrentContexts as E, type InferRouterInputs as F, type InferRouterOutputs as G, type InferRouterInitialContext as I, type Lazyable as L, type Middleware as M, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, LAZY_SYMBOL as k, type LazyMeta as l, mergeContext as m, lazy as n, isLazy as o, getLazyMeta as p, type MiddlewareResult as q, type MiddlewareNextFnOptions as r, type MiddlewareNextFn as s, type MiddlewareOutputFn as t, unlazy as u, type MiddlewareOptions as v, middlewareOutputFn as w, type ProcedureHandlerOptions as x, type ProcedureDef as y, isProcedure as z };
@@ -1,11 +1,10 @@
1
1
  import { ORPCError, toORPCError } from '@orpc/client';
2
2
  import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
3
3
  import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
4
- import { c as createProcedureClient, e as eachContractProcedure, a as convertPathToHttpPath, i as isProcedure, u as unlazy, g as getRouterChild, b as createContractedProcedure } from './server.V6zT5iYQ.mjs';
5
- import { RPCSerializer } from '@orpc/client/standard';
4
+ import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.CMrS28Go.mjs';
6
5
 
7
6
  class StandardHandler {
8
- constructor(router, matcher, codec, options = {}) {
7
+ constructor(router, matcher, codec, options) {
9
8
  this.matcher = matcher;
10
9
  this.codec = codec;
11
10
  this.options = options;
@@ -71,9 +70,8 @@ class StandardHandler {
71
70
  }
72
71
 
73
72
  class RPCCodec {
74
- serializer;
75
- constructor(options = {}) {
76
- this.serializer = options.serializer ?? new RPCSerializer();
73
+ constructor(serializer) {
74
+ this.serializer = serializer;
77
75
  }
78
76
  async decode(request, _params, _procedure) {
79
77
  const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
@@ -99,11 +97,8 @@ class RPCMatcher {
99
97
  tree = {};
100
98
  pendingRouters = [];
101
99
  init(router, path = []) {
102
- const laziedOptions = eachContractProcedure({
103
- router,
104
- path
105
- }, ({ path: path2, contract }) => {
106
- const httpPath = convertPathToHttpPath(path2);
100
+ const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
101
+ const httpPath = toHttpPath(path2);
107
102
  if (isProcedure(contract)) {
108
103
  this.tree[httpPath] = {
109
104
  path: path2,
@@ -123,7 +118,7 @@ class RPCMatcher {
123
118
  });
124
119
  this.pendingRouters.push(...laziedOptions.map((option) => ({
125
120
  ...option,
126
- httpPathPrefix: convertPathToHttpPath(option.path)
121
+ httpPathPrefix: toHttpPath(option.path)
127
122
  })));
128
123
  }
129
124
  async match(_method, pathname) {
@@ -131,7 +126,7 @@ class RPCMatcher {
131
126
  const newPendingRouters = [];
132
127
  for (const pendingRouter of this.pendingRouters) {
133
128
  if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
134
- const { default: router } = await unlazy(pendingRouter.lazied);
129
+ const { default: router } = await unlazy(pendingRouter.router);
135
130
  this.init(router, pendingRouter.path);
136
131
  } else {
137
132
  newPendingRouters.push(pendingRouter);
@@ -144,14 +139,14 @@ class RPCMatcher {
144
139
  return void 0;
145
140
  }
146
141
  if (!match.procedure) {
147
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
142
+ const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
148
143
  if (!isProcedure(maybeProcedure)) {
149
144
  throw new Error(`
150
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
145
+ [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
151
146
  Ensure that the procedure is correctly defined and matches the expected contract.
152
147
  `);
153
148
  }
154
- match.procedure = createContractedProcedure(match.contract, maybeProcedure);
149
+ match.procedure = createContractedProcedure(maybeProcedure, match.contract);
155
150
  }
156
151
  return {
157
152
  path: match.path,
@@ -0,0 +1,28 @@
1
+ import { RPCSerializer } from '@orpc/client/standard';
2
+ import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
3
+ import { S as StandardHandler, a as RPCMatcher, R as RPCCodec } from './server.CSZRzcSW.mjs';
4
+
5
+ class RPCHandler {
6
+ standardHandler;
7
+ constructor(router, options = {}) {
8
+ const serializer = new RPCSerializer();
9
+ const matcher = new RPCMatcher();
10
+ const codec = new RPCCodec(serializer);
11
+ this.standardHandler = new StandardHandler(router, matcher, codec, options);
12
+ }
13
+ async handle(request, ...[
14
+ options = {}
15
+ ]) {
16
+ const standardRequest = toStandardLazyRequest(request);
17
+ const result = await this.standardHandler.handle(standardRequest, options);
18
+ if (!result.matched) {
19
+ return result;
20
+ }
21
+ return {
22
+ matched: true,
23
+ response: toFetchResponse(result.response, options)
24
+ };
25
+ }
26
+ }
27
+
28
+ export { RPCHandler as R };
@@ -1,12 +1,12 @@
1
- import { HTTPPath, Schema, Meta, SchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
1
+ import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
2
  import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
- import { StandardResponse, StandardRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.Cn9ybJtE.mjs';
3
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.CPteJIPP.js';
5
5
  import { ORPCError } from '@orpc/client';
6
6
 
7
7
  type StandardParams = Record<string, string>;
8
8
  type StandardMatchResult = {
9
- path: string[];
9
+ path: readonly string[];
10
10
  procedure: AnyProcedure;
11
11
  params?: StandardParams;
12
12
  } | undefined;
@@ -17,7 +17,7 @@ interface StandardMatcher {
17
17
  interface StandardCodec {
18
18
  encode(output: unknown, procedure: AnyProcedure): StandardResponse;
19
19
  encodeError(error: ORPCError<any, any>): StandardResponse;
20
- decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
20
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
21
  }
22
22
 
23
23
  type StandardHandleOptions<T extends Context> = {
@@ -27,9 +27,6 @@ type StandardHandleOptions<T extends Context> = {
27
27
  } : {
28
28
  context: T;
29
29
  });
30
- type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
31
- context: T;
32
- };
33
30
  type StandardHandleResult = {
34
31
  matched: true;
35
32
  response: StandardResponse;
@@ -37,11 +34,12 @@ type StandardHandleResult = {
37
34
  matched: false;
38
35
  response: undefined;
39
36
  };
40
- type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
41
- request: StandardRequest;
37
+ type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
+ context: T;
39
+ request: StandardLazyRequest;
42
40
  };
43
41
  interface StandardHandlerOptions<TContext extends Context> {
44
- plugins?: Plugin<TContext>[];
42
+ plugins?: HandlerPlugin<TContext>[];
45
43
  /**
46
44
  * Interceptors at the request level, helpful when you want catch errors
47
45
  */
@@ -54,24 +52,24 @@ interface StandardHandlerOptions<TContext extends Context> {
54
52
  *
55
53
  * Interceptors for procedure client.
56
54
  */
57
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
55
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
58
56
  }
59
57
  declare class StandardHandler<T extends Context> {
60
58
  private readonly matcher;
61
59
  private readonly codec;
62
60
  private readonly options;
63
61
  private readonly plugin;
64
- constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
65
- handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
62
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
+ handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
66
64
  }
67
65
 
68
- interface Plugin<TContext extends Context> {
66
+ interface HandlerPlugin<TContext extends Context> {
69
67
  init?(options: StandardHandlerOptions<TContext>): void;
70
68
  }
71
- declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
69
+ declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
72
70
  private readonly plugins;
73
- constructor(plugins?: Plugin<TContext>[]);
71
+ constructor(plugins?: HandlerPlugin<TContext>[]);
74
72
  init(options: StandardHandlerOptions<TContext>): void;
75
73
  }
76
74
 
77
- export { CompositePlugin as C, type Plugin as P, type StandardHandleOptions as S, type WellStandardHandleOptions as W, type StandardHandlerOptions as a, type StandardMatcher as b, type StandardCodec as c, type StandardHandlerInterceptorOptions as d, type StandardParams as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
75
+ export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
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.e7ee5a9",
4
+ "version": "0.0.0-next.e98b833",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -58,12 +58,12 @@
58
58
  "next": ">=14.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@orpc/client": "0.0.0-next.e7ee5a9",
62
- "@orpc/contract": "0.0.0-next.e7ee5a9",
63
- "@orpc/shared": "0.0.0-next.e7ee5a9",
64
- "@orpc/standard-server": "0.0.0-next.e7ee5a9",
65
- "@orpc/standard-server-node": "0.0.0-next.e7ee5a9",
66
- "@orpc/standard-server-fetch": "0.0.0-next.e7ee5a9"
61
+ "@orpc/client": "0.0.0-next.e98b833",
62
+ "@orpc/shared": "0.0.0-next.e98b833",
63
+ "@orpc/standard-server": "0.0.0-next.e98b833",
64
+ "@orpc/contract": "0.0.0-next.e98b833",
65
+ "@orpc/standard-server-fetch": "0.0.0-next.e98b833",
66
+ "@orpc/standard-server-node": "0.0.0-next.e98b833"
67
67
  },
68
68
  "devDependencies": {
69
69
  "light-my-request": "^6.5.1"
@@ -1,9 +0,0 @@
1
- import { C as Context } from './server.Cn9ybJtE.mjs';
2
- import { a as StandardHandlerOptions, b as StandardMatcher, c as StandardCodec } from './server.D86dtDX_.mjs';
3
-
4
- interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
5
- matcher?: StandardMatcher;
6
- codec?: StandardCodec;
7
- }
8
-
9
- export type { RPCHandlerOptions as R };
@@ -1,24 +0,0 @@
1
- import { toStandardRequest, toFetchResponse } from '@orpc/standard-server-fetch';
2
- import { a as RPCMatcher, R as RPCCodec, S as StandardHandler } from './server.BBGuTxHE.mjs';
3
-
4
- class RPCHandler {
5
- standardHandler;
6
- constructor(router, options) {
7
- const matcher = options?.matcher ?? new RPCMatcher();
8
- const codec = options?.codec ?? new RPCCodec();
9
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
10
- }
11
- async handle(request, ...[options]) {
12
- const standardRequest = toStandardRequest(request);
13
- const result = await this.standardHandler.handle(standardRequest, options);
14
- if (!result.matched) {
15
- return result;
16
- }
17
- return {
18
- matched: true,
19
- response: toFetchResponse(result.response, options)
20
- };
21
- }
22
- }
23
-
24
- export { RPCHandler as R };