@orpc/server 0.0.0-next.ccd4e42 → 0.0.0-next.d0e429d
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-AJXRPY6I.js +32 -0
- package/dist/{chunk-NOA3GBJQ.js → chunk-MHVECKBC.js} +64 -23
- package/dist/chunk-NTHCS5CK.js +182 -0
- package/dist/chunk-TXHKQO7N.js +120 -0
- package/dist/fetch.js +6 -13
- package/dist/hono.js +18 -16
- package/dist/index.js +16 -7
- package/dist/next.js +6 -13
- package/dist/node.js +9 -151
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +0 -1
- package/dist/src/adapters/fetch/rpc-handler.d.ts +4 -2
- package/dist/src/adapters/fetch/types.d.ts +4 -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 +4 -2
- package/dist/src/adapters/node/types.d.ts +4 -2
- package/dist/src/adapters/standard/handler.d.ts +30 -10
- 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 +11 -0
- package/dist/src/plugins/cors.d.ts +19 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +21 -8
- 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 +7 -17
- package/dist/src/router.d.ts +1 -0
- package/dist/standard.js +5 -8
- package/package.json +12 -4
- package/dist/chunk-6RSW63UJ.js +0 -136
- package/dist/chunk-JHLUGXCM.js +0 -294
- package/dist/src/adapters/fetch/utils.d.ts +0 -6
- package/dist/src/adapters/node/utils.d.ts +0 -5
- package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
package/dist/index.js
CHANGED
@@ -21,7 +21,7 @@ import {
|
|
21
21
|
middlewareOutputFn,
|
22
22
|
setRouterContract,
|
23
23
|
unlazy
|
24
|
-
} from "./chunk-
|
24
|
+
} from "./chunk-MHVECKBC.js";
|
25
25
|
|
26
26
|
// src/builder.ts
|
27
27
|
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
@@ -50,10 +50,14 @@ function decorateMiddleware(middleware) {
|
|
50
50
|
decorated.concat = (concatMiddleware, mapInput) => {
|
51
51
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
52
52
|
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
53
|
-
const
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
const merged = middleware({
|
54
|
+
...options,
|
55
|
+
next: (...[nextOptions1]) => mapped({
|
56
|
+
...options,
|
57
|
+
context: { ...options.context, ...nextOptions1?.context },
|
58
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
59
|
+
}, input, output, ...rest)
|
60
|
+
}, input, output, ...rest);
|
57
61
|
return merged;
|
58
62
|
});
|
59
63
|
return concatted;
|
@@ -357,8 +361,10 @@ function createRouterClient(router, ...rest) {
|
|
357
361
|
}
|
358
362
|
|
359
363
|
// src/index.ts
|
360
|
-
import { isDefinedError, ORPCError, safe
|
364
|
+
import { isDefinedError, ORPCError, safe } from "@orpc/client";
|
365
|
+
import { eventIterator, type, ValidationError } from "@orpc/contract";
|
361
366
|
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
367
|
+
import { getEventMeta, withEventMeta } from "@orpc/standard-server";
|
362
368
|
export {
|
363
369
|
Builder,
|
364
370
|
DecoratedProcedure,
|
@@ -378,8 +384,10 @@ export {
|
|
378
384
|
deepSetLazyRouterPrefix,
|
379
385
|
eachAllContractProcedure,
|
380
386
|
eachContractProcedure,
|
387
|
+
eventIterator,
|
381
388
|
fallbackConfig,
|
382
389
|
flatLazy,
|
390
|
+
getEventMeta,
|
383
391
|
getLazyRouterPrefix,
|
384
392
|
getRouterChild,
|
385
393
|
getRouterContract,
|
@@ -399,6 +407,7 @@ export {
|
|
399
407
|
safe,
|
400
408
|
setRouterContract,
|
401
409
|
type,
|
402
|
-
unlazy
|
410
|
+
unlazy,
|
411
|
+
withEventMeta
|
403
412
|
};
|
404
413
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
import {
|
2
|
-
RPCHandler
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
} from "./chunk-6RSW63UJ.js";
|
8
|
-
import "./chunk-JHLUGXCM.js";
|
9
|
-
import "./chunk-NOA3GBJQ.js";
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-AJXRPY6I.js";
|
4
|
+
import "./chunk-NTHCS5CK.js";
|
5
|
+
import "./chunk-MHVECKBC.js";
|
6
|
+
import "./chunk-TXHKQO7N.js";
|
10
7
|
|
11
8
|
// src/adapters/next/serve.ts
|
12
9
|
import { value } from "@orpc/shared";
|
@@ -29,10 +26,6 @@ function serve(handler, ...[options]) {
|
|
29
26
|
}
|
30
27
|
export {
|
31
28
|
RPCHandler,
|
32
|
-
|
33
|
-
fetchRequestToStandardRequest,
|
34
|
-
serve,
|
35
|
-
standardBodyToFetchBody,
|
36
|
-
standardResponseToFetchResponse
|
29
|
+
serve
|
37
30
|
};
|
38
31
|
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
@@ -2,152 +2,12 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
6
|
-
import "./chunk-
|
7
|
-
|
8
|
-
// src/adapters/node/utils.ts
|
9
|
-
import { Buffer, File } from "node:buffer";
|
10
|
-
import { Readable } from "node:stream";
|
11
|
-
import { once } from "@orpc/shared";
|
12
|
-
import cd from "content-disposition";
|
13
|
-
function nodeHttpToStandardRequest(req, res) {
|
14
|
-
const method = req.method ?? "GET";
|
15
|
-
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
16
|
-
const host = req.headers.host ?? "localhost";
|
17
|
-
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
18
|
-
return {
|
19
|
-
raw: { request: req, response: res },
|
20
|
-
method,
|
21
|
-
url,
|
22
|
-
headers: req.headers,
|
23
|
-
body: once(() => {
|
24
|
-
return nodeHttpRequestToStandardBody(req);
|
25
|
-
}),
|
26
|
-
get signal() {
|
27
|
-
const signal = nodeHttpResponseToAbortSignal(res);
|
28
|
-
Object.defineProperty(this, "signal", { value: signal, writable: true });
|
29
|
-
return signal;
|
30
|
-
},
|
31
|
-
set signal(value) {
|
32
|
-
Object.defineProperty(this, "signal", { value, writable: true });
|
33
|
-
}
|
34
|
-
};
|
35
|
-
}
|
36
|
-
function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
37
|
-
return new Promise((resolve, reject) => {
|
38
|
-
res.on("error", reject);
|
39
|
-
res.on("finish", resolve);
|
40
|
-
if (standardResponse.body === void 0) {
|
41
|
-
res.writeHead(standardResponse.status, standardResponse.headers);
|
42
|
-
res.end();
|
43
|
-
}
|
44
|
-
if (standardResponse.body instanceof Blob) {
|
45
|
-
const resHeaders = {
|
46
|
-
...standardResponse.headers,
|
47
|
-
"content-type": standardResponse.body.type,
|
48
|
-
"content-length": standardResponse.body.size.toString()
|
49
|
-
};
|
50
|
-
if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
|
51
|
-
resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
|
52
|
-
}
|
53
|
-
res.writeHead(standardResponse.status, resHeaders);
|
54
|
-
Readable.fromWeb(
|
55
|
-
standardResponse.body.stream()
|
56
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
57
|
-
).pipe(res);
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
if (standardResponse.body instanceof FormData) {
|
61
|
-
const response = new Response(standardResponse.body);
|
62
|
-
res.writeHead(standardResponse.status, {
|
63
|
-
...standardResponse.headers,
|
64
|
-
"content-type": response.headers.get("content-type")
|
65
|
-
});
|
66
|
-
Readable.fromWeb(
|
67
|
-
response.body
|
68
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
69
|
-
).pipe(res);
|
70
|
-
return;
|
71
|
-
}
|
72
|
-
if (standardResponse.body instanceof URLSearchParams) {
|
73
|
-
res.writeHead(standardResponse.status, {
|
74
|
-
...standardResponse.headers,
|
75
|
-
"content-type": "application/x-www-form-urlencoded"
|
76
|
-
});
|
77
|
-
const string2 = standardResponse.body.toString();
|
78
|
-
res.end(string2);
|
79
|
-
return;
|
80
|
-
}
|
81
|
-
res.writeHead(standardResponse.status, {
|
82
|
-
...standardResponse.headers,
|
83
|
-
"content-type": "application/json"
|
84
|
-
});
|
85
|
-
const string = JSON.stringify(standardResponse.body);
|
86
|
-
res.end(string);
|
87
|
-
});
|
88
|
-
}
|
89
|
-
async function nodeHttpRequestToStandardBody(req) {
|
90
|
-
const method = req.method ?? "GET";
|
91
|
-
if (method === "GET" || method === "HEAD") {
|
92
|
-
return void 0;
|
93
|
-
}
|
94
|
-
const contentDisposition = req.headers["content-disposition"];
|
95
|
-
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
96
|
-
const contentType = req.headers["content-type"];
|
97
|
-
if (fileName) {
|
98
|
-
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
99
|
-
}
|
100
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
101
|
-
const text = await streamToString(req);
|
102
|
-
if (!text) {
|
103
|
-
return void 0;
|
104
|
-
}
|
105
|
-
return JSON.parse(text);
|
106
|
-
}
|
107
|
-
if (contentType.startsWith("multipart/form-data")) {
|
108
|
-
return await streamToFormData(req, contentType);
|
109
|
-
}
|
110
|
-
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
111
|
-
const text = await streamToString(req);
|
112
|
-
return new URLSearchParams(text);
|
113
|
-
}
|
114
|
-
if (contentType.startsWith("text/")) {
|
115
|
-
return await streamToString(req);
|
116
|
-
}
|
117
|
-
return streamToFile(req, "blob", contentType);
|
118
|
-
}
|
119
|
-
function streamToFormData(stream, contentType) {
|
120
|
-
const response = new Response(stream, {
|
121
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
122
|
-
headers: {
|
123
|
-
"content-type": contentType
|
124
|
-
}
|
125
|
-
});
|
126
|
-
return response.formData();
|
127
|
-
}
|
128
|
-
async function streamToString(stream) {
|
129
|
-
let string = "";
|
130
|
-
for await (const chunk of stream) {
|
131
|
-
string += chunk.toString();
|
132
|
-
}
|
133
|
-
return string;
|
134
|
-
}
|
135
|
-
async function streamToFile(stream, fileName, contentType) {
|
136
|
-
const chunks = [];
|
137
|
-
for await (const chunk of stream) {
|
138
|
-
chunks.push(chunk);
|
139
|
-
}
|
140
|
-
return new File([Buffer.concat(chunks)], fileName, { type: contentType });
|
141
|
-
}
|
142
|
-
function nodeHttpResponseToAbortSignal(res) {
|
143
|
-
const controller = new AbortController();
|
144
|
-
res.on("close", () => {
|
145
|
-
controller.abort();
|
146
|
-
});
|
147
|
-
return controller.signal;
|
148
|
-
}
|
5
|
+
} from "./chunk-NTHCS5CK.js";
|
6
|
+
import "./chunk-MHVECKBC.js";
|
7
|
+
import "./chunk-TXHKQO7N.js";
|
149
8
|
|
150
9
|
// src/adapters/node/rpc-handler.ts
|
10
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/standard-server-node";
|
151
11
|
var RPCHandler = class {
|
152
12
|
standardHandler;
|
153
13
|
constructor(router, options) {
|
@@ -155,19 +15,17 @@ var RPCHandler = class {
|
|
155
15
|
const matcher = options?.matcher ?? new RPCMatcher();
|
156
16
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
157
17
|
}
|
158
|
-
async handle(req, res, ...
|
159
|
-
const standardRequest =
|
160
|
-
const result = await this.standardHandler.handle(standardRequest,
|
18
|
+
async handle(req, res, ...[options]) {
|
19
|
+
const standardRequest = toStandardRequest(req, res);
|
20
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
161
21
|
if (!result.matched) {
|
162
22
|
return { matched: false };
|
163
23
|
}
|
164
|
-
await
|
24
|
+
await sendStandardResponse(res, result.response, options);
|
165
25
|
return { matched: true };
|
166
26
|
}
|
167
27
|
};
|
168
28
|
export {
|
169
|
-
RPCHandler
|
170
|
-
nodeHttpResponseSendStandardResponse,
|
171
|
-
nodeHttpToStandardRequest
|
29
|
+
RPCHandler
|
172
30
|
};
|
173
31
|
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
ADDED
@@ -1,10 +1,12 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
1
3
|
import type { Context } from '../../context';
|
2
4
|
import type { Router } from '../../router';
|
3
|
-
import type { RPCHandlerOptions,
|
5
|
+
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
4
6
|
import type { FetchHandler, FetchHandleResult } from './types';
|
5
7
|
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
6
8
|
private readonly standardHandler;
|
7
9
|
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
8
|
-
handle(request: Request, ...
|
10
|
+
handle(request: Request, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
9
11
|
}
|
10
12
|
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,5 +1,7 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
1
3
|
import type { Context } from '../../context';
|
2
|
-
import type {
|
4
|
+
import type { StandardHandleOptions } from '../standard';
|
3
5
|
export type FetchHandleResult = {
|
4
6
|
matched: true;
|
5
7
|
response: Response;
|
@@ -8,6 +10,6 @@ export type FetchHandleResult = {
|
|
8
10
|
response: undefined;
|
9
11
|
};
|
10
12
|
export interface FetchHandler<T extends Context> {
|
11
|
-
handle(request: Request, ...rest:
|
13
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
12
14
|
}
|
13
15
|
//# 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,12 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
1
3
|
import type { Context } from '../../context';
|
2
4
|
import type { Router } from '../../router';
|
3
|
-
import type { RPCHandlerOptions,
|
5
|
+
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
4
6
|
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
|
5
7
|
export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
6
8
|
private readonly standardHandler;
|
7
9
|
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
8
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...
|
10
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
9
11
|
}
|
10
12
|
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -1,7 +1,9 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
1
3
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
4
|
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
3
5
|
import type { Context } from '../../context';
|
4
|
-
import type {
|
6
|
+
import type { StandardHandleOptions } from '../standard';
|
5
7
|
export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
6
8
|
/**
|
7
9
|
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
@@ -16,6 +18,6 @@ export type NodeHttpHandleResult = {
|
|
16
18
|
matched: false;
|
17
19
|
};
|
18
20
|
export interface NodeHttpHandler<T extends Context> {
|
19
|
-
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest:
|
21
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
20
22
|
}
|
21
23
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1,8 +1,11 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type {
|
1
|
+
import type { ErrorFromErrorMap, HTTPPath, Meta, Schema, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
3
4
|
import type { Context } from '../../context';
|
5
|
+
import type { Plugin } from '../../plugins';
|
6
|
+
import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
|
4
7
|
import type { Router } from '../../router';
|
5
|
-
import type { StandardCodec, StandardMatcher
|
8
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
6
9
|
export type StandardHandleOptions<T extends Context> = {
|
7
10
|
prefix?: HTTPPath;
|
8
11
|
} & (Record<never, never> extends T ? {
|
@@ -10,7 +13,9 @@ export type StandardHandleOptions<T extends Context> = {
|
|
10
13
|
} : {
|
11
14
|
context: T;
|
12
15
|
});
|
13
|
-
export type
|
16
|
+
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
17
|
+
context: T;
|
18
|
+
};
|
14
19
|
export type StandardHandleResult = {
|
15
20
|
matched: true;
|
16
21
|
response: StandardResponse;
|
@@ -18,16 +23,31 @@ export type StandardHandleResult = {
|
|
18
23
|
matched: false;
|
19
24
|
response: undefined;
|
20
25
|
};
|
21
|
-
export
|
22
|
-
context: TContext;
|
26
|
+
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
23
27
|
request: StandardRequest;
|
24
|
-
}
|
28
|
+
};
|
29
|
+
export interface StandardHandlerOptions<TContext extends Context> {
|
30
|
+
plugins?: Plugin<TContext>[];
|
31
|
+
/**
|
32
|
+
* Interceptors at the request level, helpful when you want catch errors
|
33
|
+
*/
|
34
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
35
|
+
/**
|
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.
|
42
|
+
*/
|
43
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
|
25
44
|
}
|
26
|
-
export declare class StandardHandler<
|
45
|
+
export declare class StandardHandler<T extends Context> {
|
27
46
|
private readonly matcher;
|
28
47
|
private readonly codec;
|
29
48
|
private readonly options;
|
30
|
-
|
31
|
-
|
49
|
+
private readonly plugin;
|
50
|
+
constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
|
51
|
+
handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
32
52
|
}
|
33
53
|
//# sourceMappingURL=handler.d.ts.map
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import type { ORPCError } from '@orpc/
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
2
|
+
import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
2
3
|
import type { AnyProcedure } from '../../procedure';
|
3
|
-
import type { StandardCodec, StandardParams
|
4
|
-
import { RPCSerializer } from '
|
4
|
+
import type { StandardCodec, StandardParams } from './types';
|
5
|
+
import { RPCSerializer } from '@orpc/client/rpc';
|
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/standard-server';
|
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';
|
22
23
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
24
|
+
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
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>;
|