@trpc/server 11.0.0-rc.359 → 11.0.0-rc.361
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 +62 -0
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +60 -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/concurrentCache.d.ts +7 -0
- package/dist/adapters/content-handlers/concurrentCache.d.ts.map +1 -0
- package/dist/adapters/content-handlers/concurrentCache.js +17 -0
- package/dist/adapters/content-handlers/concurrentCache.mjs +15 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +10 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +1 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +33 -0
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +31 -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 +62 -0
- package/dist/adapters/fastify/content-type/json/index.mjs +60 -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 +55 -0
- package/dist/adapters/fetch/content-type/json/index.mjs +53 -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/index.d.ts +4 -25
- 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 +25 -128
- package/dist/adapters/node-http/content-type/form-data/index.mjs +25 -103
- 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 +62 -10
- package/dist/adapters/node-http/content-type/json/index.mjs +62 -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 +231 -220
- 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 +7 -15
- 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 +26 -20
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +26 -20
- 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 +2 -3
- package/src/@trpc/server/http.ts +0 -1
- package/src/@trpc/server/index.ts +4 -0
- package/src/adapters/aws-lambda/content-type/json/index.ts +108 -0
- package/src/adapters/aws-lambda/index.ts +24 -9
- package/src/adapters/aws-lambda/utils.ts +21 -15
- package/src/adapters/content-handlers/concurrentCache.ts +16 -0
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +45 -0
- package/src/adapters/express.ts +1 -6
- package/src/adapters/fastify/content-type/json/index.ts +106 -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 +90 -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/index.ts +33 -159
- package/src/adapters/node-http/content-type/json/getPostBody.ts +9 -18
- package/src/adapters/node-http/content-type/json/index.ts +98 -9
- package/src/adapters/node-http/content-type/octet/index.ts +27 -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 +10 -85
- package/src/unstable-core-do-not-import/http/index.ts +0 -1
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +30 -27
- 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/content-type/form-data/fileUploadHandler.d.ts +0 -73
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- 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
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +0 -277
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +0 -89
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
var concurrentCache = require('../../../content-handlers/concurrentCache.js');
|
|
6
|
+
|
|
7
|
+
// @trpc/server
|
|
8
|
+
const getFastifyHTTPJSONContentTypeHandler = ()=>{
|
|
9
|
+
const cache = concurrentCache.createConcurrentCache();
|
|
10
|
+
return {
|
|
11
|
+
name: 'fastify-json',
|
|
12
|
+
isMatch: (headers)=>{
|
|
13
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
14
|
+
},
|
|
15
|
+
getInputs: async (opts, info)=>{
|
|
16
|
+
async function getRawProcedureInputOrThrow() {
|
|
17
|
+
const { req } = opts;
|
|
18
|
+
try {
|
|
19
|
+
if (req.method === 'GET') {
|
|
20
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
21
|
+
const input = query.get('input');
|
|
22
|
+
if (!input) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return JSON.parse(input);
|
|
26
|
+
}
|
|
27
|
+
const body = opts.req.body ?? 'null';
|
|
28
|
+
if (typeof body === 'string') {
|
|
29
|
+
// A mutation with no inputs will have req.body === ''
|
|
30
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
31
|
+
}
|
|
32
|
+
return body;
|
|
33
|
+
} catch (cause) {
|
|
34
|
+
throw new TRPCError.TRPCError({
|
|
35
|
+
code: 'PARSE_ERROR',
|
|
36
|
+
cause
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
41
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
42
|
+
};
|
|
43
|
+
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
44
|
+
if (rawInput === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const transformer = opts.router._def._config.transformer;
|
|
48
|
+
if (!info.isBatchCall) {
|
|
49
|
+
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
50
|
+
}
|
|
51
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
52
|
+
throw new TRPCError.TRPCError({
|
|
53
|
+
code: 'BAD_REQUEST',
|
|
54
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.getFastifyHTTPJSONContentTypeHandler = getFastifyHTTPJSONContentTypeHandler;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
|
|
4
|
+
|
|
5
|
+
// @trpc/server
|
|
6
|
+
const getFastifyHTTPJSONContentTypeHandler = ()=>{
|
|
7
|
+
const cache = createConcurrentCache();
|
|
8
|
+
return {
|
|
9
|
+
name: 'fastify-json',
|
|
10
|
+
isMatch: (headers)=>{
|
|
11
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
12
|
+
},
|
|
13
|
+
getInputs: async (opts, info)=>{
|
|
14
|
+
async function getRawProcedureInputOrThrow() {
|
|
15
|
+
const { req } = opts;
|
|
16
|
+
try {
|
|
17
|
+
if (req.method === 'GET') {
|
|
18
|
+
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
19
|
+
const input = query.get('input');
|
|
20
|
+
if (!input) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return JSON.parse(input);
|
|
24
|
+
}
|
|
25
|
+
const body = opts.req.body ?? 'null';
|
|
26
|
+
if (typeof body === 'string') {
|
|
27
|
+
// A mutation with no inputs will have req.body === ''
|
|
28
|
+
return body.length === 0 ? undefined : JSON.parse(body);
|
|
29
|
+
}
|
|
30
|
+
return body;
|
|
31
|
+
} catch (cause) {
|
|
32
|
+
throw new TRPCError({
|
|
33
|
+
code: 'PARSE_ERROR',
|
|
34
|
+
cause
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
39
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
40
|
+
};
|
|
41
|
+
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
42
|
+
if (rawInput === undefined) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const transformer = opts.router._def._config.transformer;
|
|
46
|
+
if (!info.isBatchCall) {
|
|
47
|
+
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
48
|
+
}
|
|
49
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
50
|
+
throw new TRPCError({
|
|
51
|
+
code: 'BAD_REQUEST',
|
|
52
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { getFastifyHTTPJSONContentTypeHandler };
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
2
|
import type { AnyRouter } from '../../@trpc/server';
|
|
3
|
-
import type {
|
|
4
|
-
import type { NodeHTTPCreateContextOption } from '../node-http';
|
|
5
|
-
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
6
|
-
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
|
-
};
|
|
3
|
+
import type { FastifyRequestHandlerOptions } from './types';
|
|
11
4
|
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
|
|
12
|
-
export {};
|
|
13
5
|
//# sourceMappingURL=fastifyRequestHandler.d.ts.map
|
|
@@ -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;AAE5E,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,CAsEzC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
var concurrentCache = require('../../../content-handlers/concurrentCache.js');
|
|
6
|
+
|
|
7
|
+
// @trpc/server
|
|
8
|
+
const getFetchHTTPJSONContentTypeHandler = ()=>{
|
|
9
|
+
const cache = concurrentCache.createConcurrentCache();
|
|
10
|
+
return {
|
|
11
|
+
name: 'fetch-json',
|
|
12
|
+
isMatch: (headers)=>{
|
|
13
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
14
|
+
},
|
|
15
|
+
getInputs: async (opts, info)=>{
|
|
16
|
+
async function getRawProcedureInputOrThrow() {
|
|
17
|
+
try {
|
|
18
|
+
if (opts.url.searchParams.has('input')) {
|
|
19
|
+
const input = opts.url.searchParams.get('input');
|
|
20
|
+
if (!input) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return JSON.parse(input);
|
|
24
|
+
}
|
|
25
|
+
return await opts.req.json();
|
|
26
|
+
} catch (cause) {
|
|
27
|
+
throw new TRPCError.TRPCError({
|
|
28
|
+
code: 'PARSE_ERROR',
|
|
29
|
+
cause
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
34
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
35
|
+
};
|
|
36
|
+
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
37
|
+
if (rawInput === undefined) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const transformer = opts.router._def._config.transformer;
|
|
41
|
+
if (!info.isBatchCall) {
|
|
42
|
+
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
43
|
+
}
|
|
44
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
45
|
+
throw new TRPCError.TRPCError({
|
|
46
|
+
code: 'BAD_REQUEST',
|
|
47
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.getFetchHTTPJSONContentTypeHandler = getFetchHTTPJSONContentTypeHandler;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
|
|
4
|
+
|
|
5
|
+
// @trpc/server
|
|
6
|
+
const getFetchHTTPJSONContentTypeHandler = ()=>{
|
|
7
|
+
const cache = createConcurrentCache();
|
|
8
|
+
return {
|
|
9
|
+
name: 'fetch-json',
|
|
10
|
+
isMatch: (headers)=>{
|
|
11
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
12
|
+
},
|
|
13
|
+
getInputs: async (opts, info)=>{
|
|
14
|
+
async function getRawProcedureInputOrThrow() {
|
|
15
|
+
try {
|
|
16
|
+
if (opts.url.searchParams.has('input')) {
|
|
17
|
+
const input = opts.url.searchParams.get('input');
|
|
18
|
+
if (!input) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return JSON.parse(input);
|
|
22
|
+
}
|
|
23
|
+
return await opts.req.json();
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
throw new TRPCError({
|
|
26
|
+
code: 'PARSE_ERROR',
|
|
27
|
+
cause
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const deserializeInputValue = (rawValue, transformer)=>{
|
|
32
|
+
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
33
|
+
};
|
|
34
|
+
const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
|
|
35
|
+
if (rawInput === undefined) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const transformer = opts.router._def._config.transformer;
|
|
39
|
+
if (!info.isBatchCall) {
|
|
40
|
+
return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
|
|
41
|
+
}
|
|
42
|
+
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
43
|
+
throw new TRPCError({
|
|
44
|
+
code: 'BAD_REQUEST',
|
|
45
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
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,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
6
|
-
*/
|
|
7
|
-
import type { NodeHTTPRequest } from '../../types';
|
|
8
|
-
import type { UploadHandler } from './uploadHandler';
|
|
9
|
-
/**
|
|
10
|
-
* Allows you to handle multipart forms (file uploads) for your app.
|
|
11
|
-
* Request body parts with a 'filename' property will be treated as files.
|
|
12
|
-
* The rest will be treated as text.
|
|
13
|
-
* @param request The incoming Node HTTP request
|
|
14
|
-
* @param uploadHandler A function that handles file uploads and returns a value to be used in the request body. If uploaded to disk, the returned value is a NodeOnDiskFile. If uploaded to memory, the returned value is a File.
|
|
15
|
-
* @param maxBodySize The maximum size of the request body in bytes. Defaults to Infinity.
|
|
16
|
-
*
|
|
17
|
-
* @link https://remix.run/utils/parse-multipart-form-data
|
|
18
|
-
*/
|
|
19
|
-
declare function parseMultipartFormData(request: NodeHTTPRequest, uploadHandler: UploadHandler, maxBodySize?: number): Promise<FormData>;
|
|
20
|
-
declare function isMultipartFormDataRequest(req: NodeHTTPRequest): boolean;
|
|
21
|
-
export declare const nodeHTTPFormDataContentTypeHandler: <TRequest extends NodeHTTPRequest, TResponse extends import("../../types").NodeHTTPResponse>() => import("../../internals/contentType").NodeHTTPContentTypeHandler<TRequest, TResponse>;
|
|
22
|
-
export { NodeOnDiskFile as experimental_NodeOnDiskFile, createFileUploadHandler as experimental_createFileUploadHandler, } from './fileUploadHandler';
|
|
23
|
-
export { createMemoryUploadHandler as experimental_createMemoryUploadHandler } from './memoryUploadHandler';
|
|
24
|
-
export { MaxBodySizeExceededError, MaxPartSizeExceededError, composeUploadHandlers as experimental_composeUploadHandlers, type UploadHandler, } from './uploadHandler';
|
|
25
|
-
export { isMultipartFormDataRequest as experimental_isMultipartFormDataRequest, parseMultipartFormData as experimental_parseMultipartFormData, };
|
|
1
|
+
import type { AnyRouter } from '../../../../@trpc/server';
|
|
2
|
+
import type { NodeHTTPRequest, NodeHTTPResponse } from '../../types';
|
|
3
|
+
import type { NodeHTTPContentTypeHandler } from '../types';
|
|
4
|
+
export declare const getFormDataContentTypeHandler: <TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>() => NodeHTTPContentTypeHandler<TRouter, TRequest, TResponse>;
|
|
26
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAE3D,eAAO,MAAM,6BAA6B,EAAE,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,OAC7B,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CA0B5D,CAAC"}
|