@orpc/server 0.0.0-next.eb37cbe → 0.0.0-next.ed15210
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.
- package/dist/chunk-6YJ5NGUE.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/chunk-XHFINNVL.js +217 -0
- package/dist/fetch.js +10 -310
- package/dist/hono.js +30 -0
- package/dist/index.js +718 -193
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/{fetch → adapters/fetch}/index.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/{fetch → adapters/fetch}/orpc-payload-codec.d.ts +1 -1
- package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +2 -2
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder-with-errors-middlewares.d.ts +49 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +49 -0
- package/dist/src/builder.d.ts +35 -24
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +10 -0
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +1 -3
- package/dist/src/implementer-chainable.d.ts +11 -5
- package/dist/src/index.d.ts +7 -4
- package/dist/src/lazy-decorated.d.ts +4 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +29 -13
- package/dist/src/procedure-builder-with-input.d.ts +35 -0
- package/dist/src/procedure-builder-with-output.d.ts +34 -0
- package/dist/src/procedure-builder.d.ts +24 -18
- package/dist/src/procedure-client.d.ts +9 -22
- package/dist/src/procedure-decorated.d.ts +22 -11
- package/dist/src/procedure-implementer.d.ts +18 -13
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +37 -13
- package/dist/src/router-builder.d.ts +20 -16
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +15 -12
- package/dist/src/router-utils.d.ts +15 -0
- package/dist/src/router.d.ts +9 -6
- package/dist/src/types.d.ts +2 -3
- package/package.json +24 -8
- package/dist/chunk-37HIYNDO.js +0 -182
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/types.d.ts +0 -16
- package/dist/src/utils.d.ts +0 -3
- /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { Context, TypeInitialContext } from './context';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { ANY_MIDDLEWARE } from './middleware';
|
4
|
+
import type { ANY_ROUTER } from './router';
|
5
|
+
import { type DecoratedLazy } from './lazy-decorated';
|
6
|
+
import { type Procedure } from './procedure';
|
7
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
8
|
+
export type UnshiftedMiddlewaresRouter<TRouter extends ANY_ROUTER, TInitialContext extends Context> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<UnshiftedMiddlewaresRouter<U, TInitialContext>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer URoute> ? DecoratedProcedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap, URoute> : {
|
9
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? UnshiftedMiddlewaresRouter<TRouter[K], TInitialContext> : never;
|
10
|
+
};
|
11
|
+
export declare function unshiftMiddlewaresRouter<TRouter extends ANY_ROUTER, TInitialContext extends Context>(router: TRouter, options: {
|
12
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
13
|
+
middlewares: ANY_MIDDLEWARE[];
|
14
|
+
}): UnshiftedMiddlewaresRouter<TRouter, TInitialContext>;
|
15
|
+
//# sourceMappingURL=router-utils.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
2
3
|
import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
|
3
4
|
import type { ANY_PROCEDURE, Procedure } from './procedure';
|
4
|
-
|
5
|
-
|
6
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter ? Router<TContext, TContract[K]> : never;
|
5
|
+
export type Router<TInitialContext extends Context, TContract extends ContractRouter<any>> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer URoute> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, URoute> : {
|
6
|
+
[K in keyof TContract]: TContract[K] extends ContractRouter<any> ? Router<TInitialContext, TContract[K]> : never;
|
7
7
|
}>;
|
8
|
+
export type RouterToContract<T extends Router<any, any>> = T extends Lazy<infer U extends Router<any, any>> ? RouterToContract<U> : T extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, any, infer UErrorMap, infer URoute> ? ContractProcedure<UInputSchema, UOutputSchema, UErrorMap, URoute> : {
|
9
|
+
[K in keyof T]: T[K] extends Router<any, any> ? RouterToContract<T[K]> : never;
|
10
|
+
};
|
8
11
|
export type ANY_ROUTER = Router<any, any>;
|
9
|
-
export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : {
|
12
|
+
export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
|
10
13
|
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterInputs<T[K]> : never;
|
11
14
|
};
|
12
|
-
export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
15
|
+
export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
13
16
|
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterOutputs<T[K]> : never;
|
14
17
|
};
|
15
|
-
export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE | Record<string, ANY_ROUTER
|
18
|
+
export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER>> | Lazy<undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
|
16
19
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
+
import type { FindGlobalInstanceType } from '@orpc/shared';
|
1
2
|
import type { ANY_PROCEDURE } from './procedure';
|
2
|
-
export type
|
3
|
-
export type WELL_CONTEXT = Record<string, unknown> | undefined;
|
4
|
-
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB;
|
3
|
+
export type AbortSignal = FindGlobalInstanceType<'AbortSignal'>;
|
5
4
|
export interface WithSignal {
|
6
5
|
signal?: AbortSignal;
|
7
6
|
}
|
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.ed15210",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -20,10 +20,25 @@
|
|
20
20
|
"default": "./dist/index.js"
|
21
21
|
},
|
22
22
|
"./fetch": {
|
23
|
-
"types": "./dist/src/fetch/index.d.ts",
|
23
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
24
24
|
"import": "./dist/fetch.js",
|
25
25
|
"default": "./dist/fetch.js"
|
26
26
|
},
|
27
|
+
"./hono": {
|
28
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
29
|
+
"import": "./dist/hono.js",
|
30
|
+
"default": "./dist/hono.js"
|
31
|
+
},
|
32
|
+
"./next": {
|
33
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
34
|
+
"import": "./dist/next.js",
|
35
|
+
"default": "./dist/next.js"
|
36
|
+
},
|
37
|
+
"./node": {
|
38
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
39
|
+
"import": "./dist/node.js",
|
40
|
+
"default": "./dist/node.js"
|
41
|
+
},
|
27
42
|
"./🔒/*": {
|
28
43
|
"types": "./dist/src/*.d.ts"
|
29
44
|
}
|
@@ -33,15 +48,16 @@
|
|
33
48
|
"!**/*.tsbuildinfo",
|
34
49
|
"dist"
|
35
50
|
],
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
51
|
+
"peerDependencies": {
|
52
|
+
"hono": ">=4.6.0",
|
53
|
+
"next": ">=14.0.0"
|
39
54
|
},
|
40
|
-
"
|
41
|
-
"
|
55
|
+
"dependencies": {
|
56
|
+
"@orpc/contract": "0.0.0-next.ed15210",
|
57
|
+
"@orpc/shared": "0.0.0-next.ed15210"
|
42
58
|
},
|
43
59
|
"scripts": {
|
44
|
-
"build": "tsup --
|
60
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
45
61
|
"build:watch": "pnpm run build --watch",
|
46
62
|
"type:check": "tsc -b"
|
47
63
|
}
|
package/dist/chunk-37HIYNDO.js
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
// src/utils.ts
|
2
|
-
function mergeContext(a, b) {
|
3
|
-
if (!a)
|
4
|
-
return b;
|
5
|
-
if (!b)
|
6
|
-
return a;
|
7
|
-
return {
|
8
|
-
...a,
|
9
|
-
...b
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
|
-
// src/procedure.ts
|
14
|
-
import { isContractProcedure } from "@orpc/contract";
|
15
|
-
var Procedure = class {
|
16
|
-
"~type" = "Procedure";
|
17
|
-
"~orpc";
|
18
|
-
constructor(def) {
|
19
|
-
this["~orpc"] = def;
|
20
|
-
}
|
21
|
-
};
|
22
|
-
function isProcedure(item) {
|
23
|
-
if (item instanceof Procedure) {
|
24
|
-
return true;
|
25
|
-
}
|
26
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
27
|
-
}
|
28
|
-
|
29
|
-
// src/lazy.ts
|
30
|
-
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
31
|
-
function lazy(loader) {
|
32
|
-
return {
|
33
|
-
[LAZY_LOADER_SYMBOL]: loader
|
34
|
-
};
|
35
|
-
}
|
36
|
-
function isLazy(item) {
|
37
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
|
38
|
-
}
|
39
|
-
function unlazy(lazied) {
|
40
|
-
return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
|
41
|
-
}
|
42
|
-
function flatLazy(lazied) {
|
43
|
-
const flattenLoader = async () => {
|
44
|
-
let current = await unlazy(lazied);
|
45
|
-
while (true) {
|
46
|
-
if (!isLazy(current.default)) {
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
current = await unlazy(current.default);
|
50
|
-
}
|
51
|
-
return current;
|
52
|
-
};
|
53
|
-
return lazy(flattenLoader);
|
54
|
-
}
|
55
|
-
|
56
|
-
// src/procedure-client.ts
|
57
|
-
import { executeWithHooks, value } from "@orpc/shared";
|
58
|
-
import { ORPCError } from "@orpc/shared/error";
|
59
|
-
function createProcedureClient(options) {
|
60
|
-
return async (...[input, callerOptions]) => {
|
61
|
-
const path = options.path ?? [];
|
62
|
-
const { default: procedure } = await unlazy(options.procedure);
|
63
|
-
const context = await value(options.context);
|
64
|
-
const meta = {
|
65
|
-
path,
|
66
|
-
procedure,
|
67
|
-
signal: callerOptions?.signal
|
68
|
-
};
|
69
|
-
const executeWithValidation = async () => {
|
70
|
-
const validInput = await validateInput(procedure, input);
|
71
|
-
const output = await executeMiddlewareChain(
|
72
|
-
procedure,
|
73
|
-
validInput,
|
74
|
-
context,
|
75
|
-
meta
|
76
|
-
);
|
77
|
-
return validateOutput(procedure, output);
|
78
|
-
};
|
79
|
-
return executeWithHooks({
|
80
|
-
hooks: options,
|
81
|
-
input,
|
82
|
-
context,
|
83
|
-
meta,
|
84
|
-
execute: executeWithValidation
|
85
|
-
});
|
86
|
-
};
|
87
|
-
}
|
88
|
-
async function validateInput(procedure, input) {
|
89
|
-
const schema = procedure["~orpc"].contract["~orpc"].InputSchema;
|
90
|
-
if (!schema)
|
91
|
-
return input;
|
92
|
-
const result = await schema["~standard"].validate(input);
|
93
|
-
if (result.issues) {
|
94
|
-
throw new ORPCError({
|
95
|
-
message: "Input validation failed",
|
96
|
-
code: "BAD_REQUEST",
|
97
|
-
issues: result.issues
|
98
|
-
});
|
99
|
-
}
|
100
|
-
return result.value;
|
101
|
-
}
|
102
|
-
async function validateOutput(procedure, output) {
|
103
|
-
const schema = procedure["~orpc"].contract["~orpc"].OutputSchema;
|
104
|
-
if (!schema)
|
105
|
-
return output;
|
106
|
-
const result = await schema["~standard"].validate(output);
|
107
|
-
if (result.issues) {
|
108
|
-
throw new ORPCError({
|
109
|
-
message: "Output validation failed",
|
110
|
-
code: "INTERNAL_SERVER_ERROR",
|
111
|
-
issues: result.issues
|
112
|
-
});
|
113
|
-
}
|
114
|
-
return result.value;
|
115
|
-
}
|
116
|
-
async function executeMiddlewareChain(procedure, input, context, meta) {
|
117
|
-
const middlewares = procedure["~orpc"].middlewares ?? [];
|
118
|
-
let currentMidIndex = 0;
|
119
|
-
let currentContext = context;
|
120
|
-
const next = async (nextOptions) => {
|
121
|
-
const mid = middlewares[currentMidIndex];
|
122
|
-
currentMidIndex += 1;
|
123
|
-
currentContext = mergeContext(currentContext, nextOptions.context);
|
124
|
-
if (mid) {
|
125
|
-
return await mid(input, currentContext, {
|
126
|
-
...meta,
|
127
|
-
next,
|
128
|
-
output: (output) => ({ output, context: void 0 })
|
129
|
-
});
|
130
|
-
}
|
131
|
-
const result = {
|
132
|
-
output: await procedure["~orpc"].handler(input, currentContext, meta),
|
133
|
-
context: currentContext
|
134
|
-
};
|
135
|
-
return result;
|
136
|
-
};
|
137
|
-
return (await next({})).output;
|
138
|
-
}
|
139
|
-
|
140
|
-
// src/router.ts
|
141
|
-
function getRouterChild(router, ...path) {
|
142
|
-
let current = router;
|
143
|
-
for (let i = 0; i < path.length; i++) {
|
144
|
-
const segment = path[i];
|
145
|
-
if (!current) {
|
146
|
-
return void 0;
|
147
|
-
}
|
148
|
-
if (isProcedure(current)) {
|
149
|
-
return void 0;
|
150
|
-
}
|
151
|
-
if (!isLazy(current)) {
|
152
|
-
current = current[segment];
|
153
|
-
continue;
|
154
|
-
}
|
155
|
-
const lazied = current;
|
156
|
-
const rest = path.slice(i);
|
157
|
-
const newLazy = lazy(async () => {
|
158
|
-
const unwrapped = await unlazy(lazied);
|
159
|
-
if (!unwrapped.default) {
|
160
|
-
return unwrapped;
|
161
|
-
}
|
162
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
163
|
-
return { default: next };
|
164
|
-
});
|
165
|
-
return flatLazy(newLazy);
|
166
|
-
}
|
167
|
-
return current;
|
168
|
-
}
|
169
|
-
|
170
|
-
export {
|
171
|
-
mergeContext,
|
172
|
-
Procedure,
|
173
|
-
isProcedure,
|
174
|
-
LAZY_LOADER_SYMBOL,
|
175
|
-
lazy,
|
176
|
-
isLazy,
|
177
|
-
unlazy,
|
178
|
-
flatLazy,
|
179
|
-
createProcedureClient,
|
180
|
-
getRouterChild
|
181
|
-
};
|
182
|
-
//# sourceMappingURL=chunk-37HIYNDO.js.map
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import type { Context } from '../types';
|
2
|
-
import type { ConditionalFetchHandler, FetchHandler, FetchOptions } from './types';
|
3
|
-
export declare class CompositeHandler<T extends Context> implements FetchHandler<T> {
|
4
|
-
private readonly handlers;
|
5
|
-
constructor(handlers: ConditionalFetchHandler<T>[]);
|
6
|
-
fetch(request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
7
|
-
}
|
8
|
-
//# sourceMappingURL=composite-handler.d.ts.map
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import type { Hooks } from '@orpc/shared';
|
2
|
-
import type { Router } from '../router';
|
3
|
-
import type { Context, WithSignal } from '../types';
|
4
|
-
import type { ConditionalFetchHandler, FetchOptions } from './types';
|
5
|
-
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
-
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
-
export type ORPCHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
|
8
|
-
procedureMatcher?: PublicORPCProcedureMatcher;
|
9
|
-
payloadCodec?: PublicORPCPayloadCodec;
|
10
|
-
};
|
11
|
-
export declare class ORPCHandler<T extends Context> implements ConditionalFetchHandler<T> {
|
12
|
-
readonly router: Router<T, any>;
|
13
|
-
readonly options?: NoInfer<ORPCHandlerOptions<T>> | undefined;
|
14
|
-
private readonly procedureMatcher;
|
15
|
-
private readonly payloadCodec;
|
16
|
-
constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>> | undefined);
|
17
|
-
condition(request: Request): boolean;
|
18
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
19
|
-
}
|
20
|
-
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Context, WithSignal } from '../types';
|
3
|
-
export type FetchOptions<T extends Context> = WithSignal & {
|
4
|
-
prefix?: HTTPPath;
|
5
|
-
} & (undefined extends T ? {
|
6
|
-
context?: T;
|
7
|
-
} : {
|
8
|
-
context: T;
|
9
|
-
});
|
10
|
-
export interface FetchHandler<T extends Context> {
|
11
|
-
fetch: (request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)) => Promise<Response>;
|
12
|
-
}
|
13
|
-
export interface ConditionalFetchHandler<T extends Context> extends FetchHandler<T> {
|
14
|
-
condition: (request: Request) => boolean;
|
15
|
-
}
|
16
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/utils.d.ts
DELETED
File without changes
|