@trpc/server 10.12.0 → 10.13.1

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 (87) hide show
  1. package/adapters/node-http/content-type/form-data/index.d.ts +1 -0
  2. package/adapters/node-http/content-type/form-data/index.js +1 -0
  3. package/adapters/node-http/content-type/json/index.d.ts +1 -0
  4. package/adapters/node-http/content-type/json/index.js +1 -0
  5. package/dist/TRPCError-ed16b3b7.js +55 -0
  6. package/dist/adapters/aws-lambda/index.js +3 -3
  7. package/dist/adapters/aws-lambda/index.mjs +3 -3
  8. package/dist/adapters/express.js +4 -4
  9. package/dist/adapters/express.mjs +4 -4
  10. package/dist/adapters/fastify/index.js +4 -4
  11. package/dist/adapters/fastify/index.mjs +4 -4
  12. package/dist/adapters/fetch/index.js +4 -4
  13. package/dist/adapters/fetch/index.mjs +4 -4
  14. package/dist/adapters/next.js +4 -4
  15. package/dist/adapters/next.mjs +4 -4
  16. package/dist/adapters/node-http/index.js +4 -4
  17. package/dist/adapters/node-http/index.mjs +4 -4
  18. package/dist/adapters/standalone.js +4 -4
  19. package/dist/adapters/standalone.mjs +4 -4
  20. package/dist/adapters/ws.js +11 -11
  21. package/dist/adapters/ws.mjs +11 -11
  22. package/dist/codes-ec2bad91.js +45 -0
  23. package/dist/config-69ee2314.js +225 -0
  24. package/dist/{config-d356ff77.js → config-bd759464.js} +2 -2
  25. package/dist/{config-4ca0221b.mjs → config-fb5f49a1.mjs} +2 -2
  26. package/dist/core/index.d.ts +1 -0
  27. package/dist/core/index.d.ts.map +1 -1
  28. package/dist/core/internals/config.d.ts.map +1 -1
  29. package/dist/core/internals/procedureBuilder.d.ts +3 -6
  30. package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
  31. package/dist/deprecated/internals/procedure.d.ts.map +1 -1
  32. package/dist/error/TRPCError.d.ts +1 -0
  33. package/dist/error/TRPCError.d.ts.map +1 -1
  34. package/dist/error/utils.d.ts +0 -2
  35. package/dist/error/utils.d.ts.map +1 -1
  36. package/dist/http/index.js +3 -3
  37. package/dist/http/index.mjs +3 -3
  38. package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
  39. package/dist/index-f38f12ba.js +47 -0
  40. package/dist/index.js +3 -2
  41. package/dist/index.mjs +4 -4
  42. package/dist/internals.d.ts +1 -1
  43. package/dist/internals.d.ts.map +1 -1
  44. package/dist/{nodeHTTPRequestHandler-196730a5.js → nodeHTTPRequestHandler-40bc6a18.js} +2 -2
  45. package/dist/{nodeHTTPRequestHandler-1fb01cee.mjs → nodeHTTPRequestHandler-4314fa32.mjs} +2 -2
  46. package/dist/nodeHTTPRequestHandler-93528c16.js +76 -0
  47. package/dist/observable-a1c2103f.js +83 -0
  48. package/dist/resolveHTTPResponse-39258d19.js +205 -0
  49. package/dist/{resolveHTTPResponse-64517f5d.mjs → resolveHTTPResponse-8e9dd846.mjs} +4 -4
  50. package/dist/{resolveHTTPResponse-5e0173eb.js → resolveHTTPResponse-cbfdc43d.js} +4 -4
  51. package/dist/subscription.js +4 -4
  52. package/dist/subscription.mjs +4 -4
  53. package/dist/transformTRPCResponse-896669e0.js +28 -0
  54. package/dist/transformer.d.ts +35 -8
  55. package/dist/transformer.d.ts.map +1 -1
  56. package/package.json +11 -15
  57. package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
  58. package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
  59. package/src/adapters/ws.ts +11 -11
  60. package/src/core/index.ts +1 -0
  61. package/src/core/internals/config.ts +2 -1
  62. package/src/core/internals/procedureBuilder.ts +10 -22
  63. package/src/deprecated/internals/procedure.ts +2 -5
  64. package/src/error/TRPCError.ts +20 -0
  65. package/src/error/utils.ts +0 -23
  66. package/src/http/resolveHTTPResponse.ts +4 -4
  67. package/src/internals.ts +1 -1
  68. package/src/observable/observable.test.ts +15 -15
  69. package/src/observable/operators/map.test.ts +2 -2
  70. package/src/observable/operators/share.test.ts +9 -9
  71. package/src/subscription.ts +4 -4
  72. package/src/transformer.ts +36 -8
  73. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.d.ts +0 -1
  74. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.dev.js +0 -190
  75. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.js +0 -7
  76. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.prod.js +0 -190
  77. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.esm.js +0 -186
  78. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.d.ts +0 -1
  79. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +0 -109
  80. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.js +0 -7
  81. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +0 -109
  82. package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +0 -104
  83. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +0 -202
  84. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +0 -1
  85. package/src/core/internals/__generated__/mergeRoutersGeneric.ts +0 -306
  86. package/dist/{TRPCError-bd37df84.js → TRPCError-4cbab0d0.js} +7 -7
  87. package/dist/{TRPCError-7de0a793.mjs → TRPCError-e7333eae.mjs} +7 -7
@@ -19,7 +19,8 @@ export const isServerDefault: boolean =
19
19
  typeof window === 'undefined' ||
20
20
  'Deno' in window ||
21
21
  globalThis.process?.env?.NODE_ENV === 'test' ||
22
- !!globalThis.process?.env?.JEST_WORKER_ID;
22
+ !!globalThis.process?.env?.JEST_WORKER_ID ||
23
+ !!globalThis.process?.env?.VITEST_WORKER_ID;
23
24
 
24
25
  /**
25
26
  * The runtime config that are used and actually represents real values underneath
@@ -1,11 +1,5 @@
1
- import { TRPCError } from '../../error/TRPCError';
2
- import { getTRPCErrorFromUnknown } from '../../error/utils';
3
- import {
4
- InferOptional,
5
- MaybePromise,
6
- Simplify,
7
- UndefinedKeys,
8
- } from '../../types';
1
+ import { TRPCError, getTRPCErrorFromUnknown } from '../../error/TRPCError';
2
+ import { MaybePromise, Simplify } from '../../types';
9
3
  import {
10
4
  MiddlewareBuilder,
11
5
  MiddlewareFunction,
@@ -68,19 +62,9 @@ export interface BuildProcedure<
68
62
  : TParams
69
63
  > {}
70
64
 
71
- type Merge<TType, TWith> = {
72
- [TKey in keyof TType | keyof TWith]: TKey extends keyof TType
73
- ? TKey extends keyof TWith
74
- ? TType[TKey] & TWith[TKey]
75
- : TType[TKey]
76
- : TWith[TKey & keyof TWith];
77
- };
78
-
79
65
  type OverwriteIfDefined<TType, TWith> = UnsetMarker extends TType
80
66
  ? TWith
81
- : Simplify<
82
- InferOptional<Merge<TType, TWith>, UndefinedKeys<Merge<TType, TWith>>>
83
- >;
67
+ : Simplify<TType & TWith>;
84
68
 
85
69
  type ErrorMessage<TMessage extends string> = TMessage;
86
70
 
@@ -104,9 +88,13 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
104
88
  input<$Parser extends Parser>(
105
89
  schema: TParams['_input_out'] extends UnsetMarker
106
90
  ? $Parser
107
- : inferParser<$Parser>['out'] extends Record<string, unknown>
108
- ? TParams['_input_out'] extends Record<string, unknown>
109
- ? $Parser
91
+ : inferParser<$Parser>['out'] extends Record<string, unknown> | undefined
92
+ ? TParams['_input_out'] extends Record<string, unknown> | undefined
93
+ ? undefined extends inferParser<$Parser>['out'] // if current is optional the previous must be too
94
+ ? undefined extends TParams['_input_out']
95
+ ? $Parser
96
+ : ErrorMessage<'Cannot chain an optional parser to a required parser'>
97
+ : $Parser
110
98
  : ErrorMessage<'All input parsers did not resolve to an object'>
111
99
  : ErrorMessage<'All input parsers did not resolve to an object'>,
112
100
  ): ProcedureBuilder<{
@@ -1,8 +1,5 @@
1
- import { TRPCError } from '../../error/TRPCError';
2
- import {
3
- getCauseFromUnknown,
4
- getTRPCErrorFromUnknown,
5
- } from '../../error/utils';
1
+ import { TRPCError, getTRPCErrorFromUnknown } from '../../error/TRPCError';
2
+ import { getCauseFromUnknown } from '../../error/utils';
6
3
  import { InferLast } from '../../types';
7
4
  import { ProcedureType } from '../router';
8
5
  import {
@@ -4,6 +4,26 @@ import {
4
4
  } from '../error/utils';
5
5
  import { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
6
6
 
7
+ export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
8
+ const error = getErrorFromUnknown(cause);
9
+ // this should ideally be an `instanceof TRPCError` but for some reason that isn't working
10
+ // ref https://github.com/trpc/trpc/issues/331
11
+ if (error.name === 'TRPCError') {
12
+ return cause as TRPCError;
13
+ }
14
+
15
+ const trpcError = new TRPCError({
16
+ code: 'INTERNAL_SERVER_ERROR',
17
+ cause: error,
18
+ message: error.message,
19
+ });
20
+
21
+ // Inherit stack from error
22
+ trpcError.stack = error.stack;
23
+
24
+ return trpcError;
25
+ }
26
+
7
27
  export class TRPCError extends Error {
8
28
  public readonly cause?;
9
29
  public readonly code;
@@ -1,5 +1,3 @@
1
- import { TRPCError } from './TRPCError';
2
-
3
1
  export function getMessageFromUnknownError(
4
2
  err: unknown,
5
3
  fallback: string,
@@ -7,7 +5,6 @@ export function getMessageFromUnknownError(
7
5
  if (typeof err === 'string') {
8
6
  return err;
9
7
  }
10
-
11
8
  if (err instanceof Error && typeof err.message === 'string') {
12
9
  return err.message;
13
10
  }
@@ -22,26 +19,6 @@ export function getErrorFromUnknown(cause: unknown): Error {
22
19
  return new Error(message);
23
20
  }
24
21
 
25
- export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
26
- const error = getErrorFromUnknown(cause);
27
- // this should ideally be an `instanceof TRPCError` but for some reason that isn't working
28
- // ref https://github.com/trpc/trpc/issues/331
29
- if (error.name === 'TRPCError') {
30
- return cause as TRPCError;
31
- }
32
-
33
- const trpcError = new TRPCError({
34
- code: 'INTERNAL_SERVER_ERROR',
35
- cause: error,
36
- message: error.message,
37
- });
38
-
39
- // Inherit stack from error
40
- trpcError.stack = error.stack;
41
-
42
- return trpcError;
43
- }
44
-
45
22
  export function getCauseFromUnknown(cause: unknown) {
46
23
  if (cause instanceof Error) {
47
24
  return cause;
@@ -6,8 +6,8 @@ import {
6
6
  inferRouterContext,
7
7
  inferRouterError,
8
8
  } from '../core';
9
- import { TRPCError } from '../error/TRPCError';
10
- import { getCauseFromUnknown, getTRPCErrorFromUnknown } from '../error/utils';
9
+ import { TRPCError, getTRPCErrorFromUnknown } from '../error/TRPCError';
10
+ import { getCauseFromUnknown } from '../error/utils';
11
11
  import { transformTRPCResponse } from '../internals/transformTRPCResponse';
12
12
  import { TRPCResponse } from '../rpc';
13
13
  import { Maybe } from '../types';
@@ -124,7 +124,7 @@ export async function resolveHTTPResponse<
124
124
  if (isBatchCall && !batchingEnabled) {
125
125
  throw new Error(`Batching is not enabled on the server`);
126
126
  }
127
- /* istanbul ignore if */
127
+ /* istanbul ignore if -- @preserve */
128
128
  if (type === 'subscription') {
129
129
  throw new TRPCError({
130
130
  message: 'Subscriptions should use wsLink',
@@ -154,7 +154,7 @@ export async function resolveHTTPResponse<
154
154
  };
155
155
  }
156
156
 
157
- /* istanbul ignore if */
157
+ /* istanbul ignore if -- @preserve */
158
158
  if (
159
159
  rawInput == null ||
160
160
  typeof rawInput !== 'object' ||
package/src/internals.ts CHANGED
@@ -8,5 +8,5 @@ export type {
8
8
  ProcedureBuilder,
9
9
  BuildProcedure,
10
10
  } from './core/internals/procedureBuilder';
11
- export type { unsetMarker } from './core/internals/utils';
11
+ export type { Overwrite, unsetMarker } from './core/internals/utils';
12
12
  export type { MiddlewareFunction, MiddlewareBuilder } from './core/middleware';
@@ -6,9 +6,9 @@ test('vanilla observable - complete()', () => {
6
6
  observer.complete();
7
7
  });
8
8
 
9
- const next = jest.fn();
10
- const error = jest.fn();
11
- const complete = jest.fn();
9
+ const next = vi.fn();
10
+ const error = vi.fn();
11
+ const complete = vi.fn();
12
12
  obs.subscribe({
13
13
  next,
14
14
  error,
@@ -25,9 +25,9 @@ test('vanilla observable - unsubscribe()', () => {
25
25
  observer.next(1);
26
26
  });
27
27
 
28
- const next = jest.fn();
29
- const error = jest.fn();
30
- const complete = jest.fn();
28
+ const next = vi.fn();
29
+ const error = vi.fn();
30
+ const complete = vi.fn();
31
31
  const sub = obs$.subscribe({
32
32
  next,
33
33
  error,
@@ -42,9 +42,9 @@ test('vanilla observable - unsubscribe()', () => {
42
42
 
43
43
  test('pipe - combine operators', () => {
44
44
  const taps = {
45
- next: jest.fn(),
46
- complete: jest.fn(),
47
- error: jest.fn(),
45
+ next: vi.fn(),
46
+ complete: vi.fn(),
47
+ error: vi.fn(),
48
48
  };
49
49
  const obs = observable<number, Error>((observer) => {
50
50
  observer.next(1);
@@ -54,9 +54,9 @@ test('pipe - combine operators', () => {
54
54
  tap(taps),
55
55
  );
56
56
  {
57
- const next = jest.fn();
58
- const error = jest.fn();
59
- const complete = jest.fn();
57
+ const next = vi.fn();
58
+ const error = vi.fn();
59
+ const complete = vi.fn();
60
60
  obs.subscribe({
61
61
  next,
62
62
  error,
@@ -69,9 +69,9 @@ test('pipe - combine operators', () => {
69
69
  }
70
70
 
71
71
  {
72
- const next = jest.fn();
73
- const error = jest.fn();
74
- const complete = jest.fn();
72
+ const next = vi.fn();
73
+ const error = vi.fn();
74
+ const complete = vi.fn();
75
75
  obs.subscribe({
76
76
  next,
77
77
  error,
@@ -39,7 +39,7 @@ test('map', () => {
39
39
  ee.off('data', callback);
40
40
  };
41
41
  });
42
- const pipeCalls = jest.fn();
42
+ const pipeCalls = vi.fn();
43
43
  const piped = eventObservable.pipe(
44
44
  map((...args) => {
45
45
  pipeCalls(...args);
@@ -48,7 +48,7 @@ test('map', () => {
48
48
  }),
49
49
  );
50
50
 
51
- const next = jest.fn();
51
+ const next = vi.fn();
52
52
  const subscription = piped.subscribe({
53
53
  next(value) {
54
54
  expectTypeOf<number>(value);
@@ -10,9 +10,9 @@ test('share', () => {
10
10
  );
11
11
 
12
12
  {
13
- const next = jest.fn();
14
- const error = jest.fn();
15
- const complete = jest.fn();
13
+ const next = vi.fn();
14
+ const error = vi.fn();
15
+ const complete = vi.fn();
16
16
  var subscription1 = obs.subscribe({
17
17
  next,
18
18
  error,
@@ -26,9 +26,9 @@ test('share', () => {
26
26
 
27
27
  {
28
28
  // subscribe again - it's shared so should not propagate any results
29
- const next = jest.fn();
30
- const error = jest.fn();
31
- const complete = jest.fn();
29
+ const next = vi.fn();
30
+ const error = vi.fn();
31
+ const complete = vi.fn();
32
32
  var subscription2 = obs.subscribe({
33
33
  next,
34
34
  error,
@@ -43,9 +43,9 @@ test('share', () => {
43
43
  subscription2.unsubscribe();
44
44
  // now it should be reset so we can do a new subscription
45
45
  {
46
- const next = jest.fn();
47
- const error = jest.fn();
48
- const complete = jest.fn();
46
+ const next = vi.fn();
47
+ const error = vi.fn();
48
+ const complete = vi.fn();
49
49
  var subscription3 = obs.subscribe({
50
50
  next,
51
51
  error,
@@ -1,4 +1,4 @@
1
- import { getTRPCErrorFromUnknown } from './error/utils';
1
+ import { getTRPCErrorFromUnknown } from './error/TRPCError';
2
2
  import { Observable, Observer, observable } from './observable';
3
3
 
4
4
  /**
@@ -15,17 +15,17 @@ export function subscriptionPullFactory<TOutput>(opts: {
15
15
  let timer: any;
16
16
  let stopped = false;
17
17
  async function _pull(emit: Observer<TOutput, unknown>) {
18
- /* istanbul ignore next */
18
+ /* istanbul ignore next -- @preserve */
19
19
  if (stopped) {
20
20
  return;
21
21
  }
22
22
  try {
23
23
  await opts.pull(emit);
24
- } catch (err /* istanbul ignore next */) {
24
+ } catch (err /* istanbul ignore next -- @preserve */) {
25
25
  emit.error(getTRPCErrorFromUnknown(err));
26
26
  }
27
27
 
28
- /* istanbul ignore else */
28
+ /* istanbul ignore else -- @preserve */
29
29
  if (!stopped) {
30
30
  timer = setTimeout(() => _pull(emit), opts.intervalMs);
31
31
  }
@@ -1,25 +1,53 @@
1
1
  /**
2
2
  * @public
3
3
  */
4
- export type DataTransformer = {
4
+ export interface DataTransformer {
5
5
  serialize(object: any): any;
6
6
  deserialize(object: any): any;
7
- };
7
+ }
8
+
9
+ interface InputDataTransformer extends DataTransformer {
10
+ /**
11
+ * This function runs **on the client** before sending the data to the server.
12
+ */
13
+ serialize(object: any): any;
14
+ /**
15
+ * This function runs **on the server** to transform the data before it is passed to the resolver
16
+ */
17
+ deserialize(object: any): any;
18
+ }
19
+
20
+ interface OutputDataTransformer extends DataTransformer {
21
+ /**
22
+ * This function runs **on the server** before sending the data to the client.
23
+ */
24
+ serialize(object: any): any;
25
+ /**
26
+ * This function runs **only on the client** to transform the data sent from the server.
27
+ */
28
+ deserialize(object: any): any;
29
+ }
8
30
 
9
31
  /**
10
32
  * @public
11
33
  */
12
- export type CombinedDataTransformer = {
13
- input: DataTransformer;
14
- output: DataTransformer;
15
- };
34
+ export interface CombinedDataTransformer {
35
+ /**
36
+ * Specify how the data sent from the client to the server should be transformed.
37
+ */
38
+ input: InputDataTransformer;
39
+ /**
40
+ * Specify how the data sent from the server to the client should be transformed.
41
+ */
42
+ output: OutputDataTransformer;
43
+ }
16
44
 
17
45
  /**
18
46
  * @public
19
47
  */
20
48
  export type CombinedDataTransformerClient = {
21
- input: Pick<DataTransformer, 'serialize'>;
22
- output: Pick<DataTransformer, 'deserialize'>;
49
+ input: Pick<CombinedDataTransformer['input'], 'serialize'>;
50
+ output: Pick<CombinedDataTransformer['output'], 'deserialize'>;
23
51
  };
24
52
 
25
53
  /**
@@ -1 +0,0 @@
1
- export * from "../../../dist/declarations/src/adapters/aws-lambda/index";
@@ -1,190 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var transformTRPCResponse = require('../../../dist/transformTRPCResponse-36a41418.cjs.dev.js');
6
- require('../../../dist/router-ee876044.cjs.dev.js');
7
- require('events');
8
- require('http');
9
- require('url');
10
- require('../../../dist/nodeHTTPRequestHandler-9a93c255.cjs.dev.js');
11
- var resolveHTTPResponse = require('../../../dist/resolveHTTPResponse-ab01e4b9.cjs.dev.js');
12
- require('../../../dist/codes-130e62df.cjs.dev.js');
13
-
14
- function isPayloadV1(event) {
15
- return determinePayloadFormat(event) == '1.0';
16
- }
17
- function isPayloadV2(event) {
18
- return determinePayloadFormat(event) == '2.0';
19
- }
20
-
21
- function determinePayloadFormat(event) {
22
- // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
23
- // According to AWS support, version is is extracted from the version property in the event.
24
- // If there is no version property, then the version is implied as 1.0
25
- const unknownEvent = event;
26
-
27
- if (typeof unknownEvent.version === 'undefined') {
28
- return '1.0';
29
- } else {
30
- if (['1.0', '2.0'].includes(unknownEvent.version)) {
31
- return unknownEvent.version;
32
- } else {
33
- return 'custom';
34
- }
35
- }
36
- }
37
-
38
- const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
39
-
40
- function lambdaEventToHTTPRequest(event) {
41
- const query = new URLSearchParams();
42
-
43
- for (const [key, value] of Object.entries((_event$queryStringPar = event.queryStringParameters) !== null && _event$queryStringPar !== void 0 ? _event$queryStringPar : {})) {
44
- var _event$queryStringPar;
45
-
46
- if (typeof value !== 'undefined') {
47
- query.append(key, value);
48
- }
49
- }
50
-
51
- return {
52
- method: getHTTPMethod(event),
53
- query: query,
54
- headers: event.headers,
55
- body: event.body
56
- };
57
- }
58
-
59
- function getHTTPMethod(event) {
60
- if (isPayloadV1(event)) {
61
- return event.httpMethod;
62
- }
63
-
64
- if (isPayloadV2(event)) {
65
- return event.requestContext.http.method;
66
- }
67
-
68
- throw new transformTRPCResponse.TRPCError({
69
- code: 'INTERNAL_SERVER_ERROR',
70
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
71
- });
72
- }
73
-
74
- function getPath(event) {
75
- if (isPayloadV1(event)) {
76
- const matches = event.resource.matchAll(/\{(.*?)\}/g);
77
-
78
- for (const match of matches) {
79
- const group = match[1];
80
-
81
- if (group.includes('+') && event.pathParameters) {
82
- return event.pathParameters[group.replace('+', '')] || '';
83
- }
84
- }
85
-
86
- return event.path.slice(1);
87
- }
88
-
89
- if (isPayloadV2(event)) {
90
- const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
91
-
92
- for (const match of matches) {
93
- const group = match[1];
94
-
95
- if (group.includes('+') && event.pathParameters) {
96
- return event.pathParameters[group.replace('+', '')] || '';
97
- }
98
- }
99
-
100
- return event.rawPath.slice(1);
101
- }
102
-
103
- throw new transformTRPCResponse.TRPCError({
104
- code: 'INTERNAL_SERVER_ERROR',
105
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
106
- });
107
- }
108
-
109
- function transformHeaders(headers) {
110
- const obj = {};
111
-
112
- for (const [key, value] of Object.entries(headers)) {
113
- if (typeof value === 'undefined') {
114
- continue;
115
- }
116
-
117
- obj[key] = Array.isArray(value) ? value.join(',') : value;
118
- }
119
-
120
- return obj;
121
- }
122
-
123
- function tRPCOutputToAPIGatewayOutput(event, response) {
124
- if (isPayloadV1(event)) {
125
- var _response$body, _response$headers;
126
-
127
- const resp = {
128
- statusCode: response.status,
129
- body: (_response$body = response.body) !== null && _response$body !== void 0 ? _response$body : '',
130
- headers: transformHeaders((_response$headers = response.headers) !== null && _response$headers !== void 0 ? _response$headers : {})
131
- };
132
- return resp;
133
- } else if (isPayloadV2(event)) {
134
- var _response$body2, _response$headers2;
135
-
136
- const resp = {
137
- statusCode: response.status,
138
- body: (_response$body2 = response.body) !== null && _response$body2 !== void 0 ? _response$body2 : undefined,
139
- headers: transformHeaders((_response$headers2 = response.headers) !== null && _response$headers2 !== void 0 ? _response$headers2 : {})
140
- };
141
- return resp;
142
- } else {
143
- throw new transformTRPCResponse.TRPCError({
144
- code: 'INTERNAL_SERVER_ERROR',
145
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
146
- });
147
- }
148
- }
149
- /** Will check the createContext of the TRouter and get the parameter of event.
150
- * @internal
151
- **/
152
-
153
-
154
- function awsLambdaRequestHandler(opts) {
155
- return async (event, context) => {
156
- const req = lambdaEventToHTTPRequest(event);
157
- const path = getPath(event);
158
-
159
- const createContext = async function _createContext() {
160
- var _opts$createContext;
161
-
162
- return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, {
163
- event,
164
- context
165
- }));
166
- };
167
-
168
- const response = await resolveHTTPResponse.resolveHTTPResponse({
169
- router: opts.router,
170
- batching: opts.batching,
171
- responseMeta: opts === null || opts === void 0 ? void 0 : opts.responseMeta,
172
- createContext,
173
- req,
174
- path,
175
- error: null,
176
-
177
- onError(o) {
178
- var _opts$onError;
179
-
180
- opts === null || opts === void 0 ? void 0 : (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, { ...o,
181
- req: event
182
- });
183
- }
184
-
185
- });
186
- return tRPCOutputToAPIGatewayOutput(event, response);
187
- };
188
- }
189
-
190
- exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./trpc-server-adapters-aws-lambda.cjs.prod.js");
5
- } else {
6
- module.exports = require("./trpc-server-adapters-aws-lambda.cjs.dev.js");
7
- }