@trpc/server 11.0.0-next-beta.206 → 11.0.0-next-beta.216

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.
Files changed (56) hide show
  1. package/dist/adapters/aws-lambda/index.js +14 -105
  2. package/dist/adapters/aws-lambda/index.mjs +1 -90
  3. package/dist/adapters/aws-lambda/utils.js +100 -0
  4. package/dist/adapters/aws-lambda/utils.mjs +93 -0
  5. package/dist/adapters/express.js +1 -7
  6. package/dist/adapters/express.mjs +1 -5
  7. package/dist/adapters/fastify/fastifyRequestHandler.js +81 -0
  8. package/dist/adapters/fastify/fastifyRequestHandler.mjs +79 -0
  9. package/dist/adapters/fastify/fastifyTRPCPlugin.js +51 -0
  10. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +49 -0
  11. package/dist/adapters/fastify/index.js +4 -128
  12. package/dist/adapters/fastify/index.mjs +2 -128
  13. package/dist/adapters/fetch/fetchRequestHandler.js +118 -0
  14. package/dist/adapters/fetch/fetchRequestHandler.mjs +116 -0
  15. package/dist/adapters/fetch/index.js +2 -115
  16. package/dist/adapters/fetch/index.mjs +1 -116
  17. package/dist/adapters/next.js +1 -6
  18. package/dist/adapters/next.mjs +1 -4
  19. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
  20. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
  21. package/dist/adapters/node-http/content-type/form-data/index.js +20 -646
  22. package/dist/adapters/node-http/content-type/form-data/index.mjs +9 -631
  23. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
  24. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
  25. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
  26. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
  27. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
  28. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
  29. package/dist/adapters/node-http/content-type/json/getPostBody.js +42 -0
  30. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +40 -0
  31. package/dist/adapters/node-http/content-type/json/index.js +3 -42
  32. package/dist/adapters/node-http/content-type/json/index.mjs +2 -39
  33. package/dist/adapters/node-http/index.js +1 -7
  34. package/dist/adapters/node-http/index.mjs +1 -5
  35. package/dist/{contentType-72ed9df5.mjs → adapters/node-http/internals/contentType.mjs} +1 -1
  36. package/dist/{nodeHTTPRequestHandler-83441c73.js → adapters/node-http/nodeHTTPRequestHandler.js} +2 -2
  37. package/dist/{nodeHTTPRequestHandler-0223fac5.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +2 -2
  38. package/dist/adapters/standalone.js +2 -12
  39. package/dist/adapters/standalone.mjs +1 -5
  40. package/dist/adapters/ws.js +0 -2
  41. package/dist/bundle-analysis.json +97 -97
  42. package/dist/http.js +1 -3
  43. package/dist/index.js +10 -12
  44. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
  45. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
  46. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
  47. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
  48. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
  49. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
  50. package/dist/observable.js +1 -3
  51. package/dist/rpc.js +1 -3
  52. package/dist/shared.js +2 -4
  53. package/package.json +4 -4
  54. package/dist/contentType-24c44bba.js +0 -5
  55. package/dist/nodeHTTPRequestHandler-aa0dce4e.js +0 -105
  56. /package/dist/{contentType-d9d22104.js → adapters/node-http/internals/contentType.js} +0 -0
@@ -0,0 +1,163 @@
1
+ import { stringToArray } from './utils.mjs';
2
+
3
+ function coerce(a) {
4
+ if (a instanceof Uint8Array) {
5
+ return index => a[index];
6
+ }
7
+ return a;
8
+ }
9
+ function jsmemcmp(buf1, pos1, buf2, pos2, len) {
10
+ const fn1 = coerce(buf1);
11
+ const fn2 = coerce(buf2);
12
+ for (let i = 0; i < len; ++i) {
13
+ if (fn1(pos1 + i) !== fn2(pos2 + i)) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+ function createOccurenceTable(s) {
20
+ const table = new Array(256).fill(s.length);
21
+ if (s.length > 1) {
22
+ for (let i = 0; i < s.length - 1; i++) {
23
+ table[s[i]] = s.length - 1 - i;
24
+ }
25
+ }
26
+ return table;
27
+ }
28
+ const MATCH = Symbol('Match');
29
+ class StreamSearch {
30
+ constructor(needle) {
31
+ this._lookbehind = new Uint8Array();
32
+ if (typeof needle === 'string') {
33
+ this._needle = needle = stringToArray(needle);
34
+ } else {
35
+ this._needle = needle;
36
+ }
37
+ this._lastChar = needle[needle.length - 1];
38
+ this._occ = createOccurenceTable(needle);
39
+ }
40
+ feed(chunk) {
41
+ let pos = 0;
42
+ let tokens;
43
+ const allTokens = [];
44
+ while (pos !== chunk.length) {
45
+ [pos, ...tokens] = this._feed(chunk, pos);
46
+ allTokens.push(...tokens);
47
+ }
48
+ return allTokens;
49
+ }
50
+ end() {
51
+ const tail = this._lookbehind;
52
+ this._lookbehind = new Uint8Array();
53
+ return tail;
54
+ }
55
+ _feed(data, bufPos) {
56
+ const tokens = [];
57
+ let pos = -this._lookbehind.length;
58
+ if (pos < 0) {
59
+ while (pos < 0 && pos <= data.length - this._needle.length) {
60
+ const ch = this._charAt(data, pos + this._needle.length - 1);
61
+ if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
62
+ if (pos > -this._lookbehind.length) {
63
+ tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
64
+ }
65
+ tokens.push(MATCH);
66
+ this._lookbehind = new Uint8Array();
67
+ return [
68
+ pos + this._needle.length,
69
+ ...tokens
70
+ ];
71
+ } else {
72
+ pos += this._occ[ch];
73
+ }
74
+ }
75
+ if (pos < 0) {
76
+ while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
77
+ pos++;
78
+ }
79
+ }
80
+ if (pos >= 0) {
81
+ tokens.push(this._lookbehind);
82
+ this._lookbehind = new Uint8Array();
83
+ } else {
84
+ const bytesToCutOff = this._lookbehind.length + pos;
85
+ if (bytesToCutOff > 0) {
86
+ tokens.push(this._lookbehind.slice(0, bytesToCutOff));
87
+ this._lookbehind = this._lookbehind.slice(bytesToCutOff);
88
+ }
89
+ this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
90
+ return [
91
+ data.length,
92
+ ...tokens
93
+ ];
94
+ }
95
+ }
96
+ pos += bufPos;
97
+ while (pos <= data.length - this._needle.length) {
98
+ const ch = data[pos + this._needle.length - 1];
99
+ if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
100
+ if (pos > bufPos) {
101
+ tokens.push(data.slice(bufPos, pos));
102
+ }
103
+ tokens.push(MATCH);
104
+ return [
105
+ pos + this._needle.length,
106
+ ...tokens
107
+ ];
108
+ } else {
109
+ pos += this._occ[ch];
110
+ }
111
+ }
112
+ if (pos < data.length) {
113
+ while (pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
114
+ ++pos;
115
+ }
116
+ if (pos < data.length) {
117
+ this._lookbehind = data.slice(pos);
118
+ }
119
+ }
120
+ if (pos > 0) {
121
+ tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
122
+ }
123
+ return [
124
+ data.length,
125
+ ...tokens
126
+ ];
127
+ }
128
+ _charAt(data, pos) {
129
+ if (pos < 0) {
130
+ return this._lookbehind[this._lookbehind.length + pos];
131
+ }
132
+ return data[pos];
133
+ }
134
+ _memcmp(data, pos, len) {
135
+ return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
136
+ }
137
+ }
138
+ class ReadableStreamSearch {
139
+ constructor(needle, _readableStream) {
140
+ this._readableStream = _readableStream;
141
+ this._search = new StreamSearch(needle);
142
+ }
143
+ async *[Symbol.asyncIterator]() {
144
+ const reader = this._readableStream.getReader();
145
+ try {
146
+ while (true) {
147
+ const result = await reader.read();
148
+ if (result.done) {
149
+ break;
150
+ }
151
+ yield* this._search.feed(result.value);
152
+ }
153
+ const tail = this._search.end();
154
+ if (tail.length) {
155
+ yield tail;
156
+ }
157
+ } finally {
158
+ reader.releaseLock();
159
+ }
160
+ }
161
+ }
162
+
163
+ export { MATCH, ReadableStreamSearch, StreamSearch };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ function stringToArray(s) {
4
+ const utf8 = unescape(encodeURIComponent(s));
5
+ return Uint8Array.from(utf8, (_, i) => utf8.charCodeAt(i));
6
+ }
7
+ function arrayToString(a) {
8
+ const utf8 = String.fromCharCode.apply(null, a);
9
+ return decodeURIComponent(escape(utf8));
10
+ }
11
+ function mergeArrays(...arrays) {
12
+ const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
13
+ let offset = 0;
14
+ for (const arr of arrays) {
15
+ out.set(arr, offset);
16
+ offset += arr.length;
17
+ }
18
+ return out;
19
+ }
20
+ function arraysEqual(a, b) {
21
+ if (a.length !== b.length) {
22
+ return false;
23
+ }
24
+ for (let i = 0; i < a.length; i++) {
25
+ if (a[i] !== b[i]) {
26
+ return false;
27
+ }
28
+ }
29
+ return true;
30
+ }
31
+
32
+ exports.arrayToString = arrayToString;
33
+ exports.arraysEqual = arraysEqual;
34
+ exports.mergeArrays = mergeArrays;
35
+ exports.stringToArray = stringToArray;
@@ -0,0 +1,30 @@
1
+ function stringToArray(s) {
2
+ const utf8 = unescape(encodeURIComponent(s));
3
+ return Uint8Array.from(utf8, (_, i) => utf8.charCodeAt(i));
4
+ }
5
+ function arrayToString(a) {
6
+ const utf8 = String.fromCharCode.apply(null, a);
7
+ return decodeURIComponent(escape(utf8));
8
+ }
9
+ function mergeArrays(...arrays) {
10
+ const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
11
+ let offset = 0;
12
+ for (const arr of arrays) {
13
+ out.set(arr, offset);
14
+ offset += arr.length;
15
+ }
16
+ return out;
17
+ }
18
+ function arraysEqual(a, b) {
19
+ if (a.length !== b.length) {
20
+ return false;
21
+ }
22
+ for (let i = 0; i < a.length; i++) {
23
+ if (a[i] !== b[i]) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }
29
+
30
+ export { arrayToString, arraysEqual, mergeArrays, stringToArray };
@@ -1,13 +1,11 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var observable = require('@trpc/core/observable');
6
4
 
7
5
 
8
6
 
9
7
  Object.keys(observable).forEach(function (k) {
10
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
8
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
11
9
  enumerable: true,
12
10
  get: function () { return observable[k]; }
13
11
  });
package/dist/rpc.js CHANGED
@@ -1,13 +1,11 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var rpc = require('@trpc/core/rpc');
6
4
 
7
5
 
8
6
 
9
7
  Object.keys(rpc).forEach(function (k) {
10
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
8
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
11
9
  enumerable: true,
12
10
  get: function () { return rpc[k]; }
13
11
  });
package/dist/shared.js CHANGED
@@ -1,16 +1,14 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@trpc/core');
6
4
 
7
5
 
8
6
 
9
- Object.defineProperty(exports, 'createFlatProxy', {
7
+ Object.defineProperty(exports, "createFlatProxy", {
10
8
  enumerable: true,
11
9
  get: function () { return core.createFlatProxy; }
12
10
  });
13
- Object.defineProperty(exports, 'getErrorShape', {
11
+ Object.defineProperty(exports, "getErrorShape", {
14
12
  enumerable: true,
15
13
  get: function () { return core.getErrorShape; }
16
14
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-next-beta.206+255803252",
3
+ "version": "11.0.0-next-beta.216+ccd4f1b0e",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -115,7 +115,7 @@
115
115
  "access": "public"
116
116
  },
117
117
  "dependencies": {
118
- "@trpc/core": "11.0.0-next-beta.206+255803252"
118
+ "@trpc/core": "11.0.0-next-beta.216+ccd4f1b0e"
119
119
  },
120
120
  "devDependencies": {
121
121
  "@fastify/websocket": "^7.1.2",
@@ -139,7 +139,7 @@
139
139
  "next": "^14.0.1",
140
140
  "react": "^18.2.0",
141
141
  "react-dom": "^18.2.0",
142
- "rollup": "^2.79.1",
142
+ "rollup": "^4.9.5",
143
143
  "superjson": "^1.12.4",
144
144
  "superstruct": "^1.0.0",
145
145
  "tslib": "^2.5.0",
@@ -154,5 +154,5 @@
154
154
  "funding": [
155
155
  "https://trpc.io/sponsor"
156
156
  ],
157
- "gitHead": "2558032520acb8dc9ffe9dfe30ba94bab3f06e36"
157
+ "gitHead": "ccd4f1b0e0f2a11dbac63085665dfc9639a9cfb3"
158
158
  }
@@ -1,5 +0,0 @@
1
- function createNodeHTTPContentTypeHandler(contentTypeHandler) {
2
- return () => contentTypeHandler;
3
- }
4
-
5
- export { createNodeHTTPContentTypeHandler as c };
@@ -1,105 +0,0 @@
1
- import { resolveHTTPResponse, getBatchStreamFormatter } from '@trpc/core/http';
2
- import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.js';
3
-
4
- const defaultJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler();
5
- async function nodeHTTPRequestHandler(opts) {
6
- const handleViaMiddleware = opts.middleware ?? ((_req, _res, next) => next());
7
- return handleViaMiddleware(opts.req, opts.res, async (err) => {
8
- if (err)
9
- throw err;
10
- //
11
- // Build tRPC dependencies
12
- const createContext = async (innerOpts) => {
13
- return await opts.createContext?.({
14
- ...opts,
15
- ...innerOpts,
16
- });
17
- };
18
- const query = opts.req.query
19
- ? new URLSearchParams(opts.req.query)
20
- : new URLSearchParams(opts.req.url.split('?')[1]);
21
- const jsonContentTypeHandler = defaultJSONContentTypeHandler;
22
- const contentTypeHandlers = opts.experimental_contentTypeHandlers ?? [
23
- jsonContentTypeHandler,
24
- ];
25
- const contentTypeHandler = contentTypeHandlers.find((handler) => handler.isMatch({
26
- ...opts,
27
- query,
28
- })) ??
29
- // fallback to json
30
- jsonContentTypeHandler;
31
- const bodyResult = await contentTypeHandler.getBody({
32
- ...opts,
33
- query,
34
- });
35
- const req = {
36
- method: opts.req.method,
37
- headers: opts.req.headers,
38
- query,
39
- body: bodyResult.ok ? bodyResult.data : undefined,
40
- };
41
- let isStream = false;
42
- let formatter;
43
- const unstable_onHead = (head, isStreaming) => {
44
- if ('status' in head &&
45
- (!opts.res.statusCode || opts.res.statusCode === 200)) {
46
- opts.res.statusCode = head.status;
47
- }
48
- for (const [key, value] of Object.entries(head.headers ?? {})) {
49
- /* istanbul ignore if -- @preserve */
50
- if (typeof value === 'undefined') {
51
- continue;
52
- }
53
- opts.res.setHeader(key, value);
54
- }
55
- if (isStreaming) {
56
- opts.res.setHeader('Transfer-Encoding', 'chunked');
57
- const vary = opts.res.getHeader('Vary');
58
- opts.res.setHeader('Vary', vary ? 'trpc-batch-mode, ' + vary : 'trpc-batch-mode');
59
- isStream = true;
60
- formatter = getBatchStreamFormatter();
61
- opts.res.flushHeaders();
62
- }
63
- };
64
- const unstable_onChunk = ([index, string]) => {
65
- if (index === -1) {
66
- /**
67
- * Full response, no streaming. This can happen
68
- * - if the response is an error
69
- * - if response is empty (HEAD request)
70
- */
71
- opts.res.end(string);
72
- }
73
- else {
74
- opts.res.write(formatter(index, string));
75
- opts.res.flush?.();
76
- }
77
- };
78
- await resolveHTTPResponse({
79
- batching: opts.batching,
80
- responseMeta: opts.responseMeta,
81
- path: opts.path,
82
- createContext,
83
- router: opts.router,
84
- req,
85
- error: bodyResult.ok ? null : bodyResult.error,
86
- preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
87
- onError(o) {
88
- opts?.onError?.({
89
- ...o,
90
- req: opts.req,
91
- });
92
- },
93
- contentTypeHandler,
94
- unstable_onHead,
95
- unstable_onChunk,
96
- });
97
- if (isStream) {
98
- opts.res.write(formatter.end());
99
- opts.res.end();
100
- }
101
- return opts.res;
102
- });
103
- }
104
-
105
- export { nodeHTTPRequestHandler as n };