@orpc/server 0.28.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-V3I7RIRY.js → chunk-2HRHHZJD.js} +5 -6
- package/dist/{chunk-DNG2IB3R.js → chunk-SA7HGGVY.js} +51 -36
- package/dist/fetch.js +4 -4
- package/dist/hono.js +4 -4
- package/dist/index.js +169 -123
- package/dist/next.js +4 -4
- package/dist/node.js +6 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +3 -3
- package/dist/src/adapters/node/orpc-handler.d.ts +3 -3
- package/dist/src/builder.d.ts +24 -22
- package/dist/src/error.d.ts +1 -1
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/lazy-decorated.d.ts +3 -6
- package/dist/src/middleware.d.ts +1 -0
- package/dist/src/procedure-builder.d.ts +5 -5
- package/dist/src/procedure-client.d.ts +7 -19
- package/dist/src/procedure-decorated.d.ts +22 -10
- package/dist/src/procedure-implementer.d.ts +3 -2
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +3 -2
- package/dist/src/router-builder.d.ts +17 -15
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +6 -6
- package/dist/src/router.d.ts +3 -3
- package/package.json +3 -3
package/dist/src/error.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { ORPCError } from '@orpc/contract';
|
|
3
3
|
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
|
4
4
|
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
5
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> =
|
6
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
7
7
|
[K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
|
8
8
|
};
|
9
9
|
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
package/dist/src/hidden.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
-
export declare function setRouterContract<T extends object>(obj: T, contract: ContractRouter): T;
|
3
|
-
export declare function getRouterContract(obj: object): ContractRouter | undefined;
|
2
|
+
export declare function setRouterContract<T extends object>(obj: T, contract: ContractRouter<any>): T;
|
3
|
+
export declare function getRouterContract(obj: object): ContractRouter<any> | undefined;
|
4
4
|
export declare function deepSetLazyRouterPrefix<T extends object>(router: T, prefix: HTTPPath): T;
|
5
5
|
export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
|
6
6
|
//# sourceMappingURL=hidden.d.ts.map
|
@@ -3,8 +3,8 @@ import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
|
3
3
|
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
4
|
import { ProcedureImplementer } from './procedure-implementer';
|
5
5
|
import { RouterImplementer } from './router-implementer';
|
6
|
-
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter
|
7
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
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
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>(contract: TContract, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<
|
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
10
|
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -13,6 +13,7 @@ export * from './procedure-builder';
|
|
13
13
|
export * from './procedure-client';
|
14
14
|
export * from './procedure-decorated';
|
15
15
|
export * from './procedure-implementer';
|
16
|
+
export * from './procedure-utils';
|
16
17
|
export * from './router';
|
17
18
|
export * from './router-builder';
|
18
19
|
export * from './router-client';
|
@@ -20,5 +21,5 @@ export * from './router-implementer';
|
|
20
21
|
export * from './types';
|
21
22
|
export * from './utils';
|
22
23
|
export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from '@orpc/contract';
|
23
|
-
export declare const os: Builder<WELL_CONTEXT, undefined
|
24
|
+
export declare const os: Builder<WELL_CONTEXT, undefined, Record<never, never>>;
|
24
25
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,10 +1,7 @@
|
|
1
|
-
import type { ErrorFromErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Lazy } from './lazy';
|
3
|
-
import type { Procedure } from './procedure';
|
4
|
-
import type { ProcedureClient } from './procedure-client';
|
5
2
|
import { type ANY_ROUTER } from './router';
|
6
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends
|
7
|
-
[K in keyof T]:
|
8
|
-
});
|
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);
|
9
6
|
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
10
7
|
//# sourceMappingURL=lazy-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -32,4 +32,5 @@ export interface MapInputMiddleware<TInput, TMappedInput> {
|
|
32
32
|
(input: TInput): TMappedInput;
|
33
33
|
}
|
34
34
|
export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
|
35
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
35
36
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,13 +1,13 @@
|
|
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
2
|
import type { ORPCErrorConstructorMap } from './error';
|
3
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
-
import type {
|
4
|
+
import type { ProcedureHandler } from './procedure';
|
5
5
|
import type { Context, MergeContext } from './types';
|
6
|
-
import {
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
7
|
import { ProcedureImplementer } from './procedure-implementer';
|
8
8
|
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
9
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
10
|
-
middlewares
|
10
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
|
11
11
|
}
|
12
12
|
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
13
13
|
'~type': "ProcedureBuilder";
|
@@ -16,7 +16,7 @@ export declare class ProcedureBuilder<TContext extends Context, TExtraContext ex
|
|
16
16
|
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
17
17
|
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
|
18
18
|
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
|
19
|
-
errors<
|
19
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap & U>;
|
20
20
|
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
21
21
|
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
22
22
|
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
@@ -2,33 +2,21 @@ import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOu
|
|
2
2
|
import type { Hooks, Value } from '@orpc/shared';
|
3
3
|
import type { Lazyable } from './lazy';
|
4
4
|
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>;
|
5
|
+
import type { Context, Meta } from './types';
|
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>>;
|
14
7
|
/**
|
15
8
|
* Options for creating a procedure caller with comprehensive type safety
|
16
9
|
*/
|
17
|
-
export type CreateProcedureClientOptions<TContext extends Context,
|
18
|
-
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>;
|
10
|
+
export type CreateProcedureClientOptions<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = {
|
19
11
|
/**
|
20
12
|
* This is helpful for logging and analytics.
|
21
|
-
*
|
22
|
-
* @internal
|
23
13
|
*/
|
24
14
|
path?: string[];
|
25
15
|
} & ({
|
26
|
-
|
27
|
-
* The context used when calling the procedure.
|
28
|
-
*/
|
29
|
-
context: Value<TContext>;
|
16
|
+
context: Value<TContext, [clientContext: TClientContext]>;
|
30
17
|
} | (undefined extends TContext ? {
|
31
|
-
context?:
|
18
|
+
context?: Value<TContext, [clientContext: TClientContext]>;
|
32
19
|
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
33
|
-
export
|
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>;
|
34
22
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -1,15 +1,27 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ClientRest, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { ORPCErrorConstructorMap } from './error';
|
3
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
5
|
import type { Context, MergeContext } from './types';
|
6
6
|
import { Procedure } from './procedure';
|
7
|
-
export
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
export declare class DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> {
|
8
|
+
static decorate<UContext extends Context, UExtraContext extends Context, UInputSchema extends Schema, UOutputSchema extends Schema, UHandlerOutput extends SchemaInput<UOutputSchema>, UErrorMap extends ErrorMap>(procedure: Procedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>): DecoratedProcedure<any, any, any, any, any, any> | DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>;
|
9
|
+
prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
10
|
+
route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
11
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap & U>;
|
12
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
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>;
|
16
|
+
/**
|
17
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
18
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
19
|
+
*/
|
20
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
21
|
+
/**
|
22
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
23
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
24
|
+
*/
|
25
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
26
|
+
}
|
15
27
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -2,11 +2,12 @@ import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } f
|
|
2
2
|
import type { ORPCErrorConstructorMap } from './error';
|
3
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
4
|
import type { ProcedureHandler } from './procedure';
|
5
|
-
import type { DecoratedProcedure } from './procedure-decorated';
|
6
5
|
import type { Context, MergeContext } from './types';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
7
|
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
8
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
-
|
9
|
+
preMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
|
10
|
+
postMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, Record<never, never>>[];
|
10
11
|
};
|
11
12
|
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
12
13
|
'~type': "ProcedureImplementer";
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Lazyable } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { Context } from './types';
|
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<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -16,7 +16,7 @@ export interface ProcedureHandler<TContext extends Context, TExtraContext extend
|
|
16
16
|
(opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
17
17
|
}
|
18
18
|
/**
|
19
|
-
* Why is `ErrorConstructorMap` passed to `
|
19
|
+
* Why is `ErrorConstructorMap` passed to `postMiddlewares` as `Record<never, never>`?
|
20
20
|
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
21
|
*
|
22
22
|
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
@@ -27,7 +27,8 @@ export interface ProcedureHandler<TContext extends Context, TExtraContext extend
|
|
27
27
|
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
28
|
*/
|
29
29
|
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
30
|
-
|
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>>[];
|
31
32
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
32
33
|
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
33
34
|
}
|
@@ -1,29 +1,31 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, StrictErrorMap } from '@orpc/contract';
|
2
2
|
import type { FlattenLazy, Lazy } from './lazy';
|
3
3
|
import type { Middleware } from './middleware';
|
4
4
|
import type { Procedure } from './procedure';
|
5
5
|
import type { ANY_ROUTER, Router } from './router';
|
6
6
|
import type { Context, MergeContext } from './types';
|
7
7
|
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
-
import {
|
9
|
-
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
10
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K]> : never;
|
8
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
9
|
+
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER, TErrorMapExtra extends ErrorMap> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U, TErrorMapExtra>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap & TErrorMapExtra> : {
|
10
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K], TErrorMapExtra> : never;
|
11
11
|
};
|
12
|
-
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context> = {
|
12
|
+
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> = {
|
13
13
|
prefix?: HTTPPath;
|
14
14
|
tags?: readonly string[];
|
15
|
-
middlewares
|
15
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
|
16
|
+
errorMap: TErrorMap;
|
16
17
|
};
|
17
|
-
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
18
|
+
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
18
19
|
'~type': "RouterBuilder";
|
19
|
-
'~orpc': RouterBuilderDef<TContext, TExtraContext>;
|
20
|
-
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
21
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
22
|
-
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
'~orpc': RouterBuilderDef<TContext, TExtraContext, TErrorMap>;
|
21
|
+
constructor(def: RouterBuilderDef<TContext, TExtraContext, TErrorMap>);
|
22
|
+
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, TErrorMap>;
|
23
|
+
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, TErrorMap>;
|
24
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): RouterBuilder<TContext, TExtraContext, TErrorMap & U>;
|
25
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): RouterBuilder<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
|
26
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
|
27
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
26
28
|
default: U;
|
27
|
-
}>): AdaptedRouter<TContext, FlattenLazy<U
|
29
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
|
28
30
|
}
|
29
31
|
//# 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
|
@@ -4,18 +4,18 @@ import type { Middleware } from './middleware';
|
|
4
4
|
import type { Router } from './router';
|
5
5
|
import type { AdaptedRouter } from './router-builder';
|
6
6
|
import type { Context, MergeContext } from './types';
|
7
|
-
export interface RouterImplementerDef<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter
|
8
|
-
middlewares
|
7
|
+
export interface RouterImplementerDef<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter<any>> {
|
8
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
|
9
9
|
contract: TContract;
|
10
10
|
}
|
11
|
-
export declare class RouterImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter
|
11
|
+
export declare class RouterImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter<any>> {
|
12
12
|
'~type': "RouterImplementer";
|
13
13
|
'~orpc': RouterImplementerDef<TContext, TExtraContext, TContract>;
|
14
14
|
constructor(def: RouterImplementerDef<TContext, TExtraContext, TContract>);
|
15
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<
|
16
|
-
router<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(router: U): AdaptedRouter<TContext, U
|
15
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): RouterImplementer<TContext, MergeContext<TExtraContext, U>, TContract>;
|
16
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
|
17
17
|
lazy<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(loader: () => Promise<{
|
18
18
|
default: U;
|
19
|
-
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
19
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
|
20
20
|
}
|
21
21
|
//# sourceMappingURL=router-implementer.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -2,8 +2,8 @@ import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } fro
|
|
2
2
|
import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
|
3
3
|
import type { ANY_PROCEDURE, Procedure } from './procedure';
|
4
4
|
import type { Context } from './types';
|
5
|
-
export type Router<TContext extends Context, TContract extends ContractRouter
|
6
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter ? Router<TContext, TContract[K]> : never;
|
5
|
+
export type Router<TContext extends Context, TContract extends ContractRouter<any>> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any, UErrorMap> : {
|
6
|
+
[K in keyof TContract]: TContract[K] extends ContractRouter<any> ? Router<TContext, 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/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.30.0",
|
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.
|
57
|
-
"@orpc/shared": "0.
|
56
|
+
"@orpc/contract": "0.30.0",
|
57
|
+
"@orpc/shared": "0.30.0"
|
58
58
|
},
|
59
59
|
"scripts": {
|
60
60
|
"build": "tsup --onSuccess='tsc -b --noCheck'",
|