@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.cba521d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-3EVCPLVI.js +301 -0
- package/dist/chunk-OUPZ7QGV.js +245 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +11 -102
- package/dist/hono.js +30 -0
- package/dist/index.js +442 -274
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder.d.ts +30 -43
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +6 -0
- package/dist/src/implementer-chainable.d.ts +10 -0
- package/dist/src/index.d.ts +14 -4
- package/dist/src/lazy-decorated.d.ts +7 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +18 -0
- package/dist/src/middleware-decorated.d.ts +9 -0
- package/dist/src/middleware.d.ts +22 -12
- package/dist/src/procedure-builder.d.ts +19 -26
- package/dist/src/procedure-client.d.ts +22 -0
- package/dist/src/procedure-decorated.d.ts +26 -0
- package/dist/src/procedure-implementer.d.ts +17 -15
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +40 -25
- package/dist/src/router-builder.d.ts +24 -17
- package/dist/src/router-client.d.ts +26 -0
- package/dist/src/router-implementer.d.ts +18 -17
- package/dist/src/router.d.ts +11 -15
- package/dist/src/types.d.ts +10 -4
- package/package.json +22 -11
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/procedure-caller.d.ts +0 -19
- package/dist/src/router-caller.d.ts +0 -22
@@ -1,31 +1,24 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
1
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
+
import type { ProcedureHandler } from './procedure';
|
2
5
|
import type { Context, MergeContext } from './types';
|
3
|
-
import {
|
4
|
-
import { type DecoratedProcedure, type ProcedureFunc } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
5
7
|
import { ProcedureImplementer } from './procedure-implementer';
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
/**
|
22
|
-
* Convert to ProcedureBuilder
|
23
|
-
*/
|
24
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
25
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
26
|
-
/**
|
27
|
-
* Convert to Procedure
|
28
|
-
*/
|
29
|
-
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
8
|
+
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
10
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
11
|
+
}
|
12
|
+
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
13
|
+
'~type': "ProcedureBuilder";
|
14
|
+
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
15
|
+
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
16
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
|
18
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
|
19
|
+
errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, UErrorMap>;
|
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
|
+
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
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
30
23
|
}
|
31
24
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Lazyable } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
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>>;
|
7
|
+
/**
|
8
|
+
* Options for creating a procedure caller with comprehensive type safety
|
9
|
+
*/
|
10
|
+
export type CreateProcedureClientOptions<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = {
|
11
|
+
/**
|
12
|
+
* This is helpful for logging and analytics.
|
13
|
+
*/
|
14
|
+
path?: string[];
|
15
|
+
} & ({
|
16
|
+
context: Value<TContext, [clientContext: TClientContext]>;
|
17
|
+
} | (undefined extends TContext ? {
|
18
|
+
context?: Value<TContext, [clientContext: TClientContext]>;
|
19
|
+
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
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>;
|
22
|
+
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { ClientRest, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import type { Context, MergeContext } from './types';
|
6
|
+
import { Procedure } from './procedure';
|
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
|
+
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>;
|
12
|
+
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>;
|
13
|
+
unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
|
+
unshiftMiddleware(...middlewares: Middleware<TContext, Context & Partial<MergeContext<TContext, TExtraContext>> | undefined, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
|
+
/**
|
16
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
17
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
18
|
+
*/
|
19
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, 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
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
23
|
+
*/
|
24
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
25
|
+
}
|
26
|
+
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,18 +1,20 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
+
import type { ProcedureHandler } from './procedure';
|
2
5
|
import type { Context, MergeContext } from './types';
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
use<
|
15
|
-
|
16
|
-
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
+
preMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
10
|
+
postMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, Record<string, unknown>>[];
|
11
|
+
};
|
12
|
+
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
13
|
+
'~type': "ProcedureImplementer";
|
14
|
+
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
15
|
+
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
16
|
+
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>;
|
17
|
+
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>;
|
18
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
17
19
|
}
|
18
20
|
//# 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 { 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
@@ -1,29 +1,44 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
middlewares?: Middleware<any, any, any, any>[];
|
14
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
15
|
-
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
16
|
-
});
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { Lazy } from './lazy';
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { AbortSignal, Context, MergeContext } from './types';
|
7
|
+
export interface ProcedureHandlerOptions<TContext extends Context, TExtraContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
8
|
+
context: MergeContext<TContext, TExtraContext>;
|
9
|
+
input: TInput;
|
10
|
+
path: string[];
|
11
|
+
procedure: ANY_PROCEDURE;
|
12
|
+
signal?: AbortSignal;
|
13
|
+
errors: TErrorConstructorMap;
|
17
14
|
}
|
18
|
-
export
|
19
|
-
|
20
|
-
route: (opts: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
21
|
-
use: (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, TFuncOutput>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema, TFuncOutput>) & (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema, TFuncOutput>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, TFuncOutput>, UMappedInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema, TFuncOutput>);
|
22
|
-
} & (undefined extends TContext ? ProcedureCaller<Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>> : unknown);
|
23
|
-
export interface ProcedureFunc<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TOutput extends SchemaOutput<TOutputSchema>> {
|
24
|
-
(input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, TOutput>>;
|
15
|
+
export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
16
|
+
(opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
25
17
|
}
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
/**
|
19
|
+
* Why is `ErrorConstructorMap` passed to `postMiddlewares` as `Record<string, unknown>`?
|
20
|
+
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
|
+
*
|
22
|
+
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
23
|
+
* causes unexpected errors in the router (the root cause is unclear, but it occurs consistently).
|
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<string, unknown>>[];
|
31
|
+
postMiddlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, Record<string, unknown>>[];
|
32
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
33
|
+
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
34
|
+
}
|
35
|
+
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
36
|
+
'~type': "Procedure";
|
37
|
+
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
38
|
+
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
39
|
+
}
|
40
|
+
export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any>;
|
41
|
+
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any>;
|
42
|
+
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
43
|
+
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
29
44
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -1,22 +1,29 @@
|
|
1
|
-
import type {
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { FlattenLazy, Lazy } from './lazy';
|
3
|
+
import type { Middleware } from './middleware';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
import type { ANY_ROUTER, Router } from './router';
|
2
6
|
import type { Context, MergeContext } from './types';
|
3
|
-
import { type
|
4
|
-
import {
|
7
|
+
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
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;
|
11
|
+
};
|
12
|
+
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context> = {
|
13
|
+
prefix?: HTTPPath;
|
14
|
+
tags?: readonly string[];
|
15
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
16
|
+
};
|
5
17
|
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
middlewares?: Middleware<any, any, any, any>[];
|
10
|
-
};
|
11
|
-
constructor(zz$rb: {
|
12
|
-
prefix?: HTTPPath;
|
13
|
-
tags?: string[];
|
14
|
-
middlewares?: Middleware<any, any, any, any>[];
|
15
|
-
});
|
18
|
+
'~type': "RouterBuilder";
|
19
|
+
'~orpc': RouterBuilderDef<TContext, TExtraContext>;
|
20
|
+
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
16
21
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
17
|
-
|
18
|
-
use<
|
19
|
-
|
20
|
-
|
22
|
+
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
23
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): RouterBuilder<TContext, MergeContext<TExtraContext, U>>;
|
24
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
25
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
|
26
|
+
default: U;
|
27
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
21
28
|
}
|
22
29
|
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { Hooks, Value } from '@orpc/shared';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import type { Meta } from './types';
|
6
|
+
import { type ANY_ROUTER, type Router } from './router';
|
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;
|
12
|
+
};
|
13
|
+
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
14
|
+
/**
|
15
|
+
* This is helpful for logging and analytics.
|
16
|
+
*
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
path?: string[];
|
20
|
+
} & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
|
21
|
+
context?: Value<UContext>;
|
22
|
+
} : {
|
23
|
+
context: Value<UContext>;
|
24
|
+
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
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>;
|
26
|
+
//# sourceMappingURL=router-client.d.ts.map
|
@@ -1,20 +1,21 @@
|
|
1
|
+
import type { ContractRouter } from '@orpc/contract';
|
2
|
+
import type { FlattenLazy } from './lazy';
|
1
3
|
import type { Middleware } from './middleware';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
import type { Router } from './router';
|
5
|
+
import type { AdaptedRouter } from './router-builder';
|
6
|
+
import type { Context, MergeContext } from './types';
|
7
|
+
export interface RouterImplementerDef<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
8
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
9
|
+
contract: TContract;
|
10
|
+
}
|
11
|
+
export declare class RouterImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
12
|
+
'~type': "RouterImplementer";
|
13
|
+
'~orpc': RouterImplementerDef<TContext, TExtraContext, TContract>;
|
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<string, unknown>>): RouterImplementer<TContext, MergeContext<TExtraContext, U>, TContract>;
|
16
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(router: U): AdaptedRouter<TContext, U>;
|
17
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(loader: () => Promise<{
|
18
|
+
default: U;
|
19
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
14
20
|
}
|
15
|
-
export type ChainedRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context> = {
|
16
|
-
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? ChainedRouterImplementer<TContext, TContract[K], TExtraContext> : never;
|
17
|
-
} & RouterImplementer<TContext, TContract>;
|
18
|
-
export declare function chainRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context>(contract: TContract, middlewares?: Middleware<any, any, any, any>[]): ChainedRouterImplementer<TContext, TContract, TExtraContext>;
|
19
|
-
export declare function assertRouterImplementation(contract: ContractRouter, router: RouterWithContract<any, any>, path?: string[]): void;
|
20
21
|
//# sourceMappingURL=router-implementer.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
|
3
|
+
import type { ANY_PROCEDURE, Procedure } from './procedure';
|
2
4
|
import type { Context } from './types';
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
export type
|
8
|
-
[K in keyof
|
5
|
+
export type Router<TContext extends Context, TContract extends ContractRouter> = 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 ? Router<TContext, TContract[K]> : never;
|
7
|
+
}>;
|
8
|
+
export type ANY_ROUTER = Router<any, any>;
|
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> : {
|
10
|
+
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterInputs<T[K]> : never;
|
9
11
|
};
|
10
|
-
export type
|
11
|
-
[K in keyof
|
12
|
-
};
|
13
|
-
export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter;
|
14
|
-
export type InferRouterInputs<T extends Router<any>> = {
|
15
|
-
[K in keyof T]: T[K] extends Procedure<any, any, infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : T[K] extends Router<any> ? InferRouterInputs<T[K]> : never;
|
16
|
-
};
|
17
|
-
export type InferRouterOutputs<T extends Router<any>> = {
|
18
|
-
[K in keyof T]: T[K] extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput> ? SchemaOutput<UOutputSchema, UFuncOutput> : T[K] extends Router<any> ? InferRouterOutputs<T[K]> : never;
|
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
|
+
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterOutputs<T[K]> : never;
|
19
14
|
};
|
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;
|
20
16
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type { FindGlobalInstanceType } from '@orpc/shared';
|
2
|
+
import type { ANY_PROCEDURE } from './procedure';
|
3
|
+
export type Context = Record<string, any> | undefined;
|
4
|
+
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
3
5
|
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
4
|
-
export
|
6
|
+
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
7
|
+
export interface WithSignal {
|
8
|
+
signal?: AbortSignal;
|
9
|
+
}
|
10
|
+
export interface Meta extends WithSignal {
|
5
11
|
path: string[];
|
6
|
-
procedure:
|
12
|
+
procedure: ANY_PROCEDURE;
|
7
13
|
}
|
8
14
|
//# sourceMappingURL=types.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.cba521d",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -20,10 +20,25 @@
|
|
20
20
|
"default": "./dist/index.js"
|
21
21
|
},
|
22
22
|
"./fetch": {
|
23
|
-
"types": "./dist/src/fetch/index.d.ts",
|
23
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
24
24
|
"import": "./dist/fetch.js",
|
25
25
|
"default": "./dist/fetch.js"
|
26
26
|
},
|
27
|
+
"./hono": {
|
28
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
29
|
+
"import": "./dist/hono.js",
|
30
|
+
"default": "./dist/hono.js"
|
31
|
+
},
|
32
|
+
"./next": {
|
33
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
34
|
+
"import": "./dist/next.js",
|
35
|
+
"default": "./dist/next.js"
|
36
|
+
},
|
37
|
+
"./node": {
|
38
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
39
|
+
"import": "./dist/node.js",
|
40
|
+
"default": "./dist/node.js"
|
41
|
+
},
|
27
42
|
"./🔒/*": {
|
28
43
|
"types": "./dist/src/*.d.ts"
|
29
44
|
}
|
@@ -34,19 +49,15 @@
|
|
34
49
|
"dist"
|
35
50
|
],
|
36
51
|
"peerDependencies": {
|
37
|
-
"
|
38
|
-
"
|
52
|
+
"hono": ">=4.6.0",
|
53
|
+
"next": ">=14.0.0"
|
39
54
|
},
|
40
55
|
"dependencies": {
|
41
|
-
"@orpc/contract": "0.0.0-next.
|
42
|
-
"@orpc/shared": "0.0.0-next.
|
43
|
-
"@orpc/transformer": "0.0.0-next.c59d67c"
|
44
|
-
},
|
45
|
-
"devDependencies": {
|
46
|
-
"@orpc/openapi": "0.0.0-next.c59d67c"
|
56
|
+
"@orpc/contract": "0.0.0-next.cba521d",
|
57
|
+
"@orpc/shared": "0.0.0-next.cba521d"
|
47
58
|
},
|
48
59
|
"scripts": {
|
49
|
-
"build": "tsup --
|
60
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
50
61
|
"build:watch": "pnpm run build --watch",
|
51
62
|
"type:check": "tsc -b"
|
52
63
|
}
|