@trpc/server 11.0.0-next-alpha.133 → 11.0.0-next-alpha.140

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 (60) hide show
  1. package/dist/adapters/aws-lambda/index.js +2 -2
  2. package/dist/adapters/aws-lambda/index.mjs +2 -2
  3. package/dist/adapters/express.js +3 -3
  4. package/dist/adapters/express.mjs +3 -3
  5. package/dist/adapters/fastify/index.js +2 -2
  6. package/dist/adapters/fastify/index.mjs +2 -2
  7. package/dist/adapters/fetch/index.js +2 -2
  8. package/dist/adapters/fetch/index.mjs +2 -2
  9. package/dist/adapters/next.js +3 -3
  10. package/dist/adapters/next.mjs +3 -3
  11. package/dist/adapters/node-http/index.js +3 -3
  12. package/dist/adapters/node-http/index.mjs +3 -3
  13. package/dist/adapters/standalone.js +3 -3
  14. package/dist/adapters/standalone.mjs +3 -3
  15. package/dist/adapters/ws.js +1 -1
  16. package/dist/adapters/ws.mjs +1 -1
  17. package/dist/bundle-analysis.json +73 -72
  18. package/dist/core/index.d.ts +2 -3
  19. package/dist/core/index.d.ts.map +1 -1
  20. package/dist/core/initTRPC.d.ts +16 -41
  21. package/dist/core/initTRPC.d.ts.map +1 -1
  22. package/dist/core/internals/procedureBuilder.d.ts +46 -60
  23. package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
  24. package/dist/core/internals/utils.d.ts +1 -9
  25. package/dist/core/internals/utils.d.ts.map +1 -1
  26. package/dist/core/middleware.d.ts +33 -85
  27. package/dist/core/middleware.d.ts.map +1 -1
  28. package/dist/core/router.d.ts +6 -1
  29. package/dist/core/router.d.ts.map +1 -1
  30. package/dist/http/index.js +2 -2
  31. package/dist/http/index.mjs +2 -2
  32. package/dist/index.js +12 -3
  33. package/dist/index.mjs +13 -5
  34. package/dist/{nodeHTTPRequestHandler-84248270.js → nodeHTTPRequestHandler-3f218e71.js} +1 -1
  35. package/dist/{nodeHTTPRequestHandler-fb26ba4e.mjs → nodeHTTPRequestHandler-c92e159b.mjs} +1 -1
  36. package/dist/{nodeHTTPRequestHandler-e24d9576.js → nodeHTTPRequestHandler-f04ea0b8.js} +1 -1
  37. package/dist/{procedureBuilder-c990500b.js → procedureBuilder-51db231f.js} +13 -21
  38. package/dist/{procedureBuilder-88b211d2.mjs → procedureBuilder-955ce9bc.mjs} +12 -17
  39. package/dist/{procedureBuilder-0ee77d9c.js → procedureBuilder-f3a66e27.js} +12 -17
  40. package/dist/{resolveHTTPResponse-c5c776d4.js → resolveHTTPResponse-62594a39.js} +1 -1
  41. package/dist/{resolveHTTPResponse-cbea0b76.js → resolveHTTPResponse-e5110d33.js} +1 -1
  42. package/dist/{resolveHTTPResponse-6ce6731d.mjs → resolveHTTPResponse-fda30ede.mjs} +1 -1
  43. package/dist/{router-6e6a40b3.js → router-05a567ea.js} +19 -0
  44. package/dist/{router-2e54d451.js → router-40fcf5e5.js} +19 -1
  45. package/dist/{router-accbd60f.mjs → router-8564439c.mjs} +19 -1
  46. package/dist/shared/internal/serialize.d.ts +38 -8
  47. package/dist/shared/internal/serialize.d.ts.map +1 -1
  48. package/dist/unstableInternalsExport.js +2 -2
  49. package/dist/unstableInternalsExport.mjs +2 -2
  50. package/package.json +2 -2
  51. package/src/core/index.ts +3 -2
  52. package/src/core/initTRPC.ts +18 -3
  53. package/src/core/internals/procedureBuilder.ts +174 -111
  54. package/src/core/internals/utils.ts +1 -14
  55. package/src/core/middleware.ts +114 -163
  56. package/src/core/router.ts +30 -1
  57. package/src/shared/internal/serialize.ts +58 -23
  58. package/dist/core/internals/builderTypes.d.ts +0 -14
  59. package/dist/core/internals/builderTypes.d.ts.map +0 -1
  60. package/src/core/internals/builderTypes.ts +0 -14
@@ -1,16 +1,7 @@
1
1
  import { TRPCError } from '../error/TRPCError';
2
2
  import { Simplify } from '../types';
3
- import { AnyProcedureBuilderParams } from './internals/builderTypes';
4
- import { AnyRootConfig, RootConfig } from './internals/config';
5
3
  import { ParseFn } from './internals/getParseFn';
6
- import { ProcedureBuilderMiddleware } from './internals/procedureBuilder';
7
- import {
8
- DefaultValue,
9
- GetRawInputFn,
10
- MiddlewareMarker,
11
- Overwrite,
12
- UnsetMarker,
13
- } from './internals/utils';
4
+ import { GetRawInputFn, MiddlewareMarker, Overwrite } from './internals/utils';
14
5
  import { ProcedureType } from './types';
15
6
 
16
7
  /**
@@ -27,8 +18,7 @@ interface MiddlewareResultBase {
27
18
  /**
28
19
  * @internal
29
20
  */
30
- interface MiddlewareOKResult<_TParams extends AnyProcedureBuilderParams>
31
- extends MiddlewareResultBase {
21
+ interface MiddlewareOKResult<_TContextOverride> extends MiddlewareResultBase {
32
22
  ok: true;
33
23
  data: unknown;
34
24
  // this could be extended with `input`/`rawInput` later
@@ -37,7 +27,7 @@ interface MiddlewareOKResult<_TParams extends AnyProcedureBuilderParams>
37
27
  /**
38
28
  * @internal
39
29
  */
40
- interface MiddlewareErrorResult<_TParams extends AnyProcedureBuilderParams>
30
+ interface MiddlewareErrorResult<_TContextOverride>
41
31
  extends MiddlewareResultBase {
42
32
  ok: false;
43
33
  error: TRPCError;
@@ -46,133 +36,96 @@ interface MiddlewareErrorResult<_TParams extends AnyProcedureBuilderParams>
46
36
  /**
47
37
  * @internal
48
38
  */
49
- export type MiddlewareResult<TParams extends AnyProcedureBuilderParams> =
50
- | MiddlewareErrorResult<TParams>
51
- | MiddlewareOKResult<TParams>;
39
+ export type MiddlewareResult<_TContextOverride> =
40
+ | MiddlewareErrorResult<_TContextOverride>
41
+ | MiddlewareOKResult<_TContextOverride>;
52
42
 
53
43
  /**
54
44
  * @internal
55
45
  */
56
46
  export interface MiddlewareBuilder<
57
- TRoot extends AnyProcedureBuilderParams,
58
- TNewParams extends AnyProcedureBuilderParams,
47
+ TContext,
48
+ TMeta,
49
+ TContextOverrides,
50
+ TInputIn,
59
51
  > {
60
52
  /**
61
53
  * Create a new builder based on the current middleware builder
62
54
  */
63
- unstable_pipe<$Params extends AnyProcedureBuilderParams>(
64
- fn: {
65
- _config: TRoot['_config'];
66
- _meta: TRoot['_meta'];
67
- _ctx_out: Overwrite<TRoot['_ctx_out'], TNewParams['_ctx_out']>;
68
- _input_in: DefaultValue<TRoot['_input_in'], TNewParams['_input_in']>;
69
- _input_out: DefaultValue<TRoot['_input_out'], TNewParams['_input_out']>;
70
- _output_in: DefaultValue<TRoot['_output_in'], TNewParams['_output_in']>;
71
- _output_out: DefaultValue<
72
- TRoot['_output_out'],
73
- TNewParams['_output_out']
74
- >;
75
- } extends infer OParams extends AnyProcedureBuilderParams
76
- ?
77
- | MiddlewareBuilder<OParams, $Params>
78
- | MiddlewareFunction<OParams, $Params>
79
- : never,
80
- ): CreateMiddlewareReturnInput<
81
- TRoot,
82
- TNewParams,
83
- Overwrite<TNewParams, $Params>
55
+ unstable_pipe<$ContextOverridesOut>(
56
+ fn:
57
+ | MiddlewareFunction<
58
+ TContext,
59
+ TMeta,
60
+ TContextOverrides,
61
+ $ContextOverridesOut,
62
+ TInputIn
63
+ >
64
+ | MiddlewareBuilder<
65
+ Overwrite<TContext, TContextOverrides>,
66
+ TMeta,
67
+ $ContextOverridesOut,
68
+ TInputIn
69
+ >,
70
+ ): MiddlewareBuilder<
71
+ TContext,
72
+ TMeta,
73
+ Overwrite<TContextOverrides, $ContextOverridesOut>,
74
+ TInputIn
84
75
  >;
85
76
 
86
77
  /**
87
78
  * List of middlewares within this middleware builder
88
79
  */
89
- _middlewares: MiddlewareFunction<TRoot, TNewParams>[];
80
+ _middlewares: MiddlewareFunction<
81
+ TContext,
82
+ TMeta,
83
+ TContextOverrides,
84
+ object,
85
+ TInputIn
86
+ >[];
90
87
  }
91
88
 
92
- /**
93
- * @internal
94
- * FIXME: there must be a nicer way of doing this, it's hard to maintain when we have several structures like this
95
- */
96
- type CreateMiddlewareReturnInput<
97
- TRoot extends AnyProcedureBuilderParams,
98
- TPrev extends AnyProcedureBuilderParams,
99
- TNext extends AnyProcedureBuilderParams,
100
- > = MiddlewareBuilder<
101
- TRoot,
102
- {
103
- _config: TPrev['_config'];
104
- _meta: TPrev['_meta'];
105
- _ctx_out: Overwrite<TPrev['_ctx_out'], TNext['_ctx_out']>;
106
- _input_in: DefaultValue<TNext['_input_in'], TPrev['_input_in']>;
107
- _input_out: DefaultValue<TNext['_input_out'], TPrev['_input_out']>;
108
- _output_in: DefaultValue<TNext['_output_in'], TPrev['_output_in']>;
109
- _output_out: DefaultValue<TNext['_output_out'], TPrev['_output_out']>;
110
- }
111
- >;
112
-
113
- /**
114
- * @internal
115
- */
116
- type deriveParamsFromConfig<
117
- TConfig extends AnyRootConfig,
118
- TInputIn = unknown,
119
- > = {
120
- _config: TConfig;
121
- // eslint-disable-next-line @typescript-eslint/ban-types
122
- _ctx_out: {};
123
- _input_out: UnsetMarker;
124
- _input_in: TInputIn;
125
- _output_in: unknown;
126
- _output_out: unknown;
127
- _meta: TConfig['$types']['meta'];
128
- };
129
89
  /**
130
90
  * @internal
131
91
  */
132
92
  export type MiddlewareFunction<
133
- TParams extends AnyProcedureBuilderParams,
134
- TParamsAfter extends AnyProcedureBuilderParams,
93
+ TContext,
94
+ TMeta,
95
+ TContextOverridesIn,
96
+ $ContextOverridesOut,
97
+ TInputIn,
135
98
  > = {
136
99
  (opts: {
137
- ctx: Simplify<
138
- Overwrite<TParams['_config']['$types']['ctx'], TParams['_ctx_out']>
139
- >;
100
+ ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
140
101
  type: ProcedureType;
141
102
  path: string;
142
- input: TParams['_input_in'];
103
+ input: TInputIn;
143
104
  getRawInput: GetRawInputFn;
144
- meta: TParams['_meta'] | undefined;
105
+ meta: TMeta | undefined;
145
106
  next: {
146
- (): Promise<MiddlewareResult<TParams>>;
147
- <$Context>(opts: { ctx?: $Context; input?: unknown }): Promise<
148
- MiddlewareResult<{
149
- _config: TParams['_config'];
150
- _ctx_out: $Context;
151
- _input_in: TParams['_input_in'];
152
- _input_out: TParams['_input_out'];
153
- _output_in: TParams['_output_in'];
154
- _output_out: TParams['_output_out'];
155
- _meta: TParams['_meta'];
156
- }>
157
- >;
107
+ (): Promise<MiddlewareResult<TContextOverridesIn>>;
108
+ <$ContextOverride>(opts: {
109
+ ctx?: $ContextOverride;
110
+ input?: unknown;
111
+ }): Promise<MiddlewareResult<$ContextOverride>>;
158
112
  (opts: { getRawInput: GetRawInputFn }): Promise<
159
- MiddlewareResult<TParams>
113
+ MiddlewareResult<TContextOverridesIn>
160
114
  >;
161
115
  };
162
- }): Promise<MiddlewareResult<TParamsAfter>>;
116
+ }): Promise<MiddlewareResult<$ContextOverridesOut>>;
163
117
  _type?: string | undefined;
164
118
  };
165
119
 
120
+ export type AnyMiddlewareFunction = MiddlewareFunction<any, any, any, any, any>;
121
+ export type AnyMiddlewareBuilder = MiddlewareBuilder<any, any, any, any>;
166
122
  /**
167
123
  * @internal
168
124
  */
169
- export function createMiddlewareFactory<
170
- TConfig extends AnyRootConfig,
171
- TInputIn = unknown,
172
- >() {
173
- function createMiddlewareInner<TNewParams extends AnyProcedureBuilderParams>(
174
- middlewares: MiddlewareFunction<any, any>[],
175
- ): MiddlewareBuilder<deriveParamsFromConfig<TConfig, TInputIn>, TNewParams> {
125
+ export function createMiddlewareFactory<TContext, TMeta, TInputIn = unknown>() {
126
+ function createMiddlewareInner(
127
+ middlewares: AnyMiddlewareFunction[],
128
+ ): AnyMiddlewareBuilder {
176
129
  return {
177
130
  _middlewares: middlewares,
178
131
  unstable_pipe(middlewareBuilderOrFn) {
@@ -181,20 +134,20 @@ export function createMiddlewareFactory<
181
134
  ? middlewareBuilderOrFn._middlewares
182
135
  : [middlewareBuilderOrFn];
183
136
 
184
- return createMiddlewareInner([
185
- ...(middlewares as any),
186
- ...pipedMiddleware,
187
- ]);
137
+ return createMiddlewareInner([...middlewares, ...pipedMiddleware]);
188
138
  },
189
139
  };
190
140
  }
191
141
 
192
- function createMiddleware<TNewParams extends AnyProcedureBuilderParams>(
142
+ function createMiddleware<$ContextOverrides>(
193
143
  fn: MiddlewareFunction<
194
- deriveParamsFromConfig<TConfig, TInputIn>,
195
- TNewParams
144
+ TContext,
145
+ TMeta,
146
+ object,
147
+ $ContextOverrides,
148
+ TInputIn
196
149
  >,
197
- ): MiddlewareBuilder<deriveParamsFromConfig<TConfig, TInputIn>, TNewParams> {
150
+ ): MiddlewareBuilder<TContext, TMeta, $ContextOverrides, TInputIn> {
198
151
  return createMiddlewareInner([fn]);
199
152
  }
200
153
 
@@ -209,12 +162,8 @@ export const experimental_standaloneMiddleware = <
209
162
  },
210
163
  >() => ({
211
164
  create: createMiddlewareFactory<
212
- RootConfig<{
213
- ctx: TCtx extends { ctx: infer T extends object } ? T : object;
214
- meta: TCtx extends { meta: infer T extends object } ? T : object;
215
- errorShape: object;
216
- transformer: object;
217
- }>,
165
+ TCtx extends { ctx: infer T extends object } ? T : any,
166
+ TCtx extends { meta: infer T extends object } ? T : object,
218
167
  TCtx extends { input: infer T } ? T : unknown
219
168
  >(),
220
169
  });
@@ -228,30 +177,31 @@ function isPlainObject(obj: unknown) {
228
177
  * Please note, `trpc-openapi` uses this function.
229
178
  */
230
179
  export function createInputMiddleware<TInput>(parse: ParseFn<TInput>) {
231
- const inputMiddleware: ProcedureBuilderMiddleware = async (opts) => {
232
- let parsedInput: ReturnType<typeof parse>;
233
-
234
- const rawInput = await opts.getRawInput();
235
- try {
236
- parsedInput = await parse(rawInput);
237
- } catch (cause) {
238
- throw new TRPCError({
239
- code: 'BAD_REQUEST',
240
- cause,
241
- });
242
- }
243
-
244
- // Multiple input parsers
245
- const combinedInput =
246
- isPlainObject(opts.input) && isPlainObject(parsedInput)
247
- ? {
248
- ...opts.input,
249
- ...parsedInput,
250
- }
251
- : parsedInput;
252
-
253
- return opts.next({ input: combinedInput });
254
- };
180
+ const inputMiddleware: AnyMiddlewareFunction =
181
+ async function inputValidatorMiddleware(opts) {
182
+ let parsedInput: ReturnType<typeof parse>;
183
+
184
+ const rawInput = await opts.getRawInput();
185
+ try {
186
+ parsedInput = await parse(rawInput);
187
+ } catch (cause) {
188
+ throw new TRPCError({
189
+ code: 'BAD_REQUEST',
190
+ cause,
191
+ });
192
+ }
193
+
194
+ // Multiple input parsers
195
+ const combinedInput =
196
+ isPlainObject(opts.input) && isPlainObject(parsedInput)
197
+ ? {
198
+ ...opts.input,
199
+ ...parsedInput,
200
+ }
201
+ : parsedInput;
202
+
203
+ return opts.next({ input: combinedInput });
204
+ };
255
205
  inputMiddleware._type = 'input';
256
206
  return inputMiddleware;
257
207
  }
@@ -260,26 +210,27 @@ export function createInputMiddleware<TInput>(parse: ParseFn<TInput>) {
260
210
  * @internal
261
211
  */
262
212
  export function createOutputMiddleware<TOutput>(parse: ParseFn<TOutput>) {
263
- const outputMiddleware: ProcedureBuilderMiddleware = async ({ next }) => {
264
- const result = await next();
265
- if (!result.ok) {
266
- // pass through failures without validating
267
- return result;
268
- }
269
- try {
270
- const data = await parse(result.data);
271
- return {
272
- ...result,
273
- data,
274
- };
275
- } catch (cause) {
276
- throw new TRPCError({
277
- message: 'Output validation failed',
278
- code: 'INTERNAL_SERVER_ERROR',
279
- cause,
280
- });
281
- }
282
- };
213
+ const outputMiddleware: AnyMiddlewareFunction =
214
+ async function outputValidatorMiddleware({ next }) {
215
+ const result = await next();
216
+ if (!result.ok) {
217
+ // pass through failures without validating
218
+ return result;
219
+ }
220
+ try {
221
+ const data = await parse(result.data);
222
+ return {
223
+ ...result,
224
+ data,
225
+ };
226
+ } catch (cause) {
227
+ throw new TRPCError({
228
+ message: 'Output validation failed',
229
+ code: 'INTERNAL_SERVER_ERROR',
230
+ cause,
231
+ });
232
+ }
233
+ };
283
234
  outputMiddleware._type = 'output';
284
235
  return outputMiddleware;
285
236
  }
@@ -46,12 +46,16 @@ type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
46
46
  /**
47
47
  * @internal
48
48
  */
49
- type RouterCaller<TDef extends AnyRouterDef> = (
49
+ export type RouterCaller<TDef extends AnyRouterDef> = (
50
50
  ctx: TDef['_config']['$types']['ctx'],
51
51
  ) => DecoratedProcedureRecord<TDef['record']>;
52
52
 
53
53
  export interface Router<TDef extends AnyRouterDef> {
54
54
  _def: TDef;
55
+ /**
56
+ * @deprecated use `t.createCallerFactory(router)` instead
57
+ * @see https://trpc.io/docs/server/server-side-calls
58
+ */
55
59
  createCaller: RouterCaller<TDef>;
56
60
  }
57
61
 
@@ -164,6 +168,7 @@ export function createRouterFactory<TConfig extends AnyRootConfig>(
164
168
  return proxy as ReturnType<RouterCaller<any>>;
165
169
  },
166
170
  };
171
+
167
172
  return router as any;
168
173
  };
169
174
  }
@@ -190,3 +195,27 @@ export function callProcedure(
190
195
 
191
196
  return proc(opts);
192
197
  }
198
+
199
+ export function createCallerFactory<TConfig extends AnyRootConfig>() {
200
+ return function createCallerInner<
201
+ TRouter extends Router<AnyRouterDef<TConfig>>,
202
+ >(router: TRouter): RouterCaller<TRouter['_def']> {
203
+ const _def = router._def;
204
+
205
+ return function createCaller(ctx) {
206
+ const proxy = createRecursiveProxy(({ path, args }) => {
207
+ const fullPath = path.join('.');
208
+ const procedure = _def.procedures[fullPath] as AnyProcedure;
209
+
210
+ return procedure({
211
+ path: fullPath,
212
+ getRawInput: async () => args[0],
213
+ ctx,
214
+ type: procedure._def.type,
215
+ });
216
+ });
217
+
218
+ return proxy as ReturnType<RouterCaller<any>>;
219
+ };
220
+ };
221
+ }
@@ -40,48 +40,83 @@ export type Serialize<T> =
40
40
 
41
41
  /** JSON serialize [tuples](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) */
42
42
  type SerializeTuple<T extends [unknown, ...unknown[]]> = {
43
- [k in keyof T]: T[k] extends NonJsonPrimitive ? null : Serialize<T[k]>;
43
+ [K in keyof T]: T[K] extends NonJsonPrimitive ? null : Serialize<T[K]>;
44
44
  };
45
45
 
46
46
  // prettier-ignore
47
- type SerializeObjectKey<T extends Record<any, any>, TKey> =
47
+ type SerializeObjectKey<T extends Record<any, any>, K> =
48
48
  // never include entries where the key is a symbol
49
- TKey extends symbol ? never :
49
+ K extends symbol ? never :
50
50
  // always include entries where the value is any
51
- IsAny<T[TKey]> extends true ? TKey :
51
+ IsAny<T[K]> extends true ? K :
52
52
  // always include entries where the value is unknown
53
- unknown extends T[TKey] ? TKey :
53
+ unknown extends T[K] ? K :
54
54
  // never include entries where the value is a non-JSON primitive
55
- T[TKey] extends NonJsonPrimitive ? never :
55
+ T[K] extends NonJsonPrimitive ? never :
56
56
  // otherwise serialize the value
57
- TKey;
57
+ K;
58
58
  /**
59
59
  * JSON serialize objects (not including arrays) and classes
60
60
  * @internal
61
61
  **/
62
62
  export type SerializeObject<T extends object> = {
63
- [$Key in keyof T as SerializeObjectKey<T, $Key>]: Serialize<T[$Key]>;
63
+ [K in keyof T as SerializeObjectKey<T, K>]: Serialize<T[K]>;
64
64
  };
65
65
 
66
- type FilterDefinedKeys<TObj extends object> = Exclude<
66
+ /**
67
+ * Extract keys from T where the value dosen't extend undefined
68
+ * Note: Can't parse IndexSignature or Record types
69
+ */
70
+ type FilterDefinedKeys<T extends object> = Exclude<
67
71
  {
68
- [TKey in keyof TObj]: undefined extends TObj[TKey] ? never : TKey;
69
- }[keyof TObj],
72
+ [K in keyof T]: undefined extends T[K] ? never : K;
73
+ }[keyof T],
70
74
  undefined
71
75
  >;
72
76
 
73
- /*
74
- * For an object T, if it has any properties that are a union with `undefined`,
75
- * make those into optional properties instead.
76
- *
77
- * Example: { a: string | undefined} --> { a?: string}
77
+ /**
78
+ * Get value of exactOptionalPropertyTypes config
79
+ */
80
+ type ExactOptionalPropertyTypes = { a?: 0 | undefined } extends {
81
+ a?: 0;
82
+ }
83
+ ? false
84
+ : true;
85
+
86
+ /**
87
+ * Check if T has an index signature
88
+ */
89
+ type HasIndexSignature<T extends object> = string extends keyof T
90
+ ? true
91
+ : false;
92
+
93
+ /**
94
+ * { [key: string]: number | undefined } --> { [key: string]: number }
95
+ */
96
+ type HandleIndexSignature<T extends object> = {
97
+ [K in keyof Omit<T, keyof WithoutIndexSignature<T>>]: Exclude<
98
+ T[K],
99
+ undefined
100
+ >;
101
+ };
102
+
103
+ /**
104
+ * { a: number | undefined } --> { a?: number }
105
+ * Note: Can't parse IndexSignature or Record types
106
+ */
107
+ type HandleUndefined<T extends object> = {
108
+ [K in keyof Omit<T, FilterDefinedKeys<T>>]?: Exclude<T[K], undefined>;
109
+ };
110
+
111
+ /**
112
+ * Handle undefined, index signature and records
78
113
  */
79
114
  type UndefinedToOptional<T extends object> =
80
115
  // Property is not a union with `undefined`, keep as-is
81
- Pick<
82
- WithoutIndexSignature<T>,
83
- FilterDefinedKeys<WithoutIndexSignature<T>>
84
- > & {
85
- // Property _is_ a union with `defined`. Set as optional (via `?`) and remove `undefined` from the union
86
- [k in keyof Omit<T, FilterDefinedKeys<T>>]?: Exclude<T[k], undefined>;
87
- };
116
+ Pick<WithoutIndexSignature<T>, FilterDefinedKeys<WithoutIndexSignature<T>>> &
117
+ // If following is true, don't merge undefined or optional into index signature if any in T
118
+ (ExactOptionalPropertyTypes extends true
119
+ ? HandleIndexSignature<T> & HandleUndefined<WithoutIndexSignature<T>>
120
+ : HasIndexSignature<T> extends true
121
+ ? HandleIndexSignature<T>
122
+ : HandleUndefined<T>);
@@ -1,14 +0,0 @@
1
- import { AnyRootConfig } from './config';
2
- /**
3
- * @internal
4
- */
5
- export type AnyProcedureBuilderParams = {
6
- _config: AnyRootConfig;
7
- _meta: unknown;
8
- _ctx_out: unknown;
9
- _input_in: unknown;
10
- _input_out: unknown;
11
- _output_in: unknown;
12
- _output_out: unknown;
13
- };
14
- //# sourceMappingURL=builderTypes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builderTypes.d.ts","sourceRoot":"","sources":["../../../src/core/internals/builderTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
@@ -1,14 +0,0 @@
1
- import { AnyRootConfig } from './config';
2
-
3
- /**
4
- * @internal
5
- */
6
- export type AnyProcedureBuilderParams = {
7
- _config: AnyRootConfig;
8
- _meta: unknown;
9
- _ctx_out: unknown;
10
- _input_in: unknown;
11
- _input_out: unknown;
12
- _output_in: unknown;
13
- _output_out: unknown;
14
- };