@orpc/server 0.0.0-next.3f3f19b → 0.0.0-next.4555a17
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.
@@ -114,20 +114,20 @@ function createProcedureCaller(options) {
|
|
114
114
|
const procedure = await loadProcedure(options.procedure);
|
115
115
|
const context = await value(options.context);
|
116
116
|
const execute = async () => {
|
117
|
-
const validInput = (() => {
|
118
|
-
const schema = procedure.zz$p.contract.
|
117
|
+
const validInput = await (async () => {
|
118
|
+
const schema = procedure.zz$p.contract["~orpc"].InputSchema;
|
119
119
|
if (!schema) {
|
120
120
|
return input;
|
121
121
|
}
|
122
|
-
|
123
|
-
|
124
|
-
} catch (e) {
|
122
|
+
const result = await schema["~standard"].validate(input);
|
123
|
+
if (result.issues) {
|
125
124
|
throw new ORPCError({
|
126
125
|
message: "Validation input failed",
|
127
126
|
code: "BAD_REQUEST",
|
128
|
-
|
127
|
+
issues: result.issues
|
129
128
|
});
|
130
129
|
}
|
130
|
+
return result.value;
|
131
131
|
})();
|
132
132
|
const meta = {
|
133
133
|
path,
|
@@ -156,19 +156,18 @@ function createProcedureCaller(options) {
|
|
156
156
|
};
|
157
157
|
const output2 = (await next({})).output;
|
158
158
|
const validOutput = await (async () => {
|
159
|
-
const schema = procedure.zz$p.contract.
|
159
|
+
const schema = procedure.zz$p.contract["~orpc"].OutputSchema;
|
160
160
|
if (!schema) {
|
161
161
|
return output2;
|
162
162
|
}
|
163
|
-
const result = await schema.
|
164
|
-
if (result.
|
163
|
+
const result = await schema["~standard"].validate(output2);
|
164
|
+
if (result.issues) {
|
165
165
|
throw new ORPCError({
|
166
166
|
message: "Validation output failed",
|
167
|
-
code: "INTERNAL_SERVER_ERROR"
|
168
|
-
cause: result.error
|
167
|
+
code: "INTERNAL_SERVER_ERROR"
|
169
168
|
});
|
170
169
|
}
|
171
|
-
return result.
|
170
|
+
return result.value;
|
172
171
|
})();
|
173
172
|
return validOutput;
|
174
173
|
};
|
@@ -271,4 +270,4 @@ export {
|
|
271
270
|
decorateProcedure,
|
272
271
|
isProcedure
|
273
272
|
};
|
274
|
-
//# 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 { executeWithHooks, 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);
|
package/dist/index.js
CHANGED
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
loadLazy,
|
13
13
|
loadProcedure,
|
14
14
|
mergeContext
|
15
|
-
} from "./chunk-
|
15
|
+
} from "./chunk-VARUID7X.js";
|
16
16
|
|
17
17
|
// src/builder.ts
|
18
18
|
import {
|
@@ -26,7 +26,7 @@ import {
|
|
26
26
|
} from "@orpc/contract";
|
27
27
|
|
28
28
|
// src/router-builder.ts
|
29
|
-
import { DecoratedContractProcedure
|
29
|
+
import { DecoratedContractProcedure } from "@orpc/contract";
|
30
30
|
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
31
31
|
var RouterBuilder = class _RouterBuilder {
|
32
32
|
constructor(zz$rb) {
|
@@ -109,7 +109,7 @@ function adaptLazyRouter(options) {
|
|
109
109
|
};
|
110
110
|
let lazyRouterPrefix = options.prefix;
|
111
111
|
if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") {
|
112
|
-
lazyRouterPrefix =
|
112
|
+
lazyRouterPrefix = `${options.current[LAZY_ROUTER_PREFIX_SYMBOL]}${lazyRouterPrefix ?? ""}`;
|
113
113
|
}
|
114
114
|
const decoratedLazy = Object.assign(decorateLazy(createLazy(loader)), {
|
115
115
|
[LAZY_ROUTER_PREFIX_SYMBOL]: lazyRouterPrefix
|
@@ -141,7 +141,7 @@ function adaptProcedure(options) {
|
|
141
141
|
];
|
142
142
|
let contract = DecoratedContractProcedure.decorate(
|
143
143
|
options.procedure.zz$p.contract
|
144
|
-
).
|
144
|
+
).pushTag(...options.tags ?? []);
|
145
145
|
if (options.prefix) {
|
146
146
|
contract = contract.prefix(options.prefix);
|
147
147
|
}
|
@@ -298,11 +298,11 @@ var Builder = class _Builder {
|
|
298
298
|
/**
|
299
299
|
* Convert to ContractProcedureBuilder
|
300
300
|
*/
|
301
|
-
route(
|
301
|
+
route(route) {
|
302
302
|
return new ProcedureBuilder({
|
303
303
|
middlewares: this.zz$b.middlewares,
|
304
304
|
contract: new ContractProcedure({
|
305
|
-
|
305
|
+
route,
|
306
306
|
InputSchema: void 0,
|
307
307
|
OutputSchema: void 0
|
308
308
|
})
|
@@ -389,25 +389,6 @@ var Builder = class _Builder {
|
|
389
389
|
}
|
390
390
|
};
|
391
391
|
|
392
|
-
// src/router.ts
|
393
|
-
import {
|
394
|
-
isContractProcedure as isContractProcedure3
|
395
|
-
} from "@orpc/contract";
|
396
|
-
function toContractRouter(router) {
|
397
|
-
const contract = {};
|
398
|
-
for (const key in router) {
|
399
|
-
const item = router[key];
|
400
|
-
if (isContractProcedure3(item)) {
|
401
|
-
contract[key] = item;
|
402
|
-
} else if (isProcedure(item)) {
|
403
|
-
contract[key] = item.zz$p.contract;
|
404
|
-
} else {
|
405
|
-
contract[key] = toContractRouter(item);
|
406
|
-
}
|
407
|
-
}
|
408
|
-
return contract;
|
409
|
-
}
|
410
|
-
|
411
392
|
// src/router-caller.ts
|
412
393
|
function createRouterCaller(options) {
|
413
394
|
return createRouterCallerInternal(options);
|
@@ -461,7 +442,6 @@ export {
|
|
461
442
|
loadLazy,
|
462
443
|
loadProcedure,
|
463
444
|
mergeContext,
|
464
|
-
os
|
465
|
-
toContractRouter
|
445
|
+
os
|
466
446
|
};
|
467
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
|
*/
|
@@ -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
|
}
|
@@ -11,7 +11,6 @@ export type HandledRouter<TRouter extends Router<any>> = {
|
|
11
11
|
export type RouterWithContract<TContext extends Context, TContract extends ContractRouter> = {
|
12
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
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
|
};
|
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.4555a17",
|
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.3f3f19b"
|
37
|
+
"@orpc/zod": "0.0.0-next.4555a17"
|
39
38
|
},
|
40
39
|
"dependencies": {
|
41
|
-
"@orpc/contract": "0.0.0-next.
|
42
|
-
"@orpc/transformer": "0.0.0-next.
|
43
|
-
"@orpc/shared": "0.0.0-next.
|
40
|
+
"@orpc/contract": "0.0.0-next.4555a17",
|
41
|
+
"@orpc/transformer": "0.0.0-next.4555a17",
|
42
|
+
"@orpc/shared": "0.0.0-next.4555a17"
|
44
43
|
},
|
45
44
|
"devDependencies": {
|
46
|
-
"@orpc/openapi": "0.0.0-next.
|
45
|
+
"@orpc/openapi": "0.0.0-next.4555a17"
|
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'",
|