@orpc/server 0.0.0-next.f22c7ec → 0.0.0-next.f56d2b3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-2HRHHZJD.js → chunk-ESTRJAOX.js} +5 -7
- package/dist/chunk-KK4SDLC7.js +320 -0
- package/dist/fetch.js +2 -2
- package/dist/hono.js +3 -3
- package/dist/index.js +205 -405
- package/dist/next.js +3 -3
- package/dist/node.js +6 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +4 -4
- package/dist/src/adapters/fetch/types.d.ts +4 -4
- package/dist/src/adapters/hono/middleware.d.ts +3 -3
- package/dist/src/adapters/next/serve.d.ts +8 -8
- package/dist/src/adapters/node/orpc-handler.d.ts +2 -2
- package/dist/src/adapters/node/types.d.ts +5 -5
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +50 -31
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +5 -3
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +16 -0
- package/dist/src/implementer.d.ts +27 -0
- package/dist/src/index.d.ts +9 -13
- package/dist/src/lazy-utils.d.ts +4 -2
- package/dist/src/lazy.d.ts +9 -5
- package/dist/src/middleware-decorated.d.ts +7 -6
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +22 -21
- package/dist/src/procedure-client.d.ts +6 -8
- package/dist/src/procedure-decorated.d.ts +10 -14
- package/dist/src/procedure-utils.d.ts +2 -2
- package/dist/src/procedure.d.ts +19 -34
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +6 -10
- package/dist/src/router.d.ts +25 -12
- package/package.json +3 -3
- package/dist/chunk-SA7HGGVY.js +0 -242
- package/dist/src/error.d.ts +0 -10
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/lazy-decorated.d.ts +0 -7
- package/dist/src/procedure-builder.d.ts +0 -24
- package/dist/src/procedure-implementer.d.ts +0 -20
- package/dist/src/router-builder.d.ts +0 -31
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
package/dist/src/middleware.d.ts
CHANGED
@@ -1,36 +1,37 @@
|
|
1
|
+
import type { AbortSignal, ErrorMap, Meta, ORPCErrorConstructorMap, Schema } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
|
5
|
-
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
3
|
+
import type { Context } from './context';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
6
6
|
output: TOutput;
|
7
|
-
context:
|
7
|
+
context: TOutContext;
|
8
8
|
}>;
|
9
|
-
export
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
export type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
10
|
+
context?: TOutContext;
|
11
|
+
} : {
|
12
|
+
context: TOutContext;
|
13
|
+
};
|
14
|
+
export type MiddlewareNextFnRest<TOutContext extends Context> = [options: MiddlewareNextFnOptions<TOutContext>] | (Record<never, never> extends TOutContext ? [] : never);
|
15
|
+
export interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
16
|
+
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MiddlewareNextFnRest<U>): MiddlewareResult<U, TOutput>;
|
15
17
|
}
|
16
18
|
export interface MiddlewareOutputFn<TOutput> {
|
17
|
-
(output: TOutput): MiddlewareResult<
|
19
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
18
20
|
}
|
19
|
-
export interface MiddlewareOptions<
|
20
|
-
context:
|
21
|
+
export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
22
|
+
context: TInContext;
|
21
23
|
path: string[];
|
22
|
-
procedure:
|
24
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
23
25
|
signal?: AbortSignal;
|
24
|
-
next: MiddlewareNextFn<TOutput>;
|
26
|
+
next: MiddlewareNextFn<TInContext, TOutput>;
|
25
27
|
errors: TErrorConstructorMap;
|
26
28
|
}
|
27
|
-
export interface Middleware<
|
28
|
-
(options: MiddlewareOptions<
|
29
|
+
export interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
30
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
29
31
|
}
|
30
|
-
export type
|
32
|
+
export type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
31
33
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
32
34
|
(input: TInput): TMappedInput;
|
33
35
|
}
|
34
|
-
export
|
35
|
-
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
36
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
36
37
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,22 +1,20 @@
|
|
1
1
|
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Context } from './context';
|
3
4
|
import type { Lazyable } from './lazy';
|
4
5
|
import type { Procedure } from './procedure';
|
5
|
-
import type { Context, Meta } from './types';
|
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
7
|
/**
|
8
8
|
* Options for creating a procedure caller with comprehensive type safety
|
9
9
|
*/
|
10
|
-
export type CreateProcedureClientOptions<
|
10
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
|
11
11
|
/**
|
12
12
|
* This is helpful for logging and analytics.
|
13
13
|
*/
|
14
14
|
path?: string[];
|
15
15
|
} & ({
|
16
|
-
context: Value<
|
17
|
-
} | (
|
18
|
-
|
19
|
-
|
20
|
-
export type CreateProcedureClientRest<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TContext, TOutputSchema, THandlerOutput, TClientContext>] | (undefined extends TContext ? [] : never);
|
21
|
-
export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, ...[options]: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
|
+
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>;
|
22
20
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -1,25 +1,21 @@
|
|
1
|
-
import type { ClientRest, ErrorMap,
|
2
|
-
import type {
|
1
|
+
import type { ClientRest, ErrorMap, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
4
|
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
-
import type { Context, MergeContext } from './types';
|
6
5
|
import { Procedure } from './procedure';
|
7
|
-
export declare class DecoratedProcedure<
|
8
|
-
|
9
|
-
|
10
|
-
route(route:
|
11
|
-
|
12
|
-
use<
|
13
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
|
-
unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
|
-
unshiftMiddleware(...middlewares: Middleware<TContext, Context & Partial<MergeContext<TContext, TExtraContext>> | undefined, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
6
|
+
export declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
|
7
|
+
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, MergedErrorMap<TErrorMap, U>, TMeta>;
|
8
|
+
meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
9
|
+
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
10
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
11
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
16
12
|
/**
|
17
13
|
* Make this procedure callable (works like a function while still being a procedure).
|
18
14
|
*/
|
19
|
-
callable<TClientContext>(...rest: CreateProcedureClientRest<
|
15
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
16
|
/**
|
21
17
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
22
18
|
*/
|
23
|
-
actionable<TClientContext>(...rest: CreateProcedureClientRest<
|
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>>);
|
24
20
|
}
|
25
21
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
2
3
|
import type { Lazyable } from './lazy';
|
3
4
|
import type { Procedure } from './procedure';
|
4
|
-
import type { Context } from './types';
|
5
5
|
import { type CreateProcedureClientRest } from './procedure-client';
|
6
6
|
/**
|
7
7
|
* Directly call a procedure without creating a client.
|
@@ -13,5 +13,5 @@ import { type CreateProcedureClientRest } from './procedure-client';
|
|
13
13
|
* ```
|
14
14
|
*
|
15
15
|
*/
|
16
|
-
export declare function call<
|
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>>;
|
17
17
|
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,44 +1,29 @@
|
|
1
|
-
import type {
|
1
|
+
import type { AbortSignal, ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
7
|
-
export interface ProcedureHandlerOptions<TContext extends Context, TExtraContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
8
|
-
context: MergeContext<TContext, TExtraContext>;
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
4
|
+
import type { AnyMiddleware } from './middleware';
|
5
|
+
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
6
|
+
context: TCurrentContext;
|
9
7
|
input: TInput;
|
10
8
|
path: string[];
|
11
|
-
procedure:
|
9
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
12
10
|
signal?: AbortSignal;
|
13
11
|
errors: TErrorConstructorMap;
|
14
12
|
}
|
15
|
-
export interface ProcedureHandler<
|
16
|
-
(opt: ProcedureHandlerOptions<
|
13
|
+
export interface ProcedureHandler<TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
14
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
17
15
|
}
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
* To avoid these issues, `any` is used as a workaround.
|
25
|
-
*
|
26
|
-
* This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
|
27
|
-
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
|
-
*/
|
29
|
-
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
30
|
-
preMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
|
31
|
-
postMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, Record<never, never>>[];
|
32
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
33
|
-
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
16
|
+
export interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
17
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
18
|
+
middlewares: AnyMiddleware[];
|
19
|
+
inputValidationIndex: number;
|
20
|
+
outputValidationIndex: number;
|
21
|
+
handler: ProcedureHandler<TCurrentContext, any, any, THandlerOutput, any, any>;
|
34
22
|
}
|
35
|
-
export declare class Procedure<
|
36
|
-
'~
|
37
|
-
|
38
|
-
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
23
|
+
export declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
24
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
25
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
39
26
|
}
|
40
|
-
export type
|
41
|
-
export
|
42
|
-
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
43
|
-
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
27
|
+
export type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
28
|
+
export declare function isProcedure(item: unknown): item is AnyProcedure;
|
44
29
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Lazy } from './lazy';
|
2
|
+
import type { AnyProcedure } from './procedure';
|
3
|
+
import type { AnyRouter } from './router';
|
4
|
+
export type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
5
|
+
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
6
|
+
});
|
7
|
+
export declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
8
|
+
//# sourceMappingURL=router-accessible-lazy.d.ts.map
|
@@ -2,15 +2,11 @@ import type { Hooks, Value } from '@orpc/shared';
|
|
2
2
|
import type { Lazy } from './lazy';
|
3
3
|
import type { Procedure } from './procedure';
|
4
4
|
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
-
import type {
|
6
|
-
|
7
|
-
|
8
|
-
* FIXME: separate RouterClient and ContractRouterClient, don't mix them
|
9
|
-
*/
|
10
|
-
export type RouterClient<TRouter extends ANY_ROUTER, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
11
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
|
5
|
+
import type { AnyRouter, Router } from './router';
|
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
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
12
8
|
};
|
13
|
-
export type CreateRouterClientOptions<TRouter extends
|
9
|
+
export type CreateRouterClientOptions<TRouter extends AnyRouter> = {
|
14
10
|
/**
|
15
11
|
* This is helpful for logging and analytics.
|
16
12
|
*
|
@@ -21,6 +17,6 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
|
21
17
|
context?: Value<UContext>;
|
22
18
|
} : {
|
23
19
|
context: Value<UContext>;
|
24
|
-
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never,
|
25
|
-
export declare function createRouterClient<TRouter extends
|
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>;
|
26
22
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,16 +1,29 @@
|
|
1
|
-
import type { ContractProcedure,
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ErrorMap, HTTPPath, MergedErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
3
|
+
import type { Lazy, Lazyable } from './lazy';
|
4
|
+
import type { AnyMiddleware } from './middleware';
|
5
|
+
import type { AnyProcedure } from './procedure';
|
6
|
+
import { Procedure } from './procedure';
|
7
|
+
import { type AccessibleLazyRouter } from './router-accessible-lazy';
|
8
|
+
export type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
|
9
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
7
10
|
}>;
|
8
|
-
export type
|
9
|
-
export type InferRouterInputs<T extends
|
10
|
-
[K in keyof T]: T[K] extends
|
11
|
+
export type AnyRouter = Router<any, any>;
|
12
|
+
export type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
13
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
11
14
|
};
|
12
|
-
export type InferRouterOutputs<T extends
|
13
|
-
[K in keyof T]: T[K] extends
|
15
|
+
export type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
16
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
14
17
|
};
|
15
|
-
export
|
18
|
+
export type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
19
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
20
|
+
};
|
21
|
+
export interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
22
|
+
middlewares: AnyMiddleware[];
|
23
|
+
tags?: readonly string[];
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
errorMap: TErrorMap;
|
26
|
+
}
|
27
|
+
export declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
28
|
+
export declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
|
16
29
|
//# sourceMappingURL=router.d.ts.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.
|
4
|
+
"version": "0.0.0-next.f56d2b3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -53,8 +53,8 @@
|
|
53
53
|
"next": ">=14.0.0"
|
54
54
|
},
|
55
55
|
"dependencies": {
|
56
|
-
"@orpc/contract": "0.0.0-next.
|
57
|
-
"@orpc/shared": "0.0.0-next.
|
56
|
+
"@orpc/contract": "0.0.0-next.f56d2b3",
|
57
|
+
"@orpc/shared": "0.0.0-next.f56d2b3"
|
58
58
|
},
|
59
59
|
"scripts": {
|
60
60
|
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
package/dist/chunk-SA7HGGVY.js
DELETED
@@ -1,242 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __export = (target, all) => {
|
3
|
-
for (var name in all)
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
-
};
|
6
|
-
|
7
|
-
// src/utils.ts
|
8
|
-
function mergeContext(a, b) {
|
9
|
-
if (!a)
|
10
|
-
return b;
|
11
|
-
if (!b)
|
12
|
-
return a;
|
13
|
-
return {
|
14
|
-
...a,
|
15
|
-
...b
|
16
|
-
};
|
17
|
-
}
|
18
|
-
|
19
|
-
// src/procedure.ts
|
20
|
-
import { isContractProcedure } from "@orpc/contract";
|
21
|
-
var Procedure = class {
|
22
|
-
"~type" = "Procedure";
|
23
|
-
"~orpc";
|
24
|
-
constructor(def) {
|
25
|
-
this["~orpc"] = def;
|
26
|
-
}
|
27
|
-
};
|
28
|
-
function isProcedure(item) {
|
29
|
-
if (item instanceof Procedure) {
|
30
|
-
return true;
|
31
|
-
}
|
32
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
33
|
-
}
|
34
|
-
|
35
|
-
// src/error.ts
|
36
|
-
import { ORPCError } from "@orpc/contract";
|
37
|
-
function createORPCErrorConstructorMap(errors) {
|
38
|
-
const constructors = {};
|
39
|
-
for (const code in errors) {
|
40
|
-
const config = errors[code];
|
41
|
-
if (!config) {
|
42
|
-
continue;
|
43
|
-
}
|
44
|
-
const constructor = (...[options]) => {
|
45
|
-
return new ORPCError({
|
46
|
-
code,
|
47
|
-
defined: true,
|
48
|
-
status: config.status,
|
49
|
-
message: options?.message ?? config.message,
|
50
|
-
data: options?.data,
|
51
|
-
cause: options?.cause
|
52
|
-
});
|
53
|
-
};
|
54
|
-
constructors[code] = constructor;
|
55
|
-
}
|
56
|
-
return constructors;
|
57
|
-
}
|
58
|
-
|
59
|
-
// src/lazy.ts
|
60
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
61
|
-
function lazy(loader) {
|
62
|
-
return {
|
63
|
-
[LAZY_LOADER_SYMBOL]: loader
|
64
|
-
};
|
65
|
-
}
|
66
|
-
function isLazy(item) {
|
67
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
68
|
-
}
|
69
|
-
function unlazy(lazied) {
|
70
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
71
|
-
}
|
72
|
-
function flatLazy(lazied) {
|
73
|
-
const flattenLoader = async () => {
|
74
|
-
let current = await unlazy(lazied);
|
75
|
-
while (true) {
|
76
|
-
if (!isLazy(current.default)) {
|
77
|
-
break;
|
78
|
-
}
|
79
|
-
current = await unlazy(current.default);
|
80
|
-
}
|
81
|
-
return current;
|
82
|
-
};
|
83
|
-
return lazy(flattenLoader);
|
84
|
-
}
|
85
|
-
|
86
|
-
// src/middleware.ts
|
87
|
-
function middlewareOutputFn(output) {
|
88
|
-
return { output, context: void 0 };
|
89
|
-
}
|
90
|
-
|
91
|
-
// src/procedure-client.ts
|
92
|
-
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
93
|
-
import { executeWithHooks, toError, value } from "@orpc/shared";
|
94
|
-
function createProcedureClient(lazyableProcedure, ...[options]) {
|
95
|
-
return async (...[input, callerOptions]) => {
|
96
|
-
const path = options?.path ?? [];
|
97
|
-
const { default: procedure } = await unlazy(lazyableProcedure);
|
98
|
-
const context = await value(options?.context, callerOptions?.context);
|
99
|
-
const errors = createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap);
|
100
|
-
const executeOptions = {
|
101
|
-
input,
|
102
|
-
context,
|
103
|
-
errors,
|
104
|
-
path,
|
105
|
-
procedure,
|
106
|
-
signal: callerOptions?.signal
|
107
|
-
};
|
108
|
-
try {
|
109
|
-
const output = await executeWithHooks({
|
110
|
-
hooks: options,
|
111
|
-
input,
|
112
|
-
context,
|
113
|
-
meta: executeOptions,
|
114
|
-
execute: () => executeProcedureInternal(procedure, executeOptions)
|
115
|
-
});
|
116
|
-
return output;
|
117
|
-
} catch (e) {
|
118
|
-
if (!(e instanceof ORPCError2)) {
|
119
|
-
throw toError(e);
|
120
|
-
}
|
121
|
-
const validated = await validateORPCError(procedure["~orpc"].contract["~orpc"].errorMap, e);
|
122
|
-
throw validated;
|
123
|
-
}
|
124
|
-
};
|
125
|
-
}
|
126
|
-
async function validateInput(procedure, input) {
|
127
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
128
|
-
if (!schema)
|
129
|
-
return input;
|
130
|
-
const result = await schema["~standard"].validate(input);
|
131
|
-
if (result.issues) {
|
132
|
-
throw new ORPCError2({
|
133
|
-
message: "Input validation failed",
|
134
|
-
code: "BAD_REQUEST",
|
135
|
-
data: {
|
136
|
-
issues: result.issues
|
137
|
-
},
|
138
|
-
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
139
|
-
});
|
140
|
-
}
|
141
|
-
return result.value;
|
142
|
-
}
|
143
|
-
async function validateOutput(procedure, output) {
|
144
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
145
|
-
if (!schema)
|
146
|
-
return output;
|
147
|
-
const result = await schema["~standard"].validate(output);
|
148
|
-
if (result.issues) {
|
149
|
-
throw new ORPCError2({
|
150
|
-
message: "Output validation failed",
|
151
|
-
code: "INTERNAL_SERVER_ERROR",
|
152
|
-
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
153
|
-
});
|
154
|
-
}
|
155
|
-
return result.value;
|
156
|
-
}
|
157
|
-
function executeMiddlewareChain(middlewares, opt, input) {
|
158
|
-
let currentIndex = 0;
|
159
|
-
let currentContext = opt.context;
|
160
|
-
const executeMiddlewareChain2 = async (nextOptions) => {
|
161
|
-
const mid = middlewares[currentIndex];
|
162
|
-
currentIndex += 1;
|
163
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
164
|
-
if (mid) {
|
165
|
-
return await mid({ ...opt, context: currentContext, next: executeMiddlewareChain2 }, input, middlewareOutputFn);
|
166
|
-
}
|
167
|
-
return opt.next({ context: currentContext });
|
168
|
-
};
|
169
|
-
return executeMiddlewareChain2({});
|
170
|
-
}
|
171
|
-
async function executeProcedureInternal(procedure, options) {
|
172
|
-
const executeHandler = async (context, input) => {
|
173
|
-
return await procedure["~orpc"].handler({ ...options, context, input });
|
174
|
-
};
|
175
|
-
const executePostMiddlewares = async (context, input) => {
|
176
|
-
const validatedInput = await validateInput(procedure, input);
|
177
|
-
const result2 = await executeMiddlewareChain(procedure["~orpc"].postMiddlewares, {
|
178
|
-
...options,
|
179
|
-
context,
|
180
|
-
next: async ({ context: context2 }) => {
|
181
|
-
return middlewareOutputFn(
|
182
|
-
await executeHandler(context2, validatedInput)
|
183
|
-
);
|
184
|
-
}
|
185
|
-
}, validatedInput);
|
186
|
-
const validatedOutput = await validateOutput(procedure, result2.output);
|
187
|
-
return { ...result2, output: validatedOutput };
|
188
|
-
};
|
189
|
-
const result = await executeMiddlewareChain(procedure["~orpc"].preMiddlewares, {
|
190
|
-
...options,
|
191
|
-
context: options.context,
|
192
|
-
next: ({ context }) => executePostMiddlewares(context, options.input)
|
193
|
-
}, options.input);
|
194
|
-
return result.output;
|
195
|
-
}
|
196
|
-
|
197
|
-
// src/router.ts
|
198
|
-
function getRouterChild(router, ...path) {
|
199
|
-
let current = router;
|
200
|
-
for (let i = 0; i < path.length; i++) {
|
201
|
-
const segment = path[i];
|
202
|
-
if (!current) {
|
203
|
-
return void 0;
|
204
|
-
}
|
205
|
-
if (isProcedure(current)) {
|
206
|
-
return void 0;
|
207
|
-
}
|
208
|
-
if (!isLazy(current)) {
|
209
|
-
current = current[segment];
|
210
|
-
continue;
|
211
|
-
}
|
212
|
-
const lazied = current;
|
213
|
-
const rest = path.slice(i);
|
214
|
-
const newLazy = lazy(async () => {
|
215
|
-
const unwrapped = await unlazy(lazied);
|
216
|
-
if (!unwrapped.default) {
|
217
|
-
return unwrapped;
|
218
|
-
}
|
219
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
220
|
-
return { default: next };
|
221
|
-
});
|
222
|
-
return flatLazy(newLazy);
|
223
|
-
}
|
224
|
-
return current;
|
225
|
-
}
|
226
|
-
|
227
|
-
export {
|
228
|
-
__export,
|
229
|
-
mergeContext,
|
230
|
-
Procedure,
|
231
|
-
isProcedure,
|
232
|
-
createORPCErrorConstructorMap,
|
233
|
-
LAZY_LOADER_SYMBOL,
|
234
|
-
lazy,
|
235
|
-
isLazy,
|
236
|
-
unlazy,
|
237
|
-
flatLazy,
|
238
|
-
middlewareOutputFn,
|
239
|
-
createProcedureClient,
|
240
|
-
getRouterChild
|
241
|
-
};
|
242
|
-
//# sourceMappingURL=chunk-SA7HGGVY.js.map
|
package/dist/src/error.d.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { ErrorMap, ErrorMapItem, ORPCErrorOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import { ORPCError } from '@orpc/contract';
|
3
|
-
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
|
4
|
-
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
5
|
-
export type ORPCErrorConstructorMapItem<TCode extends string, TDataSchema extends Schema> = (...rest: ORPCErrorConstructorMapItemRest<SchemaInput<TDataSchema>>) => ORPCError<TCode, SchemaOutput<TDataSchema>>;
|
6
|
-
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
7
|
-
[K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
|
8
|
-
};
|
9
|
-
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
10
|
-
//# sourceMappingURL=error.d.ts.map
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { Middleware } from './middleware';
|
2
|
-
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
3
|
-
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
|
-
import { ProcedureImplementer } from './procedure-implementer';
|
5
|
-
import { RouterImplementer } from './router-implementer';
|
6
|
-
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter<any>> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
7
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter<any> ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
8
|
-
} & Omit<RouterImplementer<TContext, TExtraContext, TContract>, '~type' | '~orpc'>;
|
9
|
-
export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter<any> = any>(contract: TContract, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[]): ChainableImplementer<TContext, TExtraContext, TContract>;
|
10
|
-
//# sourceMappingURL=implementer-chainable.d.ts.map
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import type { Lazy } from './lazy';
|
2
|
-
import { type ANY_ROUTER } from './router';
|
3
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
|
4
|
-
[K in keyof T]: DecoratedLazy<T[K]>;
|
5
|
-
} : unknown);
|
6
|
-
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
7
|
-
//# sourceMappingURL=lazy-decorated.d.ts.map
|