@orpc/server 0.0.0-next.ee0aeaf → 0.0.0-next.f99e554
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-6A7XHEBH.js +189 -0
- package/dist/chunk-B2EZJB7X.js +303 -0
- package/dist/fetch.js +22 -101
- package/dist/index.js +367 -296
- package/dist/node.js +45 -0
- package/dist/src/adapters/fetch/composite-handler.d.ts +8 -0
- package/dist/src/adapters/fetch/index.d.ts +7 -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 +16 -0
- package/dist/src/adapters/node/composite-handler.d.ts +9 -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/types.d.ts +21 -0
- package/dist/src/builder.d.ts +24 -43
- package/dist/src/hidden.d.ts +6 -0
- package/dist/src/implementer-chainable.d.ts +10 -0
- package/dist/src/index.d.ts +9 -3
- package/dist/src/lazy-decorated.d.ts +10 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +6 -11
- package/dist/src/middleware-decorated.d.ts +8 -0
- package/dist/src/middleware.d.ts +3 -6
- package/dist/src/procedure-builder.d.ts +15 -24
- package/dist/src/procedure-client.d.ts +34 -0
- package/dist/src/procedure-decorated.d.ts +14 -0
- package/dist/src/procedure-implementer.d.ts +13 -17
- package/dist/src/procedure.d.ts +15 -24
- package/dist/src/router-builder.d.ts +23 -21
- package/dist/src/router-client.d.ts +25 -0
- package/dist/src/router-implementer.d.ts +17 -20
- package/dist/src/router.d.ts +11 -15
- package/dist/src/types.d.ts +6 -8
- package/package.json +12 -10
- package/dist/chunk-VARUID7X.js +0 -273
- 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 -28
- package/dist/src/procedure-caller.d.ts +0 -26
- package/dist/src/router-caller.d.ts +0 -25
package/dist/src/procedure.d.ts
CHANGED
@@ -1,32 +1,23 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
2
|
import type { Lazy } from './lazy';
|
3
|
-
import type {
|
3
|
+
import type { Middleware } from './middleware';
|
4
4
|
import type { Context, MergeContext, Meta } from './types';
|
5
|
-
import { type ContractProcedure, type
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
5
|
+
import { type ContractProcedure, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
6
|
+
export interface ProcedureFunc<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
|
7
|
+
(input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
8
|
+
}
|
9
|
+
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
|
10
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, any>[];
|
11
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
12
|
+
handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
13
|
+
}
|
14
|
+
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
|
15
|
+
'~type': "Procedure";
|
16
|
+
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
17
|
+
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>);
|
18
18
|
}
|
19
19
|
export type ANY_PROCEDURE = Procedure<any, any, any, any, any>;
|
20
|
-
export type
|
20
|
+
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>;
|
21
21
|
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
22
|
-
export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> = Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput> & {
|
23
|
-
prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
24
|
-
route: (opts: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
25
|
-
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>);
|
26
|
-
} & (undefined extends TContext ? ProcedureCaller<Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>> : unknown);
|
27
|
-
export interface ProcedureFunc<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TOutput extends SchemaOutput<TOutputSchema>> {
|
28
|
-
(input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, TOutput>>;
|
29
|
-
}
|
30
|
-
export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(procedure: Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
31
22
|
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
32
23
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -1,27 +1,29 @@
|
|
1
|
-
import type {
|
2
|
-
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';
|
3
6
|
import type { Context, MergeContext } from './types';
|
4
|
-
import { type
|
5
|
-
import { type
|
6
|
-
export
|
7
|
+
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
+
import { type 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> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : {
|
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>[];
|
16
|
+
};
|
7
17
|
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
middlewares?: Middleware<any, any, any, any>[];
|
12
|
-
};
|
13
|
-
constructor(zz$rb: {
|
14
|
-
prefix?: HTTPPath;
|
15
|
-
tags?: string[];
|
16
|
-
middlewares?: Middleware<any, any, any, any>[];
|
17
|
-
});
|
18
|
+
'~type': "RouterBuilder";
|
19
|
+
'~orpc': RouterBuilderDef<TContext, TExtraContext>;
|
20
|
+
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
18
21
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
19
|
-
|
20
|
-
use<
|
21
|
-
|
22
|
-
|
23
|
-
lazy<U extends Router<TContext>>(loader: () => Promise<{
|
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>): 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<{
|
24
26
|
default: U;
|
25
|
-
}>):
|
27
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
26
28
|
}
|
27
29
|
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Lazy } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
import type { ProcedureClient } from './procedure-client';
|
6
|
+
import type { Meta } from './types';
|
7
|
+
import { type ANY_ROUTER, type Router } from './router';
|
8
|
+
export type RouterClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER | ContractRouter> ? RouterClient<U, TClientContext> : TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? ProcedureClient<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, TClientContext> : {
|
9
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER | ContractRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
10
|
+
};
|
11
|
+
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
12
|
+
router: TRouter | Lazy<undefined>;
|
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>;
|
25
|
+
//# sourceMappingURL=router-client.d.ts.map
|
@@ -1,24 +1,21 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ContractRouter } from '@orpc/contract';
|
2
|
+
import type { FlattenLazy } from './lazy';
|
2
3
|
import type { Middleware } from './middleware';
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
router<U extends
|
16
|
-
lazy<U extends
|
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>[];
|
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>): 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<{
|
17
18
|
default: U;
|
18
|
-
}>):
|
19
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
19
20
|
}
|
20
|
-
export type ChainedRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context> = {
|
21
|
-
[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;
|
22
|
-
} & RouterImplementer<TContext, TContract>;
|
23
|
-
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>;
|
24
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,
|
3
|
-
import type {
|
2
|
+
import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
|
3
|
+
import type { ANY_PROCEDURE, Procedure } from './procedure';
|
4
4
|
import type { Context } from './types';
|
5
|
-
export
|
6
|
-
[
|
7
|
-
}
|
8
|
-
export type
|
9
|
-
|
5
|
+
export type Router<TContext extends Context, TContract extends ContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> : {
|
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> ? SchemaInput<UInputSchema> : {
|
10
|
+
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterInputs<T[K]> : never;
|
10
11
|
};
|
11
|
-
export type
|
12
|
-
[K in keyof
|
13
|
-
};
|
14
|
-
export type InferRouterInputs<T extends Router<any>> = {
|
15
|
-
[K in keyof T]: T[K] extends Procedure<any, any, infer UInputSchema, any, any> | Lazy<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> | Lazy<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> ? 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 | Record<string, ANY_ROUTER> | undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
|
20
16
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
export type Context = Record<string,
|
1
|
+
import type { ANY_PROCEDURE } from './procedure';
|
2
|
+
export type Context = Record<string, any> | undefined;
|
3
|
+
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
3
4
|
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
4
|
-
export interface
|
5
|
+
export interface WithSignal {
|
5
6
|
signal?: AbortSignal;
|
6
7
|
}
|
7
|
-
export interface
|
8
|
-
(...opts: [input: TInput, options?: CallerOptions] | (undefined extends TInput ? [] : never)): Promise<TOutput>;
|
9
|
-
}
|
10
|
-
export interface Meta extends CallerOptions {
|
8
|
+
export interface Meta extends WithSignal {
|
11
9
|
path: string[];
|
12
|
-
procedure:
|
10
|
+
procedure: ANY_PROCEDURE;
|
13
11
|
}
|
14
12
|
//# 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.f99e554",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -20,10 +20,15 @@
|
|
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
|
+
"./node": {
|
28
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
29
|
+
"import": "./dist/node.js",
|
30
|
+
"default": "./dist/node.js"
|
31
|
+
},
|
27
32
|
"./🔒/*": {
|
28
33
|
"types": "./dist/src/*.d.ts"
|
29
34
|
}
|
@@ -33,19 +38,16 @@
|
|
33
38
|
"!**/*.tsbuildinfo",
|
34
39
|
"dist"
|
35
40
|
],
|
36
|
-
"peerDependencies": {
|
37
|
-
"@orpc/zod": "0.0.0-next.ee0aeaf"
|
38
|
-
},
|
39
41
|
"dependencies": {
|
40
|
-
"@
|
41
|
-
"@orpc/
|
42
|
-
"@orpc/
|
42
|
+
"@mjackson/node-fetch-server": "^0.5.0",
|
43
|
+
"@orpc/contract": "0.0.0-next.f99e554",
|
44
|
+
"@orpc/shared": "0.0.0-next.f99e554"
|
43
45
|
},
|
44
46
|
"devDependencies": {
|
45
|
-
"
|
47
|
+
"zod": "^3.24.1"
|
46
48
|
},
|
47
49
|
"scripts": {
|
48
|
-
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
50
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --entry.node=src/adapters/node/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
49
51
|
"build:watch": "pnpm run build --watch",
|
50
52
|
"type:check": "tsc -b"
|
51
53
|
}
|
package/dist/chunk-VARUID7X.js
DELETED
@@ -1,273 +0,0 @@
|
|
1
|
-
// src/utils.ts
|
2
|
-
function mergeContext(a, b) {
|
3
|
-
if (!a)
|
4
|
-
return b;
|
5
|
-
if (!b)
|
6
|
-
return a;
|
7
|
-
return {
|
8
|
-
...a,
|
9
|
-
...b
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
|
-
// src/middleware.ts
|
14
|
-
var decoratedMiddlewareSymbol = Symbol("\u{1F512}decoratedMiddleware");
|
15
|
-
function decorateMiddleware(middleware) {
|
16
|
-
if (Reflect.get(middleware, decoratedMiddlewareSymbol)) {
|
17
|
-
return middleware;
|
18
|
-
}
|
19
|
-
const concat = (concatMiddleware, mapInput2) => {
|
20
|
-
const concatMiddleware_ = mapInput2 ? decorateMiddleware(concatMiddleware).mapInput(mapInput2) : concatMiddleware;
|
21
|
-
return decorateMiddleware(async (input, context, meta, ...rest) => {
|
22
|
-
const input_ = input;
|
23
|
-
const context_ = context;
|
24
|
-
const meta_ = meta;
|
25
|
-
const next = async (options) => {
|
26
|
-
return concatMiddleware_(input_, mergeContext(context_, options.context), meta_, ...rest);
|
27
|
-
};
|
28
|
-
const m1 = await middleware(input_, context_, {
|
29
|
-
...meta_,
|
30
|
-
next
|
31
|
-
}, ...rest);
|
32
|
-
return m1;
|
33
|
-
});
|
34
|
-
};
|
35
|
-
const mapInput = (map) => {
|
36
|
-
return decorateMiddleware(
|
37
|
-
(input, ...rest) => middleware(map(input), ...rest)
|
38
|
-
);
|
39
|
-
};
|
40
|
-
return Object.assign(middleware, {
|
41
|
-
[decoratedMiddlewareSymbol]: true,
|
42
|
-
concat,
|
43
|
-
mapInput
|
44
|
-
});
|
45
|
-
}
|
46
|
-
|
47
|
-
// src/procedure-caller.ts
|
48
|
-
import { executeWithHooks, trim, value } from "@orpc/shared";
|
49
|
-
import { ORPCError } from "@orpc/shared/error";
|
50
|
-
|
51
|
-
// src/procedure.ts
|
52
|
-
import {
|
53
|
-
DecoratedContractProcedure,
|
54
|
-
isContractProcedure
|
55
|
-
} from "@orpc/contract";
|
56
|
-
var Procedure = class {
|
57
|
-
constructor(zz$p) {
|
58
|
-
this.zz$p = zz$p;
|
59
|
-
}
|
60
|
-
};
|
61
|
-
var DECORATED_PROCEDURE_SYMBOL = Symbol("DECORATED_PROCEDURE");
|
62
|
-
function decorateProcedure(procedure) {
|
63
|
-
if (DECORATED_PROCEDURE_SYMBOL in procedure) {
|
64
|
-
return procedure;
|
65
|
-
}
|
66
|
-
return Object.assign(createProcedureCaller({
|
67
|
-
procedure,
|
68
|
-
context: void 0
|
69
|
-
}), {
|
70
|
-
[DECORATED_PROCEDURE_SYMBOL]: true,
|
71
|
-
zz$p: procedure.zz$p,
|
72
|
-
prefix(prefix) {
|
73
|
-
return decorateProcedure({
|
74
|
-
zz$p: {
|
75
|
-
...procedure.zz$p,
|
76
|
-
contract: DecoratedContractProcedure.decorate(
|
77
|
-
procedure.zz$p.contract
|
78
|
-
).prefix(prefix)
|
79
|
-
}
|
80
|
-
});
|
81
|
-
},
|
82
|
-
route(opts) {
|
83
|
-
return decorateProcedure({
|
84
|
-
zz$p: {
|
85
|
-
...procedure.zz$p,
|
86
|
-
contract: DecoratedContractProcedure.decorate(
|
87
|
-
procedure.zz$p.contract
|
88
|
-
).route(opts)
|
89
|
-
}
|
90
|
-
});
|
91
|
-
},
|
92
|
-
use(middleware, mapInput) {
|
93
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
94
|
-
return decorateProcedure({
|
95
|
-
zz$p: {
|
96
|
-
...procedure.zz$p,
|
97
|
-
middlewares: [middleware_, ...procedure.zz$p.middlewares ?? []]
|
98
|
-
}
|
99
|
-
});
|
100
|
-
}
|
101
|
-
});
|
102
|
-
}
|
103
|
-
function isProcedure(item) {
|
104
|
-
if (item instanceof Procedure)
|
105
|
-
return true;
|
106
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "zz$p" in item && typeof item.zz$p === "object" && item.zz$p !== null && "contract" in item.zz$p && isContractProcedure(item.zz$p.contract) && "func" in item.zz$p && typeof item.zz$p.func === "function";
|
107
|
-
}
|
108
|
-
|
109
|
-
// src/procedure-caller.ts
|
110
|
-
function createProcedureCaller(options) {
|
111
|
-
const caller = async (...args) => {
|
112
|
-
const [input, callerOptions] = args;
|
113
|
-
const path = options.path ?? [];
|
114
|
-
const procedure = await loadProcedure(options.procedure);
|
115
|
-
const context = await value(options.context);
|
116
|
-
const execute = async () => {
|
117
|
-
const validInput = await (async () => {
|
118
|
-
const schema = procedure.zz$p.contract["~orpc"].InputSchema;
|
119
|
-
if (!schema) {
|
120
|
-
return input;
|
121
|
-
}
|
122
|
-
const result = await schema["~standard"].validate(input);
|
123
|
-
if (result.issues) {
|
124
|
-
throw new ORPCError({
|
125
|
-
message: "Validation input failed",
|
126
|
-
code: "BAD_REQUEST",
|
127
|
-
issues: result.issues
|
128
|
-
});
|
129
|
-
}
|
130
|
-
return result.value;
|
131
|
-
})();
|
132
|
-
const meta = {
|
133
|
-
path,
|
134
|
-
procedure,
|
135
|
-
signal: callerOptions?.signal
|
136
|
-
};
|
137
|
-
const middlewares = procedure.zz$p.middlewares ?? [];
|
138
|
-
let currentMidIndex = 0;
|
139
|
-
let currentContext = context;
|
140
|
-
const next = async (nextOptions) => {
|
141
|
-
const mid = middlewares[currentMidIndex];
|
142
|
-
currentMidIndex += 1;
|
143
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
144
|
-
if (mid) {
|
145
|
-
return await mid(validInput, currentContext, {
|
146
|
-
...meta,
|
147
|
-
next,
|
148
|
-
output: (output3) => ({ output: output3, context: void 0 })
|
149
|
-
});
|
150
|
-
} else {
|
151
|
-
return {
|
152
|
-
output: await await procedure.zz$p.func(validInput, currentContext, meta),
|
153
|
-
context: currentContext
|
154
|
-
};
|
155
|
-
}
|
156
|
-
};
|
157
|
-
const output2 = (await next({})).output;
|
158
|
-
const validOutput = await (async () => {
|
159
|
-
const schema = procedure.zz$p.contract["~orpc"].OutputSchema;
|
160
|
-
if (!schema) {
|
161
|
-
return output2;
|
162
|
-
}
|
163
|
-
const result = await schema["~standard"].validate(output2);
|
164
|
-
if (result.issues) {
|
165
|
-
throw new ORPCError({
|
166
|
-
message: "Validation output failed",
|
167
|
-
code: "INTERNAL_SERVER_ERROR"
|
168
|
-
});
|
169
|
-
}
|
170
|
-
return result.value;
|
171
|
-
})();
|
172
|
-
return validOutput;
|
173
|
-
};
|
174
|
-
const output = await executeWithHooks({
|
175
|
-
hooks: options,
|
176
|
-
input,
|
177
|
-
context,
|
178
|
-
meta: {
|
179
|
-
path,
|
180
|
-
procedure
|
181
|
-
},
|
182
|
-
execute
|
183
|
-
});
|
184
|
-
return output;
|
185
|
-
};
|
186
|
-
return caller;
|
187
|
-
}
|
188
|
-
async function loadProcedure(procedure) {
|
189
|
-
let loadedProcedure;
|
190
|
-
if (isLazy(procedure)) {
|
191
|
-
loadedProcedure = (await loadLazy(procedure)).default;
|
192
|
-
} else {
|
193
|
-
loadedProcedure = procedure;
|
194
|
-
}
|
195
|
-
if (!isProcedure(loadedProcedure)) {
|
196
|
-
throw new ORPCError({
|
197
|
-
code: "NOT_FOUND",
|
198
|
-
message: "Not found",
|
199
|
-
cause: new Error(trim(`
|
200
|
-
This error should be caught by the typescript compiler.
|
201
|
-
But if you still see this error, it means that you trying to call a lazy router (expected to be a lazy procedure).
|
202
|
-
`))
|
203
|
-
});
|
204
|
-
}
|
205
|
-
return loadedProcedure;
|
206
|
-
}
|
207
|
-
|
208
|
-
// src/lazy.ts
|
209
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
210
|
-
function createLazy(loader) {
|
211
|
-
return {
|
212
|
-
[LAZY_LOADER_SYMBOL]: loader
|
213
|
-
};
|
214
|
-
}
|
215
|
-
function loadLazy(lazy) {
|
216
|
-
return lazy[LAZY_LOADER_SYMBOL]();
|
217
|
-
}
|
218
|
-
function isLazy(item) {
|
219
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
220
|
-
}
|
221
|
-
function createFlattenLazy(lazy) {
|
222
|
-
const flattenLoader = async () => {
|
223
|
-
let current = await loadLazy(lazy);
|
224
|
-
while (true) {
|
225
|
-
if (!isLazy(current.default)) {
|
226
|
-
break;
|
227
|
-
}
|
228
|
-
current = await loadLazy(current.default);
|
229
|
-
}
|
230
|
-
return current;
|
231
|
-
};
|
232
|
-
const flattenLazy = {
|
233
|
-
[LAZY_LOADER_SYMBOL]: flattenLoader
|
234
|
-
};
|
235
|
-
return flattenLazy;
|
236
|
-
}
|
237
|
-
function decorateLazy(lazy) {
|
238
|
-
const flattenLazy = createFlattenLazy(lazy);
|
239
|
-
const procedureCaller = createProcedureCaller({
|
240
|
-
procedure: flattenLazy,
|
241
|
-
context: void 0
|
242
|
-
});
|
243
|
-
Object.assign(procedureCaller, flattenLazy);
|
244
|
-
const recursive = new Proxy(procedureCaller, {
|
245
|
-
get(target, key) {
|
246
|
-
if (typeof key !== "string") {
|
247
|
-
return Reflect.get(target, key);
|
248
|
-
}
|
249
|
-
return decorateLazy(createLazy(async () => {
|
250
|
-
const current = await loadLazy(flattenLazy);
|
251
|
-
return { default: current.default[key] };
|
252
|
-
}));
|
253
|
-
}
|
254
|
-
});
|
255
|
-
return recursive;
|
256
|
-
}
|
257
|
-
|
258
|
-
export {
|
259
|
-
mergeContext,
|
260
|
-
decorateMiddleware,
|
261
|
-
LAZY_LOADER_SYMBOL,
|
262
|
-
createLazy,
|
263
|
-
loadLazy,
|
264
|
-
isLazy,
|
265
|
-
createFlattenLazy,
|
266
|
-
decorateLazy,
|
267
|
-
createProcedureCaller,
|
268
|
-
loadProcedure,
|
269
|
-
Procedure,
|
270
|
-
decorateProcedure,
|
271
|
-
isProcedure
|
272
|
-
};
|
273
|
-
//# sourceMappingURL=chunk-VARUID7X.js.map
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import type { Router } from '../router';
|
2
|
-
import type { FetchHandler, FetchHandlerOptions } from './types';
|
3
|
-
export type HandleFetchRequestOptions<TRouter extends Router<any>> = FetchHandlerOptions<TRouter> & {
|
4
|
-
handlers: readonly [FetchHandler, ...FetchHandler[]];
|
5
|
-
};
|
6
|
-
export declare function handleFetchRequest<TRouter extends Router<any>>(options: HandleFetchRequestOptions<TRouter>): Promise<Response>;
|
7
|
-
//# sourceMappingURL=handle.d.ts.map
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
2
|
-
import type { Router } from '../router';
|
3
|
-
import type { CallerOptions } from '../types';
|
4
|
-
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
5
|
-
/**
|
6
|
-
* The `router` used for handling the request and routing,
|
7
|
-
*
|
8
|
-
*/
|
9
|
-
router: TRouter;
|
10
|
-
/**
|
11
|
-
* The request need to be handled.
|
12
|
-
*/
|
13
|
-
request: Request;
|
14
|
-
/**
|
15
|
-
* Remove the prefix from the request path.
|
16
|
-
*
|
17
|
-
* @example /orpc
|
18
|
-
* @example /api
|
19
|
-
*/
|
20
|
-
prefix?: string;
|
21
|
-
} & PartialOnUndefinedDeep<{
|
22
|
-
/**
|
23
|
-
* The context used to handle the request.
|
24
|
-
*/
|
25
|
-
context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
|
26
|
-
}> & CallerOptions & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, CallerOptions>;
|
27
|
-
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
|
28
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
3
|
-
import type { Lazy } from './lazy';
|
4
|
-
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Procedure } from './procedure';
|
5
|
-
import type { Caller } from './types';
|
6
|
-
export type CreateProcedureCallerOptions<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = T extends Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput>> ? {
|
7
|
-
procedure: T;
|
8
|
-
/**
|
9
|
-
* This is helpful for logging and analytics.
|
10
|
-
*
|
11
|
-
* @internal
|
12
|
-
*/
|
13
|
-
path?: string[];
|
14
|
-
} & PartialOnUndefinedDeep<{
|
15
|
-
/**
|
16
|
-
* The context used when calling the procedure.
|
17
|
-
*/
|
18
|
-
context: Value<UContext>;
|
19
|
-
}> & Hooks<unknown, SchemaOutput<UOutputSchema, UFuncOutput>, UContext, {
|
20
|
-
path: string[];
|
21
|
-
procedure: ANY_PROCEDURE;
|
22
|
-
}> : never;
|
23
|
-
export type ProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? Caller<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>> : never;
|
24
|
-
export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>;
|
25
|
-
export declare function loadProcedure(procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE): Promise<ANY_PROCEDURE>;
|
26
|
-
//# sourceMappingURL=procedure-caller.d.ts.map
|