@orpc/server 0.0.0-next.837ee14 → 0.0.0-next.854b646
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-3XSZ4GNO.js +136 -0
- package/dist/chunk-SD2T3J2Z.js +319 -0
- package/dist/chunk-SV6DBVXJ.js +377 -0
- package/dist/chunk-XFBAK67J.js +128 -0
- package/dist/fetch.js +14 -28
- package/dist/hono.js +42 -0
- package/dist/index.js +269 -386
- package/dist/next.js +39 -0
- package/dist/node.js +162 -32
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +2 -5
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +10 -13
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +13 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +20 -0
- package/dist/src/adapters/node/index.d.ts +2 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +17 -17
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +51 -0
- package/dist/src/adapters/standard/index.d.ts +7 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
- package/dist/src/adapters/standard/types.d.ts +44 -0
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +52 -30
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +6 -4
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +17 -0
- package/dist/src/implementer.d.ts +28 -0
- package/dist/src/index.d.ts +11 -12
- package/dist/src/lazy-utils.d.ts +4 -2
- package/dist/src/lazy.d.ts +9 -5
- package/dist/src/middleware-decorated.d.ts +7 -5
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +28 -14
- package/dist/src/plugins/base.d.ts +13 -0
- package/dist/src/plugins/cors.d.ts +19 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +20 -23
- package/dist/src/procedure-decorated.d.ts +18 -11
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +24 -18
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +7 -21
- package/dist/src/router.d.ts +25 -12
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +17 -0
- package/package.json +30 -6
- package/dist/chunk-6A7XHEBH.js +0 -189
- package/dist/chunk-B2EZJB7X.js +0 -303
- package/dist/src/adapters/fetch/composite-handler.d.ts +0 -8
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/node/composite-handler.d.ts +0 -9
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/lazy-decorated.d.ts +0 -10
- package/dist/src/procedure-builder.d.ts +0 -22
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/types.d.ts +0 -12
@@ -1,14 +1,21 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ClientRest, ErrorMap, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
2
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
-
import type { Context, MergeContext } from './types';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
5
|
import { Procedure } from './procedure';
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
export declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
|
7
|
+
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, MergedErrorMap<TErrorMap, U>, TMeta>;
|
8
|
+
meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
9
|
+
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
10
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
11
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
12
|
+
/**
|
13
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
14
|
+
*/
|
15
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
|
+
/**
|
17
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
18
|
+
*/
|
19
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
20
|
+
}
|
14
21
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Meta, 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, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,23 +1,29 @@
|
|
1
|
+
import type { AbortSignal, ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
4
|
+
import type { AnyMiddleware } from './middleware';
|
5
|
+
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
6
|
+
context: TCurrentContext;
|
7
|
+
input: TInput;
|
8
|
+
path: string[];
|
9
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
10
|
+
signal?: AbortSignal;
|
11
|
+
errors: TErrorConstructorMap;
|
8
12
|
}
|
9
|
-
export interface
|
10
|
-
|
11
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
12
|
-
handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
13
|
+
export interface ProcedureHandler<TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
14
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
13
15
|
}
|
14
|
-
export
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
export interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
17
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
18
|
+
middlewares: AnyMiddleware[];
|
19
|
+
inputValidationIndex: number;
|
20
|
+
outputValidationIndex: number;
|
21
|
+
handler: ProcedureHandler<TCurrentContext, any, any, THandlerOutput, any, any>;
|
18
22
|
}
|
19
|
-
export
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
export declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
24
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
25
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
26
|
+
}
|
27
|
+
export type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
28
|
+
export declare function isProcedure(item: unknown): item is AnyProcedure;
|
23
29
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Lazy } from './lazy';
|
2
|
+
import type { AnyProcedure } from './procedure';
|
3
|
+
import type { AnyRouter } from './router';
|
4
|
+
export type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
5
|
+
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
6
|
+
});
|
7
|
+
export declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
8
|
+
//# sourceMappingURL=router-accessible-lazy.d.ts.map
|
@@ -1,25 +1,11 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Hooks, Value } from '@orpc/shared';
|
1
|
+
import type { ErrorMap, Meta } from '@orpc/contract';
|
3
2
|
import type { Lazy } from './lazy';
|
4
3
|
import type { Procedure } from './procedure';
|
5
|
-
import type { ProcedureClient } from './procedure-client';
|
6
|
-
import type {
|
7
|
-
|
8
|
-
|
9
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER | ContractRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import type { AnyRouter, Router } from './router';
|
6
|
+
export type RouterClient<TRouter extends AnyRouter, TClientContext> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
7
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
10
8
|
};
|
11
|
-
export type
|
12
|
-
|
13
|
-
/**
|
14
|
-
* This is helpful for logging and analytics.
|
15
|
-
*
|
16
|
-
* @internal
|
17
|
-
*/
|
18
|
-
path?: string[];
|
19
|
-
} & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
|
20
|
-
context?: Value<UContext>;
|
21
|
-
} : {
|
22
|
-
context: Value<UContext>;
|
23
|
-
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
24
|
-
export declare function createRouterClient<TRouter extends ANY_ROUTER>(options: CreateRouterClientOptions<TRouter>): RouterClient<TRouter, unknown>;
|
9
|
+
export type CreateRouterClientRest<TRouter extends AnyRouter, TClientContext> = CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>;
|
10
|
+
export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateRouterClientRest<TRouter, TClientContext>): RouterClient<TRouter, TClientContext>;
|
25
11
|
//# sourceMappingURL=router-client.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,16 +1,29 @@
|
|
1
|
-
import type { ContractProcedure,
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ErrorMap, HTTPPath, MergedErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
3
|
+
import type { Lazy, Lazyable } from './lazy';
|
4
|
+
import type { AnyMiddleware } from './middleware';
|
5
|
+
import type { AnyProcedure } from './procedure';
|
6
|
+
import { Procedure } from './procedure';
|
7
|
+
import { type AccessibleLazyRouter } from './router-accessible-lazy';
|
8
|
+
export type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
|
9
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
|
7
10
|
}>;
|
8
|
-
export type
|
9
|
-
export type InferRouterInputs<T extends
|
10
|
-
[K in keyof T]: T[K] extends
|
11
|
+
export type AnyRouter = Router<any, any>;
|
12
|
+
export type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
13
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
|
11
14
|
};
|
12
|
-
export type InferRouterOutputs<T extends
|
13
|
-
[K in keyof T]: T[K] extends
|
15
|
+
export type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
16
|
+
[K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
|
14
17
|
};
|
15
|
-
export
|
18
|
+
export type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
19
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
|
20
|
+
};
|
21
|
+
export interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
|
22
|
+
middlewares: AnyMiddleware[];
|
23
|
+
tags?: readonly string[];
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
errorMap: TErrorMap;
|
26
|
+
}
|
27
|
+
export declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
|
28
|
+
export declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
|
16
29
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type { AnyContractProcedure, AnyContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { AnyProcedure } from './procedure';
|
4
|
+
import type { AnyRouter } from './router';
|
5
|
+
export interface EachContractProcedureOptions {
|
6
|
+
router: AnyRouter | AnyContractRouter;
|
7
|
+
path: string[];
|
8
|
+
}
|
9
|
+
export interface EachContractProcedureCallbackOptions {
|
10
|
+
contract: AnyContractProcedure;
|
11
|
+
path: string[];
|
12
|
+
}
|
13
|
+
export interface EachContractProcedureLaziedOptions {
|
14
|
+
lazied: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
|
15
|
+
path: string[];
|
16
|
+
}
|
17
|
+
export declare function eachContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void, laziedOptions?: EachContractProcedureLaziedOptions[]): EachContractProcedureLaziedOptions[];
|
18
|
+
export declare function eachAllContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void): Promise<void>;
|
19
|
+
export declare function convertPathToHttpPath(path: string[]): HTTPPath;
|
20
|
+
/**
|
21
|
+
* Create a new procedure that ensure the contract is applied to the procedure.
|
22
|
+
*/
|
23
|
+
export declare function createContractedProcedure(contract: AnyContractProcedure, procedure: AnyProcedure): AnyProcedure;
|
3
24
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/standard.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import {
|
2
|
+
RPCCodec,
|
3
|
+
RPCMatcher,
|
4
|
+
RPCSerializer,
|
5
|
+
StandardHandler,
|
6
|
+
serializeRPCJson
|
7
|
+
} from "./chunk-SD2T3J2Z.js";
|
8
|
+
import "./chunk-SV6DBVXJ.js";
|
9
|
+
import "./chunk-XFBAK67J.js";
|
10
|
+
export {
|
11
|
+
RPCCodec,
|
12
|
+
RPCMatcher,
|
13
|
+
RPCSerializer,
|
14
|
+
StandardHandler,
|
15
|
+
serializeRPCJson
|
16
|
+
};
|
17
|
+
//# sourceMappingURL=standard.js.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.854b646",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -19,11 +19,31 @@
|
|
19
19
|
"import": "./dist/index.js",
|
20
20
|
"default": "./dist/index.js"
|
21
21
|
},
|
22
|
+
"./plugins": {
|
23
|
+
"types": "./dist/src/plugins/index.d.ts",
|
24
|
+
"import": "./dist/plugins.js",
|
25
|
+
"default": "./dist/plugins.js"
|
26
|
+
},
|
27
|
+
"./standard": {
|
28
|
+
"types": "./dist/src/adapters/standard/index.d.ts",
|
29
|
+
"import": "./dist/standard.js",
|
30
|
+
"default": "./dist/standard.js"
|
31
|
+
},
|
22
32
|
"./fetch": {
|
23
33
|
"types": "./dist/src/adapters/fetch/index.d.ts",
|
24
34
|
"import": "./dist/fetch.js",
|
25
35
|
"default": "./dist/fetch.js"
|
26
36
|
},
|
37
|
+
"./hono": {
|
38
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
39
|
+
"import": "./dist/hono.js",
|
40
|
+
"default": "./dist/hono.js"
|
41
|
+
},
|
42
|
+
"./next": {
|
43
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
44
|
+
"import": "./dist/next.js",
|
45
|
+
"default": "./dist/next.js"
|
46
|
+
},
|
27
47
|
"./node": {
|
28
48
|
"types": "./dist/src/adapters/node/index.d.ts",
|
29
49
|
"import": "./dist/node.js",
|
@@ -38,16 +58,20 @@
|
|
38
58
|
"!**/*.tsbuildinfo",
|
39
59
|
"dist"
|
40
60
|
],
|
61
|
+
"peerDependencies": {
|
62
|
+
"hono": ">=4.6.0",
|
63
|
+
"next": ">=14.0.0"
|
64
|
+
},
|
41
65
|
"dependencies": {
|
42
|
-
"@
|
43
|
-
"@orpc/contract": "0.0.0-next.
|
44
|
-
"@orpc/shared": "0.0.0-next.
|
66
|
+
"@tinyhttp/content-disposition": "^2.2.2",
|
67
|
+
"@orpc/contract": "0.0.0-next.854b646",
|
68
|
+
"@orpc/shared": "0.0.0-next.854b646"
|
45
69
|
},
|
46
70
|
"devDependencies": {
|
47
|
-
"
|
71
|
+
"light-my-request": "^6.5.1"
|
48
72
|
},
|
49
73
|
"scripts": {
|
50
|
-
"build": "tsup --
|
74
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
51
75
|
"build:watch": "pnpm run build --watch",
|
52
76
|
"type:check": "tsc -b"
|
53
77
|
}
|
package/dist/chunk-6A7XHEBH.js
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __export = (target, all) => {
|
3
|
-
for (var name in all)
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
-
};
|
6
|
-
|
7
|
-
// src/utils.ts
|
8
|
-
function mergeContext(a, b) {
|
9
|
-
if (!a)
|
10
|
-
return b;
|
11
|
-
if (!b)
|
12
|
-
return a;
|
13
|
-
return {
|
14
|
-
...a,
|
15
|
-
...b
|
16
|
-
};
|
17
|
-
}
|
18
|
-
|
19
|
-
// src/procedure.ts
|
20
|
-
import { isContractProcedure } from "@orpc/contract";
|
21
|
-
var Procedure = class {
|
22
|
-
"~type" = "Procedure";
|
23
|
-
"~orpc";
|
24
|
-
constructor(def) {
|
25
|
-
this["~orpc"] = def;
|
26
|
-
}
|
27
|
-
};
|
28
|
-
function isProcedure(item) {
|
29
|
-
if (item instanceof Procedure) {
|
30
|
-
return true;
|
31
|
-
}
|
32
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
33
|
-
}
|
34
|
-
|
35
|
-
// src/lazy.ts
|
36
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
37
|
-
function lazy(loader) {
|
38
|
-
return {
|
39
|
-
[LAZY_LOADER_SYMBOL]: loader
|
40
|
-
};
|
41
|
-
}
|
42
|
-
function isLazy(item) {
|
43
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
44
|
-
}
|
45
|
-
function unlazy(lazied) {
|
46
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
47
|
-
}
|
48
|
-
function flatLazy(lazied) {
|
49
|
-
const flattenLoader = async () => {
|
50
|
-
let current = await unlazy(lazied);
|
51
|
-
while (true) {
|
52
|
-
if (!isLazy(current.default)) {
|
53
|
-
break;
|
54
|
-
}
|
55
|
-
current = await unlazy(current.default);
|
56
|
-
}
|
57
|
-
return current;
|
58
|
-
};
|
59
|
-
return lazy(flattenLoader);
|
60
|
-
}
|
61
|
-
|
62
|
-
// src/procedure-client.ts
|
63
|
-
import { executeWithHooks, value } from "@orpc/shared";
|
64
|
-
import { ORPCError } from "@orpc/shared/error";
|
65
|
-
function createProcedureClient(options) {
|
66
|
-
return async (...[input, callerOptions]) => {
|
67
|
-
const path = options.path ?? [];
|
68
|
-
const { default: procedure } = await unlazy(options.procedure);
|
69
|
-
const context = await value(options.context);
|
70
|
-
const meta = {
|
71
|
-
path,
|
72
|
-
procedure,
|
73
|
-
signal: callerOptions?.signal
|
74
|
-
};
|
75
|
-
const executeWithValidation = async () => {
|
76
|
-
const validInput = await validateInput(procedure, input);
|
77
|
-
const output = await executeMiddlewareChain(
|
78
|
-
procedure,
|
79
|
-
validInput,
|
80
|
-
context,
|
81
|
-
meta
|
82
|
-
);
|
83
|
-
return validateOutput(procedure, output);
|
84
|
-
};
|
85
|
-
return executeWithHooks({
|
86
|
-
hooks: options,
|
87
|
-
input,
|
88
|
-
context,
|
89
|
-
meta,
|
90
|
-
execute: executeWithValidation
|
91
|
-
});
|
92
|
-
};
|
93
|
-
}
|
94
|
-
async function validateInput(procedure, input) {
|
95
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
96
|
-
if (!schema)
|
97
|
-
return input;
|
98
|
-
const result = await schema["~standard"].validate(input);
|
99
|
-
if (result.issues) {
|
100
|
-
throw new ORPCError({
|
101
|
-
message: "Input validation failed",
|
102
|
-
code: "BAD_REQUEST",
|
103
|
-
issues: result.issues
|
104
|
-
});
|
105
|
-
}
|
106
|
-
return result.value;
|
107
|
-
}
|
108
|
-
async function validateOutput(procedure, output) {
|
109
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
110
|
-
if (!schema)
|
111
|
-
return output;
|
112
|
-
const result = await schema["~standard"].validate(output);
|
113
|
-
if (result.issues) {
|
114
|
-
throw new ORPCError({
|
115
|
-
message: "Output validation failed",
|
116
|
-
code: "INTERNAL_SERVER_ERROR",
|
117
|
-
issues: result.issues
|
118
|
-
});
|
119
|
-
}
|
120
|
-
return result.value;
|
121
|
-
}
|
122
|
-
async function executeMiddlewareChain(procedure, input, context, meta) {
|
123
|
-
const middlewares = procedure["~orpc"].middlewares ?? [];
|
124
|
-
let currentMidIndex = 0;
|
125
|
-
let currentContext = context;
|
126
|
-
const next = async (nextOptions) => {
|
127
|
-
const mid = middlewares[currentMidIndex];
|
128
|
-
currentMidIndex += 1;
|
129
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
130
|
-
if (mid) {
|
131
|
-
return await mid(input, currentContext, {
|
132
|
-
...meta,
|
133
|
-
next,
|
134
|
-
output: (output) => ({ output, context: void 0 })
|
135
|
-
});
|
136
|
-
}
|
137
|
-
const result = {
|
138
|
-
output: await procedure["~orpc"].handler(input, currentContext, meta),
|
139
|
-
context: currentContext
|
140
|
-
};
|
141
|
-
return result;
|
142
|
-
};
|
143
|
-
return (await next({})).output;
|
144
|
-
}
|
145
|
-
|
146
|
-
// src/router.ts
|
147
|
-
function getRouterChild(router, ...path) {
|
148
|
-
let current = router;
|
149
|
-
for (let i = 0; i < path.length; i++) {
|
150
|
-
const segment = path[i];
|
151
|
-
if (!current) {
|
152
|
-
return void 0;
|
153
|
-
}
|
154
|
-
if (isProcedure(current)) {
|
155
|
-
return void 0;
|
156
|
-
}
|
157
|
-
if (!isLazy(current)) {
|
158
|
-
current = current[segment];
|
159
|
-
continue;
|
160
|
-
}
|
161
|
-
const lazied = current;
|
162
|
-
const rest = path.slice(i);
|
163
|
-
const newLazy = lazy(async () => {
|
164
|
-
const unwrapped = await unlazy(lazied);
|
165
|
-
if (!unwrapped.default) {
|
166
|
-
return unwrapped;
|
167
|
-
}
|
168
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
169
|
-
return { default: next };
|
170
|
-
});
|
171
|
-
return flatLazy(newLazy);
|
172
|
-
}
|
173
|
-
return current;
|
174
|
-
}
|
175
|
-
|
176
|
-
export {
|
177
|
-
__export,
|
178
|
-
mergeContext,
|
179
|
-
Procedure,
|
180
|
-
isProcedure,
|
181
|
-
LAZY_LOADER_SYMBOL,
|
182
|
-
lazy,
|
183
|
-
isLazy,
|
184
|
-
unlazy,
|
185
|
-
flatLazy,
|
186
|
-
createProcedureClient,
|
187
|
-
getRouterChild
|
188
|
-
};
|
189
|
-
//# sourceMappingURL=chunk-6A7XHEBH.js.map
|