@trpc/server 11.0.0-rc.340 → 11.0.0-rc.345
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/@trpc/server/http.d.ts +0 -1
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +2 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts +10 -0
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/content-type/json/index.js +59 -0
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +57 -0
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +19 -9
- package/dist/adapters/aws-lambda/index.mjs +19 -9
- package/dist/adapters/aws-lambda/utils.d.ts +3 -12
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +12 -1
- package/dist/adapters/aws-lambda/utils.mjs +12 -2
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +4 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +1 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +22 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +20 -0
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +0 -1
- package/dist/adapters/express.mjs +0 -1
- package/dist/adapters/fastify/content-type/json/index.d.ts +8 -0
- package/dist/adapters/fastify/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/fastify/content-type/json/index.js +59 -0
- package/dist/adapters/fastify/content-type/json/index.mjs +57 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +1 -9
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +10 -2
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +10 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/types.d.ts +11 -0
- package/dist/adapters/fastify/types.d.ts.map +1 -0
- package/dist/adapters/fetch/content-type/json/index.d.ts +9 -0
- package/dist/adapters/fetch/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/fetch/content-type/json/index.js +58 -0
- package/dist/adapters/fetch/content-type/json/index.mjs +56 -0
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -5
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +16 -2
- package/dist/adapters/fetch/fetchRequestHandler.mjs +16 -2
- package/dist/adapters/fetch/types.d.ts +9 -12
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +2 -7
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +0 -1
- package/dist/adapters/next.mjs +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -72
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +5 -76
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +5 -19
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +14 -39
- package/dist/adapters/node-http/content-type/form-data/index.mjs +15 -35
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +2 -2
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -12
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +1 -12
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +4 -12
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +4 -12
- package/dist/adapters/node-http/content-type/json/index.d.ts +4 -1
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/index.js +59 -10
- package/dist/adapters/node-http/content-type/json/index.mjs +59 -10
- package/dist/adapters/node-http/content-type/octet/index.d.ts +5 -0
- package/dist/adapters/node-http/content-type/octet/index.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/octet/index.js +19 -0
- package/dist/adapters/node-http/content-type/octet/index.mjs +17 -0
- package/dist/adapters/node-http/content-type/types.d.ts +8 -0
- package/dist/adapters/node-http/content-type/types.d.ts.map +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +19 -21
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +20 -22
- package/dist/adapters/node-http/types.d.ts +8 -19
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +0 -1
- package/dist/adapters/standalone.mjs +0 -1
- package/dist/adapters/ws.d.ts +2 -12
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/bundle-analysis.json +266 -207
- package/dist/http.js +0 -2
- package/dist/http.mjs +0 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +16 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.js +23 -0
- package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +21 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +6 -14
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +5 -5
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +25 -22
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +25 -22
- package/dist/unstable-core-do-not-import/http/types.d.ts +0 -2
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +21 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +0 -2
- package/dist/unstable-core-do-not-import.mjs +0 -1
- package/package.json +3 -3
- package/src/@trpc/server/http.ts +0 -1
- package/src/@trpc/server/index.ts +7 -0
- package/src/adapters/aws-lambda/content-type/json/index.ts +99 -0
- package/src/adapters/aws-lambda/index.ts +24 -9
- package/src/adapters/aws-lambda/utils.ts +21 -15
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +21 -0
- package/src/adapters/express.ts +1 -6
- package/src/adapters/fastify/content-type/json/index.ts +97 -0
- package/src/adapters/fastify/fastifyRequestHandler.ts +15 -21
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fastify/types.ts +22 -0
- package/src/adapters/fetch/content-type/json/index.ts +96 -0
- package/src/adapters/fetch/fetchRequestHandler.ts +22 -10
- package/src/adapters/fetch/types.ts +22 -15
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -9
- package/src/adapters/next.ts +1 -6
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +7 -7
- package/src/adapters/node-http/content-type/form-data/index.ts +29 -51
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +2 -2
- package/src/adapters/node-http/content-type/json/getPostBody.ts +9 -18
- package/src/adapters/node-http/content-type/json/index.ts +85 -5
- package/src/adapters/node-http/content-type/octet/index.ts +29 -0
- package/src/adapters/node-http/{internals/contentType.ts → content-type/types.ts} +2 -14
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +22 -35
- package/src/adapters/node-http/types.ts +46 -46
- package/src/adapters/standalone.ts +1 -2
- package/src/adapters/ws.ts +9 -14
- package/src/unstable-core-do-not-import/contentTypeParsers.ts +37 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +9 -84
- package/src/unstable-core-do-not-import/http/index.ts +0 -1
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +29 -28
- package/src/unstable-core-do-not-import/http/types.ts +0 -2
- package/src/unstable-core-do-not-import/rootConfig.ts +31 -0
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/unstable-core-do-not-import/http/contentType.js +0 -54
- package/dist/unstable-core-do-not-import/http/contentType.mjs +0 -52
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAapD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAE5D,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,kBAgGjE"}
|
|
@@ -4,6 +4,8 @@ var node_stream = require('node:stream');
|
|
|
4
4
|
var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
5
5
|
var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
6
6
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
7
|
+
var selectContentHandlerOrUnsupportedMediaType = require('../content-handlers/selectContentHandlerOrUnsupportedMediaType.js');
|
|
8
|
+
var index = require('./content-type/json/index.js');
|
|
7
9
|
|
|
8
10
|
async function fastifyRequestHandler(opts) {
|
|
9
11
|
const createContext = async (innerOpts)=>{
|
|
@@ -16,8 +18,7 @@ async function fastifyRequestHandler(opts) {
|
|
|
16
18
|
const req = {
|
|
17
19
|
query,
|
|
18
20
|
method: opts.req.method,
|
|
19
|
-
headers: opts.req.headers
|
|
20
|
-
body: opts.req.body ?? 'null'
|
|
21
|
+
headers: opts.req.headers
|
|
21
22
|
};
|
|
22
23
|
let resolve;
|
|
23
24
|
const promise = new Promise((r)=>resolve = r);
|
|
@@ -52,9 +53,16 @@ async function fastifyRequestHandler(opts) {
|
|
|
52
53
|
stream.push(formatter(index, string));
|
|
53
54
|
}
|
|
54
55
|
};
|
|
56
|
+
const [contentTypeHandler, unsupportedMediaTypeError] = selectContentHandlerOrUnsupportedMediaType.selectContentHandlerOrUnsupportedMediaType([
|
|
57
|
+
index.getFastifyHTTPJSONContentTypeHandler()
|
|
58
|
+
], opts);
|
|
55
59
|
resolveHTTPResponse.resolveHTTPResponse({
|
|
56
60
|
...opts,
|
|
57
61
|
req,
|
|
62
|
+
error: unsupportedMediaTypeError,
|
|
63
|
+
async getInput (info) {
|
|
64
|
+
return await contentTypeHandler?.getInputs(opts, info);
|
|
65
|
+
},
|
|
58
66
|
createContext,
|
|
59
67
|
onError (o) {
|
|
60
68
|
opts?.onError?.({
|
|
@@ -2,6 +2,8 @@ import { Readable } from 'node:stream';
|
|
|
2
2
|
import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
3
3
|
import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
4
4
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
5
|
+
import { selectContentHandlerOrUnsupportedMediaType } from '../content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs';
|
|
6
|
+
import { getFastifyHTTPJSONContentTypeHandler } from './content-type/json/index.mjs';
|
|
5
7
|
|
|
6
8
|
async function fastifyRequestHandler(opts) {
|
|
7
9
|
const createContext = async (innerOpts)=>{
|
|
@@ -14,8 +16,7 @@ async function fastifyRequestHandler(opts) {
|
|
|
14
16
|
const req = {
|
|
15
17
|
query,
|
|
16
18
|
method: opts.req.method,
|
|
17
|
-
headers: opts.req.headers
|
|
18
|
-
body: opts.req.body ?? 'null'
|
|
19
|
+
headers: opts.req.headers
|
|
19
20
|
};
|
|
20
21
|
let resolve;
|
|
21
22
|
const promise = new Promise((r)=>resolve = r);
|
|
@@ -50,9 +51,16 @@ async function fastifyRequestHandler(opts) {
|
|
|
50
51
|
stream.push(formatter(index, string));
|
|
51
52
|
}
|
|
52
53
|
};
|
|
54
|
+
const [contentTypeHandler, unsupportedMediaTypeError] = selectContentHandlerOrUnsupportedMediaType([
|
|
55
|
+
getFastifyHTTPJSONContentTypeHandler()
|
|
56
|
+
], opts);
|
|
53
57
|
resolveHTTPResponse({
|
|
54
58
|
...opts,
|
|
55
59
|
req,
|
|
60
|
+
error: unsupportedMediaTypeError,
|
|
61
|
+
async getInput (info) {
|
|
62
|
+
return await contentTypeHandler?.getInputs(opts, info);
|
|
63
|
+
},
|
|
56
64
|
createContext,
|
|
57
65
|
onError (o) {
|
|
58
66
|
opts?.onError?.({
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
10
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
11
|
-
import type { FastifyHandlerOptions } from '.';
|
|
12
11
|
import type { AnyRouter } from '../../@trpc/server';
|
|
13
12
|
import type { NodeHTTPCreateContextFnOptions } from '../node-http';
|
|
13
|
+
import type { FastifyHandlerOptions } from './types';
|
|
14
14
|
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
15
15
|
prefix?: string;
|
|
16
16
|
useWSS?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fastifyTRPCPlugin.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAInE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,SAAS;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;CAC3E;AAED,MAAM,MAAM,2BAA2B,GAAG,8BAA8B,CACtE,cAAc,EACd,YAAY,CACb,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,EACvC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,QAmC5B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import type { AnyRouter } from '../../@trpc/server';
|
|
3
|
+
import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
|
|
4
|
+
import type { NodeHTTPConditionCreateContextOption } from '../node-http';
|
|
5
|
+
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPConditionCreateContextOption<TRouter, TRequest, TResponse>;
|
|
6
|
+
export type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
7
|
+
req: TRequest;
|
|
8
|
+
res: TResponse;
|
|
9
|
+
path: string;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,oCAAoC,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE,MAAM,MAAM,4BAA4B,CACtC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyRouter } from '../../../../@trpc/server';
|
|
2
|
+
import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
|
|
3
|
+
import type { FetchHandlerRequestOptions } from '../../types';
|
|
4
|
+
export interface FetchHTTPContentTypeHandler<TRouter extends AnyRouter> extends BaseContentTypeHandler<FetchHandlerRequestOptions<TRouter> & {
|
|
5
|
+
url: URL;
|
|
6
|
+
}> {
|
|
7
|
+
}
|
|
8
|
+
export declare const getFetchHTTPJSONContentTypeHandler: <TRouter extends AnyRouter>() => FetchHTTPContentTypeHandler<TRouter>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/fetch/content-type/json/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,WAAW,2BAA2B,CAAC,OAAO,SAAS,SAAS,CACpE,SAAQ,sBAAsB,CAC5B,0BAA0B,CAAC,OAAO,CAAC,GAAG;IACpC,GAAG,EAAE,GAAG,CAAC;CACV,CACF;CAAG;AAEN,eAAO,MAAM,kCAAkC,EAAE,CAC/C,OAAO,SAAS,SAAS,OACpB,2BAA2B,CAAC,OAAO,CA6ExC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var TRPCError = require('../../../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
|
+
require('../../../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
+
|
|
6
|
+
// @trpc/server
|
|
7
|
+
const getFetchHTTPJSONContentTypeHandler = ()=>({
|
|
8
|
+
name: 'fetch-json',
|
|
9
|
+
isMatch (opts) {
|
|
10
|
+
return !!opts.req.headers.get('content-type')?.startsWith('application/json');
|
|
11
|
+
},
|
|
12
|
+
getInputs: async (opts, info)=>{
|
|
13
|
+
async function getRawProcedureInputOrThrow() {
|
|
14
|
+
const { req } = opts;
|
|
15
|
+
try {
|
|
16
|
+
if (req.method === 'GET') {
|
|
17
|
+
const input = opts.url.searchParams.get('input');
|
|
18
|
+
if (!input) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return JSON.parse(input);
|
|
22
|
+
}
|
|
23
|
+
const body = opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : '';
|
|
24
|
+
if (typeof body === 'string') {
|
|
25
|
+
// A mutation with no inputs will have req.body === ''
|
|
26
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
27
|
+
}
|
|
28
|
+
return body;
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
throw new TRPCError.TRPCError({
|
|
31
|
+
code: 'PARSE_ERROR',
|
|
32
|
+
cause
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
37
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
38
|
+
};
|
|
39
|
+
const rawInput = await getRawProcedureInputOrThrow();
|
|
40
|
+
if (rawInput === undefined) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const transformer = opts.router._def._config.transformer;
|
|
44
|
+
if (!info.isBatchCall) {
|
|
45
|
+
return deserializeInputValue(rawInput, transformer);
|
|
46
|
+
}
|
|
47
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
48
|
+
throw new TRPCError.TRPCError({
|
|
49
|
+
code: 'BAD_REQUEST',
|
|
50
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const rawValue = rawInput[info.batch];
|
|
54
|
+
return deserializeInputValue(rawValue, transformer);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
exports.getFetchHTTPJSONContentTypeHandler = getFetchHTTPJSONContentTypeHandler;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
|
|
4
|
+
// @trpc/server
|
|
5
|
+
const getFetchHTTPJSONContentTypeHandler = ()=>({
|
|
6
|
+
name: 'fetch-json',
|
|
7
|
+
isMatch (opts) {
|
|
8
|
+
return !!opts.req.headers.get('content-type')?.startsWith('application/json');
|
|
9
|
+
},
|
|
10
|
+
getInputs: async (opts, info)=>{
|
|
11
|
+
async function getRawProcedureInputOrThrow() {
|
|
12
|
+
const { req } = opts;
|
|
13
|
+
try {
|
|
14
|
+
if (req.method === 'GET') {
|
|
15
|
+
const input = opts.url.searchParams.get('input');
|
|
16
|
+
if (!input) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return JSON.parse(input);
|
|
20
|
+
}
|
|
21
|
+
const body = opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : '';
|
|
22
|
+
if (typeof body === 'string') {
|
|
23
|
+
// A mutation with no inputs will have req.body === ''
|
|
24
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
25
|
+
}
|
|
26
|
+
return body;
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
throw new TRPCError({
|
|
29
|
+
code: 'PARSE_ERROR',
|
|
30
|
+
cause
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
35
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
36
|
+
};
|
|
37
|
+
const rawInput = await getRawProcedureInputOrThrow();
|
|
38
|
+
if (rawInput === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const transformer = opts.router._def._config.transformer;
|
|
42
|
+
if (!info.isBatchCall) {
|
|
43
|
+
return deserializeInputValue(rawInput, transformer);
|
|
44
|
+
}
|
|
45
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
46
|
+
throw new TRPCError({
|
|
47
|
+
code: 'BAD_REQUEST',
|
|
48
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const rawValue = rawInput[info.batch];
|
|
52
|
+
return deserializeInputValue(rawValue, transformer);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export { getFetchHTTPJSONContentTypeHandler };
|
|
@@ -9,9 +9,5 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { AnyRouter } from '../../@trpc/server';
|
|
11
11
|
import type { FetchHandlerOptions } from './types';
|
|
12
|
-
export
|
|
13
|
-
req: Request;
|
|
14
|
-
endpoint: string;
|
|
15
|
-
};
|
|
16
|
-
export declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
12
|
+
export declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerOptions<TRouter>): Promise<Response>;
|
|
17
13
|
//# sourceMappingURL=fetchRequestHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAcpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AASnD,wBAAsB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACjC,OAAO,CAAC,QAAQ,CAAC,CAuHnB"}
|
|
@@ -4,6 +4,8 @@ var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolv
|
|
|
4
4
|
var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
5
5
|
var toURL = require('../../unstable-core-do-not-import/http/toURL.js');
|
|
6
6
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
7
|
+
var selectContentHandlerOrUnsupportedMediaType = require('../content-handlers/selectContentHandlerOrUnsupportedMediaType.js');
|
|
8
|
+
var index = require('./content-type/json/index.js');
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
@@ -35,8 +37,7 @@ async function fetchRequestHandler(opts) {
|
|
|
35
37
|
const req = {
|
|
36
38
|
query: url.searchParams,
|
|
37
39
|
method: opts.req.method,
|
|
38
|
-
headers: Object.fromEntries(opts.req.headers)
|
|
39
|
-
body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
|
|
40
|
+
headers: Object.fromEntries(opts.req.headers)
|
|
40
41
|
};
|
|
41
42
|
let resolve;
|
|
42
43
|
const promise = new Promise((r)=>resolve = r);
|
|
@@ -89,11 +90,24 @@ async function fetchRequestHandler(opts) {
|
|
|
89
90
|
controller.enqueue(encoder.encode(formatter(index, string)));
|
|
90
91
|
}
|
|
91
92
|
};
|
|
93
|
+
const [contentTypeHandler, unsupportedMediaTypeError] = selectContentHandlerOrUnsupportedMediaType.selectContentHandlerOrUnsupportedMediaType([
|
|
94
|
+
index.getFetchHTTPJSONContentTypeHandler()
|
|
95
|
+
], {
|
|
96
|
+
...opts,
|
|
97
|
+
url
|
|
98
|
+
});
|
|
92
99
|
resolveHTTPResponse.resolveHTTPResponse({
|
|
93
100
|
...opts,
|
|
94
101
|
req,
|
|
95
102
|
createContext,
|
|
96
103
|
path,
|
|
104
|
+
error: unsupportedMediaTypeError,
|
|
105
|
+
async getInput (info) {
|
|
106
|
+
return await contentTypeHandler?.getInputs({
|
|
107
|
+
...opts,
|
|
108
|
+
url
|
|
109
|
+
}, info);
|
|
110
|
+
},
|
|
97
111
|
onError (o) {
|
|
98
112
|
opts?.onError?.({
|
|
99
113
|
...o,
|
|
@@ -2,6 +2,8 @@ import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/reso
|
|
|
2
2
|
import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
3
3
|
import { toURL } from '../../unstable-core-do-not-import/http/toURL.mjs';
|
|
4
4
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
5
|
+
import { selectContentHandlerOrUnsupportedMediaType } from '../content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs';
|
|
6
|
+
import { getFetchHTTPJSONContentTypeHandler } from './content-type/json/index.mjs';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
@@ -33,8 +35,7 @@ async function fetchRequestHandler(opts) {
|
|
|
33
35
|
const req = {
|
|
34
36
|
query: url.searchParams,
|
|
35
37
|
method: opts.req.method,
|
|
36
|
-
headers: Object.fromEntries(opts.req.headers)
|
|
37
|
-
body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
|
|
38
|
+
headers: Object.fromEntries(opts.req.headers)
|
|
38
39
|
};
|
|
39
40
|
let resolve;
|
|
40
41
|
const promise = new Promise((r)=>resolve = r);
|
|
@@ -87,11 +88,24 @@ async function fetchRequestHandler(opts) {
|
|
|
87
88
|
controller.enqueue(encoder.encode(formatter(index, string)));
|
|
88
89
|
}
|
|
89
90
|
};
|
|
91
|
+
const [contentTypeHandler, unsupportedMediaTypeError] = selectContentHandlerOrUnsupportedMediaType([
|
|
92
|
+
getFetchHTTPJSONContentTypeHandler()
|
|
93
|
+
], {
|
|
94
|
+
...opts,
|
|
95
|
+
url
|
|
96
|
+
});
|
|
90
97
|
resolveHTTPResponse({
|
|
91
98
|
...opts,
|
|
92
99
|
req,
|
|
93
100
|
createContext,
|
|
94
101
|
path,
|
|
102
|
+
error: unsupportedMediaTypeError,
|
|
103
|
+
async getInput (info) {
|
|
104
|
+
return await contentTypeHandler?.getInputs({
|
|
105
|
+
...opts,
|
|
106
|
+
url
|
|
107
|
+
}, info);
|
|
108
|
+
},
|
|
95
109
|
onError (o) {
|
|
96
110
|
opts?.onError?.({
|
|
97
111
|
...o,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
|
|
10
|
+
import type { AnyRouter, CreateContextCallback, inferRouterContext, WrapCreateContext } from '../../@trpc/server';
|
|
11
11
|
import type { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../@trpc/server/http';
|
|
12
12
|
export type FetchCreateContextFnOptions = {
|
|
13
13
|
req: Request;
|
|
@@ -15,16 +15,13 @@ export type FetchCreateContextFnOptions = {
|
|
|
15
15
|
info: TRPCRequestInfo;
|
|
16
16
|
};
|
|
17
17
|
export type FetchCreateContextFn<TRouter extends AnyRouter> = (opts: FetchCreateContextFnOptions) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
18
|
-
export type FetchCreateContextOption<TRouter extends AnyRouter> =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
**/
|
|
27
|
-
createContext: FetchCreateContextFn<TRouter>;
|
|
18
|
+
export type FetchCreateContextOption<TRouter extends AnyRouter> = CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>>;
|
|
19
|
+
export type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request> & {
|
|
20
|
+
req: Request;
|
|
21
|
+
endpoint: string;
|
|
22
|
+
};
|
|
23
|
+
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> = HTTPBaseHandlerOptions<TRouter, Request> & WrapCreateContext<FetchCreateContextFn<TRouter>> & {
|
|
24
|
+
req: Request;
|
|
25
|
+
endpoint: string;
|
|
28
26
|
};
|
|
29
|
-
export type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request>;
|
|
30
27
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,2BAA2B,GAAG;IACxC,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC5D,IAAI,EAAE,2BAA2B,KAC9B,kBAAkB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAExE,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,qBAAqB,CACnB,kBAAkB,CAAC,OAAO,CAAC,EAC3B,oBAAoB,CAAC,OAAO,CAAC,CAC9B,CAAC;AAEJ,MAAM,MAAM,mBAAmB,CAAC,OAAO,SAAS,SAAS,IACvD,wBAAwB,CAAC,OAAO,CAAC,GAC/B,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG;IACzC,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEN,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,GACtC,iBAAiB,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GAAG;IACjD,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import type { CreateContextCallback } from '../../@trpc/server';
|
|
1
2
|
import type { ErrorHandlerOptions } from '../../unstable-core-do-not-import/procedure';
|
|
2
3
|
import type { CallerOverride } from '../../unstable-core-do-not-import/procedureBuilder';
|
|
3
4
|
import type { MaybePromise, Simplify } from '../../unstable-core-do-not-import/types';
|
|
4
|
-
type ContextCallback<TContext> = object extends TContext ? {
|
|
5
|
-
createContext?: () => MaybePromise<TContext>;
|
|
6
|
-
} : {
|
|
7
|
-
createContext: () => MaybePromise<TContext>;
|
|
8
|
-
};
|
|
9
5
|
/**
|
|
10
6
|
* Create a caller that works with Next.js React Server Components & Server Actions
|
|
11
7
|
*/
|
|
@@ -19,6 +15,5 @@ export declare function nextAppDirCaller<TContext>(config: Simplify<{
|
|
|
19
15
|
* Called when an error occurs in the handler
|
|
20
16
|
*/
|
|
21
17
|
onError?: (opts: ErrorHandlerOptions<TContext>) => void;
|
|
22
|
-
} &
|
|
23
|
-
export {};
|
|
18
|
+
} & CreateContextCallback<TContext, () => MaybePromise<TContext>>>): CallerOverride<TContext>;
|
|
24
19
|
//# sourceMappingURL=nextAppDirCaller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextAppDirCaller.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/nextAppDirCaller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nextAppDirCaller.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/nextAppDirCaller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAIhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAGvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAGzF,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACT,MAAM,yCAAyC,CAAC;AAKjD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EACvC,MAAM,EAAE,QAAQ,CACd;IACE;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;CACzD,GAAG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC,CAClE,GACA,cAAc,CAAC,QAAQ,CAAC,CAsF1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,cAAc,EACd,eAAe,CAChB,CAAC;AAEF;;GAEG;AACH,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAC5D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,GACrE,cAAc,
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,cAAc,EACd,eAAe,CAChB,CAAC;AAEF;;GAEG;AACH,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAC5D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,GACrE,cAAc,CAyChB"}
|
package/dist/adapters/next.js
CHANGED
package/dist/adapters/next.mjs
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var node_crypto = require('node:crypto');
|
|
4
3
|
var node_fs = require('node:fs');
|
|
5
4
|
var fs = require('node:fs/promises');
|
|
6
|
-
var node_os = require('node:os');
|
|
7
5
|
var node_path = require('node:path');
|
|
8
6
|
var node_stream = require('node:stream');
|
|
9
|
-
var node_util = require('node:util');
|
|
10
7
|
var streamSlice = require('./streamSlice.js');
|
|
11
|
-
var uploadHandler = require('./uploadHandler.js');
|
|
12
8
|
|
|
13
9
|
async function readableStreamToString(stream, encoding) {
|
|
14
10
|
const reader = stream.getReader();
|
|
@@ -25,73 +21,6 @@ async function readableStreamToString(stream, encoding) {
|
|
|
25
21
|
await read();
|
|
26
22
|
return Buffer.concat(chunks).toString(encoding);
|
|
27
23
|
}
|
|
28
|
-
const defaultFilePathResolver = ({ filename , })=>{
|
|
29
|
-
const ext = filename ? node_path.extname(filename) : '';
|
|
30
|
-
return 'upload_' + node_crypto.randomBytes(4).readUInt32LE(0) + ext;
|
|
31
|
-
};
|
|
32
|
-
async function uniqueFile(filepath) {
|
|
33
|
-
const ext = node_path.extname(filepath);
|
|
34
|
-
let uniqueFilepath = filepath;
|
|
35
|
-
for(let i = 1; await fs.stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
|
|
36
|
-
uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
|
|
37
|
-
}
|
|
38
|
-
return uniqueFilepath;
|
|
39
|
-
}
|
|
40
|
-
function createFileUploadHandler({ directory =node_os.tmpdir() , avoidFileConflicts =true , file =defaultFilePathResolver , filter , maxPartSize =3000000 } = {}) {
|
|
41
|
-
return async ({ name , filename , contentType , data })=>{
|
|
42
|
-
if (!filename || filter && !await filter({
|
|
43
|
-
name,
|
|
44
|
-
filename,
|
|
45
|
-
contentType
|
|
46
|
-
})) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
const dir = typeof directory === 'string' ? directory : directory({
|
|
50
|
-
name,
|
|
51
|
-
filename,
|
|
52
|
-
contentType
|
|
53
|
-
});
|
|
54
|
-
if (!dir) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
const filedir = node_path.resolve(dir);
|
|
58
|
-
const path = typeof file === 'string' ? file : file({
|
|
59
|
-
name,
|
|
60
|
-
filename,
|
|
61
|
-
contentType
|
|
62
|
-
});
|
|
63
|
-
if (!path) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
let filepath = node_path.resolve(filedir, path);
|
|
67
|
-
if (avoidFileConflicts) {
|
|
68
|
-
filepath = await uniqueFile(filepath);
|
|
69
|
-
}
|
|
70
|
-
await fs.mkdir(node_path.dirname(filepath), {
|
|
71
|
-
recursive: true
|
|
72
|
-
}).catch(()=>{});
|
|
73
|
-
const writeFileStream = node_fs.createWriteStream(filepath);
|
|
74
|
-
let size = 0;
|
|
75
|
-
let deleteFile = false;
|
|
76
|
-
try {
|
|
77
|
-
for await (const chunk of data){
|
|
78
|
-
size += chunk.byteLength;
|
|
79
|
-
if (size > maxPartSize) {
|
|
80
|
-
deleteFile = true;
|
|
81
|
-
throw new uploadHandler.MaxPartSizeExceededError(name, maxPartSize);
|
|
82
|
-
}
|
|
83
|
-
writeFileStream.write(chunk);
|
|
84
|
-
}
|
|
85
|
-
} finally{
|
|
86
|
-
writeFileStream.end();
|
|
87
|
-
await node_util.promisify(node_stream.finished)(writeFileStream);
|
|
88
|
-
if (deleteFile) {
|
|
89
|
-
await fs.rm(filepath).catch(()=>{});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return new NodeOnDiskFile(filepath, contentType);
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
24
|
let _toStringTag = Symbol.toStringTag;
|
|
96
25
|
class NodeOnDiskFile {
|
|
97
26
|
get size() {
|
|
@@ -157,5 +86,4 @@ class NodeOnDiskFile {
|
|
|
157
86
|
}
|
|
158
87
|
|
|
159
88
|
exports.NodeOnDiskFile = NodeOnDiskFile;
|
|
160
|
-
exports.createFileUploadHandler = createFileUploadHandler;
|
|
161
89
|
exports.readableStreamToString = readableStreamToString;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { resolve, dirname, basename, extname } from 'node:path';
|
|
6
|
-
import { finished, Readable } from 'node:stream';
|
|
7
|
-
import { promisify } from 'node:util';
|
|
1
|
+
import { statSync, createReadStream } from 'node:fs';
|
|
2
|
+
import { unlink } from 'node:fs/promises';
|
|
3
|
+
import { basename } from 'node:path';
|
|
4
|
+
import { Readable } from 'node:stream';
|
|
8
5
|
import { streamSlice } from './streamSlice.mjs';
|
|
9
|
-
import { MaxPartSizeExceededError } from './uploadHandler.mjs';
|
|
10
6
|
|
|
11
7
|
async function readableStreamToString(stream, encoding) {
|
|
12
8
|
const reader = stream.getReader();
|
|
@@ -23,73 +19,6 @@ async function readableStreamToString(stream, encoding) {
|
|
|
23
19
|
await read();
|
|
24
20
|
return Buffer.concat(chunks).toString(encoding);
|
|
25
21
|
}
|
|
26
|
-
const defaultFilePathResolver = ({ filename , })=>{
|
|
27
|
-
const ext = filename ? extname(filename) : '';
|
|
28
|
-
return 'upload_' + randomBytes(4).readUInt32LE(0) + ext;
|
|
29
|
-
};
|
|
30
|
-
async function uniqueFile(filepath) {
|
|
31
|
-
const ext = extname(filepath);
|
|
32
|
-
let uniqueFilepath = filepath;
|
|
33
|
-
for(let i = 1; await stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
|
|
34
|
-
uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
|
|
35
|
-
}
|
|
36
|
-
return uniqueFilepath;
|
|
37
|
-
}
|
|
38
|
-
function createFileUploadHandler({ directory =tmpdir() , avoidFileConflicts =true , file =defaultFilePathResolver , filter , maxPartSize =3000000 } = {}) {
|
|
39
|
-
return async ({ name , filename , contentType , data })=>{
|
|
40
|
-
if (!filename || filter && !await filter({
|
|
41
|
-
name,
|
|
42
|
-
filename,
|
|
43
|
-
contentType
|
|
44
|
-
})) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
const dir = typeof directory === 'string' ? directory : directory({
|
|
48
|
-
name,
|
|
49
|
-
filename,
|
|
50
|
-
contentType
|
|
51
|
-
});
|
|
52
|
-
if (!dir) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
const filedir = resolve(dir);
|
|
56
|
-
const path = typeof file === 'string' ? file : file({
|
|
57
|
-
name,
|
|
58
|
-
filename,
|
|
59
|
-
contentType
|
|
60
|
-
});
|
|
61
|
-
if (!path) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
let filepath = resolve(filedir, path);
|
|
65
|
-
if (avoidFileConflicts) {
|
|
66
|
-
filepath = await uniqueFile(filepath);
|
|
67
|
-
}
|
|
68
|
-
await mkdir(dirname(filepath), {
|
|
69
|
-
recursive: true
|
|
70
|
-
}).catch(()=>{});
|
|
71
|
-
const writeFileStream = createWriteStream(filepath);
|
|
72
|
-
let size = 0;
|
|
73
|
-
let deleteFile = false;
|
|
74
|
-
try {
|
|
75
|
-
for await (const chunk of data){
|
|
76
|
-
size += chunk.byteLength;
|
|
77
|
-
if (size > maxPartSize) {
|
|
78
|
-
deleteFile = true;
|
|
79
|
-
throw new MaxPartSizeExceededError(name, maxPartSize);
|
|
80
|
-
}
|
|
81
|
-
writeFileStream.write(chunk);
|
|
82
|
-
}
|
|
83
|
-
} finally{
|
|
84
|
-
writeFileStream.end();
|
|
85
|
-
await promisify(finished)(writeFileStream);
|
|
86
|
-
if (deleteFile) {
|
|
87
|
-
await rm(filepath).catch(()=>{});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return new NodeOnDiskFile(filepath, contentType);
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
22
|
let _toStringTag = Symbol.toStringTag;
|
|
94
23
|
class NodeOnDiskFile {
|
|
95
24
|
get size() {
|
|
@@ -154,4 +83,4 @@ class NodeOnDiskFile {
|
|
|
154
83
|
}
|
|
155
84
|
}
|
|
156
85
|
|
|
157
|
-
export { NodeOnDiskFile,
|
|
86
|
+
export { NodeOnDiskFile, readableStreamToString };
|