@orpc/server 0.14.0 → 0.15.0
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.
@@ -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";
|
@@ -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,
|
@@ -61,7 +61,9 @@ function createORPCHandler() {
|
|
61
61
|
context,
|
62
62
|
execute: handler,
|
63
63
|
input: options.request,
|
64
|
-
meta:
|
64
|
+
meta: {
|
65
|
+
signal: options.signal
|
66
|
+
}
|
65
67
|
});
|
66
68
|
} catch (e) {
|
67
69
|
const error = e instanceof ORPCError2 ? e : new ORPCError2({
|
package/dist/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
2
2
|
import type { Router } from '../router';
|
3
|
+
import type { CallerOptions } from '../types';
|
3
4
|
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
4
5
|
/**
|
5
6
|
* The `router` used for handling the request and routing,
|
@@ -22,6 +23,6 @@ export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
|
22
23
|
* The context used to handle the request.
|
23
24
|
*/
|
24
25
|
context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
|
25
|
-
}> & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never,
|
26
|
+
}> & CallerOptions & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, CallerOptions>;
|
26
27
|
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
|
27
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
@@ -9,7 +9,7 @@ export type HandledRouter<TRouter extends Router<any>> = {
|
|
9
9
|
[K in keyof TRouter]: TRouter[K] extends Procedure<infer UContext, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends ANY_LAZY ? DecoratedLazy<TRouter[K]> : TRouter[K] extends Router<any> ? HandledRouter<TRouter[K]> : never;
|
10
10
|
};
|
11
11
|
export type RouterWithContract<TContext extends Context, TContract extends ContractRouter> = {
|
12
|
-
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> | Lazy<Procedure<TContext, any, UInputSchema, UOutputSchema, any>> : TContract[K] extends ContractRouter ? RouterWithContract<TContext, TContract[K]>
|
12
|
+
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> | Lazy<Procedure<TContext, any, UInputSchema, UOutputSchema, any>> : TContract[K] extends ContractRouter ? RouterWithContract<TContext, TContract[K]> : never;
|
13
13
|
};
|
14
14
|
export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter;
|
15
15
|
export type InferRouterInputs<T extends Router<any>> = {
|
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.
|
4
|
+
"version": "0.15.0",
|
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.
|
38
|
+
"@orpc/zod": "0.15.0"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@orpc/
|
42
|
-
"@orpc/
|
43
|
-
"@orpc/
|
41
|
+
"@orpc/contract": "0.15.0",
|
42
|
+
"@orpc/shared": "0.15.0",
|
43
|
+
"@orpc/transformer": "0.15.0"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
|
-
"@orpc/openapi": "0.
|
46
|
+
"@orpc/openapi": "0.15.0"
|
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'",
|