@orpc/server 0.36.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-LBBHJSG5.js → chunk-2OH4QMZ4.js} +35 -26
- package/dist/{chunk-F75AQ6KO.js → chunk-BFGSRNYZ.js} +10 -4
- package/dist/{chunk-SV6DBVXJ.js → chunk-EDQKEHUX.js} +1 -1
- package/dist/fetch.js +3 -5
- package/dist/hono.js +4 -6
- package/dist/index.js +1 -1
- package/dist/next.js +3 -5
- package/dist/node.js +26 -31
- package/dist/src/adapters/fetch/utils.d.ts +0 -1
- package/dist/src/adapters/standard/rpc-serializer.d.ts +1 -1
- package/dist/src/adapters/standard/types.d.ts +1 -1
- package/dist/src/middleware.d.ts +1 -1
- package/dist/src/procedure.d.ts +1 -1
- package/dist/standard.js +2 -2
- package/package.json +4 -4
@@ -2,11 +2,11 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
5
|
+
} from "./chunk-BFGSRNYZ.js";
|
6
6
|
|
7
7
|
// src/adapters/fetch/utils.ts
|
8
8
|
import { once } from "@orpc/shared";
|
9
|
-
import
|
9
|
+
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
10
10
|
function fetchHeadersToStandardHeaders(headers) {
|
11
11
|
const standardHeaders = {};
|
12
12
|
for (const [key, value] of headers) {
|
@@ -24,13 +24,15 @@ async function fetchReToStandardBody(re) {
|
|
24
24
|
if (!re.body) {
|
25
25
|
return void 0;
|
26
26
|
}
|
27
|
-
const
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
const contentDisposition2 = re.headers.get("content-disposition");
|
28
|
+
if (contentDisposition2) {
|
29
|
+
const fileName = parseContentDisposition(contentDisposition2).parameters.filename;
|
30
|
+
if (typeof fileName === "string") {
|
31
|
+
const blob2 = await re.blob();
|
32
|
+
return new File([blob2], fileName, {
|
33
|
+
type: blob2.type
|
34
|
+
});
|
35
|
+
}
|
34
36
|
}
|
35
37
|
const contentType = re.headers.get("content-type");
|
36
38
|
if (!contentType || contentType.startsWith("application/json")) {
|
@@ -85,24 +87,32 @@ function standardResponseToFetchHeaders(response) {
|
|
85
87
|
fetchHeaders.append(key, value);
|
86
88
|
}
|
87
89
|
}
|
88
|
-
if (response.body instanceof Blob && !fetchHeaders.has("content-disposition")) {
|
89
|
-
fetchHeaders.set("content-disposition", cd(response.body instanceof File ? response.body.name : "blob"));
|
90
|
-
} else if (!(response.body instanceof Blob) && !(response.body instanceof URLSearchParams) && !(response.body instanceof FormData) && response.body !== void 0 && !fetchHeaders.has("content-type")) {
|
91
|
-
fetchHeaders.set("content-type", "application/json");
|
92
|
-
}
|
93
90
|
return fetchHeaders;
|
94
91
|
}
|
95
|
-
function standardBodyToFetchBody(body) {
|
96
|
-
if (body instanceof Blob || body instanceof FormData || body instanceof URLSearchParams) {
|
97
|
-
return body;
|
98
|
-
}
|
99
|
-
return JSON.stringify(body);
|
100
|
-
}
|
101
92
|
function standardResponseToFetchResponse(response) {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
93
|
+
const resHeaders = standardResponseToFetchHeaders(response);
|
94
|
+
resHeaders.delete("content-type");
|
95
|
+
resHeaders.delete("content-disposition");
|
96
|
+
if (response.body === void 0) {
|
97
|
+
return new Response(void 0, { headers: resHeaders, status: response.status });
|
98
|
+
}
|
99
|
+
if (response.body instanceof Blob) {
|
100
|
+
resHeaders.set("content-type", response.body.type);
|
101
|
+
resHeaders.set("content-length", response.body.size.toString());
|
102
|
+
resHeaders.set(
|
103
|
+
"content-disposition",
|
104
|
+
contentDisposition(response.body instanceof File ? response.body.name : "blob", { type: "inline" })
|
105
|
+
);
|
106
|
+
return new Response(response.body, { headers: resHeaders, status: response.status });
|
107
|
+
}
|
108
|
+
if (response.body instanceof FormData) {
|
109
|
+
return new Response(response.body, { headers: resHeaders, status: response.status });
|
110
|
+
}
|
111
|
+
if (response.body instanceof URLSearchParams) {
|
112
|
+
return new Response(response.body, { headers: resHeaders, status: response.status });
|
113
|
+
}
|
114
|
+
resHeaders.set("content-type", "application/json");
|
115
|
+
return new Response(JSON.stringify(response.body), { headers: resHeaders, status: response.status });
|
106
116
|
}
|
107
117
|
|
108
118
|
// src/adapters/fetch/rpc-handler.ts
|
@@ -129,8 +139,7 @@ var RPCHandler = class {
|
|
129
139
|
export {
|
130
140
|
fetchReToStandardBody,
|
131
141
|
fetchRequestToStandardRequest,
|
132
|
-
standardBodyToFetchBody,
|
133
142
|
standardResponseToFetchResponse,
|
134
143
|
RPCHandler
|
135
144
|
};
|
136
|
-
//# sourceMappingURL=chunk-
|
145
|
+
//# sourceMappingURL=chunk-2OH4QMZ4.js.map
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
getRouterChild,
|
7
7
|
isProcedure,
|
8
8
|
unlazy
|
9
|
-
} from "./chunk-
|
9
|
+
} from "./chunk-EDQKEHUX.js";
|
10
10
|
import {
|
11
11
|
CompositePlugin
|
12
12
|
} from "./chunk-XFBAK67J.js";
|
@@ -75,9 +75,12 @@ var StandardHandler = class {
|
|
75
75
|
};
|
76
76
|
|
77
77
|
// src/adapters/standard/rpc-serializer.ts
|
78
|
-
import { findDeepMatches,
|
78
|
+
import { findDeepMatches, isObject, set } from "@orpc/shared";
|
79
79
|
var RPCSerializer = class {
|
80
80
|
serialize(data) {
|
81
|
+
if (data === void 0) {
|
82
|
+
return void 0;
|
83
|
+
}
|
81
84
|
if (data instanceof Blob) {
|
82
85
|
return data;
|
83
86
|
}
|
@@ -95,6 +98,9 @@ var RPCSerializer = class {
|
|
95
98
|
return form;
|
96
99
|
}
|
97
100
|
deserialize(serialized) {
|
101
|
+
if (serialized === void 0) {
|
102
|
+
return void 0;
|
103
|
+
}
|
98
104
|
if (serialized instanceof Blob) {
|
99
105
|
return serialized;
|
100
106
|
}
|
@@ -131,7 +137,7 @@ function serializeRPCJson(value, segments = [], meta = []) {
|
|
131
137
|
meta.push(["url", segments]);
|
132
138
|
return { json: value.toString(), meta };
|
133
139
|
}
|
134
|
-
if (
|
140
|
+
if (isObject(value)) {
|
135
141
|
const json = {};
|
136
142
|
for (const k in value) {
|
137
143
|
json[k] = serializeRPCJson(value[k], [...segments, k], meta).json;
|
@@ -310,4 +316,4 @@ export {
|
|
310
316
|
RPCCodec,
|
311
317
|
RPCMatcher
|
312
318
|
};
|
313
|
-
//# sourceMappingURL=chunk-
|
319
|
+
//# sourceMappingURL=chunk-BFGSRNYZ.js.map
|
package/dist/fetch.js
CHANGED
@@ -2,17 +2,15 @@ import {
|
|
2
2
|
RPCHandler,
|
3
3
|
fetchReToStandardBody,
|
4
4
|
fetchRequestToStandardRequest,
|
5
|
-
standardBodyToFetchBody,
|
6
5
|
standardResponseToFetchResponse
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
6
|
+
} from "./chunk-2OH4QMZ4.js";
|
7
|
+
import "./chunk-BFGSRNYZ.js";
|
8
|
+
import "./chunk-EDQKEHUX.js";
|
10
9
|
import "./chunk-XFBAK67J.js";
|
11
10
|
export {
|
12
11
|
RPCHandler,
|
13
12
|
fetchReToStandardBody,
|
14
13
|
fetchRequestToStandardRequest,
|
15
|
-
standardBodyToFetchBody,
|
16
14
|
standardResponseToFetchResponse
|
17
15
|
};
|
18
16
|
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
CHANGED
@@ -2,11 +2,10 @@ import {
|
|
2
2
|
RPCHandler,
|
3
3
|
fetchReToStandardBody,
|
4
4
|
fetchRequestToStandardRequest,
|
5
|
-
standardBodyToFetchBody,
|
6
5
|
standardResponseToFetchResponse
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
6
|
+
} from "./chunk-2OH4QMZ4.js";
|
7
|
+
import "./chunk-BFGSRNYZ.js";
|
8
|
+
import "./chunk-EDQKEHUX.js";
|
10
9
|
import "./chunk-XFBAK67J.js";
|
11
10
|
|
12
11
|
// src/adapters/hono/middleware.ts
|
@@ -26,7 +25,7 @@ function createMiddleware(handler, ...[options]) {
|
|
26
25
|
const context = await value(options?.context ?? {}, c);
|
27
26
|
const { matched, response } = await handler.handle(request, { ...options, context });
|
28
27
|
if (matched) {
|
29
|
-
return c.
|
28
|
+
return c.newResponse(response.body, response);
|
30
29
|
}
|
31
30
|
await next();
|
32
31
|
};
|
@@ -36,7 +35,6 @@ export {
|
|
36
35
|
createMiddleware,
|
37
36
|
fetchReToStandardBody,
|
38
37
|
fetchRequestToStandardRequest,
|
39
|
-
standardBodyToFetchBody,
|
40
38
|
standardResponseToFetchResponse
|
41
39
|
};
|
42
40
|
//# sourceMappingURL=hono.js.map
|
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-EDQKEHUX.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";
|
package/dist/next.js
CHANGED
@@ -2,11 +2,10 @@ import {
|
|
2
2
|
RPCHandler,
|
3
3
|
fetchReToStandardBody,
|
4
4
|
fetchRequestToStandardRequest,
|
5
|
-
standardBodyToFetchBody,
|
6
5
|
standardResponseToFetchResponse
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
6
|
+
} from "./chunk-2OH4QMZ4.js";
|
7
|
+
import "./chunk-BFGSRNYZ.js";
|
8
|
+
import "./chunk-EDQKEHUX.js";
|
10
9
|
import "./chunk-XFBAK67J.js";
|
11
10
|
|
12
11
|
// src/adapters/next/serve.ts
|
@@ -33,7 +32,6 @@ export {
|
|
33
32
|
fetchReToStandardBody,
|
34
33
|
fetchRequestToStandardRequest,
|
35
34
|
serve,
|
36
|
-
standardBodyToFetchBody,
|
37
35
|
standardResponseToFetchResponse
|
38
36
|
};
|
39
37
|
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
@@ -2,15 +2,15 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
6
|
-
import "./chunk-
|
5
|
+
} from "./chunk-BFGSRNYZ.js";
|
6
|
+
import "./chunk-EDQKEHUX.js";
|
7
7
|
import "./chunk-XFBAK67J.js";
|
8
8
|
|
9
9
|
// src/adapters/node/utils.ts
|
10
10
|
import { Buffer, File } from "node:buffer";
|
11
11
|
import { Readable } from "node:stream";
|
12
12
|
import { once } from "@orpc/shared";
|
13
|
-
import
|
13
|
+
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
14
14
|
function nodeHttpToStandardRequest(req, res) {
|
15
15
|
const method = req.method ?? "GET";
|
16
16
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
@@ -38,20 +38,21 @@ function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
|
38
38
|
return new Promise((resolve, reject) => {
|
39
39
|
res.on("error", reject);
|
40
40
|
res.on("finish", resolve);
|
41
|
+
const resHeaders = standardResponse.headers;
|
42
|
+
delete resHeaders["content-type"];
|
43
|
+
delete resHeaders["content-disposition"];
|
41
44
|
if (standardResponse.body === void 0) {
|
42
45
|
res.writeHead(standardResponse.status, standardResponse.headers);
|
43
46
|
res.end();
|
44
47
|
return;
|
45
48
|
}
|
46
49
|
if (standardResponse.body instanceof Blob) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
|
54
|
-
}
|
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
|
+
);
|
55
56
|
res.writeHead(standardResponse.status, resHeaders);
|
56
57
|
Readable.fromWeb(
|
57
58
|
standardResponse.body.stream()
|
@@ -61,10 +62,8 @@ function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
|
61
62
|
}
|
62
63
|
if (standardResponse.body instanceof FormData) {
|
63
64
|
const response = new Response(standardResponse.body);
|
64
|
-
|
65
|
-
|
66
|
-
"content-type": response.headers.get("content-type")
|
67
|
-
});
|
65
|
+
resHeaders["content-type"] = response.headers.get("content-type");
|
66
|
+
res.writeHead(standardResponse.status, resHeaders);
|
68
67
|
Readable.fromWeb(
|
69
68
|
response.body
|
70
69
|
// Conflict between types=node and lib=dom so we need to cast it
|
@@ -72,20 +71,14 @@ function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
|
72
71
|
return;
|
73
72
|
}
|
74
73
|
if (standardResponse.body instanceof URLSearchParams) {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
});
|
79
|
-
const string2 = standardResponse.body.toString();
|
80
|
-
res.end(string2);
|
74
|
+
resHeaders["content-type"] = "application/x-www-form-urlencoded";
|
75
|
+
res.writeHead(standardResponse.status, resHeaders);
|
76
|
+
res.end(standardResponse.body.toString());
|
81
77
|
return;
|
82
78
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
});
|
87
|
-
const string = JSON.stringify(standardResponse.body);
|
88
|
-
res.end(string);
|
79
|
+
resHeaders["content-type"] = "application/json";
|
80
|
+
res.writeHead(standardResponse.status, resHeaders);
|
81
|
+
res.end(JSON.stringify(standardResponse.body));
|
89
82
|
});
|
90
83
|
}
|
91
84
|
async function nodeHttpRequestToStandardBody(req) {
|
@@ -93,11 +86,13 @@ async function nodeHttpRequestToStandardBody(req) {
|
|
93
86
|
if (method === "GET" || method === "HEAD") {
|
94
87
|
return void 0;
|
95
88
|
}
|
96
|
-
const
|
97
|
-
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
89
|
+
const contentDisposition2 = req.headers["content-disposition"];
|
98
90
|
const contentType = req.headers["content-type"];
|
99
|
-
if (
|
100
|
-
|
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
|
+
}
|
101
96
|
}
|
102
97
|
if (!contentType || contentType.startsWith("application/json")) {
|
103
98
|
const text = await streamToString(req);
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { StandardBody, StandardRequest, StandardResponse } from '../standard';
|
2
2
|
export declare function fetchReToStandardBody(re: Request | Response): Promise<StandardBody>;
|
3
3
|
export declare function fetchRequestToStandardRequest(request: Request): StandardRequest;
|
4
|
-
export declare function standardBodyToFetchBody(body: StandardBody): Blob | FormData | URLSearchParams | string | undefined;
|
5
4
|
export declare function standardResponseToFetchResponse(response: StandardResponse): Response;
|
6
5
|
//# sourceMappingURL=utils.d.ts.map
|
@@ -3,7 +3,7 @@ export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | '
|
|
3
3
|
export type RPCSerialized = {
|
4
4
|
json: unknown;
|
5
5
|
meta: RPCSerializedJsonMeta;
|
6
|
-
} | FormData | Blob;
|
6
|
+
} | FormData | Blob | undefined;
|
7
7
|
export type RPCSerializedFormDataMaps = Segment[][];
|
8
8
|
export declare class RPCSerializer {
|
9
9
|
serialize(data: unknown): RPCSerialized;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { HTTPPath, ORPCError } from '@orpc/contract';
|
2
2
|
import type { JsonValue } from '@orpc/shared';
|
3
3
|
import type { AnyProcedure } from '../../procedure';
|
4
4
|
import type { AnyRouter } from '../../router';
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ErrorMap, Meta, ORPCErrorConstructorMap, Schema } from '@orpc/contract';
|
2
2
|
import type { Promisable } from '@orpc/shared';
|
3
3
|
import type { Context } from './context';
|
4
4
|
import type { Procedure } from './procedure';
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Promisable } from '@orpc/shared';
|
3
3
|
import type { Context, TypeInitialContext } from './context';
|
4
4
|
import type { AnyMiddleware } from './middleware';
|
package/dist/standard.js
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.37.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -63,9 +63,9 @@
|
|
63
63
|
"next": ">=14.0.0"
|
64
64
|
},
|
65
65
|
"dependencies": {
|
66
|
-
"content-disposition": "^
|
67
|
-
"@orpc/contract": "0.
|
68
|
-
"@orpc/shared": "0.
|
66
|
+
"@tinyhttp/content-disposition": "^2.2.2",
|
67
|
+
"@orpc/contract": "0.37.0",
|
68
|
+
"@orpc/shared": "0.37.0"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
71
71
|
"light-my-request": "^6.5.1"
|