phecda-zod 1.0.1 → 1.0.2

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.
@@ -0,0 +1,7 @@
1
+ import { ZodTypeDef, ZodSchema, z } from 'zod';
2
+
3
+ declare function zodToClass<TOutput = any, TDef extends ZodTypeDef = ZodTypeDef, TInput = TOutput>(zod: ZodSchema<TOutput, TDef, TInput>): (new (data?: Partial<z.infer<ZodSchema<TOutput, TDef, TInput>>>) => z.infer<ZodSchema<TOutput, TDef, TInput>>) & {
4
+ schema: ZodSchema<TOutput, TDef, TInput>;
5
+ };
6
+
7
+ export { zodToClass };
package/dist/index.js CHANGED
@@ -33,11 +33,9 @@ function ZodTo(cb) {
33
33
  const ret = cb(instance, addError);
34
34
  if (ret) {
35
35
  for (const key2 in instance) {
36
- if (key2 !== "_value")
37
- delete instance[key2];
36
+ if (key2 !== "_value") delete instance[key2];
38
37
  }
39
- for (const key2 in ret)
40
- instance[key2] = ret[key2];
38
+ for (const key2 in ret) instance[key2] = ret[key2];
41
39
  }
42
40
  }
43
41
  });
@@ -45,19 +43,20 @@ function ZodTo(cb) {
45
43
  }
46
44
  __name(ZodTo, "ZodTo");
47
45
  function zodToClass(zod) {
48
- let Z = /* @__PURE__ */ __name(class Z {
46
+ let Z = class Z {
47
+ static {
48
+ __name(this, "Z");
49
+ }
49
50
  constructor(data) {
50
51
  for (const key in data)
51
52
  this[key] = data[key];
52
53
  }
53
54
  static schema = zod;
54
- }, "Z");
55
+ };
55
56
  (0, import_phecda_core.addDecoToClass)(Z, void 0, ZodTo((ins, addError) => {
56
57
  const result = zod.safeParse(ins);
57
- if (!result.success)
58
- result.error.issues.forEach(({ message }) => addError(message));
59
- else
60
- return result.data;
58
+ if (!result.success) result.error.issues.forEach(({ message }) => addError(message));
59
+ else return result.data;
61
60
  }));
62
61
  return Z;
63
62
  }
package/dist/index.mjs CHANGED
@@ -11,11 +11,9 @@ function ZodTo(cb) {
11
11
  const ret = cb(instance, addError);
12
12
  if (ret) {
13
13
  for (const key2 in instance) {
14
- if (key2 !== "_value")
15
- delete instance[key2];
14
+ if (key2 !== "_value") delete instance[key2];
16
15
  }
17
- for (const key2 in ret)
18
- instance[key2] = ret[key2];
16
+ for (const key2 in ret) instance[key2] = ret[key2];
19
17
  }
20
18
  }
21
19
  });
@@ -23,19 +21,20 @@ function ZodTo(cb) {
23
21
  }
24
22
  __name(ZodTo, "ZodTo");
25
23
  function zodToClass(zod) {
26
- let Z = /* @__PURE__ */ __name(class Z {
24
+ let Z = class Z {
25
+ static {
26
+ __name(this, "Z");
27
+ }
27
28
  constructor(data) {
28
29
  for (const key in data)
29
30
  this[key] = data[key];
30
31
  }
31
32
  static schema = zod;
32
- }, "Z");
33
+ };
33
34
  addDecoToClass(Z, void 0, ZodTo((ins, addError) => {
34
35
  const result = zod.safeParse(ins);
35
- if (!result.success)
36
- result.error.issues.forEach(({ message }) => addError(message));
37
- else
38
- return result.data;
36
+ if (!result.success) result.error.issues.forEach(({ message }) => addError(message));
37
+ else return result.data;
39
38
  }));
40
39
  return Z;
41
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-zod",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "use zod instead of decorator/reflect-metadata",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -12,10 +12,10 @@
12
12
  ],
13
13
  "license": "MIT",
14
14
  "devDependencies": {
15
- "tsup": "^6.5.0"
15
+ "tsup": "^8.1.0"
16
16
  },
17
17
  "dependencies": {
18
- "phecda-core": "3.0.0",
18
+ "phecda-core": "3.0.1",
19
19
  "zod": "^3.23.5"
20
20
  },
21
21
  "scripts": {