server-act 1.1.5 → 1.1.6

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/index.d.mts CHANGED
@@ -2,10 +2,11 @@ import { z } from 'zod';
2
2
 
3
3
  declare const unsetMarker: unique symbol;
4
4
  type UnsetMarker = typeof unsetMarker;
5
+ type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
5
6
  type Prettify<T> = {
6
7
  [P in keyof T]: T[P];
7
8
  } & {};
8
- type OptionalizeUndefined<T> = undefined extends T ? [param?: T] : [param: T];
9
+ type SanitizeFunctionParam<T extends (param: any) => any> = T extends (param: infer P) => infer R ? Equals<P, undefined> extends true ? () => R : Equals<P, P | undefined> extends true ? (param?: P) => R : (param: P) => R : never;
9
10
  type InferParserType<T, TType extends 'in' | 'out'> = T extends z.ZodEffects<infer I, any, any> ? I[TType extends 'in' ? '_input' : '_output'] : T extends z.ZodType ? T[TType extends 'in' ? '_input' : '_output'] : never;
10
11
  type InferInputType<T, TType extends 'in' | 'out'> = T extends UnsetMarker ? undefined : InferParserType<T, TType>;
11
12
  type InferContextType<T> = T extends UnsetMarker ? undefined : T;
@@ -34,7 +35,7 @@ interface ActionBuilder<TParams extends ActionParams> {
34
35
  action: <TOutput>(action: (params: {
35
36
  ctx: InferContextType<TParams['_context']>;
36
37
  input: InferInputType<TParams['_input'], 'out'>;
37
- }) => Promise<TOutput>) => (...[input]: OptionalizeUndefined<InferInputType<TParams['_input'], 'in'>>) => Promise<TOutput>;
38
+ }) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams['_input'], 'in'>) => Promise<TOutput>>;
38
39
  /**
39
40
  * Create an action for React `useFormState`
40
41
  */
package/dist/index.d.ts CHANGED
@@ -2,10 +2,11 @@ import { z } from 'zod';
2
2
 
3
3
  declare const unsetMarker: unique symbol;
4
4
  type UnsetMarker = typeof unsetMarker;
5
+ type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
5
6
  type Prettify<T> = {
6
7
  [P in keyof T]: T[P];
7
8
  } & {};
8
- type OptionalizeUndefined<T> = undefined extends T ? [param?: T] : [param: T];
9
+ type SanitizeFunctionParam<T extends (param: any) => any> = T extends (param: infer P) => infer R ? Equals<P, undefined> extends true ? () => R : Equals<P, P | undefined> extends true ? (param?: P) => R : (param: P) => R : never;
9
10
  type InferParserType<T, TType extends 'in' | 'out'> = T extends z.ZodEffects<infer I, any, any> ? I[TType extends 'in' ? '_input' : '_output'] : T extends z.ZodType ? T[TType extends 'in' ? '_input' : '_output'] : never;
10
11
  type InferInputType<T, TType extends 'in' | 'out'> = T extends UnsetMarker ? undefined : InferParserType<T, TType>;
11
12
  type InferContextType<T> = T extends UnsetMarker ? undefined : T;
@@ -34,7 +35,7 @@ interface ActionBuilder<TParams extends ActionParams> {
34
35
  action: <TOutput>(action: (params: {
35
36
  ctx: InferContextType<TParams['_context']>;
36
37
  input: InferInputType<TParams['_input'], 'out'>;
37
- }) => Promise<TOutput>) => (...[input]: OptionalizeUndefined<InferInputType<TParams['_input'], 'in'>>) => Promise<TOutput>;
38
+ }) => Promise<TOutput>) => SanitizeFunctionParam<(input: InferInputType<TParams['_input'], 'in'>) => Promise<TOutput>>;
38
39
  /**
39
40
  * Create an action for React `useFormState`
40
41
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "server-act",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "homepage": "https://github.com/chungweileong94/server-act#readme",
5
5
  "author": "chungweileong94",
6
6
  "license": "MIT",