@orpc/server 0.0.0-next.db1f26d → 0.0.0-next.ee0aeaf
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-FL4ZAGNE.js → chunk-VARUID7X.js} +94 -88
- package/dist/fetch.js +12 -8
- package/dist/index.js +18 -39
- package/dist/src/builder.d.ts +4 -3
- package/dist/src/fetch/types.d.ts +3 -10
- package/dist/src/procedure-caller.d.ts +16 -10
- package/dist/src/router-caller.d.ts +5 -2
- package/dist/src/router-implementer.d.ts +4 -4
- package/dist/src/router.d.ts +4 -5
- package/dist/src/types.d.ts +7 -1
- package/package.json +6 -7
@@ -45,9 +45,8 @@ function decorateMiddleware(middleware) {
|
|
45
45
|
}
|
46
46
|
|
47
47
|
// src/procedure-caller.ts
|
48
|
-
import { trim, value } from "@orpc/shared";
|
48
|
+
import { executeWithHooks, trim, value } from "@orpc/shared";
|
49
49
|
import { ORPCError } from "@orpc/shared/error";
|
50
|
-
import { OpenAPIDeserializer } from "@orpc/transformer";
|
51
50
|
|
52
51
|
// src/procedure.ts
|
53
52
|
import {
|
@@ -109,96 +108,102 @@ function isProcedure(item) {
|
|
109
108
|
|
110
109
|
// src/procedure-caller.ts
|
111
110
|
function createProcedureCaller(options) {
|
112
|
-
const
|
113
|
-
|
114
|
-
if (isLazy(options.procedure)) {
|
115
|
-
procedure = (await loadLazy(options.procedure)).default;
|
116
|
-
} else {
|
117
|
-
procedure = options.procedure;
|
118
|
-
}
|
119
|
-
if (!isProcedure(procedure)) {
|
120
|
-
throw new ORPCError({
|
121
|
-
code: "NOT_FOUND",
|
122
|
-
message: "Not found",
|
123
|
-
cause: new Error(trim(`
|
124
|
-
This error should be caught by the typescript compiler.
|
125
|
-
But if you still see this error, it means that you trying to call a lazy router (expected to be a lazy procedure).
|
126
|
-
`))
|
127
|
-
});
|
128
|
-
}
|
129
|
-
return procedure;
|
130
|
-
};
|
131
|
-
const caller = async (input) => {
|
111
|
+
const caller = async (...args) => {
|
112
|
+
const [input, callerOptions] = args;
|
132
113
|
const path = options.path ?? [];
|
133
|
-
const procedure = await loadProcedure();
|
134
|
-
const
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
return
|
150
|
-
}
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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;
|
181
173
|
};
|
182
|
-
const output =
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
cause: result.error
|
194
|
-
});
|
195
|
-
}
|
196
|
-
return result.data;
|
197
|
-
})();
|
198
|
-
return validOutput;
|
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;
|
199
185
|
};
|
200
186
|
return caller;
|
201
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
|
+
}
|
202
207
|
|
203
208
|
// src/lazy.ts
|
204
209
|
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
@@ -260,8 +265,9 @@ export {
|
|
260
265
|
createFlattenLazy,
|
261
266
|
decorateLazy,
|
262
267
|
createProcedureCaller,
|
268
|
+
loadProcedure,
|
263
269
|
Procedure,
|
264
270
|
decorateProcedure,
|
265
271
|
isProcedure
|
266
272
|
};
|
267
|
-
//# sourceMappingURL=chunk-
|
273
|
+
//# sourceMappingURL=chunk-VARUID7X.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-VARUID7X.js";
|
6
6
|
|
7
7
|
// src/fetch/handle.ts
|
8
8
|
import { ORPCError } from "@orpc/shared/error";
|
@@ -23,15 +23,14 @@ async function handleFetchRequest(options) {
|
|
23
23
|
}
|
24
24
|
|
25
25
|
// src/fetch/handler.ts
|
26
|
-
import {
|
27
|
-
import { trim, value } from "@orpc/shared";
|
26
|
+
import { executeWithHooks, ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim, value } from "@orpc/shared";
|
28
27
|
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
29
28
|
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
30
29
|
var serializer = new ORPCSerializer();
|
31
30
|
var deserializer = new ORPCDeserializer();
|
32
31
|
function createORPCHandler() {
|
33
32
|
return async (options) => {
|
34
|
-
if (options.request.headers.get(
|
33
|
+
if (!options.request.headers.get(ORPC_PROTOCOL_HEADER)?.includes(ORPC_PROTOCOL_VALUE)) {
|
35
34
|
return void 0;
|
36
35
|
}
|
37
36
|
const context = await value(options.context);
|
@@ -48,7 +47,7 @@ function createORPCHandler() {
|
|
48
47
|
procedure: match.procedure,
|
49
48
|
path: match.path
|
50
49
|
});
|
51
|
-
const output = await caller(input);
|
50
|
+
const output = await caller(input, { signal: options.signal });
|
52
51
|
const { body, headers } = serializer.serialize(output);
|
53
52
|
return new Response(body, {
|
54
53
|
status: 200,
|
@@ -56,10 +55,15 @@ function createORPCHandler() {
|
|
56
55
|
});
|
57
56
|
};
|
58
57
|
try {
|
59
|
-
return await
|
58
|
+
return await executeWithHooks({
|
59
|
+
hooks: options,
|
60
60
|
context,
|
61
|
-
|
62
|
-
|
61
|
+
execute: handler,
|
62
|
+
input: options.request,
|
63
|
+
meta: {
|
64
|
+
signal: options.signal
|
65
|
+
}
|
66
|
+
});
|
63
67
|
} catch (e) {
|
64
68
|
const error = e instanceof ORPCError2 ? e : new ORPCError2({
|
65
69
|
code: "INTERNAL_SERVER_ERROR",
|
package/dist/index.js
CHANGED
@@ -10,8 +10,9 @@ import {
|
|
10
10
|
isLazy,
|
11
11
|
isProcedure,
|
12
12
|
loadLazy,
|
13
|
+
loadProcedure,
|
13
14
|
mergeContext
|
14
|
-
} from "./chunk-
|
15
|
+
} from "./chunk-VARUID7X.js";
|
15
16
|
|
16
17
|
// src/builder.ts
|
17
18
|
import {
|
@@ -25,7 +26,7 @@ import {
|
|
25
26
|
} from "@orpc/contract";
|
26
27
|
|
27
28
|
// src/router-builder.ts
|
28
|
-
import { DecoratedContractProcedure
|
29
|
+
import { DecoratedContractProcedure } from "@orpc/contract";
|
29
30
|
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
30
31
|
var RouterBuilder = class _RouterBuilder {
|
31
32
|
constructor(zz$rb) {
|
@@ -108,7 +109,7 @@ function adaptLazyRouter(options) {
|
|
108
109
|
};
|
109
110
|
let lazyRouterPrefix = options.prefix;
|
110
111
|
if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") {
|
111
|
-
lazyRouterPrefix =
|
112
|
+
lazyRouterPrefix = `${options.current[LAZY_ROUTER_PREFIX_SYMBOL]}${lazyRouterPrefix ?? ""}`;
|
112
113
|
}
|
113
114
|
const decoratedLazy = Object.assign(decorateLazy(createLazy(loader)), {
|
114
115
|
[LAZY_ROUTER_PREFIX_SYMBOL]: lazyRouterPrefix
|
@@ -140,7 +141,7 @@ function adaptProcedure(options) {
|
|
140
141
|
];
|
141
142
|
let contract = DecoratedContractProcedure.decorate(
|
142
143
|
options.procedure.zz$p.contract
|
143
|
-
).
|
144
|
+
).pushTag(...options.tags ?? []);
|
144
145
|
if (options.prefix) {
|
145
146
|
contract = contract.prefix(options.prefix);
|
146
147
|
}
|
@@ -297,11 +298,11 @@ var Builder = class _Builder {
|
|
297
298
|
/**
|
298
299
|
* Convert to ContractProcedureBuilder
|
299
300
|
*/
|
300
|
-
route(
|
301
|
+
route(route) {
|
301
302
|
return new ProcedureBuilder({
|
302
303
|
middlewares: this.zz$b.middlewares,
|
303
304
|
contract: new ContractProcedure({
|
304
|
-
|
305
|
+
route,
|
305
306
|
InputSchema: void 0,
|
306
307
|
OutputSchema: void 0
|
307
308
|
})
|
@@ -388,49 +389,27 @@ var Builder = class _Builder {
|
|
388
389
|
}
|
389
390
|
};
|
390
391
|
|
391
|
-
// src/router.ts
|
392
|
-
import {
|
393
|
-
isContractProcedure as isContractProcedure3
|
394
|
-
} from "@orpc/contract";
|
395
|
-
function toContractRouter(router) {
|
396
|
-
const contract = {};
|
397
|
-
for (const key in router) {
|
398
|
-
const item = router[key];
|
399
|
-
if (isContractProcedure3(item)) {
|
400
|
-
contract[key] = item;
|
401
|
-
} else if (isProcedure(item)) {
|
402
|
-
contract[key] = item.zz$p.contract;
|
403
|
-
} else {
|
404
|
-
contract[key] = toContractRouter(item);
|
405
|
-
}
|
406
|
-
}
|
407
|
-
return contract;
|
408
|
-
}
|
409
|
-
|
410
392
|
// src/router-caller.ts
|
411
393
|
function createRouterCaller(options) {
|
412
|
-
return createRouterCallerInternal(
|
413
|
-
current: options.router,
|
414
|
-
context: options.context,
|
415
|
-
path: options.basePath ?? []
|
416
|
-
});
|
394
|
+
return createRouterCallerInternal(options);
|
417
395
|
}
|
418
396
|
function createRouterCallerInternal(options) {
|
419
|
-
const procedureCaller = isLazy(options.
|
420
|
-
|
397
|
+
const procedureCaller = isLazy(options.router) || isProcedure(options.router) ? createProcedureCaller({
|
398
|
+
...options,
|
399
|
+
procedure: options.router,
|
421
400
|
context: options.context,
|
422
|
-
path: options.
|
401
|
+
path: options.basePath
|
423
402
|
}) : {};
|
424
403
|
const recursive = new Proxy(procedureCaller, {
|
425
404
|
get(target, key) {
|
426
405
|
if (typeof key !== "string") {
|
427
406
|
return Reflect.get(target, key);
|
428
407
|
}
|
429
|
-
const next = options.
|
408
|
+
const next = options.router[key];
|
430
409
|
return createRouterCallerInternal({
|
431
|
-
|
432
|
-
|
433
|
-
|
410
|
+
...options,
|
411
|
+
router: next,
|
412
|
+
basePath: [...options.basePath ?? [], key]
|
434
413
|
});
|
435
414
|
}
|
436
415
|
});
|
@@ -461,8 +440,8 @@ export {
|
|
461
440
|
isLazy,
|
462
441
|
isProcedure,
|
463
442
|
loadLazy,
|
443
|
+
loadProcedure,
|
464
444
|
mergeContext,
|
465
|
-
os
|
466
|
-
toContractRouter
|
445
|
+
os
|
467
446
|
};
|
468
447
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { IsEqual } from '@orpc/shared';
|
2
3
|
import type { DecoratedLazy } from './lazy';
|
3
4
|
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
|
4
5
|
import type { HandledRouter, Router } from './router';
|
5
6
|
import type { Context, MergeContext } from './types';
|
6
|
-
import { ContractProcedure
|
7
|
+
import { ContractProcedure } from '@orpc/contract';
|
7
8
|
import { type DecoratedMiddleware, type MapInputMiddleware, type Middleware } from './middleware';
|
8
9
|
import { ProcedureBuilder } from './procedure-builder';
|
9
10
|
import { ProcedureImplementer } from './procedure-implementer';
|
@@ -25,7 +26,7 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
25
26
|
/**
|
26
27
|
* Convert to ContractProcedureBuilder
|
27
28
|
*/
|
28
|
-
route(
|
29
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
29
30
|
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
30
31
|
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
31
32
|
/**
|
@@ -35,7 +36,7 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
35
36
|
/**
|
36
37
|
* Convert to ProcedureImplementer | RouterBuilder
|
37
38
|
*/
|
38
|
-
contract<UContract extends
|
39
|
+
contract<UContract extends ANY_CONTRACT_PROCEDURE | ContractRouter>(contract: UContract): UContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : UContract extends ContractRouter ? ChainedRouterImplementer<TContext, UContract, TExtraContext> : never;
|
39
40
|
/**
|
40
41
|
* Create ExtendedMiddleware
|
41
42
|
*/
|
@@ -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
|
@@ -1,20 +1,26 @@
|
|
1
1
|
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
2
3
|
import type { Lazy } from './lazy';
|
3
|
-
import {
|
4
|
-
import
|
5
|
-
export
|
6
|
-
procedure:
|
7
|
-
/**
|
8
|
-
* The context used when calling the procedure.
|
9
|
-
*/
|
10
|
-
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> | Lazy<Procedure<infer UContext, any, any, any, any>> ? UContext : never>;
|
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;
|
11
8
|
/**
|
12
9
|
* This is helpful for logging and analytics.
|
13
10
|
*
|
14
11
|
* @internal
|
15
12
|
*/
|
16
13
|
path?: string[];
|
17
|
-
}
|
18
|
-
|
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;
|
19
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>;
|
20
26
|
//# sourceMappingURL=procedure-caller.d.ts.map
|
@@ -1,8 +1,11 @@
|
|
1
|
-
import type { Value } from '@orpc/shared';
|
1
|
+
import type { Hooks, Value } from '@orpc/shared';
|
2
2
|
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE } from './procedure';
|
3
3
|
import type { Router } from './router';
|
4
4
|
import { type ProcedureCaller } from './procedure-caller';
|
5
|
-
export interface CreateRouterCallerOptions<TRouter extends Router<any>> {
|
5
|
+
export interface CreateRouterCallerOptions<TRouter extends Router<any>> extends Hooks<unknown, unknown, TRouter extends Router<infer UContext> ? UContext : never, {
|
6
|
+
path: string[];
|
7
|
+
procedure: ANY_PROCEDURE;
|
8
|
+
}> {
|
6
9
|
router: TRouter;
|
7
10
|
/**
|
8
11
|
* The context used when calling the procedure.
|
@@ -12,10 +12,10 @@ export declare class RouterImplementer<TContext extends Context, TContract exten
|
|
12
12
|
constructor(zz$ri: {
|
13
13
|
contract: TContract;
|
14
14
|
});
|
15
|
-
router
|
16
|
-
lazy(loader: () => Promise<{
|
17
|
-
default:
|
18
|
-
}>): DecoratedLazy<
|
15
|
+
router<U extends RouterWithContract<TContext, TContract>>(router: U): HandledRouter<U>;
|
16
|
+
lazy<U extends RouterWithContract<TContext, TContract>>(loader: () => Promise<{
|
17
|
+
default: U;
|
18
|
+
}>): DecoratedLazy<U>;
|
19
19
|
}
|
20
20
|
export type ChainedRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context> = {
|
21
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;
|
package/dist/src/router.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { ANY_LAZY, DecoratedLazy, Lazy } from './lazy';
|
3
|
+
import type { DecoratedProcedure, Procedure } from './procedure';
|
3
4
|
import type { Context } from './types';
|
4
|
-
import { type DecoratedProcedure, type Procedure } from './procedure';
|
5
5
|
export interface Router<TContext extends Context> {
|
6
6
|
[k: string]: Procedure<TContext, any, any, any, any> | Lazy<Procedure<TContext, any, any, any, any>> | Router<TContext> | Lazy<Router<TContext>>;
|
7
7
|
}
|
@@ -9,13 +9,12 @@ 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
|
-
export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter;
|
15
14
|
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;
|
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;
|
17
16
|
};
|
18
17
|
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;
|
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;
|
20
19
|
};
|
21
20
|
//# 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.ee0aeaf",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -34,16 +34,15 @@
|
|
34
34
|
"dist"
|
35
35
|
],
|
36
36
|
"peerDependencies": {
|
37
|
-
"zod": "
|
38
|
-
"@orpc/zod": "0.0.0-next.db1f26d"
|
37
|
+
"@orpc/zod": "0.0.0-next.ee0aeaf"
|
39
38
|
},
|
40
39
|
"dependencies": {
|
41
|
-
"@orpc/
|
42
|
-
"@orpc/
|
43
|
-
"@orpc/
|
40
|
+
"@orpc/shared": "0.0.0-next.ee0aeaf",
|
41
|
+
"@orpc/transformer": "0.0.0-next.ee0aeaf",
|
42
|
+
"@orpc/contract": "0.0.0-next.ee0aeaf"
|
44
43
|
},
|
45
44
|
"devDependencies": {
|
46
|
-
"@orpc/openapi": "0.0.0-next.
|
45
|
+
"@orpc/openapi": "0.0.0-next.ee0aeaf"
|
47
46
|
},
|
48
47
|
"scripts": {
|
49
48
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|