server-act 1.1.5 → 1.1.7

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
4
4
  try {
5
5
  var info = gen[key](arg);
6
6
  var value = info.value;
@@ -43,10 +43,10 @@ function _extends() {
43
43
  };
44
44
  return _extends.apply(this, arguments);
45
45
  }
46
- const createNewServerActionBuilder = (def)=>{
46
+ function createNewServerActionBuilder(def) {
47
47
  return createServerActionBuilder(def);
48
- };
49
- const createServerActionBuilder = (initDef = {})=>{
48
+ }
49
+ function createServerActionBuilder(initDef = {}) {
50
50
  const _def = _extends({
51
51
  input: undefined,
52
52
  middleware: undefined
@@ -59,6 +59,7 @@ const createServerActionBuilder = (initDef = {})=>{
59
59
  input
60
60
  })),
61
61
  action: (action)=>{
62
+ // biome-ignore lint/suspicious/noExplicitAny: Intended
62
63
  return /*#__PURE__*/ _async_to_generator(function*(input) {
63
64
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
64
65
  if (_def.input) {
@@ -78,7 +79,7 @@ const createServerActionBuilder = (initDef = {})=>{
78
79
  return /*#__PURE__*/ _async_to_generator(function*(prevState, formData) {
79
80
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
80
81
  if (_def.input) {
81
- const result = _def.input.safeParse(formData);
82
+ const result = yield _def.input.safeParseAsync(formData);
82
83
  if (!result.success) {
83
84
  return yield action({
84
85
  ctx,
@@ -100,7 +101,7 @@ const createServerActionBuilder = (initDef = {})=>{
100
101
  });
101
102
  }
102
103
  };
103
- };
104
+ }
104
105
  /**
105
106
  * Server action builder
106
107
  */ const serverAct = createServerActionBuilder();
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
2
  try {
3
3
  var info = gen[key](arg);
4
4
  var value = info.value;
@@ -41,10 +41,10 @@ function _extends() {
41
41
  };
42
42
  return _extends.apply(this, arguments);
43
43
  }
44
- const createNewServerActionBuilder = (def)=>{
44
+ function createNewServerActionBuilder(def) {
45
45
  return createServerActionBuilder(def);
46
- };
47
- const createServerActionBuilder = (initDef = {})=>{
46
+ }
47
+ function createServerActionBuilder(initDef = {}) {
48
48
  const _def = _extends({
49
49
  input: undefined,
50
50
  middleware: undefined
@@ -57,6 +57,7 @@ const createServerActionBuilder = (initDef = {})=>{
57
57
  input
58
58
  })),
59
59
  action: (action)=>{
60
+ // biome-ignore lint/suspicious/noExplicitAny: Intended
60
61
  return /*#__PURE__*/ _async_to_generator(function*(input) {
61
62
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
62
63
  if (_def.input) {
@@ -76,7 +77,7 @@ const createServerActionBuilder = (initDef = {})=>{
76
77
  return /*#__PURE__*/ _async_to_generator(function*(prevState, formData) {
77
78
  const ctx = yield _def.middleware == null ? void 0 : _def.middleware.call(_def);
78
79
  if (_def.input) {
79
- const result = _def.input.safeParse(formData);
80
+ const result = yield _def.input.safeParseAsync(formData);
80
81
  if (!result.success) {
81
82
  return yield action({
82
83
  ctx,
@@ -98,7 +99,7 @@ const createServerActionBuilder = (initDef = {})=>{
98
99
  });
99
100
  }
100
101
  };
101
- };
102
+ }
102
103
  /**
103
104
  * Server action builder
104
105
  */ const serverAct = createServerActionBuilder();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "server-act",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "homepage": "https://github.com/chungweileong94/server-act#readme",
5
5
  "author": "chungweileong94",
6
6
  "license": "MIT",
@@ -45,9 +45,6 @@
45
45
  ],
46
46
  "devDependencies": {
47
47
  "bunchee": "^4.3.3",
48
- "eslint": "^8.49.0",
49
- "eslint-config-whiteroom": "^3.3.0",
50
- "prettier": "^3.0.3",
51
48
  "typescript": "^5.2.2",
52
49
  "zod": "^3.22.2",
53
50
  "zod-form-data": "^2.0.2"
@@ -64,7 +61,7 @@
64
61
  "scripts": {
65
62
  "build": "bunchee",
66
63
  "dev": "bunchee -w",
67
- "test": "vitest run",
68
- "lint": "eslint src --ext .ts"
64
+ "typecheck": "tsc --noEmit",
65
+ "test": "vitest run"
69
66
  }
70
67
  }