@orpc/server 0.0.0-next.0787cc6 → 0.0.0-next.0c0619f
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/README.md +118 -0
- package/dist/chunk-7A2ZRAPK.js +182 -0
- package/dist/chunk-MEBJNUSY.js +32 -0
- package/dist/{chunk-EDQKEHUX.js → chunk-MHVECKBC.js} +51 -7
- package/dist/{chunk-XFBAK67J.js → chunk-WQNNSBXW.js} +7 -15
- package/dist/fetch.js +6 -12
- package/dist/hono.js +6 -12
- package/dist/index.js +16 -7
- package/dist/next.js +6 -12
- package/dist/node.js +7 -146
- package/dist/plugins.js +1 -1
- package/dist/src/adapters/fetch/index.d.ts +0 -1
- package/dist/src/adapters/fetch/rpc-handler.d.ts +3 -2
- package/dist/src/adapters/fetch/types.d.ts +3 -2
- package/dist/src/adapters/hono/middleware.d.ts +2 -3
- package/dist/src/adapters/next/serve.d.ts +2 -3
- package/dist/src/adapters/node/index.d.ts +0 -1
- package/dist/src/adapters/node/rpc-handler.d.ts +3 -2
- package/dist/src/adapters/node/types.d.ts +3 -2
- package/dist/src/adapters/standard/handler.d.ts +15 -13
- package/dist/src/adapters/standard/index.d.ts +0 -1
- package/dist/src/adapters/standard/rpc-codec.d.ts +4 -3
- package/dist/src/adapters/standard/types.d.ts +3 -26
- package/dist/src/builder-variants.d.ts +2 -1
- package/dist/src/builder.d.ts +2 -1
- package/dist/src/context.d.ts +0 -1
- package/dist/src/error.d.ts +12 -0
- package/dist/src/implementer-procedure.d.ts +7 -4
- package/dist/src/implementer-variants.d.ts +2 -1
- package/dist/src/implementer.d.ts +2 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/middleware-decorated.d.ts +2 -1
- package/dist/src/middleware.d.ts +5 -4
- package/dist/src/plugins/base.d.ts +1 -3
- package/dist/src/procedure-client.d.ts +8 -6
- package/dist/src/procedure-decorated.d.ts +7 -4
- package/dist/src/procedure-utils.d.ts +5 -3
- package/dist/src/procedure.d.ts +5 -3
- package/dist/src/router-client.d.ts +6 -5
- package/dist/src/router.d.ts +1 -0
- package/dist/standard.js +5 -9
- package/package.json +7 -4
- package/dist/chunk-2OH4QMZ4.js +0 -145
- package/dist/chunk-BFGSRNYZ.js +0 -319
- package/dist/src/adapters/fetch/utils.d.ts +0 -5
- package/dist/src/adapters/node/utils.d.ts +0 -5
- package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
package/dist/node.js
CHANGED
@@ -2,149 +2,12 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
6
|
-
import "./chunk-
|
7
|
-
import "./chunk-
|
8
|
-
|
9
|
-
// src/adapters/node/utils.ts
|
10
|
-
import { Buffer, File } from "node:buffer";
|
11
|
-
import { Readable } from "node:stream";
|
12
|
-
import { once } from "@orpc/shared";
|
13
|
-
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
14
|
-
function nodeHttpToStandardRequest(req, res) {
|
15
|
-
const method = req.method ?? "GET";
|
16
|
-
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
17
|
-
const host = req.headers.host ?? "localhost";
|
18
|
-
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
19
|
-
return {
|
20
|
-
raw: { request: req, response: res },
|
21
|
-
method,
|
22
|
-
url,
|
23
|
-
headers: req.headers,
|
24
|
-
body: once(() => {
|
25
|
-
return nodeHttpRequestToStandardBody(req);
|
26
|
-
}),
|
27
|
-
get signal() {
|
28
|
-
const signal = nodeHttpResponseToAbortSignal(res);
|
29
|
-
Object.defineProperty(this, "signal", { value: signal, writable: true });
|
30
|
-
return signal;
|
31
|
-
},
|
32
|
-
set signal(value) {
|
33
|
-
Object.defineProperty(this, "signal", { value, writable: true });
|
34
|
-
}
|
35
|
-
};
|
36
|
-
}
|
37
|
-
function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
38
|
-
return new Promise((resolve, reject) => {
|
39
|
-
res.on("error", reject);
|
40
|
-
res.on("finish", resolve);
|
41
|
-
const resHeaders = standardResponse.headers;
|
42
|
-
delete resHeaders["content-type"];
|
43
|
-
delete resHeaders["content-disposition"];
|
44
|
-
if (standardResponse.body === void 0) {
|
45
|
-
res.writeHead(standardResponse.status, standardResponse.headers);
|
46
|
-
res.end();
|
47
|
-
return;
|
48
|
-
}
|
49
|
-
if (standardResponse.body instanceof Blob) {
|
50
|
-
resHeaders["content-type"] = standardResponse.body.type;
|
51
|
-
resHeaders["content-length"] = standardResponse.body.size.toString();
|
52
|
-
resHeaders["content-disposition"] = contentDisposition(
|
53
|
-
standardResponse.body instanceof File ? standardResponse.body.name : "blob",
|
54
|
-
{ type: "inline" }
|
55
|
-
);
|
56
|
-
res.writeHead(standardResponse.status, resHeaders);
|
57
|
-
Readable.fromWeb(
|
58
|
-
standardResponse.body.stream()
|
59
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
60
|
-
).pipe(res);
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
if (standardResponse.body instanceof FormData) {
|
64
|
-
const response = new Response(standardResponse.body);
|
65
|
-
resHeaders["content-type"] = response.headers.get("content-type");
|
66
|
-
res.writeHead(standardResponse.status, resHeaders);
|
67
|
-
Readable.fromWeb(
|
68
|
-
response.body
|
69
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
70
|
-
).pipe(res);
|
71
|
-
return;
|
72
|
-
}
|
73
|
-
if (standardResponse.body instanceof URLSearchParams) {
|
74
|
-
resHeaders["content-type"] = "application/x-www-form-urlencoded";
|
75
|
-
res.writeHead(standardResponse.status, resHeaders);
|
76
|
-
res.end(standardResponse.body.toString());
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
resHeaders["content-type"] = "application/json";
|
80
|
-
res.writeHead(standardResponse.status, resHeaders);
|
81
|
-
res.end(JSON.stringify(standardResponse.body));
|
82
|
-
});
|
83
|
-
}
|
84
|
-
async function nodeHttpRequestToStandardBody(req) {
|
85
|
-
const method = req.method ?? "GET";
|
86
|
-
if (method === "GET" || method === "HEAD") {
|
87
|
-
return void 0;
|
88
|
-
}
|
89
|
-
const contentDisposition2 = req.headers["content-disposition"];
|
90
|
-
const contentType = req.headers["content-type"];
|
91
|
-
if (contentDisposition2) {
|
92
|
-
const fileName = parseContentDisposition(contentDisposition2).parameters.filename;
|
93
|
-
if (typeof fileName === "string") {
|
94
|
-
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
95
|
-
}
|
96
|
-
}
|
97
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
98
|
-
const text = await streamToString(req);
|
99
|
-
if (!text) {
|
100
|
-
return void 0;
|
101
|
-
}
|
102
|
-
return JSON.parse(text);
|
103
|
-
}
|
104
|
-
if (contentType.startsWith("multipart/form-data")) {
|
105
|
-
return await streamToFormData(req, contentType);
|
106
|
-
}
|
107
|
-
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
108
|
-
const text = await streamToString(req);
|
109
|
-
return new URLSearchParams(text);
|
110
|
-
}
|
111
|
-
if (contentType.startsWith("text/")) {
|
112
|
-
return await streamToString(req);
|
113
|
-
}
|
114
|
-
return streamToFile(req, "blob", contentType);
|
115
|
-
}
|
116
|
-
function streamToFormData(stream, contentType) {
|
117
|
-
const response = new Response(stream, {
|
118
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
119
|
-
headers: {
|
120
|
-
"content-type": contentType
|
121
|
-
}
|
122
|
-
});
|
123
|
-
return response.formData();
|
124
|
-
}
|
125
|
-
async function streamToString(stream) {
|
126
|
-
let string = "";
|
127
|
-
for await (const chunk of stream) {
|
128
|
-
string += chunk.toString();
|
129
|
-
}
|
130
|
-
return string;
|
131
|
-
}
|
132
|
-
async function streamToFile(stream, fileName, contentType) {
|
133
|
-
const chunks = [];
|
134
|
-
for await (const chunk of stream) {
|
135
|
-
chunks.push(chunk);
|
136
|
-
}
|
137
|
-
return new File([Buffer.concat(chunks)], fileName, { type: contentType });
|
138
|
-
}
|
139
|
-
function nodeHttpResponseToAbortSignal(res) {
|
140
|
-
const controller = new AbortController();
|
141
|
-
res.on("close", () => {
|
142
|
-
controller.abort();
|
143
|
-
});
|
144
|
-
return controller.signal;
|
145
|
-
}
|
5
|
+
} from "./chunk-7A2ZRAPK.js";
|
6
|
+
import "./chunk-MHVECKBC.js";
|
7
|
+
import "./chunk-WQNNSBXW.js";
|
146
8
|
|
147
9
|
// src/adapters/node/rpc-handler.ts
|
10
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
|
148
11
|
var RPCHandler = class {
|
149
12
|
standardHandler;
|
150
13
|
constructor(router, options) {
|
@@ -153,18 +16,16 @@ var RPCHandler = class {
|
|
153
16
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
154
17
|
}
|
155
18
|
async handle(req, res, ...rest) {
|
156
|
-
const standardRequest =
|
19
|
+
const standardRequest = toStandardRequest(req, res);
|
157
20
|
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
158
21
|
if (!result.matched) {
|
159
22
|
return { matched: false };
|
160
23
|
}
|
161
|
-
await
|
24
|
+
await sendStandardResponse(res, result.response);
|
162
25
|
return { matched: true };
|
163
26
|
}
|
164
27
|
};
|
165
28
|
export {
|
166
|
-
RPCHandler
|
167
|
-
nodeHttpResponseSendStandardResponse,
|
168
|
-
nodeHttpToStandardRequest
|
29
|
+
RPCHandler
|
169
30
|
};
|
170
31
|
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
1
2
|
import type { Context } from '../../context';
|
2
3
|
import type { Router } from '../../router';
|
3
|
-
import type { RPCHandlerOptions,
|
4
|
+
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
4
5
|
import type { FetchHandler, FetchHandleResult } from './types';
|
5
6
|
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
6
7
|
private readonly standardHandler;
|
7
8
|
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
8
|
-
handle(request: Request, ...rest:
|
9
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
9
10
|
}
|
10
11
|
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,5 +1,6 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
1
2
|
import type { Context } from '../../context';
|
2
|
-
import type {
|
3
|
+
import type { StandardHandleOptions } from '../standard';
|
3
4
|
export type FetchHandleResult = {
|
4
5
|
matched: true;
|
5
6
|
response: Response;
|
@@ -8,6 +9,6 @@ export type FetchHandleResult = {
|
|
8
9
|
response: undefined;
|
9
10
|
};
|
10
11
|
export interface FetchHandler<T extends Context> {
|
11
|
-
handle(request: Request, ...rest:
|
12
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
12
13
|
}
|
13
14
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1,13 +1,12 @@
|
|
1
|
+
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
1
2
|
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
3
|
import type { Context } from '../../context';
|
3
4
|
import type { FetchHandler } from '../fetch';
|
4
5
|
import type { StandardHandleOptions } from '../standard';
|
5
|
-
import { type Value } from '@orpc/shared';
|
6
6
|
export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
7
|
context?: Value<T, [HonoContext]>;
|
8
8
|
} : {
|
9
9
|
context: Value<T, [HonoContext]>;
|
10
10
|
});
|
11
|
-
export
|
12
|
-
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
|
11
|
+
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
13
12
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,14 +1,13 @@
|
|
1
|
+
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
1
2
|
import type { NextRequest } from 'next/server';
|
2
3
|
import type { Context } from '../../context';
|
3
4
|
import type { FetchHandler } from '../fetch';
|
4
5
|
import type { StandardHandleOptions } from '../standard';
|
5
|
-
import { type Value } from '@orpc/shared';
|
6
6
|
export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
7
|
context?: Value<T, [NextRequest]>;
|
8
8
|
} : {
|
9
9
|
context: Value<T, [NextRequest]>;
|
10
10
|
});
|
11
|
-
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
|
12
11
|
export interface ServeResult {
|
13
12
|
GET(req: NextRequest): Promise<Response>;
|
14
13
|
POST(req: NextRequest): Promise<Response>;
|
@@ -16,5 +15,5 @@ export interface ServeResult {
|
|
16
15
|
PATCH(req: NextRequest): Promise<Response>;
|
17
16
|
DELETE(req: NextRequest): Promise<Response>;
|
18
17
|
}
|
19
|
-
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]:
|
18
|
+
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
20
19
|
//# sourceMappingURL=serve.d.ts.map
|
@@ -1,10 +1,11 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
1
2
|
import type { Context } from '../../context';
|
2
3
|
import type { Router } from '../../router';
|
3
|
-
import type { RPCHandlerOptions,
|
4
|
+
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
4
5
|
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
|
5
6
|
export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
6
7
|
private readonly standardHandler;
|
7
8
|
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
8
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest:
|
9
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
9
10
|
}
|
10
11
|
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,7 +1,8 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
1
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
3
|
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
3
4
|
import type { Context } from '../../context';
|
4
|
-
import type {
|
5
|
+
import type { StandardHandleOptions } from '../standard';
|
5
6
|
export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
6
7
|
/**
|
7
8
|
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
@@ -16,6 +17,6 @@ export type NodeHttpHandleResult = {
|
|
16
17
|
matched: false;
|
17
18
|
};
|
18
19
|
export interface NodeHttpHandler<T extends Context> {
|
19
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest:
|
20
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
20
21
|
}
|
21
22
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1,10 +1,11 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
1
|
+
import type { ErrorFromErrorMap, HTTPPath, Meta, Schema, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
3
|
+
import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
4
|
import type { Context } from '../../context';
|
4
5
|
import type { Plugin } from '../../plugins';
|
5
|
-
import type {
|
6
|
+
import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
|
6
7
|
import type { Router } from '../../router';
|
7
|
-
import type { StandardCodec, StandardMatcher
|
8
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
8
9
|
export type StandardHandleOptions<T extends Context> = {
|
9
10
|
prefix?: HTTPPath;
|
10
11
|
} & (Record<never, never> extends T ? {
|
@@ -15,7 +16,6 @@ export type StandardHandleOptions<T extends Context> = {
|
|
15
16
|
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
16
17
|
context: T;
|
17
18
|
};
|
18
|
-
export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
19
19
|
export type StandardHandleResult = {
|
20
20
|
matched: true;
|
21
21
|
response: StandardResponse;
|
@@ -26,9 +26,6 @@ export type StandardHandleResult = {
|
|
26
26
|
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
27
27
|
request: StandardRequest;
|
28
28
|
};
|
29
|
-
export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, unknown> & {
|
30
|
-
context: TContext;
|
31
|
-
};
|
32
29
|
export interface StandardHandlerOptions<TContext extends Context> {
|
33
30
|
plugins?: Plugin<TContext>[];
|
34
31
|
/**
|
@@ -36,16 +33,21 @@ export interface StandardHandlerOptions<TContext extends Context> {
|
|
36
33
|
*/
|
37
34
|
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
38
35
|
/**
|
39
|
-
* Interceptors at the root level, helpful when you want override the response
|
36
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
37
|
+
*/
|
38
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
39
|
+
/**
|
40
|
+
*
|
41
|
+
* Interceptors for procedure client.
|
40
42
|
*/
|
41
|
-
|
43
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
|
42
44
|
}
|
43
|
-
export declare class StandardHandler<
|
45
|
+
export declare class StandardHandler<T extends Context> {
|
44
46
|
private readonly matcher;
|
45
47
|
private readonly codec;
|
46
48
|
private readonly options;
|
47
49
|
private readonly plugin;
|
48
|
-
constructor(router: Router<
|
49
|
-
handle(request: StandardRequest, ...[options]:
|
50
|
+
constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
|
51
|
+
handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
50
52
|
}
|
51
53
|
//# sourceMappingURL=handler.d.ts.map
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import type { ORPCError } from '@orpc/
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
2
2
|
import type { AnyProcedure } from '../../procedure';
|
3
|
-
import type { StandardCodec, StandardParams
|
4
|
-
import { RPCSerializer } from '
|
3
|
+
import type { StandardCodec, StandardParams } from './types';
|
4
|
+
import { RPCSerializer } from '@orpc/client/rpc';
|
5
|
+
import { type StandardRequest, type StandardResponse } from '@orpc/server-standard';
|
5
6
|
export interface StandardCodecOptions {
|
6
7
|
serializer?: RPCSerializer;
|
7
8
|
}
|
@@ -1,31 +1,8 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
2
|
+
import type { HTTPPath } from '@orpc/contract';
|
3
|
+
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
3
4
|
import type { AnyProcedure } from '../../procedure';
|
4
5
|
import type { AnyRouter } from '../../router';
|
5
|
-
export interface StandardHeaders {
|
6
|
-
[key: string]: string | string[] | undefined;
|
7
|
-
}
|
8
|
-
export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData;
|
9
|
-
export interface StandardRequest {
|
10
|
-
/**
|
11
|
-
* Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
|
12
|
-
*/
|
13
|
-
raw: Record<string, unknown>;
|
14
|
-
method: string;
|
15
|
-
url: URL;
|
16
|
-
headers: StandardHeaders;
|
17
|
-
/**
|
18
|
-
* The body has been parsed base on the content-type header.
|
19
|
-
* This method can safely call multiple times (cached).
|
20
|
-
*/
|
21
|
-
body(): Promise<StandardBody>;
|
22
|
-
signal?: AbortSignal;
|
23
|
-
}
|
24
|
-
export interface StandardResponse {
|
25
|
-
status: number;
|
26
|
-
headers: StandardHeaders;
|
27
|
-
body: StandardBody;
|
28
|
-
}
|
29
6
|
export type StandardParams = Record<string, string>;
|
30
7
|
export type StandardMatchResult = {
|
31
8
|
path: string[];
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta,
|
1
|
+
import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { BuilderDef } from './builder';
|
3
3
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
5
|
import type { FlattenLazy } from './lazy-utils';
|
5
6
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
6
7
|
import type { ProcedureHandler } from './procedure';
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import type { ContractProcedureDef, ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta,
|
1
|
+
import type { ContractProcedureDef, ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { BuilderWithMiddlewares, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithOutput, RouterBuilder } from './builder-variants';
|
3
3
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
5
|
import type { FlattenLazy } from './lazy-utils';
|
5
6
|
import type { AnyMiddleware, MapInputMiddleware, Middleware } from './middleware';
|
6
7
|
import type { DecoratedMiddleware } from './middleware-decorated';
|
package/dist/src/context.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { IsNever } from '@orpc/shared';
|
2
2
|
export type Context = Record<string, any>;
|
3
|
-
export type TypeInitialContext<T extends Context> = (type: T) => unknown;
|
4
3
|
export type MergedContext<T extends Context, U extends Context> = T & U;
|
5
4
|
export declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
6
5
|
export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ORPCErrorCode, ORPCErrorOptions } from '@orpc/client';
|
2
|
+
import type { ErrorMap, ErrorMapItem, SchemaInput } from '@orpc/contract';
|
3
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { ORPCError } from '@orpc/client';
|
5
|
+
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
6
|
+
export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
7
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
8
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
9
|
+
};
|
10
|
+
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
11
|
+
export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
12
|
+
//# sourceMappingURL=error.d.ts.map
|
@@ -1,9 +1,12 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ClientContext, ClientRest } from '@orpc/client';
|
2
|
+
import type { ErrorMap, Meta, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
3
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
4
|
import type { BuilderDef } from './builder';
|
3
5
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
6
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
7
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
8
|
import type { Procedure, ProcedureHandler } from './procedure';
|
6
|
-
import type {
|
9
|
+
import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
|
7
10
|
import type { DecoratedProcedure } from './procedure-decorated';
|
8
11
|
/**
|
9
12
|
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
@@ -13,11 +16,11 @@ export interface ImplementedProcedure<TInitialContext extends Context, TCurrentC
|
|
13
16
|
/**
|
14
17
|
* Make this procedure callable (works like a function while still being a procedure).
|
15
18
|
*/
|
16
|
-
callable<TClientContext>(...rest:
|
19
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
17
20
|
/**
|
18
21
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
19
22
|
*/
|
20
|
-
actionable<TClientContext>(...rest:
|
23
|
+
actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
21
24
|
}
|
22
25
|
/**
|
23
26
|
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta } from '@orpc/contract';
|
2
2
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { ProcedureImplementer } from './implementer-procedure';
|
4
5
|
import type { FlattenLazy } from './lazy-utils';
|
5
6
|
import type { Middleware } from './middleware';
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta } from '@orpc/contract';
|
2
2
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { ProcedureImplementer } from './implementer-procedure';
|
4
5
|
import type { ImplementerInternalWithMiddlewares } from './implementer-variants';
|
5
6
|
import type { AnyMiddleware, Middleware } from './middleware';
|
package/dist/src/index.d.ts
CHANGED
@@ -18,6 +18,8 @@ export * from './router';
|
|
18
18
|
export * from './router-accessible-lazy';
|
19
19
|
export * from './router-client';
|
20
20
|
export * from './utils';
|
21
|
-
export { isDefinedError, ORPCError, safe
|
21
|
+
export { isDefinedError, ORPCError, safe } from '@orpc/client';
|
22
|
+
export { eventIterator, type, ValidationError } from '@orpc/contract';
|
23
|
+
export { getEventMeta, withEventMeta } from '@orpc/server-standard';
|
22
24
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import type { Meta
|
1
|
+
import type { Meta } from '@orpc/contract';
|
2
2
|
import type { Context, MergedContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
5
|
export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
|
5
6
|
concat<UOutContext extends Context, UInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, MergedContext<TOutContext, UOutContext>, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>;
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import type { ErrorMap, Meta,
|
2
|
-
import type { Promisable } from '@orpc/shared';
|
1
|
+
import type { ErrorMap, Meta, Schema } from '@orpc/contract';
|
2
|
+
import type { MaybeOptionalOptions, Promisable } from '@orpc/shared';
|
3
3
|
import type { Context } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
5
|
import type { Procedure } from './procedure';
|
5
6
|
export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
6
7
|
output: TOutput;
|
@@ -11,9 +12,8 @@ export type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never,
|
|
11
12
|
} : {
|
12
13
|
context: TOutContext;
|
13
14
|
};
|
14
|
-
export type MiddlewareNextFnRest<TOutContext extends Context> = [options: MiddlewareNextFnOptions<TOutContext>] | (Record<never, never> extends TOutContext ? [] : never);
|
15
15
|
export interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
16
|
-
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest:
|
16
|
+
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
|
17
17
|
}
|
18
18
|
export interface MiddlewareOutputFn<TOutput> {
|
19
19
|
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
@@ -23,6 +23,7 @@ export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorCo
|
|
23
23
|
path: string[];
|
24
24
|
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
25
25
|
signal?: AbortSignal;
|
26
|
+
lastEventId: string | undefined;
|
26
27
|
next: MiddlewareNextFn<TInContext, TOutput>;
|
27
28
|
errors: TErrorConstructorMap;
|
28
29
|
}
|
@@ -1,13 +1,11 @@
|
|
1
|
-
import type {
|
1
|
+
import type { StandardHandlerOptions } from '../adapters/standard';
|
2
2
|
import type { Context } from '../context';
|
3
3
|
export interface Plugin<TContext extends Context> {
|
4
4
|
init?(options: StandardHandlerOptions<TContext>): void;
|
5
|
-
beforeCreateProcedureClient?(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
|
6
5
|
}
|
7
6
|
export declare class CompositePlugin<TContext extends Context> implements Plugin<TContext> {
|
8
7
|
private readonly plugins;
|
9
8
|
constructor(plugins?: Plugin<TContext>[]);
|
10
9
|
init(options: StandardHandlerOptions<TContext>): void;
|
11
|
-
beforeCreateProcedureClient(clientOptions: WellCreateProcedureClientOptions<TContext>, interceptorOptions: StandardHandlerInterceptorOptions<TContext>): void;
|
12
10
|
}
|
13
11
|
//# sourceMappingURL=base.d.ts.map
|
@@ -1,9 +1,11 @@
|
|
1
|
-
import type { Client,
|
2
|
-
import type { Interceptor, Value } from '@orpc/shared';
|
1
|
+
import type { Client, ClientContext } from '@orpc/client';
|
2
|
+
import type { Interceptor, MaybeOptionalOptions, Value } from '@orpc/shared';
|
3
3
|
import type { Context } from './context';
|
4
4
|
import type { Lazyable } from './lazy';
|
5
5
|
import type { Procedure } from './procedure';
|
6
|
-
|
6
|
+
import { type ErrorFromErrorMap, type ErrorMap, type Meta, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
7
|
+
import { type ORPCErrorConstructorMap } from './error';
|
8
|
+
export type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
7
9
|
export interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
8
10
|
context: TInitialContext;
|
9
11
|
input: SchemaInput<TInputSchema>;
|
@@ -11,11 +13,12 @@ export interface ProcedureClientInterceptorOptions<TInitialContext extends Conte
|
|
11
13
|
path: string[];
|
12
14
|
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
13
15
|
signal?: AbortSignal;
|
16
|
+
lastEventId: string | undefined;
|
14
17
|
}
|
15
18
|
/**
|
16
19
|
* Options for creating a procedure caller with comprehensive type safety
|
17
20
|
*/
|
18
|
-
export type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext> = {
|
21
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
19
22
|
/**
|
20
23
|
* This is helpful for logging and analytics.
|
21
24
|
*/
|
@@ -26,6 +29,5 @@ export type CreateProcedureClientOptions<TInitialContext extends Context, TInput
|
|
26
29
|
} : {
|
27
30
|
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
28
31
|
});
|
29
|
-
export
|
30
|
-
export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: CreateProcedureClientRest<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
32
|
+
export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
31
33
|
//# sourceMappingURL=procedure-client.d.ts.map
|