@orpc/server 0.25.0 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-B2EZJB7X.js → chunk-6BY63WA5.js} +2 -2
- package/dist/{chunk-6A7XHEBH.js → chunk-E7GUWVR4.js} +12 -15
- package/dist/fetch.js +2 -2
- package/dist/index.js +6 -6
- package/dist/node.js +2 -2
- package/dist/src/builder.d.ts +2 -2
- package/dist/src/middleware.d.ts +16 -6
- package/dist/src/procedure-builder.d.ts +2 -2
- package/dist/src/procedure-implementer.d.ts +2 -2
- package/dist/src/procedure.d.ts +11 -4
- package/dist/src/types.d.ts +2 -0
- package/package.json +3 -3
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
getRouterChild,
|
5
5
|
isProcedure,
|
6
6
|
unlazy
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-E7GUWVR4.js";
|
8
8
|
|
9
9
|
// src/adapters/fetch/super-json.ts
|
10
10
|
var super_json_exports = {};
|
@@ -300,4 +300,4 @@ export {
|
|
300
300
|
ORPCProcedureMatcher,
|
301
301
|
ORPCHandler
|
302
302
|
};
|
303
|
-
//# sourceMappingURL=chunk-
|
303
|
+
//# sourceMappingURL=chunk-6BY63WA5.js.map
|
@@ -74,12 +74,13 @@ function createProcedureClient(options) {
|
|
74
74
|
};
|
75
75
|
const executeWithValidation = async () => {
|
76
76
|
const validInput = await validateInput(procedure, input);
|
77
|
-
const output = await executeMiddlewareChain(
|
78
|
-
procedure,
|
79
|
-
validInput,
|
77
|
+
const output = await executeMiddlewareChain({
|
80
78
|
context,
|
81
|
-
|
82
|
-
|
79
|
+
input: validInput,
|
80
|
+
path,
|
81
|
+
procedure,
|
82
|
+
signal: callerOptions?.signal
|
83
|
+
});
|
83
84
|
return validateOutput(procedure, output);
|
84
85
|
};
|
85
86
|
return executeWithHooks({
|
@@ -119,23 +120,19 @@ async function validateOutput(procedure, output) {
|
|
119
120
|
}
|
120
121
|
return result.value;
|
121
122
|
}
|
122
|
-
async function executeMiddlewareChain(
|
123
|
-
const middlewares = procedure["~orpc"].middlewares ?? [];
|
123
|
+
async function executeMiddlewareChain(opt) {
|
124
|
+
const middlewares = opt.procedure["~orpc"].middlewares ?? [];
|
124
125
|
let currentMidIndex = 0;
|
125
|
-
let currentContext = context;
|
126
|
+
let currentContext = opt.context;
|
126
127
|
const next = async (nextOptions) => {
|
127
128
|
const mid = middlewares[currentMidIndex];
|
128
129
|
currentMidIndex += 1;
|
129
130
|
currentContext = mergeContext(currentContext, nextOptions.context);
|
130
131
|
if (mid) {
|
131
|
-
return await mid(
|
132
|
-
...meta,
|
133
|
-
next,
|
134
|
-
output: (output) => ({ output, context: void 0 })
|
135
|
-
});
|
132
|
+
return await mid({ ...opt, context: currentContext, next }, opt.input, (output) => ({ output, context: void 0 }));
|
136
133
|
}
|
137
134
|
const result = {
|
138
|
-
output: await procedure["~orpc"].handler(
|
135
|
+
output: await opt.procedure["~orpc"].handler({ ...opt, context: currentContext }),
|
139
136
|
context: currentContext
|
140
137
|
};
|
141
138
|
return result;
|
@@ -186,4 +183,4 @@ export {
|
|
186
183
|
createProcedureClient,
|
187
184
|
getRouterChild
|
188
185
|
};
|
189
|
-
//# sourceMappingURL=chunk-
|
186
|
+
//# sourceMappingURL=chunk-E7GUWVR4.js.map
|
package/dist/fetch.js
CHANGED
@@ -3,8 +3,8 @@ import {
|
|
3
3
|
ORPCPayloadCodec,
|
4
4
|
ORPCProcedureMatcher,
|
5
5
|
super_json_exports
|
6
|
-
} from "./chunk-
|
7
|
-
import "./chunk-
|
6
|
+
} from "./chunk-6BY63WA5.js";
|
7
|
+
import "./chunk-E7GUWVR4.js";
|
8
8
|
|
9
9
|
// src/adapters/fetch/composite-handler.ts
|
10
10
|
var CompositeHandler = class {
|
package/dist/index.js
CHANGED
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
lazy,
|
10
10
|
mergeContext,
|
11
11
|
unlazy
|
12
|
-
} from "./chunk-
|
12
|
+
} from "./chunk-E7GUWVR4.js";
|
13
13
|
|
14
14
|
// src/builder.ts
|
15
15
|
import { ContractProcedure } from "@orpc/contract";
|
@@ -23,17 +23,17 @@ function decorateMiddleware(middleware) {
|
|
23
23
|
const decorated = middleware;
|
24
24
|
decorated.mapInput = (mapInput) => {
|
25
25
|
const mapped = decorateMiddleware(
|
26
|
-
(input, ...rest) => middleware(mapInput(input), ...rest)
|
26
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
27
27
|
);
|
28
28
|
return mapped;
|
29
29
|
};
|
30
30
|
decorated.concat = (concatMiddleware, mapInput) => {
|
31
31
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
32
|
-
const concatted = decorateMiddleware((
|
33
|
-
const next = async (
|
34
|
-
return mapped(
|
32
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
33
|
+
const next = async (nextOptions) => {
|
34
|
+
return mapped({ ...options, context: mergeContext(nextOptions.context, options.context) }, input, output, ...rest);
|
35
35
|
};
|
36
|
-
const merged = middleware(
|
36
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
37
37
|
return merged;
|
38
38
|
});
|
39
39
|
return concatted;
|
package/dist/node.js
CHANGED
package/dist/src/builder.d.ts
CHANGED
@@ -6,7 +6,7 @@ import type { Router } from './router';
|
|
6
6
|
import type { AdaptedRouter } from './router-builder';
|
7
7
|
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
8
8
|
import { type ChainableImplementer } from './implementer-chainable';
|
9
|
-
import { type
|
9
|
+
import { type ProcedureHandler } from './procedure';
|
10
10
|
import { ProcedureBuilder } from './procedure-builder';
|
11
11
|
import { type DecoratedProcedure } from './procedure-decorated';
|
12
12
|
import { RouterBuilder } from './router-builder';
|
@@ -23,7 +23,7 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
23
23
|
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
24
24
|
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
25
25
|
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
26
|
-
handler<UFuncOutput = undefined>(handler:
|
26
|
+
handler<UFuncOutput = undefined>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
|
27
27
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
28
28
|
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
29
29
|
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,19 +1,29 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
2
|
+
import type { ANY_PROCEDURE } from './procedure';
|
3
|
+
import type { Context } from './types';
|
3
4
|
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
4
5
|
output: TOutput;
|
5
6
|
context: TExtraContext;
|
6
7
|
}>;
|
7
|
-
export interface
|
8
|
-
|
8
|
+
export interface MiddlewareNextFn<TOutput> {
|
9
|
+
<UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
|
9
10
|
context?: UExtraContext;
|
10
11
|
} : {
|
11
12
|
context: UExtraContext;
|
12
|
-
})
|
13
|
-
|
13
|
+
}): MiddlewareResult<UExtraContext, TOutput>;
|
14
|
+
}
|
15
|
+
export interface MiddlewareOutputFn<TOutput> {
|
16
|
+
(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
17
|
+
}
|
18
|
+
export interface MiddlewareOptions<TContext extends Context, TOutput> {
|
19
|
+
context: TContext;
|
20
|
+
path: string[];
|
21
|
+
procedure: ANY_PROCEDURE;
|
22
|
+
signal?: AbortSignal;
|
23
|
+
next: MiddlewareNextFn<TOutput>;
|
14
24
|
}
|
15
25
|
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput> {
|
16
|
-
(
|
26
|
+
(options: MiddlewareOptions<TContext, TOutput>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
17
27
|
}
|
18
28
|
export type ANY_MIDDLEWARE = Middleware<any, any, any, any>;
|
19
29
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
@@ -2,7 +2,7 @@ import type { MapInputMiddleware, Middleware } from './middleware';
|
|
2
2
|
import type { DecoratedProcedure } from './procedure-decorated';
|
3
3
|
import type { Context, MergeContext } from './types';
|
4
4
|
import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
5
|
-
import { type
|
5
|
+
import { type ProcedureHandler } from './procedure';
|
6
6
|
import { ProcedureImplementer } from './procedure-implementer';
|
7
7
|
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
8
8
|
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
@@ -17,6 +17,6 @@ export declare class ProcedureBuilder<TContext extends Context, TExtraContext ex
|
|
17
17
|
output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U>;
|
18
18
|
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
|
19
19
|
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
|
20
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler:
|
20
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
21
21
|
}
|
22
22
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type {
|
3
|
+
import type { ProcedureHandler } from './procedure';
|
4
4
|
import type { DecoratedProcedure } from './procedure-decorated';
|
5
5
|
import type { Context, MergeContext } from './types';
|
6
6
|
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> = {
|
@@ -13,6 +13,6 @@ export declare class ProcedureImplementer<TContext extends Context, TExtraContex
|
|
13
13
|
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
14
14
|
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
|
15
15
|
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
|
16
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler:
|
16
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
17
17
|
}
|
18
18
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
2
|
import type { Lazy } from './lazy';
|
3
3
|
import type { Middleware } from './middleware';
|
4
|
-
import type { Context, MergeContext
|
4
|
+
import type { AbortSignal, Context, MergeContext } from './types';
|
5
5
|
import { type ContractProcedure, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
6
|
-
export interface
|
7
|
-
|
6
|
+
export interface ProcedureHandlerOptions<TContext extends Context, TInput> {
|
7
|
+
context: TContext;
|
8
|
+
input: TInput;
|
9
|
+
path: string[];
|
10
|
+
procedure: ANY_PROCEDURE;
|
11
|
+
signal?: AbortSignal;
|
12
|
+
}
|
13
|
+
export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
|
14
|
+
(opt: ProcedureHandlerOptions<MergeContext<TContext, TExtraContext>, SchemaOutput<TInputSchema>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
8
15
|
}
|
9
16
|
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
|
10
17
|
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, any>[];
|
11
18
|
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
12
|
-
handler:
|
19
|
+
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
13
20
|
}
|
14
21
|
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> {
|
15
22
|
'~type': "Procedure";
|
package/dist/src/types.d.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
import type { FindGlobalInstanceType } from '@orpc/shared';
|
1
2
|
import type { ANY_PROCEDURE } from './procedure';
|
2
3
|
export type Context = Record<string, any> | undefined;
|
3
4
|
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
4
5
|
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
6
|
+
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
5
7
|
export interface WithSignal {
|
6
8
|
signal?: AbortSignal;
|
7
9
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.26.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -40,8 +40,8 @@
|
|
40
40
|
],
|
41
41
|
"dependencies": {
|
42
42
|
"@mjackson/node-fetch-server": "^0.5.0",
|
43
|
-
"@orpc/contract": "0.
|
44
|
-
"@orpc/shared": "0.
|
43
|
+
"@orpc/contract": "0.26.0",
|
44
|
+
"@orpc/shared": "0.26.0"
|
45
45
|
},
|
46
46
|
"devDependencies": {
|
47
47
|
"zod": "^3.24.1"
|