@orpc/server 0.0.0-next.4220427 → 0.0.0-next.43889a7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-V3I7RIRY.js → chunk-26GHKV43.js} +6 -7
- package/dist/{chunk-DNG2IB3R.js → chunk-LDIL7OEP.js} +40 -50
- package/dist/fetch.js +4 -4
- package/dist/hono.js +5 -5
- package/dist/index.js +687 -181
- package/dist/next.js +5 -5
- package/dist/node.js +10 -10
- package/dist/src/adapters/fetch/orpc-handler.d.ts +4 -4
- package/dist/src/adapters/fetch/types.d.ts +3 -3
- package/dist/src/adapters/hono/middleware.d.ts +3 -3
- package/dist/src/adapters/next/serve.d.ts +3 -3
- package/dist/src/adapters/node/orpc-handler.d.ts +5 -5
- package/dist/src/adapters/node/types.d.ts +3 -3
- package/dist/src/builder-with-errors-middlewares.d.ts +49 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +49 -0
- package/dist/src/builder.d.ts +33 -23
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +10 -0
- package/dist/src/error.d.ts +1 -1
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +11 -5
- package/dist/src/index.d.ts +5 -4
- package/dist/src/lazy-decorated.d.ts +4 -6
- package/dist/src/middleware-decorated.d.ts +5 -5
- package/dist/src/middleware.d.ts +19 -15
- package/dist/src/procedure-builder-with-input.d.ts +35 -0
- package/dist/src/procedure-builder-with-output.d.ts +34 -0
- package/dist/src/procedure-builder.d.ts +23 -19
- package/dist/src/procedure-client.d.ts +8 -21
- package/dist/src/procedure-decorated.d.ts +21 -11
- package/dist/src/procedure-implementer.d.ts +14 -10
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +16 -12
- package/dist/src/router-builder.d.ts +20 -16
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +12 -10
- package/dist/src/router.d.ts +4 -4
- package/dist/src/types.d.ts +0 -3
- package/package.json +3 -3
- package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
8
|
+
export interface ProcedureBuilderWithInputDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
10
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
11
|
+
contract: ContractProcedure<TInputSchema, undefined, TErrorMap>;
|
12
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
13
|
+
inputValidationIndex: number;
|
14
|
+
outputValidationIndex: number;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* `ProcedureBuilderWithInput` is a branch of `ProcedureBuilder` which it has input schema.
|
18
|
+
*
|
19
|
+
* Why?
|
20
|
+
* - prevents override input schema after .input
|
21
|
+
* - allows .use between .input and .output
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export declare class ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
|
25
|
+
'~type': "ProcedureBuilderWithInput";
|
26
|
+
'~orpc': ProcedureBuilderWithInputDef<TInitialContext, TCurrentContext, TInputSchema, TErrorMap>;
|
27
|
+
constructor(def: ProcedureBuilderWithInputDef<TInitialContext, TCurrentContext, TInputSchema, TErrorMap>);
|
28
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TErrorMap & U>;
|
29
|
+
route(route: RouteOptions): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TErrorMap>;
|
30
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureBuilderWithInput<TInitialContext, TCurrentContext & U, TInputSchema, TErrorMap>;
|
31
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<TCurrentContext & UOutContext> & ProcedureBuilderWithInput<TInitialContext, TCurrentContext & UOutContext, TInputSchema, TErrorMap>;
|
32
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureImplementer<TInitialContext, TCurrentContext, TInputSchema, U, TErrorMap>;
|
33
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, TInputSchema, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, undefined, UFuncOutput, TErrorMap>;
|
34
|
+
}
|
35
|
+
//# sourceMappingURL=procedure-builder-with-input.d.ts.map
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaInput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
8
|
+
export interface ProcedureBuilderWithOutputDef<TInitialContext extends Context, TCurrentContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
10
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
11
|
+
contract: ContractProcedure<undefined, TOutputSchema, TErrorMap>;
|
12
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
13
|
+
inputValidationIndex: number;
|
14
|
+
outputValidationIndex: number;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* `ProcedureBuilderWithOutput` is a branch of `ProcedureBuilder` which it has output schema.
|
18
|
+
*
|
19
|
+
* Why?
|
20
|
+
* - prevents override output schema after .output
|
21
|
+
* - allows .use between .input and .output
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export declare class ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
25
|
+
'~type': "ProcedureBuilderWithOutput";
|
26
|
+
'~orpc': ProcedureBuilderWithOutputDef<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap>;
|
27
|
+
constructor(def: ProcedureBuilderWithOutputDef<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap>);
|
28
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap & U>;
|
29
|
+
route(route: RouteOptions): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap>;
|
30
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureBuilderWithOutput<TInitialContext, TCurrentContext & U, TOutputSchema, TErrorMap>;
|
31
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureImplementer<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap>;
|
32
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>;
|
33
|
+
}
|
34
|
+
//# sourceMappingURL=procedure-builder-with-output.d.ts.map
|
@@ -1,24 +1,28 @@
|
|
1
|
-
import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
3
|
import type { ORPCErrorConstructorMap } from './error';
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
export interface ProcedureBuilderDef<
|
9
|
-
|
10
|
-
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
7
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
8
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
9
|
+
export interface ProcedureBuilderDef<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
10
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
11
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
12
|
+
contract: ContractProcedure<undefined, undefined, TErrorMap>;
|
13
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
14
|
+
inputValidationIndex: number;
|
15
|
+
outputValidationIndex: number;
|
11
16
|
}
|
12
|
-
export declare class ProcedureBuilder<
|
17
|
+
export declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
13
18
|
'~type': "ProcedureBuilder";
|
14
|
-
'~orpc': ProcedureBuilderDef<
|
15
|
-
constructor(def: ProcedureBuilderDef<
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
19
|
+
'~orpc': ProcedureBuilderDef<TInitialContext, TCurrentContext, TErrorMap>;
|
20
|
+
constructor(def: ProcedureBuilderDef<TInitialContext, TCurrentContext, TErrorMap>);
|
21
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TErrorMap & U>;
|
22
|
+
route(route: RouteOptions): ProcedureBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
23
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureBuilder<TInitialContext, TCurrentContext & U, TErrorMap>;
|
24
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, U, TErrorMap>;
|
25
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, U, TErrorMap>;
|
26
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, undefined, undefined, UFuncOutput, TErrorMap>;
|
23
27
|
}
|
24
28
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,34 +1,21 @@
|
|
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 {
|
6
|
-
export type
|
7
|
-
signal?: AbortSignal;
|
8
|
-
} & (undefined extends TClientContext ? {
|
9
|
-
context?: TClientContext;
|
10
|
-
} : {
|
11
|
-
context: TClientContext;
|
12
|
-
});
|
13
|
-
export type ProcedureClient<TClientContext, TInput, TOutput, TError extends Error> = Client<TClientContext, TInput, TOutput, TError>;
|
6
|
+
import type { Meta } from './types';
|
7
|
+
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>>;
|
14
8
|
/**
|
15
9
|
* Options for creating a procedure caller with comprehensive type safety
|
16
10
|
*/
|
17
|
-
export type CreateProcedureClientOptions<
|
18
|
-
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>;
|
11
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
|
19
12
|
/**
|
20
13
|
* This is helpful for logging and analytics.
|
21
|
-
*
|
22
|
-
* @internal
|
23
14
|
*/
|
24
15
|
path?: string[];
|
25
16
|
} & ({
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
} | (undefined extends TContext ? {
|
31
|
-
context?: undefined;
|
32
|
-
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
33
|
-
export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(options: CreateProcedureClientOptions<TContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>): ProcedureClient<unknown, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
18
|
+
} | (Record<never, never> extends TInitialContext ? Record<never, never> : never)) & Hooks<unknown, SchemaOutput<TCurrentContext, THandlerOutput>, TInitialContext, Meta>;
|
19
|
+
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);
|
20
|
+
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>>, ...[options]: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
34
21
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -1,15 +1,25 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ClientRest, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context } from './context';
|
2
3
|
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
-
import type { ProcedureClient } from './procedure-client';
|
5
|
-
import type { Context, MergeContext } from './types';
|
5
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
6
6
|
import { Procedure } from './procedure';
|
7
|
-
export
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
export declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> {
|
8
|
+
static decorate<UInitialContext extends Context, UCurrentContext extends Context, UInputSchema extends Schema, UOutputSchema extends Schema, UHandlerOutput extends SchemaInput<UOutputSchema>, UErrorMap extends ErrorMap>(procedure: Procedure<UInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>): DecoratedProcedure<any, any, any, any, any, any> | DecoratedProcedure<UInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>;
|
9
|
+
prefix(prefix: HTTPPath): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
10
|
+
route(route: RouteOptions): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
11
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap & U>;
|
12
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & DecoratedProcedure<TInitialContext, TCurrentContext & U, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
13
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): ConflictContextGuard<TCurrentContext & UOutContext> & DecoratedProcedure<TInitialContext, TCurrentContext & UOutContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
|
+
unshiftTag(...tags: string[]): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
|
+
unshiftMiddleware<U extends Context>(...middlewares: Middleware<TInitialContext, U, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): ConflictContextGuard<TInitialContext & U> & DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
|
+
/**
|
17
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
18
|
+
*/
|
19
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
|
+
/**
|
21
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
22
|
+
*/
|
23
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
24
|
+
}
|
15
25
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,19 +1,23 @@
|
|
1
1
|
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
3
|
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
5
|
import type { ProcedureHandler } from './procedure';
|
5
|
-
import
|
6
|
-
|
7
|
-
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
export type ProcedureImplementerDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
9
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
8
10
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
-
middlewares
|
11
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
12
|
+
inputValidationIndex: number;
|
13
|
+
outputValidationIndex: number;
|
10
14
|
};
|
11
|
-
export declare class ProcedureImplementer<
|
15
|
+
export declare class ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
12
16
|
'~type': "ProcedureImplementer";
|
13
|
-
'~orpc': ProcedureImplementerDef<
|
14
|
-
constructor(def: ProcedureImplementerDef<
|
15
|
-
use<U extends Context
|
16
|
-
use<
|
17
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<
|
17
|
+
'~orpc': ProcedureImplementerDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap>;
|
18
|
+
constructor(def: ProcedureImplementerDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap>);
|
19
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureImplementer<TInitialContext, TCurrentContext & U, TInputSchema, TOutputSchema, TErrorMap>;
|
20
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<TCurrentContext & UOutContext> & ProcedureImplementer<TInitialContext, TCurrentContext & UOutContext, TInputSchema, TOutputSchema, TErrorMap>;
|
21
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
18
22
|
}
|
19
23
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
3
|
+
import type { Lazyable } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
import { type CreateProcedureClientRest } from './procedure-client';
|
6
|
+
/**
|
7
|
+
* Directly call a procedure without creating a client.
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* const output = await call(getting, 'input')
|
12
|
+
* const output = await call(getting, 'input', { context: { db: 'postgres' } })
|
13
|
+
* ```
|
14
|
+
*
|
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>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
3
4
|
import type { ORPCErrorConstructorMap } from './error';
|
4
5
|
import type { Lazy } from './lazy';
|
5
6
|
import type { Middleware } from './middleware';
|
6
|
-
import type { AbortSignal
|
7
|
-
export interface ProcedureHandlerOptions<
|
8
|
-
context:
|
7
|
+
import type { AbortSignal } from './types';
|
8
|
+
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
9
|
+
context: TCurrentContext;
|
9
10
|
input: TInput;
|
10
11
|
path: string[];
|
11
12
|
procedure: ANY_PROCEDURE;
|
12
13
|
signal?: AbortSignal;
|
13
14
|
errors: TErrorConstructorMap;
|
14
15
|
}
|
15
|
-
export interface ProcedureHandler<
|
16
|
-
(opt: ProcedureHandlerOptions<
|
16
|
+
export interface ProcedureHandler<TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
17
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
17
18
|
}
|
18
19
|
/**
|
19
|
-
* Why is `ErrorConstructorMap` passed to `
|
20
|
+
* Why is `ErrorConstructorMap` passed to `middlewares` as `any`?
|
20
21
|
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
22
|
*
|
22
23
|
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
@@ -26,15 +27,18 @@ export interface ProcedureHandler<TContext extends Context, TExtraContext extend
|
|
26
27
|
* This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
|
27
28
|
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
29
|
*/
|
29
|
-
export interface ProcedureDef<
|
30
|
-
|
30
|
+
export interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
31
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
32
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
33
|
+
inputValidationIndex: number;
|
34
|
+
outputValidationIndex: number;
|
31
35
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
32
|
-
handler: ProcedureHandler<
|
36
|
+
handler: ProcedureHandler<TCurrentContext, any, any, THandlerOutput, any>;
|
33
37
|
}
|
34
|
-
export declare class Procedure<
|
38
|
+
export declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
35
39
|
'~type': "Procedure";
|
36
|
-
'~orpc': ProcedureDef<
|
37
|
-
constructor(def: ProcedureDef<
|
40
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
41
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
38
42
|
}
|
39
43
|
export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any>;
|
40
44
|
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any>;
|
@@ -1,29 +1,33 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
3
|
import type { FlattenLazy, Lazy } from './lazy';
|
3
4
|
import type { Middleware } from './middleware';
|
4
5
|
import type { Procedure } from './procedure';
|
5
6
|
import type { ANY_ROUTER, Router } from './router';
|
6
|
-
import type { Context, MergeContext } from './types';
|
7
7
|
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
-
import {
|
9
|
-
export type AdaptedRouter<
|
10
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<
|
8
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
9
|
+
export type AdaptedRouter<TInitialContext extends Context, TRouter extends ANY_ROUTER, TErrorMapExtra extends ErrorMap> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TInitialContext, U, TErrorMapExtra>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap & TErrorMapExtra> : {
|
10
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TInitialContext, TRouter[K], TErrorMapExtra> : never;
|
11
11
|
};
|
12
|
-
export type RouterBuilderDef<
|
12
|
+
export type RouterBuilderDef<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = {
|
13
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
14
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
13
15
|
prefix?: HTTPPath;
|
14
16
|
tags?: readonly string[];
|
15
|
-
middlewares
|
17
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
18
|
+
errorMap: TErrorMap;
|
16
19
|
};
|
17
|
-
export declare class RouterBuilder<
|
20
|
+
export declare class RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
18
21
|
'~type': "RouterBuilder";
|
19
|
-
'~orpc': RouterBuilderDef<
|
20
|
-
constructor(def: RouterBuilderDef<
|
21
|
-
prefix(prefix: HTTPPath): RouterBuilder<
|
22
|
-
tag(...tags: string[]): RouterBuilder<
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
'~orpc': RouterBuilderDef<TInitialContext, TCurrentContext, TErrorMap>;
|
23
|
+
constructor(def: RouterBuilderDef<TInitialContext, TCurrentContext, TErrorMap>);
|
24
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
25
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
26
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap & U>;
|
27
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, Record<never, never>>): ConflictContextGuard<TCurrentContext & U> & RouterBuilder<TInitialContext, TCurrentContext & U, TErrorMap>;
|
28
|
+
router<U extends Router<TCurrentContext, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TInitialContext, U, TErrorMap>;
|
29
|
+
lazy<U extends Router<TCurrentContext, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
26
30
|
default: U;
|
27
|
-
}>): AdaptedRouter<
|
31
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, TErrorMap>;
|
28
32
|
}
|
29
33
|
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -1,15 +1,16 @@
|
|
1
|
-
import type { ContractProcedure, ContractRouter, ErrorFromErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Hooks, Value } from '@orpc/shared';
|
3
2
|
import type { Lazy } from './lazy';
|
4
3
|
import type { Procedure } from './procedure';
|
5
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
6
5
|
import type { Meta } from './types';
|
7
6
|
import { type ANY_ROUTER, type Router } from './router';
|
8
|
-
|
9
|
-
|
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;
|
10
12
|
};
|
11
13
|
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
12
|
-
router: TRouter | Lazy<undefined>;
|
13
14
|
/**
|
14
15
|
* This is helpful for logging and analytics.
|
15
16
|
*
|
@@ -21,5 +22,5 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
|
21
22
|
} : {
|
22
23
|
context: Value<UContext>;
|
23
24
|
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
24
|
-
export declare function createRouterClient<TRouter extends ANY_ROUTER>(
|
25
|
+
export declare function createRouterClient<TRouter extends ANY_ROUTER, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
25
26
|
//# sourceMappingURL=router-client.d.ts.map
|
@@ -1,21 +1,23 @@
|
|
1
1
|
import type { ContractRouter } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
3
|
import type { FlattenLazy } from './lazy';
|
3
4
|
import type { Middleware } from './middleware';
|
4
5
|
import type { Router } from './router';
|
5
6
|
import type { AdaptedRouter } from './router-builder';
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
export interface RouterImplementerDef<TInitialContext extends Context, TCurrentContext extends Context, TContract extends ContractRouter<any>> {
|
8
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
9
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
10
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
9
11
|
contract: TContract;
|
10
12
|
}
|
11
|
-
export declare class RouterImplementer<
|
13
|
+
export declare class RouterImplementer<TInitialContext extends Context, TCurrentContext extends Context, TContract extends ContractRouter<any>> {
|
12
14
|
'~type': "RouterImplementer";
|
13
|
-
'~orpc': RouterImplementerDef<
|
14
|
-
constructor(def: RouterImplementerDef<
|
15
|
-
use<U extends Context
|
16
|
-
router<U extends Router<
|
17
|
-
lazy<U extends Router<
|
15
|
+
'~orpc': RouterImplementerDef<TInitialContext, TCurrentContext, TContract>;
|
16
|
+
constructor(def: RouterImplementerDef<TInitialContext, TCurrentContext, TContract>);
|
17
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, Record<never, never>>): ConflictContextGuard<TCurrentContext & U> & RouterImplementer<TInitialContext, TCurrentContext & U, TContract>;
|
18
|
+
router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<TInitialContext, U, Record<never, never>>;
|
19
|
+
lazy<U extends Router<TCurrentContext, TContract>>(loader: () => Promise<{
|
18
20
|
default: U;
|
19
|
-
}>): AdaptedRouter<
|
21
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, Record<never, never>>;
|
20
22
|
}
|
21
23
|
//# sourceMappingURL=router-implementer.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
2
3
|
import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
|
3
4
|
import type { ANY_PROCEDURE, Procedure } from './procedure';
|
4
|
-
|
5
|
-
|
6
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter ? Router<TContext, TContract[K]> : never;
|
5
|
+
export type Router<TInitialContext extends Context, TContract extends ContractRouter<any>> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap> : {
|
6
|
+
[K in keyof TContract]: TContract[K] extends ContractRouter<any> ? Router<TInitialContext, TContract[K]> : never;
|
7
7
|
}>;
|
8
8
|
export type ANY_ROUTER = Router<any, any>;
|
9
9
|
export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
|
@@ -12,5 +12,5 @@ export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U ext
|
|
12
12
|
export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
13
13
|
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterOutputs<T[K]> : never;
|
14
14
|
};
|
15
|
-
export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE | Record<string, ANY_ROUTER
|
15
|
+
export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER>> | Lazy<undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
|
16
16
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import type { FindGlobalInstanceType } from '@orpc/shared';
|
2
2
|
import type { ANY_PROCEDURE } from './procedure';
|
3
|
-
export type Context = Record<string, any> | undefined;
|
4
|
-
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
5
|
-
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
6
3
|
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
7
4
|
export interface WithSignal {
|
8
5
|
signal?: AbortSignal;
|
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.43889a7",
|
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.43889a7",
|
57
|
+
"@orpc/shared": "0.0.0-next.43889a7"
|
58
58
|
},
|
59
59
|
"scripts": {
|
60
60
|
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
package/dist/src/utils.d.ts
DELETED