@orpc/server 0.0.0-next.caefe3a → 0.0.0-next.cc4cb21
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-EWOWWNDI.js +182 -0
- package/dist/{chunk-OEPDHGQ4.js → chunk-MHVECKBC.js} +60 -17
- package/dist/{chunk-OWMUECGT.js → chunk-TXHKQO7N.js} +20 -11
- package/dist/chunk-XT6IYOIS.js +32 -0
- package/dist/fetch.js +6 -14
- package/dist/hono.js +7 -15
- package/dist/index.js +16 -7
- package/dist/next.js +6 -14
- package/dist/node.js +7 -151
- 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 -9
- 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/cors.d.ts +2 -1
- 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 -4
- package/dist/src/router.d.ts +1 -0
- package/dist/standard.js +5 -9
- package/package.json +7 -4
- package/dist/chunk-M65OCXNG.js +0 -136
- package/dist/chunk-PZ44ZPVC.js +0 -308
- 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/node.js
CHANGED
@@ -2,154 +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 cd from "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
|
-
if (standardResponse.body === void 0) {
|
42
|
-
res.writeHead(standardResponse.status, standardResponse.headers);
|
43
|
-
res.end();
|
44
|
-
return;
|
45
|
-
}
|
46
|
-
if (standardResponse.body instanceof Blob) {
|
47
|
-
const resHeaders = {
|
48
|
-
...standardResponse.headers,
|
49
|
-
"content-type": standardResponse.body.type,
|
50
|
-
"content-length": standardResponse.body.size.toString()
|
51
|
-
};
|
52
|
-
if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
|
53
|
-
resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
|
54
|
-
}
|
55
|
-
res.writeHead(standardResponse.status, resHeaders);
|
56
|
-
Readable.fromWeb(
|
57
|
-
standardResponse.body.stream()
|
58
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
59
|
-
).pipe(res);
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
if (standardResponse.body instanceof FormData) {
|
63
|
-
const response = new Response(standardResponse.body);
|
64
|
-
res.writeHead(standardResponse.status, {
|
65
|
-
...standardResponse.headers,
|
66
|
-
"content-type": response.headers.get("content-type")
|
67
|
-
});
|
68
|
-
Readable.fromWeb(
|
69
|
-
response.body
|
70
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
71
|
-
).pipe(res);
|
72
|
-
return;
|
73
|
-
}
|
74
|
-
if (standardResponse.body instanceof URLSearchParams) {
|
75
|
-
res.writeHead(standardResponse.status, {
|
76
|
-
...standardResponse.headers,
|
77
|
-
"content-type": "application/x-www-form-urlencoded"
|
78
|
-
});
|
79
|
-
const string2 = standardResponse.body.toString();
|
80
|
-
res.end(string2);
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
res.writeHead(standardResponse.status, {
|
84
|
-
...standardResponse.headers,
|
85
|
-
"content-type": "application/json"
|
86
|
-
});
|
87
|
-
const string = JSON.stringify(standardResponse.body);
|
88
|
-
res.end(string);
|
89
|
-
});
|
90
|
-
}
|
91
|
-
async function nodeHttpRequestToStandardBody(req) {
|
92
|
-
const method = req.method ?? "GET";
|
93
|
-
if (method === "GET" || method === "HEAD") {
|
94
|
-
return void 0;
|
95
|
-
}
|
96
|
-
const contentDisposition = req.headers["content-disposition"];
|
97
|
-
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
98
|
-
const contentType = req.headers["content-type"];
|
99
|
-
if (fileName) {
|
100
|
-
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
101
|
-
}
|
102
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
103
|
-
const text = await streamToString(req);
|
104
|
-
if (!text) {
|
105
|
-
return void 0;
|
106
|
-
}
|
107
|
-
return JSON.parse(text);
|
108
|
-
}
|
109
|
-
if (contentType.startsWith("multipart/form-data")) {
|
110
|
-
return await streamToFormData(req, contentType);
|
111
|
-
}
|
112
|
-
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
113
|
-
const text = await streamToString(req);
|
114
|
-
return new URLSearchParams(text);
|
115
|
-
}
|
116
|
-
if (contentType.startsWith("text/")) {
|
117
|
-
return await streamToString(req);
|
118
|
-
}
|
119
|
-
return streamToFile(req, "blob", contentType);
|
120
|
-
}
|
121
|
-
function streamToFormData(stream, contentType) {
|
122
|
-
const response = new Response(stream, {
|
123
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
124
|
-
headers: {
|
125
|
-
"content-type": contentType
|
126
|
-
}
|
127
|
-
});
|
128
|
-
return response.formData();
|
129
|
-
}
|
130
|
-
async function streamToString(stream) {
|
131
|
-
let string = "";
|
132
|
-
for await (const chunk of stream) {
|
133
|
-
string += chunk.toString();
|
134
|
-
}
|
135
|
-
return string;
|
136
|
-
}
|
137
|
-
async function streamToFile(stream, fileName, contentType) {
|
138
|
-
const chunks = [];
|
139
|
-
for await (const chunk of stream) {
|
140
|
-
chunks.push(chunk);
|
141
|
-
}
|
142
|
-
return new File([Buffer.concat(chunks)], fileName, { type: contentType });
|
143
|
-
}
|
144
|
-
function nodeHttpResponseToAbortSignal(res) {
|
145
|
-
const controller = new AbortController();
|
146
|
-
res.on("close", () => {
|
147
|
-
controller.abort();
|
148
|
-
});
|
149
|
-
return controller.signal;
|
150
|
-
}
|
5
|
+
} from "./chunk-EWOWWNDI.js";
|
6
|
+
import "./chunk-MHVECKBC.js";
|
7
|
+
import "./chunk-TXHKQO7N.js";
|
151
8
|
|
152
9
|
// src/adapters/node/rpc-handler.ts
|
10
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/standard-server-node";
|
153
11
|
var RPCHandler = class {
|
154
12
|
standardHandler;
|
155
13
|
constructor(router, options) {
|
@@ -158,18 +16,16 @@ var RPCHandler = class {
|
|
158
16
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
159
17
|
}
|
160
18
|
async handle(req, res, ...rest) {
|
161
|
-
const standardRequest =
|
19
|
+
const standardRequest = toStandardRequest(req, res);
|
162
20
|
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
163
21
|
if (!result.matched) {
|
164
22
|
return { matched: false };
|
165
23
|
}
|
166
|
-
await
|
24
|
+
await sendStandardResponse(res, result.response);
|
167
25
|
return { matched: true };
|
168
26
|
}
|
169
27
|
};
|
170
28
|
export {
|
171
|
-
RPCHandler
|
172
|
-
nodeHttpResponseSendStandardResponse,
|
173
|
-
nodeHttpToStandardRequest
|
29
|
+
RPCHandler
|
174
30
|
};
|
175
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,9 +1,11 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Interceptor } from '@orpc/shared';
|
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';
|
4
5
|
import type { Plugin } from '../../plugins';
|
6
|
+
import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
|
5
7
|
import type { Router } from '../../router';
|
6
|
-
import type { StandardCodec, StandardMatcher
|
8
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
7
9
|
export type StandardHandleOptions<T extends Context> = {
|
8
10
|
prefix?: HTTPPath;
|
9
11
|
} & (Record<never, never> extends T ? {
|
@@ -14,7 +16,6 @@ export type StandardHandleOptions<T extends Context> = {
|
|
14
16
|
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
15
17
|
context: T;
|
16
18
|
};
|
17
|
-
export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
18
19
|
export type StandardHandleResult = {
|
19
20
|
matched: true;
|
20
21
|
response: StandardResponse;
|
@@ -32,16 +33,21 @@ export interface StandardHandlerOptions<TContext extends Context> {
|
|
32
33
|
*/
|
33
34
|
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
34
35
|
/**
|
35
|
-
* 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
|
36
37
|
*/
|
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>>>[];
|
38
44
|
}
|
39
|
-
export declare class StandardHandler<
|
45
|
+
export declare class StandardHandler<T extends Context> {
|
40
46
|
private readonly matcher;
|
41
47
|
private readonly codec;
|
42
48
|
private readonly options;
|
43
49
|
private readonly plugin;
|
44
|
-
constructor(router: Router<
|
45
|
-
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>;
|
46
52
|
}
|
47
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>;
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import type {
|
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
|
}
|
@@ -3,7 +3,8 @@ import type { Context } from '../context';
|
|
3
3
|
import type { Plugin } from './base';
|
4
4
|
import { type Value } from '@orpc/shared';
|
5
5
|
export interface CORSOptions<TContext extends Context> {
|
6
|
-
origin
|
6
|
+
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
7
|
+
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
7
8
|
allowMethods?: string[];
|
8
9
|
allowHeaders?: string[];
|
9
10
|
maxAge?: number;
|
@@ -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
|