@orpc/server 0.0.0-next.a055cad → 0.0.0-next.a895960
Sign up to get free protection for your applications and to get access to all the features.
@@ -108,7 +108,8 @@ function isProcedure(item) {
|
|
108
108
|
|
109
109
|
// src/procedure-caller.ts
|
110
110
|
function createProcedureCaller(options) {
|
111
|
-
const caller = async (
|
111
|
+
const caller = async (...args) => {
|
112
|
+
const [input, callerOptions] = args;
|
112
113
|
const path = options.path ?? [];
|
113
114
|
const procedure = await loadProcedure(options.procedure);
|
114
115
|
const context = await value(options.context);
|
@@ -128,6 +129,11 @@ function createProcedureCaller(options) {
|
|
128
129
|
});
|
129
130
|
}
|
130
131
|
})();
|
132
|
+
const meta = {
|
133
|
+
path,
|
134
|
+
procedure,
|
135
|
+
signal: callerOptions?.signal
|
136
|
+
};
|
131
137
|
const middlewares = procedure.zz$p.middlewares ?? [];
|
132
138
|
let currentMidIndex = 0;
|
133
139
|
let currentContext = context;
|
@@ -137,17 +143,13 @@ function createProcedureCaller(options) {
|
|
137
143
|
currentContext = mergeContext(currentContext, nextOptions.context);
|
138
144
|
if (mid) {
|
139
145
|
return await mid(validInput, currentContext, {
|
140
|
-
|
141
|
-
procedure,
|
146
|
+
...meta,
|
142
147
|
next,
|
143
148
|
output: (output3) => ({ output: output3, context: void 0 })
|
144
149
|
});
|
145
150
|
} else {
|
146
151
|
return {
|
147
|
-
output: await await procedure.zz$p.func(validInput, currentContext,
|
148
|
-
path,
|
149
|
-
procedure
|
150
|
-
}),
|
152
|
+
output: await await procedure.zz$p.func(validInput, currentContext, meta),
|
151
153
|
context: currentContext
|
152
154
|
};
|
153
155
|
}
|
@@ -269,4 +271,4 @@ export {
|
|
269
271
|
decorateProcedure,
|
270
272
|
isProcedure
|
271
273
|
};
|
272
|
-
//# sourceMappingURL=chunk-
|
274
|
+
//# sourceMappingURL=chunk-3JMSDC5L.js.map
|
package/dist/fetch.js
CHANGED
@@ -2,7 +2,7 @@ import {
|
|
2
2
|
createProcedureCaller,
|
3
3
|
isLazy,
|
4
4
|
isProcedure
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-3JMSDC5L.js";
|
6
6
|
|
7
7
|
// src/fetch/handle.ts
|
8
8
|
import { ORPCError } from "@orpc/shared/error";
|
@@ -24,7 +24,7 @@ async function handleFetchRequest(options) {
|
|
24
24
|
|
25
25
|
// src/fetch/handler.ts
|
26
26
|
import { ORPC_HEADER, ORPC_HEADER_VALUE } from "@orpc/contract";
|
27
|
-
import { trim, value } from "@orpc/shared";
|
27
|
+
import { executeWithHooks, trim, value } from "@orpc/shared";
|
28
28
|
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
29
29
|
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
30
30
|
var serializer = new ORPCSerializer();
|
@@ -48,7 +48,7 @@ function createORPCHandler() {
|
|
48
48
|
procedure: match.procedure,
|
49
49
|
path: match.path
|
50
50
|
});
|
51
|
-
const output = await caller(input);
|
51
|
+
const output = await caller(input, { signal: options.signal });
|
52
52
|
const { body, headers } = serializer.serialize(output);
|
53
53
|
return new Response(body, {
|
54
54
|
status: 200,
|
@@ -56,10 +56,15 @@ function createORPCHandler() {
|
|
56
56
|
});
|
57
57
|
};
|
58
58
|
try {
|
59
|
-
return await
|
59
|
+
return await executeWithHooks({
|
60
|
+
hooks: options,
|
60
61
|
context,
|
61
|
-
|
62
|
-
|
62
|
+
execute: handler,
|
63
|
+
input: options.request,
|
64
|
+
meta: {
|
65
|
+
signal: options.signal
|
66
|
+
}
|
67
|
+
});
|
63
68
|
} catch (e) {
|
64
69
|
const error = e instanceof ORPCError2 ? e : new ORPCError2({
|
65
70
|
code: "INTERNAL_SERVER_ERROR",
|
package/dist/index.js
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
2
2
|
import type { Router } from '../router';
|
3
|
-
|
4
|
-
next: () => Promise<Response>;
|
5
|
-
response: (response: Response) => Response;
|
6
|
-
}
|
3
|
+
import type { CallerOptions } from '../types';
|
7
4
|
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
8
5
|
/**
|
9
6
|
* The `router` used for handling the request and routing,
|
@@ -21,15 +18,11 @@ export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
|
21
18
|
* @example /api
|
22
19
|
*/
|
23
20
|
prefix?: string;
|
24
|
-
/**
|
25
|
-
* Hooks for executing logics on lifecycle events.
|
26
|
-
*/
|
27
|
-
hooks?: (context: TRouter extends Router<infer UContext> ? UContext : never, hooks: FetchHandlerHooks) => Promisable<Response>;
|
28
21
|
} & PartialOnUndefinedDeep<{
|
29
22
|
/**
|
30
23
|
* The context used to handle the request.
|
31
24
|
*/
|
32
25
|
context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
|
33
|
-
}>;
|
26
|
+
}> & CallerOptions & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, CallerOptions>;
|
34
27
|
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
|
35
28
|
//# sourceMappingURL=types.d.ts.map
|
@@ -2,6 +2,7 @@ import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
|
2
2
|
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
3
3
|
import type { Lazy } from './lazy';
|
4
4
|
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Procedure } from './procedure';
|
5
|
+
import type { Caller } from './types';
|
5
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>> ? {
|
6
7
|
procedure: T;
|
7
8
|
/**
|
@@ -19,7 +20,7 @@ export type CreateProcedureCallerOptions<T extends ANY_PROCEDURE | ANY_LAZY_PROC
|
|
19
20
|
path: string[];
|
20
21
|
procedure: ANY_PROCEDURE;
|
21
22
|
}> : never;
|
22
|
-
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>> ?
|
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;
|
23
24
|
export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>;
|
24
25
|
export declare function loadProcedure(procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE): Promise<ANY_PROCEDURE>;
|
25
26
|
//# sourceMappingURL=procedure-caller.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -13,9 +13,9 @@ export type RouterWithContract<TContext extends Context, TContract extends Contr
|
|
13
13
|
};
|
14
14
|
export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter;
|
15
15
|
export type InferRouterInputs<T extends Router<any>> = {
|
16
|
-
[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
|
+
[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;
|
17
17
|
};
|
18
18
|
export type InferRouterOutputs<T extends Router<any>> = {
|
19
|
-
[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;
|
19
|
+
[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;
|
20
20
|
};
|
21
21
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
import type { WELL_DEFINED_PROCEDURE } from './procedure';
|
2
2
|
export type Context = Record<string, unknown> | undefined;
|
3
3
|
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
4
|
-
export interface
|
4
|
+
export interface CallerOptions {
|
5
|
+
signal?: AbortSignal;
|
6
|
+
}
|
7
|
+
export interface Caller<TInput, TOutput> {
|
8
|
+
(...opts: [input: TInput, options?: CallerOptions] | (undefined extends TInput ? [] : never)): Promise<TOutput>;
|
9
|
+
}
|
10
|
+
export interface Meta extends CallerOptions {
|
5
11
|
path: string[];
|
6
12
|
procedure: WELL_DEFINED_PROCEDURE;
|
7
13
|
}
|
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.a895960",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -35,15 +35,15 @@
|
|
35
35
|
],
|
36
36
|
"peerDependencies": {
|
37
37
|
"zod": ">=3.23.0",
|
38
|
-
"@orpc/zod": "0.0.0-next.
|
38
|
+
"@orpc/zod": "0.0.0-next.a895960"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@orpc/contract": "0.0.0-next.
|
42
|
-
"@orpc/
|
43
|
-
"@orpc/
|
41
|
+
"@orpc/contract": "0.0.0-next.a895960",
|
42
|
+
"@orpc/shared": "0.0.0-next.a895960",
|
43
|
+
"@orpc/transformer": "0.0.0-next.a895960"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
|
-
"@orpc/openapi": "0.0.0-next.
|
46
|
+
"@orpc/openapi": "0.0.0-next.a895960"
|
47
47
|
},
|
48
48
|
"scripts": {
|
49
49
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|